* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)rsh.c 5.7 (Berkeley) 9/20/88";
#include <kerberos/krb.h>
char krb_realm
[REALM_SZ
];
int use_kerberos
= 1, encrypt
= 0;
char *index(), *rindex(), *malloc(), *getpass(), *strcpy();
struct passwd
*getpwuid();
#define mask(s) (1 << ((s) - 1))
char *host
, *cp
, **ap
, buf
[BUFSIZ
], *args
, **argv
= argv0
, *user
= 0;
host
= rindex(argv
[0], '/');
if (!strcmp(host
, "rsh")) {
if (argc
> 0 && !strcmp(*argv
, "-l")) {
if (argc
> 0 && !strcmp(*argv
, "-n")) {
if (argc
> 0 && !strcmp(*argv
, "-d")) {
* Ignore the -L, -w, -e and -8 flags to allow aliases with rlogin
* There must be a better way to do this! -jmb
if (argc
> 0 && !strncmp(*argv
, "-L", 2)) {
if (argc
> 0 && !strncmp(*argv
, "-w", 2)) {
if (argc
> 0 && !strncmp(*argv
, "-e", 2)) {
if (argc
> 0 && !strncmp(*argv
, "-8", 2)) {
if(argc
> 0 && !strncmp(*argv
, "-x", 2)) {
des_set_key(cred
.session
, schedule
);
if(argc
> 0 && !strcmp(*argv
, "-k")) {
if(argc
<= 0 || (**argv
== '-')) {
fprintf(stderr
, "-k option requires an argument\n");
strncpy(krb_realm
, *argv
, REALM_SZ
);
execv("/usr/ucb/rlogin", argv0
);
perror("/usr/ucb/rlogin");
pwd
= getpwuid(getuid());
fprintf(stderr
, "who are you?\n");
for (ap
= argv
; *ap
; ap
++)
for (ap
= argv
; *ap
; ap
++) {
sp
= getservbyname("kshell", "tcp");
old_warning("kshell service unknown");
sp
= getservbyname("shell", "tcp");
sp
= getservbyname("shell", "tcp");
fprintf(stderr
, "rsh: shell/tcp: unknown service\n");
if(krb_realm
[0] == '\0') {
rem
= krb_get_lrealm(krb_realm
, 1);
user
? user
: pwd
->pw_name
,
user
? user
: pwd
->pw_name
,
"%s: error getting local realm\n",
if((rem
< 0) && errno
== ECONNREFUSED
) {
sp
= getservbyname("shell", "tcp");
fprintf(stderr
, "unknown service shell/tcp\n");
old_warning("remote host doesn't support Kerberos");
fprintf(stderr
,"The -x flag requires Kerberos authentication\n");
rem
= rcmd(&host
, sp
->s_port
, pwd
->pw_name
,
user
? user
: pwd
->pw_name
, args
, &rfd2
);
rem
= rcmd(&host
, sp
->s_port
, pwd
->pw_name
,
user
? user
: pwd
->pw_name
, args
, &rfd2
);
fprintf(stderr
, "rsh: can't establish stderr\n");
if (options
& SO_DEBUG
) {
if (setsockopt(rem
, SOL_SOCKET
, SO_DEBUG
, &one
, sizeof (one
)) < 0)
perror("setsockopt (stdin)");
if (setsockopt(rfd2
, SOL_SOCKET
, SO_DEBUG
, &one
, sizeof (one
)) < 0)
perror("setsockopt (stderr)");
omask
= sigblock(mask(SIGINT
)|mask(SIGQUIT
)|mask(SIGTERM
));
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
if (signal(SIGQUIT
, SIG_IGN
) != SIG_IGN
)
signal(SIGQUIT
, sendsig
);
if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
signal(SIGTERM
, sendsig
);
ioctl(rfd2
, FIONBIO
, &one
);
ioctl(rem
, FIONBIO
, &one
);
if (nflag
== 0 && pid
== 0) {
char *bp
; int rembits
, wc
;
cc
= read(0, buf
, sizeof buf
);
if (select(16, 0, &rembits
, 0, 0) < 0) {
if ((rembits
& (1<<rem
)) == 0)
if (errno
== EWOULDBLOCK
)
readfrom
= (1<<rfd2
) | (1<<rem
);
if (select(16, &ready
, 0, 0, 0) < 0) {
cc
= read(rfd2
, buf
, sizeof buf
);
if (errno
!= EWOULDBLOCK
)
(void) write(2, buf
, cc
);
cc
= read(rem
, buf
, sizeof buf
);
if (errno
!= EWOULDBLOCK
)
(void) write(1, buf
, cc
);
(void) kill(pid
, SIGKILL
);
"usage: rsh host [ -l login ] [ -n ] [ -k realm ] command\n");
"usage: rsh host [ -l login ] [ -n ] command\n");
(void) write(rfd2
, &signo
, 1);
fprintf(stderr
,"Warning: %s, using standard rsh\n", str
);