diff options
-rw-r--r-- | bin/rcp/Makefile | 4 | ||||
-rw-r--r-- | libexec/rshd/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/passwd/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/rlogin/Makefile | 18 | ||||
-rw-r--r-- | usr.bin/rlogin/rlogin.1 | 199 | ||||
-rw-r--r-- | usr.bin/rlogin/rlogin.c | 956 | ||||
-rw-r--r-- | usr.bin/rsh/Makefile | 3 | ||||
-rw-r--r-- | usr.bin/rsh/des_rw.c (renamed from usr.bin/rlogin/des_rw.c) | 4 | ||||
-rw-r--r-- | usr.bin/rsh/kcmd.c (renamed from usr.bin/rlogin/kcmd.c) | 4 | ||||
-rw-r--r-- | usr.bin/rsh/krcmd.c (renamed from usr.bin/rlogin/krcmd.c) | 4 |
11 files changed, 15 insertions, 1189 deletions
diff --git a/bin/rcp/Makefile b/bin/rcp/Makefile index 7af01718b8c..b627be30efc 100644 --- a/bin/rcp/Makefile +++ b/bin/rcp/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2000/09/03 18:41:11 espie Exp $ +# $OpenBSD: Makefile,v 1.7 2002/05/06 22:23:53 deraadt Exp $ PROG= rcp SRCS= rcp.c util.c @@ -9,7 +9,7 @@ BINMODE=4555 .include <bsd.own.mk> # For KERBEROS .if (${KERBEROS:L} == "yes") -.PATH: ${.CURDIR}/../../usr.bin/rlogin +.PATH: ${.CURDIR}/../../usr.bin/rsh SRCS+= krcmd.c kcmd.c CFLAGS+=-DKERBEROS LDADD+= -lkrb -ldes diff --git a/libexec/rshd/Makefile b/libexec/rshd/Makefile index b3d671fdef3..f497dd94141 100644 --- a/libexec/rshd/Makefile +++ b/libexec/rshd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2001/01/28 19:34:32 niklas Exp $ +# $OpenBSD: Makefile,v 1.7 2002/05/06 22:23:53 deraadt Exp $ PROG= rshd SRCS= rshd.c @@ -9,7 +9,7 @@ CFLAGS+= -Wall -Wno-unused .if (${KERBEROS:L} == "yes") SRCS+= des_rw.c -.PATH: ${.CURDIR}/../../usr.bin/rlogin +.PATH: ${.CURDIR}/../../usr.bin/rsh CFLAGS+=-DKERBEROS DPADD+= ${LIBKRB} ${LIBDES} LDADD+= -lkrb -ldes diff --git a/usr.bin/Makefile b/usr.bin/Makefile index a71135e3715..2210d21e96b 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.76 2002/03/01 22:01:11 millert Exp $ +# $OpenBSD: Makefile,v 1.77 2002/05/06 22:23:53 deraadt Exp $ .include <bsd.own.mk> @@ -12,7 +12,7 @@ SUBDIR= apply apropos arch asa at aucat audioctl awk banner basename bdes \ login logname look lorder m4 mail make man mesg mg midiplay mixerctl \ mkdep mkstr mktemp modstat msgs nc netstat newsyslog nfsstat nice \ nohup oldrdist pagesize passwd paste patch pctr pr printenv printf \ - quota radioctl rdist rdistd readlink renice rev rlogin rpcgen rpcinfo \ + quota radioctl rdist rdistd readlink renice rev rpcgen rpcinfo \ rs rsh \ rup ruptime rusers rwall rwho script sectok sed shar showmount skey \ skeyaudit skeyinfo skeyinit sort spell split ssh su sup systat sudo \ diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile index ded45ff9476..01f0ba21e58 100644 --- a/usr.bin/passwd/Makefile +++ b/usr.bin/passwd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.24 2001/11/22 20:37:18 espie Exp $ +# $OpenBSD: Makefile,v 1.25 2002/05/06 22:23:53 deraadt Exp $ .include <bsd.own.mk> @@ -24,7 +24,7 @@ LDADD+= -lkrb5 -lcrypto -lasn1 .endif .if (${KERBEROS:L} == "yes") -.PATH: ${.CURDIR}/../rlogin +.PATH: ${.CURDIR}/../rsh SRCS+= new_pwd.c krb_passwd.c des_rw.c CFLAGS+= -DKERBEROS DPADD+= ${LIBKRB} ${LIBDES} diff --git a/usr.bin/rlogin/Makefile b/usr.bin/rlogin/Makefile deleted file mode 100644 index 52ec1e88340..00000000000 --- a/usr.bin/rlogin/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $OpenBSD: Makefile,v 1.6 2000/09/03 18:41:18 espie Exp $ - -PROG= rlogin -SRCS= rlogin.c -BINOWN= root -BINMODE=4555 -#INSTALLFLAGS=-fschg - -.include <bsd.own.mk> - -.if (${KERBEROS:L} == "yes") -CFLAGS+=-DKERBEROS -SRCS+= krcmd.c kcmd.c des_rw.c -LDADD+= -lkrb -ldes -DPADD+= ${LIBKRB} ${LIBDES} -.endif - -.include <bsd.prog.mk> diff --git a/usr.bin/rlogin/rlogin.1 b/usr.bin/rlogin/rlogin.1 deleted file mode 100644 index d0963d125ed..00000000000 --- a/usr.bin/rlogin/rlogin.1 +++ /dev/null @@ -1,199 +0,0 @@ -.\" $OpenBSD: rlogin.1,v 1.10 2001/06/23 23:15:37 hin Exp $ -.\" $NetBSD: rlogin.1,v 1.4 1995/08/18 15:07:35 pk Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1993 -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)rlogin.1 8.1 (Berkeley) 6/6/93 -.\" -.Dd June 6, 1993 -.Dt RLOGIN 1 -.Os -.Sh NAME -.Nm rlogin -.Nd remote login -.Sh SYNOPSIS -.Ar rlogin -.Op Fl 8EKLd -.Op Fl e Ar char -.Op Fl k Ar realm -.Op Fl l Ar username -.Ar host -.Sh DESCRIPTION -.Nm -starts a terminal session on a remote host -.Ar host . -.Pp -.Nm -first attempts to use the Kerberos authorization mechanism, described below. -If the remote host does not support Kerberos the standard Berkeley -.Pa rhosts -authorization mechanism is used. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl 8 -The -.Fl 8 -option allows an eight-bit input data path at all times; otherwise -parity bits are stripped except when the remote side's stop and start -characters are other than -^S/^Q . -.It Fl E -The -.Fl E -option stops any character from being recognized as an escape character. -When used with the -.Fl 8 -option, this provides a completely transparent connection. -.It Fl K -The -.Fl K -option turns off all Kerberos authentication. -.It Fl L -The -.Fl L -option allows the rlogin session to be run in -.Dq litout -(see -.Xr tty 4 ) -mode. -.It Fl d -The -.Fl d -option turns on socket debugging (see -.Xr setsockopt 2 ) -on the TCP sockets used for communication with the remote host. -.It Fl e Ar char -The -.Fl e -option allows user specification of the escape character, which is -.Ql ~ -by default. -This specification may be as a literal character, or as an octal -value in the form \ennn. -.It Fl k Ar realm -The -.Fl k -option requests rlogin to obtain tickets for the remote host -in realm -.Ar realm -instead of the remote host's realm as determined by -.Xr krb_realmofhost 3 . -.It Fl l Ar username -The -.Fl l -option specifies a different -.Ar username -for the remote login. -If this option is not specified, your local username will be used. -.El -.Pp -A line of the form -.Dq <escape char>. -disconnects from the remote host. -Similarly, the line -.Dq <escape char>^Z -will suspend the -.Nm -session, and -.Dq <escape char><delayed-suspend char> -suspends the -send portion of the rlogin, but allows output from the remote system. -By default, the tilde -.Pq Ql ~ -character is the escape character, and -normally control-Y -.Pq Ql ^Y -is the delayed-suspend character. -.Pp -All echoing takes place at the remote site, so that (except for delays) -the -.Nm -is transparent. -Flow control via ^S/^Q and flushing of input and output on interrupts -are handled properly. -.Sh KERBEROS AUTHENTICATION -Each user may have a private authorization list in the file -.Pa .klogin -in their home directory. -Each line in this file should contain a Kerberos principal name of the -form -.Ar principal.instance@realm . -If the originating user is authenticated to one of the principals named -in -.Pa .klogin , -access is granted to the account. -The principal -.Ar accountname.@localrealm -is granted access if -there is no -.Pa .klogin -file. -Otherwise a login and password will be prompted for on the remote machine -as in -.Xr login 1 . -To avoid certain security problems, the -.Pa .klogin -file must be owned by -the remote user. -.Pp -If Kerberos authentication fails, a warning message is printed and the -standard Berkeley -.Nm -is used instead. -.Sh ENVIRONMENT -.Bl -tag -width TERM -.It Ev TERM -Determines the user's terminal type. -.El -.Sh SEE ALSO -.Xr rsh 1 , -.Xr kerberos 3 , -.Xr krb_realmofhost 3 , -.Xr krb_sendauth 3 -.Sh HISTORY -The -.Nm rlogin -command appeared in -.Bx 4.2 . -.Sh BUGS -.Nm rlogin -will be replaced by -.Xr telnet 1 -in the near future. -.Pp -More of the environment should be propagated. -.Pp -.Nm -does not currently support encryption of the datastream when Kerberos -authentication is used. - diff --git a/usr.bin/rlogin/rlogin.c b/usr.bin/rlogin/rlogin.c deleted file mode 100644 index 39b80273bb3..00000000000 --- a/usr.bin/rlogin/rlogin.c +++ /dev/null @@ -1,956 +0,0 @@ -/* $OpenBSD: rlogin.c,v 1.30 2002/02/19 19:39:39 millert Exp $ */ -/* $NetBSD: rlogin.c,v 1.8 1995/10/05 09:07:22 mycroft Exp $ */ - -/* - * Copyright (c) 1983, 1990, 1993 - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)rlogin.c 8.1 (Berkeley) 6/6/93"; -#else -static char rcsid[] = "$OpenBSD: rlogin.c,v 1.30 2002/02/19 19:39:39 millert Exp $"; -#endif -#endif /* not lint */ - -/* - * rlogin - remote login - */ -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <sys/wait.h> - -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> - -#include <errno.h> -#include <fcntl.h> -#include <netdb.h> -#include <pwd.h> -#include <setjmp.h> -#include <termios.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> - -#ifdef KERBEROS -#include <des.h> -#include <kerberosIV/krb.h> - -CREDENTIALS cred; -des_key_schedule schedule; -int use_kerberos = 1, doencrypt; -char dst_realm_buf[REALM_SZ], *dest_realm = NULL; - -int des_read(int, char *, int); -int des_write(int, char *, int); - -int krcmd(char **, u_short, char *, char *, int *, char *); -int krcmd_mutual(char **, u_short, char *, char *, int *, char *, - CREDENTIALS *, Key_schedule); -#endif - -#ifndef TIOCPKT_WINDOW -#define TIOCPKT_WINDOW 0x80 -#endif - -/* concession to Sun */ -#ifndef SIGUSR1 -#define SIGUSR1 30 -#endif - -#ifndef CCEQ -#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0) -#endif - -int eight, rem; -struct termios deftty; - -int noescape; -u_char escapechar = '~'; - -#ifdef OLDSUN -struct winsize { - unsigned short ws_row, ws_col; - unsigned short ws_xpixel, ws_ypixel; -}; -#else -#define get_window_size(fd, wp) ioctl(fd, TIOCGWINSZ, wp) -#endif -struct winsize winsize; - -void catch_child(int); -void copytochild(int); -__dead void doit(sigset_t *); -__dead void done(int); -__dead void sig_done(int); -void echo(char); -u_int getescape(char *); -void lostpeer(int); -void mode(int); -void msg(char *); -void oob(int); -int reader(sigset_t *); -void sendwindow(void); -void setsignal(int); -void sigwinch(int); -void stop(int); -__dead void usage(void) __attribute__((__noreturn__)); -void writer(void); -void writeroob(int); - -#ifdef KERBEROS -void warning(const char *, ...); -void desrw_set_key(des_cblock *, des_key_schedule *); -#endif -#ifdef OLDSUN -int get_window_size(int, struct winsize *); -#endif - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - extern int optind; - struct passwd *pw; - struct servent *sp; - struct termios tty; - sigset_t mask, omask; - int argoff, ch, dflag, one, uid; - char *host, *p, *user, term[64]; - struct sockaddr_storage ss; - socklen_t sslen; - - argoff = dflag = 0; - one = 1; - host = user = NULL; - - if ((p = strrchr(argv[0], '/'))) - ++p; - else - p = argv[0]; - - if (strcmp(p, "rlogin")) - host = p; - - /* handle "rlogin host flags" */ - if (!host && argc > 2 && argv[1][0] != '-') { - host = argv[1]; - argoff = 1; - } - -#ifdef KERBEROS -#define OPTIONS "8EKLde:k:l:x" -#else -#define OPTIONS "8EKLde:l:" -#endif - while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != -1) - switch(ch) { - case '8': - eight = 1; - break; - case 'E': - noescape = 1; - break; - case 'K': -#ifdef KERBEROS - use_kerberos = 0; -#endif - break; - case 'd': - dflag = 1; - break; - case 'e': - noescape = 0; - escapechar = getescape(optarg); - break; -#ifdef KERBEROS - case 'k': - (void)strlcpy(dst_realm_buf, optarg, - sizeof(dst_realm_buf)); - dest_realm = dst_realm_buf; - break; -#endif - case 'l': - user = optarg; - break; -#ifdef KERBEROS - case 'x': - doencrypt = 1; - desrw_set_key(&cred.session, &schedule); - break; -#endif - case '?': - default: - usage(); - } - optind += argoff; - argc -= optind; - argv += optind; - - /* if haven't gotten a host yet, do so */ - if (!host && !(host = *argv++)) - usage(); - - if (*argv) - usage(); - - if (!(pw = getpwuid(uid = getuid()))) { - (void)fprintf(stderr, "rlogin: unknown user id.\n"); - exit(1); - } - if (!user) - user = pw->pw_name; - - sp = NULL; -#ifdef KERBEROS - if (use_kerberos) { - sp = getservbyname((doencrypt ? "eklogin" : "klogin"), "tcp"); - if (sp == NULL) { - use_kerberos = 0; - warning("can't get entry for %s/tcp service", - doencrypt ? "eklogin" : "klogin"); - } - } -#endif - if (sp == NULL) - sp = getservbyname("login", "tcp"); - if (sp == NULL) { - (void)fprintf(stderr, "rlogin: login/tcp: unknown service.\n"); - exit(1); - } - - (void)strlcpy(term, (p = getenv("TERM")) ? p : "network", - sizeof(term)); - - /* - * Add "/baud" only if there is room left; ie. do not send "/19" - * for 19200 baud with a particularily long $TERM - */ - if (tcgetattr(0, &tty) == 0) { - char baud[20]; /* more than enough.. */ - - (void)sprintf(baud, "/%d", cfgetospeed(&tty)); - if (strlen(term) + strlen(baud) < sizeof(term) - 1) - (void)strcat(term, baud); - } - - (void)get_window_size(0, &winsize); - - (void)signal(SIGPIPE, lostpeer); - /* will use SIGUSR1 for window size hack, so hold it off */ - sigemptyset(&mask); - sigaddset(&mask, SIGURG); - sigaddset(&mask, SIGUSR1); - sigprocmask(SIG_BLOCK, &mask, &omask); - /* - * We set SIGURG and SIGUSR1 below so that an - * incoming signal will be held pending rather than being - * discarded. Note that these routines will be ready to get - * a signal by the time that they are unblocked below. - */ - (void)signal(SIGURG, copytochild); - (void)signal(SIGUSR1, writeroob); - -#ifdef KERBEROS -try_connect: - if (use_kerberos) { - struct hostent *hp; - - /* Fully qualify hostname (needed for krb_realmofhost). */ - hp = gethostbyname(host); - if (hp != NULL && !(host = strdup(hp->h_name))) { - (void)fprintf(stderr, "rlogin: %s\n", - strerror(ENOMEM)); - exit(1); - } - - rem = KSUCCESS; - errno = 0; - if (dest_realm == NULL) - dest_realm = krb_realmofhost(host); - - if (doencrypt) - rem = krcmd_mutual(&host, sp->s_port, user, term, 0, - dest_realm, &cred, schedule); - else - rem = krcmd(&host, sp->s_port, user, term, 0, - dest_realm); - if (rem < 0) { - use_kerberos = 0; - sp = getservbyname("login", "tcp"); - if (sp == NULL) { - (void)fprintf(stderr, - "rlogin: unknown service login/tcp.\n"); - exit(1); - } - if (errno == ECONNREFUSED) - warning("remote host doesn't support Kerberos"); - if (errno == ENOENT) - warning("can't provide Kerberos auth data"); - goto try_connect; - } - } else { - if (doencrypt) { - (void)fprintf(stderr, - "rlogin: the -x flag requires Kerberos authentication.\n"); - exit(1); - } - rem = rcmd_af(&host, sp->s_port, pw->pw_name, user, term, 0, - PF_UNSPEC); - } -#else - rem = rcmd_af(&host, sp->s_port, pw->pw_name, user, term, 0, PF_UNSPEC); -#endif /* KERBEROS */ - - if (rem < 0) - exit(1); - - if (dflag && - setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, sizeof(one)) < 0) - (void)fprintf(stderr, "rlogin: setsockopt: %s.\n", - strerror(errno)); - - sslen = sizeof(ss); - if (getsockname(rem, (struct sockaddr *)&ss, &sslen) == 0 && - ss.ss_family == AF_INET) { - one = IPTOS_LOWDELAY; - if (setsockopt(rem, IPPROTO_IP, IP_TOS, (char *)&one, - sizeof(int)) < 0) - perror("rlogin: setsockopt TOS (ignored)"); - } - - (void)seteuid(uid); - (void)setuid(uid); - doit(&omask); - /*NOTREACHED*/ - - return 0; -} - -pid_t child; - -void -doit(omask) - sigset_t *omask; -{ - struct sigaction sa; - - (void)signal(SIGINT, SIG_IGN); - setsignal(SIGHUP); - setsignal(SIGQUIT); - mode(1); - child = fork(); - if (child == -1) { - (void)fprintf(stderr, "rlogin: fork: %s.\n", strerror(errno)); - done(1); - } - if (child == 0) { - (void)signal(SIGCHLD, SIG_DFL); - if (reader(omask) == 0) { - msg("connection closed."); - exit(0); - } - sleep(1); - - msg("\aconnection closed."); - exit(1); - } - - /* - * Use sigaction() instead of signal() to avoid getting SIGCHLDs - * for stopped children. - */ - memset(&sa, 0, sizeof sa); - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; - sa.sa_handler = catch_child; - (void)sigaction(SIGCHLD, &sa, NULL); - - /* - * We may still own the socket, and may have a pending SIGURG (or might - * receive one soon) that we really want to send to the reader. When - * one of these comes in, the trap copytochild simply copies such - * signals to the child. We can now unblock SIGURG and SIGUSR1 - * that were set above. - */ - (void)sigprocmask(SIG_SETMASK, omask, NULL); - writer(); - msg("closed connection."); - done(0); -} - -/* trap a signal, unless it is being ignored. */ -void -setsignal(sig) - int sig; -{ - sigset_t mask, omask; - - sigemptyset(&mask); - sigaddset(&mask, sig); - sigprocmask(SIG_BLOCK, &mask, &omask); - - if (signal(sig, exit) == SIG_IGN) - (void)signal(sig, SIG_IGN); - - sigprocmask(SIG_SETMASK, &omask, NULL); -} - -__dead void -done(status) - int status; -{ - int w, wstatus; - - mode(0); - if (child > 0) { - /* make sure catch_child does not snap it up */ - (void)signal(SIGCHLD, SIG_DFL); - if (kill(child, SIGKILL) >= 0) - while ((w = wait(&wstatus)) > 0 && w != child) - ; - } - exit(status); -} - -__dead void -sig_done(status) - int status; -{ - int w, wstatus; - - mode(0); - if (child > 0) { - /* make sure catch_child does not snap it up */ - (void)signal(SIGCHLD, SIG_DFL); - if (kill(child, SIGKILL) >= 0) - while ((w = wait(&wstatus)) > 0 && w != child) - ; - } - _exit(status); -} - -int dosigwinch; - -/* - * This is called when the reader process gets the out-of-band (urgent) - * request to turn on the window-changing protocol. - */ -void -writeroob(signo) - int signo; -{ - if (dosigwinch == 0) { - sendwindow(); - (void)signal(SIGWINCH, sigwinch); - } - dosigwinch = 1; -} - -void -catch_child(signo) - int signo; -{ - int save_errno = errno; - int status; - pid_t pid; - - for (;;) { - pid = wait3(&status, WNOHANG, NULL); - if (pid == 0) - break; - /* if the child (reader) dies, just quit */ - if (pid == child && !WIFSTOPPED(status)) { - child = -1; - if (WIFEXITED(status)) - sig_done(WEXITSTATUS(status)); - sig_done(WTERMSIG(status)); - } - } - errno = save_errno; -} - -/* - * writer: write to remote: 0 -> line. - * ~. terminate - * ~^Z suspend rlogin process. - * ~<delayed-suspend char> suspend rlogin process, but leave reader alone. - */ -void -writer() -{ - int bol, local, n; - char c; - - bol = 1; /* beginning of line */ - local = 0; - for (;;) { - n = read(STDIN_FILENO, &c, 1); - if (n <= 0) { - if (n < 0 && errno == EINTR) - continue; - break; - } - /* - * If we're at the beginning of the line and recognize a - * command character, then we echo locally. Otherwise, - * characters are echo'd remotely. If the command character - * is doubled, this acts as a force and local echo is - * suppressed. - */ - if (bol) { - bol = 0; - if (!noescape && c == escapechar) { - local = 1; - continue; - } - } else if (local) { - local = 0; - if (c == '.' || CCEQ(deftty.c_cc[VEOF], c)) { - echo(c); - break; - } - if (CCEQ(deftty.c_cc[VSUSP], c)) { - bol = 1; - echo(c); - stop(1); - continue; - } - if (CCEQ(deftty.c_cc[VDSUSP], c)) { - bol = 1; - echo(c); - stop(0); - continue; - } - if (c != escapechar) { -#ifdef KERBEROS - if (doencrypt) - (void)des_write(rem, - (char *)&escapechar, 1); - else -#endif - (void)write(rem, &escapechar, 1); - } - } - -#ifdef KERBEROS - if (doencrypt) { - if (des_write(rem, &c, 1) == 0) { - msg("line gone"); - break; - } - } else -#endif - if (write(rem, &c, 1) == 0) { - msg("line gone"); - break; - } - bol = CCEQ(deftty.c_cc[VKILL], c) || - CCEQ(deftty.c_cc[VEOF], c) || - CCEQ(deftty.c_cc[VINTR], c) || - CCEQ(deftty.c_cc[VSUSP], c) || - c == '\r' || c == '\n'; - } -} - -void -echo(char c) -{ - char *p; - char buf[8]; - - p = buf; - c &= 0177; - *p++ = escapechar; - if (c < ' ') { - *p++ = '^'; - *p++ = c + '@'; - } else if (c == 0177) { - *p++ = '^'; - *p++ = '?'; - } else - *p++ = c; - *p++ = '\r'; - *p++ = '\n'; - (void)write(STDOUT_FILENO, buf, p - buf); -} - -void -stop(all) - int all; -{ - mode(0); - (void)kill(all ? 0 : getpid(), SIGTSTP); - mode(1); - sigwinch(0); /* check for size changes */ -} - -void -sigwinch(signo) - int signo; -{ - struct winsize ws; - - if (dosigwinch && get_window_size(0, &ws) == 0 && - bcmp(&ws, &winsize, sizeof(ws))) { - winsize = ws; - sendwindow(); - } -} - -/* - * Send the window size to the server via the magic escape - */ -void -sendwindow() -{ - struct winsize *wp; - char obuf[4 + sizeof (struct winsize)]; - - wp = (struct winsize *)(obuf+4); - obuf[0] = 0377; - obuf[1] = 0377; - obuf[2] = 's'; - obuf[3] = 's'; - wp->ws_row = htons(winsize.ws_row); - wp->ws_col = htons(winsize.ws_col); - wp->ws_xpixel = htons(winsize.ws_xpixel); - wp->ws_ypixel = htons(winsize.ws_ypixel); - -#ifdef KERBEROS - if(doencrypt) - (void)des_write(rem, obuf, sizeof(obuf)); - else -#endif - (void)write(rem, obuf, sizeof(obuf)); -} - -/* - * reader: read from remote: line -> 1 - */ -#define READING 1 -#define WRITING 2 - -jmp_buf rcvtop; -pid_t ppid; -int rcvcnt, rcvstate; -char rcvbuf[8 * 1024]; - -void -oob(signo) - int signo; -{ - struct termios tty; - int atmark, n, rcvd; - int save_errno = errno; - char waste[BUFSIZ], mark; - - rcvd = 0; - while (recv(rem, &mark, 1, MSG_OOB) < 0) { - switch (errno) { - case EWOULDBLOCK: - /* - * Urgent data not here yet. It may not be possible - * to send it yet if we are blocked for output and - * our input buffer is full. - */ - if (rcvcnt < sizeof(rcvbuf)) { - n = read(rem, rcvbuf + rcvcnt, - sizeof(rcvbuf) - rcvcnt); - if (n <= 0) { - errno = save_errno; - return; - } - rcvd += n; - } else { - n = read(rem, waste, sizeof(waste)); - if (n <= 0) { - errno = save_errno; - return; - } - } - continue; - default: - errno = save_errno; - return; - } - } - if (mark & TIOCPKT_WINDOW && ppid > 1) { - /* Let server know about window size changes */ - (void)kill(ppid, SIGUSR1); - } - if (!eight && (mark & TIOCPKT_NOSTOP)) { - (void)tcgetattr(0, &tty); - tty.c_iflag &= ~IXON; - (void)tcsetattr(0, TCSANOW, &tty); - } - if (!eight && (mark & TIOCPKT_DOSTOP)) { - (void)tcgetattr(0, &tty); - tty.c_iflag |= (deftty.c_iflag & IXON); - (void)tcsetattr(0, TCSANOW, &tty); - } - if (mark & TIOCPKT_FLUSHWRITE) { - (void)tcflush(1, TCIOFLUSH); - for (;;) { - if (ioctl(rem, SIOCATMARK, &atmark) < 0) { - (void)fprintf(stderr, "rlogin: ioctl: %s.\n", - strerror(errno)); - break; - } - if (atmark) - break; - n = read(rem, waste, sizeof (waste)); - if (n <= 0) - break; - } - /* - * Don't want any pending data to be output, so clear the recv - * buffer. If we were hanging on a write when interrupted, - * don't want it to restart. If we were reading, restart - * anyway. - */ - rcvcnt = 0; - longjmp(rcvtop, 1); - } - - /* oob does not do FLUSHREAD (alas!) */ - - /* - * If we filled the receive buffer while a read was pending, longjmp - * to the top to restart appropriately. Don't abort a pending write, - * however, or we won't know how much was written. - */ - if (rcvd && rcvstate == READING) - longjmp(rcvtop, 1); - errno = save_errno; -} - -/* reader: read from remote: line -> 1 */ -int -reader(omask) - sigset_t *omask; -{ - pid_t pid; - int n, remaining; - char *bufp; - - pid = getpid(); /* modern systems use positives for pid */ - (void)signal(SIGTTOU, SIG_IGN); - (void)signal(SIGURG, oob); - ppid = getppid(); - (void)fcntl(rem, F_SETOWN, pid); - (void)setjmp(rcvtop); - (void)sigprocmask(SIG_SETMASK, omask, NULL); - bufp = rcvbuf; - for (;;) { - while ((remaining = rcvcnt - (bufp - rcvbuf)) > 0) { - rcvstate = WRITING; - n = write(STDOUT_FILENO, bufp, remaining); - if (n < 0) { - if (errno != EINTR) - return (-1); - continue; - } - bufp += n; - } - bufp = rcvbuf; - rcvcnt = 0; - rcvstate = READING; - -#ifdef KERBEROS - if (doencrypt) - rcvcnt = des_read(rem, rcvbuf, sizeof(rcvbuf)); - else -#endif - rcvcnt = read(rem, rcvbuf, sizeof (rcvbuf)); - if (rcvcnt == 0) - return (0); - if (rcvcnt < 0) { - if (errno == EINTR) - continue; - (void)fprintf(stderr, "rlogin: read: %s.\n", - strerror(errno)); - return (-1); - } - } -} - -void -mode(f) - int f; -{ - struct termios tty; - - switch (f) { - case 0: - (void)tcsetattr(0, TCSANOW, &deftty); - break; - case 1: - (void)tcgetattr(0, &deftty); - tty = deftty; - /* This is loosely derived from sys/compat/tty_compat.c. */ - tty.c_lflag &= ~(ECHO|ICANON|ISIG|IEXTEN); - tty.c_iflag &= ~ICRNL; - tty.c_oflag &= ~OPOST; - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 0; - if (eight) { - tty.c_iflag &= IXOFF; - tty.c_cflag &= ~(CSIZE|PARENB); - tty.c_cflag |= CS8; - } - (void)tcsetattr(0, TCSANOW, &tty); - break; - default: - return; - } -} - -void -lostpeer(signo) - int signo; -{ - (void)signal(SIGPIPE, SIG_IGN); - msg("\aconnection closed."); - done(1); -} - -/* copy SIGURGs to the child process. */ -void -copytochild(signo) - int signo; -{ - int save_errno = errno; - (void)kill(child, SIGURG); - errno = save_errno; -} - -void -msg(str) - char *str; -{ - (void)fprintf(stderr, "rlogin: %s\r\n", str); -} - -#ifdef KERBEROS -/* VARARGS */ -void -warning(const char *fmt, ...) -{ - char myrealm[REALM_SZ]; - va_list ap; - - if (krb_get_lrealm(myrealm, 0) != KSUCCESS) - return; - (void)fprintf(stderr, "rlogin: warning, using standard rlogin: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, ".\n"); -} -#endif - -__dead void -usage() -{ - (void)fprintf(stderr, - "usage: rlogin [ -%s]%s[-e char] [ -l username ] host\n", -#ifdef KERBEROS - "8EKLx", " [-k realm] "); -#else - "8EL", " "); -#endif - exit(1); -} - -/* - * The following routine provides compatibility (such as it is) between older - * Suns and others. Suns have only a `ttysize', so we convert it to a winsize. - */ -#ifdef OLDSUN -int -get_window_size(fd, wp) - int fd; - struct winsize *wp; -{ - struct ttysize ts; - int error; - - if ((error = ioctl(0, TIOCGSIZE, &ts)) != 0) - return (error); - wp->ws_row = ts.ts_lines; - wp->ws_col = ts.ts_cols; - wp->ws_xpixel = 0; - wp->ws_ypixel = 0; - return (0); -} -#endif - -u_int -getescape(p) - char *p; -{ - long val; - int len; - - if ((len = strlen(p)) == 1) /* use any single char, including '\' */ - return ((u_int)*p); - /* otherwise, \nnn */ - if (*p == '\\' && len >= 2 && len <= 4) { - val = strtol(++p, NULL, 8); - for (;;) { - if (!*++p) - return ((u_int)val); - if (*p < '0' || *p > '8') - break; - } - } - msg("illegal option value -- e"); - usage(); - /* NOTREACHED */ -} diff --git a/usr.bin/rsh/Makefile b/usr.bin/rsh/Makefile index 6a717e2ae2b..cf593094f1c 100644 --- a/usr.bin/rsh/Makefile +++ b/usr.bin/rsh/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2000/09/03 18:41:18 espie Exp $ +# $OpenBSD: Makefile,v 1.6 2002/05/06 22:23:53 deraadt Exp $ PROG= rsh SRCS= rsh.c @@ -9,7 +9,6 @@ BINMODE=4555 .if (${KERBEROS:L} == "yes") SRCS+= des_rw.c -.PATH: ${.CURDIR}/../rlogin CFLAGS+=-DKERBEROS SRCS+= krcmd.c kcmd.c LDADD+= -lkrb -ldes diff --git a/usr.bin/rlogin/des_rw.c b/usr.bin/rsh/des_rw.c index aec04db7ec2..46f9e508fb7 100644 --- a/usr.bin/rlogin/des_rw.c +++ b/usr.bin/rsh/des_rw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: des_rw.c,v 1.10 2002/02/16 21:27:51 millert Exp $ */ +/* $OpenBSD: des_rw.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $ */ /* $NetBSD: des_rw.c,v 1.2 1995/03/21 07:58:30 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)des_rw.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: des_rw.c,v 1.10 2002/02/16 21:27:51 millert Exp $"; +static char rcsid[] = "$OpenBSD: des_rw.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $"; #endif #endif /* not lint */ diff --git a/usr.bin/rlogin/kcmd.c b/usr.bin/rsh/kcmd.c index aa12550961d..69e510dd2aa 100644 --- a/usr.bin/rlogin/kcmd.c +++ b/usr.bin/rsh/kcmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kcmd.c,v 1.15 2002/02/17 19:42:31 millert Exp $ */ +/* $OpenBSD: kcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $ */ /* $NetBSD: kcmd.c,v 1.2 1995/03/21 07:58:32 cgd Exp $ */ /* @@ -39,7 +39,7 @@ static char Xsccsid[] = "derived from @(#)rcmd.c 5.17 (Berkeley) 6/27/88"; static char sccsid[] = "@(#)kcmd.c 8.2 (Berkeley) 8/19/93"; #else -static char rcsid[] = "$OpenBSD: kcmd.c,v 1.15 2002/02/17 19:42:31 millert Exp $"; +static char rcsid[] = "$OpenBSD: kcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $"; #endif #endif /* not lint */ diff --git a/usr.bin/rlogin/krcmd.c b/usr.bin/rsh/krcmd.c index a50cf3584c0..ac118546bb9 100644 --- a/usr.bin/rlogin/krcmd.c +++ b/usr.bin/rsh/krcmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: krcmd.c,v 1.10 2002/02/17 19:42:31 millert Exp $ */ +/* $OpenBSD: krcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $ */ /* $NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)krcmd.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: krcmd.c,v 1.10 2002/02/17 19:42:31 millert Exp $"; +static char rcsid[] = "$OpenBSD: krcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $"; #endif #endif /* not lint */ |