mirror of
https://git.savannah.gnu.org/git/inetutils.git
synced 2026-01-12 00:19:39 +08:00
4.4BSD-Lite distribution
This commit is contained in:
580
ftp/cmds.c
580
ftp/cmds.c
@@ -32,16 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
|
||||
static char sccsid[] = "@(#)cmds.c 8.5 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* FTP User Program -- Command Routines.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -51,82 +47,22 @@ static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
/* Include glob.h last, because it may define "const" which breaks
|
||||
system headers on some platforms. */
|
||||
#include <glob.h>
|
||||
|
||||
#include "ftp_var.h"
|
||||
|
||||
/* Returns true if STR is entirely lower case. */
|
||||
static int
|
||||
all_lower (str)
|
||||
char *str;
|
||||
{
|
||||
while (*str)
|
||||
if (isupper (*str++))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Returns true if STR is entirely upper case. */
|
||||
static int
|
||||
all_upper (str)
|
||||
char *str;
|
||||
{
|
||||
while (*str)
|
||||
if (islower (*str++))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Destructively converts STR to upper case. */
|
||||
static char *
|
||||
strup (str)
|
||||
char *str;
|
||||
{
|
||||
char *p;
|
||||
for (p = str; *p; p++)
|
||||
if (islower (*p))
|
||||
*p = toupper (*p);
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Destructively converts STR to lower case. */
|
||||
static char *
|
||||
strdown (str)
|
||||
char *str;
|
||||
{
|
||||
char *p;
|
||||
for (p = str; *p; p++)
|
||||
if (isupper (*p))
|
||||
*p = tolower (*p);
|
||||
return str;
|
||||
}
|
||||
#include "pathnames.h"
|
||||
|
||||
jmp_buf jabort;
|
||||
char *mname;
|
||||
char *home = "/";
|
||||
|
||||
char *mapin = 0;
|
||||
char *mapout = 0;
|
||||
|
||||
/*
|
||||
* `Another' gets another argument, and stores the new argc and argv.
|
||||
* It reverts to the top level (via main.c's intr()) on EOF/error.
|
||||
@@ -258,7 +194,7 @@ setpeer(argc, argv)
|
||||
unix_proxy = 0;
|
||||
else
|
||||
unix_server = 0;
|
||||
if (overbose &&
|
||||
if (overbose &&
|
||||
!strncmp(reply_string, "215 TOPS20", 10))
|
||||
printf(
|
||||
"Remember to set tenex mode when transfering binary files from this machine.\n");
|
||||
@@ -461,8 +397,9 @@ put(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *cmd, *local, *remote;
|
||||
char *cmd;
|
||||
int loc = 0;
|
||||
char *oldargv1, *oldargv2;
|
||||
|
||||
if (argc == 2) {
|
||||
argc++;
|
||||
@@ -477,38 +414,28 @@ usage:
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
local = globulize (argv[1]);
|
||||
if (! local) {
|
||||
oldargv1 = argv[1];
|
||||
oldargv2 = argv[2];
|
||||
if (!globulize(&argv[1])) {
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If "globulize" modifies argv[1], and argv[2] is a copy of
|
||||
* the old argv[1], make it a copy of the new argv[1].
|
||||
*/
|
||||
if (loc)
|
||||
remote = strdup (local);
|
||||
else
|
||||
remote = strdup (argv[2]);
|
||||
|
||||
if (argv[1] != oldargv1 && argv[2] == oldargv1) {
|
||||
argv[2] = argv[1];
|
||||
}
|
||||
cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
|
||||
if (loc && ntflag) {
|
||||
char *new = dotrans(remote);
|
||||
free (remote);
|
||||
remote = new;
|
||||
argv[2] = dotrans(argv[2]);
|
||||
}
|
||||
if (loc && mapflag) {
|
||||
char *new = domap(remote);
|
||||
free (remote);
|
||||
remote = new;
|
||||
argv[2] = domap(argv[2]);
|
||||
}
|
||||
sendrequest(cmd, local, remote,
|
||||
strcmp (argv[1], local) != 0
|
||||
|| strcmp (argv[2], remote) != 0);
|
||||
free (local);
|
||||
free (remote);
|
||||
sendrequest(cmd, argv[1], argv[2],
|
||||
argv[1] != oldargv1 || argv[2] != oldargv2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -522,6 +449,7 @@ mput(argc, argv)
|
||||
int i;
|
||||
sig_t oldintr;
|
||||
int ointer;
|
||||
char *tp;
|
||||
|
||||
if (argc < 2 && !another(&argc, &argv, "local-files")) {
|
||||
printf("usage: %s local-files\n", argv[0]);
|
||||
@@ -533,29 +461,37 @@ mput(argc, argv)
|
||||
oldintr = signal(SIGINT, mabort);
|
||||
(void) setjmp(jabort);
|
||||
if (proxy) {
|
||||
char *cp;
|
||||
char *cp, *tp2, tmpbuf[MAXPATHLEN];
|
||||
|
||||
while ((cp = remglob(argv,0)) != NULL) {
|
||||
if (*cp == 0)
|
||||
if (*cp == 0) {
|
||||
mflag = 0;
|
||||
continue;
|
||||
}
|
||||
if (mflag && confirm(argv[0], cp)) {
|
||||
char *tp = cp;
|
||||
|
||||
tp = cp;
|
||||
if (mcase) {
|
||||
if (all_upper (tp))
|
||||
tp = strdown (strdup (tp));
|
||||
while (*tp && !islower(*tp)) {
|
||||
tp++;
|
||||
}
|
||||
if (!*tp) {
|
||||
tp = cp;
|
||||
tp2 = tmpbuf;
|
||||
while ((*tp2 = *tp) != NULL) {
|
||||
if (isupper(*tp2)) {
|
||||
*tp2 = 'a' + *tp2 - 'A';
|
||||
}
|
||||
tp++;
|
||||
tp2++;
|
||||
}
|
||||
}
|
||||
tp = tmpbuf;
|
||||
}
|
||||
if (ntflag) {
|
||||
char *new = dotrans(tp);
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
tp = new;
|
||||
tp = dotrans(tp);
|
||||
}
|
||||
if (mapflag) {
|
||||
char *new = domap(tp);
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
tp = new;
|
||||
tp = domap(tp);
|
||||
}
|
||||
sendrequest((sunique) ? "STOU" : "STOR",
|
||||
cp, tp, cp != tp || !interactive);
|
||||
@@ -567,12 +503,7 @@ mput(argc, argv)
|
||||
}
|
||||
interactive = ointer;
|
||||
}
|
||||
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
}
|
||||
|
||||
free (cp);
|
||||
}
|
||||
(void) signal(SIGINT, oldintr);
|
||||
mflag = 0;
|
||||
@@ -585,15 +516,8 @@ mput(argc, argv)
|
||||
|
||||
if (!doglob) {
|
||||
if (mflag && confirm(argv[0], argv[i])) {
|
||||
char *tp = argv[i];
|
||||
if (ntflag)
|
||||
tp = dotrans (tp);
|
||||
if (mapflag) {
|
||||
char *new = domap (tp);
|
||||
if (tp != argv[i])
|
||||
free (tp);
|
||||
tp = new;
|
||||
}
|
||||
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
|
||||
tp = (mapflag) ? domap(tp) : tp;
|
||||
sendrequest((sunique) ? "STOU" : "STOR",
|
||||
argv[i], tp, tp != argv[i] || !interactive);
|
||||
if (!mflag && fromatty) {
|
||||
@@ -604,17 +528,12 @@ mput(argc, argv)
|
||||
}
|
||||
interactive = ointer;
|
||||
}
|
||||
if (tp != argv[i])
|
||||
free (tp);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
|
||||
#ifdef GLOB_QUOTE
|
||||
flags |= GLOB_QUOTE;
|
||||
#endif
|
||||
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
|
||||
warnx("%s: not found", argv[i]);
|
||||
globfree(&gl);
|
||||
@@ -622,15 +541,8 @@ mput(argc, argv)
|
||||
}
|
||||
for (cpp = gl.gl_pathv; cpp && *cpp != NULL; cpp++) {
|
||||
if (mflag && confirm(argv[0], *cpp)) {
|
||||
char *tp = *cpp;
|
||||
if (ntflag)
|
||||
tp = dotrans (tp);
|
||||
if (mapflag) {
|
||||
char *new = domap (tp);
|
||||
if (tp != *cpp)
|
||||
free (tp);
|
||||
tp = new;
|
||||
}
|
||||
tp = (ntflag) ? dotrans(*cpp) : *cpp;
|
||||
tp = (mapflag) ? domap(tp) : tp;
|
||||
sendrequest((sunique) ? "STOU" : "STOR",
|
||||
*cpp, tp, *cpp != tp || !interactive);
|
||||
if (!mflag && fromatty) {
|
||||
@@ -641,8 +553,6 @@ mput(argc, argv)
|
||||
}
|
||||
interactive = ointer;
|
||||
}
|
||||
if (tp != *cpp)
|
||||
free (tp);
|
||||
}
|
||||
}
|
||||
globfree(&gl);
|
||||
@@ -680,7 +590,7 @@ getit(argc, argv, restartit, mode)
|
||||
int restartit;
|
||||
{
|
||||
int loc = 0;
|
||||
char *local;
|
||||
char *oldargv1, *oldargv2;
|
||||
|
||||
if (argc == 2) {
|
||||
argc++;
|
||||
@@ -695,33 +605,43 @@ usage:
|
||||
code = -1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
local = globulize (argv[2]);
|
||||
if (! local) {
|
||||
oldargv1 = argv[1];
|
||||
oldargv2 = argv[2];
|
||||
if (!globulize(&argv[2])) {
|
||||
code = -1;
|
||||
return (0);
|
||||
}
|
||||
if (loc && mcase && all_upper (local))
|
||||
strdown (local);
|
||||
if (loc && ntflag) {
|
||||
char *new = dotrans(local);
|
||||
free (local);
|
||||
local = new;
|
||||
}
|
||||
if (loc && mapflag) {
|
||||
char *new = domap(local);
|
||||
free (local);
|
||||
local = new;
|
||||
if (loc && mcase) {
|
||||
char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
|
||||
|
||||
while (*tp && !islower(*tp)) {
|
||||
tp++;
|
||||
}
|
||||
if (!*tp) {
|
||||
tp = argv[2];
|
||||
tp2 = tmpbuf;
|
||||
while ((*tp2 = *tp) != NULL) {
|
||||
if (isupper(*tp2)) {
|
||||
*tp2 = 'a' + *tp2 - 'A';
|
||||
}
|
||||
tp++;
|
||||
tp2++;
|
||||
}
|
||||
argv[2] = tmpbuf;
|
||||
}
|
||||
}
|
||||
if (loc && ntflag)
|
||||
argv[2] = dotrans(argv[2]);
|
||||
if (loc && mapflag)
|
||||
argv[2] = domap(argv[2]);
|
||||
if (restartit) {
|
||||
struct stat stbuf;
|
||||
int ret;
|
||||
|
||||
ret = stat(local, &stbuf);
|
||||
ret = stat(argv[2], &stbuf);
|
||||
if (restartit == 1) {
|
||||
if (ret < 0) {
|
||||
warn("local: %s", local);
|
||||
free (local);
|
||||
warn("local: %s", argv[2]);
|
||||
return (0);
|
||||
}
|
||||
restart_point = stbuf.st_size;
|
||||
@@ -741,36 +661,31 @@ usage:
|
||||
&yy, &mo, &day, &hour, &min, &sec);
|
||||
tm = gmtime(&stbuf.st_mtime);
|
||||
tm->tm_mon++;
|
||||
if (tm->tm_year > yy%100) {
|
||||
free (local);
|
||||
if (tm->tm_year > yy%100)
|
||||
return (1);
|
||||
}
|
||||
if ((tm->tm_year == yy%100 &&
|
||||
if ((tm->tm_year == yy%100 &&
|
||||
tm->tm_mon > mo) ||
|
||||
(tm->tm_mon == mo &&
|
||||
(tm->tm_mon == mo &&
|
||||
tm->tm_mday > day) ||
|
||||
(tm->tm_mday == day &&
|
||||
(tm->tm_mday == day &&
|
||||
tm->tm_hour > hour) ||
|
||||
(tm->tm_hour == hour &&
|
||||
(tm->tm_hour == hour &&
|
||||
tm->tm_min > min) ||
|
||||
(tm->tm_min == min &&
|
||||
tm->tm_sec > sec)) {
|
||||
free (local);
|
||||
(tm->tm_min == min &&
|
||||
tm->tm_sec > sec))
|
||||
return (1);
|
||||
}
|
||||
} else {
|
||||
printf("%s\n", reply_string);
|
||||
verbose = overbose;
|
||||
free (local);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recvrequest("RETR", local, argv[1], mode, strcmp (local, argv[2]) != 0);
|
||||
recvrequest("RETR", argv[2], argv[1], mode,
|
||||
argv[1] != oldargv1 || argv[2] != oldargv2);
|
||||
restart_point = 0;
|
||||
free (local);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -806,7 +721,7 @@ mget(argc, argv)
|
||||
{
|
||||
sig_t oldintr;
|
||||
int ch, ointer;
|
||||
char *cp, *tp, *tp2;
|
||||
char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
|
||||
|
||||
if (argc < 2 && !another(&argc, &argv, "remote-files")) {
|
||||
printf("usage: %s remote-files\n", argv[0]);
|
||||
@@ -824,22 +739,19 @@ mget(argc, argv)
|
||||
}
|
||||
if (mflag && confirm(argv[0], cp)) {
|
||||
tp = cp;
|
||||
if (mcase && ! all_lower (tp))
|
||||
tp = strdown (strdup (tp));
|
||||
if (mcase) {
|
||||
for (tp2 = tmpbuf; ch = *tp++;)
|
||||
*tp2++ = isupper(ch) ? tolower(ch) : ch;
|
||||
tp = tmpbuf;
|
||||
}
|
||||
if (ntflag) {
|
||||
char *new = dotrans (tp);
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
tp = new;
|
||||
tp = dotrans(tp);
|
||||
}
|
||||
if (mapflag) {
|
||||
char *new = domap (tp);
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
tp = new;
|
||||
tp = domap(tp);
|
||||
}
|
||||
recvrequest("RETR", tp, cp, "w",
|
||||
tp != cp || !interactive);
|
||||
tp != cp || !interactive);
|
||||
if (!mflag && fromatty) {
|
||||
ointer = interactive;
|
||||
interactive = 1;
|
||||
@@ -848,10 +760,7 @@ mget(argc, argv)
|
||||
}
|
||||
interactive = ointer;
|
||||
}
|
||||
if (tp != cp)
|
||||
free (tp);
|
||||
}
|
||||
free (cp);
|
||||
}
|
||||
(void) signal(SIGINT,oldintr);
|
||||
mflag = 0;
|
||||
@@ -862,13 +771,12 @@ remglob(argv,doswitch)
|
||||
char *argv[];
|
||||
int doswitch;
|
||||
{
|
||||
char temp[16];
|
||||
static char buf[MAXPATHLEN];
|
||||
static FILE *ftemp = NULL;
|
||||
static char **args;
|
||||
int buf_len = 0;
|
||||
char *buf = 0;
|
||||
int sofar = 0;
|
||||
int oldverbose, oldhash;
|
||||
char *cp, *mode, *end;
|
||||
char *cp, *mode;
|
||||
|
||||
if (!mflag) {
|
||||
if (!doglob) {
|
||||
@@ -887,15 +795,11 @@ remglob(argv,doswitch)
|
||||
args = argv;
|
||||
if ((cp = *++args) == NULL)
|
||||
args = NULL;
|
||||
return cp ? 0 : strdup (cp);
|
||||
return (cp);
|
||||
}
|
||||
if (ftemp == NULL) {
|
||||
char temp[sizeof PATH_TMP + sizeof "XXXXXX"];
|
||||
|
||||
strcpy (temp, PATH_TMP);
|
||||
strcat (temp, "XXXXXX");
|
||||
mktemp (temp);
|
||||
|
||||
(void) strcpy(temp, _PATH_TMP);
|
||||
(void) mktemp(temp);
|
||||
oldverbose = verbose, verbose = 0;
|
||||
oldhash = hash, hash = 0;
|
||||
if (doswitch) {
|
||||
@@ -914,39 +818,20 @@ remglob(argv,doswitch)
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
buf_len = 100; /* Any old size */
|
||||
buf = malloc (buf_len + 1);
|
||||
|
||||
sofar = 0;
|
||||
for (;;) {
|
||||
if (! buf) {
|
||||
printf ("malloc failure\n");
|
||||
return 0;
|
||||
}
|
||||
if (! fgets(buf + sofar, buf_len - sofar, ftemp)) {
|
||||
fclose(ftemp);
|
||||
ftemp = NULL;
|
||||
free (buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sofar = strlen (buf);
|
||||
if (buf[sofar - 1] == '\n') {
|
||||
buf[sofar - 1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Make more room and read some more... */
|
||||
buf_len += buf_len;
|
||||
buf = realloc (buf, buf_len);
|
||||
if (fgets(buf, sizeof (buf), ftemp) == NULL) {
|
||||
(void) fclose(ftemp), ftemp = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
if ((cp = strchr(buf, '\n')) != NULL)
|
||||
*cp = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
onoff(bool)
|
||||
int bool;
|
||||
{
|
||||
|
||||
return (bool ? "on" : "off");
|
||||
}
|
||||
|
||||
@@ -977,7 +862,7 @@ status(argc, argv)
|
||||
}
|
||||
printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n",
|
||||
modename, typename, formname, structname);
|
||||
printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n",
|
||||
printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n",
|
||||
onoff(verbose), onoff(bell), onoff(interactive),
|
||||
onoff(doglob));
|
||||
printf("Store unique: %s; Receive unique: %s\n", onoff(sunique),
|
||||
@@ -1110,7 +995,7 @@ setglob(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
|
||||
|
||||
doglob = !doglob;
|
||||
printf("Globbing %s.\n", onoff(doglob));
|
||||
code = doglob;
|
||||
@@ -1177,7 +1062,7 @@ lcd(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *dir;
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (argc < 2)
|
||||
argc++, argv[1] = home;
|
||||
@@ -1186,28 +1071,19 @@ lcd(argc, argv)
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
dir = globulize (argv[1]);
|
||||
if (! dir) {
|
||||
if (!globulize(&argv[1])) {
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (chdir(dir) < 0) {
|
||||
warn("dir: %s", dir);
|
||||
free (dir);
|
||||
if (chdir(argv[1]) < 0) {
|
||||
warn("local: %s", argv[1]);
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
free (dir);
|
||||
|
||||
dir = getcwd (0, 0);
|
||||
if (dir) {
|
||||
printf("Local directory now %s\n", dir);
|
||||
free (dir);
|
||||
} else
|
||||
warnx("getcwd: %s", strerror (errno));
|
||||
if (getwd(buf) != NULL)
|
||||
printf("Local directory now %s\n", buf);
|
||||
else
|
||||
warnx("getwd: %s", buf);
|
||||
code = 0;
|
||||
}
|
||||
|
||||
@@ -1265,7 +1141,6 @@ mdelete(argc, argv)
|
||||
interactive = ointer;
|
||||
}
|
||||
}
|
||||
free (cp);
|
||||
}
|
||||
(void) signal(SIGINT, oldintr);
|
||||
mflag = 0;
|
||||
@@ -1301,7 +1176,7 @@ ls(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *cmd, *dest;
|
||||
char *cmd;
|
||||
|
||||
if (argc < 2)
|
||||
argc++, argv[1] = NULL;
|
||||
@@ -1313,24 +1188,16 @@ ls(argc, argv)
|
||||
return;
|
||||
}
|
||||
cmd = argv[0][0] == 'n' ? "NLST" : "LIST";
|
||||
|
||||
if (strcmp(argv[2], "-") != 0) {
|
||||
dest = globulize(argv[2]);
|
||||
if (! dest) {
|
||||
if (strcmp(argv[2], "-") && !globulize(&argv[2])) {
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
if (strcmp(argv[2], "-") && *argv[2] != '|')
|
||||
if (!globulize(&argv[2]) || !confirm("output to local-file:", argv[2])) {
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
if (*dest != '|' && !confirm("output to local-file:", dest)) {
|
||||
code = -1;
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
dest = 0;
|
||||
|
||||
recvrequest(cmd, dest ? dest : "-", argv[1], "w", 0);
|
||||
out:
|
||||
if (dest)
|
||||
free (dest);
|
||||
}
|
||||
recvrequest(cmd, argv[2], argv[1], "w", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1354,23 +1221,14 @@ usage:
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
dest = argv[argc - 1];
|
||||
argv[argc - 1] = NULL;
|
||||
if (strcmp(dest, "-") && *dest != '|') {
|
||||
dest = globulize (dest);
|
||||
if (! dest) {
|
||||
if (strcmp(dest, "-") && *dest != '|')
|
||||
if (!globulize(&dest) ||
|
||||
!confirm("output to local-file:", dest)) {
|
||||
code = -1;
|
||||
return;
|
||||
}
|
||||
if (! confirm("output to local-file:", dest)) {
|
||||
code = -1;
|
||||
free (dest);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
dest = strdup (dest);
|
||||
|
||||
}
|
||||
cmd = argv[0][1] == 'l' ? "NLST" : "LIST";
|
||||
mname = argv[0];
|
||||
mflag = 1;
|
||||
@@ -1388,10 +1246,8 @@ usage:
|
||||
interactive = ointer;
|
||||
}
|
||||
}
|
||||
|
||||
(void) signal(SIGINT, oldintr);
|
||||
mflag = 0;
|
||||
free (dest);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1405,7 +1261,8 @@ shell(argc, argv)
|
||||
{
|
||||
pid_t pid;
|
||||
sig_t old1, old2;
|
||||
char shellnam[40], *shell, *namep;
|
||||
char shellnam[40], *shell, *namep;
|
||||
union wait status;
|
||||
|
||||
old1 = signal (SIGINT, SIG_IGN);
|
||||
old2 = signal (SIGQUIT, SIG_IGN);
|
||||
@@ -1416,7 +1273,7 @@ shell(argc, argv)
|
||||
(void) signal(SIGQUIT, SIG_DFL);
|
||||
shell = getenv("SHELL");
|
||||
if (shell == NULL)
|
||||
shell = PATH_BSHELL;
|
||||
shell = _PATH_BSHELL;
|
||||
namep = strrchr(shell,'/');
|
||||
if (namep == NULL)
|
||||
namep = shell;
|
||||
@@ -1439,7 +1296,7 @@ shell(argc, argv)
|
||||
exit(1);
|
||||
}
|
||||
if (pid > 0)
|
||||
while (wait(0) != pid)
|
||||
while (wait((int *)&status) != pid)
|
||||
;
|
||||
(void) signal(SIGINT, old1);
|
||||
(void) signal(SIGQUIT, old2);
|
||||
@@ -1653,7 +1510,7 @@ do_umask(argc, argv)
|
||||
}
|
||||
|
||||
void
|
||||
site_idle(argc, argv)
|
||||
idle(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
@@ -1750,33 +1607,27 @@ fatal(msg)
|
||||
* Can't control multiple values being expanded
|
||||
* from the expression, we return only the first.
|
||||
*/
|
||||
char *
|
||||
globulize(cp)
|
||||
char *cp;
|
||||
int
|
||||
globulize(cpp)
|
||||
char **cpp;
|
||||
{
|
||||
glob_t gl;
|
||||
int flags;
|
||||
|
||||
if (!doglob)
|
||||
return strdup (cp);
|
||||
|
||||
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
|
||||
#ifdef GLOB_QUOTE
|
||||
flags |= GLOB_QUOTE;
|
||||
#endif
|
||||
return (1);
|
||||
|
||||
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
if (glob(cp, flags, NULL, &gl) ||
|
||||
if (glob(*cpp, flags, NULL, &gl) ||
|
||||
gl.gl_pathc == 0) {
|
||||
warnx("%s: not found", cp);
|
||||
warnx("%s: not found", *cpp);
|
||||
globfree(&gl);
|
||||
return (0);
|
||||
}
|
||||
|
||||
cp = strdup(gl.gl_pathv[0]);
|
||||
*cpp = strdup(gl.gl_pathv[0]); /* XXX - wasted memory */
|
||||
globfree(&gl);
|
||||
|
||||
return cp;
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1807,8 +1658,7 @@ account(argc,argv)
|
||||
jmp_buf abortprox;
|
||||
|
||||
void
|
||||
proxabort(sig)
|
||||
int sig;
|
||||
proxabort()
|
||||
{
|
||||
|
||||
if (!proxy) {
|
||||
@@ -1930,7 +1780,7 @@ char *
|
||||
dotrans(name)
|
||||
char *name;
|
||||
{
|
||||
char *new = malloc (strlen (name) + 1);
|
||||
static char new[MAXPATHLEN];
|
||||
char *cp1, *cp2 = new;
|
||||
int i, ostop, found;
|
||||
|
||||
@@ -1955,17 +1805,6 @@ dotrans(name)
|
||||
return (new);
|
||||
}
|
||||
|
||||
void
|
||||
setpassive(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
|
||||
passivemode = !passivemode;
|
||||
printf("Passive mode %s.\n", onoff(passivemode));
|
||||
code = passivemode;
|
||||
}
|
||||
|
||||
void
|
||||
setnmap(argc, argv)
|
||||
int argc;
|
||||
@@ -1994,60 +1833,17 @@ setnmap(argc, argv)
|
||||
cp = strchr(altarg, ' ');
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if (mapin)
|
||||
free (mapin);
|
||||
mapin = strdup (altarg);
|
||||
|
||||
(void) strncpy(mapin, altarg, MAXPATHLEN - 1);
|
||||
while (*++cp == ' ')
|
||||
continue;
|
||||
if (mapout)
|
||||
free (mapout);
|
||||
mapout = strdup (cp);
|
||||
}
|
||||
|
||||
static int
|
||||
cp_subst (from_p, to_p, toks, tp, te, tok0, buf_p, buf_len_p)
|
||||
char **from_p, **to_p;
|
||||
char *tp[9], *te[9];
|
||||
int toks[9];
|
||||
char *tok0;
|
||||
char **buf_p;
|
||||
int *buf_len_p;
|
||||
{
|
||||
int toknum;
|
||||
char *src;
|
||||
int src_len;
|
||||
|
||||
if (*++(*from_p) == '0') {
|
||||
src = tok0;
|
||||
src_len = strlen (tok0);
|
||||
}
|
||||
else if (toks[toknum = **from_p - '1']) {
|
||||
src = tp[toknum];
|
||||
src_len = te[toknum] - src;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
if (src_len > 2) {
|
||||
/* This subst will be longer than the original, so make room
|
||||
for it. */
|
||||
*buf_len_p += src_len - 2;
|
||||
*buf_p = realloc (*buf_p, *buf_len_p);
|
||||
}
|
||||
while (src_len--)
|
||||
*(*to_p)++ = *src++;
|
||||
|
||||
return 1;
|
||||
(void) strncpy(mapout, cp, MAXPATHLEN - 1);
|
||||
}
|
||||
|
||||
char *
|
||||
domap(name)
|
||||
char *name;
|
||||
{
|
||||
int buf_len = strlen (name) + 1;
|
||||
char *buf = malloc (buf_len);
|
||||
static char new[MAXPATHLEN];
|
||||
char *cp1 = name, *cp2 = mapin;
|
||||
char *tp[9], *te[9];
|
||||
int i, toks[9], toknum = 0, match = 1;
|
||||
@@ -2092,7 +1888,7 @@ domap(name)
|
||||
{
|
||||
toks[toknum] = 0;
|
||||
}
|
||||
cp1 = buf;
|
||||
cp1 = new;
|
||||
*cp1 = '\0';
|
||||
cp2 = mapout;
|
||||
while (*cp2) {
|
||||
@@ -2105,26 +1901,49 @@ domap(name)
|
||||
break;
|
||||
case '[':
|
||||
LOOP:
|
||||
if (*++cp2 == '$' && isdigit(*(cp2+1)))
|
||||
cp_subst (&cp2, &cp1,
|
||||
toks, tp, te, name,
|
||||
&buf, &buf_len);
|
||||
if (*++cp2 == '$' && isdigit(*(cp2+1))) {
|
||||
if (*++cp2 == '0') {
|
||||
char *cp3 = name;
|
||||
|
||||
while (*cp3) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
match = 1;
|
||||
}
|
||||
else if (toks[toknum = *cp2 - '1']) {
|
||||
char *cp3 = tp[toknum];
|
||||
|
||||
while (cp3 != te[toknum]) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (*cp2 && *cp2 != ',' &&
|
||||
while (*cp2 && *cp2 != ',' &&
|
||||
*cp2 != ']') {
|
||||
if (*cp2 == '\\') {
|
||||
cp2++;
|
||||
}
|
||||
else if (*cp2 == '$' &&
|
||||
isdigit(*(cp2+1)))
|
||||
if (cp_subst (&cp2,
|
||||
&cp1,
|
||||
toks,
|
||||
tp, te,
|
||||
name,
|
||||
&buf,
|
||||
&buf_len))
|
||||
match = 1;
|
||||
isdigit(*(cp2+1))) {
|
||||
if (*++cp2 == '0') {
|
||||
char *cp3 = name;
|
||||
|
||||
while (*cp3) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
}
|
||||
else if (toks[toknum =
|
||||
*cp2 - '1']) {
|
||||
char *cp3=tp[toknum];
|
||||
|
||||
while (cp3 !=
|
||||
te[toknum]) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*cp2) {
|
||||
*cp1++ = *cp2++;
|
||||
}
|
||||
@@ -2160,10 +1979,20 @@ LOOP:
|
||||
break;
|
||||
case '$':
|
||||
if (isdigit(*(cp2 + 1))) {
|
||||
if (cp_subst (&cp2, &cp1,
|
||||
toks, tp, te, name,
|
||||
&buf, &buf_len))
|
||||
match = 1;
|
||||
if (*++cp2 == '0') {
|
||||
char *cp3 = name;
|
||||
|
||||
while (*cp3) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
}
|
||||
else if (toks[toknum = *cp2 - '1']) {
|
||||
char *cp3 = tp[toknum];
|
||||
|
||||
while (cp3 != te[toknum]) {
|
||||
*cp1++ = *cp3++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* intentional drop through */
|
||||
@@ -2174,11 +2003,10 @@ LOOP:
|
||||
cp2++;
|
||||
}
|
||||
*cp1 = '\0';
|
||||
|
||||
if (! *buf)
|
||||
strcpy (buf, name);
|
||||
|
||||
return buf;
|
||||
if (!*new) {
|
||||
return (name);
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2228,9 +2056,7 @@ restart(argc, argv)
|
||||
printf("restart: offset not specified\n");
|
||||
else {
|
||||
restart_point = atol(argv[1]);
|
||||
printf((sizeof(restart_point) > sizeof(long)
|
||||
? "restarting at %qd. %s\n"
|
||||
: "restarting at %ld. %s\n"), restart_point,
|
||||
printf("restarting at %qd. %s\n", restart_point,
|
||||
"execute get, put or append to initiate transfer");
|
||||
}
|
||||
}
|
||||
|
||||
10
ftp/cmdtab.c
10
ftp/cmdtab.c
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
|
||||
static char sccsid[] = "@(#)cmdtab.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ftp_var.h"
|
||||
|
||||
@@ -98,7 +94,6 @@ char rmtstatushelp[]="show status of remote machine";
|
||||
char runiquehelp[] = "toggle store unique for local files";
|
||||
char resethelp[] = "clear queued command replies";
|
||||
char sendhelp[] = "send one file";
|
||||
char passivehelp[] = "enter passive transfer mode";
|
||||
char sitehelp[] = "send site specific command to remote server\n\t\tTry \"rhelp site\" or \"site help\" for more information";
|
||||
char shellhelp[] = "escape to the shell";
|
||||
char sizecmdhelp[] = "show size of remote file";
|
||||
@@ -137,7 +132,7 @@ struct cmd cmdtab[] = {
|
||||
{ "glob", globhelp, 0, 0, 0, setglob },
|
||||
{ "hash", hashhelp, 0, 0, 0, sethash },
|
||||
{ "help", helphelp, 0, 0, 1, help },
|
||||
{ "idle", idlehelp, 0, 1, 1, site_idle },
|
||||
{ "idle", idlehelp, 0, 1, 1, idle },
|
||||
{ "image", binaryhelp, 0, 1, 1, setbinary },
|
||||
{ "lcd", lcdhelp, 0, 0, 0, lcd },
|
||||
{ "ls", lshelp, 1, 1, 1, ls },
|
||||
@@ -155,7 +150,6 @@ struct cmd cmdtab[] = {
|
||||
{ "nlist", nlisthelp, 1, 1, 1, ls },
|
||||
{ "ntrans", ntranshelp, 0, 0, 1, setntrans },
|
||||
{ "open", connecthelp, 0, 0, 1, setpeer },
|
||||
{ "passive", passivehelp, 0, 0, 0, setpassive },
|
||||
{ "prompt", prompthelp, 0, 0, 0, setprompt },
|
||||
{ "proxy", proxyhelp, 0, 0, 1, doproxy },
|
||||
{ "sendport", porthelp, 0, 0, 0, setport },
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
15
ftp/extern.h
15
ftp/extern.h
@@ -30,7 +30,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.3 (Berkeley) 10/9/94
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/3/94
|
||||
*/
|
||||
|
||||
struct timeval;
|
||||
@@ -48,7 +48,7 @@ void cdup __P((int, char **));
|
||||
void changetype __P((int, int));
|
||||
void cmdabort __P(());
|
||||
void cmdscanner __P((int));
|
||||
int command __P((const char *fmt, ...));
|
||||
int command __P(());
|
||||
int confirm __P((char *, char *));
|
||||
FILE *dataconn __P((char *));
|
||||
void delete __P((int, char **));
|
||||
@@ -59,17 +59,17 @@ void domacro __P((int, char **));
|
||||
char *domap __P((char *));
|
||||
void doproxy __P((int, char **));
|
||||
char *dotrans __P((char *));
|
||||
int empty __P((fd_set *, int));
|
||||
int empty __P((struct fd_set *, int));
|
||||
void fatal __P((char *));
|
||||
void get __P((int, char **));
|
||||
struct cmd *getcmd __P((char *));
|
||||
int getit __P((int, char **, int, char *));
|
||||
int getreply __P((int));
|
||||
char *globulize __P((char *));
|
||||
int globulize __P((char **));
|
||||
char *gunique __P((char *));
|
||||
void help __P((int, char **));
|
||||
char *hookup __P((char *, int));
|
||||
void site_idle __P((int, char **));
|
||||
void idle __P((int, char **));
|
||||
int initconn __P((void));
|
||||
void intr __P(());
|
||||
void lcd __P((int, char **));
|
||||
@@ -120,7 +120,6 @@ void setglob __P((int, char **));
|
||||
void sethash __P((int, char **));
|
||||
void setnmap __P((int, char **));
|
||||
void setntrans __P((int, char **));
|
||||
void setpassive __P((int, char **));
|
||||
void setpeer __P((int, char **));
|
||||
void setport __P((int, char **));
|
||||
void setprompt __P((int, char **));
|
||||
@@ -151,7 +150,3 @@ extern int proxy;
|
||||
extern char reply_string[];
|
||||
extern off_t restart_point;
|
||||
extern int NCMDS;
|
||||
|
||||
#ifndef HAVE_GETPASS_DECL
|
||||
extern char *getpass __P((const char *));
|
||||
#endif
|
||||
|
||||
27
ftp/ftp.1
27
ftp/ftp.1
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
|
||||
.\" @(#)ftp.1 8.2 (Berkeley) 12/30/93
|
||||
.\"
|
||||
.Dd October 9, 1994
|
||||
.Dd December 30, 1993
|
||||
.Dt FTP 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -360,7 +360,7 @@ If no local file is specified, or if
|
||||
is
|
||||
.Sq Fl ,
|
||||
the output is sent to the terminal.
|
||||
.It Ic macdef Ar macro-name
|
||||
.It Ic macdefNs Ar macro-name
|
||||
Define a macro.
|
||||
Subsequent lines are stored as the macro
|
||||
.Ar macro-name ;
|
||||
@@ -601,27 +601,6 @@ will also attempt to automatically log the user in to
|
||||
the
|
||||
.Tn FTP
|
||||
server (see below).
|
||||
.It Ic passive
|
||||
Toggle passive mode. If passive mode is turned on
|
||||
(default is off), the ftp client will
|
||||
send a
|
||||
.Dv PASV
|
||||
command for all data connections instead of the usual
|
||||
.Dv PORT
|
||||
command. The
|
||||
.Dv PASV
|
||||
command requests that the remote server open a port for the data connection
|
||||
and return the address of that port. The remote server listens on that
|
||||
port and the client connects to it. When using the more traditional
|
||||
.Dv PORT
|
||||
command, the client listens on a port and sends that address to the remote
|
||||
server, who connects back to it. Passive mode is useful when using
|
||||
.Nm ftp
|
||||
through a gateway router or host that controls the directionality of
|
||||
traffic.
|
||||
(Note that though ftp servers are required to support the
|
||||
.Dv PASV
|
||||
command by RFC 1123, some do not.)
|
||||
.It Ic prompt
|
||||
Toggle interactive prompting.
|
||||
Interactive prompting
|
||||
|
||||
242
ftp/ftp.c
242
ftp/ftp.c
@@ -32,36 +32,19 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
|
||||
static char sccsid[] = "@(#)ftp.c 8.4 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/ftp.h>
|
||||
#include <arpa/telnet.h>
|
||||
@@ -77,27 +60,10 @@ static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "ftp_var.h"
|
||||
|
||||
#ifndef HAVE_FCLOSE_DECL
|
||||
/* Some systems don't declare fclose in <stdio.h>, so do it ourselves. */
|
||||
extern int fclose __P ((FILE *));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PCLOSE_DECL
|
||||
/* Some systems don't declare pclose in <stdio.h>, so do it ourselves. */
|
||||
extern int pclose __P ((FILE *));
|
||||
#endif
|
||||
|
||||
extern int h_errno;
|
||||
|
||||
struct sockaddr_in hisctladdr;
|
||||
@@ -130,15 +96,7 @@ hookup(host, port)
|
||||
} else {
|
||||
hp = gethostbyname(host);
|
||||
if (hp == NULL) {
|
||||
#ifdef HAVE_HSTRERROR
|
||||
warnx("%s: %s", host, hstrerror(h_errno));
|
||||
#else
|
||||
extern char *__progname;
|
||||
char *pfx =
|
||||
malloc (strlen (__progname) + 2 + strlen (host) + 1);
|
||||
sprintf (pfx, "%s: %s", __progname, host);
|
||||
herror (pfx);
|
||||
#endif
|
||||
code = -1;
|
||||
return ((char *) 0);
|
||||
}
|
||||
@@ -187,7 +145,7 @@ hookup(host, port)
|
||||
code = -1;
|
||||
goto bad;
|
||||
}
|
||||
#if defined (IP_TOS) && defined (IPPROTO_IP) && defined (IPTOS_LOWDELAY)
|
||||
#ifdef IP_TOS
|
||||
tos = IPTOS_LOWDELAY;
|
||||
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
|
||||
warn("setsockopt TOS (ignored)");
|
||||
@@ -256,11 +214,8 @@ login(host)
|
||||
printf("Name (%s:%s): ", host, myname);
|
||||
else
|
||||
printf("Name (%s): ", host);
|
||||
if (fgets(tmp, sizeof(tmp) - 1, stdin)) {
|
||||
/* If they press Ctrl-d immediately, it's empty. */
|
||||
tmp[strlen(tmp) - 1] = '\0';
|
||||
} else
|
||||
*tmp = '\0';
|
||||
(void) fgets(tmp, sizeof(tmp) - 1, stdin);
|
||||
tmp[strlen(tmp) - 1] = '\0';
|
||||
if (*tmp == '\0')
|
||||
user = myname;
|
||||
else
|
||||
@@ -297,8 +252,7 @@ login(host)
|
||||
}
|
||||
|
||||
void
|
||||
cmdabort(sig)
|
||||
int sig;
|
||||
cmdabort()
|
||||
{
|
||||
|
||||
printf("\n");
|
||||
@@ -310,29 +264,19 @@ cmdabort(sig)
|
||||
|
||||
/*VARARGS*/
|
||||
int
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
command (const char *fmt, ...)
|
||||
#else
|
||||
command(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if !(defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__)
|
||||
const char *fmt;
|
||||
#endif
|
||||
char *fmt;
|
||||
int r;
|
||||
sig_t oldintr;
|
||||
|
||||
abrtflag = 0;
|
||||
if (debug) {
|
||||
printf("---> ");
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
fmt = va_arg(ap, char *);
|
||||
#endif
|
||||
if (strncmp("PASS ", fmt, 5) == 0)
|
||||
printf("PASS XXXX");
|
||||
else
|
||||
@@ -347,12 +291,8 @@ va_dcl
|
||||
return (0);
|
||||
}
|
||||
oldintr = signal(SIGINT, cmdabort);
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
fmt = va_arg(ap, char *);
|
||||
#endif
|
||||
vfprintf(cout, fmt, ap);
|
||||
va_end(ap);
|
||||
fprintf(cout, "\r\n");
|
||||
@@ -471,21 +411,20 @@ getreply(expecteof)
|
||||
|
||||
int
|
||||
empty(mask, sec)
|
||||
fd_set *mask;
|
||||
struct fd_set *mask;
|
||||
int sec;
|
||||
{
|
||||
struct timeval t;
|
||||
|
||||
t.tv_sec = (long) sec;
|
||||
t.tv_usec = 0;
|
||||
return (select(32, mask, (fd_set *) 0, (fd_set *) 0, &t));
|
||||
return (select(32, mask, (struct fd_set *) 0, (struct fd_set *) 0, &t));
|
||||
}
|
||||
|
||||
jmp_buf sendabort;
|
||||
|
||||
void
|
||||
abortsend(sig)
|
||||
int sig;
|
||||
abortsend()
|
||||
{
|
||||
|
||||
mflag = 0;
|
||||
@@ -707,10 +646,10 @@ sendrequest(cmd, local, remote, printnames)
|
||||
}
|
||||
break;
|
||||
}
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
if (closefunc != NULL)
|
||||
(*closefunc)(fin);
|
||||
(void) fclose(dout);
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
(void) getreply(0);
|
||||
(void) signal(SIGINT, oldintr);
|
||||
if (oldintp)
|
||||
@@ -719,6 +658,7 @@ sendrequest(cmd, local, remote, printnames)
|
||||
ptransfer("sent", bytes, &start, &stop);
|
||||
return;
|
||||
abort:
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
(void) signal(SIGINT, oldintr);
|
||||
if (oldintp)
|
||||
(void) signal(SIGPIPE, oldintp);
|
||||
@@ -736,7 +676,6 @@ abort:
|
||||
code = -1;
|
||||
if (closefunc != NULL && fin != NULL)
|
||||
(*closefunc)(fin);
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
if (bytes > 0)
|
||||
ptransfer("sent", bytes, &start, &stop);
|
||||
}
|
||||
@@ -744,8 +683,7 @@ abort:
|
||||
jmp_buf recvabort;
|
||||
|
||||
void
|
||||
abortrecv(sig)
|
||||
int sig;
|
||||
abortrecv()
|
||||
{
|
||||
|
||||
mflag = 0;
|
||||
@@ -763,8 +701,8 @@ recvrequest(cmd, local, remote, lmode, printnames)
|
||||
FILE *fout, *din = 0;
|
||||
int (*closefunc) __P((FILE *));
|
||||
sig_t oldintr, oldintp;
|
||||
int c, d, is_retr, tcrflag, bare_lfs = 0, blksize;
|
||||
static int bufsize=0;
|
||||
int c, d, is_retr, tcrflag, bare_lfs = 0;
|
||||
static int bufsize;
|
||||
static char *buf;
|
||||
long bytes = 0, hashbytes = HASHBYTES;
|
||||
struct timeval start, stop;
|
||||
@@ -888,20 +826,18 @@ recvrequest(cmd, local, remote, lmode, printnames)
|
||||
}
|
||||
closefunc = fclose;
|
||||
}
|
||||
if (fstat(fileno(fout), &st) < 0 || ST_BLKSIZE(st) == 0)
|
||||
blksize = BUFSIZ;
|
||||
else
|
||||
blksize = ST_BLKSIZE(st);
|
||||
if (blksize > bufsize) {
|
||||
if (fstat(fileno(fout), &st) < 0 || st.st_blksize == 0)
|
||||
st.st_blksize = BUFSIZ;
|
||||
if (st.st_blksize > bufsize) {
|
||||
if (buf)
|
||||
(void) free(buf);
|
||||
buf = malloc((unsigned)blksize);
|
||||
buf = malloc((unsigned)st.st_blksize);
|
||||
if (buf == NULL) {
|
||||
warn("malloc");
|
||||
bufsize = 0;
|
||||
goto abort;
|
||||
}
|
||||
bufsize = blksize;
|
||||
bufsize = st.st_blksize;
|
||||
}
|
||||
(void) gettimeofday(&start, (struct timezone *)0);
|
||||
switch (curtype) {
|
||||
@@ -1019,8 +955,8 @@ break2:
|
||||
(void) signal(SIGINT, oldintr);
|
||||
if (oldintp)
|
||||
(void) signal(SIGPIPE, oldintp);
|
||||
(void) fclose(din);
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
(void) fclose(din);
|
||||
(void) getreply(0);
|
||||
if (bytes > 0 && is_retr)
|
||||
ptransfer("received", bytes, &start, &stop);
|
||||
@@ -1029,6 +965,7 @@ abort:
|
||||
|
||||
/* abort using RFC959 recommended IP,SYNC sequence */
|
||||
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
if (oldintp)
|
||||
(void) signal(SIGPIPE, oldintr);
|
||||
(void) signal(SIGINT, SIG_IGN);
|
||||
@@ -1048,7 +985,6 @@ abort:
|
||||
(*closefunc)(fout);
|
||||
if (din)
|
||||
(void) fclose(din);
|
||||
(void) gettimeofday(&stop, (struct timezone *)0);
|
||||
if (bytes > 0)
|
||||
ptransfer("received", bytes, &start, &stop);
|
||||
(void) signal(SIGINT, oldintr);
|
||||
@@ -1064,61 +1000,6 @@ initconn()
|
||||
char *p, *a;
|
||||
int result, len, tmpno = 0;
|
||||
int on = 1;
|
||||
int a0, a1, a2, a3, p0, p1;
|
||||
|
||||
if (passivemode) {
|
||||
data = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (data < 0) {
|
||||
perror("ftp: socket");
|
||||
return(1);
|
||||
}
|
||||
if ((options & SO_DEBUG) &&
|
||||
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
|
||||
sizeof (on)) < 0)
|
||||
perror("ftp: setsockopt (ignored)");
|
||||
if (command("PASV") != COMPLETE) {
|
||||
printf("Passive mode refused.\n");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* What we've got at this point is a string of comma
|
||||
* separated one-byte unsigned integer values.
|
||||
* The first four are the an IP address. The fifth is
|
||||
* the MSB of the port number, the sixth is the LSB.
|
||||
* From that we'll prepare a sockaddr_in.
|
||||
*/
|
||||
|
||||
if (sscanf(pasv,"%d,%d,%d,%d,%d,%d",
|
||||
&a0, &a1, &a2, &a3, &p0, &p1) != 6) {
|
||||
printf("Passive mode address scan failure. Shouldn't happen!\n");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
bzero(&data_addr, sizeof(data_addr));
|
||||
data_addr.sin_family = AF_INET;
|
||||
a = (char *)&data_addr.sin_addr.s_addr;
|
||||
a[0] = a0 & 0xff;
|
||||
a[1] = a1 & 0xff;
|
||||
a[2] = a2 & 0xff;
|
||||
a[3] = a3 & 0xff;
|
||||
p = (char *)&data_addr.sin_port;
|
||||
p[0] = p0 & 0xff;
|
||||
p[1] = p1 & 0xff;
|
||||
|
||||
if (connect(data, (struct sockaddr *)&data_addr,
|
||||
sizeof(data_addr)) < 0) {
|
||||
perror("ftp: connect");
|
||||
goto bad;
|
||||
}
|
||||
#if defined(IP_TOS) && defined(IPTOS_THROUGPUT)
|
||||
on = IPTOS_THROUGHPUT;
|
||||
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on,
|
||||
sizeof(int)) < 0)
|
||||
perror("ftp: setsockopt TOS (ignored)");
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
noport:
|
||||
data_addr = myctladdr;
|
||||
@@ -1169,7 +1050,7 @@ noport:
|
||||
}
|
||||
if (tmpno)
|
||||
sendport = 1;
|
||||
#if defined (IP_TOS) && defined (IPPROTO_IP) && defined (IPTOS_THROUGHPUT)
|
||||
#ifdef IP_TOS
|
||||
on = IPTOS_THROUGHPUT;
|
||||
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
|
||||
warn("setsockopt TOS (ignored)");
|
||||
@@ -1189,9 +1070,6 @@ dataconn(lmode)
|
||||
struct sockaddr_in from;
|
||||
int s, fromlen = sizeof (from), tos;
|
||||
|
||||
if (passivemode)
|
||||
return (fdopen(data, lmode));
|
||||
|
||||
s = accept(data, (struct sockaddr *) &from, &fromlen);
|
||||
if (s < 0) {
|
||||
warn("accept");
|
||||
@@ -1200,7 +1078,7 @@ dataconn(lmode)
|
||||
}
|
||||
(void) close(data);
|
||||
data = s;
|
||||
#if defined (IP_TOS) && defined (IPPROTO_IP) && defined (IPTOS_THROUGHPUT)
|
||||
#ifdef IP_TOS
|
||||
tos = IPTOS_THROUGHPUT;
|
||||
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
|
||||
warn("setsockopt TOS (ignored)");
|
||||
@@ -1215,16 +1093,15 @@ ptransfer(direction, bytes, t0, t1)
|
||||
struct timeval *t0, *t1;
|
||||
{
|
||||
struct timeval td;
|
||||
float s;
|
||||
long bs;
|
||||
float s, bs;
|
||||
|
||||
if (verbose) {
|
||||
tvsub(&td, t1, t0);
|
||||
s = td.tv_sec + (td.tv_usec / 1000000.);
|
||||
#define nz(x) ((x) == 0 ? 1 : (x))
|
||||
bs = bytes / nz(s);
|
||||
printf("%ld bytes %s in %.3g seconds (%ld bytes/s)\n",
|
||||
bytes, direction, s, bs);
|
||||
printf("%ld bytes %s in %.2g seconds (%.2g Kbytes/s)\n",
|
||||
bytes, direction, s, bs / 1024.);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1253,8 +1130,7 @@ tvsub(tdiff, t1, t0)
|
||||
}
|
||||
|
||||
void
|
||||
psabort(sig)
|
||||
int sig;
|
||||
psabort()
|
||||
{
|
||||
|
||||
abrtflag++;
|
||||
@@ -1267,7 +1143,7 @@ pswitch(flag)
|
||||
sig_t oldintr;
|
||||
static struct comvars {
|
||||
int connect;
|
||||
char *name;
|
||||
char name[MAXHOSTNAMELEN];
|
||||
struct sockaddr_in mctl;
|
||||
struct sockaddr_in hctl;
|
||||
FILE *in;
|
||||
@@ -1282,9 +1158,9 @@ pswitch(flag)
|
||||
char nti[17];
|
||||
char nto[17];
|
||||
int mapflg;
|
||||
char *mi;
|
||||
char *mo;
|
||||
} proxstruct = {0}, tmpstruct = {0};
|
||||
char mi[MAXPATHLEN];
|
||||
char mo[MAXPATHLEN];
|
||||
} proxstruct, tmpstruct;
|
||||
struct comvars *ip, *op;
|
||||
|
||||
abrtflag = 0;
|
||||
@@ -1304,13 +1180,12 @@ pswitch(flag)
|
||||
}
|
||||
ip->connect = connected;
|
||||
connected = op->connect;
|
||||
|
||||
if (ip->name)
|
||||
free (ip->name);
|
||||
ip->name = hostname;
|
||||
if (hostname) {
|
||||
(void) strncpy(ip->name, hostname, sizeof(ip->name) - 1);
|
||||
ip->name[strlen(ip->name)] = '\0';
|
||||
} else
|
||||
ip->name[0] = 0;
|
||||
hostname = op->name;
|
||||
op->name = 0;
|
||||
|
||||
ip->hctl = hisctladdr;
|
||||
hisctladdr = op->hctl;
|
||||
ip->mctl = myctladdr;
|
||||
@@ -1341,19 +1216,12 @@ pswitch(flag)
|
||||
(void) strcpy(ntout, op->nto);
|
||||
ip->mapflg = mapflag;
|
||||
mapflag = op->mapflg;
|
||||
|
||||
if (ip->mi)
|
||||
free (ip->mi);
|
||||
ip->mi = mapin;
|
||||
mapin = op->mi;
|
||||
op->mi = 0;
|
||||
|
||||
if (ip->mo)
|
||||
free (ip->mo);
|
||||
ip->mo = mapout;
|
||||
mapout = op->mo;
|
||||
op->mo = 0;
|
||||
|
||||
(void) strncpy(ip->mi, mapin, MAXPATHLEN - 1);
|
||||
(ip->mi)[strlen(ip->mi)] = '\0';
|
||||
(void) strcpy(mapin, op->mi);
|
||||
(void) strncpy(ip->mo, mapout, MAXPATHLEN - 1);
|
||||
(ip->mo)[strlen(ip->mo)] = '\0';
|
||||
(void) strcpy(mapout, op->mo);
|
||||
(void) signal(SIGINT, oldintr);
|
||||
if (abrtflag) {
|
||||
abrtflag = 0;
|
||||
@@ -1362,8 +1230,7 @@ pswitch(flag)
|
||||
}
|
||||
|
||||
void
|
||||
abortpt(sig)
|
||||
int sig;
|
||||
abortpt()
|
||||
{
|
||||
|
||||
printf("\n");
|
||||
@@ -1381,7 +1248,7 @@ proxtrans(cmd, local, remote)
|
||||
sig_t oldintr;
|
||||
int secndflag = 0, prox_type, nfnd;
|
||||
char *cmd2;
|
||||
fd_set mask;
|
||||
struct fd_set mask;
|
||||
|
||||
if (strcmp(cmd, "RETR"))
|
||||
cmd2 = "RETR";
|
||||
@@ -1498,7 +1365,7 @@ reset(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
fd_set mask;
|
||||
struct fd_set mask;
|
||||
int nfnd = 1;
|
||||
|
||||
FD_ZERO(&mask);
|
||||
@@ -1519,7 +1386,7 @@ char *
|
||||
gunique(local)
|
||||
char *local;
|
||||
{
|
||||
static char *new = 0;
|
||||
static char new[MAXPATHLEN];
|
||||
char *cp = strrchr(local, '/');
|
||||
int d, count=0;
|
||||
char ext = '1';
|
||||
@@ -1533,21 +1400,12 @@ gunique(local)
|
||||
warn("local: %s", local);
|
||||
return ((char *) 0);
|
||||
}
|
||||
|
||||
if (new)
|
||||
free (new);
|
||||
new = malloc (strlen (local) + 1 + 3 + 1); /* '.' + 100 + '\0' */
|
||||
if (! new) {
|
||||
printf ("gunique: malloc failed.\n");
|
||||
return 0;
|
||||
}
|
||||
strcpy (new, local);
|
||||
|
||||
(void) strcpy(new, local);
|
||||
cp = new + strlen(new);
|
||||
*cp++ = '.';
|
||||
while (!d) {
|
||||
if (++count == 100) {
|
||||
printf("runique: can't find unique file name.\n");
|
||||
printf("runique: can't find unique file name.\n");
|
||||
return ((char *) 0);
|
||||
}
|
||||
*cp++ = ext;
|
||||
@@ -1576,7 +1434,7 @@ abort_remote(din)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
int nfnd;
|
||||
fd_set mask;
|
||||
struct fd_set mask;
|
||||
|
||||
/*
|
||||
* send IAC in urgent mode instead of DM because 4.3BSD places oob mark
|
||||
|
||||
114
ftp/ftp_var.h
114
ftp/ftp_var.h
@@ -30,7 +30,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ftp_var.h 8.4 (Berkeley) 10/9/94
|
||||
* @(#)ftp_var.h 8.3 (Berkeley) 4/2/94
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -42,69 +42,65 @@
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#ifndef FTP_EXTERN
|
||||
#define FTP_EXTERN extern
|
||||
#endif
|
||||
/*
|
||||
* Options and other state info.
|
||||
*/
|
||||
FTP_EXTERN int trace; /* trace packets exchanged */
|
||||
FTP_EXTERN int hash; /* print # for each buffer transferred */
|
||||
FTP_EXTERN int sendport; /* use PORT cmd for each data connection */
|
||||
FTP_EXTERN int verbose; /* print messages coming back from server */
|
||||
FTP_EXTERN int connected; /* connected to server */
|
||||
FTP_EXTERN int fromatty; /* input is from a terminal */
|
||||
FTP_EXTERN int interactive; /* interactively prompt on m* cmds */
|
||||
FTP_EXTERN int debug; /* debugging level */
|
||||
FTP_EXTERN int bell; /* ring bell on cmd completion */
|
||||
FTP_EXTERN int doglob; /* glob local file names */
|
||||
FTP_EXTERN int autologin; /* establish user account on connection */
|
||||
FTP_EXTERN int proxy; /* proxy server connection active */
|
||||
FTP_EXTERN int proxflag; /* proxy connection exists */
|
||||
FTP_EXTERN int sunique; /* store files on server with unique name */
|
||||
FTP_EXTERN int runique; /* store local files with unique name */
|
||||
FTP_EXTERN int mcase; /* map upper to lower case for mget names */
|
||||
FTP_EXTERN int ntflag; /* use ntin ntout tables for name translation */
|
||||
FTP_EXTERN int mapflag; /* use mapin mapout templates on file names */
|
||||
FTP_EXTERN int code; /* return/reply code for ftp command */
|
||||
FTP_EXTERN int crflag; /* if 1, strip car. rets. on ascii gets */
|
||||
FTP_EXTERN char pasv[64]; /* passive port for proxy data connection */
|
||||
FTP_EXTERN int passivemode; /* passive mode enabled */
|
||||
FTP_EXTERN char *altarg; /* argv[1] with no shell-like preprocessing */
|
||||
FTP_EXTERN char ntin[17]; /* input translation table */
|
||||
FTP_EXTERN char ntout[17]; /* output translation table */
|
||||
extern char *mapin; /* input map template */
|
||||
extern char *mapout; /* output map template */
|
||||
FTP_EXTERN char typename[32]; /* name of file transfer type */
|
||||
FTP_EXTERN int type; /* requested file transfer type */
|
||||
FTP_EXTERN int curtype; /* current file transfer type */
|
||||
FTP_EXTERN char structname[32]; /* name of file transfer structure */
|
||||
FTP_EXTERN int stru; /* file transfer structure */
|
||||
FTP_EXTERN char formname[32]; /* name of file transfer format */
|
||||
FTP_EXTERN int form; /* file transfer format */
|
||||
FTP_EXTERN char modename[32]; /* name of file transfer mode */
|
||||
FTP_EXTERN int mode; /* file transfer mode */
|
||||
FTP_EXTERN char bytename[32]; /* local byte size in ascii */
|
||||
FTP_EXTERN int bytesize; /* local byte size in binary */
|
||||
int trace; /* trace packets exchanged */
|
||||
int hash; /* print # for each buffer transferred */
|
||||
int sendport; /* use PORT cmd for each data connection */
|
||||
int verbose; /* print messages coming back from server */
|
||||
int connected; /* connected to server */
|
||||
int fromatty; /* input is from a terminal */
|
||||
int interactive; /* interactively prompt on m* cmds */
|
||||
int debug; /* debugging level */
|
||||
int bell; /* ring bell on cmd completion */
|
||||
int doglob; /* glob local file names */
|
||||
int autologin; /* establish user account on connection */
|
||||
int proxy; /* proxy server connection active */
|
||||
int proxflag; /* proxy connection exists */
|
||||
int sunique; /* store files on server with unique name */
|
||||
int runique; /* store local files with unique name */
|
||||
int mcase; /* map upper to lower case for mget names */
|
||||
int ntflag; /* use ntin ntout tables for name translation */
|
||||
int mapflag; /* use mapin mapout templates on file names */
|
||||
int code; /* return/reply code for ftp command */
|
||||
int crflag; /* if 1, strip car. rets. on ascii gets */
|
||||
char pasv[64]; /* passive port for proxy data connection */
|
||||
char *altarg; /* argv[1] with no shell-like preprocessing */
|
||||
char ntin[17]; /* input translation table */
|
||||
char ntout[17]; /* output translation table */
|
||||
char mapin[MAXPATHLEN]; /* input map template */
|
||||
char mapout[MAXPATHLEN]; /* output map template */
|
||||
char typename[32]; /* name of file transfer type */
|
||||
int type; /* requested file transfer type */
|
||||
int curtype; /* current file transfer type */
|
||||
char structname[32]; /* name of file transfer structure */
|
||||
int stru; /* file transfer structure */
|
||||
char formname[32]; /* name of file transfer format */
|
||||
int form; /* file transfer format */
|
||||
char modename[32]; /* name of file transfer mode */
|
||||
int mode; /* file transfer mode */
|
||||
char bytename[32]; /* local byte size in ascii */
|
||||
int bytesize; /* local byte size in binary */
|
||||
|
||||
FTP_EXTERN char *hostname; /* name of host connected to */
|
||||
FTP_EXTERN int unix_server; /* server is unix, can use binary for ascii */
|
||||
FTP_EXTERN int unix_proxy; /* proxy is unix, can use binary for ascii */
|
||||
char *hostname; /* name of host connected to */
|
||||
int unix_server; /* server is unix, can use binary for ascii */
|
||||
int unix_proxy; /* proxy is unix, can use binary for ascii */
|
||||
|
||||
FTP_EXTERN struct servent *sp; /* service spec for tcp/ftp */
|
||||
struct servent *sp; /* service spec for tcp/ftp */
|
||||
|
||||
FTP_EXTERN jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
|
||||
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
|
||||
|
||||
FTP_EXTERN char line[200]; /* input line buffer */
|
||||
FTP_EXTERN char *stringbase; /* current scan point in line buffer */
|
||||
FTP_EXTERN char argbuf[200]; /* argument storage buffer */
|
||||
FTP_EXTERN char *argbase; /* current storage point in arg buffer */
|
||||
FTP_EXTERN int margc; /* count of arguments on input line */
|
||||
FTP_EXTERN char *margv[20]; /* args parsed from input line */
|
||||
FTP_EXTERN int cpend; /* flag: if != 0, then pending server reply */
|
||||
FTP_EXTERN int mflag; /* flag: if != 0, then active multi command */
|
||||
char line[200]; /* input line buffer */
|
||||
char *stringbase; /* current scan point in line buffer */
|
||||
char argbuf[200]; /* argument storage buffer */
|
||||
char *argbase; /* current storage point in arg buffer */
|
||||
int margc; /* count of arguments on input line */
|
||||
char *margv[20]; /* args parsed from input line */
|
||||
int cpend; /* flag: if != 0, then pending server reply */
|
||||
int mflag; /* flag: if != 0, then active multi command */
|
||||
|
||||
FTP_EXTERN int options; /* used during socket creation */
|
||||
int options; /* used during socket creation */
|
||||
|
||||
/*
|
||||
* Format of command table.
|
||||
@@ -124,6 +120,6 @@ struct macel {
|
||||
char *mac_end; /* end of macro in macbuf */
|
||||
};
|
||||
|
||||
FTP_EXTERN int macnum; /* number of defined macros */
|
||||
FTP_EXTERN struct macel macros[16];
|
||||
FTP_EXTERN char macbuf[4096];
|
||||
int macnum; /* number of defined macros */
|
||||
struct macel macros[16];
|
||||
char macbuf[4096];
|
||||
|
||||
129
ftp/main.c
129
ftp/main.c
@@ -38,17 +38,12 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 4/3/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* FTP User Program -- Command Interface.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/*#include <sys/ioctl.h>*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -63,73 +58,9 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <version.h>
|
||||
|
||||
/* Define macro to nothing so declarations in ftp_var.h become definitions. */
|
||||
#define FTP_EXTERN
|
||||
#include "ftp_var.h"
|
||||
|
||||
#define USAGE "Usage: %s [OPTION...] [HOST [PORT]]\n"
|
||||
|
||||
/* basename (argv[0]). NetBSD, linux, & gnu libc all define it. */
|
||||
extern char *__progname;
|
||||
|
||||
#define DEFAULT_PROMPT "ftp> "
|
||||
static char *prompt = 0;
|
||||
|
||||
/* Print a help message describing all options to STDOUT and exit with a
|
||||
status of 0. */
|
||||
static void
|
||||
ohelp ()
|
||||
{
|
||||
fprintf (stdout, USAGE, __progname);
|
||||
puts ("Remote file transfer\n\n\
|
||||
-d, --debug Turn on debugging mode\n\
|
||||
-g, --no-glob Turn off file name globbing\n\
|
||||
-i, --no-prompt Don't prompt during multiple-file transfers\n\
|
||||
-n, --no-login Don't automatically login to the remove system\n\
|
||||
-t, --trace Enable packet tracing\n\
|
||||
-p, --prompt[=PROMPT] Print a command-line prompt (optionally PROMPT),\n\
|
||||
even if not on a tty\n\
|
||||
-v, --verbose Be verbose\n\
|
||||
--help Give this help list\n\
|
||||
--version Print program version");
|
||||
fprintf (stdout, "\nSubmit bug reports to %s.\n", inetutils_bugaddr);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
/* Print a message saying to use --help to STDERR, and exit with a status of
|
||||
1. */
|
||||
static void
|
||||
try_help ()
|
||||
{
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", __progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* Print a usage message to STDERR and exit with a status of 1. */
|
||||
static void
|
||||
usage ()
|
||||
{
|
||||
fprintf (stderr, USAGE, __progname);
|
||||
try_help ();
|
||||
}
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{ "trace", no_argument, 0, 't' },
|
||||
{ "verbose", no_argument, 0, 'v' },
|
||||
{ "no-login", no_argument, 0, 'n' },
|
||||
{ "no-prompt", no_argument, 0, 'i' },
|
||||
{ "debug", no_argument, 0, 'd' },
|
||||
{ "no-glob", no_argument, 0, 'g' },
|
||||
{ "help", no_argument, 0, '&' },
|
||||
{ "prompt", optional_argument, 0, 'p' },
|
||||
{ "version", no_argument, 0, 'V' },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
@@ -137,12 +68,7 @@ main(argc, argv)
|
||||
{
|
||||
int ch, top;
|
||||
struct passwd *pw = NULL;
|
||||
char *cp;
|
||||
|
||||
#ifndef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
__progname = argv[0];
|
||||
#endif
|
||||
char *cp, homedir[MAXPATHLEN];
|
||||
|
||||
sp = getservbyname("ftp", "tcp");
|
||||
if (sp == 0)
|
||||
@@ -151,10 +77,8 @@ main(argc, argv)
|
||||
interactive = 1;
|
||||
autologin = 1;
|
||||
|
||||
while ((ch = getopt_long (argc, argv, "dginp::tv", long_options, 0))
|
||||
!= EOF)
|
||||
{
|
||||
switch (ch) {
|
||||
while ((ch = getopt(argc, argv, "dgintv")) != EOF) {
|
||||
switch (*cp) {
|
||||
case 'd':
|
||||
options |= SO_DEBUG;
|
||||
debug++;
|
||||
@@ -180,37 +104,20 @@ main(argc, argv)
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
prompt = optarg ? optarg : DEFAULT_PROMPT;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
ohelp ();
|
||||
case 'V':
|
||||
printf ("ftp (%s) %s\n",
|
||||
inetutils_package, inetutils_version);
|
||||
exit (0);
|
||||
|
||||
case '?':
|
||||
try_help ();
|
||||
|
||||
default:
|
||||
usage ();
|
||||
(void)fprintf(stderr,
|
||||
"usage: ftp [-dgintv] [host [port]]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
fromatty = isatty(fileno(stdin));
|
||||
if (fromatty) {
|
||||
if (fromatty)
|
||||
verbose++;
|
||||
if (! prompt)
|
||||
prompt = DEFAULT_PROMPT;
|
||||
}
|
||||
|
||||
cpend = 0; /* no pending replies */
|
||||
proxy = 0; /* proxy not active */
|
||||
passivemode = 0; /* passive mode not active */
|
||||
crflag = 1; /* strip c.r. on ascii gets */
|
||||
sendport = -1; /* not using ports */
|
||||
/*
|
||||
@@ -223,11 +130,8 @@ main(argc, argv)
|
||||
if (pw == NULL)
|
||||
pw = getpwuid(getuid());
|
||||
if (pw != NULL) {
|
||||
char *buf = malloc (strlen (pw->pw_dir) + 1);
|
||||
if (buf) {
|
||||
strcpy(buf, pw->pw_dir);
|
||||
home = buf;
|
||||
}
|
||||
home = homedir;
|
||||
(void) strcpy(home, pw->pw_dir);
|
||||
}
|
||||
if (argc > 0) {
|
||||
char *xargv[5];
|
||||
@@ -256,16 +160,14 @@ main(argc, argv)
|
||||
}
|
||||
|
||||
void
|
||||
intr(sig)
|
||||
int sig;
|
||||
intr()
|
||||
{
|
||||
|
||||
longjmp(toplevel, 1);
|
||||
}
|
||||
|
||||
void
|
||||
lostpeer(sig)
|
||||
int sig;
|
||||
lostpeer()
|
||||
{
|
||||
|
||||
if (connected) {
|
||||
@@ -326,11 +228,10 @@ cmdscanner(top)
|
||||
if (!top)
|
||||
(void) putchar('\n');
|
||||
for (;;) {
|
||||
if (prompt) {
|
||||
printf (prompt);
|
||||
fflush(stdout);
|
||||
if (fromatty) {
|
||||
printf("ftp> ");
|
||||
(void) fflush(stdout);
|
||||
}
|
||||
|
||||
if (fgets(line, sizeof line, stdin) == NULL)
|
||||
quit(0, 0);
|
||||
l = strlen(line);
|
||||
|
||||
@@ -32,33 +32,22 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
|
||||
static char sccsid[] = "@(#)ruserpass.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <err.h>
|
||||
|
||||
#include "ftp_var.h"
|
||||
|
||||
extern char *localhost __P((void));
|
||||
|
||||
static int token __P((void));
|
||||
static FILE *cfile;
|
||||
|
||||
@@ -91,25 +80,22 @@ ruserpass(host, aname, apass, aacct)
|
||||
char *host, **aname, **apass, **aacct;
|
||||
{
|
||||
char *hdir, buf[BUFSIZ], *tmp;
|
||||
char *myname = 0, *mydomain;
|
||||
char myname[MAXHOSTNAMELEN], *mydomain;
|
||||
int t, i, c, usedefault = 0;
|
||||
struct stat stb;
|
||||
|
||||
hdir = getenv("HOME");
|
||||
if (hdir == NULL)
|
||||
hdir = ".";
|
||||
snprintf (buf, sizeof buf, "%s/.netrc", hdir);
|
||||
(void) sprintf(buf, "%s/.netrc", hdir);
|
||||
cfile = fopen(buf, "r");
|
||||
if (cfile == NULL) {
|
||||
if (errno != ENOENT)
|
||||
warn("%s", buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
myname = localhost ();
|
||||
if (! myname)
|
||||
myname = "";
|
||||
|
||||
if (gethostname(myname, sizeof(myname)) < 0)
|
||||
myname[0] = '\0';
|
||||
if ((mydomain = strchr(myname, '.')) == NULL)
|
||||
mydomain = "";
|
||||
next:
|
||||
@@ -158,7 +144,7 @@ next:
|
||||
}
|
||||
break;
|
||||
case PASSWD:
|
||||
if ((*aname == NULL || strcmp(*aname, "anonymous")) &&
|
||||
if (strcmp(*aname, "anonymous") &&
|
||||
fstat(fileno(cfile), &stb) >= 0 &&
|
||||
(stb.st_mode & 077) != 0) {
|
||||
warnx("Error: .netrc file is readable by others.");
|
||||
@@ -183,9 +169,10 @@ next:
|
||||
}
|
||||
break;
|
||||
case MACDEF:
|
||||
if (proxy)
|
||||
goto done;
|
||||
|
||||
if (proxy) {
|
||||
(void) fclose(cfile);
|
||||
return (0);
|
||||
}
|
||||
while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
|
||||
if (c == EOF || c == '\n') {
|
||||
printf("Missing macdef name argument.\n");
|
||||
@@ -248,13 +235,9 @@ next:
|
||||
}
|
||||
done:
|
||||
(void) fclose(cfile);
|
||||
if (myname && *myname)
|
||||
free (myname);
|
||||
return (0);
|
||||
bad:
|
||||
(void) fclose(cfile);
|
||||
if (myname && *myname)
|
||||
free (myname);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ void dologout __P((int));
|
||||
void fatal __P((char *));
|
||||
int ftpd_pclose __P((FILE *));
|
||||
FILE *ftpd_popen __P((char *, char *));
|
||||
char *telnet_fgets __P((char *, int, FILE *));
|
||||
void logwtmp __P((const char *, const char *, const char *));
|
||||
char *getline __P((char *, int, FILE *));
|
||||
void logwtmp __P((char *, char *, char *));
|
||||
void lreply __P((int, const char *, ...));
|
||||
void makedir __P((char *));
|
||||
void nack __P((char *));
|
||||
@@ -63,7 +63,3 @@ void store __P((char *, char *, int));
|
||||
void upper __P((char *));
|
||||
void user __P((char *));
|
||||
void yyerror __P((char *));
|
||||
|
||||
#ifndef HAVE_GETUSERSHELL_DECL
|
||||
extern char * getusershell __P((void));
|
||||
#endif
|
||||
|
||||
148
ftpd/ftpcmd.y
148
ftpd/ftpcmd.y
@@ -44,11 +44,6 @@
|
||||
static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -58,6 +53,7 @@ static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <pwd.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
@@ -65,31 +61,11 @@ static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_SYS_UTSNAME_H
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
/* Include glob.h last, because it may define "const" which breaks
|
||||
system headers on some platforms. */
|
||||
#include <glob.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#if ! defined (NBBY) && defined (CHAR_BIT)
|
||||
#define NBBY CHAR_BIT
|
||||
#endif
|
||||
|
||||
extern struct sockaddr_in data_dest;
|
||||
extern int logged_in;
|
||||
extern struct passwd *pw;
|
||||
@@ -101,7 +77,7 @@ extern int debug;
|
||||
extern int timeout;
|
||||
extern int maxtimeout;
|
||||
extern int pdata;
|
||||
extern char *hostname, *remotehost;
|
||||
extern char hostname[], remotehost[];
|
||||
extern char proctitle[];
|
||||
extern int usedefault;
|
||||
extern int transflag;
|
||||
@@ -115,24 +91,6 @@ static int cmd_bytesz;
|
||||
char cbuf[512];
|
||||
char *fromname;
|
||||
|
||||
struct tab {
|
||||
char *name;
|
||||
short token;
|
||||
short state;
|
||||
short implemented; /* 1 if command is implemented */
|
||||
char *help;
|
||||
};
|
||||
|
||||
extern struct tab cmdtab[], sitetab[];
|
||||
|
||||
static char *copy __P((char *));
|
||||
static void help __P((struct tab *, char *));
|
||||
static struct tab *
|
||||
lookup __P((struct tab *, char *));
|
||||
static void sizecmd __P((char *));
|
||||
static void toolong __P((int));
|
||||
static int yylex __P((void));
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
@@ -199,10 +157,7 @@ cmd
|
||||
}
|
||||
reply(200, "PORT command successful.");
|
||||
}
|
||||
/* telnet to ftpd and type PASV, server will crash
|
||||
* *Hobbit
|
||||
*/
|
||||
| PASV check_login CRLF
|
||||
| PASV CRLF
|
||||
{
|
||||
passive();
|
||||
}
|
||||
@@ -229,7 +184,7 @@ cmd
|
||||
break;
|
||||
|
||||
case TYPE_L:
|
||||
#if defined (NBBY) && NBBY == 8
|
||||
#if NBBY == 8
|
||||
if (cmd_bytesz == 8) {
|
||||
reply(200,
|
||||
"Type set to L (byte size 8).");
|
||||
@@ -465,11 +420,6 @@ cmd
|
||||
}
|
||||
| SITE SP IDLE SP NUMBER CRLF
|
||||
{
|
||||
if (!guest && $5 == 0) {
|
||||
timeout = 0;
|
||||
alarm (0);
|
||||
reply (200, "IDLE time limit disabled");
|
||||
}
|
||||
if ($5 < 30 || $5 > maxtimeout) {
|
||||
reply(501,
|
||||
"Maximum IDLE time must be between 30 and %d seconds",
|
||||
@@ -491,41 +441,16 @@ cmd
|
||||
}
|
||||
| SYST CRLF
|
||||
{
|
||||
char *type; /* The official rfc-defined os type. */
|
||||
char *version = 0; /* A more specific type. */
|
||||
|
||||
#ifdef HAVE_UNAME
|
||||
struct utsname u;
|
||||
if (uname (&u) == 0) {
|
||||
version =
|
||||
malloc (strlen (u.sysname)
|
||||
+ 1 + strlen (u.release) + 1);
|
||||
if (version)
|
||||
sprintf (version, "%s %s",
|
||||
u.sysname, u.release);
|
||||
}
|
||||
#else
|
||||
#ifdef BSD
|
||||
version = "BSD";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef unix
|
||||
type = "UNIX";
|
||||
#else
|
||||
type = "UNKNOWN";
|
||||
#endif
|
||||
|
||||
if (version)
|
||||
reply(215, "%s Type: L%d Version: %s",
|
||||
type, NBBY, version);
|
||||
else
|
||||
reply(215, "%s Type: L%d", type, NBBY);
|
||||
|
||||
#ifdef HAVE_UNAME
|
||||
if (version)
|
||||
free (version);
|
||||
#endif
|
||||
#ifdef BSD
|
||||
reply(215, "UNIX Type: L%d Version: BSD-%d",
|
||||
NBBY, BSD);
|
||||
#else /* BSD */
|
||||
reply(215, "UNIX Type: L%d", NBBY);
|
||||
#endif /* BSD */
|
||||
#else /* unix */
|
||||
reply(215, "UNKNOWN Type: L%d", NBBY);
|
||||
#endif /* unix */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -600,10 +525,7 @@ rcmd
|
||||
{
|
||||
fromname = (char *) 0;
|
||||
restart_point = $3; /* XXX $3 is only "int" */
|
||||
reply(350,
|
||||
(sizeof(restart_point) > sizeof(long)
|
||||
? "Restarting at %qd. %s"
|
||||
: "Restarting at %ld. %s"), restart_point,
|
||||
reply(350, "Restarting at %qd. %s", restart_point,
|
||||
"Send STORE or RETRIEVE to initiate transfer.");
|
||||
}
|
||||
;
|
||||
@@ -736,17 +658,8 @@ pathname
|
||||
*/
|
||||
if (logged_in && $1 && *$1 == '~') {
|
||||
glob_t gl;
|
||||
int flags = GLOB_NOCHECK;
|
||||
|
||||
#ifdef GLOB_BRACE
|
||||
flags |= GLOB_BRACE;
|
||||
#endif
|
||||
#ifdef GLOB_QUOTE
|
||||
flags |= GLOB_QUOTE;
|
||||
#endif
|
||||
#ifdef GLOB_TILDE
|
||||
flags |= GLOB_TILDE;
|
||||
#endif
|
||||
int flags =
|
||||
GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
if (glob($1, flags, NULL, &gl) ||
|
||||
@@ -820,6 +733,14 @@ extern jmp_buf errcatch;
|
||||
#define SITECMD 7 /* SITE command */
|
||||
#define NSTR 8 /* Number followed by a string */
|
||||
|
||||
struct tab {
|
||||
char *name;
|
||||
short token;
|
||||
short state;
|
||||
short implemented; /* 1 if command is implemented */
|
||||
char *help;
|
||||
};
|
||||
|
||||
struct tab cmdtab[] = { /* In order defined in RFC 765 */
|
||||
{ "USER", USER, STR1, 1, "<sp> username" },
|
||||
{ "PASS", PASS, ZSTR1, 1, "<sp> password" },
|
||||
@@ -879,6 +800,14 @@ struct tab sitetab[] = {
|
||||
{ NULL, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static char *copy __P((char *));
|
||||
static void help __P((struct tab *, char *));
|
||||
static struct tab *
|
||||
lookup __P((struct tab *, char *));
|
||||
static void sizecmd __P((char *));
|
||||
static void toolong __P((int));
|
||||
static int yylex __P((void));
|
||||
|
||||
static struct tab *
|
||||
lookup(p, cmd)
|
||||
struct tab *p;
|
||||
@@ -897,7 +826,7 @@ lookup(p, cmd)
|
||||
* getline - a hacked up version of fgets to ignore TELNET escape codes.
|
||||
*/
|
||||
char *
|
||||
telnet_fgets(s, n, iop)
|
||||
getline(s, n, iop)
|
||||
char *s;
|
||||
int n;
|
||||
FILE *iop;
|
||||
@@ -1000,7 +929,7 @@ yylex()
|
||||
case CMD:
|
||||
(void) signal(SIGALRM, toolong);
|
||||
(void) alarm((unsigned) timeout);
|
||||
if (telnet_fgets(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
|
||||
if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
|
||||
reply(221, "You could at least say goodbye.");
|
||||
dologout(0);
|
||||
}
|
||||
@@ -1303,9 +1232,7 @@ sizecmd(filename)
|
||||
if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
|
||||
reply(550, "%s: not a plain file.", filename);
|
||||
else
|
||||
reply(213,
|
||||
(sizeof (stbuf.st_size) > sizeof(long)
|
||||
? "%qu" : "%lu"), stbuf.st_size);
|
||||
reply(213, "%qu", stbuf.st_size);
|
||||
break; }
|
||||
case TYPE_A: {
|
||||
FILE *fin;
|
||||
@@ -1331,8 +1258,7 @@ sizecmd(filename)
|
||||
}
|
||||
(void) fclose(fin);
|
||||
|
||||
reply(213, sizeof(count) > sizeof(long) ? "%qd" : "%ld",
|
||||
count);
|
||||
reply(213, "%qd", count);
|
||||
break; }
|
||||
default:
|
||||
reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ftpd.8 8.3 (Berkeley) 6/1/94
|
||||
.\" @(#)ftpd.8 8.2 (Berkeley) 4/19/94
|
||||
.\"
|
||||
.Dd June 1, 1994
|
||||
.Dd April 19, 1994
|
||||
.Dt FTPD 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -228,7 +228,6 @@ subtree be constructed with care, following these rules:
|
||||
Make the home directory owned by
|
||||
.Dq root
|
||||
and unwritable by anyone.
|
||||
.ne 1i
|
||||
.It Pa ~ftp/bin
|
||||
Make this directory owned by
|
||||
.Dq root
|
||||
|
||||
564
ftpd/ftpd.c
564
ftpd/ftpd.c
@@ -38,34 +38,12 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ftpd.c 8.5 (Berkeley) 4/28/95";
|
||||
static char sccsid[] = "@(#)ftpd.c 8.4 (Berkeley) 4/16/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* FTP server.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined (__GNUC__) && defined (_AIX)
|
||||
#pragma alloca
|
||||
#endif
|
||||
#ifndef alloca /* Make alloca work the best possible way. */
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#else /* not __GNUC__ */
|
||||
#if HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#else /* not __GNUC__ or HAVE_ALLOCA_H */
|
||||
#ifndef _AIX /* Already did AIX, up at the top. */
|
||||
char *alloca ();
|
||||
#endif /* not _AIX */
|
||||
#endif /* not HAVE_ALLOCA_H */
|
||||
#endif /* not __GNUC__ */
|
||||
#endif /* not alloca */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -73,12 +51,8 @@ char *alloca ();
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
#define FTP_NAMES
|
||||
#include <arpa/ftp.h>
|
||||
@@ -87,54 +61,32 @@ char *alloca ();
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <pwd.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <crypt.h>
|
||||
/* Include glob.h last, because it may define "const" which breaks
|
||||
system headers on some platforms. */
|
||||
#include <glob.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
#include "extern.h"
|
||||
#include "version.h"
|
||||
|
||||
#ifndef LINE_MAX
|
||||
#define LINE_MAX 2048
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifndef LOG_FTP
|
||||
#define LOG_FTP LOG_DAEMON /* Use generic facility. */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FCLOSE_DECL
|
||||
/* Some systems don't declare fclose in <stdio.h>, so do it ourselves. */
|
||||
extern int fclose __P ((FILE *));
|
||||
#endif
|
||||
static char version[] = "Version 6.00";
|
||||
|
||||
extern off_t restart_point;
|
||||
extern char cbuf[];
|
||||
@@ -169,35 +121,8 @@ off_t byte_count;
|
||||
#endif
|
||||
int defumask = CMASK; /* default umask value */
|
||||
char tmpline[7];
|
||||
char *hostname = 0;
|
||||
char *remotehost = 0;
|
||||
|
||||
#define NUM_SIMUL_OFF_TO_STRS 4
|
||||
|
||||
/* Returns a string with the decimal representation of the off_t OFF, taking
|
||||
into account that off_t might be longer than a long. The return value is
|
||||
a pointer to a static buffer, but a return value will only be reused every
|
||||
NUM_SIMUL_OFF_TO_STRS calls, to allow multiple off_t's to be conveniently
|
||||
printed with a single printf statement. */
|
||||
static char *
|
||||
off_to_str (off)
|
||||
off_t off;
|
||||
{
|
||||
static char bufs[NUM_SIMUL_OFF_TO_STRS][80];
|
||||
static char (*next_buf)[80] = bufs;
|
||||
|
||||
if (next_buf > (bufs+NUM_SIMUL_OFF_TO_STRS))
|
||||
next_buf = bufs;
|
||||
|
||||
if (sizeof (off) > sizeof (long))
|
||||
sprintf (*next_buf, "%qd", off);
|
||||
else if (sizeof (off) == sizeof (long))
|
||||
sprintf (*next_buf, "%ld", off);
|
||||
else
|
||||
sprintf (*next_buf, "%d", off);
|
||||
|
||||
return *next_buf++;
|
||||
}
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
char remotehost[MAXHOSTNAMELEN];
|
||||
|
||||
/*
|
||||
* Timeout intervals for retrying connections
|
||||
@@ -231,9 +156,8 @@ char proctitle[LINE_MAX]; /* initial part of title */
|
||||
syslog(LOG_INFO,"%s %s%s", cmd, \
|
||||
*(file) == '/' ? "" : curdir(), file); \
|
||||
else \
|
||||
syslog(LOG_INFO, "%s %s%s = %s bytes", \
|
||||
cmd, (*(file) == '/') ? "" : curdir(), file, \
|
||||
off_to_str (cnt)); \
|
||||
syslog(LOG_INFO, "%s %s%s = %qd bytes", \
|
||||
cmd, (*(file) == '/') ? "" : curdir(), file, cnt); \
|
||||
}
|
||||
|
||||
static void ack __P((char *));
|
||||
@@ -255,19 +179,12 @@ static char *sgetsave __P((char *));
|
||||
static char *
|
||||
curdir()
|
||||
{
|
||||
static char *path = 0;
|
||||
if (path)
|
||||
free (path);
|
||||
path = getcwd (0, 0);
|
||||
if (! path)
|
||||
static char path[MAXPATHLEN+1+1]; /* path + '/' + '\0' */
|
||||
|
||||
if (getcwd(path, sizeof(path)-2) == NULL)
|
||||
return ("");
|
||||
if (path[1] != '\0') { /* special case for root dir. */
|
||||
char *new = realloc (path, strlen (path) + 2); /* '/' + '\0' */
|
||||
if (! new)
|
||||
return "";
|
||||
strcat(new, "/");
|
||||
path = new;
|
||||
}
|
||||
if (path[1] != '\0') /* special case for root dir. */
|
||||
strcat(path, "/");
|
||||
/* For guest account, skip / since it's chrooted */
|
||||
return (guest ? path+1 : path);
|
||||
}
|
||||
@@ -278,7 +195,6 @@ main(argc, argv, envp)
|
||||
char *argv[];
|
||||
char **envp;
|
||||
{
|
||||
extern char *localhost ();
|
||||
int addrlen, ch, on = 1, tos;
|
||||
char *cp, line[LINE_MAX];
|
||||
FILE *fd;
|
||||
@@ -298,7 +214,7 @@ main(argc, argv, envp)
|
||||
syslog(LOG_ERR, "getsockname (%s): %m",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
#if defined (IP_TOS) && defined (IPTOS_LOWDELAY) && defined (IPPROTO_IP)
|
||||
#ifdef IP_TOS
|
||||
tos = IPTOS_LOWDELAY;
|
||||
if (setsockopt(0, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
|
||||
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
|
||||
@@ -343,8 +259,7 @@ main(argc, argv, envp)
|
||||
|
||||
val = strtol(optarg, &optarg, 8);
|
||||
if (*optarg != '\0' || val < 0)
|
||||
fprintf (stderr,
|
||||
"%s: bad value for -u", argv[0]);
|
||||
warnx("bad value for -u");
|
||||
else
|
||||
defumask = val;
|
||||
break;
|
||||
@@ -355,12 +270,11 @@ main(argc, argv, envp)
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf (stderr,
|
||||
"%s: unknown flag -%c ignored", argv[0]);
|
||||
warnx("unknown flag -%c ignored", optopt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void) freopen(PATH_DEVNULL, "w", stderr);
|
||||
(void) freopen(_PATH_DEVNULL, "w", stderr);
|
||||
(void) signal(SIGPIPE, lostconn);
|
||||
(void) signal(SIGCHLD, SIG_IGN);
|
||||
if ((int)signal(SIGURG, myoob) < 0)
|
||||
@@ -388,7 +302,7 @@ main(argc, argv, envp)
|
||||
tmpline[0] = '\0';
|
||||
|
||||
/* If logins are disabled, print out the message. */
|
||||
if ((fd = fopen(PATH_NOLOGIN,"r")) != NULL) {
|
||||
if ((fd = fopen(_PATH_NOLOGIN,"r")) != NULL) {
|
||||
while (fgets(line, sizeof(line), fd) != NULL) {
|
||||
if ((cp = strchr(line, '\n')) != NULL)
|
||||
*cp = '\0';
|
||||
@@ -399,7 +313,7 @@ main(argc, argv, envp)
|
||||
reply(530, "System not available.");
|
||||
exit(0);
|
||||
}
|
||||
if ((fd = fopen(PATH_FTPWELCOME, "r")) != NULL) {
|
||||
if ((fd = fopen(_PATH_FTPWELCOME, "r")) != NULL) {
|
||||
while (fgets(line, sizeof(line), fd) != NULL) {
|
||||
if ((cp = strchr(line, '\n')) != NULL)
|
||||
*cp = '\0';
|
||||
@@ -409,13 +323,8 @@ main(argc, argv, envp)
|
||||
(void) fclose(fd);
|
||||
/* reply(220,) must follow */
|
||||
}
|
||||
|
||||
hostname = localhost ();
|
||||
if (! hostname)
|
||||
perror_reply (550, "Local resource failure: malloc");
|
||||
|
||||
reply(220, "%s FTP server (%s %s) ready.",
|
||||
hostname, inetutils_package, inetutils_version);
|
||||
(void) gethostname(hostname, sizeof(hostname));
|
||||
reply(220, "%s FTP server (%s) ready.", hostname, version);
|
||||
(void) setjmp(errcatch);
|
||||
for (;;)
|
||||
(void) yyparse();
|
||||
@@ -486,21 +395,141 @@ static int login_attempts; /* number of failed login attempts */
|
||||
static int askpasswd; /* had user command, ask for passwd */
|
||||
static char curname[10]; /* current USER name */
|
||||
|
||||
static void
|
||||
complete_login (passwd)
|
||||
char *passwd;
|
||||
/*
|
||||
* USER command.
|
||||
* Sets global passwd pointer pw if named account exists and is acceptable;
|
||||
* sets askpasswd if a PASS command is expected. If logged in previously,
|
||||
* need to reset state. If name is "ftp" or "anonymous", the name is not in
|
||||
* _PATH_FTPUSERS, and ftp account exists, set guest and pw, then just return.
|
||||
* If account doesn't exist, ask for passwd anyway. Otherwise, check user
|
||||
* requesting login privileges. Disallow anyone who does not have a standard
|
||||
* shell as returned by getusershell(). Disallow anyone mentioned in the file
|
||||
* _PATH_FTPUSERS to allow people such as root and uucp to be avoided.
|
||||
*/
|
||||
void
|
||||
user(name)
|
||||
char *name;
|
||||
{
|
||||
char *cp, *shell;
|
||||
|
||||
if (logged_in) {
|
||||
if (guest) {
|
||||
reply(530, "Can't change user from guest login.");
|
||||
return;
|
||||
}
|
||||
end_login();
|
||||
}
|
||||
|
||||
guest = 0;
|
||||
if (strcmp(name, "ftp") == 0 || strcmp(name, "anonymous") == 0) {
|
||||
if (checkuser("ftp") || checkuser("anonymous"))
|
||||
reply(530, "User %s access denied.", name);
|
||||
else if ((pw = sgetpwnam("ftp")) != NULL) {
|
||||
guest = 1;
|
||||
askpasswd = 1;
|
||||
reply(331,
|
||||
"Guest login ok, type your name as password.");
|
||||
} else
|
||||
reply(530, "User %s unknown.", name);
|
||||
if (!askpasswd && logging)
|
||||
syslog(LOG_NOTICE,
|
||||
"ANONYMOUS FTP LOGIN REFUSED FROM %s", remotehost);
|
||||
return;
|
||||
}
|
||||
if (pw = sgetpwnam(name)) {
|
||||
if ((shell = pw->pw_shell) == NULL || *shell == 0)
|
||||
shell = _PATH_BSHELL;
|
||||
while ((cp = getusershell()) != NULL)
|
||||
if (strcmp(cp, shell) == 0)
|
||||
break;
|
||||
endusershell();
|
||||
|
||||
if (cp == NULL || checkuser(name)) {
|
||||
reply(530, "User %s access denied.", name);
|
||||
if (logging)
|
||||
syslog(LOG_NOTICE,
|
||||
"FTP LOGIN REFUSED FROM %s, %s",
|
||||
remotehost, name);
|
||||
pw = (struct passwd *) NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (logging)
|
||||
strncpy(curname, name, sizeof(curname)-1);
|
||||
reply(331, "Password required for %s.", name);
|
||||
askpasswd = 1;
|
||||
/*
|
||||
* Delay before reading passwd after first failed
|
||||
* attempt to slow down passwd-guessing programs.
|
||||
*/
|
||||
if (login_attempts)
|
||||
sleep((unsigned) login_attempts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a user is in the file _PATH_FTPUSERS
|
||||
*/
|
||||
static int
|
||||
checkuser(name)
|
||||
char *name;
|
||||
{
|
||||
FILE *fd;
|
||||
int found = 0;
|
||||
char *p, line[BUFSIZ];
|
||||
|
||||
if (!guest && (!pw || *pw->pw_passwd)) {
|
||||
char *xpasswd;
|
||||
if ((fd = fopen(_PATH_FTPUSERS, "r")) != NULL) {
|
||||
while (fgets(line, sizeof(line), fd) != NULL)
|
||||
if ((p = strchr(line, '\n')) != NULL) {
|
||||
*p = '\0';
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
if (strcmp(p, name) == 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void) fclose(fd);
|
||||
}
|
||||
return (found);
|
||||
}
|
||||
|
||||
if (pw) {
|
||||
char *salt = pw->pw_passwd;
|
||||
xpasswd = CRYPT (passwd, salt);
|
||||
}
|
||||
/*
|
||||
* Terminate login as previous user, if any, resetting state;
|
||||
* used when USER command is given or login fails.
|
||||
*/
|
||||
static void
|
||||
end_login()
|
||||
{
|
||||
|
||||
if (!pw || !xpasswd || strcmp (xpasswd, pw->pw_passwd) != 0) {
|
||||
(void) seteuid((uid_t)0);
|
||||
if (logged_in)
|
||||
logwtmp(ttyline, "", "");
|
||||
pw = NULL;
|
||||
logged_in = 0;
|
||||
guest = 0;
|
||||
}
|
||||
|
||||
void
|
||||
pass(passwd)
|
||||
char *passwd;
|
||||
{
|
||||
char *salt, *xpasswd;
|
||||
FILE *fd;
|
||||
|
||||
if (logged_in || askpasswd == 0) {
|
||||
reply(503, "Login with USER first.");
|
||||
return;
|
||||
}
|
||||
askpasswd = 0;
|
||||
if (!guest) { /* "ftp" is only account allowed no password */
|
||||
if (pw == NULL)
|
||||
salt = "xx";
|
||||
else
|
||||
salt = pw->pw_passwd;
|
||||
xpasswd = crypt(passwd, salt);
|
||||
/* The strcmp does not catch null passwords! */
|
||||
if (pw == NULL || *pw->pw_passwd == '\0' ||
|
||||
strcmp(xpasswd, pw->pw_passwd)) {
|
||||
reply(530, "Login incorrect.");
|
||||
if (logging)
|
||||
syslog(LOG_NOTICE,
|
||||
@@ -516,7 +545,6 @@ complete_login (passwd)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
login_attempts = 0; /* this time successful */
|
||||
if (setegid((gid_t)pw->pw_gid) < 0) {
|
||||
reply(550, "Can't set gid.");
|
||||
@@ -526,7 +554,7 @@ complete_login (passwd)
|
||||
|
||||
/* open wtmp before chroot */
|
||||
(void)sprintf(ttyline, "ftp%d", getpid());
|
||||
logwtmp_keep_open (ttyline, pw->pw_name, remotehost);
|
||||
logwtmp(ttyline, pw->pw_name, remotehost);
|
||||
logged_in = 1;
|
||||
|
||||
if (guest) {
|
||||
@@ -555,7 +583,7 @@ complete_login (passwd)
|
||||
* Display a login message, if it exists.
|
||||
* N.B. reply(230,) must follow the message.
|
||||
*/
|
||||
if ((fd = fopen(PATH_FTPLOGINMESG, "r")) != NULL) {
|
||||
if ((fd = fopen(_PATH_FTPLOGINMESG, "r")) != NULL) {
|
||||
char *cp, line[LINE_MAX];
|
||||
|
||||
while (fgets(line, sizeof(line), fd) != NULL) {
|
||||
@@ -596,138 +624,6 @@ bad:
|
||||
end_login();
|
||||
}
|
||||
|
||||
/*
|
||||
* USER command.
|
||||
* Sets global passwd pointer pw if named account exists and is acceptable;
|
||||
* sets askpasswd if a PASS command is expected. If logged in previously,
|
||||
* need to reset state. If name is "ftp" or "anonymous", the name is not in
|
||||
* PATH_FTPUSERS, and ftp account exists, set guest and pw, then just return.
|
||||
* If account doesn't exist, ask for passwd anyway. Otherwise, check user
|
||||
* requesting login privileges. Disallow anyone who does not have a standard
|
||||
* shell as returned by getusershell(). Disallow anyone mentioned in the file
|
||||
* PATH_FTPUSERS to allow people such as root and uucp to be avoided.
|
||||
*/
|
||||
void
|
||||
user(name)
|
||||
char *name;
|
||||
{
|
||||
char *cp, *shell;
|
||||
|
||||
if (logged_in) {
|
||||
if (guest) {
|
||||
reply(530, "Can't change user from guest login.");
|
||||
return;
|
||||
}
|
||||
end_login();
|
||||
}
|
||||
|
||||
guest = 0;
|
||||
if (strcmp(name, "ftp") == 0 || strcmp(name, "anonymous") == 0) {
|
||||
if (checkuser("ftp") || checkuser("anonymous"))
|
||||
reply(530, "User %s access denied.", name);
|
||||
else if ((pw = sgetpwnam("ftp")) != NULL) {
|
||||
guest = 1;
|
||||
askpasswd = 1;
|
||||
reply(331,
|
||||
"Guest login ok, type your name as password.");
|
||||
} else
|
||||
reply(530, "User %s unknown.", name);
|
||||
if (!askpasswd && logging)
|
||||
syslog(LOG_NOTICE,
|
||||
"ANONYMOUS FTP LOGIN REFUSED FROM %s", remotehost);
|
||||
return;
|
||||
}
|
||||
if (pw = sgetpwnam(name)) {
|
||||
if ((shell = pw->pw_shell) == NULL || *shell == 0)
|
||||
shell = PATH_BSHELL;
|
||||
while ((cp = getusershell()) != NULL)
|
||||
if (strcmp(cp, shell) == 0)
|
||||
break;
|
||||
endusershell();
|
||||
|
||||
if (cp == NULL || checkuser(name)) {
|
||||
reply(530, "User %s access denied.", name);
|
||||
if (logging)
|
||||
syslog(LOG_NOTICE,
|
||||
"FTP LOGIN REFUSED FROM %s, %s",
|
||||
remotehost, name);
|
||||
pw = (struct passwd *) NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (logging)
|
||||
strncpy(curname, name, sizeof(curname)-1);
|
||||
|
||||
if (!pw || *pw->pw_passwd) {
|
||||
reply(331, "Password required for %s.", name);
|
||||
askpasswd = 1;
|
||||
} else
|
||||
complete_login (0);
|
||||
|
||||
/*
|
||||
* Delay before reading passwd after first failed
|
||||
* attempt to slow down passwd-guessing programs.
|
||||
*/
|
||||
if (login_attempts)
|
||||
sleep((unsigned) login_attempts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a user is in the file PATH_FTPUSERS
|
||||
*/
|
||||
static int
|
||||
checkuser(name)
|
||||
char *name;
|
||||
{
|
||||
FILE *fd;
|
||||
int found = 0;
|
||||
char *p, line[BUFSIZ];
|
||||
|
||||
if ((fd = fopen(PATH_FTPUSERS, "r")) != NULL) {
|
||||
while (fgets(line, sizeof(line), fd) != NULL)
|
||||
if ((p = strchr(line, '\n')) != NULL) {
|
||||
*p = '\0';
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
if (strcmp(line, name) == 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void) fclose(fd);
|
||||
}
|
||||
return (found);
|
||||
}
|
||||
|
||||
/*
|
||||
* Terminate login as previous user, if any, resetting state;
|
||||
* used when USER command is given or login fails.
|
||||
*/
|
||||
static void
|
||||
end_login()
|
||||
{
|
||||
|
||||
(void) seteuid((uid_t)0);
|
||||
if (logged_in)
|
||||
logwtmp_keep_open (ttyline, "", "");
|
||||
pw = NULL;
|
||||
logged_in = 0;
|
||||
guest = 0;
|
||||
}
|
||||
|
||||
void
|
||||
pass(passwd)
|
||||
char *passwd;
|
||||
{
|
||||
if (logged_in || askpasswd == 0) {
|
||||
reply(503, "Login with USER first.");
|
||||
return;
|
||||
}
|
||||
askpasswd = 0;
|
||||
|
||||
complete_login (passwd);
|
||||
}
|
||||
|
||||
void
|
||||
retrieve(cmd, name)
|
||||
char *cmd, *name;
|
||||
@@ -735,7 +631,6 @@ retrieve(cmd, name)
|
||||
FILE *fin, *dout;
|
||||
struct stat st;
|
||||
int (*closefunc) __P((FILE *));
|
||||
size_t buffer_size=0;
|
||||
|
||||
if (cmd == 0) {
|
||||
fin = fopen(name, "r"), closefunc = fclose;
|
||||
@@ -743,11 +638,10 @@ retrieve(cmd, name)
|
||||
} else {
|
||||
char line[BUFSIZ];
|
||||
|
||||
snprintf (line, sizeof line, cmd, name);
|
||||
name = line;
|
||||
(void) sprintf(line, cmd, name), name = line;
|
||||
fin = ftpd_popen(line, "r"), closefunc = ftpd_pclose;
|
||||
st.st_size = -1;
|
||||
buffer_size = BUFSIZ;
|
||||
st.st_blksize = BUFSIZ;
|
||||
}
|
||||
if (fin == NULL) {
|
||||
if (errno != 0) {
|
||||
@@ -759,8 +653,7 @@ retrieve(cmd, name)
|
||||
return;
|
||||
}
|
||||
byte_count = -1;
|
||||
if (cmd == 0 && (fstat(fileno(fin), &st) < 0 || !S_ISREG(st.st_mode)
|
||||
|| !(buffer_size = ST_BLKSIZE(st)))) {
|
||||
if (cmd == 0 && (fstat(fileno(fin), &st) < 0 || !S_ISREG(st.st_mode))) {
|
||||
reply(550, "%s: not a plain file.", name);
|
||||
goto done;
|
||||
}
|
||||
@@ -779,7 +672,7 @@ retrieve(cmd, name)
|
||||
if (c == '\n')
|
||||
i++;
|
||||
}
|
||||
} else if (lseek(fileno(fin), restart_point, SEEK_SET) < 0) {
|
||||
} else if (lseek(fileno(fin), restart_point, L_SET) < 0) {
|
||||
perror_reply(550, name);
|
||||
goto done;
|
||||
}
|
||||
@@ -787,7 +680,7 @@ retrieve(cmd, name)
|
||||
dout = dataconn(name, st.st_size, "w");
|
||||
if (dout == NULL)
|
||||
goto done;
|
||||
send_data(fin, dout, buffer_size);
|
||||
send_data(fin, dout, st.st_blksize);
|
||||
(void) fclose(dout);
|
||||
data = -1;
|
||||
pdata = -1;
|
||||
@@ -842,11 +735,11 @@ store(name, mode, unique)
|
||||
* because we are changing from reading to
|
||||
* writing.
|
||||
*/
|
||||
if (fseek(fout, 0L, SEEK_CUR) < 0) {
|
||||
if (fseek(fout, 0L, L_INCR) < 0) {
|
||||
perror_reply(550, name);
|
||||
goto done;
|
||||
}
|
||||
} else if (lseek(fileno(fout), restart_point, SEEK_SET) < 0) {
|
||||
} else if (lseek(fileno(fout), restart_point, L_SET) < 0) {
|
||||
perror_reply(550, name);
|
||||
goto done;
|
||||
}
|
||||
@@ -896,7 +789,7 @@ getdatasock(mode)
|
||||
sleep(tries);
|
||||
}
|
||||
(void) seteuid((uid_t)pw->pw_uid);
|
||||
#if defined (IP_TOS) && defined (IPTOS_THROUGHPUT) && defined (IPPROTO_IP)
|
||||
#ifdef IP_TOS
|
||||
on = IPTOS_THROUGHPUT;
|
||||
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
|
||||
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
|
||||
@@ -924,7 +817,7 @@ dataconn(name, size, mode)
|
||||
file_size = size;
|
||||
byte_count = 0;
|
||||
if (size != (off_t) -1)
|
||||
(void) sprintf(sizebuf, " (%s bytes)", off_to_str (size));
|
||||
(void) sprintf(sizebuf, " (%qd bytes)", size);
|
||||
else
|
||||
(void) strcpy(sizebuf, "");
|
||||
if (pdata >= 0) {
|
||||
@@ -940,7 +833,7 @@ dataconn(name, size, mode)
|
||||
}
|
||||
(void) close(pdata);
|
||||
pdata = s;
|
||||
#if defined (IP_TOS) && defined (IPTOS_LOWDELAY) && defined (IPPROTO_IP)
|
||||
#ifdef IP_TOS
|
||||
tos = IPTOS_LOWDELAY;
|
||||
(void) setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
|
||||
sizeof(int));
|
||||
@@ -1183,8 +1076,8 @@ statcmd()
|
||||
struct sockaddr_in *sin;
|
||||
u_char *a, *p;
|
||||
|
||||
lreply(211, "%s FTP server status:", hostname);
|
||||
printf(" ftpd (%s) %s\r\n", inetutils_package, inetutils_version);
|
||||
lreply(211, "%s FTP server status:", hostname, version);
|
||||
printf(" %s\r\n", version);
|
||||
printf(" Connected to %s", remotehost);
|
||||
if (!isdigit(remotehost[0]))
|
||||
printf(" (%s)", inet_ntoa(his_addr.sin_addr));
|
||||
@@ -1202,14 +1095,10 @@ statcmd()
|
||||
if (type == TYPE_A || type == TYPE_E)
|
||||
printf(", FORM: %s", formnames[form]);
|
||||
if (type == TYPE_L)
|
||||
#ifdef CHAR_BIT
|
||||
printf(" %d", CHAR_BIT);
|
||||
#else
|
||||
#if NBBY == 8
|
||||
printf(" %d", NBBY);
|
||||
#else
|
||||
printf(" %d", bytesize); /* need definition! */
|
||||
#endif
|
||||
#endif
|
||||
printf("; STRUcture: %s; transfer MODE: %s\r\n",
|
||||
strunames[stru], modenames[mode]);
|
||||
@@ -1246,7 +1135,7 @@ fatal(s)
|
||||
}
|
||||
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
reply(int n, const char *fmt, ...)
|
||||
#else
|
||||
reply(n, fmt, va_alist)
|
||||
@@ -1256,7 +1145,7 @@ reply(n, fmt, va_alist)
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
@@ -1272,7 +1161,7 @@ reply(n, fmt, va_alist)
|
||||
}
|
||||
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
lreply(int n, const char *fmt, ...)
|
||||
#else
|
||||
lreply(n, fmt, va_alist)
|
||||
@@ -1282,7 +1171,7 @@ lreply(n, fmt, va_alist)
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
@@ -1370,20 +1259,8 @@ makedir(name)
|
||||
LOGCMD("mkdir", name);
|
||||
if (mkdir(name, 0777) < 0)
|
||||
perror_reply(550, name);
|
||||
else if (name[0] == '/')
|
||||
reply (257, "\"%s\" new directory created.");
|
||||
else {
|
||||
/* We have to figure out what our current directory is so that we can
|
||||
give an absolute name in the reply. */
|
||||
char *cwd = getcwd (0, 0);
|
||||
if (cwd) {
|
||||
if (cwd[1] == '\0')
|
||||
cwd[0] = '\0';
|
||||
reply (257, "\"%s/%s\" new directory created.", cwd, name);
|
||||
free (cwd);
|
||||
} else
|
||||
reply (257, "(unknown absolute name) new directory created.");
|
||||
}
|
||||
else
|
||||
reply(257, "MKD command successful.");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1401,12 +1278,12 @@ removedir(name)
|
||||
void
|
||||
pwd()
|
||||
{
|
||||
char *path = getcwd (0, 0);
|
||||
if (path) {
|
||||
char path[MAXPATHLEN + 1];
|
||||
|
||||
if (getwd(path) == (char *)NULL)
|
||||
reply(550, "%s.", path);
|
||||
else
|
||||
reply(257, "\"%s\" is current directory.", path);
|
||||
free (path);
|
||||
} else
|
||||
reply(550, "%s.", strerror (errno));
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1439,22 +1316,16 @@ static void
|
||||
dolog(sin)
|
||||
struct sockaddr_in *sin;
|
||||
{
|
||||
const char *name;
|
||||
struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
|
||||
sizeof(struct in_addr), AF_INET);
|
||||
|
||||
if (hp)
|
||||
name = hp->h_name;
|
||||
(void) strncpy(remotehost, hp->h_name, sizeof(remotehost));
|
||||
else
|
||||
name = inet_ntoa(sin->sin_addr);
|
||||
|
||||
if (remotehost)
|
||||
free (remotehost);
|
||||
remotehost = malloc (strlen (name));
|
||||
strcpy (remotehost, name);
|
||||
|
||||
(void) strncpy(remotehost, inet_ntoa(sin->sin_addr),
|
||||
sizeof(remotehost));
|
||||
#ifdef SETPROCTITLE
|
||||
snprintf (proctitle, sizeof(proctitle), "%s: connected", remotehost);
|
||||
snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
|
||||
setproctitle(proctitle);
|
||||
#endif /* SETPROCTITLE */
|
||||
|
||||
@@ -1470,15 +1341,10 @@ void
|
||||
dologout(status)
|
||||
int status;
|
||||
{
|
||||
/* racing condition with SIGURG: If SIGURG is receive
|
||||
here, it will jump back has root in the main loop
|
||||
David Greenman:dg@root.com
|
||||
*/
|
||||
transflag = 0;
|
||||
|
||||
if (logged_in) {
|
||||
(void) seteuid((uid_t)0);
|
||||
logwtmp_keep_open (ttyline, "", "");
|
||||
logwtmp(ttyline, "", "");
|
||||
}
|
||||
/* beware of flushing buffers after a SIGPIPE */
|
||||
_exit(status);
|
||||
@@ -1494,7 +1360,7 @@ myoob(signo)
|
||||
if (!transflag)
|
||||
return;
|
||||
cp = tmpline;
|
||||
if (telnet_fgets(cp, 7, stdin) == NULL) {
|
||||
if (getline(cp, 7, stdin) == NULL) {
|
||||
reply(221, "You could at least say goodbye.");
|
||||
dologout(0);
|
||||
}
|
||||
@@ -1507,11 +1373,10 @@ myoob(signo)
|
||||
}
|
||||
if (strcmp(cp, "STAT\r\n") == 0) {
|
||||
if (file_size != (off_t) -1)
|
||||
reply(213, "Status: %s of %s bytes transferred",
|
||||
off_to_str (byte_count), off_to_str (file_size));
|
||||
reply(213, "Status: %qd of %qd bytes transferred",
|
||||
byte_count, file_size);
|
||||
else
|
||||
reply(213, "Status: %s bytes transferred",
|
||||
off_to_str (byte_count));
|
||||
reply(213, "Status: %qd bytes transferred", byte_count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1570,7 +1435,7 @@ static char *
|
||||
gunique(local)
|
||||
char *local;
|
||||
{
|
||||
static char *new = 0;
|
||||
static char new[MAXPATHLEN];
|
||||
struct stat st;
|
||||
int count;
|
||||
char *cp;
|
||||
@@ -1584,22 +1449,14 @@ gunique(local)
|
||||
}
|
||||
if (cp)
|
||||
*cp = '/';
|
||||
|
||||
if (new)
|
||||
free (new);
|
||||
|
||||
new = malloc (strlen (local) + 5); /* '.' + DIG + DIG + '\0' */
|
||||
if (new) {
|
||||
strcpy(new, local);
|
||||
cp = new + strlen(new);
|
||||
*cp++ = '.';
|
||||
for (count = 1; count < 100; count++) {
|
||||
(void)sprintf(cp, "%d", count);
|
||||
if (stat(new, &st) < 0)
|
||||
return (new);
|
||||
}
|
||||
(void) strcpy(new, local);
|
||||
cp = new + strlen(new);
|
||||
*cp++ = '.';
|
||||
for (count = 1; count < 100; count++) {
|
||||
(void)sprintf(cp, "%d", count);
|
||||
if (stat(new, &st) < 0)
|
||||
return (new);
|
||||
}
|
||||
|
||||
reply(452, "Unique file name cannot be created.");
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1635,17 +1492,7 @@ send_file_list(whichf)
|
||||
glob_t gl;
|
||||
|
||||
if (strpbrk(whichf, "~{[*?") != NULL) {
|
||||
int flags = GLOB_NOCHECK;
|
||||
|
||||
#ifdef GLOB_BRACE
|
||||
flags |= GLOB_BRACE;
|
||||
#endif
|
||||
#ifdef GLOB_QUOTE
|
||||
flags |= GLOB_QUOTE;
|
||||
#endif
|
||||
#ifdef GLOB_TILDE
|
||||
flags |= GLOB_TILDE;
|
||||
#endif
|
||||
int flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
freeglob = 1;
|
||||
@@ -1707,15 +1554,14 @@ send_file_list(whichf)
|
||||
continue;
|
||||
|
||||
while ((dir = readdir(dirp)) != NULL) {
|
||||
char *nbuf;
|
||||
char nbuf[MAXPATHLEN];
|
||||
|
||||
if (dir->d_name[0] == '.' && dir->d_name[1] == '\0')
|
||||
if (dir->d_name[0] == '.' && dir->d_namlen == 1)
|
||||
continue;
|
||||
if (dir->d_name[0] == '.' && dir->d_name[1] == '.' &&
|
||||
dir->d_name[2] == '\0')
|
||||
dir->d_namlen == 2)
|
||||
continue;
|
||||
|
||||
nbuf = (char *) alloca (strlen (dirname) + 1 + strlen (dir->d_name) + 1);
|
||||
sprintf(nbuf, "%s/%s", dirname, dir->d_name);
|
||||
|
||||
/*
|
||||
@@ -1769,7 +1615,7 @@ out:
|
||||
* have much of an environment or arglist to overwrite.
|
||||
*/
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
setproctitle(const char *fmt, ...)
|
||||
#else
|
||||
setproctitle(fmt, va_alist)
|
||||
@@ -1782,7 +1628,7 @@ setproctitle(fmt, va_alist)
|
||||
char *p, *bp, ch;
|
||||
char buf[LINE_MAX];
|
||||
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
|
||||
@@ -1,27 +1,4 @@
|
||||
/*
|
||||
SYSVish version:
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
* BSDish version:
|
||||
*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
@@ -59,10 +36,6 @@ Boston, MA 02111-1307, USA.
|
||||
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -74,9 +47,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <string.h>
|
||||
#include "extern.h"
|
||||
|
||||
#if !defined (_PATH_WTMP) && defined (WTMP_FILE)
|
||||
#define _PATH_WTMP WTMP_FILE
|
||||
#endif
|
||||
static int fd = -1;
|
||||
|
||||
/*
|
||||
* Modified version of logwtmp that holds wtmp file open
|
||||
@@ -85,65 +56,20 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
*/
|
||||
void
|
||||
logwtmp(line, name, host)
|
||||
const char *line, *name, *host;
|
||||
char *line, *name, *host;
|
||||
{
|
||||
struct utmp ut;
|
||||
|
||||
/* Set information in new entry. */
|
||||
bzero (&ut, sizeof (ut));
|
||||
#if _HAVE_UT_TYPE - 0
|
||||
ut.ut_type = USER_PROCESS;
|
||||
#endif
|
||||
strncpy (ut.ut_line, line, sizeof ut.ut_line);
|
||||
strncpy (ut.ut_name, name, sizeof ut.ut_name);
|
||||
#if _HAVE_UT_HOST - 0
|
||||
strncpy (ut.ut_host, host, sizeof ut.ut_host);
|
||||
#endif
|
||||
|
||||
#if _HAVE_UT_TV - 0
|
||||
gettimeofday (&ut.ut_tv, NULL);
|
||||
#else
|
||||
time (&ut.ut_time);
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UTMPNAME) && defined (HAVE_SETUTENT_R)
|
||||
/* XXX I think frobbing the details of DATA is GNU libc specific. */
|
||||
{
|
||||
static struct utmp_data data = { -1 };
|
||||
|
||||
if (data.ut_fd < 0)
|
||||
/* Open the file. */
|
||||
{
|
||||
/* Tell that we want to use the WTMP file. */
|
||||
if (utmpname (_PATH_WTMP) == 0)
|
||||
return;
|
||||
|
||||
/* Open WTMP file. */
|
||||
setutent_r (&data);
|
||||
}
|
||||
|
||||
/* Position at end of file. */
|
||||
data.loc_utmp = lseek (data.ut_fd, 0, SEEK_END);
|
||||
if (data.loc_utmp == -1)
|
||||
return;
|
||||
|
||||
/* Write the entry. */
|
||||
pututline_r (&ut, &data);
|
||||
}
|
||||
#else
|
||||
/* Do things the old way. */
|
||||
{
|
||||
struct utmp ut;
|
||||
struct stat buf;
|
||||
static int fd = -1;
|
||||
|
||||
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
|
||||
return;
|
||||
if (fstat(fd, &buf) == 0) {
|
||||
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
|
||||
(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
|
||||
(void)time(&ut.ut_time);
|
||||
if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
|
||||
sizeof(struct utmp))
|
||||
(void)ftruncate(fd, buf.st_size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
97
ftpd/popen.c
97
ftpd/popen.c
@@ -39,22 +39,16 @@
|
||||
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
/* Include glob.h last, because it may define "const" which breaks
|
||||
system headers on some platforms. */
|
||||
#include <glob.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
@@ -63,18 +57,8 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||
* may create a pipe to a hidden program as a side effect of a list or dir
|
||||
* command.
|
||||
*/
|
||||
|
||||
#define MAX_ARGC 100
|
||||
#define MAX_GARGC 1000
|
||||
|
||||
struct file_pid {
|
||||
FILE *file;
|
||||
pid_t pid;
|
||||
struct file_pid *next;
|
||||
};
|
||||
|
||||
/* A linked list associating ftpd_popen'd FILEs with pids. */
|
||||
struct file_pid *file_pids = 0;
|
||||
static int *pids;
|
||||
static int fds;
|
||||
|
||||
FILE *
|
||||
ftpd_popen(program, type)
|
||||
@@ -82,38 +66,32 @@ ftpd_popen(program, type)
|
||||
{
|
||||
char *cp;
|
||||
FILE *iop;
|
||||
struct file_pid *fpid;
|
||||
int argc, gargc, pdes[2], pid;
|
||||
char **pop, *argv[MAX_ARGC], *gargv[MAX_GARGC];
|
||||
char **pop, *argv[100], *gargv[1000];
|
||||
|
||||
if (*type != 'r' && *type != 'w' || type[1])
|
||||
return (NULL);
|
||||
|
||||
if (!pids) {
|
||||
if ((fds = getdtablesize()) <= 0)
|
||||
return (NULL);
|
||||
if ((pids = (int *)malloc((u_int)(fds * sizeof(int)))) == NULL)
|
||||
return (NULL);
|
||||
memset(pids, 0, fds * sizeof(int));
|
||||
}
|
||||
if (pipe(pdes) < 0)
|
||||
return (NULL);
|
||||
|
||||
/* break up string into pieces */
|
||||
for (argc = 0, cp = program;; cp = NULL) {
|
||||
for (argc = 0, cp = program;; cp = NULL)
|
||||
if (!(argv[argc++] = strtok(cp, " \t\n")))
|
||||
break;
|
||||
|
||||
if (argc > MAX_ARGC) return(NULL); /* AUSCERT */
|
||||
}
|
||||
/* glob each piece */
|
||||
gargv[0] = argv[0];
|
||||
for (gargc = argc = 1; argv[argc]; argc++) {
|
||||
glob_t gl;
|
||||
int flags = GLOB_NOCHECK;
|
||||
|
||||
#ifdef GLOB_BRACE
|
||||
flags |= GLOB_BRACE;
|
||||
#endif
|
||||
#ifdef GLOB_QUOTE
|
||||
flags |= GLOB_QUOTE;
|
||||
#endif
|
||||
#ifdef GLOB_TILDE
|
||||
flags |= GLOB_TILDE;
|
||||
#endif
|
||||
int flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
if (glob(argv[argc], flags, NULL, &gl))
|
||||
@@ -158,14 +136,7 @@ ftpd_popen(program, type)
|
||||
iop = fdopen(pdes[1], type);
|
||||
(void)close(pdes[0]);
|
||||
}
|
||||
|
||||
fpid = (struct file_pid *) malloc (sizeof (struct file_pid));
|
||||
if (fpid) {
|
||||
fpid->file = iop;
|
||||
fpid->pid = pid;
|
||||
fpid->next = file_pids;
|
||||
file_pids = fpid;
|
||||
}
|
||||
pids[fileno(iop)] = pid;
|
||||
|
||||
pfree: for (argc = 1; gargv[argc] != NULL; argc++)
|
||||
free(gargv[argc]);
|
||||
@@ -177,51 +148,21 @@ int
|
||||
ftpd_pclose(iop)
|
||||
FILE *iop;
|
||||
{
|
||||
struct file_pid *fpid = file_pids, *prev_fpid = 0;
|
||||
int fdes, status;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigset_t sigs, osigs;
|
||||
#else
|
||||
int omask;
|
||||
#endif
|
||||
int fdes, omask, status;
|
||||
pid_t pid;
|
||||
|
||||
/*
|
||||
* pclose returns -1 if stream is not associated with a
|
||||
* `popened' command, or, if already `pclosed'.
|
||||
*/
|
||||
while (fpid && fpid->file != iop) {
|
||||
prev_fpid = fpid;
|
||||
fpid = fpid->next;
|
||||
}
|
||||
if (! fpid)
|
||||
return -1;
|
||||
|
||||
if (prev_fpid)
|
||||
prev_fpid->next = fpid->next;
|
||||
else
|
||||
file_pids = fpid->next;
|
||||
|
||||
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
|
||||
return (-1);
|
||||
(void)fclose(iop);
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGINT);
|
||||
sigaddset(&sigs, SIGQUIT);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
|
||||
#endif
|
||||
while ((pid = waitpid(fpid->pid, &status, 0)) < 0 && errno == EINTR)
|
||||
while ((pid = waitpid(pids[fdes], &status, 0)) < 0 && errno == EINTR)
|
||||
continue;
|
||||
|
||||
free (fpid);
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
(void)sigsetmask(omask);
|
||||
#endif
|
||||
pids[fdes] = 0;
|
||||
if (pid < 0)
|
||||
return (pid);
|
||||
if (WIFEXITED(status))
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)inetd.8 8.4 (Berkeley) 6/1/94
|
||||
.\" @(#)inetd.8 8.3 (Berkeley) 4/13/94
|
||||
.\"
|
||||
.Dd June 1, 1994
|
||||
.Dd April 13, 1994
|
||||
.Dt INETD 8
|
||||
.Os BSD 4.4
|
||||
.Sh NAME
|
||||
@@ -301,7 +301,6 @@ causes
|
||||
.Nm inetd
|
||||
to list TCPMUX services in
|
||||
.Pa inetd.conf .
|
||||
.ne 1i
|
||||
.Sh "EXAMPLES"
|
||||
.Pp
|
||||
Here are several example service entries for the various types of services:
|
||||
|
||||
175
inetd/inetd.c
175
inetd/inetd.c
@@ -90,27 +90,12 @@ static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94";
|
||||
*
|
||||
* Comment lines are indicated by a `#' in column 1.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
@@ -126,10 +111,8 @@ static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94";
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "pathnames.h"
|
||||
|
||||
#define TOOMANY 40 /* don't start more than TOOMANY */
|
||||
#define CNT_INTVL 60 /* servers in CNT_INTVL sec. */
|
||||
@@ -233,7 +216,7 @@ struct biltin {
|
||||
};
|
||||
|
||||
#define NUMINT (sizeof(intab) / sizeof(struct inent))
|
||||
char *CONFIG = PATH_INETDCONF;
|
||||
char *CONFIG = _PATH_INETDCONF;
|
||||
char **Argv;
|
||||
char *LastArg;
|
||||
|
||||
@@ -244,13 +227,7 @@ main(argc, argv, envp)
|
||||
{
|
||||
struct servtab *sep;
|
||||
struct passwd *pwd;
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction sa;
|
||||
#else
|
||||
#ifdef HAVE_SIGVEC
|
||||
struct sigvec sv;
|
||||
#endif
|
||||
#endif
|
||||
int tmpint, ch, dofork;
|
||||
pid_t pid;
|
||||
char buf[50];
|
||||
@@ -296,25 +273,6 @@ main(argc, argv, envp)
|
||||
if (debug == 0) {
|
||||
daemon(0, 0);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
bzero (&sa, sizeof (sa));
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaddset(&sa.sa_mask, SIGCHLD);
|
||||
sigaddset(&sa.sa_mask, SIGHUP);
|
||||
sigaddset(&sa.sa_mask, SIGALRM);
|
||||
#ifdef SA_RESTART
|
||||
sa.sa_flags = SA_RESTART;
|
||||
#endif
|
||||
sa.sa_handler = retry;
|
||||
sigaction (SIGALRM, &sa, (struct sigaction *)0);
|
||||
config (SIGHUP);
|
||||
sa.sa_handler = config;
|
||||
sigaction (SIGHUP, &sa, (struct sigaction *)0);
|
||||
sa.sa_handler = reapchild;
|
||||
sigaction (SIGCHLD, &sa, (struct sigaction *)0);
|
||||
#else
|
||||
#ifdef HAVE_SIGVEC
|
||||
memset(&sv, 0, sizeof(sv));
|
||||
sv.sv_mask = SIGBLOCK;
|
||||
sv.sv_handler = retry;
|
||||
@@ -324,13 +282,6 @@ main(argc, argv, envp)
|
||||
sigvec(SIGHUP, &sv, (struct sigvec *)0);
|
||||
sv.sv_handler = reapchild;
|
||||
sigvec(SIGCHLD, &sv, (struct sigvec *)0);
|
||||
#else /* !HAVE_SIGVEC */
|
||||
signal (SIGALRM, retry);
|
||||
config (SIGHUP);
|
||||
signal (SIGHUP, config);
|
||||
signal (SIGCHLD, reapchild);
|
||||
#endif /* HAVE_SIGVEC */
|
||||
#endif /* HAVE_SIGACTION */
|
||||
|
||||
{
|
||||
/* space for daemons to overwrite environment for ps */
|
||||
@@ -347,29 +298,10 @@ main(argc, argv, envp)
|
||||
fd_set readable;
|
||||
|
||||
if (nsock == 0) {
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t sigs;
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, 0);
|
||||
}
|
||||
#else
|
||||
(void) sigblock(SIGBLOCK);
|
||||
#endif
|
||||
while (nsock == 0)
|
||||
sigpause(0L);
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t empty;
|
||||
sigemptyset(&empty);
|
||||
sigprocmask(SIG_SETMASK, &empty, 0);
|
||||
}
|
||||
#else
|
||||
(void) sigsetmask(0L);
|
||||
#endif
|
||||
}
|
||||
readable = allsock;
|
||||
if ((n = select(maxsock + 1, &readable, (fd_set *)0,
|
||||
@@ -410,18 +342,7 @@ main(argc, argv, envp)
|
||||
}
|
||||
} else
|
||||
ctrl = sep->se_fd;
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t sigs;
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, 0);
|
||||
}
|
||||
#else
|
||||
(void) sigblock(SIGBLOCK);
|
||||
#endif
|
||||
pid = 0;
|
||||
dofork = (sep->se_bi == 0 || sep->se_bi->bi_fork);
|
||||
if (dofork) {
|
||||
@@ -441,15 +362,7 @@ main(argc, argv, envp)
|
||||
"%s/%s server failing (looping), service terminated",
|
||||
sep->se_service, sep->se_proto);
|
||||
close_sep(sep);
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t empty;
|
||||
sigemptyset(&empty);
|
||||
sigprocmask(SIG_SETMASK, &empty, 0);
|
||||
}
|
||||
#else
|
||||
sigsetmask(0L);
|
||||
#endif
|
||||
if (!timingout) {
|
||||
timingout = 1;
|
||||
alarm(RETRYTIME);
|
||||
@@ -464,15 +377,7 @@ main(argc, argv, envp)
|
||||
if (!sep->se_wait &&
|
||||
sep->se_socktype == SOCK_STREAM)
|
||||
close(ctrl);
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t empty;
|
||||
sigemptyset(&empty);
|
||||
sigprocmask(SIG_SETMASK, &empty, 0);
|
||||
}
|
||||
#else
|
||||
sigsetmask(0L);
|
||||
#endif
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
@@ -483,15 +388,7 @@ main(argc, argv, envp)
|
||||
nsock--;
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t empty;
|
||||
sigemptyset(&empty);
|
||||
sigprocmask(SIG_SETMASK, &empty, 0);
|
||||
}
|
||||
#else
|
||||
sigsetmask(0L);
|
||||
#endif
|
||||
if (pid == 0) {
|
||||
if (debug && dofork)
|
||||
setsid();
|
||||
@@ -589,11 +486,7 @@ config(signo)
|
||||
{
|
||||
struct servtab *sep, *cp, **sepp;
|
||||
struct passwd *pwd;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigset_t sigs, osigs;
|
||||
#else
|
||||
long omask;
|
||||
#endif
|
||||
|
||||
if (!setconfig()) {
|
||||
syslog(LOG_ERR, "%s: %m", CONFIG);
|
||||
@@ -615,15 +508,7 @@ config(signo)
|
||||
if (sep != 0) {
|
||||
int i;
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
omask = sigblock(SIGBLOCK);
|
||||
#endif
|
||||
/*
|
||||
* sep->se_wait may be holding the pid of a daemon
|
||||
* that we're waiting for. If so, don't overwrite
|
||||
@@ -640,11 +525,7 @@ config(signo)
|
||||
SWAP(sep->se_server, cp->se_server);
|
||||
for (i = 0; i < MAXARGV; i++)
|
||||
SWAP(sep->se_argv[i], cp->se_argv[i]);
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
freeconfig(cp);
|
||||
if (debug)
|
||||
print_service("REDO", sep);
|
||||
@@ -678,15 +559,7 @@ config(signo)
|
||||
/*
|
||||
* Purge anything not looked at above.
|
||||
*/
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
omask = sigblock(SIGBLOCK);
|
||||
#endif
|
||||
sepp = &servtab;
|
||||
while (sep = *sepp) {
|
||||
if (sep->se_checked) {
|
||||
@@ -701,11 +574,7 @@ config(signo)
|
||||
freeconfig(sep);
|
||||
free((char *)sep);
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
(void) sigsetmask(omask);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -798,11 +667,7 @@ enter(cp)
|
||||
struct servtab *cp;
|
||||
{
|
||||
struct servtab *sep;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigset_t sigs, osigs;
|
||||
#else
|
||||
long omask;
|
||||
#endif
|
||||
|
||||
sep = (struct servtab *)malloc(sizeof (*sep));
|
||||
if (sep == (struct servtab *)0) {
|
||||
@@ -811,32 +676,16 @@ enter(cp)
|
||||
}
|
||||
*sep = *cp;
|
||||
sep->se_fd = -1;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGCHLD);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
omask = sigblock(SIGBLOCK);
|
||||
#endif
|
||||
sep->se_next = servtab;
|
||||
servtab = sep;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
return (sep);
|
||||
}
|
||||
|
||||
FILE *fconfig = NULL;
|
||||
struct servtab serv;
|
||||
#ifdef LINE_MAX
|
||||
char line[LINE_MAX];
|
||||
#else
|
||||
char line[2048];
|
||||
#endif
|
||||
|
||||
int
|
||||
setconfig()
|
||||
@@ -1051,7 +900,7 @@ newstr(cp)
|
||||
}
|
||||
|
||||
void
|
||||
set_proc_title(a, s)
|
||||
setproctitle(a, s)
|
||||
char *a;
|
||||
int s;
|
||||
{
|
||||
@@ -1063,9 +912,9 @@ set_proc_title(a, s)
|
||||
cp = Argv[0];
|
||||
size = sizeof(sin);
|
||||
if (getpeername(s, (struct sockaddr *)&sin, &size) == 0)
|
||||
snprintf (buf, sizeof buf, "-%s [%s]", a, inet_ntoa(sin.sin_addr));
|
||||
(void) sprintf(buf, "-%s [%s]", a, inet_ntoa(sin.sin_addr));
|
||||
else
|
||||
snprintf (buf, sizeof buf, "-%s", a);
|
||||
(void) sprintf(buf, "-%s", a);
|
||||
strncpy(cp, buf, LastArg - cp);
|
||||
cp += strlen(cp);
|
||||
while (cp < LastArg)
|
||||
@@ -1086,7 +935,7 @@ echo_stream(s, sep) /* Echo service -- echo data back */
|
||||
char buffer[BUFSIZE];
|
||||
int i;
|
||||
|
||||
set_proc_title(sep->se_service, s);
|
||||
setproctitle(sep->se_service, s);
|
||||
while ((i = read(s, buffer, sizeof(buffer))) > 0 &&
|
||||
write(s, buffer, i) > 0)
|
||||
;
|
||||
@@ -1118,7 +967,7 @@ discard_stream(s, sep) /* Discard service -- ignore data */
|
||||
int ret;
|
||||
char buffer[BUFSIZE];
|
||||
|
||||
set_proc_title(sep->se_service, s);
|
||||
setproctitle(sep->se_service, s);
|
||||
while (1) {
|
||||
while ((ret = read(s, buffer, sizeof(buffer))) > 0)
|
||||
;
|
||||
@@ -1165,7 +1014,7 @@ chargen_stream(s, sep) /* Character generator */
|
||||
int len;
|
||||
char *rs, text[LINESIZ+2];
|
||||
|
||||
set_proc_title(sep->se_service, s);
|
||||
setproctitle(sep->se_service, s);
|
||||
|
||||
if (!endring) {
|
||||
initring();
|
||||
@@ -1331,7 +1180,7 @@ print_service(action, sep)
|
||||
|
||||
|
||||
static int /* # of characters upto \r,\n or \0 */
|
||||
fd_getline(fd, buf, len)
|
||||
getline(fd, buf, len)
|
||||
int fd;
|
||||
char *buf;
|
||||
int len;
|
||||
@@ -1367,7 +1216,7 @@ tcpmux(s)
|
||||
int len;
|
||||
|
||||
/* Get requested service name */
|
||||
if ((len = fd_getline(s, service, MAX_SERV_LEN)) < 0) {
|
||||
if ((len = getline(s, service, MAX_SERV_LEN)) < 0) {
|
||||
strwrite(s, "-Error reading service name\r\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)auth.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)auth.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -55,9 +55,6 @@ static char sccsid[] = "@(#)auth.c 8.3 (Berkeley) 5/30/95";
|
||||
* or implied warranty.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(AUTHENTICATION)
|
||||
#include <stdio.h>
|
||||
@@ -65,7 +62,7 @@ static char sccsid[] = "@(#)auth.c 8.3 (Berkeley) 5/30/95";
|
||||
#include <signal.h>
|
||||
#define AUTH_NAMES
|
||||
#include <arpa/telnet.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -225,9 +222,6 @@ auth_init(name, server)
|
||||
Name,
|
||||
ap->type, ap->way);
|
||||
}
|
||||
else if (auth_debug_mode)
|
||||
printf(">>>%s: Init failed: auth type %d %d\r\n",
|
||||
Name, ap->type, ap->way);
|
||||
++ap;
|
||||
}
|
||||
}
|
||||
@@ -252,7 +246,7 @@ getauthmask(type, maskp)
|
||||
{
|
||||
register int x;
|
||||
|
||||
if (!strcasecmp(type, AUTHTYPE_NAME(0))) {
|
||||
if (strcasecmp(type, AUTHTYPE_NAME(0))) {
|
||||
*maskp = -1;
|
||||
return(1);
|
||||
}
|
||||
@@ -268,14 +262,14 @@ getauthmask(type, maskp)
|
||||
|
||||
int
|
||||
auth_enable(type)
|
||||
char *type;
|
||||
int type;
|
||||
{
|
||||
return(auth_onoff(type, 1));
|
||||
}
|
||||
|
||||
int
|
||||
auth_disable(type)
|
||||
char *type;
|
||||
int type;
|
||||
{
|
||||
return(auth_onoff(type, 0));
|
||||
}
|
||||
@@ -285,20 +279,15 @@ auth_onoff(type, on)
|
||||
char *type;
|
||||
int on;
|
||||
{
|
||||
int i, mask = -1;
|
||||
int mask = -1;
|
||||
Authenticator *ap;
|
||||
|
||||
if (!strcasecmp(type, "?") || !strcasecmp(type, "help")) {
|
||||
printf("auth %s 'type'\n", on ? "enable" : "disable");
|
||||
printf("Where 'type' is one of:\n");
|
||||
printf("\t%s\n", AUTHTYPE_NAME(0));
|
||||
mask = 0;
|
||||
for (ap = authenticators; ap->type; ap++) {
|
||||
if ((mask & (i = typemask(ap->type))) != 0)
|
||||
continue;
|
||||
mask |= i;
|
||||
for (ap = authenticators; ap->type; ap++)
|
||||
printf("\t%s\n", AUTHTYPE_NAME(ap->type));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -306,6 +295,7 @@ auth_onoff(type, on)
|
||||
printf("%s: invalid authentication type\n", type);
|
||||
return(0);
|
||||
}
|
||||
mask = getauthmask(type, &mask);
|
||||
if (on)
|
||||
i_wont_support &= ~mask;
|
||||
else
|
||||
@@ -329,22 +319,16 @@ auth_togdebug(on)
|
||||
auth_status()
|
||||
{
|
||||
Authenticator *ap;
|
||||
int i, mask;
|
||||
|
||||
if (i_wont_support == -1)
|
||||
printf("Authentication disabled\n");
|
||||
else
|
||||
printf("Authentication enabled\n");
|
||||
|
||||
mask = 0;
|
||||
for (ap = authenticators; ap->type; ap++) {
|
||||
if ((mask & (i = typemask(ap->type))) != 0)
|
||||
continue;
|
||||
mask |= i;
|
||||
for (ap = authenticators; ap->type; ap++)
|
||||
printf("%s: %s\n", AUTHTYPE_NAME(ap->type),
|
||||
(i_wont_support & typemask(ap->type)) ?
|
||||
"disabled" : "enabled");
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
@@ -422,7 +406,7 @@ auth_send(data, cnt)
|
||||
auth_send_cnt = cnt > sizeof(_auth_send_data)
|
||||
? sizeof(_auth_send_data)
|
||||
: cnt;
|
||||
memmove((void *)_auth_send_data, (void *)data, auth_send_cnt);
|
||||
bcopy((void *)data, (void *)_auth_send_data, auth_send_cnt);
|
||||
auth_send_data = _auth_send_data;
|
||||
} else {
|
||||
/*
|
||||
@@ -548,7 +532,7 @@ auth_name(data, cnt)
|
||||
Name, cnt, sizeof(savename)-1);
|
||||
return;
|
||||
}
|
||||
memmove((void *)savename, (void *)data, cnt);
|
||||
bcopy((void *)data, (void *)savename, cnt);
|
||||
savename[cnt] = '\0'; /* Null terminate */
|
||||
if (auth_debug_mode)
|
||||
printf(">>>%s: Got NAME [%s]\r\n", Name, savename);
|
||||
|
||||
@@ -32,19 +32,15 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)enc_des.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)enc_des.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENCRYPTION
|
||||
# ifdef AUTHENTICATION
|
||||
# ifdef DES_ENCRYPTION
|
||||
#include <arpa/telnet.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
@@ -147,7 +143,7 @@ ofb64_init(server)
|
||||
fb64_init(fbp)
|
||||
register struct fb *fbp;
|
||||
{
|
||||
memset((void *)fbp, 0, sizeof(*fbp));
|
||||
bzero((void *)fbp, sizeof(*fbp));
|
||||
fbp->state[0] = fbp->state[1] = FAILED;
|
||||
fbp->fb_feed[0] = IAC;
|
||||
fbp->fb_feed[1] = SB;
|
||||
@@ -378,7 +374,7 @@ fb64_reply(data, cnt, fbp)
|
||||
break;
|
||||
|
||||
case FB64_IV_BAD:
|
||||
memset(fbp->temp_feed, 0, sizeof(Block));
|
||||
bzero(fbp->temp_feed, sizeof(Block));
|
||||
fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]);
|
||||
state = FAILED;
|
||||
break;
|
||||
@@ -426,7 +422,7 @@ fb64_session(key, server, fbp)
|
||||
key ? key->type : -1, SK_DES);
|
||||
return;
|
||||
}
|
||||
memmove((void *)fbp->krbdes_key, (void *)key->data, sizeof(Block));
|
||||
bcopy((void *)key->data, (void *)fbp->krbdes_key, sizeof(Block));
|
||||
|
||||
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_ENCRYPT-1]);
|
||||
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]);
|
||||
@@ -553,8 +549,8 @@ fb64_stream_iv(seed, stp)
|
||||
register struct stinfo *stp;
|
||||
{
|
||||
|
||||
memmove((void *)stp->str_iv, (void *)seed, sizeof(Block));
|
||||
memmove((void *)stp->str_output, (void *)seed, sizeof(Block));
|
||||
bcopy((void *)seed, (void *)stp->str_iv, sizeof(Block));
|
||||
bcopy((void *)seed, (void *)stp->str_output, sizeof(Block));
|
||||
|
||||
des_key_sched(stp->str_ikey, stp->str_sched);
|
||||
|
||||
@@ -566,10 +562,10 @@ fb64_stream_key(key, stp)
|
||||
Block key;
|
||||
register struct stinfo *stp;
|
||||
{
|
||||
memmove((void *)stp->str_ikey, (void *)key, sizeof(Block));
|
||||
bcopy((void *)key, (void *)stp->str_ikey, sizeof(Block));
|
||||
des_key_sched(key, stp->str_sched);
|
||||
|
||||
memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block));
|
||||
bcopy((void *)stp->str_iv, (void *)stp->str_output, sizeof(Block));
|
||||
|
||||
stp->str_index = sizeof(Block);
|
||||
}
|
||||
@@ -609,7 +605,7 @@ cfb64_encrypt(s, c)
|
||||
if (index == sizeof(Block)) {
|
||||
Block b;
|
||||
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
|
||||
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
|
||||
bcopy((void *)b, (void *)stp->str_feed, sizeof(Block));
|
||||
index = 0;
|
||||
}
|
||||
|
||||
@@ -643,7 +639,7 @@ cfb64_decrypt(data)
|
||||
if (index == sizeof(Block)) {
|
||||
Block b;
|
||||
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
|
||||
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
|
||||
bcopy((void *)b, (void *)stp->str_feed, sizeof(Block));
|
||||
stp->str_index = 1; /* Next time will be 1 */
|
||||
index = 0; /* But now use 0 */
|
||||
}
|
||||
@@ -685,7 +681,7 @@ ofb64_encrypt(s, c)
|
||||
if (index == sizeof(Block)) {
|
||||
Block b;
|
||||
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
|
||||
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
|
||||
bcopy((void *)b, (void *)stp->str_feed, sizeof(Block));
|
||||
index = 0;
|
||||
}
|
||||
*s++ ^= stp->str_feed[index];
|
||||
@@ -716,7 +712,7 @@ ofb64_decrypt(data)
|
||||
if (index == sizeof(Block)) {
|
||||
Block b;
|
||||
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
|
||||
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
|
||||
bcopy((void *)b, (void *)stp->str_feed, sizeof(Block));
|
||||
stp->str_index = 1; /* Next time will be 1 */
|
||||
index = 0; /* But now use 0 */
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)encrypt.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -55,10 +55,6 @@ static char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
|
||||
* or implied warranty.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENCRYPTION
|
||||
|
||||
#define ENCRYPT_NAMES
|
||||
@@ -67,7 +63,7 @@ static char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
|
||||
#include "encrypt.h"
|
||||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -767,13 +763,12 @@ encrypt_keyid(kp, keyid, len)
|
||||
if (ep->keyid)
|
||||
(void)(*ep->keyid)(dir, kp->keyid, &kp->keylen);
|
||||
|
||||
} else if ((len != kp->keylen) ||
|
||||
(memcmp(keyid, kp->keyid, len) != 0)) {
|
||||
} else if ((len != kp->keylen) || (bcmp(keyid, kp->keyid, len) != 0)) {
|
||||
/*
|
||||
* Length or contents are different
|
||||
*/
|
||||
kp->keylen = len;
|
||||
memmove(kp->keyid, keyid, len);
|
||||
bcopy(keyid, kp->keyid, len);
|
||||
if (ep->keyid)
|
||||
(void)(*ep->keyid)(dir, kp->keyid, &kp->keylen);
|
||||
} else {
|
||||
@@ -800,7 +795,7 @@ encrypt_send_keyid(dir, keyid, keylen, saveit)
|
||||
? ENCRYPT_ENC_KEYID : ENCRYPT_DEC_KEYID;
|
||||
if (saveit) {
|
||||
struct key_info *kp = &ki[(dir == DIR_ENCRYPT) ? 0 : 1];
|
||||
memmove(kp->keyid, keyid, keylen);
|
||||
bcopy(keyid, kp->keyid, keylen);
|
||||
kp->keylen = keylen;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)genget.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)genget.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@@ -35,17 +35,13 @@
|
||||
static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
static char *area;
|
||||
|
||||
/*ARGSUSED*/
|
||||
getent(cp, name)
|
||||
char *cp, *name;
|
||||
{
|
||||
#ifdef HAVE_CGETENT
|
||||
#ifdef HAS_CGETENT
|
||||
char *dba[2];
|
||||
|
||||
dba[0] = "/etc/gettytab";
|
||||
@@ -62,7 +58,7 @@ char *
|
||||
getstr(id, cpp)
|
||||
char *id, **cpp;
|
||||
{
|
||||
# ifdef HAVE_CGETENT
|
||||
# ifdef HAS_CGETENT
|
||||
char *answer;
|
||||
return((cgetstr(area, id, &answer) > 0) ? answer : 0);
|
||||
# else
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)kerberos.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -55,17 +55,13 @@ static char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
|
||||
* or implied warranty.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef KRB4
|
||||
#include <sys/types.h>
|
||||
#include <arpa/telnet.h>
|
||||
#include <stdio.h>
|
||||
#include <des.h> /* BSD wont include this in krb.h, so we do it here */
|
||||
#include <krb.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -189,7 +185,7 @@ kerberos4_send(ap)
|
||||
return(0);
|
||||
}
|
||||
|
||||
memset(instance, 0, sizeof(instance));
|
||||
bzero(instance, sizeof(instance));
|
||||
|
||||
if (realm = krb_get_phost(RemoteHostName))
|
||||
strncpy(instance, realm, sizeof(instance));
|
||||
@@ -231,10 +227,9 @@ kerberos4_send(ap)
|
||||
register int i;
|
||||
|
||||
des_key_sched(cred.session, sched);
|
||||
des_init_random_number_generator(cred.session);
|
||||
des_new_random_key(session_key);
|
||||
des_ecb_encrypt(session_key, session_key, sched, 0);
|
||||
des_ecb_encrypt(session_key, challenge, sched, 0);
|
||||
des_set_random_generator_seed(cred.session);
|
||||
des_new_random_key(challenge);
|
||||
des_ecb_encrypt(challenge, session_key, sched, 1);
|
||||
/*
|
||||
* Increment the challenge by 1, and encrypt it for
|
||||
* later comparison.
|
||||
@@ -284,7 +279,7 @@ kerberos4_is(ap, data, cnt)
|
||||
printf("No local realm\r\n");
|
||||
return;
|
||||
}
|
||||
memmove((void *)auth.dat, (void *)data, auth.length = cnt);
|
||||
bcopy((void *)data, (void *)auth.dat, auth.length = cnt);
|
||||
if (auth_debug_mode) {
|
||||
printf("Got %d bytes of authentication data\r\n", cnt);
|
||||
printf("CK: %d:", kerberos4_cksum(auth.dat, auth.length));
|
||||
@@ -301,7 +296,7 @@ kerberos4_is(ap, data, cnt)
|
||||
return;
|
||||
}
|
||||
#ifdef ENCRYPTION
|
||||
memmove((void *)session_key, (void *)adat.session, sizeof(Block));
|
||||
bcopy((void *)adat.session, (void *)session_key, sizeof(Block));
|
||||
#endif /* ENCRYPTION */
|
||||
krb_kntoln(&adat, name);
|
||||
|
||||
@@ -327,13 +322,8 @@ kerberos4_is(ap, data, cnt)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the random number generator since it's
|
||||
* used later on by the encryption routine.
|
||||
*/
|
||||
des_init_random_number_generator(session_key);
|
||||
des_key_sched(session_key, sched);
|
||||
memmove((void *)datablock, (void *)data, sizeof(Block));
|
||||
bcopy((void *)data, (void *)datablock, sizeof(Block));
|
||||
/*
|
||||
* Take the received encrypted challenge, and encrypt
|
||||
* it again to get a unique session_key for the
|
||||
@@ -349,7 +339,7 @@ kerberos4_is(ap, data, cnt)
|
||||
* increment by one, re-encrypt it and send it back.
|
||||
*/
|
||||
des_ecb_encrypt(datablock, challenge, sched, 0);
|
||||
for (r = 7; r >= 0; r--) {
|
||||
for (r = 7; r >= 0; r++) {
|
||||
register int t;
|
||||
t = (unsigned int)challenge[r] + 1;
|
||||
challenge[r] = t; /* ignore overflow */
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(lint) && !defined(SABER)
|
||||
static
|
||||
#ifdef __STDC__
|
||||
const
|
||||
#endif
|
||||
char rcsid_kerberos5_c[] = "$Id$";
|
||||
#endif /* lint */
|
||||
|
||||
@@ -48,7 +46,7 @@ char rcsid_kerberos5_c[] = "$Id$";
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)kerberos5.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)kerberos5.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -205,7 +203,7 @@ kerberos5_send(ap)
|
||||
ksum.checksum_type = CKSUMTYPE_CRC32;
|
||||
ksum.contents = sum;
|
||||
ksum.length = sizeof(sum);
|
||||
memset((Voidptr )sum, 0, sizeof(sum));
|
||||
bzero((Voidptr )sum, sizeof(sum));
|
||||
|
||||
if (!UserNameRequested) {
|
||||
if (auth_debug_mode) {
|
||||
@@ -258,7 +256,7 @@ kerberos5_send(ap)
|
||||
}
|
||||
|
||||
|
||||
memset((char *)&creds, 0, sizeof(creds));
|
||||
bzero((char *)&creds, sizeof(creds));
|
||||
creds.server = server;
|
||||
|
||||
if (r = krb5_cc_get_principal(ccache, &creds.client)) {
|
||||
@@ -307,12 +305,12 @@ kerberos5_send(ap)
|
||||
if (newkey->keytype != KEYTYPE_DES) {
|
||||
if (creds.keyblock.keytype == KEYTYPE_DES)
|
||||
/* use the session key in credentials instead */
|
||||
memmove((char *)session_key,
|
||||
memcpy((char *)session_key,
|
||||
(char *)creds.keyblock.contents, sizeof(Block));
|
||||
else
|
||||
/* XXX ? */;
|
||||
} else {
|
||||
memmove((char *)session_key, (char *)newkey->contents,
|
||||
memcpy((char *)session_key, (char *)newkey->contents,
|
||||
sizeof(Block));
|
||||
}
|
||||
krb5_free_keyblock(newkey);
|
||||
@@ -457,14 +455,12 @@ kerberos5_is(ap, data, cnt)
|
||||
free(name);
|
||||
if (authdat->authenticator->subkey &&
|
||||
authdat->authenticator->subkey->keytype == KEYTYPE_DES) {
|
||||
memmove((Voidptr )session_key,
|
||||
(Voidptr )authdat->authenticator->subkey->contents,
|
||||
sizeof(Block));
|
||||
bcopy((Voidptr )authdat->authenticator->subkey->contents,
|
||||
(Voidptr )session_key, sizeof(Block));
|
||||
} else if (authdat->ticket->enc_part2->session->keytype ==
|
||||
KEYTYPE_DES) {
|
||||
memmove((Voidptr )session_key,
|
||||
(Voidptr )authdat->ticket->enc_part2->session->contents,
|
||||
sizeof(Block));
|
||||
bcopy((Voidptr )authdat->ticket->enc_part2->session->contents,
|
||||
(Voidptr )session_key, sizeof(Block));
|
||||
} else
|
||||
break;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)krb4encpwd.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
|
||||
@@ -70,10 +70,6 @@ static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <arpa/telnet.h>
|
||||
#include <pwd.h>
|
||||
@@ -81,7 +77,7 @@ static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
|
||||
#include <des.h>
|
||||
#include <krb.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -171,7 +167,7 @@ krb4encpwd_init(ap, server)
|
||||
str_data[3] = TELQUAL_IS;
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
realm = krb_realmofhost(hostname);
|
||||
cp = strchr(hostname, '.');
|
||||
cp = index(hostname, '.');
|
||||
if (*cp != NULL) *cp = NULL;
|
||||
if (read_service_key(KRB_SERVICE_NAME, hostname, realm, 0,
|
||||
KEYFILE, (char *)skey)) {
|
||||
@@ -218,10 +214,10 @@ krb4encpwd_is(ap, data, cnt)
|
||||
return;
|
||||
switch (*data++) {
|
||||
case KRB4_ENCPWD_AUTH:
|
||||
memmove((void *)auth.dat, (void *)data, auth.length = cnt);
|
||||
bcopy((void *)data, (void *)auth.dat, auth.length = cnt);
|
||||
|
||||
gethostname(lhostname, sizeof(lhostname));
|
||||
if ((cp = strchr(lhostname, '.')) != 0) *cp = '\0';
|
||||
if ((cp = index(lhostname, '.')) != 0) *cp = '\0';
|
||||
|
||||
if (r = krb_rd_encpwd_req(&auth, KRB_SERVICE_NAME, lhostname, 0, &adat, NULL, challenge, r_user, r_passwd)) {
|
||||
Data(ap, KRB4_ENCPWD_REJECT, (void *)"Auth failed", -1);
|
||||
@@ -238,7 +234,7 @@ krb4encpwd_is(ap, data, cnt)
|
||||
return;
|
||||
}
|
||||
|
||||
memmove((void *)session_key, (void *)adat.session, sizeof(Block));
|
||||
bcopy((void *)adat.session, (void *)session_key, sizeof(Block));
|
||||
Data(ap, KRB4_ENCPWD_ACCEPT, (void *)0, 0);
|
||||
auth_finished(ap, AUTH_USER);
|
||||
break;
|
||||
@@ -248,7 +244,7 @@ krb4encpwd_is(ap, data, cnt)
|
||||
* Take the received random challenge text and save
|
||||
* for future authentication.
|
||||
*/
|
||||
memmove((void *)challenge, (void *)data, sizeof(Block));
|
||||
bcopy((void *)data, (void *)challenge, sizeof(Block));
|
||||
break;
|
||||
|
||||
|
||||
@@ -259,7 +255,7 @@ krb4encpwd_is(ap, data, cnt)
|
||||
|
||||
/*
|
||||
* If we are doing mutual authentication, get set up to send
|
||||
* the challenge, and verify it when the response comes back.
|
||||
* the challange, and verify it when the response comes back.
|
||||
*/
|
||||
|
||||
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
|
||||
@@ -314,13 +310,13 @@ krb4encpwd_reply(ap, data, cnt)
|
||||
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
realm = krb_realmofhost(hostname);
|
||||
memmove((void *)challenge, (void *)data, cnt);
|
||||
memset(user_passwd, 0, sizeof(user_passwd));
|
||||
bcopy((void *)data, (void *)challenge, cnt);
|
||||
bzero(user_passwd, sizeof(user_passwd));
|
||||
local_des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0);
|
||||
UserPassword = user_passwd;
|
||||
Challenge = challenge;
|
||||
strcpy(instance, RemoteHostName);
|
||||
if ((cp = strchr(instance, '.')) != 0) *cp = '\0';
|
||||
if ((cp = index(instance, '.')) != 0) *cp = '\0';
|
||||
|
||||
if (r = krb_mk_encpwd_req(&krb_token, KRB_SERVICE_NAME, instance, realm, Challenge, UserNameRequested, user_passwd)) {
|
||||
krb_token.length = 0;
|
||||
@@ -413,9 +409,10 @@ krb4encpwd_printsub(data, cnt, buf, buflen)
|
||||
}
|
||||
}
|
||||
|
||||
int passwdok (name, passwd)
|
||||
char *name, *passwd;
|
||||
int passwdok(name, passwd)
|
||||
char *name, *passwd;
|
||||
{
|
||||
char *crypt();
|
||||
char *salt, *p;
|
||||
struct passwd *pwd;
|
||||
int passwdok_status = 0;
|
||||
@@ -424,7 +421,7 @@ int passwdok (name, passwd)
|
||||
salt = pwd->pw_passwd;
|
||||
else salt = "xx";
|
||||
|
||||
p = CRYPT (passwd, salt);
|
||||
p = crypt(passwd, salt);
|
||||
|
||||
if (pwd && !strcmp(p, pwd->pw_passwd)) {
|
||||
passwdok_status = 1;
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
char *RemoteHostName;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)read_password.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)read_password.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -50,10 +50,6 @@ static char sccsid[] = "@(#)read_password.c 8.3 (Berkeley) 5/30/95";
|
||||
* echoing.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(RSA_ENCPWD) || defined(KRB4_ENCPWD)
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -90,7 +86,7 @@ local_des_read_pw_string(s,max,prompt,verify)
|
||||
}
|
||||
|
||||
/* XXX assume jmp_buf is typedef'ed to an array */
|
||||
memmove((char *)env, (char *)old_env, sizeof(env));
|
||||
bcopy((char *)old_env, (char *)env, sizeof(env));
|
||||
if (setjmp(env))
|
||||
goto lose;
|
||||
|
||||
@@ -109,7 +105,7 @@ local_des_read_pw_string(s,max,prompt,verify)
|
||||
(void) fflush(stdout);
|
||||
while (!fgets(s, max, stdin));
|
||||
|
||||
if ((ptr = strchr(s, '\n')))
|
||||
if ((ptr = index(s, '\n')))
|
||||
*ptr = '\0';
|
||||
if (verify) {
|
||||
printf("\nVerifying, please re-enter %s",prompt);
|
||||
@@ -118,7 +114,7 @@ local_des_read_pw_string(s,max,prompt,verify)
|
||||
clearerr(stdin);
|
||||
continue;
|
||||
}
|
||||
if ((ptr = strchr(key_string, '\n')))
|
||||
if ((ptr = index(key_string, '\n')))
|
||||
*ptr = '\0';
|
||||
if (strcmp(s,key_string)) {
|
||||
printf("\n\07\07Mismatch - try again\n");
|
||||
@@ -131,7 +127,7 @@ local_des_read_pw_string(s,max,prompt,verify)
|
||||
|
||||
lose:
|
||||
if (!ok)
|
||||
memset(s, 0, max);
|
||||
bzero(s, max);
|
||||
printf("\n");
|
||||
/* turn echo back on */
|
||||
tty_state.sg_flags |= ECHO;
|
||||
@@ -140,9 +136,9 @@ lose:
|
||||
/*
|
||||
pop_signals();
|
||||
*/
|
||||
memmove((char *)old_env, (char *)env, sizeof(env));
|
||||
bcopy((char *)env, (char *)old_env, sizeof(env));
|
||||
if (verify)
|
||||
memset(key_string, 0, sizeof (key_string));
|
||||
bzero(key_string, sizeof (key_string));
|
||||
s[max-1] = 0; /* force termination */
|
||||
return !ok; /* return nonzero if not okay */
|
||||
}
|
||||
|
||||
@@ -32,12 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)rsaencpwd.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef RSA_ENCPWD
|
||||
/*
|
||||
@@ -78,7 +75,7 @@ static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -86,7 +83,6 @@ static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <crypt.h>
|
||||
|
||||
#include "encrypt.h"
|
||||
#include "auth.h"
|
||||
@@ -162,9 +158,9 @@ rsaencpwd_init(ap, server)
|
||||
|
||||
if (server) {
|
||||
str_data[3] = TELQUAL_REPLY;
|
||||
memset(key_file, 0, sizeof(key_file));
|
||||
bzero(key_file, sizeof(key_file));
|
||||
gethostname(lhostname, sizeof(lhostname));
|
||||
if ((cp = strchr(lhostname, '.')) != 0) *cp = '\0';
|
||||
if ((cp = index(lhostname, '.')) != 0) *cp = '\0';
|
||||
strcpy(key_file, "/etc/.");
|
||||
strcat(key_file, lhostname);
|
||||
strcat(key_file, "_privkey");
|
||||
@@ -214,7 +210,7 @@ rsaencpwd_is(ap, data, cnt)
|
||||
cnt--;
|
||||
switch (*data++) {
|
||||
case RSA_ENCPWD_AUTH:
|
||||
memmove((void *)auth.dat, (void *)data, auth.length = cnt);
|
||||
bcopy((void *)data, (void *)auth.dat, auth.length = cnt);
|
||||
|
||||
if ((fp=fopen(key_file, "r"))==NULL) {
|
||||
Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1);
|
||||
@@ -256,7 +252,7 @@ rsaencpwd_is(ap, data, cnt)
|
||||
|
||||
/*
|
||||
* If we are doing mutual authentication, get set up to send
|
||||
* the challenge, and verify it when the response comes back.
|
||||
* the challange, and verify it when the response comes back.
|
||||
*/
|
||||
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_ONE_WAY) {
|
||||
register int i;
|
||||
@@ -298,12 +294,12 @@ rsaencpwd_is(ap, data, cnt)
|
||||
ptr +=NumEncodeLengthOctets(chalkey_len);
|
||||
*ptr++ = 0x04; /* OCTET STRING */
|
||||
*ptr++ = challenge_len;
|
||||
memmove(ptr, challenge, challenge_len);
|
||||
bcopy(challenge, ptr, challenge_len);
|
||||
ptr += challenge_len;
|
||||
*ptr++ = 0x04; /* OCTET STRING */
|
||||
EncodeLength(ptr, i);
|
||||
ptr += NumEncodeLengthOctets(i);
|
||||
memmove(ptr, key, i);
|
||||
bcopy(key, ptr, i);
|
||||
chalkey_len = 1+NumEncodeLengthOctets(chalkey_len)+chalkey_len;
|
||||
Data(ap, RSA_ENCPWD_CHALLENGEKEY, (void *)chalkey, chalkey_len);
|
||||
}
|
||||
@@ -349,7 +345,7 @@ rsaencpwd_reply(ap, data, cnt)
|
||||
* Verify that the response to the challenge is correct.
|
||||
*/
|
||||
|
||||
memmove((void *)chalkey, (void *)data, cnt);
|
||||
bcopy((void *)data, (void *)chalkey, cnt);
|
||||
ptr = (char *) &chalkey[0];
|
||||
ptr += DecodeHeaderLength(chalkey);
|
||||
if (*ptr != 0x04) {
|
||||
@@ -358,7 +354,7 @@ rsaencpwd_reply(ap, data, cnt)
|
||||
*ptr++;
|
||||
challenge_len = DecodeValueLength(ptr);
|
||||
ptr += NumEncodeLengthOctets(challenge_len);
|
||||
memmove(challenge, ptr, challenge_len);
|
||||
bcopy(ptr, challenge, challenge_len);
|
||||
ptr += challenge_len;
|
||||
if (*ptr != 0x04) {
|
||||
return;
|
||||
@@ -366,8 +362,8 @@ rsaencpwd_reply(ap, data, cnt)
|
||||
*ptr++;
|
||||
pubkey_len = DecodeValueLength(ptr);
|
||||
ptr += NumEncodeLengthOctets(pubkey_len);
|
||||
memmove(pubkey, ptr, pubkey_len);
|
||||
memset(user_passwd, 0, sizeof(user_passwd));
|
||||
bcopy(ptr, pubkey, pubkey_len);
|
||||
bzero(user_passwd, sizeof(user_passwd));
|
||||
local_des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0);
|
||||
UserPassword = user_passwd;
|
||||
Challenge = challenge;
|
||||
@@ -460,8 +456,9 @@ rsaencpwd_printsub(data, cnt, buf, buflen)
|
||||
}
|
||||
|
||||
int rsaencpwd_passwdok(name, passwd)
|
||||
char *name, *passwd;
|
||||
char *name, *passwd;
|
||||
{
|
||||
char *crypt();
|
||||
char *salt, *p;
|
||||
struct passwd *pwd;
|
||||
int passwdok_status = 0;
|
||||
@@ -470,7 +467,7 @@ int rsaencpwd_passwdok(name, passwd)
|
||||
salt = pwd->pw_passwd;
|
||||
else salt = "xx";
|
||||
|
||||
p = CRYPT (passwd, salt);
|
||||
p = crypt(passwd, salt);
|
||||
|
||||
if (pwd && !strcmp(p, pwd->pw_passwd)) {
|
||||
passwdok_status = 1;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)spx.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)spx.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef SPX
|
||||
@@ -69,15 +69,11 @@ static char sccsid[] = "@(#)spx.c 8.2 (Berkeley) 5/30/95";
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <arpa/telnet.h>
|
||||
#include <stdio.h>
|
||||
#include "gssapi_defs.h"
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_STRING_H
|
||||
@@ -251,7 +247,7 @@ spx_send(ap)
|
||||
|
||||
input_chan_bindings->initiator_addrtype = GSS_C_AF_INET;
|
||||
input_chan_bindings->initiator_address.length = 4;
|
||||
address = malloc(4);
|
||||
address = (char *) malloc(4);
|
||||
input_chan_bindings->initiator_address.value = (char *) address;
|
||||
address[0] = ((from_addr & 0xff000000) >> 24);
|
||||
address[1] = ((from_addr & 0xff0000) >> 16);
|
||||
@@ -259,7 +255,7 @@ spx_send(ap)
|
||||
address[3] = (from_addr & 0xff);
|
||||
input_chan_bindings->acceptor_addrtype = GSS_C_AF_INET;
|
||||
input_chan_bindings->acceptor_address.length = 4;
|
||||
address = malloc(4);
|
||||
address = (char *) malloc(4);
|
||||
input_chan_bindings->acceptor_address.value = (char *) address;
|
||||
address[0] = ((to_addr & 0xff000000) >> 24);
|
||||
address[1] = ((to_addr & 0xff0000) >> 16);
|
||||
@@ -356,7 +352,7 @@ spx_is(ap, data, cnt)
|
||||
|
||||
input_chan_bindings->initiator_addrtype = GSS_C_AF_INET;
|
||||
input_chan_bindings->initiator_address.length = 4;
|
||||
address = malloc(4);
|
||||
address = (char *) malloc(4);
|
||||
input_chan_bindings->initiator_address.value = (char *) address;
|
||||
address[0] = ((from_addr & 0xff000000) >> 24);
|
||||
address[1] = ((from_addr & 0xff0000) >> 16);
|
||||
@@ -364,7 +360,7 @@ spx_is(ap, data, cnt)
|
||||
address[3] = (from_addr & 0xff);
|
||||
input_chan_bindings->acceptor_addrtype = GSS_C_AF_INET;
|
||||
input_chan_bindings->acceptor_address.length = 4;
|
||||
address = malloc(4);
|
||||
address = (char *) malloc(4);
|
||||
input_chan_bindings->acceptor_address.value = (char *) address;
|
||||
address[0] = ((to_addr & 0xff000000) >> 24);
|
||||
address[1] = ((to_addr & 0xff0000) >> 16);
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)rexecd.8 8.3 (Berkeley) 6/1/94
|
||||
.\" @(#)rexecd.8 8.2 (Berkeley) 12/11/93
|
||||
.\"
|
||||
.Dd June 1, 1994
|
||||
.Dd December 11, 1993
|
||||
.Dt REXECD 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -117,7 +117,6 @@ list (as configured into the system).
|
||||
No password file entry for the user name existed.
|
||||
.It Sy Password incorrect.
|
||||
The wrong password was supplied.
|
||||
.ne 1i
|
||||
.It Sy \&No remote directory.
|
||||
The
|
||||
.Xr chdir
|
||||
|
||||
@@ -41,42 +41,22 @@ static char copyright[] =
|
||||
static char sccsid[] = "@(#)rexecd.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <paths.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <crypt.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
/*VARARGS1*/
|
||||
int error();
|
||||
@@ -108,21 +88,19 @@ main(argc, argv)
|
||||
char username[20] = "USER=";
|
||||
char homedir[64] = "HOME=";
|
||||
char shell[64] = "SHELL=";
|
||||
char path[sizeof(PATH_DEFPATH) + sizeof("PATH=")] = "PATH=";
|
||||
char path[sizeof(_PATH_DEFPATH) + sizeof("PATH=")] = "PATH=";
|
||||
char *envinit[] =
|
||||
{homedir, shell, path, username, 0};
|
||||
extern char **environ;
|
||||
char **environ;
|
||||
|
||||
struct sockaddr_in asin = { AF_INET };
|
||||
|
||||
char *getstr ();
|
||||
|
||||
doit(f, fromp)
|
||||
int f;
|
||||
struct sockaddr_in *fromp;
|
||||
{
|
||||
char *cmdbuf, *cp, *namep;
|
||||
char *user, *pass;
|
||||
char cmdbuf[NCARGS+1], *cp, *namep;
|
||||
char user[16], pass[16];
|
||||
struct passwd *pwd;
|
||||
int s;
|
||||
u_short port;
|
||||
@@ -134,7 +112,7 @@ doit(f, fromp)
|
||||
(void) signal(SIGQUIT, SIG_DFL);
|
||||
(void) signal(SIGTERM, SIG_DFL);
|
||||
#ifdef DEBUG
|
||||
{ int t = open(_PATH_TTY, O_RDWR);
|
||||
{ int t = open(_PATH_TTY, 2);
|
||||
if (t >= 0) {
|
||||
ioctl(t, TIOCNOTTY, (char *)0);
|
||||
(void) close(t);
|
||||
@@ -167,11 +145,9 @@ doit(f, fromp)
|
||||
exit(1);
|
||||
(void) alarm(0);
|
||||
}
|
||||
|
||||
user = getstr ("username");
|
||||
pass = getstr ("password");
|
||||
cmdbuf = getstr ("command");
|
||||
|
||||
getstr(user, sizeof(user), "username");
|
||||
getstr(pass, sizeof(pass), "password");
|
||||
getstr(cmdbuf, sizeof(cmdbuf), "command");
|
||||
setpwent();
|
||||
pwd = getpwnam(user);
|
||||
if (pwd == NULL) {
|
||||
@@ -180,7 +156,7 @@ doit(f, fromp)
|
||||
}
|
||||
endpwent();
|
||||
if (*pwd->pw_passwd != '\0') {
|
||||
namep = CRYPT (pass, pwd->pw_passwd);
|
||||
namep = crypt(pass, pwd->pw_passwd);
|
||||
if (strcmp(namep, pwd->pw_passwd)) {
|
||||
error("Password incorrect.\n");
|
||||
exit(1);
|
||||
@@ -226,18 +202,18 @@ doit(f, fromp)
|
||||
} while (readfrom);
|
||||
exit(0);
|
||||
}
|
||||
setpgid (0, getpid());
|
||||
setpgrp(0, getpid());
|
||||
(void) close(s); (void)close(pv[0]);
|
||||
dup2(pv[1], 2);
|
||||
}
|
||||
if (*pwd->pw_shell == '\0')
|
||||
pwd->pw_shell = PATH_BSHELL;
|
||||
pwd->pw_shell = _PATH_BSHELL;
|
||||
if (f > 2)
|
||||
(void) close(f);
|
||||
(void) setgid((gid_t)pwd->pw_gid);
|
||||
initgroups(pwd->pw_name, pwd->pw_gid);
|
||||
(void) setuid((uid_t)pwd->pw_uid);
|
||||
(void)strcat(path, PATH_DEFPATH);
|
||||
(void)strcat(path, _PATH_DEFPATH);
|
||||
environ = envinit;
|
||||
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
|
||||
strncat(shell, pwd->pw_shell, sizeof(shell)-7);
|
||||
@@ -260,46 +236,24 @@ error(fmt, a1, a2, a3)
|
||||
char buf[BUFSIZ];
|
||||
|
||||
buf[0] = 1;
|
||||
snprintf (buf + 1, sizeof buf - 1, fmt, a1, a2, a3);
|
||||
write (2, buf, strlen(buf));
|
||||
(void) sprintf(buf+1, fmt, a1, a2, a3);
|
||||
(void) write(2, buf, strlen(buf));
|
||||
}
|
||||
|
||||
char *
|
||||
getstr(err)
|
||||
getstr(buf, cnt, err)
|
||||
char *buf;
|
||||
int cnt;
|
||||
char *err;
|
||||
{
|
||||
size_t buf_len = 100;
|
||||
char *buf = malloc (buf_len), *end = buf;
|
||||
|
||||
if (! buf) {
|
||||
error ("Out of space reading %s\n", err);
|
||||
exit (1);
|
||||
}
|
||||
char c;
|
||||
|
||||
do {
|
||||
/* Oh this is efficient, oh yes. [But what can be done?] */
|
||||
int rd = read(STDIN_FILENO, end, 1);
|
||||
if (rd <= 0) {
|
||||
if (rd == 0)
|
||||
error ("EOF reading %s\n", err);
|
||||
else
|
||||
perror (err);
|
||||
if (read(0, &c, 1) != 1)
|
||||
exit(1);
|
||||
*buf++ = c;
|
||||
if (--cnt == 0) {
|
||||
error("%s too long\n", err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
end += rd;
|
||||
if ((buf + buf_len - end) < (buf_len >> 3)) {
|
||||
/* Not very much room left in our buffer, grow it. */
|
||||
size_t end_offs = end - buf;
|
||||
buf_len += buf_len;
|
||||
buf = realloc (buf, buf_len);
|
||||
if (! buf) {
|
||||
error ("Out of space reading %s\n", err);
|
||||
exit (1);
|
||||
}
|
||||
end = buf + end_offs;
|
||||
}
|
||||
} while (*(end - 1));
|
||||
|
||||
return buf;
|
||||
} while (c != 0);
|
||||
}
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
static char sccsid[] = "@(#)des_rw.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef CRYPT
|
||||
#ifdef KERBEROS
|
||||
#include <sys/param.h>
|
||||
|
||||
@@ -36,10 +36,6 @@ static char Xsccsid[] = "derived from @(#)rcmd.c 5.17 (Berkeley) 6/27/88";
|
||||
static char sccsid[] = "@(#)kcmd.c 8.2 (Berkeley) 8/19/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -44,10 +44,6 @@ static char sccsid[] = "@(#)krcmd.c 8.1 (Berkeley) 6/6/93";
|
||||
* kfall Exp Locker: kfall $";
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef KERBEROS
|
||||
#include <sys/types.h>
|
||||
#ifdef CRYPT
|
||||
|
||||
@@ -29,26 +29,21 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)rlogin.1 8.2 (Berkeley) 4/29/95
|
||||
.\" @(#)rlogin.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd April 29, 1995
|
||||
.Dd June 6, 1993
|
||||
.Dt RLOGIN 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
.Nm rlogin
|
||||
.Nd remote login
|
||||
.Sh SYNOPSIS
|
||||
.Nm rlogin
|
||||
.Ar rlogin
|
||||
.Op Fl 8EKLdx
|
||||
.Op Fl e Ar char
|
||||
.Op Fl k Ar realm
|
||||
.Op Fl l Ar username
|
||||
.Ar host
|
||||
.Nm rlogin
|
||||
.Op Fl 8EKLdx
|
||||
.Op Fl e Ar char
|
||||
.Op Fl k Ar realm
|
||||
.Ar username@host
|
||||
.Sh DESCRIPTION
|
||||
.Nm Rlogin
|
||||
starts a terminal session on a remote host
|
||||
|
||||
398
rlogin/rlogin.c
398
rlogin/rlogin.c
@@ -38,68 +38,35 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)rlogin.c 8.4 (Berkeley) 4/29/95";
|
||||
static char sccsid[] = "@(#)rlogin.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* rlogin - remote login
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_STREAM_H
|
||||
#include <sys/stream.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TTY_H
|
||||
#include <sys/tty.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PTYVAR_H
|
||||
#include <sys/ptyvar.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <netdb.h>
|
||||
#include <pwd.h>
|
||||
#include <setjmp.h>
|
||||
#include <termios.h>
|
||||
#include <sgtty.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
@@ -126,19 +93,16 @@ char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
|
||||
#define SIGUSR1 30
|
||||
#endif
|
||||
|
||||
#ifndef _POSIX_VDISABLE
|
||||
# ifdef VDISABLE
|
||||
# define _POSIX_VDISABLE VDISABLE
|
||||
# else
|
||||
# define _POSIX_VDISABLE ((cc_t)'\377')
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int eight, litout, rem;
|
||||
|
||||
int noescape;
|
||||
u_char escapechar = '~';
|
||||
|
||||
char *speeds[] = {
|
||||
"0", "50", "75", "110", "134", "150", "200", "300", "600", "1200",
|
||||
"1800", "2400", "4800", "9600", "19200", "38400"
|
||||
};
|
||||
|
||||
#ifdef OLDSUN
|
||||
struct winsize {
|
||||
unsigned short ws_row, ws_col;
|
||||
@@ -151,21 +115,20 @@ struct winsize winsize;
|
||||
|
||||
void catch_child __P((int));
|
||||
void copytochild __P((int));
|
||||
void doit __P((sigset_t *));
|
||||
void done __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((sigset_t *));
|
||||
int reader __P((int));
|
||||
void sendwindow __P((void));
|
||||
void setsignal __P((int));
|
||||
int speed __P((int));
|
||||
void sigwinch __P((int));
|
||||
void stop __P((char));
|
||||
void usage __P((void));
|
||||
__dead void usage __P((void));
|
||||
void writer __P((void));
|
||||
void writeroob __P((int));
|
||||
|
||||
@@ -176,35 +139,30 @@ void warning __P((const char *, ...));
|
||||
int get_window_size __P((int, struct winsize *));
|
||||
#endif
|
||||
|
||||
extern sig_t setsig __P((int, sig_t));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
struct passwd *pw;
|
||||
struct servent *sp;
|
||||
sigset_t smask;
|
||||
uid_t uid;
|
||||
int argoff, ch, dflag, one;
|
||||
struct sgttyb ttyb;
|
||||
long omask;
|
||||
int argoff, ch, dflag, one, uid;
|
||||
char *host, *p, *user, term[1024];
|
||||
|
||||
#ifndef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
__progname = argv[0];
|
||||
#endif
|
||||
|
||||
argoff = dflag = 0;
|
||||
one = 1;
|
||||
host = user = NULL;
|
||||
|
||||
if (p = strrchr(argv[0], '/'))
|
||||
if (p = rindex(argv[0], '/'))
|
||||
++p;
|
||||
else
|
||||
p = argv[0];
|
||||
|
||||
if (strcmp(p, "rlogin") != 0)
|
||||
if (strcmp(p, "rlogin"))
|
||||
host = p;
|
||||
|
||||
/* handle "rlogin host flags" */
|
||||
@@ -273,17 +231,9 @@ main(argc, argv)
|
||||
if (*argv)
|
||||
usage();
|
||||
|
||||
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 (!(pw = getpwuid(uid = getuid()))) {
|
||||
(void)fprintf(stderr, "rlogin: unknown user id.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!user)
|
||||
user = pw->pw_name;
|
||||
@@ -301,31 +251,30 @@ main(argc, argv)
|
||||
#endif
|
||||
if (sp == NULL)
|
||||
sp = getservbyname("login", "tcp");
|
||||
if (sp == NULL)
|
||||
errx(1, "login/tcp: unknown service.");
|
||||
if (sp == NULL) {
|
||||
(void)fprintf(stderr, "rlogin: login/tcp: unknown service.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
(void)snprintf(term, sizeof(term), "%s/%d",
|
||||
((p = getenv("TERM")) ? p : "network"),
|
||||
speed(0));
|
||||
(void)strcpy(term, (p = getenv("TERM")) ? p : "network");
|
||||
if (ioctl(0, TIOCGETP, &ttyb) == 0) {
|
||||
(void)strcat(term, "/");
|
||||
(void)strcat(term, speeds[(int)ttyb.sg_ospeed]);
|
||||
}
|
||||
|
||||
(void)get_window_size(0, &winsize);
|
||||
|
||||
setsig (SIGPIPE, lostpeer);
|
||||
|
||||
(void)signal(SIGPIPE, lostpeer);
|
||||
/* will use SIGUSR1 for window size hack, so hold it off */
|
||||
sigemptyset (&smask);
|
||||
sigaddset (&smask, SIGURG);
|
||||
sigaddset (&smask, SIGUSR1);
|
||||
sigprocmask (SIG_SETMASK, &smask, &smask);
|
||||
|
||||
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.
|
||||
*/
|
||||
setsig (SIGURG, copytochild);
|
||||
setsig (SIGUSR1, writeroob);
|
||||
(void)signal(SIGURG, copytochild);
|
||||
(void)signal(SIGUSR1, writeroob);
|
||||
|
||||
#ifdef KERBEROS
|
||||
try_connect:
|
||||
@@ -334,8 +283,11 @@ try_connect:
|
||||
|
||||
/* Fully qualify hostname (needed for krb_realmofhost). */
|
||||
hp = gethostbyname(host);
|
||||
if (hp != NULL && !(host = strdup(hp->h_name)))
|
||||
errx(1, "%s", strerror(ENOMEM));
|
||||
if (hp != NULL && !(host = strdup(hp->h_name))) {
|
||||
(void)fprintf(stderr, "rlogin: %s\n",
|
||||
strerror(ENOMEM));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rem = KSUCCESS;
|
||||
errno = 0;
|
||||
@@ -353,8 +305,11 @@ try_connect:
|
||||
if (rem < 0) {
|
||||
use_kerberos = 0;
|
||||
sp = getservbyname("login", "tcp");
|
||||
if (sp == NULL)
|
||||
errx(1, "unknown service 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)
|
||||
@@ -363,8 +318,11 @@ try_connect:
|
||||
}
|
||||
} else {
|
||||
#ifdef CRYPT
|
||||
if (doencrypt)
|
||||
errx(1, "the -x flag requires Kerberos authentication.");
|
||||
if (doencrypt) {
|
||||
(void)fprintf(stderr,
|
||||
"rlogin: the -x flag requires Kerberos authentication.\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif /* CRYPT */
|
||||
rem = rcmd(&host, sp->s_port, pw->pw_name, user, term, 0);
|
||||
}
|
||||
@@ -376,80 +334,53 @@ try_connect:
|
||||
exit(1);
|
||||
|
||||
if (dflag &&
|
||||
setsockopt(rem, SOL_SOCKET, SO_DEBUG, (char *) &one,
|
||||
sizeof(one)) < 0)
|
||||
warn("setsockopt DEBUG (ignored)");
|
||||
|
||||
#if defined (IP_TOS) && defined (IPPROTO_IP) && defined (IPTOS_LOWDELAY)
|
||||
setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, sizeof(one)) < 0)
|
||||
(void)fprintf(stderr, "rlogin: setsockopt: %s.\n",
|
||||
strerror(errno));
|
||||
one = IPTOS_LOWDELAY;
|
||||
if (setsockopt(rem, IPPROTO_IP, IP_TOS, (char *)&one, sizeof(int)) < 0)
|
||||
warn("setsockopt TOS (ignored)");
|
||||
#endif
|
||||
perror("rlogin: setsockopt TOS (ignored)");
|
||||
|
||||
(void)setuid(uid);
|
||||
doit(&smask);
|
||||
doit(omask);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
#if BSD >= 198810
|
||||
int
|
||||
speed(fd)
|
||||
int fd;
|
||||
{
|
||||
struct termios tt;
|
||||
|
||||
(void)tcgetattr(fd, &tt);
|
||||
|
||||
return ((int) cfgetispeed(&tt));
|
||||
}
|
||||
#else
|
||||
int speeds[] = { /* for older systems, B0 .. EXTB */
|
||||
0, 50, 75, 110,
|
||||
134, 150, 200, 300,
|
||||
600, 1200, 1800, 2400,
|
||||
4800, 9600, 19200, 38400
|
||||
};
|
||||
|
||||
int
|
||||
speed(fd)
|
||||
int fd;
|
||||
{
|
||||
struct termios tt;
|
||||
|
||||
(void)tcgetattr(fd, &tt);
|
||||
|
||||
return (speeds[(int)cfgetispeed(&tt)]);
|
||||
}
|
||||
#endif
|
||||
|
||||
pid_t child;
|
||||
struct termios deftt;
|
||||
struct termios nott;
|
||||
int child, defflags, deflflags, tabflag;
|
||||
char deferase, defkill;
|
||||
struct tchars deftc;
|
||||
struct ltchars defltc;
|
||||
struct tchars notc = { -1, -1, -1, -1, -1, -1 };
|
||||
struct ltchars noltc = { -1, -1, -1, -1, -1, -1 };
|
||||
|
||||
void
|
||||
doit(smask)
|
||||
sigset_t *smask;
|
||||
doit(omask)
|
||||
long omask;
|
||||
{
|
||||
int i;
|
||||
struct sgttyb sb;
|
||||
|
||||
for (i = 0; i < NCCS; i++)
|
||||
nott.c_cc[i] = _POSIX_VDISABLE;
|
||||
tcgetattr(0, &deftt);
|
||||
nott.c_cc[VSTART] = deftt.c_cc[VSTART];
|
||||
nott.c_cc[VSTOP] = deftt.c_cc[VSTOP];
|
||||
|
||||
setsig (SIGINT, SIG_IGN);
|
||||
(void)ioctl(0, TIOCGETP, (char *)&sb);
|
||||
defflags = sb.sg_flags;
|
||||
tabflag = defflags & TBDELAY;
|
||||
defflags &= ECHO | CRMOD;
|
||||
deferase = sb.sg_erase;
|
||||
defkill = sb.sg_kill;
|
||||
(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, &defltc);
|
||||
(void)signal(SIGINT, SIG_IGN);
|
||||
setsignal(SIGHUP);
|
||||
setsignal(SIGQUIT);
|
||||
|
||||
child = fork();
|
||||
if (child == -1) {
|
||||
warn("fork");
|
||||
(void)fprintf(stderr, "rlogin: fork: %s.\n", strerror(errno));
|
||||
done(1);
|
||||
}
|
||||
if (child == 0) {
|
||||
mode(1);
|
||||
if (reader(smask) == 0) {
|
||||
if (reader(omask) == 0) {
|
||||
msg("connection closed.");
|
||||
exit(0);
|
||||
}
|
||||
@@ -465,10 +396,8 @@ doit(smask)
|
||||
* signals to the child. We can now unblock SIGURG and SIGUSR1
|
||||
* that were set above.
|
||||
*/
|
||||
(void)sigprocmask(SIG_SETMASK, smask, (sigset_t *) 0);
|
||||
|
||||
setsig (SIGCHLD, catch_child);
|
||||
|
||||
(void)sigsetmask(omask);
|
||||
(void)signal(SIGCHLD, catch_child);
|
||||
writer();
|
||||
msg("closed connection.");
|
||||
done(0);
|
||||
@@ -479,34 +408,25 @@ void
|
||||
setsignal(sig)
|
||||
int sig;
|
||||
{
|
||||
sig_t handler;
|
||||
sigset_t sigs;
|
||||
int omask = sigblock(sigmask(sig));
|
||||
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, sig);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &sigs);
|
||||
|
||||
handler = setsig (sig, exit);
|
||||
if (handler == SIG_IGN)
|
||||
setsig (sig, handler);
|
||||
|
||||
(void)sigprocmask(SIG_SETMASK, &sigs, (sigset_t *) 0);
|
||||
if (signal(sig, exit) == SIG_IGN)
|
||||
(void)signal(sig, SIG_IGN);
|
||||
(void)sigsetmask(omask);
|
||||
}
|
||||
|
||||
void
|
||||
__dead void
|
||||
done(status)
|
||||
int status;
|
||||
{
|
||||
pid_t w;
|
||||
int wstatus;
|
||||
int w, wstatus;
|
||||
|
||||
mode(0);
|
||||
if (child > 0) {
|
||||
/* make sure catch_child does not snap it up */
|
||||
setsig (SIGCHLD, SIG_DFL);
|
||||
(void)signal(SIGCHLD, SIG_DFL);
|
||||
if (kill(child, SIGKILL) >= 0)
|
||||
while ((w = wait(&wstatus)) > 0 && w != child)
|
||||
continue;
|
||||
while ((w = wait(&wstatus)) > 0 && w != child);
|
||||
}
|
||||
exit(status);
|
||||
}
|
||||
@@ -523,7 +443,7 @@ writeroob(signo)
|
||||
{
|
||||
if (dosigwinch == 0) {
|
||||
sendwindow();
|
||||
setsig (SIGWINCH, sigwinch);
|
||||
(void)signal(SIGWINCH, sigwinch);
|
||||
}
|
||||
dosigwinch = 1;
|
||||
}
|
||||
@@ -532,16 +452,16 @@ void
|
||||
catch_child(signo)
|
||||
int signo;
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
union wait status;
|
||||
int pid;
|
||||
|
||||
for (;;) {
|
||||
pid = waitpid(-1, &status, WNOHANG|WUNTRACED);
|
||||
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)))
|
||||
done(WEXITSTATUS(status) | WTERMSIG(status));
|
||||
done((int)(status.w_termsig | status.w_retcode));
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
@@ -582,15 +502,11 @@ writer()
|
||||
}
|
||||
} else if (local) {
|
||||
local = 0;
|
||||
if (c == '.' || c == deftt.c_cc[VEOF]) {
|
||||
if (c == '.' || c == deftc.t_eofc) {
|
||||
echo(c);
|
||||
break;
|
||||
}
|
||||
if (c == deftt.c_cc[VSUSP]
|
||||
#ifdef VDSUSP
|
||||
|| c == deftt.c_cc[VDSUSP]
|
||||
#endif
|
||||
) {
|
||||
if (c == defltc.t_suspc || c == defltc.t_dsuspc) {
|
||||
bol = 1;
|
||||
echo(c);
|
||||
stop(c);
|
||||
@@ -622,8 +538,8 @@ writer()
|
||||
msg("line gone");
|
||||
break;
|
||||
}
|
||||
bol = c == deftt.c_cc[VKILL] || c == deftt.c_cc[VEOF] ||
|
||||
c == deftt.c_cc[VINTR] || c == deftt.c_cc[VSUSP] ||
|
||||
bol = c == defkill || c == deftc.t_eofc ||
|
||||
c == deftc.t_intrc || c == defltc.t_suspc ||
|
||||
c == '\r' || c == '\n';
|
||||
}
|
||||
}
|
||||
@@ -664,9 +580,9 @@ stop(cmdc)
|
||||
#endif
|
||||
{
|
||||
mode(0);
|
||||
setsig (SIGCHLD, SIG_IGN);
|
||||
(void)kill(cmdc == deftt.c_cc[VSUSP] ? 0 : getpid(), SIGTSTP);
|
||||
setsig (SIGCHLD, catch_child);
|
||||
(void)signal(SIGCHLD, SIG_IGN);
|
||||
(void)kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP);
|
||||
(void)signal(SIGCHLD, catch_child);
|
||||
mode(1);
|
||||
sigwinch(0); /* check for size changes */
|
||||
}
|
||||
@@ -678,7 +594,7 @@ sigwinch(signo)
|
||||
struct winsize ws;
|
||||
|
||||
if (dosigwinch && get_window_size(0, &ws) == 0 &&
|
||||
memcmp(&ws, &winsize, sizeof(ws))) {
|
||||
bcmp(&ws, &winsize, sizeof(ws))) {
|
||||
winsize = ws;
|
||||
sendwindow();
|
||||
}
|
||||
@@ -720,15 +636,14 @@ sendwindow()
|
||||
#define WRITING 2
|
||||
|
||||
jmp_buf rcvtop;
|
||||
pid_t ppid;
|
||||
int rcvcnt, rcvstate;
|
||||
int ppid, rcvcnt, rcvstate;
|
||||
char rcvbuf[8 * 1024];
|
||||
|
||||
void
|
||||
oob(signo)
|
||||
int signo;
|
||||
{
|
||||
struct termios tt;
|
||||
struct sgttyb sb;
|
||||
int atmark, n, out, rcvd;
|
||||
char waste[BUFSIZ], mark;
|
||||
|
||||
@@ -763,26 +678,29 @@ oob(signo)
|
||||
(void)kill(ppid, SIGUSR1);
|
||||
}
|
||||
if (!eight && (mark & TIOCPKT_NOSTOP)) {
|
||||
tcgetattr(0, &tt);
|
||||
tt.c_iflag &= ~(IXON | IXOFF);
|
||||
tt.c_cc[VSTOP] = _POSIX_VDISABLE;
|
||||
tt.c_cc[VSTART] = _POSIX_VDISABLE;
|
||||
tcsetattr(0, TCSANOW, &tt);
|
||||
(void)ioctl(0, TIOCGETP, (char *)&sb);
|
||||
sb.sg_flags &= ~CBREAK;
|
||||
sb.sg_flags |= RAW;
|
||||
(void)ioctl(0, TIOCSETN, (char *)&sb);
|
||||
notc.t_stopc = -1;
|
||||
notc.t_startc = -1;
|
||||
(void)ioctl(0, TIOCSETC, (char *)¬c);
|
||||
}
|
||||
if (!eight && (mark & TIOCPKT_DOSTOP)) {
|
||||
tcgetattr(0, &tt);
|
||||
tt.c_iflag |= (IXON|IXOFF);
|
||||
tt.c_cc[VSTOP] = deftt.c_cc[VSTOP];
|
||||
tt.c_cc[VSTART] = deftt.c_cc[VSTART];
|
||||
tcsetattr(0, TCSANOW, &tt);
|
||||
(void)ioctl(0, TIOCGETP, (char *)&sb);
|
||||
sb.sg_flags &= ~RAW;
|
||||
sb.sg_flags |= CBREAK;
|
||||
(void)ioctl(0, TIOCSETN, (char *)&sb);
|
||||
notc.t_stopc = deftc.t_stopc;
|
||||
notc.t_startc = deftc.t_startc;
|
||||
(void)ioctl(0, TIOCSETC, (char *)¬c);
|
||||
}
|
||||
if (mark & TIOCPKT_FLUSHWRITE) {
|
||||
#ifdef TIOCFLUSH
|
||||
(void)ioctl(1, TIOCFLUSH, (char *)&out);
|
||||
#endif
|
||||
for (;;) {
|
||||
if (ioctl(rem, SIOCATMARK, &atmark) < 0) {
|
||||
warn("ioctl SIOCATMARK (ignored)");
|
||||
(void)fprintf(stderr, "rlogin: ioctl: %s.\n",
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
if (atmark)
|
||||
@@ -814,11 +732,10 @@ oob(signo)
|
||||
|
||||
/* reader: read from remote: line -> 1 */
|
||||
int
|
||||
reader(smask)
|
||||
sigset_t *smask;
|
||||
reader(omask)
|
||||
int omask;
|
||||
{
|
||||
pid_t pid;
|
||||
int n, remaining;
|
||||
int pid, n, remaining;
|
||||
char *bufp;
|
||||
|
||||
#if BSD >= 43 || defined(SUNOS4)
|
||||
@@ -826,14 +743,12 @@ reader(smask)
|
||||
#else
|
||||
pid = -getpid(); /* old broken systems use negatives */
|
||||
#endif
|
||||
|
||||
setsig (SIGTTOU, SIG_IGN);
|
||||
setsig (SIGURG, oob);
|
||||
|
||||
(void)signal(SIGTTOU, SIG_IGN);
|
||||
(void)signal(SIGURG, oob);
|
||||
ppid = getppid();
|
||||
(void)fcntl(rem, F_SETOWN, pid);
|
||||
(void)setjmp(rcvtop);
|
||||
(void)sigprocmask(SIG_SETMASK, smask, (sigset_t *) 0);
|
||||
(void)sigsetmask(omask);
|
||||
bufp = rcvbuf;
|
||||
for (;;) {
|
||||
while ((remaining = rcvcnt - (bufp - rcvbuf)) > 0) {
|
||||
@@ -863,7 +778,8 @@ reader(smask)
|
||||
if (rcvcnt < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
warn("read");
|
||||
(void)fprintf(stderr, "rlogin: read: %s.\n",
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
@@ -873,39 +789,49 @@ void
|
||||
mode(f)
|
||||
int f;
|
||||
{
|
||||
struct termios tt;
|
||||
struct ltchars *ltc;
|
||||
struct sgttyb sb;
|
||||
struct tchars *tc;
|
||||
int lflags;
|
||||
|
||||
switch (f) {
|
||||
(void)ioctl(0, TIOCGETP, (char *)&sb);
|
||||
(void)ioctl(0, TIOCLGET, (char *)&lflags);
|
||||
switch(f) {
|
||||
case 0:
|
||||
tcsetattr(0, TCSADRAIN, &deftt);
|
||||
sb.sg_flags &= ~(CBREAK|RAW|TBDELAY);
|
||||
sb.sg_flags |= defflags|tabflag;
|
||||
tc = &deftc;
|
||||
ltc = &defltc;
|
||||
sb.sg_kill = defkill;
|
||||
sb.sg_erase = deferase;
|
||||
lflags = deflflags;
|
||||
break;
|
||||
case 1:
|
||||
tt = deftt;
|
||||
tt.c_oflag &= ~(OPOST);
|
||||
tt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
tt.c_iflag &= ~(ICRNL);
|
||||
tt.c_cc[VMIN] = 1;
|
||||
tt.c_cc[VTIME] = 0;
|
||||
if (eight) {
|
||||
tt.c_iflag &= ~(IXON | IXOFF | ISTRIP);
|
||||
tt.c_cc[VSTOP] = _POSIX_VDISABLE;
|
||||
tt.c_cc[VSTART] = _POSIX_VDISABLE;
|
||||
}
|
||||
/*if (litout)
|
||||
lflags |= LLITOUT;*/
|
||||
tcsetattr(0, TCSADRAIN, &tt);
|
||||
sb.sg_flags |= (eight ? RAW : CBREAK);
|
||||
sb.sg_flags &= ~defflags;
|
||||
/* preserve tab delays, but turn off XTABS */
|
||||
if ((sb.sg_flags & TBDELAY) == XTABS)
|
||||
sb.sg_flags &= ~TBDELAY;
|
||||
tc = ¬c;
|
||||
ltc = &noltc;
|
||||
sb.sg_kill = sb.sg_erase = -1;
|
||||
if (litout)
|
||||
lflags |= LLITOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
(void)ioctl(0, TIOCSLTC, (char *)ltc);
|
||||
(void)ioctl(0, TIOCSETC, (char *)tc);
|
||||
(void)ioctl(0, TIOCSETN, (char *)&sb);
|
||||
(void)ioctl(0, TIOCLSET, (char *)&lflags);
|
||||
}
|
||||
|
||||
void
|
||||
lostpeer(signo)
|
||||
int signo;
|
||||
{
|
||||
setsig (SIGPIPE, SIG_IGN);
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
msg("\007connection closed.");
|
||||
done(1);
|
||||
}
|
||||
@@ -915,7 +841,6 @@ void
|
||||
copytochild(signo)
|
||||
int signo;
|
||||
{
|
||||
|
||||
(void)kill(child, SIGURG);
|
||||
}
|
||||
|
||||
@@ -923,14 +848,13 @@ void
|
||||
msg(str)
|
||||
char *str;
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "rlogin: %s\r\n", str);
|
||||
}
|
||||
|
||||
#ifdef KERBEROS
|
||||
/* VARARGS */
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
warning(const char *fmt, ...)
|
||||
#else
|
||||
warning(fmt, va_alist)
|
||||
@@ -941,7 +865,7 @@ warning(fmt, va_alist)
|
||||
va_list ap;
|
||||
|
||||
(void)fprintf(stderr, "rlogin: warning, using standard rlogin: ");
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
@@ -952,11 +876,11 @@ warning(fmt, va_alist)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
__dead void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: rlogin [ -%s]%s[-e char] [ -l username ] [username@]host\n",
|
||||
"usage: rlogin [ -%s]%s[-e char] [ -l username ] host\n",
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
"8EKLx", " [-k realm] ");
|
||||
|
||||
@@ -38,7 +38,7 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)rlogind.c 8.2 (Berkeley) 4/28/95";
|
||||
static char sccsid[] = "@(#)rlogind.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -50,46 +50,17 @@ static char sccsid[] = "@(#)rlogind.c 8.2 (Berkeley) 4/28/95";
|
||||
* data
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define FD_SETSIZE 16 /* don't need many bits for select */
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STREAM_H
|
||||
#include <sys/stream.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TTY_H
|
||||
#include <sys/tty.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PTYVAR_H
|
||||
#include <sys/ptyvar.h>
|
||||
#endif
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
@@ -100,29 +71,12 @@ static char sccsid[] = "@(#)rlogind.c 8.2 (Berkeley) 4/28/95";
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include "pathnames.h"
|
||||
|
||||
#ifndef TIOCPKT_WINDOW
|
||||
#define TIOCPKT_WINDOW 0x80
|
||||
#endif
|
||||
|
||||
/* `defaults' for tty settings. */
|
||||
#ifndef TTYDEF_IFLAG
|
||||
#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
|
||||
#endif
|
||||
#ifndef TTYDEF_OFLAG
|
||||
#ifndef OXTABS
|
||||
#define OXTABS 0
|
||||
#endif
|
||||
#define TTYDEF_OFLAG (OPOST | ONLCR | OXTABS)
|
||||
#endif
|
||||
#ifndef TTYDEF_LFLAG
|
||||
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
|
||||
#endif
|
||||
|
||||
#ifdef KERBEROS
|
||||
#include <kerberosIV/des.h>
|
||||
#include <kerberosIV/krb.h>
|
||||
@@ -218,25 +172,19 @@ main(argc, argv)
|
||||
syslog(LOG_ERR,"Can't get peer name of remote host: %m");
|
||||
fatal(STDERR_FILENO, "Can't get peer name of remote host", 1);
|
||||
}
|
||||
|
||||
on = 1;
|
||||
if (keepalive &&
|
||||
setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *) &on,
|
||||
sizeof (on)) < 0)
|
||||
setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0)
|
||||
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
|
||||
|
||||
#if defined (IP_TOS) && defined (IPPROTO_IP) && defined (IPTOS_LOWDELAY)
|
||||
on = IPTOS_LOWDELAY;
|
||||
if (setsockopt(0, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
|
||||
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
|
||||
#endif
|
||||
|
||||
doit(0, &from);
|
||||
}
|
||||
|
||||
int child;
|
||||
int netf;
|
||||
char line[1024]; /* XXX */
|
||||
char line[MAXPATHLEN];
|
||||
int confirmed;
|
||||
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
@@ -250,8 +198,7 @@ doit(f, fromp)
|
||||
int master, pid, on = 1;
|
||||
int authenticated = 0;
|
||||
register struct hostent *hp;
|
||||
char *hostname;
|
||||
const char *raw_hostname;
|
||||
char hostname[2 * MAXHOSTNAMELEN + 1];
|
||||
char c;
|
||||
|
||||
alarm(60);
|
||||
@@ -269,13 +216,9 @@ doit(f, fromp)
|
||||
hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(struct in_addr),
|
||||
fromp->sin_family);
|
||||
if (hp)
|
||||
raw_hostname = hp->h_name;
|
||||
(void)strcpy(hostname, hp->h_name);
|
||||
else
|
||||
raw_hostname = inet_ntoa(fromp->sin_addr);
|
||||
hostname = malloc (strlen (raw_hostname) + 1);
|
||||
if (! hostname)
|
||||
fatal (f, "Out of memory", 0);
|
||||
strcpy (hostname, raw_hostname);
|
||||
(void)strcpy(hostname, inet_ntoa(fromp->sin_addr));
|
||||
|
||||
#ifdef KERBEROS
|
||||
if (use_kerberos) {
|
||||
@@ -359,12 +302,12 @@ doit(f, fromp)
|
||||
hostname);
|
||||
#endif
|
||||
|
||||
execle(PATH_LOGIN, "login", "-p",
|
||||
"-h", hostname, "-f", "--", lusername, NULL, env);
|
||||
execl(_PATH_LOGIN, "login", "-p",
|
||||
"-h", hostname, "-f", lusername, (char *)NULL);
|
||||
} else
|
||||
execle(PATH_LOGIN, "login", "-p",
|
||||
"-h", hostname, "--", lusername, NULL, env);
|
||||
fatal(STDERR_FILENO, PATH_LOGIN, 1);
|
||||
execl(_PATH_LOGIN, "login", "-p",
|
||||
"-h", hostname, lusername, (char *)NULL);
|
||||
fatal(STDERR_FILENO, _PATH_LOGIN, 1);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
#ifdef CRYPT
|
||||
@@ -405,7 +348,7 @@ control(pty, cp, n)
|
||||
if (n < 4+sizeof (w) || cp[2] != 's' || cp[3] != 's')
|
||||
return (0);
|
||||
oobdata[0] &= ~TIOCPKT_WINDOW; /* we know he heard */
|
||||
memmove(&w, cp+4, sizeof(w));
|
||||
bcopy(cp+4, (char *)&w, sizeof(w));
|
||||
w.ws_row = ntohs(w.ws_row);
|
||||
w.ws_col = ntohs(w.ws_col);
|
||||
w.ws_xpixel = ntohs(w.ws_xpixel);
|
||||
@@ -583,7 +526,7 @@ cleanup(signo)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = line + sizeof(PATH_DEV) - 1;
|
||||
p = line + sizeof(_PATH_DEV) - 1;
|
||||
if (logout(p))
|
||||
logwtmp(p, "", "");
|
||||
(void)chmod(line, 0666);
|
||||
@@ -611,11 +554,10 @@ fatal(f, msg, syserr)
|
||||
if (!confirmed)
|
||||
*bp++ = '\01'; /* error indicator */
|
||||
if (syserr)
|
||||
snprintf (bp, sizeof buf - (bp - buf),
|
||||
"rlogind: %s: %s.\r\n", msg, strerror(errno));
|
||||
len = sprintf(bp, "rlogind: %s: %s.\r\n",
|
||||
msg, strerror(errno));
|
||||
else
|
||||
snprintf (bp, sizeof buf - (bp - buf), "rlogind: %s.\r\n", msg);
|
||||
len = strlen (bp);
|
||||
len = sprintf(bp, "rlogind: %s.\r\n", msg);
|
||||
(void) write(f, buf, bp + len - buf);
|
||||
exit(1);
|
||||
}
|
||||
@@ -654,28 +596,25 @@ getstr(buf, cnt, errmsg)
|
||||
} while (c != 0);
|
||||
}
|
||||
|
||||
extern char **environ;
|
||||
|
||||
void
|
||||
setup_term(fd)
|
||||
int fd;
|
||||
{
|
||||
register char *cp = strchr (term+ENVSIZE, '/');
|
||||
register char *cp = index(term+ENVSIZE, '/');
|
||||
char *speed;
|
||||
struct termios tt;
|
||||
|
||||
#if 1
|
||||
#ifndef notyet
|
||||
tcgetattr(fd, &tt);
|
||||
if (cp) {
|
||||
*cp++ = '\0';
|
||||
speed = cp;
|
||||
cp = strchr (speed, '/');
|
||||
cp = index(speed, '/');
|
||||
if (cp)
|
||||
*cp++ = '\0';
|
||||
#ifdef HAVE_CFSETSPEED
|
||||
cfsetspeed(&tt, atoi(speed));
|
||||
#else
|
||||
cfsetispeed(&tt, atoi(speed));
|
||||
cfsetospeed(&tt, atoi(speed));
|
||||
#endif
|
||||
}
|
||||
|
||||
tt.c_iflag = TTYDEF_IFLAG;
|
||||
@@ -686,22 +625,18 @@ setup_term(fd)
|
||||
if (cp) {
|
||||
*cp++ = '\0';
|
||||
speed = cp;
|
||||
cp = strchr (speed, '/');
|
||||
cp = index(speed, '/');
|
||||
if (cp)
|
||||
*cp++ = '\0';
|
||||
tcgetattr(fd, &tt);
|
||||
#ifdef HAVE_CFSETSPEED
|
||||
cfsetspeed(&tt, atoi(speed));
|
||||
#else
|
||||
cfsetispeed(&tt, atoi(speed));
|
||||
cfsetospeed(&tt, atoi(speed));
|
||||
#endif
|
||||
tcsetattr(fd, TCSAFLUSH, &tt);
|
||||
}
|
||||
#endif
|
||||
|
||||
env[0] = term;
|
||||
env[1] = 0;
|
||||
environ = env;
|
||||
}
|
||||
|
||||
#ifdef KERBEROS
|
||||
@@ -793,23 +728,16 @@ int
|
||||
local_domain(h)
|
||||
char *h;
|
||||
{
|
||||
extern char *localhost ();
|
||||
char *hostname = localhost ();
|
||||
char localhost[MAXHOSTNAMELEN];
|
||||
char *p1, *p2;
|
||||
|
||||
if (! hostname)
|
||||
return 0;
|
||||
else {
|
||||
int is_local = 0;
|
||||
char *p1 = topdomain (hostname);
|
||||
char *p2 = topdomain (h);
|
||||
|
||||
if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
|
||||
is_local = 1;
|
||||
|
||||
free (hostname);
|
||||
|
||||
return is_local;
|
||||
}
|
||||
localhost[0] = 0;
|
||||
(void) gethostname(localhost, sizeof(localhost));
|
||||
p1 = topdomain(localhost);
|
||||
p2 = topdomain(h);
|
||||
if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
12
rsh/rsh.1
12
rsh/rsh.1
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)rsh.1 8.2 (Berkeley) 4/29/95
|
||||
.\" @(#)rsh.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd April 29, 1995
|
||||
.Dd June 6, 1993
|
||||
.Dt RSH 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -43,10 +43,6 @@
|
||||
.Op Fl k Ar realm
|
||||
.Op Fl l Ar username
|
||||
.Ar host
|
||||
.Nm rsh
|
||||
.Op Fl Kdnx
|
||||
.Op Fl k Ar realm
|
||||
.Ar username@host
|
||||
.Op command
|
||||
.Sh DESCRIPTION
|
||||
.Nm Rsh
|
||||
@@ -90,9 +86,7 @@ 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 or the
|
||||
.Pa username@host
|
||||
format allow the remote name to be specified.
|
||||
option allows the remote name to be specified.
|
||||
Kerberos authentication is used, and authorization is determined
|
||||
as in
|
||||
.Xr rlogin 1 .
|
||||
|
||||
206
rsh/rsh.c
206
rsh/rsh.c
@@ -38,7 +38,7 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
||||
static char sccsid[] = "@(#)rsh.c 8.3 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -46,28 +46,11 @@ static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
||||
* $Header$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <sys/file.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
@@ -80,15 +63,9 @@ static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "pathnames.h"
|
||||
|
||||
#ifdef KERBEROS
|
||||
#include <kerberosIV/des.h>
|
||||
@@ -101,8 +78,6 @@ char dst_realm_buf[REALM_SZ], *dest_realm;
|
||||
extern char *krb_realmofhost();
|
||||
#endif
|
||||
|
||||
#include "version.h"
|
||||
|
||||
/*
|
||||
* rsh - remote shell
|
||||
*/
|
||||
@@ -110,87 +85,10 @@ int rfd2;
|
||||
|
||||
char *copyargs __P((char **));
|
||||
void sendsig __P((int));
|
||||
void talk __P((int, sigset_t *, pid_t, int));
|
||||
void talk __P((int, long, pid_t, int));
|
||||
void usage __P((void));
|
||||
void warning __P((const char *, ...));
|
||||
|
||||
/* basename (argv[0]). NetBSD, linux, & gnu libc all define it. */
|
||||
extern char *__progname;
|
||||
void warning __P(());
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{ "debug", no_argument, 0, 'd' },
|
||||
{ "no-input", no_argument, 0, 'n' },
|
||||
{ "user", required_argument, 0, 'l' },
|
||||
{ "encrypt", no_argument, 0, 'x' },
|
||||
{ "realm", required_argument, 0, 'k' },
|
||||
{ "help", no_argument, 0, '&' },
|
||||
{ "version", no_argument, 0, 'V' },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static void
|
||||
pusage (stream)
|
||||
FILE *stream;
|
||||
{
|
||||
fprintf(stream,
|
||||
"Usage: %s [-nd%s]%s[-l USER] [USER@]HOST [COMMAND [ARG...]]\n",
|
||||
__progname,
|
||||
#ifdef KERBEROS
|
||||
#ifdef CRYPT
|
||||
"x", " [-k REALM] ");
|
||||
#else
|
||||
"", " [-k REALM] ");
|
||||
#endif
|
||||
#else
|
||||
"", " ");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Print a help message describing all options to STDOUT and exit with a
|
||||
status of 0. */
|
||||
static void
|
||||
help ()
|
||||
{
|
||||
pusage (stdout);
|
||||
puts ("Execute COMMAND on remote system HOST\n\n\
|
||||
-d, --debug Turn on socket debugging");
|
||||
#ifdef KERBEROS
|
||||
puts ("\
|
||||
-k REALM, --realm=REALM Obtain tickets for the remote host in REALM\n\
|
||||
instead of the remote host's realm");
|
||||
#endif
|
||||
puts ("\
|
||||
-l USER, --user=USER Run as USER on the remote system");
|
||||
puts ("\
|
||||
-n, --no-input Use /dev/null as input");
|
||||
#ifdef CRYPT
|
||||
puts ("\
|
||||
-x, --encrypt Encrypt all data using DES");
|
||||
#endif
|
||||
puts ("\
|
||||
--help Give this help list\n\
|
||||
-V, --version Print program version");
|
||||
fprintf (stdout, "\nSubmit bug reports to %s.\n", inetutils_bugaddr);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
/* Print a message saying to use --help to STDERR, and exit with a status of
|
||||
1. */
|
||||
static void
|
||||
try_help ()
|
||||
{
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", __progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
pusage (stderr);
|
||||
try_help ();
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
@@ -198,17 +96,12 @@ main(argc, argv)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct servent *sp;
|
||||
sigset_t sigs, osigs;
|
||||
long omask;
|
||||
int argoff, asrsh, ch, dflag, nflag, one, rem;
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
char *args, *host, *p, *user;
|
||||
|
||||
#ifndef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
__progname = argv[0];
|
||||
#endif
|
||||
|
||||
argoff = asrsh = dflag = nflag = 0;
|
||||
one = 1;
|
||||
host = user = NULL;
|
||||
@@ -238,9 +131,7 @@ main(argc, argv)
|
||||
#else
|
||||
#define OPTIONS "8KLdel:nw"
|
||||
#endif
|
||||
while ((ch = getopt_long (argc - argoff, argv + argoff, OPTIONS,
|
||||
long_options, 0))
|
||||
!= EOF)
|
||||
while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
|
||||
switch(ch) {
|
||||
case 'K':
|
||||
#ifdef KERBEROS
|
||||
@@ -275,17 +166,7 @@ main(argc, argv)
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
case '&':
|
||||
help ();
|
||||
case 'V':
|
||||
printf ("rsh (%s) %s\n",
|
||||
inetutils_package, inetutils_version);
|
||||
exit (0);
|
||||
|
||||
case '?':
|
||||
try_help ();
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@@ -299,8 +180,8 @@ main(argc, argv)
|
||||
if (!argv[optind]) {
|
||||
if (asrsh)
|
||||
*argv = "rlogin";
|
||||
execv(PATH_RLOGIN, argv);
|
||||
err(1, "can't exec %s", PATH_RLOGIN);
|
||||
execv(_PATH_RLOGIN, argv);
|
||||
err(1, "can't exec %s", _PATH_RLOGIN);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
@@ -308,16 +189,6 @@ main(argc, argv)
|
||||
|
||||
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;
|
||||
|
||||
@@ -396,25 +267,16 @@ try_connect:
|
||||
if (rfd2 < 0)
|
||||
errx(1, "can't establish stderr");
|
||||
if (dflag) {
|
||||
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, (char *) &one,
|
||||
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one,
|
||||
sizeof(one)) < 0)
|
||||
warn("setsockopt");
|
||||
if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, (char *) &one,
|
||||
if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, &one,
|
||||
sizeof(one)) < 0)
|
||||
warn("setsockopt");
|
||||
}
|
||||
|
||||
(void)setuid(uid);
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGINT);
|
||||
sigaddset(&sigs, SIGQUIT);
|
||||
sigaddset(&sigs, SIGTERM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
sigs = sigmask (SIGINT) | sigmask (SIGQUIT) | sigmask (SIGTERM);
|
||||
osigs = sigblock (sigs);
|
||||
#endif
|
||||
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)
|
||||
@@ -438,7 +300,7 @@ try_connect:
|
||||
(void)ioctl(rem, FIONBIO, &one);
|
||||
}
|
||||
|
||||
talk(nflag, &osigs, pid, rem);
|
||||
talk(nflag, omask, pid, rem);
|
||||
|
||||
if (!nflag)
|
||||
(void)kill(pid, SIGKILL);
|
||||
@@ -446,9 +308,9 @@ try_connect:
|
||||
}
|
||||
|
||||
void
|
||||
talk (nflag, osigs, pid, rem)
|
||||
talk(nflag, omask, pid, rem)
|
||||
int nflag;
|
||||
sigset_t *osigs;
|
||||
long omask;
|
||||
pid_t pid;
|
||||
int rem;
|
||||
{
|
||||
@@ -497,11 +359,7 @@ done:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask (SIG_SETMASK, osigs, 0);
|
||||
#else
|
||||
sigsetmask (*osigs);
|
||||
#endif
|
||||
(void)sigsetmask(omask);
|
||||
FD_ZERO(&readfrom);
|
||||
FD_SET(rfd2, &readfrom);
|
||||
FD_SET(rem, &readfrom);
|
||||
@@ -567,24 +425,14 @@ sendsig(sig)
|
||||
#ifdef KERBEROS
|
||||
/* VARARGS */
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
warning(const char * fmt, ...)
|
||||
#else
|
||||
warning(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if !(defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__)
|
||||
const char *fmt;
|
||||
#endif
|
||||
char *fmt;
|
||||
|
||||
fprintf(stderr, "%s: warning, using standard rsh: ", __progname);
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
(void)fprintf(stderr, "rsh: warning, using standard rsh: ");
|
||||
va_start(ap);
|
||||
#endif
|
||||
fmt = va_arg(ap, char *);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
@@ -612,3 +460,21 @@ copyargs(argv)
|
||||
}
|
||||
return (args);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
||||
(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);
|
||||
}
|
||||
|
||||
216
rshd/rshd.c
216
rshd/rshd.c
@@ -49,40 +49,9 @@ static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
|
||||
* command\0
|
||||
* data
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined (__GNUC__) && defined (_AIX)
|
||||
#pragma alloca
|
||||
#endif
|
||||
#ifndef alloca /* Make alloca work the best possible way. */
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#else /* not __GNUC__ */
|
||||
#if HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#else /* not __GNUC__ or HAVE_ALLOCA_H */
|
||||
#ifndef _AIX /* Already did AIX, up at the top. */
|
||||
char *alloca ();
|
||||
#endif /* not _AIX */
|
||||
#endif /* not HAVE_ALLOCA_H */
|
||||
#endif /* not __GNUC__ */
|
||||
#endif /* not alloca */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
@@ -91,25 +60,14 @@ char *alloca ();
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <paths.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
int keepalive = 1;
|
||||
int check_all;
|
||||
@@ -118,9 +76,9 @@ int sent_null;
|
||||
|
||||
void doit __P((struct sockaddr_in *));
|
||||
void error __P((const char *, ...));
|
||||
char *getstr __P((char *));
|
||||
int local_domain __P((const char *));
|
||||
const char *topdomain __P((const char *));
|
||||
void getstr __P((char *, int, char *));
|
||||
int local_domain __P((char *));
|
||||
char *topdomain __P((char *));
|
||||
void usage __P((void));
|
||||
|
||||
#ifdef KERBEROS
|
||||
@@ -225,7 +183,7 @@ char shell[64] = "SHELL=";
|
||||
char path[100] = "PATH=";
|
||||
char *envinit[] =
|
||||
{homedir, shell, path, username, 0};
|
||||
extern char **environ;
|
||||
char **environ;
|
||||
|
||||
void
|
||||
doit(fromp)
|
||||
@@ -238,9 +196,10 @@ doit(fromp)
|
||||
fd_set ready, readfrom;
|
||||
int cc, nfd, pv[2], pid, s;
|
||||
int one = 1;
|
||||
const char *hostname, *errorstr, *errorhost;
|
||||
char *hostname, *errorstr, *errorhost;
|
||||
char *cp, sig, buf[BUFSIZ];
|
||||
char *cmdbuf, *locuser, *remuser;
|
||||
char cmdbuf[NCARGS+1], locuser[16], remuser[16];
|
||||
char remotehost[2 * MAXHOSTNAMELEN + 1];
|
||||
|
||||
#ifdef KERBEROS
|
||||
AUTH_DAT *kdata = (AUTH_DAT *) NULL;
|
||||
@@ -259,7 +218,7 @@ doit(fromp)
|
||||
(void) signal(SIGQUIT, SIG_DFL);
|
||||
(void) signal(SIGTERM, SIG_DFL);
|
||||
#ifdef DEBUG
|
||||
{ int t = open(PATH_TTY, O_RDWR);
|
||||
{ int t = open(_PATH_TTY, 2);
|
||||
if (t >= 0) {
|
||||
ioctl(t, TIOCNOTTY, (char *)0);
|
||||
(void) close(t);
|
||||
@@ -377,37 +336,33 @@ doit(fromp)
|
||||
if (!use_kerberos)
|
||||
#endif
|
||||
if (check_all || local_domain(hp->h_name)) {
|
||||
char *remotehost = (char *) alloca (strlen (hp->h_name) + 1);
|
||||
if (! remotehost)
|
||||
errorstr = "Out of memory\n";
|
||||
else {
|
||||
strcpy(remotehost, hp->h_name);
|
||||
errorhost = remotehost;
|
||||
hp = gethostbyname(remotehost);
|
||||
if (hp == NULL) {
|
||||
syslog(LOG_INFO,
|
||||
"Couldn't look up address for %s",
|
||||
remotehost);
|
||||
strncpy(remotehost, hp->h_name, sizeof(remotehost) - 1);
|
||||
remotehost[sizeof(remotehost) - 1] = 0;
|
||||
errorhost = remotehost;
|
||||
hp = gethostbyname(remotehost);
|
||||
if (hp == NULL) {
|
||||
syslog(LOG_INFO,
|
||||
"Couldn't look up address for %s",
|
||||
remotehost);
|
||||
errorstr =
|
||||
"Couldn't look up address for your host (%s)\n";
|
||||
hostname = inet_ntoa(fromp->sin_addr);
|
||||
} else for (; ; hp->h_addr_list++) {
|
||||
if (hp->h_addr_list[0] == NULL) {
|
||||
syslog(LOG_NOTICE,
|
||||
"Host addr %s not listed for host %s",
|
||||
inet_ntoa(fromp->sin_addr),
|
||||
hp->h_name);
|
||||
errorstr =
|
||||
"Couldn't look up address for your host (%s)\n";
|
||||
"Host address mismatch for %s\n";
|
||||
hostname = inet_ntoa(fromp->sin_addr);
|
||||
} else for (; ; hp->h_addr_list++) {
|
||||
if (hp->h_addr_list[0] == NULL) {
|
||||
syslog(LOG_NOTICE,
|
||||
"Host addr %s not listed for host %s",
|
||||
inet_ntoa(fromp->sin_addr),
|
||||
hp->h_name);
|
||||
errorstr =
|
||||
"Host address mismatch for %s\n";
|
||||
hostname = inet_ntoa(fromp->sin_addr);
|
||||
break;
|
||||
}
|
||||
if (!bcmp(hp->h_addr_list[0],
|
||||
(caddr_t)&fromp->sin_addr,
|
||||
sizeof(fromp->sin_addr))) {
|
||||
hostname = hp->h_name;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!bcmp(hp->h_addr_list[0],
|
||||
(caddr_t)&fromp->sin_addr,
|
||||
sizeof(fromp->sin_addr))) {
|
||||
hostname = hp->h_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,11 +405,10 @@ doit(fromp)
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
remuser = getstr ("remuser");
|
||||
|
||||
locuser = getstr ("locuser");
|
||||
cmdbuf = getstr ("command");
|
||||
getstr(remuser, sizeof(remuser), "remuser");
|
||||
|
||||
getstr(locuser, sizeof(locuser), "locuser");
|
||||
getstr(cmdbuf, sizeof(cmdbuf), "command");
|
||||
setpwent();
|
||||
pwd = getpwnam(locuser);
|
||||
if (pwd == NULL) {
|
||||
@@ -510,7 +464,7 @@ fail:
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pwd->pw_uid && !access(PATH_NOLOGIN, F_OK)) {
|
||||
if (pwd->pw_uid && !access(_PATH_NOLOGIN, F_OK)) {
|
||||
error("Logins currently disabled.\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -669,7 +623,7 @@ fail:
|
||||
FD_ISSET(pv[0], &readfrom));
|
||||
exit(0);
|
||||
}
|
||||
setpgid (0, getpid ());
|
||||
setpgrp(0, getpid());
|
||||
(void) close(s);
|
||||
(void) close(pv[0]);
|
||||
#ifdef CRYPT
|
||||
@@ -687,7 +641,7 @@ fail:
|
||||
close(pv[1]);
|
||||
}
|
||||
if (*pwd->pw_shell == '\0')
|
||||
pwd->pw_shell = PATH_BSHELL;
|
||||
pwd->pw_shell = _PATH_BSHELL;
|
||||
#if BSD > 43
|
||||
if (setlogin(pwd->pw_name) < 0)
|
||||
syslog(LOG_ERR, "setlogin() failed: %m");
|
||||
@@ -697,7 +651,7 @@ fail:
|
||||
(void) setuid((uid_t)pwd->pw_uid);
|
||||
environ = envinit;
|
||||
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
|
||||
strcat(path, PATH_DEFPATH);
|
||||
strcat(path, _PATH_DEFPATH);
|
||||
strncat(shell, pwd->pw_shell, sizeof(shell)-7);
|
||||
strncat(username, pwd->pw_name, sizeof(username)-6);
|
||||
cp = strrchr(pwd->pw_shell, '/');
|
||||
@@ -728,9 +682,14 @@ fail:
|
||||
* connected to client, or older clients will hang waiting for that
|
||||
* connection first.
|
||||
*/
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
error(const char *fmt, ...)
|
||||
#else
|
||||
error(fmt, va_alist)
|
||||
@@ -741,7 +700,7 @@ error(fmt, va_alist)
|
||||
va_list ap;
|
||||
int len;
|
||||
char *bp, buf[BUFSIZ];
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
@@ -756,44 +715,22 @@ error(fmt, va_alist)
|
||||
(void)write(STDERR_FILENO, buf, len + strlen(bp));
|
||||
}
|
||||
|
||||
char *
|
||||
getstr(err)
|
||||
char *err;
|
||||
void
|
||||
getstr(buf, cnt, err)
|
||||
char *buf, *err;
|
||||
int cnt;
|
||||
{
|
||||
size_t buf_len = 100;
|
||||
char *buf = malloc (buf_len), *end = buf;
|
||||
|
||||
if (! buf) {
|
||||
error ("Out of space reading %s\n", err);
|
||||
exit (1);
|
||||
}
|
||||
char c;
|
||||
|
||||
do {
|
||||
/* Oh this is efficient, oh yes. [But what can be done?] */
|
||||
int rd = read(STDIN_FILENO, end, 1);
|
||||
if (rd <= 0) {
|
||||
if (rd == 0)
|
||||
error ("EOF reading %s\n", err);
|
||||
else
|
||||
perror (err);
|
||||
if (read(STDIN_FILENO, &c, 1) != 1)
|
||||
exit(1);
|
||||
*buf++ = c;
|
||||
if (--cnt == 0) {
|
||||
error("%s too long\n", err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
end += rd;
|
||||
if ((buf + buf_len - end) < (buf_len >> 3)) {
|
||||
/* Not very much room left in our buffer, grow it. */
|
||||
size_t end_offs = end - buf;
|
||||
buf_len += buf_len;
|
||||
buf = realloc (buf, buf_len);
|
||||
if (! buf) {
|
||||
error ("Out of space reading %s\n", err);
|
||||
exit (1);
|
||||
}
|
||||
end = buf + end_offs;
|
||||
}
|
||||
} while (*(end - 1));
|
||||
|
||||
return buf;
|
||||
} while (c != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -806,32 +743,25 @@ getstr(err)
|
||||
*/
|
||||
int
|
||||
local_domain(h)
|
||||
const char *h;
|
||||
char *h;
|
||||
{
|
||||
extern char *localhost ();
|
||||
char *hostname = localhost ();
|
||||
char localhost[MAXHOSTNAMELEN];
|
||||
char *p1, *p2;
|
||||
|
||||
if (! hostname)
|
||||
return 0;
|
||||
else {
|
||||
int is_local = 0;
|
||||
const char *p1 = topdomain (hostname);
|
||||
const char *p2 = topdomain (h);
|
||||
|
||||
if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
|
||||
is_local = 1;
|
||||
|
||||
free (hostname);
|
||||
|
||||
return is_local;
|
||||
}
|
||||
localhost[0] = 0;
|
||||
(void) gethostname(localhost, sizeof(localhost));
|
||||
p1 = topdomain(localhost);
|
||||
p2 = topdomain(h);
|
||||
if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
topdomain(h)
|
||||
const char *h;
|
||||
char *h;
|
||||
{
|
||||
const char *p, *maybe = NULL;
|
||||
char *p, *maybe = NULL;
|
||||
int dots = 0;
|
||||
|
||||
for (p = h + strlen(h); p >= h; p--) {
|
||||
|
||||
@@ -41,30 +41,22 @@ static char copyright[] =
|
||||
static char sccsid[] = "@(#)logger.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#define SYSLOG_NAMES
|
||||
#include <syslog.h>
|
||||
#ifndef HAVE_SYSLOG_INTERNAL
|
||||
#include <syslog-int.h>
|
||||
#endif
|
||||
|
||||
int decode __P((char *, CODE *));
|
||||
int pencode __P((char *));
|
||||
void usage __P((void));
|
||||
|
||||
/*
|
||||
* syslog -- read and log utility
|
||||
* logger -- read and log utility
|
||||
*
|
||||
* Reads from an input and arranges to write the result on the system
|
||||
* log.
|
||||
@@ -84,7 +76,7 @@ main(argc, argv)
|
||||
switch((char)ch) {
|
||||
case 'f': /* file to log */
|
||||
if (freopen(optarg, "r", stdin) == NULL) {
|
||||
(void)fprintf(stderr, "syslog: %s: %s.\n",
|
||||
(void)fprintf(stderr, "logger: %s: %s.\n",
|
||||
optarg, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
@@ -96,12 +88,7 @@ main(argc, argv)
|
||||
pri = pencode(optarg);
|
||||
break;
|
||||
case 's': /* log to standard error */
|
||||
#ifdef LOG_PERROR
|
||||
logflags |= LOG_PERROR;
|
||||
#else
|
||||
fprintf (stderr, "%s: -s: option not implemented\n", argv[0]);
|
||||
exit (1);
|
||||
#endif
|
||||
break;
|
||||
case 't': /* tag */
|
||||
tag = optarg;
|
||||
@@ -161,7 +148,7 @@ pencode(s)
|
||||
fac = decode(save, facilitynames);
|
||||
if (fac < 0) {
|
||||
(void)fprintf(stderr,
|
||||
"syslog: unknown facility name: %s.\n", save);
|
||||
"logger: unknown facility name: %s.\n", save);
|
||||
exit(1);
|
||||
}
|
||||
*s++ = '.';
|
||||
@@ -173,7 +160,7 @@ pencode(s)
|
||||
lev = decode(s, prioritynames);
|
||||
if (lev < 0) {
|
||||
(void)fprintf(stderr,
|
||||
"syslog: unknown priority name: %s.\n", save);
|
||||
"logger: unknown priority name: %s.\n", save);
|
||||
exit(1);
|
||||
}
|
||||
return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
|
||||
@@ -200,6 +187,6 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"syslog: [-is] [-f file] [-p pri] [-t tag] [ message ... ]\n");
|
||||
"logger: [-is] [-f file] [-p pri] [-t tag] [ message ... ]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -63,10 +63,6 @@ static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
|
||||
* more extensive changes by Eric Allman (again)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define MAXLINE 1024 /* maximum line length */
|
||||
#define MAXSVLINE 120 /* maximum saved line length */
|
||||
#define DEFUPRI (LOG_USER|LOG_NOTICE)
|
||||
@@ -78,21 +74,10 @@ static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_SYS_MSGBUF_H
|
||||
#include <sys/msgbuf.h>
|
||||
#endif
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
@@ -109,29 +94,22 @@ static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
#include <getopt.h>
|
||||
#define SYSLOG_NAMES
|
||||
#include <syslog.h>
|
||||
#ifndef HAVE_SYSLOG_INTERNAL
|
||||
#include <syslog-int.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include "pathnames.h"
|
||||
|
||||
char *LogName = PATH_LOG;
|
||||
char *ConfFile = PATH_LOGCONF;
|
||||
char *PidFile = PATH_LOGPID;
|
||||
char ctty[] = PATH_CONSOLE;
|
||||
#define SYSLOG_NAMES
|
||||
#include <sys/syslog.h>
|
||||
|
||||
char *LogName = _PATH_LOG;
|
||||
char *ConfFile = _PATH_LOGCONF;
|
||||
char *PidFile = _PATH_LOGPID;
|
||||
char ctty[] = _PATH_CONSOLE;
|
||||
|
||||
#define FDMASK(fd) (1 << (fd))
|
||||
|
||||
#ifndef LINE_MAX
|
||||
#define LINE_MAX 2048
|
||||
#endif
|
||||
|
||||
#define dprintf if (Debug) printf
|
||||
|
||||
#define MAXUNAMES 20 /* maximum number of user names */
|
||||
|
||||
/*
|
||||
* Flags to logmsg().
|
||||
*/
|
||||
@@ -153,19 +131,16 @@ struct filed {
|
||||
time_t f_time; /* time this was last written */
|
||||
u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */
|
||||
union {
|
||||
char f_uname[MAXUNAMES][UT_NAMESIZE+1];
|
||||
struct {
|
||||
int f_nusers;
|
||||
char **f_unames;
|
||||
} f_user;
|
||||
struct {
|
||||
char *f_hname;
|
||||
char f_hname[MAXHOSTNAMELEN+1];
|
||||
struct sockaddr_in f_addr;
|
||||
} f_forw; /* forwarding address */
|
||||
char *f_fname;
|
||||
char f_fname[MAXPATHLEN];
|
||||
} f_un;
|
||||
char f_prevline[MAXSVLINE]; /* last message logged */
|
||||
char f_lasttime[16]; /* time of last occurrence */
|
||||
char *f_prevhost; /* host from which recd. */
|
||||
char f_prevhost[MAXHOSTNAMELEN+1]; /* host from which recd. */
|
||||
int f_prevpri; /* pri of f_prevline */
|
||||
int f_prevlen; /* length of f_prevline */
|
||||
int f_prevcount; /* repetition cnt of prevline */
|
||||
@@ -202,7 +177,7 @@ struct filed *Files;
|
||||
struct filed consfile;
|
||||
|
||||
int Debug; /* debug flag */
|
||||
char *LocalHostName = 0; /* our hostname */
|
||||
char LocalHostName[MAXHOSTNAMELEN+1]; /* our hostname */
|
||||
char *LocalDomain; /* our local domain name */
|
||||
int InetInuse = 0; /* non-zero if INET sockets are being used */
|
||||
int finet; /* Internet datagram socket */
|
||||
@@ -212,21 +187,20 @@ int MarkInterval = 20 * 60; /* interval between marks in seconds */
|
||||
int MarkSeq = 0; /* mark sequence number */
|
||||
|
||||
void cfline __P((char *, struct filed *));
|
||||
const char *cvthname __P((struct sockaddr_in *));
|
||||
char *cvthname __P((struct sockaddr_in *));
|
||||
int decode __P((const char *, CODE *));
|
||||
void die __P((int));
|
||||
void domark __P((int));
|
||||
void fprintlog __P((struct filed *, int, const char *));
|
||||
void fprintlog __P((struct filed *, int, char *));
|
||||
void init __P((int));
|
||||
void logerror __P((const char *));
|
||||
void logmsg __P((int, const char *, const char *, int));
|
||||
void printline __P((const char *, const char *));
|
||||
void printsys __P((const char *));
|
||||
void logerror __P((char *));
|
||||
void logmsg __P((int, char *, char *, int));
|
||||
void printline __P((char *, char *));
|
||||
void printsys __P((char *));
|
||||
void reapchild __P((int));
|
||||
char *ttymsg __P((struct iovec *, int, char *, int));
|
||||
void usage __P((void));
|
||||
void wallmsg __P((struct filed *, struct iovec *));
|
||||
extern char *localhost __P ((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
@@ -237,12 +211,7 @@ main(argc, argv)
|
||||
struct sockaddr_un sunx, fromunix;
|
||||
struct sockaddr_in sin, frominet;
|
||||
FILE *fp;
|
||||
char *p;
|
||||
#ifdef MSG_BSIZE
|
||||
char line[MSG_BSIZE + 1];
|
||||
#else
|
||||
char line[MAXLINE + 1];
|
||||
#endif
|
||||
char *p, line[MSG_BSIZE + 1];
|
||||
|
||||
while ((ch = getopt(argc, argv, "df:m:p:")) != EOF)
|
||||
switch(ch) {
|
||||
@@ -268,34 +237,16 @@ main(argc, argv)
|
||||
if (!Debug)
|
||||
(void)daemon(0, 0);
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_SETLINEBUF
|
||||
setlinebuf (stdout);
|
||||
#else
|
||||
#ifndef SETVBUF_REVERSED
|
||||
setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
|
||||
#else /* setvbuf not reversed. */
|
||||
/* Some buggy systems lose if we pass 0 instead of allocating ourselves. */
|
||||
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
|
||||
#endif /* setvbuf reversed. */
|
||||
#endif /* setlinebuf missing. */
|
||||
}
|
||||
|
||||
LocalHostName = localhost ();
|
||||
if (! LocalHostName) {
|
||||
perror ("Can't get local host name");
|
||||
exit (2);
|
||||
}
|
||||
setlinebuf(stdout);
|
||||
|
||||
consfile.f_type = F_CONSOLE;
|
||||
(void)strcpy(consfile.f_un.f_fname, ctty);
|
||||
(void)gethostname(LocalHostName, sizeof(LocalHostName));
|
||||
if ((p = strchr(LocalHostName, '.')) != NULL) {
|
||||
*p++ = '\0';
|
||||
LocalDomain = p;
|
||||
} else
|
||||
LocalDomain = "";
|
||||
|
||||
consfile.f_type = F_CONSOLE;
|
||||
consfile.f_un.f_fname = strdup (ctty);
|
||||
|
||||
(void)signal(SIGTERM, die);
|
||||
(void)signal(SIGINT, Debug ? die : SIG_IGN);
|
||||
(void)signal(SIGQUIT, Debug ? die : SIG_IGN);
|
||||
@@ -305,7 +256,7 @@ main(argc, argv)
|
||||
(void)unlink(LogName);
|
||||
|
||||
#ifndef SUN_LEN
|
||||
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 3)
|
||||
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
|
||||
#endif
|
||||
memset(&sunx, 0, sizeof(sunx));
|
||||
sunx.sun_family = AF_UNIX;
|
||||
@@ -314,7 +265,7 @@ main(argc, argv)
|
||||
if (funix < 0 ||
|
||||
bind(funix, (struct sockaddr *)&sunx, SUN_LEN(&sunx)) < 0 ||
|
||||
chmod(LogName, 0666) < 0) {
|
||||
snprintf (line, sizeof line, "cannot create %s", LogName);
|
||||
(void) sprintf(line, "cannot create %s", LogName);
|
||||
logerror(line);
|
||||
dprintf("cannot create %s (%d)\n", LogName, errno);
|
||||
die(0);
|
||||
@@ -342,17 +293,12 @@ main(argc, argv)
|
||||
InetInuse = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PATH_KLOG
|
||||
if ((fklog = open(PATH_KLOG, O_RDONLY, 0)) >= 0)
|
||||
if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) >= 0)
|
||||
klogm = FDMASK(fklog);
|
||||
else {
|
||||
dprintf("can't open %s (%d)\n", PATH_KLOG, errno);
|
||||
dprintf("can't open %s (%d)\n", _PATH_KLOG, errno);
|
||||
klogm = 0;
|
||||
}
|
||||
#else
|
||||
klogm = 0;
|
||||
#endif
|
||||
|
||||
/* tuck my process id away */
|
||||
fp = fopen(PidFile, "w");
|
||||
@@ -429,12 +375,11 @@ usage()
|
||||
*/
|
||||
void
|
||||
printline(hname, msg)
|
||||
const char *hname;
|
||||
const char *msg;
|
||||
char *hname;
|
||||
char *msg;
|
||||
{
|
||||
int c, pri;
|
||||
const char *p;
|
||||
char *q, line[MAXLINE + 1];
|
||||
char *p, *q, line[MAXLINE + 1];
|
||||
|
||||
/* test for special codes */
|
||||
pri = DEFUPRI;
|
||||
@@ -478,11 +423,10 @@ printline(hname, msg)
|
||||
*/
|
||||
void
|
||||
printsys(msg)
|
||||
const char *msg;
|
||||
char *msg;
|
||||
{
|
||||
int c, pri, flags;
|
||||
char *lp, *q, line[MAXLINE + 1];
|
||||
const char *p;
|
||||
char *lp, *p, *q, line[MAXLINE + 1];
|
||||
|
||||
(void)strcpy(line, "vmunix: ");
|
||||
lp = line + strlen(line);
|
||||
@@ -519,30 +463,17 @@ time_t now;
|
||||
void
|
||||
logmsg(pri, msg, from, flags)
|
||||
int pri;
|
||||
const char *msg, *from;
|
||||
char *msg, *from;
|
||||
int flags;
|
||||
{
|
||||
struct filed *f;
|
||||
int fac, msglen, prilev;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigset_t sigs, osigs;
|
||||
#else
|
||||
int omask;
|
||||
#endif
|
||||
|
||||
const char *timestamp;
|
||||
int fac, msglen, omask, prilev;
|
||||
char *timestamp;
|
||||
|
||||
dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
|
||||
pri, flags, from, msg);
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGHUP);
|
||||
sigaddset(&sigs, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &sigs, &osigs);
|
||||
#else
|
||||
omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check to see if msg looks non-standard.
|
||||
@@ -572,16 +503,12 @@ logmsg(pri, msg, from, flags)
|
||||
if (!Initialized) {
|
||||
f = &consfile;
|
||||
f->f_file = open(ctty, O_WRONLY, 0);
|
||||
f->f_prevhost = strdup (LocalHostName);
|
||||
|
||||
if (f->f_file >= 0) {
|
||||
fprintlog(f, flags, msg);
|
||||
(void)close(f->f_file);
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
(void)sigsetmask(omask);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
for (f = Files; f; f = f->f_next) {
|
||||
@@ -601,7 +528,6 @@ logmsg(pri, msg, from, flags)
|
||||
* suppress duplicate lines to this file
|
||||
*/
|
||||
if ((flags & MARK) == 0 && msglen == f->f_prevlen &&
|
||||
f->f_prevhost &&
|
||||
!strcmp(msg, f->f_prevline) &&
|
||||
!strcmp(from, f->f_prevhost)) {
|
||||
(void)strncpy(f->f_lasttime, timestamp, 15);
|
||||
@@ -625,9 +551,8 @@ logmsg(pri, msg, from, flags)
|
||||
fprintlog(f, 0, (char *)NULL);
|
||||
f->f_repeatcount = 0;
|
||||
(void)strncpy(f->f_lasttime, timestamp, 15);
|
||||
if (f->f_prevhost)
|
||||
free (f->f_prevhost);
|
||||
f->f_prevhost = strdup (from);
|
||||
(void)strncpy(f->f_prevhost, from,
|
||||
sizeof(f->f_prevhost));
|
||||
if (msglen < MAXSVLINE) {
|
||||
f->f_prevlen = msglen;
|
||||
f->f_prevpri = pri;
|
||||
@@ -640,18 +565,14 @@ logmsg(pri, msg, from, flags)
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigprocmask(SIG_SETMASK, &osigs, 0);
|
||||
#else
|
||||
(void)sigsetmask(omask);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
fprintlog(f, flags, msg)
|
||||
struct filed *f;
|
||||
int flags;
|
||||
const char *msg;
|
||||
char *msg;
|
||||
{
|
||||
struct iovec iov[6];
|
||||
struct iovec *v;
|
||||
@@ -661,10 +582,9 @@ fprintlog(f, flags, msg)
|
||||
v = iov;
|
||||
if (f->f_type == F_WALL) {
|
||||
v->iov_base = greetings;
|
||||
snprintf (greetings, sizeof greetings,
|
||||
"\r\n\7Message from syslogd@%s at %.24s ...\r\n",
|
||||
f->f_prevhost, ctime(&now));
|
||||
v->iov_len = strlen (greetings);
|
||||
v->iov_len = sprintf(greetings,
|
||||
"\r\n\7Message from syslogd@%s at %.24s ...\r\n",
|
||||
f->f_prevhost, ctime(&now));
|
||||
v++;
|
||||
v->iov_base = "";
|
||||
v->iov_len = 0;
|
||||
@@ -685,13 +605,12 @@ fprintlog(f, flags, msg)
|
||||
v++;
|
||||
|
||||
if (msg) {
|
||||
v->iov_base = (char *)msg;
|
||||
v->iov_base = msg;
|
||||
v->iov_len = strlen(msg);
|
||||
} else if (f->f_prevcount > 1) {
|
||||
v->iov_base = repbuf;
|
||||
sprintf(repbuf, "last message repeated %d times",
|
||||
f->f_prevcount);
|
||||
v->iov_len = strlen(repbuf);
|
||||
v->iov_len = sprintf(repbuf, "last message repeated %d times",
|
||||
f->f_prevcount);
|
||||
} else {
|
||||
v->iov_base = f->f_prevline;
|
||||
v->iov_len = f->f_prevlen;
|
||||
@@ -708,9 +627,8 @@ fprintlog(f, flags, msg)
|
||||
|
||||
case F_FORW:
|
||||
dprintf(" %s\n", f->f_un.f_forw.f_hname);
|
||||
sprintf(line, "<%d>%.15s %s", f->f_prevpri,
|
||||
iov[0].iov_base, iov[4].iov_base);
|
||||
l = strlen(line);
|
||||
l = sprintf(line, "<%d>%.15s %s", f->f_prevpri,
|
||||
iov[0].iov_base, iov[4].iov_base);
|
||||
if (l > MAXLINE)
|
||||
l = MAXLINE;
|
||||
if (sendto(finet, line, l, 0,
|
||||
@@ -796,8 +714,8 @@ wallmsg(f, iov)
|
||||
|
||||
if (reenter++)
|
||||
return;
|
||||
if ((uf = fopen(PATH_UTMP, "r")) == NULL) {
|
||||
logerror(PATH_UTMP);
|
||||
if ((uf = fopen(_PATH_UTMP, "r")) == NULL) {
|
||||
logerror(_PATH_UTMP);
|
||||
reenter = 0;
|
||||
return;
|
||||
}
|
||||
@@ -815,15 +733,18 @@ wallmsg(f, iov)
|
||||
continue;
|
||||
}
|
||||
/* should we send the message to this user? */
|
||||
for (i = 0; i < f->f_un.f_user.f_nusers; i++)
|
||||
if (!strncmp(f->f_un.f_user.f_unames[i], ut.ut_name,
|
||||
sizeof (ut.ut_name))) {
|
||||
for (i = 0; i < MAXUNAMES; i++) {
|
||||
if (!f->f_un.f_uname[i][0])
|
||||
break;
|
||||
if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
|
||||
UT_NAMESIZE)) {
|
||||
if ((p = ttymsg(iov, 6, line, 60*5)) != NULL) {
|
||||
errno = 0; /* already in msg */
|
||||
logerror(p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)fclose(uf);
|
||||
reenter = 0;
|
||||
@@ -833,18 +754,16 @@ void
|
||||
reapchild(signo)
|
||||
int signo;
|
||||
{
|
||||
#ifdef HAVE_WAITPID
|
||||
while (waitpid(-1, 0, WNOHANG) > 0)
|
||||
#else
|
||||
while (wait3(0, WNOHANG, (struct rusage *)NULL) > 0)
|
||||
#endif
|
||||
union wait status;
|
||||
|
||||
while (wait3((int *)&status, WNOHANG, (struct rusage *)NULL) > 0)
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a printable representation of a host address.
|
||||
*/
|
||||
const char *
|
||||
char *
|
||||
cvthname(f)
|
||||
struct sockaddr_in *f;
|
||||
{
|
||||
@@ -899,7 +818,7 @@ domark(signo)
|
||||
*/
|
||||
void
|
||||
logerror(type)
|
||||
const char *type;
|
||||
char *type;
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
@@ -995,7 +914,7 @@ init(signo)
|
||||
*/
|
||||
for (p = cline; isspace(*p); ++p)
|
||||
continue;
|
||||
if (*p == 0 || *p == '#')
|
||||
if (*p == NULL || *p == '#')
|
||||
continue;
|
||||
for (p = strchr(cline, '\0'); isspace(*--p);)
|
||||
continue;
|
||||
@@ -1031,9 +950,8 @@ init(signo)
|
||||
break;
|
||||
|
||||
case F_USERS:
|
||||
for (i = 0; i < f->f_un.f_user.f_nusers; i++)
|
||||
printf("%s, ",
|
||||
f->f_un.f_user.f_unames[i]);
|
||||
for (i = 0; i < MAXUNAMES && *f->f_un.f_uname[i]; i++)
|
||||
printf("%s, ", f->f_un.f_uname[i]);
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
@@ -1088,8 +1006,8 @@ cfline(line, f)
|
||||
else {
|
||||
pri = decode(buf, prioritynames);
|
||||
if (pri < 0) {
|
||||
snprintf (ebuf, sizeof ebuf,
|
||||
"unknown priority name \"%s\"", buf);
|
||||
(void)sprintf(ebuf,
|
||||
"unknown priority name \"%s\"", buf);
|
||||
logerror(ebuf);
|
||||
return;
|
||||
}
|
||||
@@ -1106,8 +1024,9 @@ cfline(line, f)
|
||||
else {
|
||||
i = decode(buf, facilitynames);
|
||||
if (i < 0) {
|
||||
snprintf (ebuf, sizeof ebuf,
|
||||
"unknown facility name \"%s\"", buf);
|
||||
(void)sprintf(ebuf,
|
||||
"unknown facility name \"%s\"",
|
||||
buf);
|
||||
logerror(ebuf);
|
||||
return;
|
||||
}
|
||||
@@ -1129,18 +1048,16 @@ cfline(line, f)
|
||||
case '@':
|
||||
if (!InetInuse)
|
||||
break;
|
||||
f->f_un.f_forw.f_hname = strdup (++p);
|
||||
(void)strcpy(f->f_un.f_forw.f_hname, ++p);
|
||||
hp = gethostbyname(p);
|
||||
if (hp == NULL) {
|
||||
extern int h_errno;
|
||||
#ifndef HAVE_HSTRERROR_DECL
|
||||
extern char *hstrerror __P((int));
|
||||
#endif
|
||||
|
||||
logerror(hstrerror(h_errno));
|
||||
break;
|
||||
}
|
||||
memset(&f->f_un.f_forw.f_addr, 0,
|
||||
sizeof(f->f_un.f_forw.f_addr));
|
||||
sizeof(f->f_un.f_forw.f_addr));
|
||||
f->f_un.f_forw.f_addr.sin_family = AF_INET;
|
||||
f->f_un.f_forw.f_addr.sin_port = LogPort;
|
||||
memmove(&f->f_un.f_forw.f_addr.sin_addr, hp->h_addr, hp->h_length);
|
||||
@@ -1148,7 +1065,7 @@ cfline(line, f)
|
||||
break;
|
||||
|
||||
case '/':
|
||||
f->f_un.f_fname = strdup (p);
|
||||
(void)strcpy(f->f_un.f_fname, p);
|
||||
if ((f->f_file = open(p, O_WRONLY|O_APPEND, 0)) < 0) {
|
||||
f->f_file = F_UNUSED;
|
||||
logerror(p);
|
||||
@@ -1167,20 +1084,14 @@ cfline(line, f)
|
||||
break;
|
||||
|
||||
default:
|
||||
f->f_un.f_user.f_nusers = 1;
|
||||
for (q = p; *q; q++)
|
||||
if (*q == ',')
|
||||
f->f_un.f_user.f_nusers++;
|
||||
f->f_un.f_user.f_unames =
|
||||
(char **) malloc (f->f_un.f_user.f_nusers * sizeof (char *));
|
||||
for (i = 0; *p; i++) {
|
||||
for (i = 0; i < MAXUNAMES && *p; i++) {
|
||||
for (q = p; *q && *q != ','; )
|
||||
q++;
|
||||
f->f_un.f_user.f_unames[i] = malloc (q - p + 1);
|
||||
if (f->f_un.f_user.f_unames[i]) {
|
||||
strncpy (f->f_un.f_user.f_unames[i], p, q - p);
|
||||
f->f_un.f_user.f_unames[i][q - p] = '\0';
|
||||
}
|
||||
(void)strncpy(f->f_un.f_uname[i], p, UT_NAMESIZE);
|
||||
if ((q - p) > UT_NAMESIZE)
|
||||
f->f_un.f_uname[i][UT_NAMESIZE] = '\0';
|
||||
else
|
||||
f->f_un.f_uname[i][q - p] = '\0';
|
||||
while (*q == ',' || *q == ' ')
|
||||
q++;
|
||||
p = q;
|
||||
@@ -1190,6 +1101,7 @@ cfline(line, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Decode a symbolic name to a numeric value
|
||||
*/
|
||||
|
||||
13
talk/ctl.c
13
talk/ctl.c
@@ -41,29 +41,16 @@ static char sccsid[] = "@(#)ctl.c 8.1 (Berkeley) 6/6/93";
|
||||
* the progress
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <netinet/in.h>
|
||||
#include "talk.h"
|
||||
#include "talk_ctl.h"
|
||||
|
||||
#ifdef HAVE_SOCKADDR_IN_SIN_LEN
|
||||
struct sockaddr_in daemon_addr = { sizeof(daemon_addr), AF_INET };
|
||||
struct sockaddr_in ctl_addr = { sizeof(ctl_addr), AF_INET };
|
||||
struct sockaddr_in my_addr = { sizeof(my_addr), AF_INET };
|
||||
#else /* !HAVE_SOCKADDR_IN_SIN_LEN */
|
||||
struct sockaddr_in daemon_addr = { AF_INET };
|
||||
struct sockaddr_in ctl_addr = { AF_INET };
|
||||
struct sockaddr_in my_addr = { AF_INET };
|
||||
#endif /* HAVE_SOCKADDR_IN_SIN_LEN */
|
||||
|
||||
/* inet addresses of the two machines */
|
||||
struct in_addr my_machine_addr;
|
||||
|
||||
@@ -35,29 +35,10 @@
|
||||
static char sccsid[] = "@(#)ctl_transact.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <errno.h>
|
||||
#include "talk_ctl.h"
|
||||
@@ -75,15 +56,13 @@ ctl_transact(target, msg, type, rp)
|
||||
int type;
|
||||
CTL_RESPONSE *rp;
|
||||
{
|
||||
int nready, cc;
|
||||
fd_set read_mask, ctl_mask;
|
||||
int read_mask, ctl_mask, nready, cc;
|
||||
struct timeval wait;
|
||||
|
||||
msg.type = type;
|
||||
daemon_addr.sin_addr = target;
|
||||
daemon_addr.sin_port = daemon_port;
|
||||
FD_ZERO(&ctl_mask);
|
||||
FD_SET(ctl_sockt, &ctl_mask);
|
||||
ctl_mask = 1 << ctl_sockt;
|
||||
|
||||
/*
|
||||
* Keep sending the message until a response of
|
||||
|
||||
@@ -39,11 +39,6 @@ static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
|
||||
* The window 'manager', initializes curses and handles the actual
|
||||
* displaying of text
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "talk.h"
|
||||
|
||||
xwin_t my_win;
|
||||
|
||||
@@ -35,16 +35,9 @@
|
||||
static char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -35,22 +35,15 @@
|
||||
static char sccsid[] = "@(#)get_names.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <pwd.h>
|
||||
#include "talk.h"
|
||||
|
||||
char *getlogin();
|
||||
char *ttyname();
|
||||
char *rindex();
|
||||
extern CTL_MSG msg;
|
||||
|
||||
/*
|
||||
@@ -60,7 +53,7 @@ get_names(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
extern char *localhost ();
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
char *his_name, *my_name;
|
||||
char *my_machine_name, *his_machine_name;
|
||||
char *my_tty, *his_tty;
|
||||
@@ -83,15 +76,10 @@ get_names(argc, argv)
|
||||
}
|
||||
my_name = pw->pw_name;
|
||||
}
|
||||
|
||||
my_machine_name = localhost ();
|
||||
if (! my_machine_name) {
|
||||
perror ("Cannot get local hostname");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
gethostname(hostname, sizeof (hostname));
|
||||
my_machine_name = hostname;
|
||||
/* check for, and strip out, the machine name of the target */
|
||||
for (cp = argv[1]; *cp && !strchr ("@:!.", *cp); cp++)
|
||||
for (cp = argv[1]; *cp && !index("@:!.", *cp); cp++)
|
||||
;
|
||||
if (*cp == '\0') {
|
||||
/* this is a local to local talk */
|
||||
@@ -127,6 +115,4 @@ get_names(argc, argv)
|
||||
msg.r_name[NAME_SIZE - 1] = '\0';
|
||||
strncpy(msg.r_tty, his_tty, TTY_SIZE);
|
||||
msg.r_tty[TTY_SIZE - 1] = '\0';
|
||||
|
||||
free (my_machine_name);
|
||||
}
|
||||
|
||||
@@ -40,18 +40,8 @@ static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94";
|
||||
* as well as the signal handling routines.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#else
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_IOCTL_COMPAT_H
|
||||
#include <sys/ioctl_compat.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <err.h>
|
||||
@@ -64,38 +54,20 @@ static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94";
|
||||
init_display()
|
||||
{
|
||||
void sig_sent();
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction siga;
|
||||
#else
|
||||
#ifdef HAVE_SIGVEC
|
||||
struct sigvec sigv;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (initscr() == NULL)
|
||||
errx(1, "Terminal type unset or lacking necessary features.");
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigaction (SIGTSTP, (struct sigaction *)0, &siga);
|
||||
sigaddset(&siga.sa_mask, SIGALRM);
|
||||
sigaction (SIGTSTP, &siga, (struct sigaction *)0);
|
||||
#else /* !HAVE_SIGACTION */
|
||||
#ifdef HAVE_SIGVEC
|
||||
sigvec (SIGTSTP, (struct sigvec *)0, &sigv);
|
||||
sigv.sv_mask |= sigmask (SIGALRM);
|
||||
sigvec (SIGTSTP, &sigv, (struct sigvec *)0);
|
||||
#endif /* HAVE_SIGVEC */
|
||||
#endif /* HAVE_SIGACTION */
|
||||
|
||||
(void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
|
||||
sigv.sv_mask |= sigmask(SIGALRM);
|
||||
(void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
|
||||
curses_initialized = 1;
|
||||
clear();
|
||||
refresh();
|
||||
noecho();
|
||||
crmode();
|
||||
|
||||
signal(SIGINT, sig_sent);
|
||||
signal(SIGPIPE, sig_sent);
|
||||
|
||||
/* curses takes care of ^Z */
|
||||
my_win.x_nlines = LINES / 2;
|
||||
my_win.x_ncols = COLS;
|
||||
@@ -124,38 +96,8 @@ init_display()
|
||||
*/
|
||||
set_edit_chars()
|
||||
{
|
||||
int cc;
|
||||
char buf[3];
|
||||
|
||||
#ifdef HAVE_TCGETATTR
|
||||
struct termios tty;
|
||||
cc_t disable = (cc_t)-1, erase, werase, kill;
|
||||
|
||||
#if !defined (_POSIX_VDISABLE) && defined (HAVE_FPATHCONF) && defined (_PC_VDISABLE)
|
||||
disable = fpathconf (0, _PC_VDISABLE);
|
||||
#endif
|
||||
|
||||
erase = werase = kill = disable;
|
||||
|
||||
if (tcgetattr (0, &tty) >= 0) {
|
||||
erase = tty.c_cc[VERASE];
|
||||
#ifdef VWERASE
|
||||
werase = tty.c_cc[VWERASE];
|
||||
#endif
|
||||
kill = tty.c_cc[VKILL];
|
||||
}
|
||||
|
||||
if (erase == disable)
|
||||
erase = '\177'; /* rubout */
|
||||
if (werase == disable)
|
||||
werase = '\027'; /* ^W */
|
||||
if (kill == disable)
|
||||
kill = '\025'; /* ^U */
|
||||
|
||||
my_win.cerase = erase;
|
||||
my_win.werase = werase;
|
||||
my_win.kill = kill;
|
||||
#else /* !HAVE_TCGETATTR */
|
||||
int cc;
|
||||
struct sgttyb tty;
|
||||
struct ltchars ltc;
|
||||
|
||||
@@ -167,8 +109,6 @@ set_edit_chars()
|
||||
my_win.werase = '\027'; /* control W */
|
||||
else
|
||||
my_win.werase = ltc.t_werasc;
|
||||
#endif /* HAVE_TCGETATTR */
|
||||
|
||||
buf[0] = my_win.cerase;
|
||||
buf[1] = my_win.kill;
|
||||
buf[2] = my_win.werase;
|
||||
|
||||
@@ -35,27 +35,11 @@
|
||||
static char sccsid[] = "@(#)invite.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
@@ -89,12 +73,13 @@ invite_remote()
|
||||
itimer.it_interval = itimer.it_value;
|
||||
if (listen(sockt, 5) != 0)
|
||||
p_error("Error on attempt to listen for caller");
|
||||
|
||||
msg.addr.sa_family = htons (my_addr.sin_family);
|
||||
memcpy (msg.addr.sa_data,
|
||||
((struct sockaddr *)&my_addr)->sa_data,
|
||||
sizeof ((struct sockaddr *)&my_addr)->sa_data);
|
||||
|
||||
#ifdef MSG_EOR
|
||||
/* copy new style sockaddr to old, swap family (short in old) */
|
||||
msg.addr = *(struct osockaddr *)&my_addr; /* XXX new to old style*/
|
||||
msg.addr.sa_family = htons(my_addr.sin_family);
|
||||
#else
|
||||
msg.addr = *(struct sockaddr *)&my_addr;
|
||||
#endif
|
||||
msg.id_num = htonl(-1); /* an impossible id_num */
|
||||
invitation_waiting = 1;
|
||||
announce_invite();
|
||||
@@ -190,13 +175,13 @@ send_delete()
|
||||
*/
|
||||
msg.id_num = htonl(remote_id);
|
||||
daemon_addr.sin_addr = his_machine_addr;
|
||||
if (sendto(ctl_sockt, (const char *)&msg, sizeof (msg), 0,
|
||||
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
|
||||
(struct sockaddr *)&daemon_addr,
|
||||
sizeof (daemon_addr)) != sizeof(msg))
|
||||
perror("send_delete (remote)");
|
||||
msg.id_num = htonl(local_id);
|
||||
daemon_addr.sin_addr = my_machine_addr;
|
||||
if (sendto(ctl_sockt, (const char *)&msg, sizeof (msg), 0,
|
||||
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
|
||||
(struct sockaddr *)&daemon_addr,
|
||||
sizeof (daemon_addr)) != sizeof (msg))
|
||||
perror("send_delete (local)");
|
||||
|
||||
45
talk/io.c
45
talk/io.c
@@ -41,62 +41,41 @@ static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
|
||||
* ctl.c
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include "talk.h"
|
||||
|
||||
#define A_LONG_TIME 10000000
|
||||
#define STDIN_MASK (1<<fileno(stdin)) /* the bit mask for standard
|
||||
input */
|
||||
|
||||
/*
|
||||
* The routine to do the actual talking
|
||||
*/
|
||||
talk()
|
||||
{
|
||||
fd_set read_template, read_set;
|
||||
int stdin_fd = fileno (stdin);
|
||||
int nb, num_fds;
|
||||
register int read_template, sockt_mask;
|
||||
int read_set, nb;
|
||||
char buf[BUFSIZ];
|
||||
struct timeval wait;
|
||||
|
||||
message("Connection established\007\007\007");
|
||||
current_line = 0;
|
||||
sockt_mask = (1<<sockt);
|
||||
|
||||
/*
|
||||
* Wait on both the other process (SOCKET) and stdin.
|
||||
* Wait on both the other process (sockt_mask) and
|
||||
* standard input ( STDIN_MASK )
|
||||
*/
|
||||
FD_ZERO (&read_template);
|
||||
FD_SET (sockt, &read_template);
|
||||
FD_SET (stdin_fd, &read_template);
|
||||
num_fds = (stdin_fd > sockt ? stdin_fd : sockt) + 1;
|
||||
|
||||
read_template = sockt_mask | STDIN_MASK;
|
||||
for (;;) {
|
||||
read_set = read_template;
|
||||
wait.tv_sec = A_LONG_TIME;
|
||||
wait.tv_usec = 0;
|
||||
nb = select (num_fds, &read_set, 0, 0, &wait);
|
||||
nb = select(32, &read_set, 0, 0, &wait);
|
||||
if (nb <= 0) {
|
||||
if (errno == EINTR) {
|
||||
read_set = read_template;
|
||||
@@ -106,7 +85,7 @@ talk()
|
||||
p_error("Unexpected error from select");
|
||||
quit();
|
||||
}
|
||||
if (FD_ISSET (sockt, &read_set)) {
|
||||
if (read_set & sockt_mask) {
|
||||
/* There is data on sockt */
|
||||
nb = read(sockt, buf, sizeof buf);
|
||||
if (nb <= 0) {
|
||||
@@ -115,7 +94,7 @@ talk()
|
||||
}
|
||||
display(&his_win, buf, nb);
|
||||
}
|
||||
if (FD_ISSET (stdin_fd, &read_set)) {
|
||||
if (read_set & STDIN_MASK) {
|
||||
/*
|
||||
* We can't make the tty non_blocking, because
|
||||
* curses's output routines would screw up
|
||||
|
||||
@@ -35,16 +35,9 @@
|
||||
static char sccsid[] = "@(#)look_up.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <errno.h>
|
||||
#include "talk_ctl.h"
|
||||
@@ -59,11 +52,13 @@ check_local()
|
||||
register CTL_RESPONSE *rp = &response;
|
||||
|
||||
/* the rest of msg was set up in get_names */
|
||||
msg.ctl_addr.sa_family = htons (ctl_addr.sin_family);
|
||||
memcpy (msg.ctl_addr.sa_data,
|
||||
((struct sockaddr *)&ctl_addr)->sa_data,
|
||||
sizeof ((struct sockaddr *)&ctl_addr)->sa_data);
|
||||
|
||||
#ifdef MSG_EOR
|
||||
/* copy new style sockaddr to old, swap family (short in old) */
|
||||
msg.ctl_addr = *(struct osockaddr *)&ctl_addr;
|
||||
msg.ctl_addr.sa_family = htons(ctl_addr.sin_family);
|
||||
#else
|
||||
msg.ctl_addr = *(struct sockaddr *)&ctl_addr;
|
||||
#endif
|
||||
/* must be initiating a talk */
|
||||
if (!look_for_invite(rp))
|
||||
return (0);
|
||||
|
||||
18
talk/msgs.c
18
talk/msgs.c
@@ -40,20 +40,7 @@ static char sccsid[] = "@(#)msgs.c 8.1 (Berkeley) 6/6/93";
|
||||
* if we are slow connecting.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "talk.h"
|
||||
@@ -64,8 +51,7 @@ char *current_state;
|
||||
int current_line = 0;
|
||||
|
||||
void
|
||||
disp_msg(sig)
|
||||
int sig;
|
||||
disp_msg()
|
||||
{
|
||||
message(current_state);
|
||||
}
|
||||
|
||||
@@ -41,10 +41,6 @@ static char copyright[] =
|
||||
static char sccsid[] = "@(#)talk.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "talk.h"
|
||||
|
||||
/*
|
||||
@@ -65,11 +61,6 @@ main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
#ifndef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
__progname = argv[0];
|
||||
#endif
|
||||
|
||||
get_names(argc, argv);
|
||||
init_display();
|
||||
open_ctl();
|
||||
|
||||
@@ -32,90 +32,30 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95";
|
||||
static char sccsid[] = "@(#)announce.c 8.2 (Berkeley) 1/7/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <sgtty.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#ifdef HAVE_VIS_H
|
||||
#include <vis.h>
|
||||
#endif
|
||||
#include <paths.h>
|
||||
|
||||
extern char *hostname;
|
||||
|
||||
extern char *ttymsg ();
|
||||
extern char hostname[];
|
||||
|
||||
/*
|
||||
* Announce an invitation to talk.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_VIS_H
|
||||
|
||||
#define VIS_CSTYLE 0 /* dummy value */
|
||||
|
||||
/* A simpler version of bsd's vis function. */
|
||||
static void
|
||||
strvis (dst, src, ignored)
|
||||
char *dst, *src;
|
||||
int ignored;
|
||||
{
|
||||
int ch;
|
||||
while (*src)
|
||||
switch (ch = *src++)
|
||||
{
|
||||
case '\b': *dst++ = '\\'; *dst++ = 'b'; break;
|
||||
case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
||||
case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
||||
#ifdef __STDC__
|
||||
case '\a':
|
||||
#else
|
||||
case '\007':
|
||||
#endif
|
||||
*dst++ = '\\'; *dst++ = 'a'; break;
|
||||
case '\f': *dst++ = '\\'; *dst++ = 'f'; break;
|
||||
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
||||
default:
|
||||
if (isgraph (ch))
|
||||
*dst++ = ch;
|
||||
else
|
||||
{
|
||||
sprintf (dst, "\\%03o", ch);
|
||||
dst += strlen(dst);
|
||||
}
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
#endif /* !HAVE_VIS_H */
|
||||
|
||||
/*
|
||||
* See if the user is accepting messages. If so, announce that
|
||||
* a talk is requested.
|
||||
@@ -125,18 +65,19 @@ announce(request, remote_machine)
|
||||
char *remote_machine;
|
||||
{
|
||||
char full_tty[32];
|
||||
FILE *tf;
|
||||
struct stat stbuf;
|
||||
|
||||
(void)snprintf(full_tty, sizeof(full_tty),
|
||||
"%s%s", PATH_DEV, request->r_tty);
|
||||
"%s%s", _PATH_DEV, request->r_tty);
|
||||
if (stat(full_tty, &stbuf) < 0 || (stbuf.st_mode&020) == 0)
|
||||
return (PERMISSION_DENIED);
|
||||
return (print_mesg(request->r_tty, request, remote_machine));
|
||||
return (print_mesg(request->r_tty, tf, request, remote_machine));
|
||||
}
|
||||
|
||||
#define max(a,b) ( (a) > (b) ? (a) : (b) )
|
||||
#define N_LINES 5
|
||||
#define N_CHARS 256
|
||||
#define N_CHARS 120
|
||||
|
||||
/*
|
||||
* Build a block of characters containing the message.
|
||||
@@ -144,8 +85,9 @@ announce(request, remote_machine)
|
||||
* try to keep the message in one piece if the recipient
|
||||
* in in vi at the time
|
||||
*/
|
||||
print_mesg(tty, request, remote_machine)
|
||||
print_mesg(tty, tf, request, remote_machine)
|
||||
char *tty;
|
||||
FILE *tf;
|
||||
CTL_MSG *request;
|
||||
char *remote_machine;
|
||||
{
|
||||
@@ -157,7 +99,7 @@ print_mesg(tty, request, remote_machine)
|
||||
char line_buf[N_LINES][N_CHARS];
|
||||
int sizes[N_LINES];
|
||||
char big_buf[N_LINES*N_CHARS];
|
||||
char *bptr, *lptr, *vis_user;
|
||||
char *bptr, *lptr, *ttymsg();
|
||||
int i, j, max_size;
|
||||
|
||||
i = 0;
|
||||
@@ -168,21 +110,18 @@ print_mesg(tty, request, remote_machine)
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
snprintf (line_buf[i], sizeof line_buf[i],
|
||||
"Message from Talk_Daemon@%s at %d:%02d ...",
|
||||
(void)sprintf(line_buf[i], "Message from Talk_Daemon@%s at %d:%02d ...",
|
||||
hostname, localclock->tm_hour , localclock->tm_min );
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
vis_user = malloc(strlen(request->l_name) * 4 + 1);
|
||||
strvis(vis_user, request->l_name, VIS_CSTYLE);
|
||||
snprintf (line_buf[i], sizeof line_buf[i],
|
||||
"talk: connection requested by %s@%s", vis_user, remote_machine);
|
||||
(void)sprintf(line_buf[i], "talk: connection requested by %s@%s",
|
||||
request->l_name, remote_machine);
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
snprintf (line_buf[i], sizeof line_buf[i],
|
||||
"talk: respond with: talk %s@%s", vis_user, remote_machine);
|
||||
(void)sprintf(line_buf[i], "talk: respond with: talk %s@%s",
|
||||
request->l_name, remote_machine);
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
@@ -190,7 +129,6 @@ print_mesg(tty, request, remote_machine)
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
free (vis_user);
|
||||
bptr = big_buf;
|
||||
*bptr++ = ''; /* send something to wake them up */
|
||||
*bptr++ = '\r'; /* add a \r in case of raw mode */
|
||||
|
||||
@@ -37,15 +37,8 @@ static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
/* debug print routines */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -43,23 +43,16 @@ static char sccsid[] = "@(#)process.c 8.2 (Berkeley) 11/16/93";
|
||||
* in the table for the local user
|
||||
* DELETE - delete invitation
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <netdb.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <paths.h>
|
||||
|
||||
CTL_MSG *find_request();
|
||||
CTL_MSG *find_match();
|
||||
@@ -73,7 +66,7 @@ process_request(mp, rp)
|
||||
|
||||
rp->vers = TALK_VERSION;
|
||||
rp->type = mp->type;
|
||||
rp->id_num = htonl((long)0);
|
||||
rp->id_num = htonl(0);
|
||||
if (mp->vers != TALK_VERSION) {
|
||||
syslog(LOG_WARNING, "Bad protocol version %d", mp->vers);
|
||||
rp->answer = BADVERSION;
|
||||
@@ -190,15 +183,15 @@ find_user(name, tty)
|
||||
FILE *fd;
|
||||
struct stat statb;
|
||||
char line[sizeof(ubuf.ut_line) + 1];
|
||||
char ftty[sizeof(PATH_DEV) - 1 + sizeof(line)];
|
||||
char ftty[sizeof(_PATH_DEV) - 1 + sizeof(line)];
|
||||
|
||||
if ((fd = fopen(PATH_UTMP, "r")) == NULL) {
|
||||
fprintf(stderr, "talkd: can't read %s.\n", PATH_UTMP);
|
||||
if ((fd = fopen(_PATH_UTMP, "r")) == NULL) {
|
||||
fprintf(stderr, "talkd: can't read %s.\n", _PATH_UTMP);
|
||||
return (FAILED);
|
||||
}
|
||||
#define SCMPN(a, b) strncmp(a, b, sizeof (a))
|
||||
status = NOT_HERE;
|
||||
(void) strcpy(ftty, PATH_DEV);
|
||||
(void) strcpy(ftty, _PATH_DEV);
|
||||
while (fread((char *) &ubuf, sizeof ubuf, 1, fd) == 1)
|
||||
if (SCMPN(ubuf.ut_name, name) == 0) {
|
||||
strncpy(line, ubuf.ut_line, sizeof(ubuf.ut_line));
|
||||
@@ -206,7 +199,7 @@ find_user(name, tty)
|
||||
if (*tty == '\0') {
|
||||
status = PERMISSION_DENIED;
|
||||
/* no particular tty was requested */
|
||||
(void) strcpy(ftty + sizeof(PATH_DEV) - 1,
|
||||
(void) strcpy(ftty + sizeof(_PATH_DEV) - 1,
|
||||
line);
|
||||
if (stat(ftty, &statb) == 0) {
|
||||
if (!(statb.st_mode & 020))
|
||||
|
||||
@@ -43,26 +43,9 @@ static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/4/93";
|
||||
*
|
||||
* Consider this a mis-guided attempt at modularity
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -47,36 +47,18 @@ static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93";
|
||||
* disconnect all descriptors and ttys, and then endless
|
||||
* loop on waiting for and processing requests
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_OSOCKADDR_H
|
||||
#include <osockaddr.h>
|
||||
#endif
|
||||
#include <protocols/talkd.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern char *localhost ();
|
||||
#include <paths.h>
|
||||
|
||||
CTL_MSG request;
|
||||
CTL_RESPONSE response;
|
||||
@@ -86,7 +68,7 @@ int debug = 0;
|
||||
void timeout();
|
||||
long lastmsgtime;
|
||||
|
||||
char *hostname;
|
||||
char hostname[32];
|
||||
|
||||
#define TIMEOUT 30
|
||||
#define MAXIDLE 120
|
||||
@@ -103,13 +85,12 @@ main(argc, argv)
|
||||
exit(1);
|
||||
}
|
||||
openlog("talkd", LOG_PID, LOG_DAEMON);
|
||||
hostname = localhost ();
|
||||
if (! hostname) {
|
||||
syslog(LOG_ERR, "localhost: %m");
|
||||
if (gethostname(hostname, sizeof (hostname) - 1) < 0) {
|
||||
syslog(LOG_ERR, "gethostname: %m");
|
||||
_exit(1);
|
||||
}
|
||||
if (chdir(PATH_DEV) < 0) {
|
||||
syslog(LOG_ERR, "chdir: %s: %m", PATH_DEV);
|
||||
if (chdir(_PATH_DEV) < 0) {
|
||||
syslog(LOG_ERR, "chdir: %s: %m", _PATH_DEV);
|
||||
_exit(1);
|
||||
}
|
||||
if (argc > 1 && strcmp(argv[1], "-d") == 0)
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
|
||||
#include <sys/types.h>
|
||||
#include <arpa/telnet.h>
|
||||
@@ -96,9 +92,7 @@ telnet_gets(prompt, result, length, echo)
|
||||
int length;
|
||||
int echo;
|
||||
{
|
||||
#ifndef HAVE_GETPASS_DECL
|
||||
extern char *getpass();
|
||||
#endif
|
||||
extern int globalmode;
|
||||
int om = globalmode;
|
||||
char *res;
|
||||
|
||||
@@ -32,50 +32,31 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)commands.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#if defined(unix)
|
||||
#include <sys/param.h>
|
||||
#if defined(CRAY) || defined(sysV88)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <sys/file.h>
|
||||
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#endif /* defined(unix) */
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#ifdef CRAY
|
||||
#include <fcntl.h>
|
||||
#endif /* CRAY */
|
||||
|
||||
#include <signal.h>
|
||||
#include <netdb.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include <arpa/telnet.h>
|
||||
|
||||
#include "general.h"
|
||||
@@ -87,24 +68,24 @@ static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
|
||||
#include "types.h"
|
||||
|
||||
#if !defined(CRAY) && !defined(sysV88)
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
# if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix)
|
||||
# include <machine/endian.h>
|
||||
# endif /* vax */
|
||||
#endif /* !defined(CRAY) && !defined(sysV88) */
|
||||
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 64
|
||||
#endif MAXHOSTNAMELEN
|
||||
|
||||
#if defined(IPPROTO_IP) && defined(IP_TOS)
|
||||
int tos = -1;
|
||||
#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
|
||||
|
||||
char *hostname;
|
||||
static char *_hostname = 0;
|
||||
static char _hostname[MAXHOSTNAMELEN];
|
||||
|
||||
extern char *getenv();
|
||||
|
||||
@@ -112,8 +93,7 @@ extern int isprefix();
|
||||
extern char **genget();
|
||||
extern int Ambiguous();
|
||||
|
||||
typedef int (*intrtn_t) __P((int, char *[]));
|
||||
static call __P((intrtn_t, ...));
|
||||
static call();
|
||||
|
||||
typedef struct {
|
||||
char *name; /* command name */
|
||||
@@ -767,11 +747,13 @@ static struct togglelist Togglelist[] = {
|
||||
0,
|
||||
&showoptions,
|
||||
"show option processing" },
|
||||
#if defined(unix)
|
||||
{ "termdata",
|
||||
"(debugging) toggle printing of hexadecimal terminal data",
|
||||
0,
|
||||
&termdata,
|
||||
"print hexadecimal representation of terminal traffic" },
|
||||
#endif /* defined(unix) */
|
||||
{ "?",
|
||||
0,
|
||||
togglehelp },
|
||||
@@ -1157,13 +1139,13 @@ dolmmode(bit, on)
|
||||
}
|
||||
|
||||
int
|
||||
set_mode(bit)
|
||||
setmode(bit)
|
||||
{
|
||||
return dolmmode(bit, 1);
|
||||
}
|
||||
|
||||
int
|
||||
clear_mode(bit)
|
||||
clearmode(bit)
|
||||
{
|
||||
return dolmmode(bit, 0);
|
||||
}
|
||||
@@ -1189,18 +1171,18 @@ static struct modelist ModeList[] = {
|
||||
#endif
|
||||
{ "", "", 0 },
|
||||
{ "", "These require the LINEMODE option to be enabled", 0 },
|
||||
{ "isig", "Enable signal trapping", set_mode, 1, MODE_TRAPSIG },
|
||||
{ "+isig", 0, set_mode, 1, MODE_TRAPSIG },
|
||||
{ "-isig", "Disable signal trapping", clear_mode, 1, MODE_TRAPSIG },
|
||||
{ "edit", "Enable character editing", set_mode, 1, MODE_EDIT },
|
||||
{ "+edit", 0, set_mode, 1, MODE_EDIT },
|
||||
{ "-edit", "Disable character editing", clear_mode, 1, MODE_EDIT },
|
||||
{ "softtabs", "Enable tab expansion", set_mode, 1, MODE_SOFT_TAB },
|
||||
{ "+softtabs", 0, set_mode, 1, MODE_SOFT_TAB },
|
||||
{ "-softtabs", "Disable character editing", clear_mode, 1, MODE_SOFT_TAB },
|
||||
{ "litecho", "Enable literal character echo", set_mode, 1, MODE_LIT_ECHO },
|
||||
{ "+litecho", 0, set_mode, 1, MODE_LIT_ECHO },
|
||||
{ "-litecho", "Disable literal character echo", clear_mode, 1, MODE_LIT_ECHO },
|
||||
{ "isig", "Enable signal trapping", setmode, 1, MODE_TRAPSIG },
|
||||
{ "+isig", 0, setmode, 1, MODE_TRAPSIG },
|
||||
{ "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
|
||||
{ "edit", "Enable character editing", setmode, 1, MODE_EDIT },
|
||||
{ "+edit", 0, setmode, 1, MODE_EDIT },
|
||||
{ "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
|
||||
{ "softtabs", "Enable tab expansion", setmode, 1, MODE_SOFT_TAB },
|
||||
{ "+softtabs", 0, setmode, 1, MODE_SOFT_TAB },
|
||||
{ "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
|
||||
{ "litecho", "Enable literal character echo", setmode, 1, MODE_LIT_ECHO },
|
||||
{ "+litecho", 0, setmode, 1, MODE_LIT_ECHO },
|
||||
{ "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
|
||||
{ "help", 0, modehelp, 0 },
|
||||
#ifdef KLUDGELINEMODE
|
||||
{ "kludgeline", 0, dokludgemode, 1 },
|
||||
@@ -1381,7 +1363,7 @@ suspend()
|
||||
(void) kill(0, SIGTSTP);
|
||||
/*
|
||||
* If we didn't get the window size before the SUSPEND, but we
|
||||
* can get them now (?), then send the NAWS to make sure that
|
||||
* can get them now (???), then send the NAWS to make sure that
|
||||
* we are set up for the right window size.
|
||||
*/
|
||||
if (TerminalWindowSize(&newrows, &newcols) && connected &&
|
||||
@@ -1421,14 +1403,12 @@ shell(argc, argv)
|
||||
* Fire up the shell in the child.
|
||||
*/
|
||||
register char *shellp, *shellname;
|
||||
#ifndef strrchr
|
||||
extern char *strrchr();
|
||||
#endif
|
||||
extern char *rindex();
|
||||
|
||||
shellp = getenv("SHELL");
|
||||
if (shellp == NULL)
|
||||
shellp = "/bin/sh";
|
||||
if ((shellname = strrchr(shellp, '/')) == 0)
|
||||
if ((shellname = rindex(shellp, '/')) == 0)
|
||||
shellname = shellp;
|
||||
else
|
||||
shellname++;
|
||||
@@ -1710,12 +1690,10 @@ env_init()
|
||||
extern char **environ;
|
||||
register char **epp, *cp;
|
||||
register struct env_lst *ep;
|
||||
#ifndef strchr
|
||||
extern char *strchr();
|
||||
#endif
|
||||
extern char *index();
|
||||
|
||||
for (epp = environ; *epp; epp++) {
|
||||
if (cp = strchr(*epp, '=')) {
|
||||
if (cp = index(*epp, '=')) {
|
||||
*cp = '\0';
|
||||
ep = env_define((unsigned char *)*epp,
|
||||
(unsigned char *)cp+1);
|
||||
@@ -1731,17 +1709,15 @@ env_init()
|
||||
if ((ep = env_find("DISPLAY"))
|
||||
&& ((*ep->value == ':')
|
||||
|| (strncmp((char *)ep->value, "unix:", 5) == 0))) {
|
||||
extern char *localhost ();
|
||||
char *hostname = localhost ();
|
||||
char *cp2 = strchr((char *)ep->value, ':');
|
||||
|
||||
cp = malloc(strlen(hostname) + strlen(cp2) + 1);
|
||||
sprintf(cp, "%s%s", hostname, cp2);
|
||||
char hbuf[256+1];
|
||||
char *cp2 = index((char *)ep->value, ':');
|
||||
|
||||
gethostname(hbuf, 256);
|
||||
hbuf[256] = '\0';
|
||||
cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);
|
||||
sprintf((char *)cp, "%s%s", hbuf, cp2);
|
||||
free(ep->value);
|
||||
ep->value = (unsigned char *)cp;
|
||||
|
||||
free (hostname);
|
||||
}
|
||||
/*
|
||||
* If USER is not defined, but LOGNAME is, then add
|
||||
@@ -1939,8 +1915,8 @@ struct authlist {
|
||||
};
|
||||
|
||||
extern int
|
||||
auth_enable P((char *)),
|
||||
auth_disable P((char *)),
|
||||
auth_enable P((int)),
|
||||
auth_disable P((int)),
|
||||
auth_status P((void));
|
||||
static int
|
||||
auth_help P((void));
|
||||
@@ -1979,12 +1955,6 @@ auth_cmd(argc, argv)
|
||||
{
|
||||
struct authlist *c;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr,
|
||||
"Need an argument to 'auth' command. 'auth ?' for help.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = (struct authlist *)
|
||||
genget(argv[1], (char **) AuthList, sizeof(struct authlist));
|
||||
if (c == 0) {
|
||||
@@ -2041,7 +2011,7 @@ struct encryptlist EncryptList[] = {
|
||||
EncryptEnable, 1, 1, 2 },
|
||||
{ "disable", "Disable encryption. ('encrypt enable ?' for more)",
|
||||
EncryptDisable, 0, 1, 2 },
|
||||
{ "type", "Set encryption type. ('encrypt type ?' for more)",
|
||||
{ "type", "Set encryptiong type. ('encrypt type ?' for more)",
|
||||
EncryptType, 0, 1, 1 },
|
||||
{ "start", "Start encryption. ('encrypt start ?' for more)",
|
||||
EncryptStart, 1, 0, 1 },
|
||||
@@ -2085,12 +2055,6 @@ encrypt_cmd(argc, argv)
|
||||
{
|
||||
struct encryptlist *c;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr,
|
||||
"Need an argument to 'encrypt' command. 'encrypt ?' for help.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = (struct encryptlist *)
|
||||
genget(argv[1], (char **) EncryptList, sizeof(struct encryptlist));
|
||||
if (c == 0) {
|
||||
@@ -2258,16 +2222,13 @@ tn(argc, argv)
|
||||
unsigned long temp;
|
||||
extern char *inet_ntoa();
|
||||
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
|
||||
char *srp = 0;
|
||||
#ifndef strrchr
|
||||
char *strrchr();
|
||||
#endif
|
||||
char *srp = 0, *strrchr();
|
||||
unsigned long sourceroute(), srlen;
|
||||
#endif
|
||||
char *cmd, *hostp = 0, *portp = 0, *user = 0;
|
||||
|
||||
/* clear the socket address prior to use */
|
||||
memset((char *)&sin, 0, sizeof(sin));
|
||||
bzero((char *)&sin, sizeof(sin));
|
||||
|
||||
if (connected) {
|
||||
printf("?Already connected to %s\n", hostname);
|
||||
@@ -2285,7 +2246,7 @@ tn(argc, argv)
|
||||
cmd = *argv;
|
||||
--argc; ++argv;
|
||||
while (argc) {
|
||||
if (strcmp(*argv, "help") == 0 || isprefix(*argv, "?"))
|
||||
if (isprefix(*argv, "help") || isprefix(*argv, "?"))
|
||||
goto usage;
|
||||
if (strcmp(*argv, "-l") == 0) {
|
||||
--argc; ++argv;
|
||||
@@ -2343,40 +2304,21 @@ tn(argc, argv)
|
||||
if (temp != (unsigned long) -1) {
|
||||
sin.sin_addr.s_addr = temp;
|
||||
sin.sin_family = AF_INET;
|
||||
|
||||
if (_hostname)
|
||||
free (_hostname);
|
||||
_hostname = malloc (strlen (hostp) + 1);
|
||||
if (_hostname) {
|
||||
strcpy (_hostname, hostp);
|
||||
hostname = _hostname;
|
||||
} else {
|
||||
printf ("Can't allocate memory to copy hostname\n");
|
||||
setuid(getuid());
|
||||
return 0;
|
||||
}
|
||||
(void) strcpy(_hostname, hostp);
|
||||
hostname = _hostname;
|
||||
} else {
|
||||
host = gethostbyname(hostp);
|
||||
if (host) {
|
||||
sin.sin_family = host->h_addrtype;
|
||||
#if defined(h_addr) /* In 4.3, this is a #define */
|
||||
memmove((caddr_t)&sin.sin_addr,
|
||||
memcpy((caddr_t)&sin.sin_addr,
|
||||
host->h_addr_list[0], host->h_length);
|
||||
#else /* defined(h_addr) */
|
||||
memmove((caddr_t)&sin.sin_addr, host->h_addr, host->h_length);
|
||||
memcpy((caddr_t)&sin.sin_addr, host->h_addr, host->h_length);
|
||||
#endif /* defined(h_addr) */
|
||||
|
||||
if (_hostname)
|
||||
free (_hostname);
|
||||
_hostname = malloc (strlen (host->h_name) + 1);
|
||||
if (_hostname) {
|
||||
strcpy (_hostname, host->h_name);
|
||||
hostname = _hostname;
|
||||
} else {
|
||||
printf ("Can't allocate memory to copy hostname\n");
|
||||
setuid(getuid());
|
||||
return 0;
|
||||
}
|
||||
strncpy(_hostname, host->h_name, sizeof(_hostname));
|
||||
_hostname[sizeof(_hostname)-1] = '\0';
|
||||
hostname = _hostname;
|
||||
} else {
|
||||
herror(hostp);
|
||||
setuid(getuid());
|
||||
@@ -2403,12 +2345,10 @@ tn(argc, argv)
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
#ifndef HAVE_HTONS_DECL
|
||||
#ifndef htons
|
||||
u_short htons __P((unsigned short));
|
||||
#endif
|
||||
#endif
|
||||
sin.sin_port = htons (sin.sin_port);
|
||||
#if !defined(htons)
|
||||
u_short htons P((unsigned short));
|
||||
#endif /* !defined(htons) */
|
||||
sin.sin_port = htons(sin.sin_port);
|
||||
}
|
||||
} else {
|
||||
if (sp == 0) {
|
||||
@@ -2465,7 +2405,7 @@ tn(argc, argv)
|
||||
errno = oerrno;
|
||||
perror((char *)0);
|
||||
host->h_addr_list++;
|
||||
memmove((caddr_t)&sin.sin_addr,
|
||||
memcpy((caddr_t)&sin.sin_addr,
|
||||
host->h_addr_list[0], host->h_length);
|
||||
(void) NetClose(net);
|
||||
continue;
|
||||
@@ -2589,26 +2529,17 @@ static Command cmdtab2[] = {
|
||||
|
||||
/*VARARGS1*/
|
||||
static
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
call(intrtn_t routine, ...)
|
||||
#else
|
||||
call(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if !(defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__)
|
||||
typedef int (*intrtn_t)();
|
||||
intrtn_t routine;
|
||||
#endif
|
||||
char *args[100];
|
||||
int argno = 0;
|
||||
|
||||
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
|
||||
va_start(ap, routine);
|
||||
#else
|
||||
va_start(ap);
|
||||
routine = (va_arg(ap, intrtn_t));
|
||||
#endif
|
||||
while ((args[argno++] = va_arg(ap, char *)) != 0) {
|
||||
;
|
||||
}
|
||||
@@ -2958,16 +2889,16 @@ sourceroute(arg, cpp, lenp)
|
||||
sin_addr.s_addr = tmp;
|
||||
} else if (host = gethostbyname(cp)) {
|
||||
#if defined(h_addr)
|
||||
memmove((caddr_t)&sin_addr,
|
||||
memcpy((caddr_t)&sin_addr,
|
||||
host->h_addr_list[0], host->h_length);
|
||||
#else
|
||||
memmove((caddr_t)&sin_addr, host->h_addr, host->h_length);
|
||||
memcpy((caddr_t)&sin_addr, host->h_addr, host->h_length);
|
||||
#endif
|
||||
} else {
|
||||
*cpp = cp;
|
||||
return(0);
|
||||
}
|
||||
memmove(lsrp, (char *)&sin_addr, 4);
|
||||
memcpy(lsrp, (char *)&sin_addr, 4);
|
||||
lsrp += 4;
|
||||
if (cp2)
|
||||
cp = cp2;
|
||||
|
||||
@@ -30,22 +30,13 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)externs.h 8.3 (Berkeley) 5/30/95
|
||||
* @(#)externs.h 8.2 (Berkeley) 12/15/93
|
||||
*/
|
||||
|
||||
#ifndef BSD
|
||||
# define BSD 43
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#define USE_TERMIO
|
||||
#else /* !HAVE_TERMIOS_H */
|
||||
#ifdef HAVE_TERMIO_H
|
||||
#define USE_TERMIO
|
||||
#define SYSV_TERMIO
|
||||
#endif
|
||||
#endif /* HAVE_TERMIOS_H */
|
||||
|
||||
/*
|
||||
* ucb stdio.h defines BSD as something wierd
|
||||
*/
|
||||
@@ -64,8 +55,9 @@
|
||||
#if defined(CRAY) && !defined(NO_BSD_SETJMP)
|
||||
#include <bsdsetjmp.h>
|
||||
#endif
|
||||
#ifndef FILIO_H
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#else
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef CRAY
|
||||
@@ -74,9 +66,10 @@
|
||||
#ifdef USE_TERMIO
|
||||
# ifndef VINTR
|
||||
# ifdef SYSV_TERMIO
|
||||
# include <termio.h>
|
||||
# include <sys/termio.h>
|
||||
# else
|
||||
# include <termios.h>
|
||||
# include <sys/termios.h>
|
||||
# define termio termios
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -88,15 +81,10 @@ typedef unsigned char cc_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (USE_TERMIO) && !defined (SYSV_TERMIO)
|
||||
# define termio termios
|
||||
#endif
|
||||
|
||||
#ifndef NO_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <strings.h>
|
||||
|
||||
#ifndef _POSIX_VDISABLE
|
||||
# ifdef sun
|
||||
@@ -149,12 +137,14 @@ extern int
|
||||
crmod,
|
||||
netdata, /* Print out network data flow */
|
||||
prettydump, /* Print "netdata" output in user readable format */
|
||||
#if defined(unix)
|
||||
#if defined(TN3270)
|
||||
cursesdata, /* Print out curses data flow */
|
||||
apitrace, /* Trace API transactions */
|
||||
#endif /* defined(TN3270) */
|
||||
termdata, /* Print out terminal data flow */
|
||||
debug; /* Debug level */
|
||||
#endif /* defined(unix) */
|
||||
debug; /* Debug level */
|
||||
|
||||
extern cc_t escape; /* Escape to command mode */
|
||||
extern cc_t rlogin; /* Rlogin mode escape character */
|
||||
|
||||
158
telnet/main.c
158
telnet/main.c
@@ -38,23 +38,15 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "ring.h"
|
||||
#include "externs.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
/* These values need to be the same as defined in libtelnet/kerberos5.c */
|
||||
/* Either define them in both places, or put in some common header file. */
|
||||
#define OPTS_FORWARD_CREDS 0x00000002
|
||||
@@ -82,110 +74,42 @@ tninit()
|
||||
init_3270();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define USAGE "Usage: %s [OPTION...] [HOST [PORT]]\n"
|
||||
|
||||
/* Print a help message describing all options to STDOUT and exit with a
|
||||
status of 0. */
|
||||
static void
|
||||
help ()
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf (stdout, USAGE, prompt);
|
||||
|
||||
puts ("Login to remote system HOST (optionally, on service port PORT)\n\n\
|
||||
-8, --binary Use an 8-bit data path\n\
|
||||
-a, --login Attempt automatic login\n\
|
||||
-c, --no-rc Don't read the user's .telnetrc file\n\
|
||||
-d, --debug Turn on debugging\n\
|
||||
-e CHAR, --escape=CHAR Use CHAR as an escape character\n\
|
||||
-E, --no-escape Use no escape character\n\
|
||||
-K, --no-login Don't automatically login to the remote system\n\
|
||||
-l USER, --user=USER Attempt automatic login as USER\n\
|
||||
-L, --binary-output Use an 8-bit data path for output only\n\
|
||||
-n FILE, --trace=FILE Record trace information into FILE\n\
|
||||
-r, --rlogin Use a user-interface similar to rlogin\n\
|
||||
-S TOS, --tos=TOS Use the IP type-of-service TOS\n\
|
||||
-X ATYPE, --disable-auth=ATYPE Disable type ATYPE authentication");
|
||||
|
||||
#ifdef ENCRYPTION
|
||||
puts ("\
|
||||
-x, --encrypt Encrypt the data stream, if possible");
|
||||
fprintf(stderr, "Usage: %s %s%s%s%s\n",
|
||||
prompt,
|
||||
#ifdef AUTHENTICATION
|
||||
"[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
|
||||
"\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
|
||||
#else
|
||||
"[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
|
||||
"\n\t[-n tracefile]",
|
||||
#endif
|
||||
|
||||
#ifdef AUTHENTICATION
|
||||
puts ("\n\
|
||||
When using Kerberos authentication:\n\
|
||||
-f, --fwd-credentials Allow the the local credentials to be forwarded\n\
|
||||
-k REALM, --realm=REALM Obtain tickets for the remote host in REALM\n\
|
||||
instead of the remote host's realm");
|
||||
#endif
|
||||
|
||||
#if defined(TN3270) && defined(unix)
|
||||
puts ("\n\
|
||||
TN3270 options (note non-standard option syntax):\n\
|
||||
-noasynch\n\
|
||||
-noasynctty\n\
|
||||
-noasyncnet\n\
|
||||
-t LINE, --transcom=LINE");
|
||||
# ifdef AUTHENTICATION
|
||||
"[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
|
||||
# else
|
||||
"[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
|
||||
# endif
|
||||
#else
|
||||
"[-r] ",
|
||||
#endif
|
||||
|
||||
#if defined (ENCRYPTION) || defined (AUTHENTICATION) || defined (TN3270)
|
||||
putc ('\n');
|
||||
#endif
|
||||
|
||||
puts ("\
|
||||
--help Give this help list\n\
|
||||
-V, --version Print program version");
|
||||
|
||||
fprintf (stdout, "\nSubmit bug reports to %s.\n", inetutils_bugaddr);
|
||||
|
||||
exit (0);
|
||||
#ifdef ENCRYPTION
|
||||
"[-x] [host-name [port]]"
|
||||
#else /* ENCRYPTION */
|
||||
"[host-name [port]]"
|
||||
#endif /* ENCRYPTION */
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Print a message saying to use --help to STDERR, and exit with a status of
|
||||
1. */
|
||||
static void
|
||||
try_help ()
|
||||
{
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", prompt);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* Print a usage message to STDERR and exit with a status of 1. */
|
||||
static void
|
||||
usage ()
|
||||
{
|
||||
fprintf (stderr, USAGE, prompt);
|
||||
try_help ();
|
||||
}
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{ "binary", no_argument, 0, '8' },
|
||||
{ "login", no_argument, 0, 'a' },
|
||||
{ "no-rc", no_argument, 0, 'c' },
|
||||
{ "debug", no_argument, 0, 'd' },
|
||||
{ "escape", required_argument, 0, 'e' },
|
||||
{ "no-escape", no_argument, 0, 'E' },
|
||||
{ "no-login", no_argument, 0, 'K' },
|
||||
{ "user", required_argument, 0, 'l' },
|
||||
{ "binary-output", no_argument, 0, 'L' },
|
||||
{ "trace", required_argument, 0, 'n' },
|
||||
{ "rlogin", no_argument, 0, 'r' },
|
||||
{ "tos", required_argument, 0, 'S' },
|
||||
{ "disable-auth", required_argument, 0, 'X' },
|
||||
{ "encrypt", no_argument, 0, 'x' },
|
||||
{ "fwd-credentials", no_argument, 0, 'f' },
|
||||
{ "realm", required_argument, 0, 'k' },
|
||||
{ "transcom", required_argument, 0, 't' },
|
||||
{ "help", no_argument, 0, '&' },
|
||||
{ "version", no_argument, 0, 'V' },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* main. Parse arguments, invoke the protocol or command parser.
|
||||
*/
|
||||
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
@@ -193,10 +117,7 @@ main(argc, argv)
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int ch;
|
||||
char *user;
|
||||
#ifndef strrchr
|
||||
char *strrchr();
|
||||
#endif
|
||||
char *user, *strrchr();
|
||||
#ifdef FORWARD
|
||||
extern int forward_flags;
|
||||
#endif /* FORWARD */
|
||||
@@ -218,10 +139,7 @@ main(argc, argv)
|
||||
rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
|
||||
autologin = -1;
|
||||
|
||||
while ((ch = getopt_long (argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x",
|
||||
long_options, 0))
|
||||
!= EOF)
|
||||
{
|
||||
while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != EOF) {
|
||||
switch(ch) {
|
||||
case '8':
|
||||
eight = 3; /* binary output and input */
|
||||
@@ -277,7 +195,7 @@ main(argc, argv)
|
||||
fprintf(stderr,
|
||||
"%s: Only one of -f and -F allowed.\n",
|
||||
prompt);
|
||||
help (0);
|
||||
usage();
|
||||
}
|
||||
forward_flags |= OPTS_FORWARD_CREDS;
|
||||
#else
|
||||
@@ -292,7 +210,7 @@ main(argc, argv)
|
||||
fprintf(stderr,
|
||||
"%s: Only one of -f and -F allowed.\n",
|
||||
prompt);
|
||||
help (0);
|
||||
usage();
|
||||
}
|
||||
forward_flags |= OPTS_FORWARD_CREDS;
|
||||
forward_flags |= OPTS_FORWARDABLE_CREDS;
|
||||
@@ -358,19 +276,9 @@ main(argc, argv)
|
||||
prompt);
|
||||
#endif /* ENCRYPTION */
|
||||
break;
|
||||
|
||||
case '&':
|
||||
help ();
|
||||
case 'V':
|
||||
printf ("telnet (%s) %s\n",
|
||||
inetutils_package, inetutils_version);
|
||||
exit (0);
|
||||
|
||||
case '?':
|
||||
try_help ();
|
||||
|
||||
default:
|
||||
usage ();
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
@@ -384,7 +292,7 @@ main(argc, argv)
|
||||
char *args[7], **argp = args;
|
||||
|
||||
if (argc > 2)
|
||||
usage ();
|
||||
usage();
|
||||
*argp++ = prompt;
|
||||
if (user) {
|
||||
*argp++ = "-l";
|
||||
|
||||
@@ -35,29 +35,13 @@
|
||||
static char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/telnet.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "ring.h"
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)ring.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -46,10 +46,6 @@ static char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -299,7 +295,7 @@ ring_supply_data(ring, buffer, count)
|
||||
|
||||
while (count) {
|
||||
i = MIN(count, ring_empty_consecutive(ring));
|
||||
memmove(ring->supply, buffer, i);
|
||||
memcpy(ring->supply, buffer, i);
|
||||
ring_supplied(ring, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
@@ -321,7 +317,7 @@ ring_consume_data(ring, buffer, count)
|
||||
|
||||
while (count) {
|
||||
i = MIN(count, ring_full_consecutive(ring));
|
||||
memmove(buffer, ring->consume, i);
|
||||
memcpy(buffer, ring->consume, i);
|
||||
ring_consumed(ring, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
|
||||
115
telnet/sys_bsd.c
115
telnet/sys_bsd.c
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)sys_bsd.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@@ -40,29 +40,14 @@ static char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
|
||||
* (at least between 4.x and dos) which is used in telnet.c.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <arpa/telnet.h>
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "ring.h"
|
||||
|
||||
@@ -72,8 +57,14 @@ static char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
|
||||
#include "externs.h"
|
||||
#include "types.h"
|
||||
|
||||
#if defined(CRAY) || (defined(USE_TERMIO) && !defined(SYSV_TERMIO))
|
||||
#define SIG_FUNC_RET void
|
||||
#else
|
||||
#define SIG_FUNC_RET int
|
||||
#endif
|
||||
|
||||
#ifdef SIGINFO
|
||||
extern RETSIGTYPE ayt_status();
|
||||
extern SIG_FUNC_RET ayt_status();
|
||||
#endif
|
||||
|
||||
int
|
||||
@@ -337,7 +328,7 @@ TerminalDefaultChars()
|
||||
nttyb.sg_kill = ottyb.sg_kill;
|
||||
nttyb.sg_erase = ottyb.sg_erase;
|
||||
#else /* USE_TERMIO */
|
||||
memmove(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc));
|
||||
memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc));
|
||||
# ifndef VDISCARD
|
||||
termFlushChar = CONTROL('O');
|
||||
# endif
|
||||
@@ -620,10 +611,10 @@ TerminalNewMode(f)
|
||||
|
||||
if (f != -1) {
|
||||
#ifdef SIGTSTP
|
||||
RETSIGTYPE susp();
|
||||
SIG_FUNC_RET susp();
|
||||
#endif /* SIGTSTP */
|
||||
#ifdef SIGINFO
|
||||
RETSIGTYPE ayt();
|
||||
SIG_FUNC_RET ayt();
|
||||
#endif
|
||||
|
||||
#ifdef SIGTSTP
|
||||
@@ -672,22 +663,13 @@ TerminalNewMode(f)
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SIGINFO
|
||||
RETSIGTYPE ayt_status();
|
||||
SIG_FUNC_RET ayt_status();
|
||||
|
||||
(void) signal(SIGINFO, ayt_status);
|
||||
#endif
|
||||
#ifdef SIGTSTP
|
||||
(void) signal(SIGTSTP, SIG_DFL);
|
||||
# ifdef HAVE_SIGACTION
|
||||
{
|
||||
sigset_t sigs;
|
||||
sigemptyset(&sigs);
|
||||
sigaddset(&sigs, SIGTSTP);
|
||||
sigprocmask(SIG_UNBLOCK, &sigs, 0);
|
||||
}
|
||||
# else
|
||||
(void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1)));
|
||||
# endif /* HAVE_SIGACTION */
|
||||
#endif /* SIGTSTP */
|
||||
#ifndef USE_TERMIO
|
||||
ltc = oltc;
|
||||
@@ -722,51 +704,14 @@ TerminalNewMode(f)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
|
||||
*/
|
||||
#if B4800 != 4800
|
||||
#define DECODE_BAUD
|
||||
#endif
|
||||
|
||||
#ifdef DECODE_BAUD
|
||||
#ifndef B7200
|
||||
#define B7200 B4800
|
||||
#endif
|
||||
|
||||
#ifndef B14400
|
||||
#define B14400 B9600
|
||||
#endif
|
||||
|
||||
#ifndef B19200
|
||||
# define B19200 B14400
|
||||
#endif
|
||||
|
||||
#ifndef B28800
|
||||
#define B28800 B19200
|
||||
# define B19200 B9600
|
||||
#endif
|
||||
|
||||
#ifndef B38400
|
||||
# define B38400 B28800
|
||||
# define B38400 B19200
|
||||
#endif
|
||||
|
||||
#ifndef B57600
|
||||
#define B57600 B38400
|
||||
#endif
|
||||
|
||||
#ifndef B76800
|
||||
#define B76800 B57600
|
||||
#endif
|
||||
|
||||
#ifndef B115200
|
||||
#define B115200 B76800
|
||||
#endif
|
||||
|
||||
#ifndef B230400
|
||||
#define B230400 B115200
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This code assumes that the values B0, B50, B75...
|
||||
* are in ascending order. They do not have to be
|
||||
@@ -780,21 +725,16 @@ struct termspeeds {
|
||||
{ 110, B110 }, { 134, B134 }, { 150, B150 },
|
||||
{ 200, B200 }, { 300, B300 }, { 600, B600 },
|
||||
{ 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
|
||||
{ 4800, B4800 }, { 7200, B7200 }, { 9600, B9600 },
|
||||
{ 14400, B14400 }, { 19200, B19200 }, { 28800, B28800 },
|
||||
{ 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 },
|
||||
{ 230400, B230400 }, { -1, B230400 }
|
||||
{ 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 },
|
||||
{ 38400, B38400 }, { -1, B38400 }
|
||||
};
|
||||
#endif /* DECODE_BAUD */
|
||||
|
||||
void
|
||||
TerminalSpeeds(ispeed, ospeed)
|
||||
long *ispeed;
|
||||
long *ospeed;
|
||||
{
|
||||
#ifdef DECODE_BAUD
|
||||
register struct termspeeds *tp;
|
||||
#endif /* DECODE_BAUD */
|
||||
register long in, out;
|
||||
|
||||
out = cfgetospeed(&old_tc);
|
||||
@@ -802,7 +742,6 @@ TerminalSpeeds(ispeed, ospeed)
|
||||
if (in == 0)
|
||||
in = out;
|
||||
|
||||
#ifdef DECODE_BAUD
|
||||
tp = termspeeds;
|
||||
while ((tp->speed != -1) && (tp->value < in))
|
||||
tp++;
|
||||
@@ -812,10 +751,6 @@ TerminalSpeeds(ispeed, ospeed)
|
||||
while ((tp->speed != -1) && (tp->value < out))
|
||||
tp++;
|
||||
*ospeed = tp->speed;
|
||||
#else /* DECODE_BAUD */
|
||||
*ispeed = in;
|
||||
*ospeed = out;
|
||||
#endif /* DECODE_BAUD */
|
||||
}
|
||||
|
||||
int
|
||||
@@ -875,7 +810,7 @@ NetSetPgrp(fd)
|
||||
*/
|
||||
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
deadpeer(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -884,7 +819,7 @@ deadpeer(sig)
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
intr(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -897,7 +832,7 @@ intr(sig)
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
intr2(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -914,7 +849,7 @@ intr2(sig)
|
||||
|
||||
#ifdef SIGTSTP
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
susp(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -927,7 +862,7 @@ susp(sig)
|
||||
|
||||
#ifdef SIGWINCH
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
sendwin(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -939,7 +874,7 @@ sendwin(sig)
|
||||
|
||||
#ifdef SIGINFO
|
||||
/* ARGSUSED */
|
||||
RETSIGTYPE
|
||||
SIG_FUNC_RET
|
||||
ayt(sig)
|
||||
int sig;
|
||||
{
|
||||
@@ -1150,7 +1085,7 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
|
||||
int i;
|
||||
i = recv(net, netiring.supply + c, canread - c, MSG_OOB);
|
||||
if (i == c &&
|
||||
memcmp(netiring.supply, netiring.supply + c, i) == 0) {
|
||||
bcmp(netiring.supply, netiring.supply + c, i) == 0) {
|
||||
bogus_oob = 1;
|
||||
first = 0;
|
||||
} else if (i < 0) {
|
||||
@@ -1199,8 +1134,6 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
|
||||
if (FD_ISSET(tin, &ibits)) {
|
||||
FD_CLR(tin, &ibits);
|
||||
c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring));
|
||||
if (c < 0 && errno == EIO)
|
||||
c = 0;
|
||||
if (c < 0 && errno == EWOULDBLOCK) {
|
||||
c = 0;
|
||||
} else {
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)telnet.1 8.6 (Berkeley) 6/1/94
|
||||
.\" @(#)telnet.1 8.5 (Berkeley) 3/1/94
|
||||
.\"
|
||||
.Dd June 1, 1994
|
||||
.Dd March 1, 1994
|
||||
.Dt TELNET 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -139,7 +139,6 @@ there will be no escape character.
|
||||
If Kerberos V5 authentication is being used, the
|
||||
.Fl f
|
||||
option allows the local credentials to be forwarded to the remote system.
|
||||
.ne 1i
|
||||
.It Fl k Ar realm
|
||||
If Kerberos authentication is being used, the
|
||||
.Fl k
|
||||
@@ -509,7 +508,6 @@ option.
|
||||
This requires that the
|
||||
.Dv LINEMODE
|
||||
option be enabled.
|
||||
.ne 1i
|
||||
.It Ic litecho Pq Ic \-litecho
|
||||
Attempt to enable (disable) the
|
||||
.Dv LIT_ECHO
|
||||
@@ -643,7 +641,6 @@ command,
|
||||
.Ic getstatus
|
||||
will send the subnegotiation to request that the server send
|
||||
its current option status.
|
||||
.ne 1i
|
||||
.It Ic ip
|
||||
Sends the
|
||||
.Dv TELNET IP
|
||||
@@ -969,7 +966,6 @@ The initial value for the suspend character is taken to be
|
||||
the terminal's
|
||||
.Ic suspend
|
||||
character.
|
||||
.ne 1i
|
||||
.It Ic tracefile
|
||||
This is the file to which the output, caused by
|
||||
.Ic netdata
|
||||
@@ -1112,7 +1108,6 @@ stream does not start automatically. The autoencrypt
|
||||
(autodecrypt) command states that encryption of the
|
||||
output (input) stream should be enabled as soon as
|
||||
possible.
|
||||
.sp
|
||||
.Pp
|
||||
Note: Because of export controls, the
|
||||
.Dv TELNET ENCRYPT
|
||||
@@ -1268,7 +1263,6 @@ protocol processing (having to do with
|
||||
options).
|
||||
The initial value for this toggle is
|
||||
.Dv FALSE .
|
||||
.ne 1i
|
||||
.It Ic prettydump
|
||||
When the
|
||||
.Ic netdata
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)telnet.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(unix)
|
||||
@@ -52,9 +48,6 @@ static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
|
||||
#include <arpa/telnet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "ring.h"
|
||||
|
||||
@@ -64,7 +57,7 @@ static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
|
||||
#include "general.h"
|
||||
|
||||
|
||||
#define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
|
||||
#define strip(x) ((x)&0x7f)
|
||||
|
||||
static unsigned char subbuffer[SUBBUFSIZE],
|
||||
*subpointer, *subend; /* buffer for sub-options */
|
||||
@@ -630,7 +623,7 @@ mklist(buf, name)
|
||||
register char c, *cp, **argvp, *cp2, **argv, **avt;
|
||||
|
||||
if (name) {
|
||||
if ((int)strlen(name) > 40) {
|
||||
if (strlen(name) > 40) {
|
||||
name = 0;
|
||||
unknown[0] = name_unknown;
|
||||
} else {
|
||||
@@ -752,7 +745,7 @@ char termbuf[1024];
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
init_term (tname, fd, errp)
|
||||
setupterm(tname, fd, errp)
|
||||
char *tname;
|
||||
int fd, *errp;
|
||||
{
|
||||
@@ -786,10 +779,10 @@ gettermname()
|
||||
if (tnamep && tnamep != unknown)
|
||||
free(tnamep);
|
||||
if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) &&
|
||||
(init_term (tname, 1, &err) == 0)) {
|
||||
(setupterm(tname, 1, &err) == 0)) {
|
||||
tnamep = mklist(termbuf, tname);
|
||||
} else {
|
||||
if (tname && ((int)strlen(tname) <= 40)) {
|
||||
if (tname && (strlen(tname) <= 40)) {
|
||||
unknown[0] = tname;
|
||||
upcase(tname);
|
||||
} else
|
||||
@@ -2258,12 +2251,12 @@ telnet(user)
|
||||
|
||||
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
|
||||
{
|
||||
extern char *localhost ();
|
||||
static char *local_host = 0;
|
||||
|
||||
if (!local_host)
|
||||
local_host = localhost ();
|
||||
static char local_host[256] = { 0 };
|
||||
|
||||
if (!local_host[0]) {
|
||||
gethostname(local_host, sizeof(local_host));
|
||||
local_host[sizeof(local_host)-1] = 0;
|
||||
}
|
||||
auth_encrypt_init(local_host, hostname, "TELNET", 0);
|
||||
auth_encrypt_user(user);
|
||||
}
|
||||
@@ -2438,7 +2431,7 @@ netclear()
|
||||
next = nextitem(next);
|
||||
} while (wewant(next) && (nfrontp > next));
|
||||
length = next-thisitem;
|
||||
memmove(good, thisitem, length);
|
||||
memcpy(good, thisitem, length);
|
||||
good += length;
|
||||
thisitem = next;
|
||||
} else {
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
|
||||
static char sccsid[] = "@(#)terminal.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <arpa/telnet.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -144,7 +140,6 @@ ttyflush(drop)
|
||||
n1 = n0 - n;
|
||||
if (!drop)
|
||||
n1 = TerminalWrite(ttyoring.bottom, n1);
|
||||
if (n1 > 0)
|
||||
n += n1;
|
||||
}
|
||||
ring_consumed(&ttyoring, n);
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)tn3270.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <arpa/telnet.h>
|
||||
|
||||
@@ -246,7 +242,7 @@ Push3270()
|
||||
if (save) {
|
||||
if (Ifrontp+save > Ibuf+sizeof Ibuf) {
|
||||
if (Ibackp != Ibuf) {
|
||||
memmove(Ibuf, Ibackp, Ifrontp-Ibackp);
|
||||
memcpy(Ibuf, Ibackp, Ifrontp-Ibackp);
|
||||
Ifrontp -= (Ibackp-Ibuf);
|
||||
Ibackp = Ibuf;
|
||||
}
|
||||
|
||||
@@ -32,28 +32,15 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)utilities.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define TELOPTS
|
||||
#define TELCMDS
|
||||
#define SLC_NAMES
|
||||
#include <arpa/telnet.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
|
||||
#include "telnetd.h"
|
||||
#include <libtelnet/misc.h>
|
||||
@@ -49,7 +45,7 @@ net_write(str, len)
|
||||
int len;
|
||||
{
|
||||
if (nfrontp + len < netobuf + BUFSIZ) {
|
||||
memmove((void *)nfrontp, (void *)str, len);
|
||||
bcopy((void *)str, (void *)nfrontp, len);
|
||||
nfrontp += len;
|
||||
return(len);
|
||||
}
|
||||
|
||||
@@ -43,15 +43,6 @@
|
||||
# define BSD 43
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#define USE_TERMIO
|
||||
#else /* !HAVE_TERMIOS_H */
|
||||
#ifdef HAVE_TERMIO_H
|
||||
#define USE_TERMIO
|
||||
#define SYSV_TERMIO
|
||||
#endif
|
||||
#endif /* HAVE_TERMIOS_H */
|
||||
|
||||
#if defined(CRAY) && !defined(LINEMODE)
|
||||
# define SYSV_TERMIO
|
||||
# define LINEMODE
|
||||
@@ -86,37 +77,19 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#ifndef FILIO_H
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#else
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STREAM_H
|
||||
#include <sys/stream.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TTY_H
|
||||
#include <sys/tty.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PTYVAR_H
|
||||
#include <sys/ptyvar.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#undef SE
|
||||
#include <arpa/telnet.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
@@ -149,7 +122,7 @@
|
||||
typedef unsigned char cc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#ifdef __STDC__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
@@ -161,6 +134,7 @@ typedef unsigned char cc_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CRAY
|
||||
# ifdef CRAY1
|
||||
# include <sys/pty.h>
|
||||
|
||||
@@ -66,7 +66,7 @@ extern int auth_level;
|
||||
|
||||
extern slcfun slctab[NSLC + 1]; /* slc mapping table */
|
||||
|
||||
extern char *terminaltype;
|
||||
char *terminaltype;
|
||||
|
||||
/*
|
||||
* I/O data buffers, pointers, and counters.
|
||||
@@ -86,6 +86,7 @@ extern char *unptyip; /* pointer to remaining characters in buffer */
|
||||
#endif
|
||||
|
||||
extern int pty, net;
|
||||
extern char *line;
|
||||
extern int SYNCHing; /* we are in TELNET SYNCH mode */
|
||||
|
||||
#ifndef P
|
||||
@@ -223,29 +224,17 @@ extern int needtermstat;
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_IM
|
||||
# ifdef HAVE_UNAME
|
||||
/* Prefix and suffix if the IM string can be generated from uname. */
|
||||
# define UNAME_IM_PREFIX "\r\n"
|
||||
# define UNAME_IM_SUFFIX " (%h) (%t)\r\n\n"
|
||||
# else /* ! HAVE_UNAME */
|
||||
# ifdef CRAY
|
||||
# define DEFAULT_IM "\r\n\r\nCray UNICOS (%h) (%t)\r\n\r\r\n\r"
|
||||
# ifdef CRAY
|
||||
# define DEFAULT_IM "\r\n\r\nCray UNICOS (%h) (%t)\r\n\r\r\n\r"
|
||||
# else
|
||||
# ifdef sun
|
||||
# define DEFAULT_IM "\r\n\r\nSunOS UNIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# else
|
||||
# ifdef sun
|
||||
# define DEFAULT_IM "\r\n\r\nSunOS UNIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# ifdef ultrix
|
||||
# define DEFAULT_IM "\r\n\r\nULTRIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# else
|
||||
# ifdef ultrix
|
||||
# define DEFAULT_IM "\r\n\r\nULTRIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# else
|
||||
# define DEFAULT_IM "\r\n\r\n4.4 BSD UNIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# endif
|
||||
# define DEFAULT_IM "\r\n\r\n4.4 BSD UNIX (%h) (%t)\r\n\r\r\n\r"
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef extern
|
||||
#undef extern
|
||||
#endif
|
||||
/* Let "line" get its definition from sys_term.c. */
|
||||
extern char *line;
|
||||
|
||||
@@ -43,10 +43,6 @@ static char sccsid[] = "@(#)global.c 8.1 (Berkeley) 6/4/93";
|
||||
* we will actually allocate the space.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "defs.h"
|
||||
#define extern
|
||||
#include "ext.h"
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)slc.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "telnetd.h"
|
||||
|
||||
#ifdef LINEMODE
|
||||
@@ -376,6 +372,7 @@ change_slc(func, flag, val)
|
||||
slctab[func].defset.val;
|
||||
val = slctab[func].current.val;
|
||||
}
|
||||
|
||||
}
|
||||
add_slc(func, flag, val);
|
||||
}
|
||||
@@ -426,6 +423,7 @@ check_slc()
|
||||
slctab[i].current.val);
|
||||
}
|
||||
}
|
||||
|
||||
} /* check_slc */
|
||||
|
||||
/*
|
||||
@@ -467,7 +465,7 @@ do_opt_slc(ptr, len)
|
||||
def_slcbuf = (unsigned char *)malloc((unsigned)len);
|
||||
if (def_slcbuf == (unsigned char *)0)
|
||||
return; /* too bad */
|
||||
memmove(def_slcbuf, ptr, len);
|
||||
bcopy(ptr, def_slcbuf, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)state.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "telnetd.h"
|
||||
#if defined(AUTHENTICATION)
|
||||
#include <libtelnet/auth.h>
|
||||
@@ -370,7 +366,7 @@ gotiac: switch (c) {
|
||||
char xbuf2[BUFSIZ];
|
||||
register char *cp;
|
||||
int n = pfrontp - opfrontp, oc;
|
||||
memmove(xptyobuf, opfrontp, n);
|
||||
bcopy(opfrontp, xptyobuf, n);
|
||||
pfrontp = opfrontp;
|
||||
pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP,
|
||||
xbuf2, &oc, BUFSIZ);
|
||||
@@ -720,6 +716,7 @@ wontoption(option)
|
||||
*/
|
||||
if (lmodetype != REAL_LINEMODE)
|
||||
break;
|
||||
lmodetype = KLUDGE_LINEMODE;
|
||||
# endif /* KLUDGELINEMODE */
|
||||
clientstat(TELOPT_LINEMODE, WONT, 0);
|
||||
break;
|
||||
@@ -1523,8 +1520,8 @@ doclientstat()
|
||||
clientstat(TELOPT_LINEMODE, WILL, 0);
|
||||
}
|
||||
|
||||
#define ADD(c) *ncp++ = c
|
||||
#define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; }
|
||||
#define ADD(c) *ncp++ = c;
|
||||
#define ADD_DATA(c) { *ncp++ = c; if (c == SE) *ncp++ = c; }
|
||||
void
|
||||
send_status()
|
||||
{
|
||||
@@ -1553,10 +1550,14 @@ send_status()
|
||||
if (my_want_state_is_will(i)) {
|
||||
ADD(WILL);
|
||||
ADD_DATA(i);
|
||||
if (i == IAC)
|
||||
ADD(IAC);
|
||||
}
|
||||
if (his_want_state_is_will(i)) {
|
||||
ADD(DO);
|
||||
ADD_DATA(i);
|
||||
if (i == IAC)
|
||||
ADD(IAC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1571,14 +1572,15 @@ send_status()
|
||||
ADD(SE);
|
||||
|
||||
if (restartany >= 0) {
|
||||
ADD(SB);
|
||||
ADD(SB)
|
||||
ADD(TELOPT_LFLOW);
|
||||
if (restartany) {
|
||||
ADD(LFLOW_RESTART_ANY);
|
||||
} else {
|
||||
ADD(LFLOW_RESTART_XON);
|
||||
}
|
||||
ADD(SE);
|
||||
ADD(SE)
|
||||
ADD(SB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1591,6 +1593,8 @@ send_status()
|
||||
ADD(TELOPT_LINEMODE);
|
||||
ADD(LM_MODE);
|
||||
ADD_DATA(editmode);
|
||||
if (editmode == IAC)
|
||||
ADD(IAC);
|
||||
ADD(SE);
|
||||
|
||||
ADD(SB);
|
||||
|
||||
@@ -32,14 +32,11 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)sys_term.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)sys_term.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "telnetd.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
#if defined(AUTHENTICATION)
|
||||
#include <libtelnet/auth.h>
|
||||
@@ -50,49 +47,44 @@ static char sccsid[] = "@(#)sys_term.c 8.4 (Berkeley) 5/30/95";
|
||||
#endif
|
||||
|
||||
#ifdef NEWINIT
|
||||
|
||||
#include <initreq.h>
|
||||
int utmp_len = MAXHOSTNAMELEN; /* sizeof(init_request.host) */
|
||||
#else /* !NEWINIT*/
|
||||
# ifdef HAVE_UTMPX_H
|
||||
# include <utmpx.h>
|
||||
#else /* NEWINIT*/
|
||||
# ifdef UTMPX
|
||||
# include <utmpx.h>
|
||||
struct utmpx wtmp;
|
||||
# ifdef HAVE_UTMPX_UT_TV
|
||||
# define HAVE_WTMP_UT_TV HAVE_UTMPX_UT_TV
|
||||
# endif
|
||||
# else /* !HAVE_UTMPX_H */
|
||||
# include <utmp.h>
|
||||
# else
|
||||
# include <utmp.h>
|
||||
struct utmp wtmp;
|
||||
# ifdef HAVE_UTMP_UT_TV
|
||||
# define HAVE_WTMP_UT_TV HAVE_UTMP_UT_TV
|
||||
# endif
|
||||
# endif /* HAVE_UTMPX_H */
|
||||
# endif /* UTMPX */
|
||||
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
int utmp_len = sizeof(wtmp.ut_host);
|
||||
#endif
|
||||
# ifndef PARENT_DOES_UTMP
|
||||
char wtmpf[] = PATH_WTMP;
|
||||
char utmpf[] = PATH_UTMP;
|
||||
char wtmpf[] = "/usr/adm/wtmp";
|
||||
char utmpf[] = "/etc/utmp";
|
||||
# else /* PARENT_DOES_UTMP */
|
||||
char wtmpf[] = PATH_WTMP;
|
||||
char wtmpf[] = "/etc/wtmp";
|
||||
# endif /* PARENT_DOES_UTMP */
|
||||
|
||||
# ifdef CRAY
|
||||
# include <tmpdir.h>
|
||||
# include <sys/wait.h>
|
||||
# if (UNICOS_LVL == '7.0') || (UNICOS_LVL == '7.1')
|
||||
# define UNICOS7x
|
||||
#include <tmpdir.h>
|
||||
#include <sys/wait.h>
|
||||
# if defined(_SC_CRAY_SECURE_SYS) && !defined(SCM_SECURITY)
|
||||
/*
|
||||
* UNICOS 6.0/6.1 do not have SCM_SECURITY defined, so we can
|
||||
* use it to tell us to turn off all the socket security code,
|
||||
* since that is only used in UNICOS 7.0 and later.
|
||||
*/
|
||||
# undef _SC_CRAY_SECURE_SYS
|
||||
# endif
|
||||
|
||||
# ifdef UNICOS7x
|
||||
# include <sys/sysv.h>
|
||||
# include <sys/secstat.h>
|
||||
# if defined(_SC_CRAY_SECURE_SYS)
|
||||
#include <sys/sysv.h>
|
||||
#include <sys/secstat.h>
|
||||
extern int secflag;
|
||||
extern struct sysv sysv;
|
||||
# endif /* UNICOS7x */
|
||||
# endif /* _SC_CRAY_SECURE_SYS */
|
||||
# endif /* CRAY */
|
||||
|
||||
#endif /* NEWINIT */
|
||||
|
||||
#ifdef STREAMSPTY
|
||||
@@ -103,13 +95,30 @@ extern struct sysv sysv;
|
||||
#define SCPYN(a, b) (void) strncpy(a, b, sizeof(a))
|
||||
#define SCMPN(a, b) strncmp(a, b, sizeof(a))
|
||||
|
||||
#ifdef HAVE_SYS_STREAM_H
|
||||
#ifdef STREAMS
|
||||
#include <sys/stream.h>
|
||||
#endif
|
||||
#ifdef __hpux
|
||||
#include <sys/resource.h>
|
||||
#include <sys/proc.h>
|
||||
#endif
|
||||
#include <sys/tty.h>
|
||||
#ifdef t_erase
|
||||
#undef t_erase
|
||||
#undef t_kill
|
||||
#undef t_intrc
|
||||
#undef t_quitc
|
||||
#undef t_startc
|
||||
#undef t_stopc
|
||||
#undef t_eofc
|
||||
#undef t_brkc
|
||||
#undef t_suspc
|
||||
#undef t_dsuspc
|
||||
#undef t_rprntc
|
||||
#undef t_flushc
|
||||
#undef t_werasc
|
||||
#undef t_lnextc
|
||||
#endif
|
||||
|
||||
#if defined(UNICOS5) && defined(CRAY2) && !defined(EXTPROC)
|
||||
# define EXTPROC 0400
|
||||
@@ -206,7 +215,7 @@ copy_termbuf(cp, len)
|
||||
{
|
||||
if (len > sizeof(termbuf))
|
||||
len = sizeof(termbuf);
|
||||
memmove((char *)&termbuf, cp, len);
|
||||
bcopy(cp, (char *)&termbuf, len);
|
||||
termbuf2 = termbuf;
|
||||
}
|
||||
#endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
|
||||
@@ -218,19 +227,17 @@ set_termbuf()
|
||||
* Only make the necessary changes.
|
||||
*/
|
||||
#ifndef USE_TERMIO
|
||||
if (memcmp((char *)&termbuf.sg, (char *)&termbuf2.sg,
|
||||
sizeof(termbuf.sg)))
|
||||
if (bcmp((char *)&termbuf.sg, (char *)&termbuf2.sg, sizeof(termbuf.sg)))
|
||||
(void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg);
|
||||
if (memcmp((char *)&termbuf.tc, (char *)&termbuf2.tc,
|
||||
sizeof(termbuf.tc)))
|
||||
if (bcmp((char *)&termbuf.tc, (char *)&termbuf2.tc, sizeof(termbuf.tc)))
|
||||
(void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc);
|
||||
if (memcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
|
||||
if (bcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
|
||||
sizeof(termbuf.ltc)))
|
||||
(void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc);
|
||||
if (termbuf.lflags != termbuf2.lflags)
|
||||
(void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags);
|
||||
#else /* USE_TERMIO */
|
||||
if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
|
||||
if (bcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
|
||||
# ifdef STREAMSPTY
|
||||
(void) tcsetattr(ttyfd, TCSANOW, &termbuf);
|
||||
# else
|
||||
@@ -474,7 +481,7 @@ int *ptynum;
|
||||
int t;
|
||||
char *ptsname();
|
||||
|
||||
p = open("/dev/ptmx", O_RDWR);
|
||||
p = open("/dev/ptmx", 2);
|
||||
if (p > 0) {
|
||||
grantpt(p);
|
||||
unlockpt(p);
|
||||
@@ -514,7 +521,7 @@ int *ptynum;
|
||||
break;
|
||||
for (i = 0; i < 16; i++) {
|
||||
*p2 = "0123456789abcdef"[i];
|
||||
p = open(line, O_RDWR);
|
||||
p = open(line, 2);
|
||||
if (p > 0) {
|
||||
#ifndef __hpux
|
||||
line[5] = 't';
|
||||
@@ -543,7 +550,7 @@ int *ptynum;
|
||||
|
||||
for (*ptynum = lowpty; *ptynum <= highpty; (*ptynum)++) {
|
||||
(void) sprintf(myline, "/dev/pty/%03d", *ptynum);
|
||||
p = open(myline, O_RDWR);
|
||||
p = open(myline, 2);
|
||||
if (p < 0)
|
||||
continue;
|
||||
(void) sprintf(line, "/dev/ttyp%03d", *ptynum);
|
||||
@@ -559,7 +566,7 @@ int *ptynum;
|
||||
chown(line, 0, 0);
|
||||
chmod(line, 0600);
|
||||
(void)close(p);
|
||||
p = open(myline, O_RDWR);
|
||||
p = open(myline, 2);
|
||||
if (p < 0)
|
||||
continue;
|
||||
}
|
||||
@@ -609,18 +616,14 @@ static int linestate;
|
||||
tty_linemode()
|
||||
{
|
||||
#ifndef convex
|
||||
#ifdef USE_TERMIO
|
||||
#ifdef EXTPROC
|
||||
return(termbuf.c_lflag & EXTPROC);
|
||||
#else
|
||||
return 0; /* Can't ever set it either. */
|
||||
#endif /* EXTPROC */
|
||||
#else /* !USE_TERMIO */
|
||||
#ifndef USE_TERMIO
|
||||
return(termbuf.state & TS_EXTPROC);
|
||||
#endif /* USE_TERMIO */
|
||||
#else /* convex */
|
||||
#else
|
||||
return(termbuf.c_lflag & EXTPROC);
|
||||
#endif
|
||||
#else
|
||||
return(linestate);
|
||||
#endif /* !convex */
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -939,15 +942,6 @@ tty_iscrnl()
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
|
||||
*/
|
||||
#if B4800 != 4800
|
||||
#define DECODE_BAUD
|
||||
#endif
|
||||
|
||||
#ifdef DECODE_BAUD
|
||||
|
||||
/*
|
||||
* A table of available terminal speeds
|
||||
*/
|
||||
@@ -959,68 +953,30 @@ struct termspeeds {
|
||||
{ 110, B110 }, { 134, B134 }, { 150, B150 },
|
||||
{ 200, B200 }, { 300, B300 }, { 600, B600 },
|
||||
{ 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
|
||||
{ 4800, B4800 },
|
||||
#ifdef B7200
|
||||
{ 7200, B7200 },
|
||||
#endif
|
||||
{ 9600, B9600 },
|
||||
#ifdef B14400
|
||||
{ 14400, B14400 },
|
||||
#endif
|
||||
#ifdef B19200
|
||||
{ 19200, B19200 },
|
||||
#endif
|
||||
#ifdef B28800
|
||||
{ 28800, B28800 },
|
||||
#endif
|
||||
#ifdef B38400
|
||||
{ 38400, B38400 },
|
||||
#endif
|
||||
#ifdef B57600
|
||||
{ 57600, B57600 },
|
||||
#endif
|
||||
#ifdef B115200
|
||||
{ 115200, B115200 },
|
||||
#endif
|
||||
#ifdef B230400
|
||||
{ 230400, B230400 },
|
||||
#endif
|
||||
{ -1, 0 }
|
||||
{ 4800, B4800 }, { 9600, B9600 }, { 19200, B9600 },
|
||||
{ 38400, B9600 }, { -1, B9600 }
|
||||
};
|
||||
#endif /* DECODE_BUAD */
|
||||
|
||||
void
|
||||
tty_tspeed(val)
|
||||
int val;
|
||||
{
|
||||
#ifdef DECODE_BAUD
|
||||
register struct termspeeds *tp;
|
||||
|
||||
for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
|
||||
;
|
||||
if (tp->speed == -1) /* back up to last valid value */
|
||||
--tp;
|
||||
cfsetospeed(&termbuf, tp->value);
|
||||
#else /* DECODE_BUAD */
|
||||
cfsetospeed(&termbuf, val);
|
||||
#endif /* DECODE_BUAD */
|
||||
}
|
||||
|
||||
void
|
||||
tty_rspeed(val)
|
||||
int val;
|
||||
{
|
||||
#ifdef DECODE_BAUD
|
||||
register struct termspeeds *tp;
|
||||
|
||||
for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
|
||||
;
|
||||
if (tp->speed == -1) /* back up to last valid value */
|
||||
--tp;
|
||||
cfsetispeed(&termbuf, tp->value);
|
||||
#else /* DECODE_BAUD */
|
||||
cfsetispeed(&termbuf, val);
|
||||
#endif /* DECODE_BAUD */
|
||||
}
|
||||
|
||||
#if defined(CRAY2) && defined(UNICOS5)
|
||||
@@ -1097,7 +1053,7 @@ getptyslave()
|
||||
* that we are the session (process group) leader.
|
||||
*/
|
||||
# ifdef TIOCNOTTY
|
||||
t = open(PATH_TTY, O_RDWR);
|
||||
t = open(_PATH_TTY, O_RDWR);
|
||||
if (t >= 0) {
|
||||
(void) ioctl(t, TIOCNOTTY, (char *)0);
|
||||
(void) close(t);
|
||||
@@ -1136,7 +1092,7 @@ getptyslave()
|
||||
init_termbuf();
|
||||
# ifdef TIOCGWINSZ
|
||||
if (def_row || def_col) {
|
||||
memset((char *)&ws, 0, sizeof(ws));
|
||||
bzero((char *)&ws, sizeof(ws));
|
||||
ws.ws_col = def_col;
|
||||
ws.ws_row = def_row;
|
||||
(void)ioctl(t, TIOCSWINSZ, (char *)&ws);
|
||||
@@ -1216,9 +1172,9 @@ cleanopen(line)
|
||||
char *line;
|
||||
{
|
||||
register int t;
|
||||
#ifdef UNICOS7x
|
||||
#if defined(_SC_CRAY_SECURE_SYS)
|
||||
struct secstat secbuf;
|
||||
#endif /* UNICOS7x */
|
||||
#endif /* _SC_CRAY_SECURE_SYS */
|
||||
|
||||
#ifndef STREAMSPTY
|
||||
/*
|
||||
@@ -1232,7 +1188,7 @@ cleanopen(line)
|
||||
# if !defined(CRAY) && (BSD > 43)
|
||||
(void) revoke(line);
|
||||
# endif
|
||||
#ifdef UNICOS7x
|
||||
#if defined(_SC_CRAY_SECURE_SYS)
|
||||
if (secflag) {
|
||||
if (secstat(line, &secbuf) < 0)
|
||||
return(-1);
|
||||
@@ -1241,18 +1197,18 @@ cleanopen(line)
|
||||
if (setucmp(secbuf.st_compart) < 0)
|
||||
return(-1);
|
||||
}
|
||||
#endif /* UNICOS7x */
|
||||
#endif /* _SC_CRAY_SECURE_SYS */
|
||||
|
||||
t = open(line, O_RDWR|O_NOCTTY);
|
||||
|
||||
#ifdef UNICOS7x
|
||||
#if defined(_SC_CRAY_SECURE_SYS)
|
||||
if (secflag) {
|
||||
if (setulvl(sysv.sy_minlvl) < 0)
|
||||
return(-1);
|
||||
if (setucmp(0) < 0)
|
||||
return(-1);
|
||||
}
|
||||
#endif /* UNICOS7x */
|
||||
#endif /* _SC_CRAY_SECURE_SYS */
|
||||
|
||||
if (t < 0)
|
||||
return(-1);
|
||||
@@ -1275,8 +1231,9 @@ cleanopen(line)
|
||||
(void) signal(SIGHUP, SIG_IGN);
|
||||
(void) ioctl(t, TCVHUP, (char *)0);
|
||||
(void) signal(SIGHUP, SIG_DFL);
|
||||
setpgrp();
|
||||
|
||||
#ifdef UNICOS7x
|
||||
#if defined(_SC_CRAY_SECURE_SYS)
|
||||
if (secflag) {
|
||||
if (secstat(line, &secbuf) < 0)
|
||||
return(-1);
|
||||
@@ -1285,18 +1242,18 @@ cleanopen(line)
|
||||
if (setucmp(secbuf.st_compart) < 0)
|
||||
return(-1);
|
||||
}
|
||||
#endif /* UNICOS7x */
|
||||
#endif /* _SC_CRAY_SECURE_SYS */
|
||||
|
||||
i = open(line, O_RDWR);
|
||||
|
||||
#ifdef UNICOS7x
|
||||
#if defined(_SC_CRAY_SECURE_SYS)
|
||||
if (secflag) {
|
||||
if (setulvl(sysv.sy_minlvl) < 0)
|
||||
return(-1);
|
||||
if (setucmp(0) < 0)
|
||||
return(-1);
|
||||
}
|
||||
#endif /* UNICOS7x */
|
||||
#endif /* _SC_CRAY_SECURE_SYS */
|
||||
|
||||
if (i < 0)
|
||||
return(-1);
|
||||
@@ -1345,8 +1302,7 @@ login_tty(t)
|
||||
* setsid() call above may have set our pgrp, so clear
|
||||
* it out before opening the tty...
|
||||
*/
|
||||
setpgid (0, 0);
|
||||
|
||||
(void) setpgrp(0, 0);
|
||||
close(open(line, O_RDWR));
|
||||
# endif
|
||||
if (t != 0)
|
||||
@@ -1380,6 +1336,7 @@ startslave(host, autologin, autoname)
|
||||
char *autoname;
|
||||
{
|
||||
register int i;
|
||||
long time();
|
||||
char name[256];
|
||||
#ifdef NEWINIT
|
||||
extern char *ptyip;
|
||||
@@ -1490,9 +1447,7 @@ startslave(host, autologin, autoname)
|
||||
if (i == 3 || n >= 0 || !gotalarm)
|
||||
break;
|
||||
gotalarm = 0;
|
||||
snprintf (tbuf, sizeof tbuf,
|
||||
"telnetd: waiting for /etc/init to start login process on %s\r\n",
|
||||
line);
|
||||
sprintf(tbuf, "telnetd: waiting for /etc/init to start login process on %s\r\n", line);
|
||||
(void) write(net, tbuf, strlen(tbuf));
|
||||
}
|
||||
if (n < 0 && gotalarm)
|
||||
@@ -1527,29 +1482,6 @@ init_env()
|
||||
|
||||
#ifndef NEWINIT
|
||||
|
||||
/* Security fix included in telnet-95.10.23.NE of David Borman <deb@cray.com>.
|
||||
*/
|
||||
/*
|
||||
* scrub_env()
|
||||
*
|
||||
* Remove a few things from the environment that
|
||||
* don't need to be there.
|
||||
*/
|
||||
static void
|
||||
scrub_env()
|
||||
{
|
||||
register char **cpp, **cpp2;
|
||||
|
||||
for (cpp2 = cpp = environ; *cpp; cpp++) {
|
||||
if (strncmp(*cpp, "LD_", 3) &&
|
||||
strncmp(*cpp, "_RLD_", 5) &&
|
||||
strncmp(*cpp, "LIBPATH=", 8) &&
|
||||
strncmp(*cpp, "IFS=", 4))
|
||||
*cpp2++ = *cpp;
|
||||
}
|
||||
*cpp2 = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* start_login(host)
|
||||
*
|
||||
@@ -1581,7 +1513,7 @@ start_login(host, autologin, name)
|
||||
* Create utmp entry for child
|
||||
*/
|
||||
|
||||
memset(&utmpx, 0, sizeof(utmpx));
|
||||
bzero(&utmpx, sizeof(utmpx));
|
||||
SCPYN(utmpx.ut_user, ".telnet");
|
||||
SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1);
|
||||
utmpx.ut_pid = pid;
|
||||
@@ -1591,12 +1523,10 @@ start_login(host, autologin, name)
|
||||
utmpx.ut_id[3] = SC_WILDC;
|
||||
utmpx.ut_type = LOGIN_PROCESS;
|
||||
(void) time(&utmpx.ut_tv.tv_sec);
|
||||
if (pututxline(&utmpx) == NULL)
|
||||
fatal(net, "pututxline failed");
|
||||
if (makeutx(&utmpx) == NULL)
|
||||
fatal(net, "makeutx failed");
|
||||
#endif
|
||||
|
||||
scrub_env();
|
||||
|
||||
/*
|
||||
* -h : pass on name of host.
|
||||
* WARNING: -h is accepted by login if and only if
|
||||
@@ -1638,19 +1568,6 @@ start_login(host, autologin, name)
|
||||
#if !defined(NO_LOGIN_P)
|
||||
argv = addarg(argv, "-p");
|
||||
#endif
|
||||
#ifdef LINEMODE
|
||||
/*
|
||||
* Set the environment variable "LINEMODE" to either
|
||||
* "real" or "kludge" if we are operating in either
|
||||
* real or kludge linemode.
|
||||
*/
|
||||
if (lmodetype == REAL_LINEMODE)
|
||||
setenv("LINEMODE", "real", 1);
|
||||
# ifdef KLUDGELINEMODE
|
||||
else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)
|
||||
setenv("LINEMODE", "kludge", 1);
|
||||
# endif
|
||||
#endif
|
||||
#ifdef BFTPDAEMON
|
||||
/*
|
||||
* Are we working as the bftp daemon? If so, then ask login
|
||||
@@ -1723,9 +1640,8 @@ start_login(host, autologin, name)
|
||||
len = strlen(name)+1;
|
||||
write(xpty, name, len);
|
||||
write(xpty, name, len);
|
||||
snprintf (speed, sizeof speed,
|
||||
"%s/%d", (cp = getenv("TERM")) ? cp : "",
|
||||
(def_rspeed > 0) ? def_rspeed : 9600);
|
||||
sprintf(speed, "%s/%d", (cp = getenv("TERM")) ? cp : "",
|
||||
(def_rspeed > 0) ? def_rspeed : 9600);
|
||||
len = strlen(speed)+1;
|
||||
write(xpty, speed, len);
|
||||
|
||||
@@ -1772,31 +1688,15 @@ start_login(host, autologin, name)
|
||||
*/
|
||||
unsetenv("USER");
|
||||
}
|
||||
#ifdef SOLARIS
|
||||
else {
|
||||
char **p;
|
||||
|
||||
argv = addarg(argv, ""); /* no login name */
|
||||
for (p = environ; *p; p++) {
|
||||
argv = addarg(argv, *p);
|
||||
}
|
||||
}
|
||||
#endif /* SOLARIS */
|
||||
#if defined(AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R)
|
||||
if (pty > 2)
|
||||
close(pty);
|
||||
#endif
|
||||
closelog();
|
||||
/*
|
||||
* This sleep(1) is in here so that telnetd can
|
||||
* finish up with the tty. There's a race condition
|
||||
* the login banner message gets lost...
|
||||
*/
|
||||
sleep(1);
|
||||
execv(PATH_LOGIN, argv);
|
||||
execv(_PATH_LOGIN, argv);
|
||||
|
||||
syslog(LOG_ERR, "%s: %m\n", PATH_LOGIN);
|
||||
fatalperror(net, PATH_LOGIN);
|
||||
syslog(LOG_ERR, "%s: %m\n", _PATH_LOGIN);
|
||||
fatalperror(net, _PATH_LOGIN);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
@@ -1822,7 +1722,7 @@ addarg(argv, val)
|
||||
if (cpp == &argv[(int)argv[-1]]) {
|
||||
--argv;
|
||||
*argv = (char *)((int)(*argv) + 10);
|
||||
argv = (char **)realloc(argv, sizeof(*argv)*((int)(*argv) + 2));
|
||||
argv = (char **)realloc(argv, (int)(*argv) + 2);
|
||||
if (argv == NULL)
|
||||
return(NULL);
|
||||
argv++;
|
||||
@@ -1875,8 +1775,6 @@ cleanup(sig)
|
||||
# ifdef CRAY
|
||||
static int incleanup = 0;
|
||||
register int t;
|
||||
int child_status; /* status of child process as returned by waitpid */
|
||||
int flags = WNOHANG|WUNTRACED;
|
||||
|
||||
/*
|
||||
* 1: Pick up the zombie, if we are being called
|
||||
@@ -1887,17 +1785,9 @@ cleanup(sig)
|
||||
* 5: Close down the network and pty connections.
|
||||
* 6: Finish up the TMPDIR cleanup, if needed.
|
||||
*/
|
||||
if (sig == SIGCHLD) {
|
||||
while (waitpid(-1, &child_status, flags) > 0)
|
||||
if (sig == SIGCHLD)
|
||||
while (waitpid(-1, 0, WNOHANG) > 0)
|
||||
; /* VOID */
|
||||
/* Check if the child process was stopped
|
||||
* rather than exited. We want cleanup only if
|
||||
* the child has died.
|
||||
*/
|
||||
if (WIFSTOPPED(child_status)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
t = sigblock(sigmask(SIGCHLD));
|
||||
if (incleanup) {
|
||||
sigsetmask(t);
|
||||
@@ -1905,7 +1795,6 @@ cleanup(sig)
|
||||
}
|
||||
incleanup = 1;
|
||||
sigsetmask(t);
|
||||
#ifdef UNICOS7x
|
||||
if (secflag) {
|
||||
/*
|
||||
* We need to set ourselves back to a null
|
||||
@@ -1915,7 +1804,6 @@ cleanup(sig)
|
||||
setulvl(sysv.sy_minlvl);
|
||||
setucmp((long)0);
|
||||
}
|
||||
#endif /* UNICOS7x */
|
||||
|
||||
t = cleantmp(&wtmp);
|
||||
setutent(); /* just to make sure */
|
||||
@@ -2015,28 +1903,6 @@ sigjob(sig)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* jid_getutid:
|
||||
* called by jobend() before calling cleantmp()
|
||||
* to find the correct $TMPDIR to cleanup.
|
||||
*/
|
||||
|
||||
struct utmp *
|
||||
jid_getutid(jid)
|
||||
int jid;
|
||||
{
|
||||
struct utmp *cur = NULL;
|
||||
|
||||
setutent(); /* just to make sure */
|
||||
while (cur = getutent()) {
|
||||
if ( (cur->ut_type != NULL) && (jid == cur->ut_jid) ) {
|
||||
return(cur);
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clean up the TMPDIR that login created.
|
||||
* The first time this is called we pick up the info
|
||||
@@ -2093,27 +1959,9 @@ jobend(jid, path, user)
|
||||
register char *user;
|
||||
{
|
||||
static int saved_jid = 0;
|
||||
static int pty_saved_jid = 0;
|
||||
static char saved_path[sizeof(wtmp.ut_tpath)+1];
|
||||
static char saved_user[sizeof(wtmp.ut_user)+1];
|
||||
|
||||
/*
|
||||
* this little piece of code comes into play
|
||||
* only when ptyreconnect is used to reconnect
|
||||
* to an previous session.
|
||||
*
|
||||
* this is the only time when the
|
||||
* "saved_jid != jid" code is executed.
|
||||
*/
|
||||
|
||||
if ( saved_jid && saved_jid != jid ) {
|
||||
if (!path) { /* called from signal handler */
|
||||
pty_saved_jid = jid;
|
||||
} else {
|
||||
pty_saved_jid = saved_jid;
|
||||
}
|
||||
}
|
||||
|
||||
if (path) {
|
||||
strncpy(saved_path, path, sizeof(wtmp.ut_tpath));
|
||||
strncpy(saved_user, user, sizeof(wtmp.ut_user));
|
||||
@@ -2124,24 +1972,6 @@ jobend(jid, path, user)
|
||||
saved_jid = jid;
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* if the jid has changed, get the correct entry from the utmp file */
|
||||
|
||||
if ( saved_jid != jid ) {
|
||||
struct utmp *utp = NULL;
|
||||
struct utmp *jid_getutid();
|
||||
|
||||
utp = jid_getutid(pty_saved_jid);
|
||||
|
||||
if (utp == 0) {
|
||||
syslog(LOG_ERR, "Can't get /etc/utmp entry to clean TMPDIR");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
cleantmpdir(jid, utp->ut_tpath, utp->ut_user);
|
||||
return(1);
|
||||
}
|
||||
|
||||
cleantmpdir(jid, saved_path, saved_user);
|
||||
return(1);
|
||||
}
|
||||
@@ -2238,9 +2068,7 @@ rmut()
|
||||
continue;
|
||||
(void) lseek(f, ((long)u)-((long)utmp), L_SET);
|
||||
SCPYN(u->ut_name, "");
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
SCPYN(u->ut_host, "");
|
||||
#endif
|
||||
(void) time(&u->ut_time);
|
||||
(void) write(f, (char *)u, sizeof(wtmp));
|
||||
found++;
|
||||
@@ -2253,14 +2081,8 @@ rmut()
|
||||
if (f >= 0) {
|
||||
SCPYN(wtmp.ut_line, line+5);
|
||||
SCPYN(wtmp.ut_name, "");
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
SCPYN(wtmp.ut_host, "");
|
||||
#endif
|
||||
#ifdef HAVE_WTMP_UT_TV
|
||||
(void) time(&wtmp.ut_tv.tv_sec);
|
||||
#else
|
||||
(void) time(&wtmp.ut_time);
|
||||
#endif
|
||||
(void) write(f, (char *)&wtmp, sizeof(wtmp));
|
||||
(void) close(f);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)telnetd.8 8.4 (Berkeley) 6/1/94
|
||||
.\" @(#)telnetd.8 8.3 (Berkeley) 3/1/94
|
||||
.\"
|
||||
.Dd June 1, 1994
|
||||
.Dd March 1, 1994
|
||||
.Dt TELNETD 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@@ -308,7 +308,6 @@ indicates that only dotted decimal addresses
|
||||
should be put into the
|
||||
.Pa utmp
|
||||
file.
|
||||
.ne 1i
|
||||
.It Fl U
|
||||
This option causes
|
||||
.Nm telnetd
|
||||
@@ -425,7 +424,6 @@ Whenever a
|
||||
command is received, it is always responded
|
||||
to with a
|
||||
.Dv WILL TIMING-MARK
|
||||
.ne 1i
|
||||
.It "WILL LOGOUT"
|
||||
When a
|
||||
.Dv DO LOGOUT
|
||||
|
||||
@@ -38,14 +38,11 @@ static char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)telnetd.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "telnetd.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
#if defined(_SC_CRAY_SECURE_SYS) && !defined(SCM_SECURITY)
|
||||
/*
|
||||
@@ -82,13 +79,7 @@ int auth_level = 0;
|
||||
int require_SecurID = 0;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_UTSNAME_H
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
extern int utmp_len;
|
||||
#endif
|
||||
int registerd_host_only = 0;
|
||||
|
||||
#ifdef STREAMSPTY
|
||||
@@ -357,9 +348,7 @@ main(argc, argv)
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
utmp_len = atoi(optarg);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
@@ -462,7 +451,7 @@ main(argc, argv)
|
||||
int szi = sizeof(int);
|
||||
#endif /* SO_SEC_MULTI */
|
||||
|
||||
memset((char *)&dv, 0, sizeof(dv));
|
||||
bzero((char *)&dv, sizeof(dv));
|
||||
|
||||
if (getsysv(&sysv, sizeof(struct sysv)) != 0) {
|
||||
perror("getsysv");
|
||||
@@ -648,40 +637,34 @@ getterminaltype(name)
|
||||
static unsigned char sb[] =
|
||||
{ IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
|
||||
|
||||
memmove(nfrontp, sb, sizeof sb);
|
||||
bcopy(sb, nfrontp, sizeof sb);
|
||||
nfrontp += sizeof sb;
|
||||
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
|
||||
}
|
||||
if (his_state_is_will(TELOPT_XDISPLOC)) {
|
||||
static unsigned char sb[] =
|
||||
{ IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
|
||||
|
||||
memmove(nfrontp, sb, sizeof sb);
|
||||
bcopy(sb, nfrontp, sizeof sb);
|
||||
nfrontp += sizeof sb;
|
||||
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
|
||||
}
|
||||
if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
|
||||
static unsigned char sb[] =
|
||||
{ IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
|
||||
|
||||
memmove(nfrontp, sb, sizeof sb);
|
||||
bcopy(sb, nfrontp, sizeof sb);
|
||||
nfrontp += sizeof sb;
|
||||
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
|
||||
}
|
||||
else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
|
||||
static unsigned char sb[] =
|
||||
{ IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
|
||||
|
||||
memmove(nfrontp, sb, sizeof sb);
|
||||
bcopy(sb, nfrontp, sizeof sb);
|
||||
nfrontp += sizeof sb;
|
||||
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
|
||||
}
|
||||
if (his_state_is_will(TELOPT_TTYPE)) {
|
||||
|
||||
memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf);
|
||||
bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
|
||||
nfrontp += sizeof ttytype_sbbuf;
|
||||
DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
|
||||
sizeof ttytype_sbbuf - 2););
|
||||
}
|
||||
if (his_state_is_will(TELOPT_TSPEED)) {
|
||||
while (sequenceIs(tspeedsubopt, baseline))
|
||||
@@ -754,10 +737,8 @@ _gettermname()
|
||||
if (his_state_is_wont(TELOPT_TTYPE))
|
||||
return;
|
||||
settimer(baseline);
|
||||
memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf);
|
||||
bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
|
||||
nfrontp += sizeof ttytype_sbbuf;
|
||||
DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
|
||||
sizeof ttytype_sbbuf - 2););
|
||||
while (sequenceIs(ttypesubopt, baseline))
|
||||
ttloop();
|
||||
}
|
||||
@@ -825,7 +806,7 @@ doit(who)
|
||||
if ((lp = getpty()) == NULL)
|
||||
fatal(net, "Out of ptys");
|
||||
|
||||
if ((pty = open(lp, O_RDWR)) >= 0) {
|
||||
if ((pty = open(lp, 2)) >= 0) {
|
||||
strcpy(line,lp);
|
||||
line[5] = 't';
|
||||
break;
|
||||
@@ -856,12 +837,8 @@ doit(who)
|
||||
if (hp == NULL && registerd_host_only) {
|
||||
fatal(net, "Couldn't resolve your address into a host name.\r\n\
|
||||
Please contact your net administrator");
|
||||
} else if (hp
|
||||
#ifdef HAVE_UTMP_UT_HOST
|
||||
&& (strlen(hp->h_name) <=
|
||||
(unsigned int)((utmp_len < 0) ? -utmp_len : utmp_len))
|
||||
#endif
|
||||
) {
|
||||
} else if (hp &&
|
||||
(strlen(hp->h_name) <= ((utmp_len < 0) ? -utmp_len : utmp_len))) {
|
||||
host = hp->h_name;
|
||||
} else {
|
||||
host = inet_ntoa(who->sin_addr);
|
||||
@@ -946,12 +923,10 @@ telnet(f, p, host)
|
||||
char defent[TABBUFSIZ];
|
||||
char defstrs[TABBUFSIZ];
|
||||
#undef TABBUFSIZ
|
||||
#undef HE /* Make sure its not defined as a macro. */
|
||||
char *HE;
|
||||
char *HN;
|
||||
char *IM;
|
||||
void netflush();
|
||||
int nfd;
|
||||
|
||||
/*
|
||||
* Initialize the slc mapping table.
|
||||
@@ -1116,7 +1091,7 @@ telnet(f, p, host)
|
||||
#ifdef TIOCNOTTY
|
||||
{
|
||||
register int t;
|
||||
t = open(PATH_TTY, O_RDWR);
|
||||
t = open(_PATH_TTY, O_RDWR);
|
||||
if (t >= 0) {
|
||||
(void) ioctl(t, TIOCNOTTY, (char *)0);
|
||||
(void) close(t);
|
||||
@@ -1154,34 +1129,9 @@ telnet(f, p, host)
|
||||
if (IM == 0)
|
||||
IM = "";
|
||||
} else {
|
||||
#ifdef HAVE_UNAME
|
||||
struct utsname u;
|
||||
#endif
|
||||
|
||||
#ifdef DEFAULT_IM
|
||||
IM = DEFAULT_IM;
|
||||
#else
|
||||
IM = 0;
|
||||
#ifdef HAVE_UNAME
|
||||
if (uname (&u) == 0) {
|
||||
IM = malloc (strlen (UNAME_IM_PREFIX)
|
||||
+ strlen (u.sysname)
|
||||
+ 1 + strlen (u.release)
|
||||
+ strlen (UNAME_IM_SUFFIX) + 1);
|
||||
if (IM)
|
||||
sprintf (IM, "%s%s %s%s",
|
||||
UNAME_IM_PREFIX,
|
||||
u.sysname, u.release,
|
||||
UNAME_IM_SUFFIX);
|
||||
}
|
||||
#endif /* HAVE_UNAME */
|
||||
if (! IM)
|
||||
IM = "\r\n\nUNIX (%h) (%t)\r\n\n";
|
||||
#endif /* DEFAULT_IM */
|
||||
|
||||
HE = 0;
|
||||
}
|
||||
|
||||
edithost(HE, host_name);
|
||||
if (hostinfo && *IM)
|
||||
putf(IM, ptyibuf2);
|
||||
@@ -1206,7 +1156,6 @@ telnet(f, p, host)
|
||||
startslave(host);
|
||||
#endif
|
||||
|
||||
nfd = ((f > p) ? f : p) + 1;
|
||||
for (;;) {
|
||||
fd_set ibits, obits, xbits;
|
||||
register int c;
|
||||
@@ -1238,7 +1187,7 @@ telnet(f, p, host)
|
||||
if (!SYNCHing) {
|
||||
FD_SET(f, &xbits);
|
||||
}
|
||||
if ((c = select(nfd, &ibits, &obits, &xbits,
|
||||
if ((c = select(16, &ibits, &obits, &xbits,
|
||||
(struct timeval *)0)) < 1) {
|
||||
if (c == -1) {
|
||||
if (errno == EINTR) {
|
||||
@@ -1320,8 +1269,9 @@ telnet(f, p, host)
|
||||
if (ncc < 0 && errno == EWOULDBLOCK)
|
||||
ncc = 0;
|
||||
else {
|
||||
if (ncc <= 0)
|
||||
if (ncc <= 0) {
|
||||
break;
|
||||
}
|
||||
netip = netibuf;
|
||||
}
|
||||
DIAG((TD_REPORT | TD_NETDATA),
|
||||
@@ -1354,7 +1304,7 @@ telnet(f, p, host)
|
||||
if (pcc <= 0)
|
||||
break;
|
||||
#if !defined(CRAY2) || !defined(UNICOS5)
|
||||
#if defined (LINEMODE) && defined (TIOCPKT_IOCTL)
|
||||
#ifdef LINEMODE
|
||||
/*
|
||||
* If ioctl from pty, pass it through net
|
||||
*/
|
||||
@@ -1363,7 +1313,7 @@ telnet(f, p, host)
|
||||
localstat();
|
||||
pcc = 1;
|
||||
}
|
||||
#endif /* LINEMODE && TIOCPKT_IOCTL */
|
||||
#endif /* LINEMODE */
|
||||
if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
|
||||
netclear(); /* clear buffer back */
|
||||
#ifndef NO_URGENT
|
||||
@@ -1376,9 +1326,6 @@ telnet(f, p, host)
|
||||
*nfrontp++ = IAC;
|
||||
*nfrontp++ = DM;
|
||||
neturg = nfrontp-1; /* off by one XXX */
|
||||
DIAG(TD_OPTIONS,
|
||||
printoption("td: send IAC", DM));
|
||||
|
||||
#endif
|
||||
}
|
||||
if (his_state_is_will(TELOPT_LFLOW) &&
|
||||
@@ -1395,9 +1342,6 @@ telnet(f, p, host)
|
||||
: LFLOW_OFF,
|
||||
IAC, SE);
|
||||
nfrontp += 6;
|
||||
DIAG(TD_OPTIONS, printsub('>',
|
||||
(unsigned char *)nfrontp-4,
|
||||
4););
|
||||
}
|
||||
}
|
||||
pcc--;
|
||||
@@ -1563,14 +1507,6 @@ interrupt()
|
||||
{
|
||||
ptyflush(); /* half-hearted */
|
||||
|
||||
#if defined(STREAMSPTY) && defined(TIOCSIGNAL)
|
||||
/* Streams PTY style ioctl to post a signal */
|
||||
{
|
||||
int sig = SIGINT;
|
||||
(void) ioctl(pty, TIOCSIGNAL, &sig);
|
||||
(void) ioctl(pty, I_FLUSH, FLUSHR);
|
||||
}
|
||||
#else
|
||||
#ifdef TCSIG
|
||||
(void) ioctl(pty, TCSIG, (char *)SIGINT);
|
||||
#else /* TCSIG */
|
||||
@@ -1578,7 +1514,6 @@ interrupt()
|
||||
*pfrontp++ = slctab[SLC_IP].sptr ?
|
||||
(unsigned char)*slctab[SLC_IP].sptr : '\177';
|
||||
#endif /* TCSIG */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)termstat.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "telnetd.h"
|
||||
|
||||
/*
|
||||
@@ -445,7 +441,7 @@ clientstat(code, parm1, parm2)
|
||||
useeditmode = 0;
|
||||
if (tty_isediting())
|
||||
useeditmode |= MODE_EDIT;
|
||||
if (tty_istrapsig())
|
||||
if (tty_istrapsig)
|
||||
useeditmode |= MODE_TRAPSIG;
|
||||
if (tty_issofttab())
|
||||
useeditmode |= MODE_SOFT_TAB;
|
||||
@@ -636,7 +632,7 @@ defer_terminit()
|
||||
if (def_col || def_row) {
|
||||
struct winsize ws;
|
||||
|
||||
memset((char *)&ws, 0, sizeof(ws));
|
||||
bzero((char *)&ws, sizeof(ws));
|
||||
ws.ws_col = def_col;
|
||||
ws.ws_row = def_row;
|
||||
(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
|
||||
|
||||
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95";
|
||||
static char sccsid[] = "@(#)utility.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define PRINTOPTIONS
|
||||
#include "telnetd.h"
|
||||
|
||||
@@ -224,7 +220,7 @@ netclear()
|
||||
next = nextitem(next);
|
||||
} while (wewant(next) && (nfrontp > next));
|
||||
length = next-thisitem;
|
||||
memmove(good, thisitem, length);
|
||||
bcopy(thisitem, good, length);
|
||||
good += length;
|
||||
thisitem = next;
|
||||
} else {
|
||||
@@ -331,7 +327,7 @@ writenet(ptr, len)
|
||||
netflush();
|
||||
}
|
||||
|
||||
memmove(nfrontp, ptr, len);
|
||||
bcopy(ptr, nfrontp, len);
|
||||
nfrontp += len;
|
||||
|
||||
} /* end of writenet */
|
||||
@@ -349,7 +345,7 @@ fatal(f, msg)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
|
||||
snprintf (buf, sizeof buf, "telnetd: %s.\r\n", msg);
|
||||
(void) sprintf(buf, "telnetd: %s.\r\n", msg);
|
||||
#ifdef ENCRYPTION
|
||||
if (encrypt_output) {
|
||||
/*
|
||||
@@ -372,7 +368,7 @@ fatalperror(f, msg)
|
||||
{
|
||||
char buf[BUFSIZ], *strerror();
|
||||
|
||||
snprintf (buf, sizeof buf, "%s: %s", msg, strerror(errno));
|
||||
(void) sprintf(buf, "%s: %s\r\n", msg, strerror(errno));
|
||||
fatal(f, buf);
|
||||
}
|
||||
|
||||
@@ -384,9 +380,7 @@ edithost(pat, host)
|
||||
register char *host;
|
||||
{
|
||||
register char *res = editedhost;
|
||||
#ifndef strncpy
|
||||
char *strncpy();
|
||||
#endif
|
||||
|
||||
if (!pat)
|
||||
pat = "";
|
||||
@@ -455,13 +449,9 @@ putf(cp, where)
|
||||
time_t t;
|
||||
char db[100];
|
||||
#ifdef STREAMSPTY
|
||||
#ifndef strchr
|
||||
extern char *strchr();
|
||||
#endif
|
||||
extern char *index();
|
||||
#else
|
||||
#ifndef strrchr
|
||||
extern char *strrchr();
|
||||
#endif
|
||||
extern char *rindex();
|
||||
#endif
|
||||
|
||||
putlocation = where;
|
||||
@@ -476,9 +466,9 @@ putf(cp, where)
|
||||
case 't':
|
||||
#ifdef STREAMSPTY
|
||||
/* names are like /dev/pts/2 -- we want pts/2 */
|
||||
slash = strchr(line+1, '/');
|
||||
slash = index(line+1, '/');
|
||||
#else
|
||||
slash = strrchr(line, '/');
|
||||
slash = rindex(line, '/');
|
||||
#endif
|
||||
if (slash == (char *) 0)
|
||||
putstr(line);
|
||||
|
||||
@@ -35,4 +35,3 @@
|
||||
|
||||
void recvfile __P((int, char *, char *));
|
||||
void sendfile __P((int, char *, char *));
|
||||
extern jmp_buf toplevel;
|
||||
|
||||
105
tftp/main.c
105
tftp/main.c
@@ -46,11 +46,6 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
/*
|
||||
* TFTP User Program -- Command Interface.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
@@ -61,7 +56,6 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
@@ -103,7 +97,7 @@ void settrace __P((int, char **));
|
||||
void setverbose __P((int, char **));
|
||||
void status __P((int, char **));
|
||||
|
||||
static void command __P((void));
|
||||
static __dead void command __P((void));
|
||||
|
||||
static void getusage __P((char *));
|
||||
static void makeargv __P((void));
|
||||
@@ -151,6 +145,8 @@ struct cmd cmdtab[] = {
|
||||
|
||||
struct cmd *getcmd();
|
||||
char *tail();
|
||||
char *index();
|
||||
char *rindex();
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
@@ -189,28 +185,6 @@ main(argc, argv)
|
||||
|
||||
char hostname[100];
|
||||
|
||||
/* Prompt for more arguments from the user with PROMPT, putting the results
|
||||
into ARGC & ARGV, with an initial argument of ARG0. Global variables
|
||||
LINE, MARGC, and MARGV are changed. */
|
||||
static void
|
||||
get_args (arg0, prompt, argc, argv)
|
||||
char *arg0, *prompt;
|
||||
int *argc;
|
||||
char ***argv;
|
||||
{
|
||||
size_t arg0_len = strlen (arg0);
|
||||
|
||||
strcpy (line, arg0);
|
||||
strcat (line, " ");
|
||||
|
||||
printf(prompt);
|
||||
fgets (line + arg0_len + 1, sizeof line - arg0_len - 1, stdin);
|
||||
|
||||
makeargv();
|
||||
*argc = margc;
|
||||
*argv = margv;
|
||||
}
|
||||
|
||||
void
|
||||
setpeer(argc, argv)
|
||||
int argc;
|
||||
@@ -218,9 +192,14 @@ setpeer(argc, argv)
|
||||
{
|
||||
struct hostent *host;
|
||||
|
||||
if (argc < 2)
|
||||
get_args ("Connect", "(to) ", &argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
strcpy(line, "Connect ");
|
||||
printf("(to) ");
|
||||
gets(&line[strlen(line)]);
|
||||
makeargv();
|
||||
argc = margc;
|
||||
argv = margv;
|
||||
}
|
||||
if (argc > 3) {
|
||||
printf("usage: %s host-name [port]\n", argv[0]);
|
||||
return;
|
||||
@@ -341,25 +320,30 @@ put(argc, argv)
|
||||
register int n;
|
||||
register char *cp, *targ;
|
||||
|
||||
if (argc < 2)
|
||||
get_args ("send", "(file) ", &argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
strcpy(line, "send ");
|
||||
printf("(file) ");
|
||||
gets(&line[strlen(line)]);
|
||||
makeargv();
|
||||
argc = margc;
|
||||
argv = margv;
|
||||
}
|
||||
if (argc < 2) {
|
||||
putusage(argv[0]);
|
||||
return;
|
||||
}
|
||||
targ = argv[argc - 1];
|
||||
if (strchr (argv[argc - 1], ':')) {
|
||||
if (index(argv[argc - 1], ':')) {
|
||||
char *cp;
|
||||
struct hostent *hp;
|
||||
|
||||
for (n = 1; n < argc - 1; n++)
|
||||
if (strchr (argv[n], ':')) {
|
||||
if (index(argv[n], ':')) {
|
||||
putusage(argv[0]);
|
||||
return;
|
||||
}
|
||||
cp = argv[argc - 1];
|
||||
targ = strchr (cp, ':');
|
||||
targ = index(cp, ':');
|
||||
*targ++ = 0;
|
||||
hp = gethostbyname(cp);
|
||||
if (hp == NULL) {
|
||||
@@ -392,7 +376,7 @@ put(argc, argv)
|
||||
}
|
||||
/* this assumes the target is a directory */
|
||||
/* on a remote unix system. hmmmm. */
|
||||
cp = strchr (targ, '\0');
|
||||
cp = index(targ, '\0');
|
||||
*cp++ = '/';
|
||||
for (n = 1; n < argc - 1; n++) {
|
||||
strcpy(cp, tail(argv[n]));
|
||||
@@ -430,22 +414,27 @@ get(argc, argv)
|
||||
register char *cp;
|
||||
char *src;
|
||||
|
||||
if (argc < 2)
|
||||
get_args ("get", "(files) ", &argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
strcpy(line, "get ");
|
||||
printf("(files) ");
|
||||
gets(&line[strlen(line)]);
|
||||
makeargv();
|
||||
argc = margc;
|
||||
argv = margv;
|
||||
}
|
||||
if (argc < 2) {
|
||||
getusage(argv[0]);
|
||||
return;
|
||||
}
|
||||
if (!connected) {
|
||||
for (n = 1; n < argc ; n++)
|
||||
if (strchr (argv[n], ':') == 0) {
|
||||
if (index(argv[n], ':') == 0) {
|
||||
getusage(argv[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (n = 1; n < argc ; n++) {
|
||||
src = strchr (argv[n], ':');
|
||||
src = index(argv[n], ':');
|
||||
if (src == NULL)
|
||||
src = argv[n];
|
||||
else {
|
||||
@@ -509,9 +498,14 @@ setrexmt(argc, argv)
|
||||
{
|
||||
int t;
|
||||
|
||||
if (argc < 2)
|
||||
get_args ("Rexmt-timeout", "(value) ", &argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
strcpy(line, "Rexmt-timeout ");
|
||||
printf("(value) ");
|
||||
gets(&line[strlen(line)]);
|
||||
makeargv();
|
||||
argc = margc;
|
||||
argv = margv;
|
||||
}
|
||||
if (argc != 2) {
|
||||
printf("usage: %s value\n", argv[0]);
|
||||
return;
|
||||
@@ -532,9 +526,14 @@ settimeout(argc, argv)
|
||||
{
|
||||
int t;
|
||||
|
||||
if (argc < 2)
|
||||
get_args ("Maximum-timeout", "(value) ", &argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
strcpy(line, "Maximum-timeout ");
|
||||
printf("(value) ");
|
||||
gets(&line[strlen(line)]);
|
||||
makeargv();
|
||||
argc = margc;
|
||||
argv = margv;
|
||||
}
|
||||
if (argc != 2) {
|
||||
printf("usage: %s value\n", argv[0]);
|
||||
return;
|
||||
@@ -577,7 +576,7 @@ tail(filename)
|
||||
register char *s;
|
||||
|
||||
while (*filename) {
|
||||
s = strrchr (filename, '/');
|
||||
s = rindex(filename, '/');
|
||||
if (s == NULL)
|
||||
break;
|
||||
if (s[1])
|
||||
@@ -590,14 +589,14 @@ tail(filename)
|
||||
/*
|
||||
* Command parser.
|
||||
*/
|
||||
static void
|
||||
static __dead void
|
||||
command()
|
||||
{
|
||||
register struct cmd *c;
|
||||
|
||||
for (;;) {
|
||||
printf("%s> ", prompt);
|
||||
if (fgets (line, sizeof line, stdin) == 0) {
|
||||
if (gets(line) == 0) {
|
||||
if (feof(stdin)) {
|
||||
exit(0);
|
||||
} else {
|
||||
|
||||
34
tftp/tftp.c
34
tftp/tftp.c
@@ -40,23 +40,9 @@ static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93";
|
||||
/*
|
||||
* TFTP User Program -- Protocol Machines
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
@@ -66,19 +52,12 @@ static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
#include "tftpsubs.h"
|
||||
|
||||
#ifndef HAVE_ERRNO_DECL
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR_DECL
|
||||
extern const char *strerror __P ((int));
|
||||
#endif
|
||||
|
||||
extern struct sockaddr_in peeraddr; /* filled in by main */
|
||||
extern int f; /* the opened socket */
|
||||
@@ -90,6 +69,7 @@ extern int maxtimeout;
|
||||
#define PKTSIZE SEGSIZE+4
|
||||
char ackbuf[PKTSIZE];
|
||||
int timeout;
|
||||
jmp_buf toplevel;
|
||||
jmp_buf timeoutbuf;
|
||||
|
||||
static void nak __P((int));
|
||||
@@ -145,7 +125,7 @@ sendfile(fd, name, mode)
|
||||
send_data:
|
||||
if (trace)
|
||||
tpacket("sent", dp, size + 4);
|
||||
n = sendto(f, (const char *)dp, size + 4, 0,
|
||||
n = sendto(f, dp, size + 4, 0,
|
||||
(struct sockaddr *)&peeraddr, sizeof(peeraddr));
|
||||
if (n != size + 4) {
|
||||
perror("tftp: sendto");
|
||||
@@ -260,7 +240,7 @@ send_ack:
|
||||
alarm(rexmtval);
|
||||
do {
|
||||
fromlen = sizeof(from);
|
||||
n = recvfrom(f, (char *)dp, PKTSIZE, 0,
|
||||
n = recvfrom(f, dp, PKTSIZE, 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
} while (n <= 0);
|
||||
alarm(0);
|
||||
@@ -339,7 +319,7 @@ makerequest(request, name, tp, mode)
|
||||
|
||||
struct errmsg {
|
||||
int e_code;
|
||||
const char *e_msg;
|
||||
char *e_msg;
|
||||
} errmsgs[] = {
|
||||
{ EUNDEF, "Undefined error code" },
|
||||
{ ENOTFOUND, "File not found" },
|
||||
@@ -365,6 +345,7 @@ nak(error)
|
||||
register struct errmsg *pe;
|
||||
register struct tftphdr *tp;
|
||||
int length;
|
||||
char *strerror();
|
||||
|
||||
tp = (struct tftphdr *)ackbuf;
|
||||
tp->th_opcode = htons((u_short)ERROR);
|
||||
@@ -395,6 +376,7 @@ tpacket(s, tp, n)
|
||||
{ "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR" };
|
||||
register char *cp, *file;
|
||||
u_short op = ntohs(tp->th_opcode);
|
||||
char *index();
|
||||
|
||||
if (op < RRQ || op > ERROR)
|
||||
printf("%s opcode=%x ", s, op);
|
||||
@@ -406,7 +388,7 @@ tpacket(s, tp, n)
|
||||
case WRQ:
|
||||
n -= 2;
|
||||
file = cp = tp->th_stuff;
|
||||
cp = strchr (cp, '\0');
|
||||
cp = index(cp, '\0');
|
||||
printf("<file=%s, mode=%s>\n", file, cp + 1);
|
||||
break;
|
||||
|
||||
|
||||
@@ -46,16 +46,9 @@ static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93";
|
||||
Jim Guyton 10/85
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/tftp.h>
|
||||
|
||||
|
||||
@@ -48,15 +48,8 @@ static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
|
||||
* <guyton@rand-unix>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -67,7 +60,6 @@ static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
@@ -79,16 +71,8 @@ static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
#include "tftpsubs.h"
|
||||
|
||||
#ifndef HAVE_STRERROR_DECL
|
||||
extern const char *strerror __P ((int));
|
||||
#endif
|
||||
|
||||
#define TIMEOUT 5
|
||||
|
||||
#ifndef LOG_FTP
|
||||
#define LOG_FTP LOG_DAEMON /* Use generic facility. */
|
||||
#endif
|
||||
|
||||
int peer;
|
||||
int rexmtval = TIMEOUT;
|
||||
int maxtimeout = 5*TIMEOUT;
|
||||
@@ -116,9 +100,9 @@ static struct dirlist {
|
||||
static int suppress_naks;
|
||||
static int logging;
|
||||
|
||||
static const char *errtomsg __P((int));
|
||||
static char *errtomsg __P((int));
|
||||
static void nak __P((int));
|
||||
static const char *verifyhost __P((struct sockaddr_in *));
|
||||
static char *verifyhost __P((struct sockaddr_in *));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
@@ -350,7 +334,7 @@ validate_access(filep, mode)
|
||||
struct stat stbuf;
|
||||
int fd;
|
||||
struct dirlist *dirp;
|
||||
static char *pathname = 0;
|
||||
static char pathname[MAXPATHLEN];
|
||||
char *filename = *filep;
|
||||
|
||||
/*
|
||||
@@ -405,12 +389,6 @@ validate_access(filep, mode)
|
||||
*/
|
||||
err = ENOTFOUND;
|
||||
for (dirp = dirs; dirp->name != NULL; dirp++) {
|
||||
if (pathname)
|
||||
free (pathname);
|
||||
pathname = malloc (strlen (dirp->name)
|
||||
+ 1 + strlen (filename) + 1);
|
||||
if (! pathname)
|
||||
return ENOMEM;
|
||||
sprintf(pathname, "%s/%s", dirp->name, filename);
|
||||
if (stat(pathname, &stbuf) == 0 &&
|
||||
(stbuf.st_mode & S_IFMT) == S_IFREG) {
|
||||
@@ -424,7 +402,7 @@ validate_access(filep, mode)
|
||||
return (err);
|
||||
*filep = filename = pathname;
|
||||
}
|
||||
fd = open(filename, mode == RRQ ? O_RDONLY : (O_WRONLY | O_TRUNC));
|
||||
fd = open(filename, mode == RRQ ? 0 : 1);
|
||||
if (fd < 0)
|
||||
return (errno + 100);
|
||||
file = fdopen(fd, (mode == RRQ)? "r":"w");
|
||||
@@ -438,8 +416,7 @@ int timeout;
|
||||
jmp_buf timeoutbuf;
|
||||
|
||||
void
|
||||
timer(sig)
|
||||
int sig;
|
||||
timer()
|
||||
{
|
||||
|
||||
timeout += rexmtval;
|
||||
@@ -476,7 +453,7 @@ sendfile(pf)
|
||||
(void)setjmp(timeoutbuf);
|
||||
|
||||
send_data:
|
||||
if (send(peer, (const char *)dp, size + 4, 0) != size + 4) {
|
||||
if (send(peer, dp, size + 4, 0) != size + 4) {
|
||||
syslog(LOG_ERR, "tftpd: write: %m\n");
|
||||
goto abort;
|
||||
}
|
||||
@@ -512,8 +489,7 @@ abort:
|
||||
}
|
||||
|
||||
void
|
||||
justquit(sig)
|
||||
int sig;
|
||||
justquit()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
@@ -549,7 +525,7 @@ send_ack:
|
||||
write_behind(file, pf->f_convert);
|
||||
for ( ; ; ) {
|
||||
alarm(rexmtval);
|
||||
n = recv(peer, (char *)dp, PKTSIZE, 0);
|
||||
n = recv(peer, dp, PKTSIZE, 0);
|
||||
alarm(0);
|
||||
if (n < 0) { /* really? */
|
||||
syslog(LOG_ERR, "tftpd: read: %m\n");
|
||||
@@ -599,7 +575,7 @@ abort:
|
||||
|
||||
struct errmsg {
|
||||
int e_code;
|
||||
const char *e_msg;
|
||||
char *e_msg;
|
||||
} errmsgs[] = {
|
||||
{ EUNDEF, "Undefined error code" },
|
||||
{ ENOTFOUND, "File not found" },
|
||||
@@ -612,7 +588,7 @@ struct errmsg {
|
||||
{ -1, 0 }
|
||||
};
|
||||
|
||||
static const char *
|
||||
static char *
|
||||
errtomsg(error)
|
||||
int error;
|
||||
{
|
||||
@@ -659,7 +635,7 @@ nak(error)
|
||||
syslog(LOG_ERR, "nak: %m\n");
|
||||
}
|
||||
|
||||
static const char *
|
||||
static char *
|
||||
verifyhost(fromp)
|
||||
struct sockaddr_in *fromp;
|
||||
{
|
||||
|
||||
120
uucpd/uucpd.c
120
uucpd/uucpd.c
@@ -49,10 +49,6 @@ static char sccsid[] = "@(#)uucpd.c 8.1 (Berkeley) 6/4/93";
|
||||
* uucico's TCP channel causes this server to be run at the remote end.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -62,31 +58,14 @@ static char sccsid[] = "@(#)uucpd.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <crypt.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#endif
|
||||
#ifdef HAVE_UTMP_H
|
||||
# include <utmp.h>
|
||||
#endif
|
||||
|
||||
void dologin ();
|
||||
#include "pathnames.h"
|
||||
|
||||
struct sockaddr_in hisctladdr;
|
||||
int hisaddrlen = sizeof hisctladdr;
|
||||
@@ -107,9 +86,9 @@ char **argv;
|
||||
#ifndef BSDINETD
|
||||
register int s, tcp_socket;
|
||||
struct servent *sp;
|
||||
#endif /* !BSDINETD */
|
||||
#endif !BSDINETD
|
||||
extern int errno;
|
||||
void dologout();
|
||||
int dologout();
|
||||
|
||||
environ = nenv;
|
||||
#ifdef BSDINETD
|
||||
@@ -125,7 +104,7 @@ char **argv;
|
||||
doit(&hisctladdr);
|
||||
dologout();
|
||||
exit(1);
|
||||
#else /* !BSDINETD */
|
||||
#else !BSDINETD
|
||||
sp = getservbyname("uucp", "tcp");
|
||||
if (sp == NULL){
|
||||
perror("uucpd: getservbyname");
|
||||
@@ -133,7 +112,7 @@ char **argv;
|
||||
}
|
||||
if (fork())
|
||||
exit(0);
|
||||
if ((s=open(PATH_TTY, O_RDWR)) >= 0){
|
||||
if ((s=open(_PATH_TTY, 2)) >= 0){
|
||||
ioctl(s, TIOCNOTTY, (char *)0);
|
||||
close(s);
|
||||
}
|
||||
@@ -171,18 +150,17 @@ char **argv;
|
||||
}
|
||||
close(s);
|
||||
}
|
||||
#endif /* BSD4_2 */
|
||||
#endif BSD4_2
|
||||
|
||||
#endif /* !BSDINETD */
|
||||
#endif !BSDINETD
|
||||
}
|
||||
|
||||
void
|
||||
doit (sinp)
|
||||
struct sockaddr_in *sinp;
|
||||
doit(sinp)
|
||||
struct sockaddr_in *sinp;
|
||||
{
|
||||
struct passwd *pw, *getpwnam();
|
||||
char user[64], passwd[64];
|
||||
char *xpasswd;
|
||||
char *xpasswd, *crypt();
|
||||
struct passwd *pw, *getpwnam();
|
||||
|
||||
alarm(60);
|
||||
printf("login: "); fflush(stdout);
|
||||
@@ -197,7 +175,7 @@ doit (sinp)
|
||||
fprintf(stderr, "user unknown\n");
|
||||
return;
|
||||
}
|
||||
if (strcmp(pw->pw_shell, PATH_UUCICO)) {
|
||||
if (strcmp(pw->pw_shell, _PATH_UUCICO)) {
|
||||
fprintf(stderr, "Login incorrect.");
|
||||
return;
|
||||
}
|
||||
@@ -207,7 +185,7 @@ doit (sinp)
|
||||
fprintf(stderr, "passwd read\n");
|
||||
return;
|
||||
}
|
||||
xpasswd = CRYPT (passwd, pw->pw_passwd);
|
||||
xpasswd = crypt(passwd, pw->pw_passwd);
|
||||
if (strcmp(xpasswd, pw->pw_passwd)) {
|
||||
fprintf(stderr, "Login incorrect.");
|
||||
return;
|
||||
@@ -219,12 +197,12 @@ doit (sinp)
|
||||
setgid(pw->pw_gid);
|
||||
#ifdef BSD4_2
|
||||
initgroups(pw->pw_name, pw->pw_gid);
|
||||
#endif /* BSD4_2 */
|
||||
#endif BSD4_2
|
||||
chdir(pw->pw_dir);
|
||||
setuid(pw->pw_uid);
|
||||
#ifdef BSD4_2
|
||||
execl(UUCICO, "uucico", (char *)0);
|
||||
#endif /* BSD4_2 */
|
||||
#endif BSD4_2
|
||||
perror("uucico server: execl");
|
||||
}
|
||||
|
||||
@@ -247,38 +225,43 @@ register int n;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
#include <utmp.h>
|
||||
#ifdef BSD4_2
|
||||
#include <fcntl.h>
|
||||
#endif /* BSD4_2 */
|
||||
#endif BSD4_2
|
||||
|
||||
#define SCPYN(a, b) strncpy(a, b, sizeof (a))
|
||||
|
||||
struct utmp utmp;
|
||||
|
||||
void
|
||||
dologout()
|
||||
{
|
||||
int pid;
|
||||
union wait status;
|
||||
int pid, wtmp;
|
||||
|
||||
#ifdef HAVE_WAITPID
|
||||
while ((pid = waitpid (-1, 0, WNOHANG)) > 0)
|
||||
#else
|
||||
# ifdef HAVE_WAIT3
|
||||
while ((pid = wait3 (0, WNOHANG, 0)) > 0)
|
||||
# else
|
||||
while ((pid = wait (0)) > 0)
|
||||
#endif /* HAVE_WAIT3 */
|
||||
#endif /* HAVE_WAITPID */
|
||||
{
|
||||
char line[100];
|
||||
sprintf(line, "uucp%.4d", pid);
|
||||
logwtmp (line, "", "");
|
||||
}
|
||||
#ifdef BSDINETD
|
||||
while ((pid=wait((int *)&status)) > 0) {
|
||||
#else !BSDINETD
|
||||
while ((pid=wait3((int *)&status,WNOHANG,0)) > 0) {
|
||||
#endif !BSDINETD
|
||||
wtmp = open(_PATH_WTMP, O_WRONLY|O_APPEND);
|
||||
if (wtmp >= 0) {
|
||||
sprintf(utmp.ut_line, "uucp%.4d", pid);
|
||||
SCPYN(utmp.ut_name, "");
|
||||
SCPYN(utmp.ut_host, "");
|
||||
(void) time(&utmp.ut_time);
|
||||
(void) write(wtmp, (char *)&utmp, sizeof (utmp));
|
||||
(void) close(wtmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Record login in wtmp file.
|
||||
*/
|
||||
void
|
||||
dologin(pw, sin)
|
||||
struct passwd *pw;
|
||||
struct sockaddr_in *sin;
|
||||
struct passwd *pw;
|
||||
struct sockaddr_in *sin;
|
||||
{
|
||||
char line[32];
|
||||
char remotehost[32];
|
||||
@@ -292,14 +275,18 @@ dologin(pw, sin)
|
||||
} else
|
||||
strncpy(remotehost, inet_ntoa(sin->sin_addr),
|
||||
sizeof (remotehost));
|
||||
|
||||
sprintf(line, "uucp%.4d", getpid());
|
||||
|
||||
logwtmp (line, pw->pw_name, remotehost);
|
||||
|
||||
#if defined (PATH_LASTLOG) && defined (HAVE_STRUCT_LASTLOG)
|
||||
#define SCPYN(a, b) strncpy(a, b, sizeof (a))
|
||||
if ((f = open(PATH_LASTLOG, O_RDWR)) >= 0) {
|
||||
wtmp = open(_PATH_WTMP, O_WRONLY|O_APPEND);
|
||||
if (wtmp >= 0) {
|
||||
/* hack, but must be unique and no tty line */
|
||||
sprintf(line, "uucp%.4d", getpid());
|
||||
SCPYN(utmp.ut_line, line);
|
||||
SCPYN(utmp.ut_name, pw->pw_name);
|
||||
SCPYN(utmp.ut_host, remotehost);
|
||||
time(&utmp.ut_time);
|
||||
(void) write(wtmp, (char *)&utmp, sizeof (utmp));
|
||||
(void) close(wtmp);
|
||||
}
|
||||
if ((f = open(_PATH_LASTLOG, O_RDWR)) >= 0) {
|
||||
struct lastlog ll;
|
||||
|
||||
time(&ll.ll_time);
|
||||
@@ -310,5 +297,4 @@ dologin(pw, sin)
|
||||
(void) write(f, (char *) &ll, sizeof ll);
|
||||
(void) close(f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user