mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-06-07 14:31:23 +00:00
Initial commit of rsh utility
This commit is contained in:
parent
bb09eed7f6
commit
715fc5ab81
24
usr.bin/rsh/Makefile
Normal file
24
usr.bin/rsh/Makefile
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||||
|
# $Id: Makefile,v 1.1 1998/01/24 08:13:58 taubert Exp $
|
||||||
|
|
||||||
|
PROG= rsh
|
||||||
|
SRCS= rsh.c
|
||||||
|
LDADD= -lnetdb
|
||||||
|
OPTIMIZE=79
|
||||||
|
DEBUG= 25
|
||||||
|
|
||||||
|
#.if exists(${DESTDIR}/usr/lib/libkrb.a) && (defined(MAKE_KERBEROS) \
|
||||||
|
# || defined(MAKE_EBONES))
|
||||||
|
#CFLAGS+=-DKERBEROS -DCRYPT
|
||||||
|
#SRCS+= krcmd.c kcmd.c
|
||||||
|
#DPADD= ${LIBKRB} ${LIBDES}
|
||||||
|
#LDADD= -lkrb -ldes
|
||||||
|
#DISTRIBUTION= krb
|
||||||
|
#.endif
|
||||||
|
|
||||||
|
BINOWN= root
|
||||||
|
BINMODE=4555
|
||||||
|
INSTALLFLAGS=-fschg
|
||||||
|
#.PATH: ${.CURDIR}/../rlogin
|
||||||
|
|
||||||
|
.INCLUDE: /src/gno/prog.mk
|
36
usr.bin/rsh/pathnames.h
Normal file
36
usr.bin/rsh/pathnames.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _PATH_RLOGIN "/usr/bin/rlogin"
|
181
usr.bin/rsh/rsh.1
Normal file
181
usr.bin/rsh/rsh.1
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
.\" 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.
|
||||||
|
.\"
|
||||||
|
.\" @(#)rsh.1 8.1 (Berkeley) 6/6/93
|
||||||
|
.\"
|
||||||
|
.Dd June 6, 1993
|
||||||
|
.Dt RSH 1
|
||||||
|
.Os BSD 4.2
|
||||||
|
.Sh NAME
|
||||||
|
.Nm rsh
|
||||||
|
.Nd remote shell
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm rsh
|
||||||
|
.Op Fl Kdnx
|
||||||
|
.Op Fl k Ar realm
|
||||||
|
.Op Fl l Ar username
|
||||||
|
.Ar host
|
||||||
|
.Op command
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm Rsh
|
||||||
|
executes
|
||||||
|
.Ar command
|
||||||
|
on
|
||||||
|
.Ar host .
|
||||||
|
.Pp
|
||||||
|
.Nm Rsh
|
||||||
|
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 rsh
|
||||||
|
normally terminates when the remote command does.
|
||||||
|
The options are as follows:
|
||||||
|
.Bl -tag -width flag
|
||||||
|
.It Fl K
|
||||||
|
The
|
||||||
|
.Fl K
|
||||||
|
option turns off all Kerberos authentication.
|
||||||
|
.It Fl d
|
||||||
|
The
|
||||||
|
.Fl d
|
||||||
|
option turns on socket debugging (using
|
||||||
|
.Xr setsockopt 2 )
|
||||||
|
on the
|
||||||
|
.Tn TCP
|
||||||
|
sockets used for communication with the remote host.
|
||||||
|
.It Fl k
|
||||||
|
The
|
||||||
|
.Fl k
|
||||||
|
option causes
|
||||||
|
.Nm rsh
|
||||||
|
to obtain tickets for the remote host in
|
||||||
|
.Ar realm
|
||||||
|
instead of the remote host's realm as determined by
|
||||||
|
.Xr krb_realmofhost 3 .
|
||||||
|
.It Fl l
|
||||||
|
By default, the remote username is the same as the local username.
|
||||||
|
The
|
||||||
|
.Fl l
|
||||||
|
option allows the remote name to be specified.
|
||||||
|
Kerberos authentication is used, and authorization is determined
|
||||||
|
as in
|
||||||
|
.Xr rlogin 1 .
|
||||||
|
.It Fl n
|
||||||
|
The
|
||||||
|
.Fl n
|
||||||
|
option redirects input from the special device
|
||||||
|
.Pa /dev/null
|
||||||
|
(see the
|
||||||
|
.Sx BUGS
|
||||||
|
section of this manual page).
|
||||||
|
.It Fl x
|
||||||
|
The
|
||||||
|
.Fl x
|
||||||
|
option turns on
|
||||||
|
.Tn DES
|
||||||
|
encryption for all data exchange.
|
||||||
|
This may introduce a significant delay in response time.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
If no
|
||||||
|
.Ar command
|
||||||
|
is specified, you will be logged in on the remote host using
|
||||||
|
.Xr rlogin 1 .
|
||||||
|
.Pp
|
||||||
|
Shell metacharacters which are not quoted are interpreted on local machine,
|
||||||
|
while quoted metacharacters 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 rlogin 1 ,
|
||||||
|
.Xr kerberos 3 ,
|
||||||
|
.Xr krb_sendauth 3 ,
|
||||||
|
.Xr krb_realmofhost 3
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Nm rsh
|
||||||
|
command appeared in
|
||||||
|
.Bx 4.2 .
|
||||||
|
.Sh BUGS
|
||||||
|
If you are using
|
||||||
|
.Xr csh 1
|
||||||
|
and put a
|
||||||
|
.Nm rsh
|
||||||
|
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 rsh
|
||||||
|
to
|
||||||
|
.Pa /dev/null
|
||||||
|
using the
|
||||||
|
.Fl n
|
||||||
|
option.
|
||||||
|
.Pp
|
||||||
|
You cannot run an interactive command
|
||||||
|
(like
|
||||||
|
.Xr rogue 6
|
||||||
|
or
|
||||||
|
.Xr vi 1 )
|
||||||
|
using
|
||||||
|
.Nm rsh ;
|
||||||
|
use
|
||||||
|
.Xr rlogin 1
|
||||||
|
instead.
|
||||||
|
.Pp
|
||||||
|
Stop signals stop the local
|
||||||
|
.Nm rsh
|
||||||
|
process only; this is arguably wrong, but currently hard to fix for reasons
|
||||||
|
too complicated to explain here.
|
477
usr.bin/rsh/rsh.c
Normal file
477
usr.bin/rsh/rsh.c
Normal file
|
@ -0,0 +1,477 @@
|
||||||
|
/*-
|
||||||
|
* 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
|
||||||
|
* 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, 1994\n\
|
||||||
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char sccsid[] = "From: @(#)rsh.c 8.3 (Berkeley) 4/6/94";
|
||||||
|
static char rcsid[] =
|
||||||
|
"$Id: rsh.c,v 1.1 1998/01/24 08:14:02 taubert Exp $";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/signal.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "pathnames.h"
|
||||||
|
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#include <varargs.h>
|
||||||
|
#include <kerberosIV/des.h>
|
||||||
|
#include <kerberosIV/krb.h>
|
||||||
|
|
||||||
|
CREDENTIALS cred;
|
||||||
|
Key_schedule schedule;
|
||||||
|
int use_kerberos = 1, doencrypt;
|
||||||
|
char dst_realm_buf[REALM_SZ], *dest_realm;
|
||||||
|
extern char *krb_realmofhost();
|
||||||
|
|
||||||
|
void warning __P(());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rsh - remote shell
|
||||||
|
*/
|
||||||
|
int rfd2;
|
||||||
|
|
||||||
|
char *copyargs __P((char **));
|
||||||
|
void sendsig __P((int));
|
||||||
|
void talk __P((int, long, pid_t, int));
|
||||||
|
void usage __P((void));
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct passwd *pw;
|
||||||
|
struct servent *sp;
|
||||||
|
long omask;
|
||||||
|
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 = strrchr(argv[0], '/'))
|
||||||
|
++p;
|
||||||
|
else
|
||||||
|
p = argv[0];
|
||||||
|
|
||||||
|
if (strcmp(p, "rsh"))
|
||||||
|
host = p;
|
||||||
|
else
|
||||||
|
asrsh = 1;
|
||||||
|
|
||||||
|
/* handle "rsh host flags" */
|
||||||
|
if (!host && argc > 2 && argv[1][0] != '-') {
|
||||||
|
host = argv[1];
|
||||||
|
argoff = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
#define OPTIONS "8KLde:k:l:nwx"
|
||||||
|
#else
|
||||||
|
#define OPTIONS "8KLde:k:l:nw"
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define OPTIONS "8KLde:l:nw"
|
||||||
|
#endif
|
||||||
|
while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
|
||||||
|
switch(ch) {
|
||||||
|
case 'K':
|
||||||
|
#ifdef KERBEROS
|
||||||
|
use_kerberos = 0;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case 'L': /* -8Lew are ignored to allow rlogin aliases */
|
||||||
|
case 'e':
|
||||||
|
case 'w':
|
||||||
|
case '8':
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
dflag = 1;
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
user = optarg;
|
||||||
|
break;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
case 'k':
|
||||||
|
dest_realm = dst_realm_buf;
|
||||||
|
strncpy(dest_realm, optarg, REALM_SZ);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case 'n':
|
||||||
|
nflag = 1;
|
||||||
|
break;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
case 'x':
|
||||||
|
doencrypt = 1;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
case '?':
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
optind += argoff;
|
||||||
|
|
||||||
|
/* if haven't gotten a host yet, do so */
|
||||||
|
if (!host && !(host = argv[optind++]))
|
||||||
|
usage();
|
||||||
|
|
||||||
|
/* if no further arguments, must have been called as rlogin. */
|
||||||
|
if (!argv[optind]) {
|
||||||
|
if (asrsh)
|
||||||
|
*argv = "rlogin";
|
||||||
|
execv(_PATH_RLOGIN, argv);
|
||||||
|
err(1, "can't exec %s", _PATH_RLOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (!(pw = getpwuid(uid = getuid())))
|
||||||
|
errx(1, "unknown user id");
|
||||||
|
if (!user)
|
||||||
|
user = pw->pw_name;
|
||||||
|
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
/* -x turns off -n */
|
||||||
|
if (doencrypt)
|
||||||
|
nflag = 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
args = copyargs(argv);
|
||||||
|
|
||||||
|
sp = NULL;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
if (use_kerberos) {
|
||||||
|
sp = getservbyname((doencrypt ? "ekshell" : "kshell"), "tcp");
|
||||||
|
if (sp == NULL) {
|
||||||
|
use_kerberos = 0;
|
||||||
|
warning("can't get entry for %s/tcp service",
|
||||||
|
doencrypt ? "ekshell" : "kshell");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (sp == NULL)
|
||||||
|
sp = getservbyname("shell", "tcp");
|
||||||
|
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)
|
||||||
|
dest_realm = krb_realmofhost(host);
|
||||||
|
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (doencrypt) {
|
||||||
|
rem = krcmd_mutual(&host, sp->s_port, user, args,
|
||||||
|
&rfd2, dest_realm, &cred, schedule);
|
||||||
|
des_set_key(cred.session, schedule);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
rem = krcmd(&host, sp->s_port, user, args, &rfd2,
|
||||||
|
dest_realm);
|
||||||
|
if (rem < 0) {
|
||||||
|
use_kerberos = 0;
|
||||||
|
sp = getservbyname("shell", "tcp");
|
||||||
|
if (sp == NULL)
|
||||||
|
errx(1, "shell/tcp: unknown service");
|
||||||
|
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)
|
||||||
|
errx(1, "the -x flag requires Kerberos authentication");
|
||||||
|
rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (rem < 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
if (rfd2 < 0)
|
||||||
|
errx(1, "can't establish stderr");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)setuid(uid);
|
||||||
|
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGTERM));
|
||||||
|
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);
|
||||||
|
|
||||||
|
#ifdef __GNO__
|
||||||
|
nflag = 1;
|
||||||
|
#else
|
||||||
|
if (!nflag) {
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0)
|
||||||
|
err(1, "fork");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (!doencrypt)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
(void)ioctl(rfd2, FIONBIO, &one);
|
||||||
|
(void)ioctl(rem, FIONBIO, &one);
|
||||||
|
}
|
||||||
|
|
||||||
|
talk(nflag, omask, pid, rem);
|
||||||
|
|
||||||
|
if (!nflag)
|
||||||
|
(void)kill(pid, SIGKILL);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
talk(int nflag, long omask, pid_t pid, int rem)
|
||||||
|
{
|
||||||
|
int cc, wc;
|
||||||
|
fd_set readfrom, ready, rembits;
|
||||||
|
char *bp;
|
||||||
|
static 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;
|
||||||
|
|
||||||
|
rewrite:
|
||||||
|
FD_ZERO(&rembits);
|
||||||
|
FD_SET(rem, &rembits);
|
||||||
|
if (select(16, 0, &rembits, 0, 0) < 0) {
|
||||||
|
if (errno != EINTR)
|
||||||
|
err(1, "select");
|
||||||
|
goto rewrite;
|
||||||
|
}
|
||||||
|
if (!FD_ISSET(rem, &rembits))
|
||||||
|
goto rewrite;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (doencrypt)
|
||||||
|
wc = des_write(rem, bp, cc);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)sigsetmask(omask);
|
||||||
|
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)
|
||||||
|
err(1, "select");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(rfd2, &ready)) {
|
||||||
|
errno = 0;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (doencrypt)
|
||||||
|
cc = des_read(rfd2, buf, sizeof buf);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
cc = read(rfd2, buf, sizeof buf);
|
||||||
|
if (cc <= 0) {
|
||||||
|
if (errno != EWOULDBLOCK)
|
||||||
|
FD_CLR(rfd2, &readfrom);
|
||||||
|
} else
|
||||||
|
(void)write(STDERR_FILENO, buf, cc);
|
||||||
|
}
|
||||||
|
if (FD_ISSET(rem, &ready)) {
|
||||||
|
errno = 0;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (doencrypt)
|
||||||
|
cc = des_read(rem, buf, sizeof buf);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
cc = read(rem, buf, sizeof buf);
|
||||||
|
if (cc <= 0) {
|
||||||
|
if (errno != EWOULDBLOCK)
|
||||||
|
FD_CLR(rem, &readfrom);
|
||||||
|
} else
|
||||||
|
(void)write(STDOUT_FILENO, buf, cc);
|
||||||
|
}
|
||||||
|
} while (FD_ISSET(rfd2, &readfrom) || FD_ISSET(rem, &readfrom));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sendsig(int sig)
|
||||||
|
{
|
||||||
|
char signo;
|
||||||
|
|
||||||
|
signo = sig;
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
if (doencrypt)
|
||||||
|
(void)des_write(rfd2, &signo, 1);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
(void)write(rfd2, &signo, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef KERBEROS
|
||||||
|
/* VARARGS */
|
||||||
|
void
|
||||||
|
warning(va_alist)
|
||||||
|
va_dcl
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *fmt;
|
||||||
|
|
||||||
|
(void)fprintf(stderr, "rsh: warning, using standard rsh: ");
|
||||||
|
va_start(ap);
|
||||||
|
fmt = va_arg(ap, char *);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
(void)fprintf(stderr, ".\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *
|
||||||
|
copyargs(char **argv)
|
||||||
|
{
|
||||||
|
int cc;
|
||||||
|
char **ap, *args, *p;
|
||||||
|
|
||||||
|
cc = 0;
|
||||||
|
for (ap = argv; *ap; ++ap)
|
||||||
|
cc += strlen(*ap) + 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
(void)fprintf(stderr,
|
||||||
|
"usage: rsh [-nd%s]%s[-l login] host [command]\n",
|
||||||
|
#ifdef KERBEROS
|
||||||
|
#ifdef CRYPT
|
||||||
|
"x", " [-k realm] ");
|
||||||
|
#else
|
||||||
|
"", " [-k realm] ");
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
"", " ");
|
||||||
|
#endif
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
9
usr.bin/rsh/rsh.desc
Normal file
9
usr.bin/rsh/rsh.desc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Name: rsh
|
||||||
|
Version: 1.0 (November 1997)
|
||||||
|
Shell: GNO & GS/TCP
|
||||||
|
Author: Derek Taubert (from FreeBSD 2.1.0 code)
|
||||||
|
Contact: taubert@geeks.org
|
||||||
|
Where: /usr/bin
|
||||||
|
FTP: ground.isca.uiowa.edu apple2.caltech.edu trenco.myrias.com
|
||||||
|
|
||||||
|
Remote shell.
|
31
usr.bin/rsh/rsh.rez
Normal file
31
usr.bin/rsh/rsh.rez
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Resources for rsh version and comment
|
||||||
|
*
|
||||||
|
* $Id: rsh.rez,v 1.1 1998/01/24 08:14:04 taubert Exp $
|
||||||
|
*/
|
||||||
|
#define PROG "rsh"
|
||||||
|
#define DESC "Remote shell."
|
||||||
|
|
||||||
|
#include "Types.rez"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Version
|
||||||
|
*/
|
||||||
|
resource rVersion (1, purgeable3) {
|
||||||
|
{ 1, 0, 0, /* Version 1.0.0 */
|
||||||
|
release, /* development|alpha|beta|final|release */
|
||||||
|
0 }, /* non-final release number */
|
||||||
|
verUS, /* Country */
|
||||||
|
PROG, /* Program name */
|
||||||
|
DESC " Released with GNO/ME and GS/TCP."
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Comment
|
||||||
|
*/
|
||||||
|
resource rComment (1, purgeable3) {
|
||||||
|
PROG " v1.0 (November 1997)\n"
|
||||||
|
"GNO utility: " DESC "\n"
|
||||||
|
"Ported from FreeBSD 2.1.0 code by Derek Taubert."
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user