+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
#ifndef lint
-static char sccsid[] = "@(#)rsh.c 4.11 85/03/02";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)rsh.c 5.7 (Berkeley) %G%";
+#endif /* not lint */
#include <sys/types.h>
#include <sys/socket.h>
*/
/* VARARGS */
int error();
-char *index(), *rindex(), *malloc(), *getpass(), *sprintf(), *strcpy();
+char *index(), *rindex(), *malloc(), *getpass(), *strcpy();
struct passwd *getpwuid();
int errno;
int options;
int rfd2;
+int nflag;
int sendsig();
#define mask(s) (1 << ((s) - 1))
}
if (argc > 0 && !strcmp(*argv, "-n")) {
argv++, argc--;
- (void) close(0);
- (void) open("/dev/null", 0);
+ nflag++;
goto another;
}
if (argc > 0 && !strcmp(*argv, "-d")) {
goto another;
}
/*
- * Ignore the -e and -8 flags to allow aliases with rlogin
+ * Ignore the -L, -w, -e and -8 flags to allow aliases with rlogin
* to work
+ *
+ * There must be a better way to do this! -jmb
*/
+ if (argc > 0 && !strncmp(*argv, "-L", 2)) {
+ argv++, argc--;
+ goto another;
+ }
+ if (argc > 0 && !strncmp(*argv, "-w", 2)) {
+ argv++, argc--;
+ goto another;
+ }
if (argc > 0 && !strncmp(*argv, "-e", 2)) {
argv++, argc--;
goto another;
}
(void) setuid(getuid());
omask = sigblock(mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
- signal(SIGINT, sendsig);
- signal(SIGQUIT, sendsig);
- signal(SIGTERM, sendsig);
- pid = fork();
- if (pid < 0) {
- perror("fork");
- exit(1);
- }
+ if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+ signal(SIGINT, sendsig);
+ if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
+ signal(SIGQUIT, sendsig);
+ if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
+ signal(SIGTERM, sendsig);
+ if (nflag == 0) {
+ pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ exit(1);
+ }
+ }
ioctl(rfd2, FIONBIO, &one);
ioctl(rem, FIONBIO, &one);
- if (pid == 0) {
+ if (nflag == 0 && pid == 0) {
char *bp; int rembits, wc;
(void) close(rfd2);
reread:
(void) write(1, buf, cc);
}
} while (readfrom);
- (void) kill(pid, SIGKILL);
+ if (nflag == 0)
+ (void) kill(pid, SIGKILL);
exit(0);
usage:
fprintf(stderr,
- "usage: rsh host [ -l login ] [ -p passwd ] command\n");
+ "usage: rsh host [ -l login ] [ -n ] command\n");
exit(1);
}