From e4551b5444f4af581d9bed22c0546f92af820c66 Mon Sep 17 00:00:00 2001 From: tedu Date: Sat, 19 Apr 2014 14:58:50 +0000 Subject: [PATCH] Once great men lived here... giants... gods... once, but long ago. --- usr.bin/rsh/Makefile | 8 -- usr.bin/rsh/pathnames.h | 34 ----- usr.bin/rsh/rsh.1 | 155 -------------------- usr.bin/rsh/rsh.c | 305 ---------------------------------------- 4 files changed, 502 deletions(-) delete mode 100644 usr.bin/rsh/Makefile delete mode 100644 usr.bin/rsh/pathnames.h delete mode 100644 usr.bin/rsh/rsh.1 delete mode 100644 usr.bin/rsh/rsh.c diff --git a/usr.bin/rsh/Makefile b/usr.bin/rsh/Makefile deleted file mode 100644 index ac35a03845a..00000000000 --- a/usr.bin/rsh/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.8 2004/01/17 20:57:15 millert Exp $ - -PROG= rsh -SRCS= rsh.c -BINOWN= root -BINMODE=4555 - -.include diff --git a/usr.bin/rsh/pathnames.h b/usr.bin/rsh/pathnames.h deleted file mode 100644 index 808db106a09..00000000000 --- a/usr.bin/rsh/pathnames.h +++ /dev/null @@ -1,34 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.5 2004/01/17 22:42:50 millert Exp $ */ - -/* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)pathnames.h 5.2 (Berkeley) 4/9/90 - */ - -#define _PATH_SSH "/usr/bin/ssh" diff --git a/usr.bin/rsh/rsh.1 b/usr.bin/rsh/rsh.1 deleted file mode 100644 index ff35cd06c51..00000000000 --- a/usr.bin/rsh/rsh.1 +++ /dev/null @@ -1,155 +0,0 @@ -.\" $OpenBSD: rsh.1,v 1.17 2007/05/31 19:20:15 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1990 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)rsh.1 6.10 (Berkeley) 7/24/91 -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt RSH 1 -.Os -.Sh NAME -.Nm rsh -.Nd remote shell -.Sh SYNOPSIS -.Nm rsh -.Op Fl dn -.Op Fl l Ar username -.Ar hostname -.Op Ar command -.Sh DESCRIPTION -.Nm -executes -.Ar command -on -.Ar hostname . -.Pp -.Em Note: -.Nm -has been deprecated in favor of -.Xr ssh 1 . -Use of -.Nm -is discouraged due to the inherent insecurity of host-based authentication. -.Pp -.Nm -copies its standard input to the remote command, the standard -output of the remote command to its standard output, and the -standard error of the remote command to its standard error. -Interrupt, quit and terminate signals are propagated to the remote -command; -.Nm -normally terminates when the remote command does. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl d -Enable socket debugging (using -.Xr setsockopt 2 ) -on the -.Tn TCP -sockets used for communication with the remote host. -.It Fl l Ar username -By default, the remote username is the same as the local username. -The -.Fl l -option allows the remote name to be specified. -.It Fl n -Redirect input from the special device -.Pa /dev/null -(see the -.Sx BUGS -section of this manual page). -.El -.Pp -If no -.Ar command -is specified, you will be logged in on the remote host using -.Xr ssh 1 . -.Pp -If -.Nm -is not invoked with the standard program name -.Pq Dq rsh , -it uses this name as its -.Ar hostname -argument. -.Pp -Shell meta-characters which are not quoted are interpreted on local machine, -while quoted meta-characters are interpreted on the remote machine. -For example, the command -.Pp -.Dl $ rsh otherhost cat remotefile >> localfile -.Pp -appends the remote file -.Ar remotefile -to the local file -.Ar localfile , -while -.Pp -.Dl $ rsh otherhost cat remotefile \&">>\&" other_remotefile -.Pp -appends -.Ar remotefile -to -.Ar other_remotefile . -.\" .Pp -.\" Many sites specify a large number of host names as commands in the -.\" directory /usr/hosts. -.\" If this directory is included in your search path, you can use the -.\" shorthand ``host command'' for the longer form ``rsh host command''. -.Sh FILES -.Bl -tag -width /etc/hosts -compact -.It Pa /etc/hosts -.El -.Sh SEE ALSO -.Xr ssh 1 , -.Xr rcmd 3 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.2 . -.Sh BUGS -If you are using -.Xr csh 1 -and put a -.Nm -in the background without redirecting its input away from the terminal, -it will block even if no reads are posted by the remote command. -If no input is desired you should redirect the input of -.Nm -to -.Pa /dev/null -using the -.Fl n -option. -.Pp -Stop signals stop the local -.Nm -process only; this is arguably wrong, but currently hard to fix for reasons -too complicated to explain here. diff --git a/usr.bin/rsh/rsh.c b/usr.bin/rsh/rsh.c deleted file mode 100644 index 52e95c6de85..00000000000 --- a/usr.bin/rsh/rsh.c +++ /dev/null @@ -1,305 +0,0 @@ -/* $OpenBSD: rsh.c,v 1.40 2009/10/27 23:59:43 deraadt Exp $ */ - -/*- - * Copyright (c) 1983, 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pathnames.h" - -__dead void usage(void); -void sendsig(int); -char *copyargs(char **argv); -void talk(int, sigset_t *, int, int); - -/* - * rsh - remote shell - */ -int rfd2; - -int -main(int argc, char *argv[]) -{ - struct passwd *pw; - struct servent *sp; - sigset_t mask, omask; - int argoff = 0, asrsh = 0, ch, dflag = 0, nflag = 0, one = 1, rem; - char *args, *host = NULL, *user = NULL; - pid_t pid = 0; - extern char *__progname; - uid_t uid; - - /* if called as something other than "rsh", use it as the host name */ - if (strcmp(__progname, "rsh") != 0) - host = __progname; - else - asrsh = 1; - - /* handle "rsh host flags" */ - if (!host && argc > 2 && argv[1][0] != '-') { - host = argv[1]; - argoff = 1; - } - - while ((ch = getopt(argc - argoff, argv + argoff, "8KLdel:nw")) != -1) - switch(ch) { - case '8': /* -8KLew are ignored to allow rlogin aliases */ - case 'K': - case 'L': - case 'e': - case 'w': - break; - case 'd': - dflag = 1; - break; - case 'l': - user = optarg; - break; - case 'n': - nflag = 1; - break; - default: - usage(); - } - optind += argoff; - - uid = getuid(); - - /* if haven't gotten a host yet, do so */ - if (!host && !(host = argv[optind++])) - usage(); - - /* if no command, login to remote host via ssh. */ - if (!argv[optind]) { - if (setresuid(uid, uid, uid) == -1) - err(1, "setresuid"); - if (asrsh) - *argv = "ssh"; - execv(_PATH_SSH, argv); - errx(1, "can't exec %s", _PATH_SSH); - } - - argc -= optind; - argv += optind; - - if (geteuid() != 0) - errx(1, "must be setuid root"); - if ((pw = getpwuid(uid)) == NULL) - errx(1, "unknown user ID %u", uid); - if (user == NULL) - user = pw->pw_name; - - args = copyargs(argv); - - if ((sp = getservbyname("shell", "tcp")) == NULL) - errx(1, "shell/tcp: unknown service"); - - (void)unsetenv("RSH"); /* no tricks with rcmd(3) */ - - rem = rcmd_af(&host, sp->s_port, pw->pw_name, user, args, &rfd2, - PF_UNSPEC); - if (rem < 0) - exit(1); - if (rfd2 < 0) - errx(1, "can't establish stderr"); - - if (setresuid(uid, uid, uid) == -1) - err(1, "setresuid"); - - if (dflag) { - if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, - sizeof(one)) < 0) - warn("setsockopt"); - if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, &one, - sizeof(one)) < 0) - warn("setsockopt"); - } - sigemptyset(&mask); - sigaddset(&mask, SIGINT); - sigaddset(&mask, SIGQUIT); - sigaddset(&mask, SIGTERM); - sigprocmask(SIG_BLOCK, &mask, &omask); - if (signal(SIGINT, SIG_IGN) != SIG_IGN) - (void)signal(SIGINT, sendsig); - if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) - (void)signal(SIGQUIT, sendsig); - if (signal(SIGTERM, SIG_IGN) != SIG_IGN) - (void)signal(SIGTERM, sendsig); - - if (!nflag) { - if ((pid = fork()) < 0) - err(1, "fork"); - } - - (void)ioctl(rfd2, FIONBIO, &one); - (void)ioctl(rem, FIONBIO, &one); - - talk(nflag, &omask, pid, rem); - - if (!nflag) - (void)kill(pid, SIGKILL); - - return 0; -} - -void -talk(int nflag, sigset_t *omask, pid_t pid, int rem) -{ - int cc, wc; - char *bp; - struct pollfd pfd[2]; - char buf[BUFSIZ]; - - if (!nflag && pid == 0) { - (void)close(rfd2); - -reread: errno = 0; - if ((cc = read(STDIN_FILENO, buf, sizeof buf)) <= 0) - goto done; - bp = buf; - - pfd[0].fd = rem; - pfd[0].events = POLLOUT; -rewrite: - if (poll(pfd, 1, INFTIM) < 0) { - if (errno != EINTR) - err(1, "poll"); - goto rewrite; - } - if (pfd[0].revents & (POLLERR|POLLHUP|POLLNVAL)) - err(1, "poll"); - wc = write(rem, bp, cc); - if (wc < 0) { - if (errno == EWOULDBLOCK) - goto rewrite; - goto done; - } - bp += wc; - cc -= wc; - if (cc == 0) - goto reread; - goto rewrite; -done: - (void)shutdown(rem, 1); - exit(0); - } - - sigprocmask(SIG_SETMASK, omask, NULL); - pfd[1].fd = rfd2; - pfd[1].events = POLLIN; - pfd[0].fd = rem; - pfd[0].events = POLLIN; - do { - if (poll(pfd, 2, INFTIM) < 0) { - if (errno != EINTR) - err(1, "poll"); - continue; - } - if ((pfd[0].revents & (POLLERR|POLLHUP|POLLNVAL)) || - (pfd[1].revents & (POLLERR|POLLHUP|POLLNVAL))) - err(1, "poll"); - if (pfd[1].revents & POLLIN) { - errno = 0; - cc = read(rfd2, buf, sizeof buf); - if (cc <= 0) { - if (errno != EWOULDBLOCK) - pfd[1].revents = 0; - } else - (void)write(STDERR_FILENO, buf, cc); - } - if (pfd[0].revents & POLLIN) { - errno = 0; - cc = read(rem, buf, sizeof buf); - if (cc <= 0) { - if (errno != EWOULDBLOCK) - pfd[0].revents = 0; - } else - (void)write(STDOUT_FILENO, buf, cc); - } - } while ((pfd[0].revents & POLLIN) || (pfd[1].revents & POLLIN)); -} - -void -sendsig(int signo) -{ - int save_errno = errno; - - (void)write(rfd2, &signo, 1); - errno = save_errno; -} - -char * -copyargs(char **argv) -{ - char **ap, *p, *args; - size_t cc, len; - - cc = 0; - for (ap = argv; *ap; ++ap) - cc += strlen(*ap) + 1; - if ((args = malloc(cc)) == NULL) - err(1, NULL); - for (p = args, ap = argv; *ap; ++ap) { - len = strlcpy(p, *ap, cc); - if (len >= cc) - errx(1, "copyargs overflow"); - p += len; - cc -= len; - if (ap[1]) { - *p++ = ' '; - cc--; - } - } - return(args); -} - -__dead void -usage(void) -{ - (void)fprintf(stderr, - "usage: rsh [-dn] [-l username] hostname [command]\n"); - exit(1); -} -- 2.20.1