* $Source: /a/staff/kfall/mit/rsh/RCS/rsh.c,v $
* $Header: /a/staff/kfall/mit/rsh/RCS/rsh.c,v 5.1 89/07/31 19:28:59 kfall Exp Locker: kfall $
* 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)rsh.c 5.12 (Berkeley) 5/11/89";
char dst_realm_buf
[REALM_SZ
];
int use_kerberos
= 1, encrypt
= 0;
extern char *krb_realmofhost();
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");
dest_realm
= dst_realm_buf
;
strncpy(dest_realm
, *argv
, REALM_SZ
);
execv(_PATH_RLOGIN
, argv0
);
pwd
= getpwuid(getuid());
fprintf(stderr
, "who are you?\n");
for (ap
= argv
; *ap
; ap
++)
for (ap
= argv
; *ap
; ap
++) {
sp
= getservbyname((encrypt
? "ekshell" : "kshell"), "tcp");
(void) sprintf(msgbuf
, "can't get entry for %s/tcp service",
(encrypt
? "ekshell" : "kshell"));
sp
= getservbyname("shell", "tcp");
sp
= getservbyname("shell", "tcp");
fprintf(stderr
, "rsh: shell/tcp: unknown service\n");
dest_realm
= krb_realmofhost(host
);
user
? user
: pwd
->pw_name
,
user
? user
: pwd
->pw_name
,
sp
= getservbyname("shell", "tcp");
fprintf(stderr
, "unknown service shell/tcp\n");
if (errno
== ECONNREFUSED
)
old_warning("remote host doesn't support Kerberos");
old_warning("Can't provide Kerberos auth data");
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)
wc
= des_write(rem
, bp
, cc
);
if (errno
== EWOULDBLOCK
)
readfrom
= (1<<rfd2
) | (1<<rem
);
if (select(16, &ready
, 0, 0, 0) < 0) {
cc
= des_read(rfd2
, buf
, sizeof buf
);
cc
= read(rfd2
, buf
, sizeof buf
);
if (errno
!= EWOULDBLOCK
)
(void) write(2, buf
, cc
);
cc
= des_read(rem
, buf
, sizeof buf
);
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) des_write(rfd2
, &signo
, 1);
(void) write(rfd2
, &signo
, 1);
fprintf(stderr
,"Warning: %s, using standard rsh\n", str
);