merge lite2 changes.
This commit is contained in:
parent
2242daf790
commit
2d7faefcd4
@ -1,10 +1,14 @@
|
||||
# $NetBSD: Makefile,v 1.3 1997/01/09 20:21:13 tls Exp $
|
||||
# from: @(#)Makefile 5.6 (Berkeley) 9/27/90
|
||||
# $NetBSD: Makefile,v 1.4 1997/02/16 15:01:02 mrg Exp $
|
||||
# from: @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
|
||||
PROG= rsh
|
||||
SRCS= rsh.c
|
||||
#CFLAGS+=-DKERBEROS -DCRYPT
|
||||
#SRCS= rsh.c krcmd.c kcmd.c des_rw.c
|
||||
#DPADD= ${LIBKRB} ${LIBDES}
|
||||
#LDADD= -lkrb -ldes
|
||||
BINOWN= root
|
||||
BINMODE=4555
|
||||
#INSTALLFLAGS=-fschg
|
||||
.PATH: ${.CURDIR}/../rlogin
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* $NetBSD: pathnames.h,v 1.3 1997/01/09 20:21:14 tls Exp $ */
|
||||
/* $NetBSD: pathnames.h,v 1.4 1997/02/16 15:01:03 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1989, 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
|
||||
@ -32,8 +32,8 @@
|
||||
* 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
|
||||
* $NetBSD: pathnames.h,v 1.3 1997/01/09 20:21:14 tls Exp $
|
||||
* from: @(#)pathnames.h 8.1 (Berkeley) 6/6/93
|
||||
* $NetBSD: pathnames.h,v 1.4 1997/02/16 15:01:03 mrg Exp $
|
||||
*/
|
||||
|
||||
#define _PATH_RLOGIN "/usr/bin/rlogin"
|
||||
|
@ -1,7 +1,7 @@
|
||||
.\" $NetBSD: rsh.1,v 1.3 1997/01/09 20:21:14 tls Exp $
|
||||
.\" $NetBSD: rsh.1,v 1.4 1997/02/16 15:01:04 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" 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
|
||||
@ -31,10 +31,10 @@
|
||||
.\" 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
|
||||
.\" $NetBSD: rsh.1,v 1.3 1997/01/09 20:21:14 tls Exp $
|
||||
.\" from: @(#)rsh.1 8.2 (Berkeley) 4/29/95
|
||||
.\" $NetBSD: rsh.1,v 1.4 1997/02/16 15:01:04 mrg Exp $
|
||||
.\"
|
||||
.Dd July 24, 1991
|
||||
.Dd April 29, 1995
|
||||
.Dt RSH 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@ -47,6 +47,11 @@
|
||||
.Op Fl l Ar username
|
||||
.Ar host
|
||||
.Op command
|
||||
.\" .Nm rsh
|
||||
.\" .Op Fl Kdnx
|
||||
.\" .Op Fl k Ar realm
|
||||
.\" .Ar username@host
|
||||
.\" .Op command
|
||||
.Sh DESCRIPTION
|
||||
.Nm Rsh
|
||||
executes
|
||||
@ -89,7 +94,11 @@ instead of the remote host's realm as determined by
|
||||
By default, the remote username is the same as the local username.
|
||||
The
|
||||
.Fl l
|
||||
option allows the remote name to be specified.
|
||||
option
|
||||
.\" or the
|
||||
.\" .Pa username@host
|
||||
.\" format allow
|
||||
allows the remote name to be specified.
|
||||
Kerberos authentication is used, and authorization is determined
|
||||
as in
|
||||
.Xr rlogin 1 .
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* $NetBSD: rsh.c,v 1.4 1997/01/09 20:21:15 tls Exp $ */
|
||||
/* $NetBSD: rsh.c,v 1.5 1997/02/16 15:01:05 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1983, 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1990, 1993, 1994
|
||||
* 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
|
||||
@ -34,21 +34,16 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1990 The Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1990, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)rsh.c 5.24 (Berkeley) 7/1/91";*/
|
||||
static char rcsid[] = "$NetBSD: rsh.c,v 1.4 1997/01/09 20:21:15 tls Exp $";
|
||||
/*static char sccsid[] = "from: @(#)rsh.c 8.4 (Berkeley) 4/29/95";*/
|
||||
static char rcsid[] = "$NetBSD: rsh.c,v 1.5 1997/02/16 15:01:05 mrg Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* $Source: /cvsroot/src/usr.bin/rsh/rsh.c,v $
|
||||
* $Header: /cvsroot/src/usr.bin/rsh/rsh.c,v 1.4 1997/01/09 20:21:15 tls Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -57,12 +52,16 @@ static char rcsid[] = "$NetBSD: rsh.c,v 1.4 1997/01/09 20:21:15 tls Exp $";
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <varargs.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
|
||||
#ifdef KERBEROS
|
||||
@ -79,29 +78,33 @@ extern char *krb_realmofhost();
|
||||
/*
|
||||
* rsh - remote shell
|
||||
*/
|
||||
extern int errno;
|
||||
int rfd2;
|
||||
int rfd2;
|
||||
|
||||
char *copyargs __P((char **));
|
||||
void sendsig __P((int));
|
||||
void talk __P((int, long, pid_t, int));
|
||||
void usage __P((void));
|
||||
void warning __P(());
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
struct passwd *pw;
|
||||
struct servent *sp;
|
||||
long omask;
|
||||
int argoff, asrsh, ch, dflag, nflag, one, pid, rem, uid;
|
||||
register char *p;
|
||||
char *args, *host, *user, *copyargs();
|
||||
void sendsig();
|
||||
int argoff, asrsh, ch, dflag, nflag, one, rem;
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
char *args, *host, *p, *user;
|
||||
|
||||
argoff = asrsh = dflag = nflag = 0;
|
||||
one = 1;
|
||||
host = user = NULL;
|
||||
|
||||
/* if called as something other than "rsh", use it as the host name */
|
||||
if (p = rindex(argv[0], '/'))
|
||||
if (p = strrchr(argv[0], '/'))
|
||||
++p;
|
||||
else
|
||||
p = argv[0];
|
||||
@ -175,16 +178,23 @@ main(argc, argv)
|
||||
if (asrsh)
|
||||
*argv = "rlogin";
|
||||
execv(_PATH_RLOGIN, argv);
|
||||
(void)fprintf(stderr, "rsh: can't exec %s.\n", _PATH_RLOGIN);
|
||||
exit(1);
|
||||
err(1, "can't exec %s", _PATH_RLOGIN);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (!(pw = getpwuid(uid = getuid()))) {
|
||||
(void)fprintf(stderr, "rsh: unknown user id.\n");
|
||||
exit(1);
|
||||
if (!(pw = getpwuid(uid = getuid())))
|
||||
errx(1, "unknown user id");
|
||||
/* Accept user1@host format, though "-l user2" overrides user1 */
|
||||
p = strchr(host, '@');
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
if (!user && p > host)
|
||||
user = host;
|
||||
host = p + 1;
|
||||
if (*host == '\0')
|
||||
usage();
|
||||
}
|
||||
if (!user)
|
||||
user = pw->pw_name;
|
||||
@ -212,14 +222,19 @@ main(argc, argv)
|
||||
#endif
|
||||
if (sp == NULL)
|
||||
sp = getservbyname("shell", "tcp");
|
||||
if (sp == NULL) {
|
||||
(void)fprintf(stderr, "rsh: shell/tcp: unknown service.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (sp == NULL)
|
||||
errx(1, "shell/tcp: unknown service");
|
||||
|
||||
#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)))
|
||||
err(1, NULL);
|
||||
|
||||
rem = KSUCCESS;
|
||||
errno = 0;
|
||||
if (dest_realm == NULL)
|
||||
@ -236,11 +251,8 @@ try_connect:
|
||||
if (rem < 0) {
|
||||
use_kerberos = 0;
|
||||
sp = getservbyname("shell", "tcp");
|
||||
if (sp == NULL) {
|
||||
(void)fprintf(stderr,
|
||||
"rsh: unknown service shell/tcp.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (sp == NULL)
|
||||
errx(1, "shell/tcp: unknown service");
|
||||
if (errno == ECONNREFUSED)
|
||||
warning("remote host doesn't support Kerberos");
|
||||
if (errno == ENOENT)
|
||||
@ -248,11 +260,8 @@ try_connect:
|
||||
goto try_connect;
|
||||
}
|
||||
} else {
|
||||
if (doencrypt) {
|
||||
(void)fprintf(stderr,
|
||||
"rsh: the -x flag requires Kerberos authentication.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (doencrypt)
|
||||
errx(1, "the -x flag requires Kerberos authentication");
|
||||
rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
|
||||
}
|
||||
#else
|
||||
@ -262,19 +271,15 @@ try_connect:
|
||||
if (rem < 0)
|
||||
exit(1);
|
||||
|
||||
if (rfd2 < 0) {
|
||||
(void)fprintf(stderr, "rsh: can't establish stderr.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (rfd2 < 0)
|
||||
errx(1, "can't establish stderr");
|
||||
if (dflag) {
|
||||
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one,
|
||||
sizeof(one)) < 0)
|
||||
(void)fprintf(stderr, "rsh: setsockopt: %s.\n",
|
||||
strerror(errno));
|
||||
warn("setsockopt");
|
||||
if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, &one,
|
||||
sizeof(one)) < 0)
|
||||
(void)fprintf(stderr, "rsh: setsockopt: %s.\n",
|
||||
strerror(errno));
|
||||
warn("setsockopt");
|
||||
}
|
||||
|
||||
(void)setuid(uid);
|
||||
@ -288,11 +293,8 @@ try_connect:
|
||||
|
||||
if (!nflag) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
(void)fprintf(stderr,
|
||||
"rsh: fork: %s.\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (pid < 0)
|
||||
err(1, "fork");
|
||||
}
|
||||
|
||||
#ifdef KERBEROS
|
||||
@ -312,15 +314,16 @@ try_connect:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
talk(nflag, omask, pid, rem)
|
||||
int nflag, pid;
|
||||
int nflag;
|
||||
long omask;
|
||||
register int rem;
|
||||
pid_t pid;
|
||||
int rem;
|
||||
{
|
||||
register int cc, wc;
|
||||
register char *bp;
|
||||
int readfrom, ready, rembits;
|
||||
char buf[BUFSIZ];
|
||||
int cc, wc;
|
||||
fd_set readfrom, ready, rembits;
|
||||
char *bp, buf[BUFSIZ];
|
||||
|
||||
if (!nflag && pid == 0) {
|
||||
(void)close(rfd2);
|
||||
@ -330,16 +333,15 @@ reread: errno = 0;
|
||||
goto done;
|
||||
bp = buf;
|
||||
|
||||
rewrite: rembits = 1 << rem;
|
||||
rewrite:
|
||||
FD_ZERO(&rembits);
|
||||
FD_SET(rem, &rembits);
|
||||
if (select(16, 0, &rembits, 0, 0) < 0) {
|
||||
if (errno != EINTR) {
|
||||
(void)fprintf(stderr,
|
||||
"rsh: select: %s.\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (errno != EINTR)
|
||||
err(1, "select");
|
||||
goto rewrite;
|
||||
}
|
||||
if ((rembits & (1 << rem)) == 0)
|
||||
if (!FD_ISSET(rem, &rembits))
|
||||
goto rewrite;
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
@ -365,18 +367,17 @@ done:
|
||||
}
|
||||
|
||||
(void)sigsetmask(omask);
|
||||
readfrom = (1 << rfd2) | (1 << rem);
|
||||
FD_ZERO(&readfrom);
|
||||
FD_SET(rfd2, &readfrom);
|
||||
FD_SET(rem, &readfrom);
|
||||
do {
|
||||
ready = readfrom;
|
||||
if (select(16, &ready, 0, 0, 0) < 0) {
|
||||
if (errno != EINTR) {
|
||||
(void)fprintf(stderr,
|
||||
"rsh: select: %s.\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (errno != EINTR)
|
||||
err(1, "select");
|
||||
continue;
|
||||
}
|
||||
if (ready & (1 << rfd2)) {
|
||||
if (FD_ISSET(rfd2, &ready)) {
|
||||
errno = 0;
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
@ -388,11 +389,11 @@ done:
|
||||
cc = read(rfd2, buf, sizeof buf);
|
||||
if (cc <= 0) {
|
||||
if (errno != EWOULDBLOCK)
|
||||
readfrom &= ~(1 << rfd2);
|
||||
FD_CLR(rfd2, &readfrom);
|
||||
} else
|
||||
(void)write(2, buf, cc);
|
||||
}
|
||||
if (ready & (1 << rem)) {
|
||||
if (FD_ISSET(rem, &ready)) {
|
||||
errno = 0;
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
@ -404,17 +405,20 @@ done:
|
||||
cc = read(rem, buf, sizeof buf);
|
||||
if (cc <= 0) {
|
||||
if (errno != EWOULDBLOCK)
|
||||
readfrom &= ~(1 << rem);
|
||||
FD_CLR(rem, &readfrom);
|
||||
} else
|
||||
(void)write(1, buf, cc);
|
||||
}
|
||||
} while (readfrom);
|
||||
} while (FD_ISSET(rfd2, &readfrom) || FD_ISSET(rem, &readfrom));
|
||||
}
|
||||
|
||||
void
|
||||
sendsig(signo)
|
||||
char signo;
|
||||
sendsig(sig)
|
||||
int sig;
|
||||
{
|
||||
char signo;
|
||||
|
||||
signo = sig;
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
if (doencrypt)
|
||||
@ -427,6 +431,7 @@ sendsig(signo)
|
||||
|
||||
#ifdef KERBEROS
|
||||
/* VARARGS */
|
||||
void
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
@ -446,30 +451,29 @@ char *
|
||||
copyargs(argv)
|
||||
char **argv;
|
||||
{
|
||||
register int cc;
|
||||
register char **ap, *p;
|
||||
char *args, *malloc();
|
||||
int cc;
|
||||
char **ap, *args, *p;
|
||||
|
||||
cc = 0;
|
||||
for (ap = argv; *ap; ++ap)
|
||||
cc += strlen(*ap) + 1;
|
||||
if (!(args = malloc((u_int)cc))) {
|
||||
(void)fprintf(stderr, "rsh: %s.\n", strerror(ENOMEM));
|
||||
exit(1);
|
||||
}
|
||||
if (!(args = malloc((u_int)cc)))
|
||||
err(1, NULL);
|
||||
for (p = args, ap = argv; *ap; ++ap) {
|
||||
(void)strcpy(p, *ap);
|
||||
for (p = strcpy(p, *ap); *p; ++p);
|
||||
if (ap[1])
|
||||
*p++ = ' ';
|
||||
}
|
||||
return(args);
|
||||
return (args);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: rsh [-nd%s]%s[-l login] host [command]\n",
|
||||
"usage: rsh [-nd%s]%s[-l login] [login@]host [command]\n",
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
"x", " [-k realm] ");
|
||||
|
Loading…
Reference in New Issue
Block a user