clean up import.

This commit is contained in:
cgd 1995-03-21 07:58:28 +00:00
parent 0e535da105
commit af7bf810f5
7 changed files with 194 additions and 92 deletions

View File

@ -1,9 +1,14 @@
# from: @(#)Makefile 5.6 (Berkeley) 9/27/90
# $Id: Makefile,v 1.4 1993/07/30 23:51:28 mycroft Exp $
# $NetBSD: Makefile,v 1.5 1995/03/21 07:58:28 cgd Exp $
# @(#)Makefile 8.1 (Berkeley) 7/19/93
PROG= rlogin
SRCS= rlogin.c
#SRCS+= krcmd.c kcmd.c des_rw.c
#DPADD= ${LIBKRB} ${LIBDES}
#CFLAGS+=-DKERBEROS -DCRYPT
#LDADD= -lkrb -ldes
BINOWN= root
BINMODE=4555
#INSTALLFLAGS=-fschg
.include <bsd.prog.mk>

View File

@ -1,3 +1,5 @@
/* $NetBSD: des_rw.c,v 1.2 1995/03/21 07:58:30 cgd Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@ -32,7 +34,11 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)des_rw.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: des_rw.c,v 1.2 1995/03/21 07:58:30 cgd Exp $";
#endif
#endif /* not lint */
#ifdef CRYPT

View File

@ -1,3 +1,5 @@
/* $NetBSD: kcmd.c,v 1.2 1995/03/21 07:58:32 cgd Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -32,8 +34,12 @@
*/
#ifndef lint
#if 0
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[] = "$NetBSD: kcmd.c,v 1.2 1995/03/21 07:58:32 cgd Exp $";
#endif
#endif /* not lint */
#include <sys/param.h>

View File

@ -1,3 +1,5 @@
/* $NetBSD: krb.h,v 1.2 1995/03/21 07:58:34 cgd Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.

View File

@ -1,3 +1,5 @@
/* $NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@ -32,16 +34,20 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)krcmd.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $";
#endif
#endif /* not lint */
/*
* $Source: /cvsroot/src/usr.bin/rlogin/Attic/krcmd.c,v $
* $Source: /a/cvsroot/src/usr.bin/rlogin/krcmd.c,v
* $Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1
* 89/07/25 15:38:44 kfall Exp Locker: kfall $
* 89/07/25 15:38:44 kfall Exp Locker: kfall
* static char *rcsid_kcmd_c =
* "$Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1 89/07/25 15:38:44
* kfall Exp Locker: kfall $";
* kfall Exp Locker: kfall ";
*/
#ifdef KERBEROS

View File

@ -1,5 +1,7 @@
.\" Copyright (c) 1983, 1990 The Regents of the University of California.
.\" All rights reserved.
.\" $NetBSD: rlogin.1,v 1.3 1995/03/21 07:58:37 cgd 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
@ -29,10 +31,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)rlogin.1 6.19 (Berkeley) 7/27/91
.\" $Id: rlogin.1,v 1.2 1993/08/01 07:29:28 mycroft Exp $
.\" @(#)rlogin.1 8.1 (Berkeley) 6/6/93
.\"
.Dd July 27, 1991
.Dd June 6, 1993
.Dt RLOGIN 1
.Os BSD 4.2
.Sh NAME

View File

@ -1,6 +1,8 @@
/* $NetBSD: rlogin.c,v 1.4 1995/03/21 07:58:38 cgd 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
@ -32,29 +34,24 @@
*/
#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\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)rlogin.c 5.33 (Berkeley) 3/1/91";*/
static char rcsid[] = "$Id: rlogin.c,v 1.3 1993/09/05 19:05:01 deraadt Exp $";
#if 0
static char sccsid[] = "@(#)rlogin.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: rlogin.c,v 1.4 1995/03/21 07:58:38 cgd Exp $";
#endif
#endif /* not lint */
/*
* $Source: /cvsroot/src/usr.bin/rlogin/rlogin.c,v $
* $Header: mit/rlogin/RCS/rlogin.c,v 5.2 89/07/26 12:11:21 kfall
* Exp Locker: kfall $
*/
/*
* rlogin - remote login
*/
#include <sys/param.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
@ -62,26 +59,35 @@ static char rcsid[] = "$Id: rlogin.c,v 1.3 1993/09/05 19:05:01 deraadt Exp $";
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netdb.h>
#include <sgtty.h>
#include <setjmp.h>
#include <varargs.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <pwd.h>
#include <setjmp.h>
#include <sgtty.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#ifdef KERBEROS
#include <kerberosIV/des.h>
#include <kerberosIV/krb.h>
#include "krb.h"
CREDENTIALS cred;
Key_schedule schedule;
int use_kerberos = 1, doencrypt;
char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
extern char *krb_realmofhost();
#endif
#ifndef TIOCPKT_WINDOW
@ -93,7 +99,6 @@ extern char *krb_realmofhost();
#define SIGUSR1 30
#endif
extern int errno;
int eight, litout, rem;
int noescape;
@ -104,23 +109,46 @@ char *speeds[] = {
"1800", "2400", "4800", "9600", "19200", "38400", "57600", "115200"
};
#ifdef sun
#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;
#ifndef sun
#define get_window_size(fd, wp) ioctl(fd, TIOCGWINSZ, wp)
void catch_child __P((int));
void copytochild __P((int));
__dead void doit __P((long));
__dead void done __P((int));
void echo __P((char));
u_int getescape __P((char *));
void lostpeer __P((int));
void mode __P((int));
void msg __P((char *));
void oob __P((int));
int reader __P((int));
void sendwindow __P((void));
void setsignal __P((int));
void sigwinch __P((int));
void stop __P((char));
__dead void usage __P((void));
void writer __P((void));
void writeroob __P((int));
#ifdef KERBEROS
void warning __P((const char *, ...));
#endif
#ifdef OLDSUN
int get_window_size __P((int, struct winsize *));
#endif
void exit();
int
main(argc, argv)
int argc;
char **argv;
char *argv[];
{
extern char *optarg;
extern int optind;
@ -130,9 +158,6 @@ main(argc, argv)
long omask;
int argoff, ch, dflag, one, uid;
char *host, *p, *user, term[1024];
void lostpeer();
u_char getescape();
char *getenv();
argoff = dflag = 0;
one = 1;
@ -177,6 +202,7 @@ main(argc, argv)
dflag = 1;
break;
case 'e':
noescape = 0;
escapechar = getescape(optarg);
break;
#ifdef KERBEROS
@ -239,7 +265,7 @@ main(argc, argv)
(void)strcpy(term, (p = getenv("TERM")) ? p : "network");
if (ioctl(0, TIOCGETP, &ttyb) == 0) {
(void)strcat(term, "/");
(void)strcat(term, speeds[ttyb.sg_ospeed]);
(void)strcat(term, speeds[(int)ttyb.sg_ospeed]);
}
(void)get_window_size(0, &winsize);
@ -247,10 +273,28 @@ main(argc, argv)
(void)signal(SIGPIPE, lostpeer);
/* will use SIGUSR1 for window size hack, so hold it off */
omask = sigblock(sigmask(SIGURG) | sigmask(SIGUSR1));
/*
* 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)
@ -315,11 +359,11 @@ struct ltchars defltc;
struct tchars notc = { -1, -1, -1, -1, -1, -1 };
struct ltchars noltc = { -1, -1, -1, -1, -1, -1 };
void
doit(omask)
long omask;
{
struct sgttyb sb;
void catch_child(), copytochild(), exit(), writeroob();
(void)ioctl(0, TIOCGETP, (char *)&sb);
defflags = sb.sg_flags;
@ -327,14 +371,14 @@ doit(omask)
defflags &= ECHO | CRMOD;
deferase = sb.sg_erase;
defkill = sb.sg_kill;
(void)ioctl(0, TIOCLGET, (char *)&deflflags);
(void)ioctl(0, TIOCGETC, (char *)&deftc);
(void)ioctl(0, TIOCLGET, &deflflags);
(void)ioctl(0, TIOCGETC, &deftc);
notc.t_startc = deftc.t_startc;
notc.t_stopc = deftc.t_stopc;
(void)ioctl(0, TIOCGLTC, (char *)&defltc);
(void)ioctl(0, TIOCGLTC, &defltc);
(void)signal(SIGINT, SIG_IGN);
setsignal(SIGHUP, exit);
setsignal(SIGQUIT, exit);
setsignal(SIGHUP);
setsignal(SIGQUIT);
child = fork();
if (child == -1) {
(void)fprintf(stderr, "rlogin: fork: %s.\n", strerror(errno));
@ -353,11 +397,11 @@ doit(omask)
/*
* 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. Set a
* trap that simply copies such signals to the child.
* 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)signal(SIGURG, copytochild);
(void)signal(SIGUSR1, writeroob);
(void)sigsetmask(omask);
(void)signal(SIGCHLD, catch_child);
writer();
@ -366,17 +410,18 @@ doit(omask)
}
/* trap a signal, unless it is being ignored. */
setsignal(sig, act)
void
setsignal(sig)
int sig;
void (*act)();
{
int omask = sigblock(sigmask(sig));
if (signal(sig, act) == SIG_IGN)
if (signal(sig, exit) == SIG_IGN)
(void)signal(sig, SIG_IGN);
(void)sigsetmask(omask);
}
__dead void
done(status)
int status;
{
@ -393,14 +438,14 @@ done(status)
}
int dosigwinch;
void sigwinch();
/*
* This is called when the reader process gets the out-of-band (urgent)
* request to turn on the window-changing protocol.
*/
void
writeroob()
writeroob(signo)
int signo;
{
if (dosigwinch == 0) {
sendwindow();
@ -410,18 +455,18 @@ writeroob()
}
void
catch_child()
catch_child(signo)
int signo;
{
union wait status;
int pid;
for (;;) {
pid = wait3((int *)&status,
WNOHANG|WUNTRACED, (struct rusage *)0);
pid = wait3((int *)&status, WNOHANG|WUNTRACED, NULL);
if (pid == 0)
return;
/* if the child (reader) dies, just quit */
if (pid < 0 || pid == child && !WIFSTOPPED(status))
if (pid < 0 || (pid == child && !WIFSTOPPED(status)))
done((int)(status.w_termsig | status.w_retcode));
}
/* NOTREACHED */
@ -433,6 +478,7 @@ catch_child()
* ~^Z suspend rlogin process.
* ~<delayed-suspend char> suspend rlogin process, but leave reader alone.
*/
void
writer()
{
register int bol, local, n;
@ -476,7 +522,8 @@ writer()
#ifdef CRYPT
#ifdef KERBEROS
if (doencrypt)
(void)des_write(rem, &escapechar, 1);
(void)des_write(rem,
(char *)&escapechar, 1);
else
#endif
#endif
@ -503,8 +550,13 @@ writer()
}
}
void
#if __STDC__
echo(register char c)
#else
echo(c)
register char c;
register char c;
#endif
{
register char *p;
char buf[8];
@ -525,19 +577,25 @@ register char c;
(void)write(STDOUT_FILENO, buf, p - buf);
}
void
#if __STDC__
stop(char cmdc)
#else
stop(cmdc)
char cmdc;
#endif
{
mode(0);
(void)signal(SIGCHLD, SIG_IGN);
(void)kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP);
(void)signal(SIGCHLD, catch_child);
mode(1);
sigwinch(); /* check for size changes */
sigwinch(0); /* check for size changes */
}
void
sigwinch()
sigwinch(signo)
int signo;
{
struct winsize ws;
@ -551,6 +609,7 @@ sigwinch()
/*
* Send the window size to the server via the magic escape
*/
void
sendwindow()
{
struct winsize *wp;
@ -587,7 +646,8 @@ int ppid, rcvcnt, rcvstate;
char rcvbuf[8 * 1024];
void
oob()
oob(signo)
int signo;
{
struct sgttyb sb;
int atmark, n, out, rcvd;
@ -595,7 +655,7 @@ oob()
out = O_RDWR;
rcvd = 0;
while (recv(rem, &mark, 1, MSG_OOB) < 0)
while (recv(rem, &mark, 1, MSG_OOB) < 0) {
switch (errno) {
case EWOULDBLOCK:
/*
@ -618,6 +678,7 @@ oob()
default:
return;
}
}
if (mark & TIOCPKT_WINDOW) {
/* Let server know about window size changes */
(void)kill(ppid, SIGUSR1);
@ -676,32 +737,32 @@ oob()
}
/* reader: read from remote: line -> 1 */
int
reader(omask)
int omask;
{
void oob();
int pid, n, remaining;
char *bufp;
#if !defined(BSD) || BSD < 43
int pid = -getpid();
#if BSD >= 43 || defined(SUNOS4)
pid = getpid(); /* modern systems use positives for pid */
#else
int pid = getpid();
pid = -getpid(); /* old broken systems use negatives */
#endif
int n, remaining;
char *bufp = rcvbuf;
(void)signal(SIGTTOU, SIG_IGN);
(void)signal(SIGURG, oob);
ppid = getppid();
(void)fcntl(rem, F_SETOWN, pid);
(void)setjmp(rcvtop);
(void)sigsetmask(omask);
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);
return (-1);
continue;
}
bufp += n;
@ -725,12 +786,14 @@ reader(omask)
continue;
(void)fprintf(stderr, "rlogin: read: %s.\n",
strerror(errno));
return(-1);
return (-1);
}
}
}
void
mode(f)
int f;
{
struct ltchars *ltc;
struct sgttyb sb;
@ -771,7 +834,8 @@ mode(f)
}
void
lostpeer()
lostpeer(signo)
int signo;
{
(void)signal(SIGPIPE, SIG_IGN);
msg("\007connection closed.");
@ -780,11 +844,13 @@ lostpeer()
/* copy SIGURGs to the child process. */
void
copytochild()
copytochild(signo)
int signo;
{
(void)kill(child, SIGURG);
}
void
msg(str)
char *str;
{
@ -793,30 +859,39 @@ msg(str)
#ifdef KERBEROS
/* VARARGS */
warning(va_alist)
va_dcl
void
#if __STDC__
warning(const char *fmt, ...)
#else
warning(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
char *fmt;
(void)fprintf(stderr, "rlogin: warning, using standard rlogin: ");
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
fmt = va_arg(ap, char *);
#endif
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
#ifdef CRYPT
"8ELx", " [-k realm] ");
"8EKLx", " [-k realm] ");
#else
"8EL", " [-k realm] ");
"8EKL", " [-k realm] ");
#endif
#else
"8EL", " ");
@ -825,10 +900,11 @@ usage()
}
/*
* The following routine provides compatibility (such as it is) between 4.2BSD
* 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 sun
#ifdef OLDSUN
int
get_window_size(fd, wp)
int fd;
struct winsize *wp;
@ -837,16 +913,16 @@ get_window_size(fd, wp)
int error;
if ((error = ioctl(0, TIOCGSIZE, &ts)) != 0)
return(error);
return (error);
wp->ws_row = ts.ts_lines;
wp->ws_col = ts.ts_cols;
wp->ws_xpixel = 0;
wp->ws_ypixel = 0;
return(0);
return (0);
}
#endif
u_char
u_int
getescape(p)
register char *p;
{
@ -854,13 +930,13 @@ getescape(p)
int len;
if ((len = strlen(p)) == 1) /* use any single char, including '\' */
return((u_char)*p);
return ((u_int)*p);
/* otherwise, \nnn */
if (*p == '\\' && len >= 2 && len <= 4) {
val = strtol(++p, (char **)NULL, 8);
val = strtol(++p, NULL, 8);
for (;;) {
if (!*++p)
return((u_char)val);
return ((u_int)val);
if (*p < '0' || *p > '8')
break;
}