From 46b15d8a2a2e4b45445e61976bd838ebb82cfd48 Mon Sep 17 00:00:00 2001 From: Ralph Campbell Date: Tue, 22 Jan 1985 22:14:18 -0800 Subject: [PATCH] bug fixes and changes from Rick Adams SCCS-vsn: usr.bin/uucp/assert.c 5.3 SCCS-vsn: usr.bin/uucp/uucico/cntrl.c 5.4 SCCS-vsn: usr.bin/uucp/uucico/condevs.c 5.8 SCCS-vsn: usr.bin/uucp/uucico/conn.c 5.4 SCCS-vsn: usr.bin/uucp/libuu/cpmv.c 5.3 SCCS-vsn: usr.bin/uucp/libuu/expfile.c 5.3 SCCS-vsn: usr.bin/uucp/libuu/gename.c 5.4 SCCS-vsn: usr.bin/uucp/libuu/getargs.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/getprm.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/getpwinfo.c 5.2 SCCS-vsn: usr.bin/uucp/uucico/gio.c 5.2 SCCS-vsn: usr.bin/uucp/gnamef.c 5.3 SCCS-vsn: usr.bin/uucp/uucico/gnsys.c 5.3 SCCS-vsn: usr.bin/uucp/libuu/gnxseq.c 5.3 SCCS-vsn: usr.bin/uucp/port/getwd.c 5.3 SCCS-vsn: usr.bin/uucp/uucico/imsg.c 5.2 SCCS-vsn: usr.bin/uucp/port/index.c 5.2 SCCS-vsn: usr.bin/uucp/port/ioctl.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/lastpart.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/logent.c 5.3 SCCS-vsn: usr.bin/uucp/libuu/mailst.c 5.3 SCCS-vsn: usr.bin/uucp/uucico/pk.h 5.2 SCCS-vsn: usr.bin/uucp/uucico/pk0.c 5.2 SCCS-vsn: usr.bin/uucp/uucico/pk1.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/prefix.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/setline.c 5.2 SCCS-vsn: usr.bin/uucp/shio.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/subdir.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/sysacct.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/systat.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/ulockf.c 5.2 SCCS-vsn: usr.bin/uucp/uuclean/uuclean.c 5.3 SCCS-vsn: usr.bin/uucp/uucp/uucp.c 5.2 SCCS-vsn: usr.bin/uucp/includes/uucp.h 5.4 SCCS-vsn: libexec/uucpd/uucpd.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/uucpdefs.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/uucpname.c 5.2 SCCS-vsn: usr.bin/uudecode/uudecode.c 5.2 SCCS-vsn: usr.bin/uuencode/uuencode.c 5.3 SCCS-vsn: usr.bin/uucp/uulog/uulog.c 5.2 SCCS-vsn: usr.bin/uucp/uuname/uuname.c 5.2 SCCS-vsn: usr.bin/uucp/uupoll/uupoll.c 5.2 SCCS-vsn: usr.bin/uucp/uusend/uusend.c 5.2 SCCS-vsn: usr.bin/uucp/uusnap/uusnap.c 5.3 SCCS-vsn: usr.bin/uucp/uux/uux.c 5.2 SCCS-vsn: usr.bin/uucp/uuxqt/uuxqt.c 5.3 SCCS-vsn: usr.bin/uucp/libuu/versys.c 5.2 SCCS-vsn: usr.bin/uucp/libuu/xqt.c 5.2 --- usr/src/libexec/uucpd/uucpd.c | 232 +++- usr/src/usr.bin/uucp/assert.c | 19 +- usr/src/usr.bin/uucp/gnamef.c | 20 +- usr/src/usr.bin/uucp/includes/uucp.h | 174 ++- usr/src/usr.bin/uucp/libuu/cpmv.c | 35 +- usr/src/usr.bin/uucp/libuu/expfile.c | 41 +- usr/src/usr.bin/uucp/libuu/gename.c | 13 +- usr/src/usr.bin/uucp/libuu/getargs.c | 25 +- usr/src/usr.bin/uucp/libuu/getprm.c | 33 +- usr/src/usr.bin/uucp/libuu/getpwinfo.c | 22 +- usr/src/usr.bin/uucp/libuu/gnxseq.c | 20 +- usr/src/usr.bin/uucp/libuu/lastpart.c | 13 +- usr/src/usr.bin/uucp/libuu/logent.c | 79 +- usr/src/usr.bin/uucp/libuu/mailst.c | 32 +- usr/src/usr.bin/uucp/libuu/prefix.c | 20 +- usr/src/usr.bin/uucp/libuu/setline.c | 20 +- usr/src/usr.bin/uucp/libuu/subdir.c | 22 +- usr/src/usr.bin/uucp/libuu/sysacct.c | 8 +- usr/src/usr.bin/uucp/libuu/systat.c | 60 +- usr/src/usr.bin/uucp/libuu/ulockf.c | 147 +-- usr/src/usr.bin/uucp/libuu/uucpdefs.c | 28 +- usr/src/usr.bin/uucp/libuu/uucpname.c | 44 +- usr/src/usr.bin/uucp/libuu/versys.c | 12 +- usr/src/usr.bin/uucp/libuu/xqt.c | 55 +- usr/src/usr.bin/uucp/port/getwd.c | 36 +- usr/src/usr.bin/uucp/port/index.c | 12 +- usr/src/usr.bin/uucp/port/ioctl.c | 3 +- usr/src/usr.bin/uucp/shio.c | 35 +- usr/src/usr.bin/uucp/uucico/cntrl.c | 397 ++++--- usr/src/usr.bin/uucp/uucico/condevs.c | 1478 +++--------------------- usr/src/usr.bin/uucp/uucico/conn.c | 487 +++++--- usr/src/usr.bin/uucp/uucico/gio.c | 143 +-- usr/src/usr.bin/uucp/uucico/gnsys.c | 47 +- usr/src/usr.bin/uucp/uucico/imsg.c | 79 +- usr/src/usr.bin/uucp/uucico/pk.h | 2 +- usr/src/usr.bin/uucp/uucico/pk0.c | 314 ++--- usr/src/usr.bin/uucp/uucico/pk1.c | 250 ++-- usr/src/usr.bin/uucp/uuclean/uuclean.c | 48 +- usr/src/usr.bin/uucp/uucp/uucp.c | 137 ++- usr/src/usr.bin/uucp/uulog/uulog.c | 2 +- usr/src/usr.bin/uucp/uuname/uuname.c | 14 +- usr/src/usr.bin/uucp/uupoll/uupoll.c | 19 +- usr/src/usr.bin/uucp/uusend/uusend.c | 102 +- usr/src/usr.bin/uucp/uusnap/uusnap.c | 254 ++-- usr/src/usr.bin/uucp/uux/uux.c | 141 ++- usr/src/usr.bin/uucp/uuxqt/uuxqt.c | 285 +++-- usr/src/usr.bin/uudecode/uudecode.c | 2 +- usr/src/usr.bin/uuencode/uuencode.c | 6 +- 48 files changed, 2521 insertions(+), 2946 deletions(-) diff --git a/usr/src/libexec/uucpd/uucpd.c b/usr/src/libexec/uucpd/uucpd.c index 62f23eff24..d56b1a59ee 100644 --- a/usr/src/libexec/uucpd/uucpd.c +++ b/usr/src/libexec/uucpd/uucpd.c @@ -1,42 +1,230 @@ #ifndef lint -static char sccsid[] = "@(#)uucpd.c 5.1 (BERKELEY) %G%"; +static char sccsid[] = "@(#)uucpd.c 5.2 (Berkeley) %G%"; #endif /* - * UUCP server daemon - * Looks for attempts to connect on our uucp socket. When it - * finds one it execs uucico to handle it. - * - * Invoked by inetd. + * 4.2BSD TCP/IP server for uucico + * uucico's TCP channel causes this server to be run at the remote end. */ -#include -#include +#include "uucp.h" +#include #include -#include +#include #include +#include #include +#include +#include +#include +#include -#define UUCICO "/usr/lib/uucp/uucico" - -extern int errno; +char lastlog[] = "/usr/adm/lastlog"; +struct sockaddr_in hisctladdr; +int hisaddrlen = sizeof hisctladdr; +struct sockaddr_in myctladdr; +int mypid; main(argc, argv) - int argc; - char **argv; +int argc; +char **argv; { - int status, fromlen; - struct sockaddr_in from; + register int s, tcp_socket; + struct servent *sp; + extern int errno; + int dologout(); - fromlen = sizeof(from); - if (getpeername(0, &from, &fromlen) < 0) { +#ifdef BSDINETD + close(1); close(2); + dup(0); dup(0); + hisaddrlen = sizeof (hisctladdr); + if (getpeername(0, &hisctladdr, &hisaddrlen) < 0) { fprintf(stderr, "%s: ", argv[0]); perror("getpeername"); _exit(1); } - - execl(UUCICO, "UUCICO", "-r0", "-v", 0); - openlog("uucpd", 0, 0); - syslog(LOG_ERR, "%s: %m", UUCICO); + if (fork() == 0) + doit(&hisctladdr); + dologout(); exit(1); +#else !BSDINETD + sp = getservbyname("uucp", "tcp"); + if (sp == NULL){ + perror("uucpd: getservbyname"); + exit(1); + } + if ((s=open("/dev/tty", 2)) >= 0){ + ioctl(s, TIOCNOTTY, (char *)0); + close(s); + } + + bzero((char *)&myctladdr, sizeof (myctladdr)); + tcp_socket = socket(AF_INET, SOCK_STREAM, 0, 0); + if ( tcp_socket<0 ) { + perror("uucpd: socket"); + exit(1); + } + myctladdr.sin_port = sp->s_port; + if (bind(tcp_socket, (char *)&myctladdr, sizeof (myctladdr), 0) < 0) { + perror("uucpd: bind"); + exit(1); + } + signal(SIGCHLD, dologout); + listen(tcp_socket, 5); /* 5's as good as any */ + + for(;;) { + s = accept(tcp_socket, &hisctladdr, &hisaddrlen); + if (s < 0){ + if (errno == EINTR) + continue; + perror("uucpd: accept"); + exit(1); + } + if (fork()== 0) { + close(0); close(1); close(2); + dup(s); dup(s); dup(s); + close(tcp_socket);close(s); + doit(&hisctladdr); + exit(1); + } + close(s); + } +#endif +} + +doit(sinp) +struct sockaddr_in *sinp; +{ + char ebuf[32]; + char user[64]; + char passwd[64]; + char *xpasswd, *crypt(); + struct passwd *pw, *getpwnam(); + + alarm(60); + if (readline(user, sizeof user) < 0) { + fprintf(stderr, "user read\n"); + return; + } + /* truncate username to 8 characters */ + user[8] = '\0'; + pw = getpwnam(user); + if (pw == NULL) { + fprintf(stderr, "user unknown\n"); + return; + } + if (strcmp(pw->pw_shell, UUCICO)) { + fprintf(stderr, "Login incorrect."); + return; + } + if (pw->pw_passwd && *pw->pw_passwd != '\0') { + if (readline(passwd, sizeof passwd) < 0) { + fprintf(stderr, "passwd read\n"); + return; + } + xpasswd = crypt(passwd, pw->pw_passwd); + if (strcmp(xpasswd, pw->pw_passwd)) { + fprintf(stderr, "Login incorrect."); + return; + } + } + alarm(0); + dologin(pw, sinp); + setegid(pw->pw_gid); + initgroups(pw->pw_name, pw->pw_gid); + chdir(pw->pw_dir); + seteuid(pw->pw_uid); + execl(UUCICO, "uucico", (char *)0); + perror("uucico server: execl"); +} + +readline(p, n) + register char *p; + register int n; +{ + char c; + + while (n-- > 0) { + if (read(0, &c, 1) <= 0) + return(-1); + c &= 0177; + if (c == '\n' || c == '\r') { + *p = '\0'; + return(0); + } + *p++ = c; + } + return(-1); +} + +#include +#include + +#define SCPYN(a, b) strncpy(a, b, sizeof (a)) + +struct utmp utmp; + +dologout() +{ + union wait status; + int pid, wtmp; + +#ifdef BSDINETD + while ((pid=wait(&status)) > 0 ) { +#else !BSDINETD + while ((pid=wait3(&status,WNOHANG,0)) > 0 ) { +#endif !BSDINETD + wtmp = open("/usr/adm/wtmp", O_WRONLY|O_APPEND); + if (wtmp >= 0) { + sprintf(utmp.ut_line, "uucp%.4d", pid); + SCPYN(utmp.ut_name, ""); + SCPYN(utmp.ut_host, ""); + utmp.ut_time = time(0); + (void) write(wtmp, (char *)&utmp, sizeof (utmp)); + (void) close(wtmp); + } + } +} + +/* + * Record login in wtmp file. + */ +dologin(pw, sin) +struct passwd *pw; +struct sockaddr_in *sin; +{ + char line[32]; + char remotehost[32]; + int wtmp, f; + struct hostent *hp = gethostbyaddr(&sin->sin_addr, + sizeof (struct in_addr), AF_INET); + + if (hp) { + strncpy(remotehost, hp->h_name, sizeof (remotehost)); + endhostent(); + } else + strncpy(remotehost, inet_ntoa(sin->sin_addr), + sizeof (remotehost)); + wtmp = open("/usr/adm/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); + utmp.ut_time = time(0); + (void) write(wtmp, (char *)&utmp, sizeof (utmp)); + (void) close(wtmp); + } + if ((f = open(lastlog, 2)) >= 0) { + struct lastlog ll; + + time(&ll.ll_time); + lseek(f, (long)pw->pw_uid * sizeof(struct lastlog), 0); + strcpy(line, remotehost); + SCPYN(ll.ll_line, line); + SCPYN(ll.ll_host, remotehost); + (void) write(f, (char *) &ll, sizeof ll); + (void) close(f); + } } diff --git a/usr/src/usr.bin/uucp/assert.c b/usr/src/usr.bin/uucp/assert.c index d29ab46f9d..4f84400d15 100644 --- a/usr/src/usr.bin/uucp/assert.c +++ b/usr/src/usr.bin/uucp/assert.c @@ -23,25 +23,30 @@ char *s1, *s2; time_t clock; int pid; - if (Debug) - errlog = stderr; - else { + errlog = NULL; + if (!Debug) { int savemask; savemask = umask(LOGMASK); errlog = fopen(ERRLOG, "a"); umask(savemask); } if (errlog == NULL) - return; + errlog = stderr; pid = getpid(); fprintf(errlog, "ASSERT ERROR (%.9s) ", Progname); fprintf(errlog, "pid: %d ", pid); time(&clock); tp = localtime(&clock); - fprintf(errlog, "(%d/%d-%d:%02d) ", tp->tm_mon + 1, +#ifdef USG + fprintf(errlog, "(%d/%d-%2.2d:%2.2d) ", tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min); - fprintf(errlog, "%s %s (%d)\n", s1, s2, i1); - fclose(errlog); +#else + fprintf(errlog, "(%d/%d-%02d:%02d) ", tp->tm_mon + 1, + tp->tm_mday, tp->tm_hour, tp->tm_min); +#endif + fprintf(errlog, "%s %s (%d)\n", s1 ? s1 : "", s2 ? s2 : "", i1); + if (errlog != stderr) + fclose(errlog); return; } diff --git a/usr/src/usr.bin/uucp/gnamef.c b/usr/src/usr.bin/uucp/gnamef.c index 831940970e..cebe07df51 100644 --- a/usr/src/usr.bin/uucp/gnamef.c +++ b/usr/src/usr.bin/uucp/gnamef.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)gnamef.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)gnamef.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" @@ -10,10 +10,8 @@ static char sccsid[] = "@(#)gnamef.c 5.2 (Berkeley) %G%"; #include #endif -/******* - * gnamef(dirp, filename) get next file name from directory - * DIR *dirp; - * char *filename; +/* + * get next file name from directory * * return codes: * 0 - end of directory read @@ -26,15 +24,17 @@ register char *filename; { register struct direct *dentp; - while (1) { - if ((dentp = readdir(dirp)) == NULL) - return(0); + for (;;) { + if ((dentp = readdir(dirp)) == NULL) { + return 0; + } if (dentp->d_ino != 0) break; } - /* Truncate filename. This may become a problem someday. rti!trt */ + /* Truncate filename. This may become a problem someday. */ strncpy(filename, dentp->d_name, NAMESIZE-1); filename[NAMESIZE-1] = '\0'; - return(1); + DEBUG(99,"gnamef returns %s\n",filename); + return 1; } diff --git a/usr/src/usr.bin/uucp/includes/uucp.h b/usr/src/usr.bin/uucp/includes/uucp.h index 1ee4923d1a..f546991e3c 100644 --- a/usr/src/usr.bin/uucp/includes/uucp.h +++ b/usr/src/usr.bin/uucp/includes/uucp.h @@ -1,4 +1,4 @@ -/* uucp.h 5.3 84/09/04 */ +/* uucp.h 5.4 85/01/22 */ #include "stdio.h" @@ -28,13 +28,14 @@ * Systems running 3Com's UNET will have the getmyhname() call. * If you want to, define GETMYHNAME. * - * You should also define MYNANE to be your uucp name. + * You should also define MYNAME to be your uucp name. * * For each of the above that are defined, uucp checks them in order. * It stops on the first method that returns a non null name. * If everything fails, it uses "unknown" for the system name. */ #define GETHOSTNAME +/*#define CCWHOAMI */ /* If the above fails ... */ #define MYNAME "erewhon" @@ -44,28 +45,35 @@ * Otherwise, define EX_NOHOST, EX_CANTCREAT, and EX_NOINPUT. */ #include -/*#define EX_NOHOST 101*/ -/*#define EX_CANTCREAT 1*/ -/*#define EX_NOINPUT 2*/ - -/* define UUDIR for uucp subdirectory kludge (recommended) */ -#define UUDIR +/*#define EX_NOINPUT 66*/ +/*#define EX_NOHOST 68*/ +/*#define EX_CANTCREAT 73*/ /* * Define the various kinds of connections to include. * The complete list is in the condevs array in condevs.c */ -#define DN11 /* standard dialer */ -/*#define DATAKIT /* ATT's datakit */ +/*#define DN11 /* standard dialer */ +/*#define DATAKIT /* ATT's datakit */ /*#define PNET /* Purdue network */ /*#define DF02 /* Dec's DF02/DF03 */ -#define HAYES /* Hayes' Smartmodem */ -#define VENTEL /* ventel dialer */ -#define VADIC /* Racal-Vadic 3450 */ -/*#define RVMACS /* Racal-Vadic MACS 831 */ -#define TCPNET /* 4.2 TCP Network */ -/*#define UNET /* 3Com's UNET */ +/*#define HAYES /* Hayes' Smartmodem */ +/*#define VENTEL /* ventel dialer */ +/*#define VADIC /* Racal-Vadic 345x */ +/*#define VA212 /* Racal-Vadic 212 */ +/*#define VA811S /* Racal-Vadic 811S dialer, 831 adaptor */ +#define VA820 /* Racal-Vadic 820 dialer, 831 adaptor */ +/*#define RVMACS /* Racal-Vadic MACS 820 dialer, 831 adaptor */ +/*#define VMACS /* Racal-Vadic MACS 811 dialer, 831 adaptor */ +/*#define UNETTCP /* 3Com's UNET */ +#define BSDTCP /* 4.2bsd TCP/IP */ +#define PAD /* X.25 PAD */ /*#define MICOM /* micom mux port */ +/*#define NOVATION /* Novation modem */ + +#if defined(UNETTCP) || defined(BSDTCP) +#define TCPIP +#endif #ifdef VENTEL /* @@ -85,25 +93,38 @@ * You will probably also have to set LIBNDIR in Makefile. * Otherwise, is assumed to have the Berkeley directory definitions. */ -/*#define NDIR*/ +/*#define NDIR */ + +/* + * If yours is a BTL system III, IV, or so-on site, define USG. + */ +/*#define USG */ /* - * If yours is a BTL system III, IV, or so-on site, define SYSIII. - * Conditional compilations should produce the right code, - * but if it doesn't (the compiler will probably complain loudly), - * make the needed adjustments and guard the code with - * #ifdef SYSIII, (code for system III), #else, (code for V7), #endif + * If you are running 4.2bsd, define BSD4_2 */ -/*#define SYSIII*/ +#define BSD4_2 + +/* + * If you are using /etc/inetd with 4.2bsd, define BSDINETD + */ +#define BSDINETD + +/*#define VMSDTR /* Turn on modem control on vms(works DTR) for + develcon and gandalf ports to gain access */ /* define the last characters for ACU */ -/* burl!lda, rti!trt, isn't "<" more widely used than "-"? */ -/* rti!trt: use -< as is done in 4.1c uucp */ #define ACULAST "-<" /* define the value of WFMASK - for umask call - used for all uucp work files */ #define WFMASK 0137 +/* define UUSTAT if you need "uustat" command */ +/* #define UUSTAT */ + +/* define UUSUB if you need "uusub" command */ +/* #define UUSUB /**/ + /* define the value of LOGMASK - for LOGFILE, SYSLOG, ERRLOG */ #define LOGMASK 0133 @@ -112,9 +133,39 @@ /* and 444 is minimal (minimally useful, maximally annoying) */ #define BASEMODE 0666 -/* All users with getuid() <= PRIV_UIDS are 'privileged'. */ -/* Was 10, reduced to 3 as suggested by duke!dbl (David Leonard) */ -#define PRIV_UIDS 3 +/* + * Define NOSTRANGERS if you don't want to accept transactions from + * sites that are not in your L.sys file (see cico.c) + */ +#define NOSTRANGERS +/* + * Traditionally LCK (lock) files have been kept in /usr/spool/uucp. + * If you want that define LOCKDIR to be ".". + * If you want the locks kept in a subdirectory, define LOCKDIR as "LCK.". + * Good news about LCK. subdirectory: the directory can be mode 777 so + * unprivileged programs can share the uucp locking system, + * and the subdirectory keeps down clutter in the main directory. + * The BAD news: you have to change 'tip' and another programs that + * know where the LCK files are kept, and you have to change your /etc/rc + * if your rc cleans out the lock files (as it should). + */ +/*#define LOCKDIR "LCK." */ +#define LOCKDIR "." + +/* + * If you want uucp and uux to copy the data files by default, + * don't define DONTCOPY (This is the way older 4bsd uucps worked) + * If you want uucp and uux to use the original files instead of + * copies, define DONTCOPY (This is the way System III and V work) + */ +#define DONTCOPY + +/* + * Very few (none I know of) systems use the sequence checking feature. + * If you are not going to use it (hint: you are not), + * do not define GNXSEQ. This saves precious room on PDP11s. + */ +/*#define GNXSEQ/* comment this out to save space */ #define XQTDIR "/usr/spool/uucp/XTMP" #define SQFILE "/usr/lib/uucp/SQFILE" @@ -128,7 +179,7 @@ #define CMDFILE "/usr/lib/uucp/L.cmds" #define SPOOL "/usr/spool/uucp" -#define SQLOCK "/usr/spool/uucp/LCK.SQ" +#define SQLOCK "LCK.SQ" #define SYSLOG "/usr/spool/uucp/SYSLOG" #define PUBDIR "/usr/spool/uucppublic" @@ -139,21 +190,24 @@ #define LOGFILE "/usr/spool/uucp/LOGFILE" #define ERRLOG "/usr/spool/uucp/ERRLOG" +#define CMDSDIR "/usr/spool/uucp/C." +#define DATADIR "/usr/spool/uucp/D." +#define XEQTDIR "/usr/spool/uucp/X." #define RMTDEBUG "AUDIT" +#define CORRUPT "CORRUPT" #define SQTIME 60 #define TRYCALLS 2 /* number of tries to dial call */ -/*define PROTODEBUG = 1 if testing protocol - introduce errors */ -#define DEBUG(l, f, s) if (Debug >= l) fprintf(stderr, f, s); else +#define LLEN 50 +#define MAXRQST 250 -#define ASSERT(e, s1, s2, i1) if (!(e)) {\ -assert(s1, s2, i1);\ -cleanup(FAIL);} else +#define DEBUG(l, f, s) if (Debug >= l) fprintf(stderr, f, s); else +#define ASSERT(e, s1, s2, i1) if (!(e)) {assert(s1, s2, i1);cleanup(FAIL);}else #define SAME 0 -#define ANYREAD 04 +#define ANYREAD 0004 #define ANYWRITE 02 #define FAIL -1 #define SUCCESS 0 @@ -161,15 +215,16 @@ cleanup(FAIL);} else #define STBNULL (struct sgttyb *) 0 #define MASTER 1 #define SLAVE 0 -#define MAXFULLNAME 250 +#define MAXFULLNAME 255 #define MAXMSGTIME 45 -#define NAMESIZE 15 +#define NAMESIZE 255 #define EOTMSG "\04\n\04\n" #define CALLBACK 1 +#define ONEDAY 86400L /* commands */ #define SHELL "/bin/sh" -#define MAIL "mail" +#define MAIL "/usr/lib/sendmail" #define UUCICO "/usr/lib/uucp/uucico" #define UUXQT "/usr/lib/uucp/uuxqt" #define UUCP "uucp" @@ -202,12 +257,16 @@ struct condev { /* This structure tells about a device */ struct Devices { - char D_type[20]; - char D_line[20]; - char D_calldev[20]; - char D_class[20]; - int D_speed; - char D_brand[20]; /* brand name, as 'Hayes' or 'Vadic' */ +#define D_type D_arg[0] +#define D_line D_arg[1] +#define D_calldev D_arg[2] +#define D_class D_arg[3] +#define D_brand D_arg[4] +#define D_CHAT 5 + int D_numargs; + int D_speed; + char *D_arg[20]; + char D_argbfr[100]; }; /* system status stuff */ @@ -217,9 +276,10 @@ struct Devices { #define SS_CALLBACK 2 #define SS_INPROGRESS 3 #define SS_BADSEQ 5 +#define SS_WRONGTIME 6 /* fail/retry parameters */ -#define RETRYTIME 3300 +#define RETRYTIME 600 #define MAXRECALLS 20 /* stuff for command execution */ @@ -230,6 +290,7 @@ struct Devices { #define X_USER 'U' #define X_SENDFILE 'S' #define X_NONOTI 'N' +#define X_RETURNTO 'R' #define X_NONZERO 'Z' #define X_LOCK "LCK.XQT" #define X_LOCKTIME 3600 @@ -242,31 +303,26 @@ extern char User[]; extern char Loginuser[]; extern char *Spool; extern char Myname[]; +extern char Myfullname[]; extern int Debug; -extern int Pkdebug; -extern int Pkdrvon; extern int Bspeed; extern char Wrkdir[]; extern long Retrytime; -extern int Unet; +extern short Usrf; +extern int IsTcpIp; extern char Progname[]; extern int (*CU_end)(); extern struct condev condevs[]; +extern int nologinflag; +extern char NOLOGIN[]; -#ifdef UUDIR -#define subfile(s) SubFile(s) -#define subdir(d, p) SubDir(d, p) -#define subchdir(d) SubChDir(d) -extern char DLocal[], DLocalX[], *SubFile(), *SubDir(); -#else -#define subfile(s) s -#define subdir(d, p) d -#define subchdir(d) chdir(d) -#endif +extern char DLocal[], DLocalX[], *subfile(), *subdir(); /* Commonly called routines which return non-int value */ extern char *ttyname(), *strcpy(), *strcat(), *index(), *rindex(), - *fgets(), *calloc(), *malloc(), + *fgets(), *calloc(), *malloc(), *fdig(), *ttyname(), *cfgets(); extern long lseek(); extern FILE *rpopen(); + +extern char _FAILED[], CANTOPEN[], DEVNULL[]; diff --git a/usr/src/usr.bin/uucp/libuu/cpmv.c b/usr/src/usr.bin/uucp/libuu/cpmv.c index 41d634c9a9..a7d9ad3023 100644 --- a/usr/src/usr.bin/uucp/libuu/cpmv.c +++ b/usr/src/usr.bin/uucp/libuu/cpmv.c @@ -1,12 +1,11 @@ #ifndef lint -static char sccsid[] = "@(#)cpmv.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)cpmv.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" #include #include - /*** * xcp(f1, f2) copy f1 to f2 * char *f1, *f2; @@ -19,13 +18,13 @@ char *f1, *f2; { char buf[BUFSIZ]; register int len; - register FILE *fp1, *fp2; + register int fp1, fp2; char *lastpart(); - char full[MAXFULLNAME]; + char full[100]; struct stat s; - if ((fp1 = fopen(subfile(f1), "r")) == NULL) - return(FAIL); + if ((fp1 = open(subfile(f1), 0)) < 0) + return FAIL; strcpy(full, f2); if (stat(subfile(f2), &s) == 0) { /* check for directory */ @@ -35,15 +34,19 @@ char *f1, *f2; } } DEBUG(4, "full %s\n", full); - if ((fp2 = fopen(subfile(full), "w")) == NULL) { - fclose(fp1); - return(FAIL); + if ((fp2 = creat(subfile(full), 0666)) < 0) { + close(fp1); + return FAIL; } - while((len = fread(buf, sizeof (char), BUFSIZ, fp1)) > 0) - fwrite(buf, sizeof (char), len, fp2); - fclose(fp1); - fclose(fp2); - return(0); + while((len = read(fp1, buf, BUFSIZ)) > 0) + if (write(fp2, buf, len) != len) { + len = -1; + break; + } + + close(fp1); + close(fp2); + return len < 0 ? FAIL: SUCCESS; } @@ -64,8 +67,8 @@ register char *f1, *f2; ret = xcp(f1, f2); if (ret == 0) unlink(subfile(f1)); - return(ret); + return ret; } unlink(subfile(f1)); - return(0); + return 0; } diff --git a/usr/src/usr.bin/uucp/libuu/expfile.c b/usr/src/usr.bin/uucp/libuu/expfile.c index d5a691a828..e67339bc79 100644 --- a/usr/src/usr.bin/uucp/libuu/expfile.c +++ b/usr/src/usr.bin/uucp/libuu/expfile.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)expfile.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)expfile.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" @@ -19,7 +19,7 @@ expfile(file) char *file; { register char *fpart, *p; - char user[20], *up; + char user[WKDSIZE], *up; char full[MAXFULLNAME]; int uid; @@ -28,28 +28,27 @@ char *file; return(1); case '~': for (fpart = file + 1, up = user; *fpart != '\0' - && *fpart != '/' && up < user+sizeof(user)-1; fpart++) + && *fpart != '/'; fpart++) *up++ = *fpart; *up = '\0'; - /* ll1b.105, mn, Mark Nettleingham, defend against - * null login name in /etc/passwd - */ if (!*user || gninfo(user, &uid, full) != 0) { strcpy(full, PUBDIR); } strcat(full, fpart); strcpy(file, full); - return(1); + return 1; default: p = index(file, '/'); - sprintf(full, "%s/%s", Wrkdir, file); + strcpy(full, Wrkdir); + strcat(full, "/"); + strcat(full, file); strcpy(file, full); if (Wrkdir[0] == '\0') - return(FAIL); + return FAIL; else if (p != NULL) - return(1); - return(0); + return 1; + return 0; } } @@ -69,10 +68,10 @@ char *name; ret = stat(subfile(name), &s); if (ret < 0) - return(0); + return 0; if ((s.st_mode & S_IFMT) == S_IFDIR) - return(1); - return(0); + return 1; + return 0; } @@ -87,26 +86,26 @@ mkdirs(name) char *name; { int ret, mask; - char cmd[100], dir[100]; + char cmd[MAXFULLNAME], dir[MAXFULLNAME]; register char *p; for (p = dir + 1;; p++) { strcpy(dir, name); if ((p = index(p, '/')) == NULL) - return(0); + return 0; *p = '\0'; if (isdir(dir)) continue; - /* rti!trt: add chmod ala 4.1c uucp */ sprintf(cmd, "mkdir %s;chmod 0777 %s", dir, dir); DEBUG(4, "mkdir - %s\n", dir); mask = umask(0); ret = shio(cmd, CNULL, CNULL, User); umask(mask); if (ret != 0) - return(FAIL); + return FAIL; } + /* NOTREACHED */ } /*** @@ -121,11 +120,11 @@ register char *file; { if (expfile(file) != FAIL) - return(0); + return 0; /* could not expand file name */ /* the gwd routine failed */ - fprintf(stderr, "Can't expand filename (%s). Pwd failed.\n", file+1); - return(FAIL); + logent("CAN'T EXPAND FILENAME - PWD FAILED", file+1); + return FAIL; } diff --git a/usr/src/usr.bin/uucp/libuu/gename.c b/usr/src/usr.bin/uucp/libuu/gename.c index ff6457dcf7..3eded76fc6 100644 --- a/usr/src/usr.bin/uucp/libuu/gename.c +++ b/usr/src/usr.bin/uucp/libuu/gename.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)gename.c 5.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)gename.c 5.4 (Berkeley) %G%"; #endif #include "uucp.h" @@ -13,16 +13,14 @@ static char sccsid[] = "@(#)gename.c 5.3 (Berkeley) %G%"; * * return codes: none */ - gename(pre, sys, grade, file) char pre, *sys, grade, *file; { - static char sqnum[SEQLEN+1]; + static char sqnum[5]; getseq(sqnum); sprintf(file, "%c.%.7s%c%.*s", pre, sys, grade, SEQLEN, sqnum); DEBUG(4, "file - %s\n", file); - return; } @@ -56,7 +54,7 @@ register char *snum; sleep(5); } - ASSERT(i < SLOCKTRIES, "CAN NOT GET", "SEQLOCK", 0); + ASSERT(i < SLOCKTRIES, "CAN NOT GET", SEQLOCK, 0); if ((fd = open(SEQFILE, 2)) >= 0) { int alphalen; @@ -65,11 +63,12 @@ register char *snum; alphalen = strlen(alphabet); read(fd, snum, SEQLEN); + /* initialize rand() for possible use */ + srand((int)time((time_t *)0)); /* increment the penultimate character */ for (i = SEQLEN - 2; i >= 0; --i) { if ((p = index(alphabet, snum[i])) == NULL) { - /* drastic but effective */ - snum[i] = alphabet[alphalen - 1]; + p = &alphabet[rand() % alphalen]; DEBUG(6, "bad seqf: %s\n", snum); } if (++p < &alphabet[alphalen]) { diff --git a/usr/src/usr.bin/uucp/libuu/getargs.c b/usr/src/usr.bin/uucp/libuu/getargs.c index b2461a40a9..45b07f41d4 100644 --- a/usr/src/usr.bin/uucp/libuu/getargs.c +++ b/usr/src/usr.bin/uucp/libuu/getargs.c @@ -1,13 +1,10 @@ #ifndef lint -static char sccsid[] = "@(#)getargs.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)getargs.c 5.2 (Berkeley) %G%"; #endif -#include +#include "uucp.h" -/******* - * getargs(s, arps) - * char *s, *arps[]; - * +/* * getargs - this routine will generate a vector of * pointers (arps) to the substrings in string "s". * Each substring is separated by blanks and/or tabs. @@ -21,12 +18,13 @@ static char sccsid[] = "@(#)getargs.c 5.1 (Berkeley) %G%"; * is used all over the place. Its features may be useful * but a separate fancy_getargs() should be called instead. * - * return - the number of subfields. + * return - the number of subfields, or -1 if >= maxargs. */ -getargs(s, arps) +getargs(s, arps, maxargs) register char *s; char *arps[]; +int maxargs; { register int i; #ifdef FANCYARGS @@ -36,8 +34,7 @@ char *arps[]; i = 0; #ifndef FANCYARGS - for (;;) { - arps[i] = NULL; + while (i < maxargs) { while (*s == ' ' || *s == '\t') *s++ = '\0'; if (*s == '\n') @@ -50,7 +47,7 @@ char *arps[]; s++; } #else - for (;;) { + while (i < maxargs) { while (*s == ' ' || *s == '\t') ++s; if (*s == '\n' || *s == '\0') @@ -91,7 +88,9 @@ char *arps[]; } *sp++ = 0; } - arps[i] = NULL; #endif - return(i); + if (i >= maxargs) + return FAIL; + arps[i] = NULL; + return i; } diff --git a/usr/src/usr.bin/uucp/libuu/getprm.c b/usr/src/usr.bin/uucp/libuu/getprm.c index 931d82594a..ece8acb99b 100644 --- a/usr/src/usr.bin/uucp/libuu/getprm.c +++ b/usr/src/usr.bin/uucp/libuu/getprm.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)getprm.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)getprm.c 5.2 (Berkeley) %G%"; #endif #include @@ -10,10 +10,8 @@ static char sccsid[] = "@(#)getprm.c 5.1 (Berkeley) %G%"; #define HASSYSPART 1 -/******* - * char * - * getprm(s, prm) get next parameter from s - * char *s, *prm; +/* + * get next parameter from s * * return - pointer to next character in s */ @@ -30,13 +28,13 @@ register char *s, *prm; *prm = '\0'; if (*s == '\0') - return(NULL); + return NULL; if (*s == '>' || *s == '<' || *s == '|' || *s == ';' || *s == '&') { *prm++ = *s++; *prm = '\0'; - return(s); + return s; } /* look for quoted argument */ @@ -46,7 +44,7 @@ register char *s, *prm; while (c != s) *prm++ = *s++; *prm = '\0'; - return(s); + return s; } } @@ -57,22 +55,21 @@ register char *s, *prm; while (c != s) *prm++ = *s++; *prm = '\0'; - return(s); + return s; } } while (*s != ' ' && *s != '\t' && *s != '<' - && *s != '>' && *s != '|' && *s != '\0' - && *s != '&' && *s != ';' && *s != '\n') + && *s != '>' && *s != '|' && *s != '\0' + && *s != '&' && *s != ';' && *s != '\n') *prm++ = *s++; *prm = '\0'; - return(s); + return s; } -/*** - * split(name, sys, rest) split into system and file part - * char *name, *sys, *rest; +/* + * split into system and file part * * return codes: * NOSYSPART @@ -95,14 +92,14 @@ char *sys; *rest++ = *name++; *rest = '\0'; *sys = '\0'; - return(NOSYSPART); + return NOSYSPART; } } if ((c = index(name, '!')) == NULL) { strcpy(rest, name); *sys = '\0'; - return(NOSYSPART); + return NOSYSPART; } *c = '\0'; @@ -111,5 +108,5 @@ char *sys; break; strcpy(rest, ++c); - return(HASSYSPART); + return HASSYSPART; } diff --git a/usr/src/usr.bin/uucp/libuu/getpwinfo.c b/usr/src/usr.bin/uucp/libuu/getpwinfo.c index ce2494f26d..e6c54e00f2 100644 --- a/usr/src/usr.bin/uucp/libuu/getpwinfo.c +++ b/usr/src/usr.bin/uucp/libuu/getpwinfo.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)getpwinfo.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)getpwinfo.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" @@ -26,28 +26,26 @@ register char *path, *name; if ((l = getlogin()) != NULL) { pwd = getpwnam(l); - if (pwd->pw_uid == uid) + if (pwd->pw_uid == uid || *l == 'U') goto setup; } if ((pwd = getpwuid(uid)) == NULL) { /* can not find uid in passwd file */ *path = '\0'; - return(FAIL); + return FAIL; } setup: strcpy(path, pwd->pw_dir); strcpy(name, pwd->pw_name); - return(0); + return SUCCESS; } -/*** - * gninfo(name, uid, path) get passwd file info for name - * char *path, *name; - * int *uid; +/* + * get passwd file info for name * - * return codes: 0 | FAIL + * return codes: SUCCESS | FAIL */ gninfo(name, uid, path) @@ -60,12 +58,10 @@ int *uid; if ((pwd = getpwnam(name)) == NULL) { /* can not find name in passwd file */ *path = '\0'; - return(FAIL); + return FAIL; } strcpy(path, pwd->pw_dir); *uid = pwd->pw_uid; - return(0); + return SUCCESS; } - - diff --git a/usr/src/usr.bin/uucp/libuu/gnxseq.c b/usr/src/usr.bin/uucp/libuu/gnxseq.c index 57c6af8c1a..c5cd4be941 100644 --- a/usr/src/usr.bin/uucp/libuu/gnxseq.c +++ b/usr/src/usr.bin/uucp/libuu/gnxseq.c @@ -1,10 +1,16 @@ #ifndef lint -static char sccsid[] = "@(#)gnxseq.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)gnxseq.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" #include +#ifdef BSD4_2 #include +#else sane +#include +#endif sane + +#ifdef GNXSEQ extern time_t time(); @@ -62,9 +68,16 @@ char *rmtname; count = ++ct; time(&clock); tp = localtime(&clock); - fprintf(fp1, "%s %d %d/%d-%d:%02d\n", name, ct, +#ifdef USG + fprintf(fp1, "%s %d %d/%d-%2.2d:%2.2d\n", name, ct, tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min); +#endif +#ifndef USG + fprintf(fp1, "%s %d %d/%d-%02d:%02d\n", name, ct, + tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, + tp->tm_min); +#endif while (fgets(buf, BUFSIZ, fp0) != NULL) fputs(buf, fp1); } @@ -88,7 +101,7 @@ cmtseq() { register int ret; - if ((ret = access(SQTMP, 0400)) != 0) { + if ((ret = access(SQTMP, 04)) != 0) { rmlock(SQLOCK); return(0); } @@ -108,3 +121,4 @@ ulkseq() unlink(SQTMP); rmlock(SQLOCK); } +#endif GNXSEQ diff --git a/usr/src/usr.bin/uucp/libuu/lastpart.c b/usr/src/usr.bin/uucp/libuu/lastpart.c index d0280be404..ccb84a983b 100644 --- a/usr/src/usr.bin/uucp/libuu/lastpart.c +++ b/usr/src/usr.bin/uucp/libuu/lastpart.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)lastpart.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)lastpart.c 5.2 (Berkeley) %G%"; #endif /******* @@ -15,10 +15,11 @@ lastpart(file) register char *file; { register char *c; + char *rindex(); - c = file + strlen(file); - while (c >= file) - if (*(--c) == '/') - break; - return(++c); + c = rindex(file, '/'); + if (c) + return c; + else + return file; } diff --git a/usr/src/usr.bin/uucp/libuu/logent.c b/usr/src/usr.bin/uucp/libuu/logent.c index e9eb795b5f..45de7e1cb3 100644 --- a/usr/src/usr.bin/uucp/libuu/logent.c +++ b/usr/src/usr.bin/uucp/libuu/logent.c @@ -1,10 +1,17 @@ #ifndef lint -static char sccsid[] = "@(#)logent.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)logent.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" #include +#ifdef BSD4_2 #include +#else +#include +#endif +#if defined(USG) || defined(BSD4_2) +#include +#endif extern time_t time(); @@ -17,15 +24,13 @@ extern time_t time(); * writes the buffer out. This could mangle things but * it isn't likely. -- ittvax!swatt * - * If the files could be opened with "guaranteed append to end", - * the lseeks could be removed. - * Using fseek would be slightly cleaner, - * but would mangle things slightly more often. + * Under USG UNIX & 4.2BSD, the files are opened with "guaranteed append to end" + * and the lseeks are removed. */ -FILE *Lp = NULL; -FILE *Sp = NULL; +static FILE *Lp = NULL; +static FILE *Sp = NULL; static Ltried = 0; static Stried = 0; @@ -43,9 +48,16 @@ char *text, *status; if (Lp == NULL) { if (!Ltried) { int savemask; +#if defined(USG) || defined(BSD4_2) + int flags; +#endif savemask = umask(LOGMASK); Lp = fopen (LOGFILE, "a"); umask(savemask); +#if defined(USG) || defined(BSD4_2) + flags = fcntl(fileno(Lp), F_GETFL, 0); + fcntl(fileno(Lp), F_SETFL, flags|O_APPEND); +#endif } Ltried = 1; if (Lp == NULL) @@ -70,22 +82,42 @@ register FILE *fp; extern struct tm *localtime(); time_t clock; + if (text == NULL) + text = ""; + if (status == NULL) + status = ""; if (!pid) pid = getpid(); + if (Rmtname[0] == '\0') + strcpy(Rmtname, Myname); time(&clock); tp = localtime(&clock); fprintf(fp, "%s %s ", User, Rmtname); - fprintf(fp, "(%d/%d-%d:%02d-%d) ", tp->tm_mon + 1, +#ifdef USG + fprintf(fp, "(%d/%d-%2.2d:%2.2d-%d) ", tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, pid); +#endif +#ifndef USG + fprintf(fp, "(%d/%d-%02d:%02d-%d) ", tp->tm_mon + 1, + tp->tm_mday, tp->tm_hour, tp->tm_min, pid); +#endif fprintf(fp, "%s (%s)\n", status, text); /* Since it's buffered */ +#ifndef USG lseek (fileno(fp), (long)0, 2); +#endif fflush (fp); - if (Debug > 0) { + if (Debug) { fprintf(stderr, "%s %s ", User, Rmtname); - fprintf(stderr, "(%d/%d-%d:%02d-%d) ", tp->tm_mon + 1, +#ifdef USG + fprintf(stderr, "(%d/%d-%2.2d:%2.2d-%d) ", tp->tm_mon + 1, + tp->tm_mday, tp->tm_hour, tp->tm_min, pid); +#endif +#ifndef USG + fprintf(stderr, "(%d/%d-%02d:%02d-%d) ", tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, pid); +#endif fprintf(stderr, "%s (%s)\n", status, text); } } @@ -127,22 +159,35 @@ char *text; if (Sp == NULL) { if (!Stried) { int savemask; +#if defined(USG) || defined(BSD4_2) + int flags; +#endif savemask = umask(LOGMASK); Sp = fopen(SYSLOG, "a"); umask(savemask); +#if defined(USG) || defined(BSD4_2) + flags = fcntl(fileno(Sp), F_GETFL, 0); + fcntl(fileno(Sp), F_SETFL, flags|O_APPEND); +#endif } Stried = 1; if (Sp == NULL) return; fioclex(fileno(Sp)); } - + time(&clock); tp = localtime(&clock); fprintf(Sp, "%s %s ", User, Rmtname); - fprintf(Sp, "(%d/%d-%d:%02d) ", tp->tm_mon + 1, +#ifdef USG + fprintf(Sp, "(%d/%d-%2.2d:%2.2d) ", tp->tm_mon + 1, + tp->tm_mday, tp->tm_hour, tp->tm_min); +#endif +#ifndef USG + fprintf(Sp, "(%d/%d-%02d:%02d) ", tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min); +#endif fprintf(Sp, "(%ld) %s\n", clock, text); /* Position at end and flush */ @@ -155,10 +200,7 @@ char *text; * Otherwise unwanted file descriptors are inherited * by other programs. And that may be a security hole. */ -#ifdef SYSIII -#include -#endif -#ifndef SYSIII +#ifndef USG #include #endif @@ -167,10 +209,9 @@ int fd; { register int ret; -#ifdef SYSIII +#if defined(USG) || defined(BSD4_2) ret = fcntl(fd, F_SETFD, 1); /* Steve Bellovin says this does it */ -#endif -#ifndef SYSIII +#else ret = ioctl(fd, FIOCLEX, STBNULL); #endif if (ret) diff --git a/usr/src/usr.bin/uucp/libuu/mailst.c b/usr/src/usr.bin/uucp/libuu/mailst.c index 49c667f5b0..9fc02ffcfc 100644 --- a/usr/src/usr.bin/uucp/libuu/mailst.c +++ b/usr/src/usr.bin/uucp/libuu/mailst.c @@ -1,12 +1,10 @@ #ifndef lint -static char sccsid[] = "@(#)mailst.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)mailst.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" -/******* - * mailst(user, str, file) - * +/* * mailst - this routine will fork and execute * a mail command sending string (str) to user (user). * If file is non-null, the file is also sent. @@ -17,20 +15,18 @@ mailst(user, str, file) char *user, *str, *file; { register FILE *fp, *fi; - char cmd[100], buf[BUFSIZ]; - register int nc; + char buf[BUFSIZ]; + register int c; - sprintf(cmd, "mail %s", user); - if ((fp = rpopen(cmd, "w")) == NULL) - return; - fprintf(fp, "%s", str); - - if (*file != '\0' && (fi = fopen(subfile(file), "r")) != NULL) { - while ((nc = fread(buf, sizeof (char), BUFSIZ, fi)) > 0) - fwrite(buf, sizeof (char), nc, fp); - fclose(fi); + sprintf(buf, "%s %s", MAIL, user); + if ((fp = rpopen(buf, "w")) != NULL) { + fprintf(fp, "From: uucp\nTo: %s\nSubject: %s\n\n", user, str); + if (file && *file != '\0' && (fi = fopen(subfile(file), "r")) != NULL) { + while ((c = getc(fi)) != EOF) + putc(c, fp); + putc('\n', fp); + fclose(fi); + } + rpclose(fp); } - - pclose(fp); - return; } diff --git a/usr/src/usr.bin/uucp/libuu/prefix.c b/usr/src/usr.bin/uucp/libuu/prefix.c index c7a9d91863..20c2a9d7b6 100644 --- a/usr/src/usr.bin/uucp/libuu/prefix.c +++ b/usr/src/usr.bin/uucp/libuu/prefix.c @@ -1,10 +1,9 @@ #ifndef lint -static char sccsid[] = "@(#)prefix.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)prefix.c 5.2 (Berkeley) %G%"; #endif -/******* - * prefix(s1, s2) check s2 for prefix s1 - * char *s1, *s2; +/* + * check s2 for prefix s1 * * return 0 - != * return 1 - == @@ -17,13 +16,12 @@ register char *s1, *s2; while ((c = *s1++) == *s2++) if (c == '\0') - return(1); - return(c == '\0'); + return 1; + return c == '\0'; } -/******* - * wprefix(s1, s2) check s2 for prefix s1 with a wildcard character ? - * char *s1, *s2; +/* + * check s2 for prefix s1 with a wildcard character ? * * return 0 - != * return 1 - == @@ -36,6 +34,6 @@ register char *s1, *s2; while ((c = *s1++) != '\0') if (*s2 == '\0' || (c != *s2++ && c != '?')) - return(0); - return(1); + return 0; + return 1; } diff --git a/usr/src/usr.bin/uucp/libuu/setline.c b/usr/src/usr.bin/uucp/libuu/setline.c index e0701a191a..8d77de8f57 100644 --- a/usr/src/usr.bin/uucp/libuu/setline.c +++ b/usr/src/usr.bin/uucp/libuu/setline.c @@ -1,15 +1,9 @@ #ifndef lint -static char sccsid[] = "@(#)setline.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)setline.c 5.2 (Berkeley) %G%"; #endif -/*** - * setline - optimize line setting for sending or receiving files - * - * return code - none - */ - #include "uucp.h" -#ifdef SYSIII +#ifdef USG #include #endif @@ -18,15 +12,20 @@ static char sccsid[] = "@(#)setline.c 5.1 (Berkeley) %G%"; #define RCVFILE 'R' #define RESET 'X' +/* + * optimize line setting for sending or receiving files + * + * return code - none + */ setline(type) char type; { -#ifdef SYSIII +#ifdef USG static struct termio tbuf, sbuf; static int set = 0; DEBUG(2, "setline - %c\n", type); - if (Unet) + if (IsTcpIp) return; switch(type) { case SNDFILE: @@ -40,7 +39,6 @@ char type; break; case RESET: if (set == 0) break; -/* Anticipatory bug fixes: set, sbuf now static, 'set' is now reset. rti!trt */ set = 0; ioctl(Ifn, TCSETAW, &sbuf); break; diff --git a/usr/src/usr.bin/uucp/libuu/subdir.c b/usr/src/usr.bin/uucp/libuu/subdir.c index 37832d04db..7d923585d0 100644 --- a/usr/src/usr.bin/uucp/libuu/subdir.c +++ b/usr/src/usr.bin/uucp/libuu/subdir.c @@ -1,16 +1,10 @@ #ifndef lint -static char sccsid[] = "@(#)subdir.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)subdir.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" -#ifdef UUDIR /* * By Tom Truscott, March 1983 - * THIS VERSION OF SYSKLUDGE IS FOR USE ONLY - * WITH THE 'UUDIR' VERSION OF UUCP. - * - * There once was a separate 'uudir' package to retrofit - * versions of uucp, but that is no longer recommended. * * Prefix table. * If a prefix is "abc", for example, @@ -37,7 +31,6 @@ static char *prefix[] = { */ #define BUFLEN 50 -/* assert(strlen(Spool)+1+14+1+14 <= BUFLEN) */ static char fn1[BUFLEN], fn2[BUFLEN]; /* remapped filename areas */ static int inspool; /* true iff working dir is Spool */ @@ -46,7 +39,7 @@ static int inspool; /* true iff working dir is Spool */ * return (possibly) remapped string s */ char * -SubFile(as) +subfile(as) char *as; { register char *s, **p; @@ -89,7 +82,7 @@ char *as; /* * save away filename */ -SubChDir(s) +subchdir(s) register char *s; { inspool = (strcmp(s, Spool) == 0); @@ -100,16 +93,13 @@ register char *s; * return possibly corrected directory for searching */ char * -SubDir(d, pre) +subdir(d, pre) register char *d, pre; { if (strcmp(d, Spool) == 0) if (pre == CMDPRE) - return("/usr/spool/uucp/C."); + return(CMDSDIR); else if (pre == XQTPRE) - return("/usr/spool/uucp/X."); + return(XEQTDIR); return(d); } -#else -static int subdir_here; /* quiet 'ranlib' command */ -#endif diff --git a/usr/src/usr.bin/uucp/libuu/sysacct.c b/usr/src/usr.bin/uucp/libuu/sysacct.c index 55b37771fa..adf89eec27 100644 --- a/usr/src/usr.bin/uucp/libuu/sysacct.c +++ b/usr/src/usr.bin/uucp/libuu/sysacct.c @@ -1,13 +1,11 @@ #ifndef lint -static char sccsid[] = "@(#)sysacct.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)sysacct.c 5.2 (Berkeley) %G%"; #endif #include -/******* - * sysacct(bytes, time) output accounting info - * time_t time; - * long bytes; +/* + * output accounting info */ sysacct(bytes, time) diff --git a/usr/src/usr.bin/uucp/libuu/systat.c b/usr/src/usr.bin/uucp/libuu/systat.c index 3e1594e74b..16439c372f 100644 --- a/usr/src/usr.bin/uucp/libuu/systat.c +++ b/usr/src/usr.bin/uucp/libuu/systat.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)systat.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)systat.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" @@ -7,7 +7,7 @@ static char sccsid[] = "@(#)systat.c 5.1 (Berkeley) %G%"; extern time_t time(); -#define STATNAME(f, n) sprintf(f, "%s/%s.%.7s", Spool, "STST", n) +#define STATNAME(f, n) sprintf(f, "%s/%s/%.7s", Spool, "STST", n) #define S_SIZE 100 /******* @@ -23,9 +23,9 @@ char *name, *text; int type; { char filename[MAXFULLNAME], line[S_SIZE]; - int count; + int count, oldtype; register FILE *fp; - time_t prestime; + time_t prestime, rtry; if (type == 0) return; @@ -37,19 +37,35 @@ int type; fp = fopen(filename, "r"); if (fp != NULL) { fgets(line, S_SIZE, fp); - sscanf(&line[2], "%d", &count); + sscanf(line, "%d %d", &oldtype, &count); if (count <= 0) count = 0; fclose(fp); + /* If merely 'wrong time', don't change existing STST */ + if (type == SS_WRONGTIME && oldtype != SS_INPROGRESS) + return; } - if (type == SS_FAIL) + rtry = Retrytime; + /* if failures repeat, don't try so often, + * to forstall a 'MAX RECALLS' situation. + */ + if (type == SS_FAIL) { count++; + if (count > 5) { + rtry = rtry * (count-5); + if (rtry > ONEDAY/2) + rtry = ONEDAY/2; + } + } + +#ifdef VMS + unlink(filename); +#endif VMS fp = fopen(filename, "w"); - ASSERT(fp != NULL, "SYSTAT OPEN FAIL", "", 0); -/* chmod(filename, 0666); rm-ed by rti!trt */ - fprintf(fp, "%d %d %ld %ld %s %s\n", type, count, prestime, Retrytime, text, name); + ASSERT(fp != NULL, "SYSTAT OPEN FAIL", filename, 0); + fprintf(fp, "%d %d %ld %ld %s %s\n", type, count, prestime, rtry, text, name); fclose(fp); return; } @@ -82,8 +98,8 @@ char *name; { char filename[MAXFULLNAME], line[S_SIZE]; register FILE *fp; - time_t lasttime, prestime; - long retrytime; + time_t lasttime, prestime, retrytime; + long t1, t2; int count, type; STATNAME(filename, name); @@ -100,7 +116,9 @@ char *name; fclose(fp); time(&prestime); - sscanf(line, "%d%d%ld%ld", &type, &count, &lasttime, &retrytime); + sscanf(line, "%d%d%ld%ld", &type, &count, &t1, &t2); + lasttime = t1; + retrytime = t2; switch(type) { case SS_BADSEQ: @@ -113,17 +131,25 @@ char *name; if (count > MAXRECALLS) { logent("MAX RECALLS", "NO CALL"); DEBUG(4, "MAX RECALL COUNT %d\n", count); - return(type); + if (Debug) { + logent("debugging", "continuing anyway"); + return SS_OK; + } + return type; } if (prestime - lasttime < retrytime) { logent("RETRY TIME NOT REACHED", "NO CALL"); - DEBUG(4, "RETRY TIME (%d) NOT REACHED\n", (long) RETRYTIME); - return(type); + DEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime); + if (Debug) { + logent("debugging", "continuing anyway"); + return SS_OK; + } + return type; } - return(SS_OK); + return SS_OK; default: - return(SS_OK); + return SS_OK; } } diff --git a/usr/src/usr.bin/uucp/libuu/ulockf.c b/usr/src/usr.bin/uucp/libuu/ulockf.c index c0477a9802..a110334da5 100644 --- a/usr/src/usr.bin/uucp/libuu/ulockf.c +++ b/usr/src/usr.bin/uucp/libuu/ulockf.c @@ -1,22 +1,17 @@ #ifndef lint -static char sccsid[] = "@(#)ulockf.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)ulockf.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" #include #include - extern time_t time(); /* File mode for lock files */ #define LCKMODE 0444 -/******* - * ulockf(file, atime) - * char *file; - * time_t atime; - * +/* * ulockf - this routine will create a lock file (file). * If one already exists, the create time is checked for * older than the age time (atime). @@ -38,7 +33,7 @@ time_t atime; if (pid < 0) { pid = getpid(); - sprintf(tempfile, "LTMP.%d", pid); + sprintf(tempfile, "%s/LTMP.%d", LOCKDIR, pid); } if (onelock(pid, tempfile, file) == -1) { /* lock file exists */ @@ -48,16 +43,18 @@ time_t atime; time(&ptime); if ((ptime - stbuf.st_ctime) < atime) { /* file not old enough to delete */ - return(FAIL); + return FAIL; } + ret = unlink(file); + logent(file, "DEAD LOCK"); + sleep(5); /* rti!trt: avoid a race */ + ret = onelock(pid, tempfile, file); } - ret = unlink(file); - ret = onelock(pid, tempfile, file); if (ret != 0) - return(FAIL); + return FAIL; } stlock(file); - return(0); + return SUCCESS; } @@ -82,7 +79,7 @@ register char *name; if (Lockfile[i] == NULL) break; } - ASSERT(i < MAXLOCKS, "TOO MANY LOCKS", "", i); + ASSERT(i < MAXLOCKS, "TOO MANY LOCKS", CNULL, i); if (i >= Nlocks) i = Nlocks++; p = calloc((unsigned)(strlen(name)+1), sizeof (char)); @@ -93,9 +90,8 @@ register char *name; } -/*** - * rmlock(name) remove all lock files in list - * char *name; or name +/* + * remove all lock files in list * or name * * return codes: none */ @@ -108,20 +104,15 @@ register char *name; for (i = 0; i < Nlocks; i++) { if (Lockfile[i] == NULL) continue; - if (name == NULL - || strcmp(name, Lockfile[i]) == SAME) { + if (name == NULL || strcmp(name, Lockfile[i]) == SAME) { unlink(Lockfile[i]); free(Lockfile[i]); Lockfile[i] = NULL; } } - return; } - /* - * this stuff from pjw - * /usr/pjw/bin/recover - Check pids to remove unnecessary locks. * isalock(name) returns 0 if the name is a lock. * unlock(name) unlocks name if it is a lock. * onelock(pid,tempfile,name) makes lock a name @@ -130,81 +121,95 @@ register char *name; * lock(pid,tempfile,names) either locks all the * names or none of them. */ -isalock(name) char *name; +isalock(name) +char *name; { struct stat xstat; - if(stat(name,&xstat)<0) return(0); - if(xstat.st_size!=sizeof(int)) return(0); - return(1); + if (stat(name,&xstat) < 0) + return 0; + if (xstat.st_size != sizeof(int)) + return 0; + return 1; } -unlock(name) char *name; +unlock(name) +char *name; { - if(isalock(name)) return(unlink(name)); - else return(-1); + if (isalock(name)) + return unlink(name); + else + return -1; } -onelock(pid,tempfile,name) char *tempfile,*name; -{ register int fd; - fd=creat(tempfile,LCKMODE); - if(fd<0) return(-1); - write(fd,(char *) &pid,sizeof(int)); +onelock(pid,tempfile,name) +char *tempfile,*name; +{ + register int fd; +#ifdef VMS + fd = creat(name, LCKMODE, "1version"); +#else !VMS + fd = creat(tempfile, LCKMODE); +#endif !VMS + if (fd<0) + return FAIL; + write(fd, (char *) &pid, sizeof(int)); close(fd); - if(link(tempfile,name)<0) - { unlink(tempfile); - return(-1); +#ifndef VMS + if (link(tempfile, name) < 0) { + unlink(tempfile); + return FAIL; } unlink(tempfile); - return(0); +#endif + return SUCCESS; } -lock(pid,tempfile,names) char *tempfile; + + +lock(pid, tempfile, names) +char *tempfile; register char **names; -{ register int i,j; - for(i=0;names[i]!=0;i++) - { if(onelock(pid,tempfile,names[i])==0) continue; - for(j=0;j #endif -/******* +/* * uucpname(name) get the uucp name * * return code - none */ - uucpname(name) register char *name; { register char *s, *d; - /* HUGE KLUDGE HERE! rti!trt + /* * Since some UNIX systems do not honor the set-user-id bit * when the invoking user is root, we must change the uid here. * So uucp files are created with the correct owner. @@ -47,18 +46,24 @@ register char *name; s = NULL; /* system name unknown, so far */ -#ifdef GETHOSTNAME - /* Use 4.1a library routine */ +#ifdef GETHOSTNAME if (s == NULL || *s == '\0') { char hostname[32]; +#ifdef VMS + int i = sizeof(hostname); +#endif VMS s = hostname; +#ifdef VMS + if(gethostname(hostname, &i) == -1) { +#else !VMS if(gethostname(hostname, sizeof(hostname)) == -1) { - DEBUG(1, "gethostname", "FAILED"); +#endif !VMS + DEBUG(1, "gethostname", _FAILED); s = NULL; } } -#endif +#endif GETHOSTNAME #ifdef UNAME /* Use USG library routine */ @@ -67,7 +72,7 @@ register char *name; s = utsn.nodename; if (uname(&utsn) == -1) { - DEBUG(1, "uname", "FAILED"); + DEBUG(1, "uname", _FAILED); s = NULL; } } @@ -80,7 +85,7 @@ register char *name; s = fakehost; if (fakegethostname(fakehost, sizeof(fakehost)) == -1) { - DEBUG(1, "whoami search", "FAILED"); + DEBUG(1, "whoami search", _FAILED); s = NULL; } } @@ -103,7 +108,7 @@ register char *name; if (((uucpf = fopen("/etc/uucpname", "r")) == NULL && (uucpf = fopen("/local/uucpname", "r")) == NULL) || fgets(s, 8, uucpf) == NULL) { - DEBUG(1, "uuname search", "FAILED"); + DEBUG(1, "uuname search", _FAILED); s = NULL; } else { for (d = stmp; *d && *d != '\n' && d < stmp + 8; d++) @@ -119,7 +124,7 @@ register char *name; /* Use 3Com's getmyhname() routine */ if (s == NULL || *s == '\0') { if ((s == getmyhname()) == NULL) - DEBUG(1, "getmyhname", "FAILED"); + DEBUG(1, "getmyhname", _FAILED); } #endif @@ -139,6 +144,12 @@ register char *name; s = "unknown"; } + /* + * save entire name for TCP/IP verification + */ + + strcpy(Myfullname, s); + /* * copy uucpname back to caller-supplied buffer, * truncating to 7 characters. @@ -150,17 +161,14 @@ register char *name; *(name + 7) = '\0'; DEBUG(1, "My uucpname = %s\n", name); -#ifdef UUDIR sprintf(DLocal, "D.%s", name); sprintf(DLocalX, "D.%sX", name); -#endif } #ifdef WHOAMI /* - * simulate the 4.1a bsd system call by reading /usr/include/whoami.h + * simulate the 4.2 bsd system call by reading /usr/include/whoami.h * and looking for the #define sysname - * CHANGE NOTICE (rti!trt): returns -1 on failure, 0 on success. */ #define HDRFILE "/usr/include/whoami.h" @@ -198,7 +206,7 @@ int len; } fclose(fd); if (hname[0] == 0) - return(-1); /* added by rti!trt */ + return FAIL; strncpy(name, hname, len); p = nname; i = strlen(hname) + 1; @@ -208,6 +216,6 @@ int len; i++; } *q++ = 0; - return(0); + return SUCCESS; } #endif diff --git a/usr/src/usr.bin/uucp/libuu/versys.c b/usr/src/usr.bin/uucp/libuu/versys.c index cd2287d706..ecad378996 100644 --- a/usr/src/usr.bin/uucp/libuu/versys.c +++ b/usr/src/usr.bin/uucp/libuu/versys.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)versys.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)versys.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" @@ -24,20 +24,20 @@ register char *name; sprintf(myname, "%.7s", Myname); sprintf(s1, "%.7s", name); if (strcmp(s1, myname) == 0) - return(0); + return SUCCESS; fp = fopen(SYSFILE, "r"); - ASSERT(fp != NULL, "CAN'T OPEN", SYSFILE, 0); + ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0); while (cfgets(line, sizeof(line), fp) != NULL) { char *targs[100]; - getargs(line, targs); + getargs(line, targs, 100); targs[0][7] = '\0'; if (strcmp(s1, targs[0]) == SAME) { fclose(fp); - return(0); + return SUCCESS; } } fclose(fp); - return(FAIL); + return FAIL; } diff --git a/usr/src/usr.bin/uucp/libuu/xqt.c b/usr/src/usr.bin/uucp/libuu/xqt.c index 882ded799d..afa6ad18f6 100644 --- a/usr/src/usr.bin/uucp/libuu/xqt.c +++ b/usr/src/usr.bin/uucp/libuu/xqt.c @@ -1,17 +1,22 @@ #ifndef lint -static char sccsid[] = "@(#)xqt.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)xqt.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" #include -/******* - * xuucico(rmtname) start up uucico for rmtname - * char *rmtname; +int LocalOnly = 0; + +/* + * start up uucico for rmtname * * return codes: none */ +#ifdef VMS +#define fork vfork +#endif VMS + xuucico(rmtname) char *rmtname; { @@ -21,9 +26,9 @@ char *rmtname; close(0); close(1); close(2); - open("/dev/null", 0); - open("/dev/null", 1); - open("/dev/null", 1); + open(DEVNULL, 0); + open(DEVNULL, 1); + open(DEVNULL, 1); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); @@ -32,15 +37,30 @@ char *rmtname; sprintf(opt, "-s%.7s", rmtname); else opt[0] = '\0'; - execl(UUCICO, "UUCICO", "-r1", opt, (char *)0); +#ifndef VMS + if (LocalOnly) + execl(UUCICO, "uucico", "-r1", "-L", opt, (char *)0); + else + execl(UUCICO, "uucico", "-r1", opt, (char *)0); +#else VMS + /* Under VMS/EUNICE release the batch job */ + if (LocalOnly) + execl(STARTUUCP, "startuucp", "uucico", "-r1", "-L", opt, (char *)0); + else + execl(STARTUUCP, "startuucp", "uucico", "-r1", opt, (char *)0); +#endif VMS exit(100); } +#ifdef VMS + while(wait(0) != -1) + ; /* Wait for it to finish!! */ +#endif VMS return; } -/******* - * xuuxqt() start up uuxqt +/* + * start up uuxqt * * return codes: none */ @@ -52,9 +72,9 @@ xuuxqt() close(0); close(1); close(2); - open("/dev/null", 2); - open("/dev/null", 2); - open("/dev/null", 2); + open(DEVNULL, 2); + open(DEVNULL, 2); + open(DEVNULL, 2); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); @@ -64,6 +84,7 @@ xuuxqt() } return; } + xuucp(str) char *str; { @@ -73,15 +94,15 @@ char *str; close(0); close(1); close(2); - open("/dev/null", 0); - open("/dev/null", 1); - open("/dev/null", 1); + open(DEVNULL, 0); + open(DEVNULL, 1); + open(DEVNULL, 1); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGKILL, SIG_IGN); sprintf(text, "%s -r %s", UUCP, str); - execl(SHELL, "sh", "-c", text, (char *)0); + execl(SHELL, "sh", "-c", text, CNULL); exit(100); } sleep(15); /* Give uucp chance to finish */ diff --git a/usr/src/usr.bin/uucp/port/getwd.c b/usr/src/usr.bin/uucp/port/getwd.c index aefb20fc86..b2617bd624 100644 --- a/usr/src/usr.bin/uucp/port/getwd.c +++ b/usr/src/usr.bin/uucp/port/getwd.c @@ -1,13 +1,13 @@ #ifndef lint -static char sccsid[] = "@(#)getwd.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)getwd.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" -/******* - * gwd(wkdir) get working directory +/* + * get working directory * - * return codes 0 | FAIL + * return codes SUCCESS | FAIL */ gwd(wkdir) @@ -18,27 +18,33 @@ register char *wkdir; extern int rpclose(); register char *c; +#ifdef BSD4_2 + if (getwd(wkdir) == 0) + return FAIL; +#else !BSD4_2 +# ifdef VMS + getwd(wkdir); /* Call Eunice C library version instead */ +#else !VMS *wkdir = '\0'; - /* PATH added to rpopen. Suggested by Henry Spencer (utzoo!henry) */ - if ((fp = rpopen("PATH=/bin:/usr/bin;pwd 2>&-", "r")) == NULL) - return(FAIL); - if (fgets(wkdir, MAXFULLNAME, fp) == NULL) { - pclose(fp); - return(FAIL); + if ((fp = rpopen("PATH=/bin:/usr/bin:/usr/ucb;pwd 2>&-", "r")) == NULL) + return FAIL; + if (fgets(wkdir, 100, fp) == NULL) { + rpclose(fp); + return FAIL; } if (*(c = wkdir + strlen(wkdir) - 1) == '\n') *c = '\0'; rpclose(fp); - return(0); +# endif !VMS +#endif !BSD4_2 + return SUCCESS; } /* - * rti!trt: gwd uses 'reverting' version of popen + * gwd uses 'reverting' version of popen * which runs process with permissions of real gid/uid * rather than the effective gid/uid. - * Bug noted by we13!rjk (Randy King). */ -/* @(#)popen.c 4.1 (Berkeley) 12/21/80 */ #include #define tst(a,b) (*mode == 'r'? (b) : (a)) #define RDR 0 @@ -93,5 +99,5 @@ FILE *ptr; signal(SIGINT, istat); signal(SIGQUIT, qstat); signal(SIGHUP, hstat); - return(status); + return status; } diff --git a/usr/src/usr.bin/uucp/port/index.c b/usr/src/usr.bin/uucp/port/index.c index e0ba6b2dd9..0dedcd29bf 100644 --- a/usr/src/usr.bin/uucp/port/index.c +++ b/usr/src/usr.bin/uucp/port/index.c @@ -1,13 +1,11 @@ #ifndef lint -static char sccsid[] = "@(#)index.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)index.c 5.2 (Berkeley) %G%"; #endif #include -/******* - * char * - * index(str, c) return pointer to character c - * char c, *str; +/* + * return pointer to character c * * return codes: * NULL - character not found @@ -20,8 +18,8 @@ register char c, *str; { for (; *str != '\0'; str++) { if (*str == c) - return(str); + return str; } - return(NULL); + return NULL; } diff --git a/usr/src/usr.bin/uucp/port/ioctl.c b/usr/src/usr.bin/uucp/port/ioctl.c index 35701f1f21..48f624240e 100644 --- a/usr/src/usr.bin/uucp/port/ioctl.c +++ b/usr/src/usr.bin/uucp/port/ioctl.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)ioctl.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)ioctl.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" @@ -29,6 +29,7 @@ struct sgttyb *ttbuf; case TIOCSETP: return(stty(fn, ttbuf)); case TIOCEXCL: + case TIOCNXCL: default: return(-1); } diff --git a/usr/src/usr.bin/uucp/shio.c b/usr/src/usr.bin/uucp/shio.c index 4c09e3f673..1ef80a97b9 100644 --- a/usr/src/usr.bin/uucp/shio.c +++ b/usr/src/usr.bin/uucp/shio.c @@ -1,11 +1,10 @@ #ifndef lint -static char sccsid[] = "@(#)shio.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)shio.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" #include - /******* * shio(cmd, fi, fo, user) execute shell of command with * char *cmd, *fi, *fo; fi and fo as standard input/output @@ -22,13 +21,17 @@ char *cmd, *fi, *fo, *user; int status, f; int uid, pid, ret; char path[MAXFULLNAME]; + extern int errno; if (fi == NULL) - fi = "/dev/null"; + fi = DEVNULL; if (fo == NULL) - fo = "/dev/null"; + fo = DEVNULL; DEBUG(3, "shio - %s\n", cmd); +#ifdef SIGCHLD + signal(SIGCHLD, SIG_IGN); +#endif SIGCHLD if ((pid = fork()) == 0) { signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); @@ -37,21 +40,25 @@ char *cmd, *fi, *fo, *user; close(Ifn); close(Ofn); close(0); - if (user == NULL - || (gninfo(user, &uid, path) != 0) - || setuid(uid)) + if (user == NULL || (gninfo(user, &uid, path) != 0) + || setuid(uid)) setuid(getuid()); f = open(subfile(fi), 0); - if (f != 0) - exit(f); + if (f != 0) { + logent(fi, "CAN'T READ"); + exit(-errno); + } close(1); f = creat(subfile(fo), 0666); - if (f != 1) - exit(f); + if (f != 1) { + logent(fo, "CAN'T WRITE"); + exit(-errno); + } execl(SHELL, "sh", "-c", cmd, (char *)0); - exit(100); + exit(100+errno); } - while ((ret = wait(&status)) != pid && ret != -1); + while ((ret = wait(&status)) != pid && ret != -1) + ; DEBUG(3, "status %d\n", status); - return(status); + return status; } diff --git a/usr/src/usr.bin/uucp/uucico/cntrl.c b/usr/src/usr.bin/uucp/uucico/cntrl.c index 35ad376bcd..33a4331af2 100644 --- a/usr/src/usr.bin/uucp/uucico/cntrl.c +++ b/usr/src/usr.bin/uucp/uucico/cntrl.c @@ -1,12 +1,13 @@ #ifndef lint -static char sccsid[] = "@(#)cntrl.c 5.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)cntrl.c 5.4 (Berkeley) %G%"; #endif #include "uucp.h" #include #include +#include "uust.h" - +extern int errno; struct Proto { char P_id; @@ -18,30 +19,41 @@ struct Proto { int (*P_turnoff)(); }; - extern int gturnon(), gturnoff(); extern int grdmsg(), grddata(); extern int gwrmsg(), gwrdata(); -extern int nturnon(), nturnoff(); -extern int nrdmsg(), nrddata(); -extern int nwrmsg(), nwrdata(); extern int imsg(), omsg(); +#ifdef BSDTCP +extern int tnullf(); +extern int twrmsg(), trdmsg(); +extern int twrdata(), trddata(); +#endif BSDTCP +#ifdef PAD +extern int fturnon(), fturnoff(); +extern int frdmsg(), frddata(); +extern int fwrmsg(), fwrdata(); +#endif PAD struct Proto Ptbl[]={ - 'n', nturnon, nrdmsg, nwrmsg, nrddata, nwrdata, nturnoff, +#ifdef BSDTCP + 't', tnullf, trdmsg, twrmsg, trddata, twrdata, tnullf, +#endif BSDTCP +#ifdef PAD + 'f', fturnon, frdmsg, fwrmsg, frddata, fwrdata, fturnoff, +#endif PAD 'g', gturnon, grdmsg, gwrmsg, grddata, gwrdata, gturnoff, '\0' }; -int (*Imsg)() = imsg, (*Omsg)() = omsg; /* avoid SEL compiler limitation */ +int (*Imsg)() = imsg, (*Omsg)() = omsg; int (*Rdmsg)()=imsg, (*Rddata)(); int (*Wrmsg)()=omsg, (*Wrdata)(); int (*Turnon)(), (*Turnoff)(); -#define YES "Y" -#define NO "N" +static char *YES = "Y"; +static char *NO = "N"; /* failure messages */ #define EM_MAX 6 @@ -59,11 +71,9 @@ char *Em_msg[] = { "system error - bad uucp command generated", "remote system can't create temp file", "can't copy to file/directory - file left in PUBDIR/user/file", - "can't copy to file/directory - file left in PUBDIR/user/file" + "can't copy to file/directory on local system - file left in PUBDIR/user/file" }; -/* */ - #define XUUCP 'X' /* execute uucp (string) */ #define SLTPTCL 'P' /* select protocol (string) */ @@ -74,7 +84,6 @@ char *Em_msg[] = { #define HUP 'H' /* ready to hangup (string - yes | no) */ #define RESET 'X' /* reset line modes */ - #define W_TYPE wrkvec[0] #define W_FILE1 wrkvec[1] #define W_FILE2 wrkvec[2] @@ -84,27 +93,23 @@ char *Em_msg[] = { #define W_MODE wrkvec[6] #define W_NUSER wrkvec[7] -#define XFRRATE 350000L -#define RMESG(m, s, n) if (rmesg(m, s, n) != 0) {(*Turnoff)(); return(FAIL);} else -#define RAMESG(s, n) if (rmesg('\0', s, n) != 0) {(*Turnoff)(); return(FAIL);} else -#define WMESG(m, s) if(wmesg(m, s) != 0) {(*Turnoff)(); return(FAIL);} else +#define XFRRATE 35000L +#define RMESG(m, s, n) if (rmesg(m, s, n) != 0) {(*Turnoff)(); return FAIL;} else +#define RAMESG(s, n) if (rmesg('\0', s, n) != 0) {(*Turnoff)(); return FAIL;} else +#define WMESG(m, s) if(wmesg(m, s) != 0) {(*Turnoff)(); return FAIL;} else char Wfile[MAXFULLNAME] = {'\0'}; char Dfile[MAXFULLNAME]; /* * To avoid a huge backlog of X. files, start uuxqt every so often. - * To avoid a huge number of uuxqt zombies, - * wait for one occasionally! */ static int nXfiles = 0; /* number of X files since last uuxqt start */ static int nXQTs = 0; /* number of uuxqts started */ +static char send_or_receive; +struct stat stbuf; -/******* - * cntrl(role, wkpre) - * int role; - * char *wkpre; - * +/* * cntrl - this routine will execute the conversation * between the two machines after both programs are * running. @@ -121,7 +126,6 @@ char *wkpre; char msg[BUFSIZ], rqstr[BUFSIZ]; register FILE *fp; int filemode; - struct stat stbuf; char filename[MAXFULLNAME], wrktype, *wrkvec[20]; extern (*Rdmsg)(), (*Wrmsg)(); extern char *index(), *lastpart(); @@ -130,28 +134,25 @@ char *wkpre; int mailopt, ntfyopt; int ret; static int pnum, tmpnum = 0; + extern int ReverseRole; pnum = getpid(); -/* - * ima.247, John Levine, IECC, PO Box 349, Cambridge MA 02238; (617) 491-5450 - * zap Wfile to prevent reuse of wrong C. file - */ Wfile[0] = '\0'; top: for (i = 0; i < sizeof wrkvec / sizeof wrkvec[0]; i++) wrkvec[i] = 0; - DEBUG(4, "*** TOP *** - role=%d, ", role); + DEBUG(4, "*** TOP *** - role=%s\n", role ? "MASTER" : "SLAVE"); setline(RESET); + send_or_receive = RESET; if (role == MASTER) { /* get work */ - if ((narg = gtwvec(Wfile, Spool, wkpre, wrkvec)) == 0) { + if (ReverseRole || (narg = gtwvec(Wfile, Spool, wkpre, wrkvec)) == 0) { + ReverseRole = 0; WMESG(HUP, ""); RMESG(HUP, msg, 1); goto process; } wrktype = W_TYPE[0]; - mailopt = index(W_OPTNS, 'm') != NULL; - ntfyopt = index(W_OPTNS, 'n') != NULL; msg[0] = '\0'; for (i = 1; i < narg; i++) { @@ -164,8 +165,18 @@ top: logent(rqstr, "REQUEST"); goto sendmsg; } + mailopt = index(W_OPTNS, 'm') != NULL; + ntfyopt = index(W_OPTNS, 'n') != NULL; - ASSERT(narg > 4, "ARG COUNT<5", "", i); + if (narg < 5) { + char *bnp; + bnp = rindex(Wfile, '/'); + sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile); + xmv(Wfile, rqstr); + logent(Wfile, "CMD FILE CORRUPTED"); + Wfile[0] = '\0'; + goto top; + } sprintf(User, "%.9s", W_USER); sprintf(rqstr, "%s %s %s %s", W_TYPE, W_FILE1, W_FILE2, W_USER); @@ -173,7 +184,7 @@ top: if (wrktype == SNDFILE ) { strcpy(filename, W_FILE1); i = expfile(filename); - DEBUG(4, "expfile type - %d", i); + DEBUG(4, "expfile type - %d, ", i); if (i != 0 && chkpth(User, "", filename)) goto e_access; strcpy(Dfile, W_DFILE); @@ -186,7 +197,8 @@ top: if (fp == NULL && (fp = fopen(subfile(filename), "r")) == NULL) { /* can not read data file */ - logent("CAN'T READ DATA", "FAILED"); + logent("CAN'T READ DATA", _FAILED); + USRF(USR_LOCACC); unlinkdf(Dfile); lnotify(User, filename, "can't access"); goto top; @@ -199,6 +211,7 @@ top: fclose(fp); fp = NULL; logent("DENIED", "ACCESS"); + USRF(USR_LOCACC); unlinkdf(W_DFILE); lnotify(User, filename, "access denied"); goto top; @@ -214,20 +227,22 @@ top: || chkperm(filename, index(W_OPTNS, 'd'))) { /* access denied */ logent("DENIED", "ACCESS"); + USRF(USR_LOCACC); lnotify(User, filename, "access denied"); goto top; } sprintf(Dfile, "%s/TM.%05d.%03d", Spool, pnum, tmpnum++); if ((fp = fopen(subfile(Dfile), "w")) == NULL) { /* can not create temp */ - logent("CAN'T CREATE TM", "FAILED"); + logent("CAN'T CREATE TM", _FAILED); + USRF(USR_LNOTMP); unlinkdf(Dfile); goto top; } setline(RCVFILE); } sendmsg: - DEBUG(4, "wrktype - %c\n ", wrktype); + DEBUG(4, "wrktype - %c\n", wrktype); WMESG(wrktype, msg); RMESG(wrktype, msg, 1); goto process; @@ -238,37 +253,44 @@ sendmsg: goto process; process: -/* rti!trt: ultouch is now done in gio.c (yes, kludge) - * ultouch(); - */ - DEBUG(4, " PROCESS: msg - %s\n", msg); + DEBUG(4, "PROCESS: msg - %s\n", msg); switch (msg[0]) { case RQSTCMPT: - DEBUG(4, "%s\n", "RQSTCMPT:"); + DEBUG(4, "RQSTCMPT:\n", CNULL); if (msg[1] == 'N') { i = atoi(&msg[2]); if (i<0 || i>EM_MAX) i=0; - /* duke!rti: only note failed requests */ - logent(msg, "REQUESTED"); + USRF( 1 << i ); + i = 0; + logent(Em_msg[i], "REQUEST FAILED"); + if (strcmp(&msg[1], EM_NOTMP) == 0) { + /* dont send him files he can't save */ + WMESG(HUP, ""); + RMESG(HUP, msg, 1); + goto process; + } } + if (msg[1] == 'Y') + USRF(USR_COK); if (role == MASTER) { notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]); } goto top; case HUP: - DEBUG(4, "%s\n", "HUP:"); + DEBUG(4, "HUP:\n", CNULL); if (msg[1] == 'Y') { - WMESG(HUP, YES); + if (role == MASTER) + WMESG(HUP, YES); (*Turnoff)(); Rdmsg = Imsg; Wrmsg = Omsg; - return(0); + return SUCCESS; } if (msg[1] == 'N') { - ASSERT(role == MASTER, "WRONG ROLE", "", role); + ASSERT(role == MASTER, "WRONG ROLE - HUP", CNULL, role); role = SLAVE; goto top; } @@ -290,11 +312,10 @@ process: } /* slave part */ - i = getargs(msg, wrkvec); + i = getargs(msg, wrkvec, 20); strcpy(filename, W_FILE1); - if (index(filename, ';') != NULL - || index(W_FILE2, ';') != NULL - || i < 3) { + if (index(filename, ';') != NULL || index(W_FILE2, ';') != NULL + || i < 3) { WMESG(XUUCP, NO); goto top; } @@ -302,6 +323,7 @@ process: if (chkpth("", Rmtname, filename)) { WMESG(XUUCP, NO); logent("XUUCP DENIED", filename); + USRF(USR_XUUCP); goto top; } sprintf(rqstr, "%s %s", filename, W_FILE2); @@ -317,11 +339,18 @@ process: i = atoi(&msg[2]); if (i < 0 || i > EM_MAX) i = 0; - logent(Em_msg[i], "REQUEST"); - notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]); - ASSERT(role == MASTER, "WRONG ROLE", "", role); + logent(Em_msg[i], "REQUEST FAILED"); + USRF( 1 << i ); fclose(fp); fp = NULL; + if (strcmp(&msg[1], EM_NOTMP) == 0) { + /* dont send him files he can't save */ + WMESG(HUP, ""); + RMESG(HUP, msg, 1); + goto process; + } + notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]); + ASSERT(role == MASTER, "WRONG ROLE - SN", CNULL, role); if (msg[1] != '4') unlinkdf(W_DFILE); goto top; @@ -329,32 +358,43 @@ process: if (msg[1] == 'Y') { /* send file */ - ASSERT(role == MASTER, "WRONG ROLE", "", role); + ASSERT(role == MASTER, "WRONG ROLE - SY", CNULL, role); ret = fstat(fileno(fp), &stbuf); ASSERT(ret != -1, "STAT FAILED", filename, 0); i = 1 + (int)(stbuf.st_size / XFRRATE); + if (send_or_receive != SNDFILE) { + send_or_receive = SNDFILE; + systat(Rmtname, SS_INPROGRESS, "SENDING"); + } ret = (*Wrdata)(fp, Ofn); fclose(fp); fp = NULL; - if (ret != 0) { + if (ret != SUCCESS) { (*Turnoff)(); - return(FAIL); + USRF(USR_CFAIL); + return FAIL; } RMESG(RQSTCMPT, msg, i); -/* put the unlink *after* the RMESG -- fortune!Dave-Yost */ unlinkdf(W_DFILE); goto process; } /* SLAVE section of SNDFILE */ - ASSERT(role == SLAVE, "WRONG ROLE", "", role); + ASSERT(role == SLAVE, "WRONG ROLE - SLAVE", CNULL, role); /* request to receive file */ /* check permissions */ - i = getargs(msg, wrkvec); - ASSERT(i > 4, "ARG COUNT<5", "", i); - sprintf(rqstr, "%s %s %s %s", W_TYPE, W_FILE1, - W_FILE2, W_USER); + i = getargs(msg, wrkvec, 20); + if (i < 5) { + char *bnp; + bnp = rindex(Wfile, '/'); + sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile); + xmv(Wfile, rqstr); + logent(Wfile, "CMD FILE CORRUPTED"); + Wfile[0] = '\0'; + goto top; + } + sprintf(rqstr, "%s %s %s %s", W_TYPE, W_FILE1, W_FILE2, W_USER); logent(rqstr, "REQUESTED"); DEBUG(4, "msg - %s\n", msg); strcpy(filename, W_FILE2); @@ -362,15 +402,18 @@ process: if (filename[0] == XQTPRE) { if (++nXfiles > 10) { nXfiles = 0; - /* I sure hope the wait(II) does not hang. - * One can never tell about UNIX variants. + /* + * want to create an orphan uuxqt, + * so a double-fork is needed. */ - if (++nXQTs > 2) - wait((int *)0); - xuuxqt(); + if (fork() == 0) { + xuuxqt(); + _exit(0); + } + wait((int *)0); } } - /* rti!trt: expand filename, i is set to 0 if this is + /* expand filename, i is set to 0 if this is * is a vanilla spool file, so no stat(II)s are needed */ i = expfile(filename); DEBUG(4, "expfile type - %d\n", i); @@ -389,42 +432,51 @@ process: sprintf(User, "%.9s", W_USER); DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname); + /* speed things up by OKing file before + * creating TM file. If the TM file cannot be created, + * then the conversation bombs, but that seems reasonable, + * as there are probably serious problems then. + */ + WMESG(SNDFILE, YES); sprintf(Dfile, "%s/TM.%05d.%03d", Spool, pnum, tmpnum++); if((fp = fopen(subfile(Dfile), "w")) == NULL) { - WMESG(SNDFILE, EM_NOTMP); - logent("CAN'T OPEN", "DENIED"); +/* WMESG(SNDFILE, EM_NOTMP);*/ + logent("CAN'T OPEN", "TM FILE"); unlinkdf(Dfile); - goto top; + (*Turnoff)(); + return FAIL; } - WMESG(SNDFILE, YES); + if (send_or_receive != RCVFILE) { + send_or_receive = RCVFILE; + systat(Rmtname, SS_INPROGRESS, "RECEIVING"); + } ret = (*Rddata)(Ifn, fp); - /* ittvax!swatt: (try to) make sure IO successful */ fflush(fp); if (ferror(fp) || fclose(fp)) ret = FAIL; - if (ret != 0) { + if (ret != SUCCESS) { + (void) unlinkdf(Dfile); (*Turnoff)(); - return(FAIL); + return FAIL; } /* copy to user directory */ ntfyopt = index(W_OPTNS, 'n') != NULL; status = xmv(Dfile, filename); WMESG(RQSTCMPT, status ? EM_RMTCP : YES); - if (status == 0) { - sscanf(W_MODE, "%o", &filemode); - if (filemode <= 0) + if (i == 0) + ; /* vanilla file, nothing to do */ + else if (status == 0) { + if (W_MODE == 0 || sscanf(W_MODE, "%o", &filemode) != 1) filemode = BASEMODE; - chmod(subfile(filename), filemode | BASEMODE); + chmod(subfile(filename), (filemode|BASEMODE)&0777); arrived(ntfyopt, filename, W_NUSER, Rmtname, User); - } - else { - logent("FAILED", "COPY"); + } else { + logent(_FAILED, "COPY"); status = putinpub(filename, Dfile, W_USER); DEBUG(4, "->PUBDIR %d\n", status); if (status == 0) - arrived(ntfyopt, filename, W_NUSER, - Rmtname, User); + arrived(ntfyopt, filename, W_NUSER, Rmtname, User); } goto top; @@ -437,25 +489,38 @@ process: i = atoi(&msg[2]); if (i < 0 || i > EM_MAX) i = 0; - logent(Em_msg[i], "REQUEST"); - notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]); - ASSERT(role == MASTER, "WRONG ROLE", "", role); + logent(Em_msg[i], "REQUEST FAILED"); + USRF( 1 << i ); fclose(fp); + fp = NULL; + if (strcmp(&msg[1], EM_NOTMP) == 0) { + /* dont send him files he can't save */ + WMESG(HUP, ""); + RMESG(HUP, msg, 1); + goto process; + } + notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]); + ASSERT(role == MASTER, "WRONG ROLE - RN", CNULL, role); unlinkdf(Dfile); goto top; } if (msg[1] == 'Y') { /* receive file */ - ASSERT(role == MASTER, "WRONG ROLE", "", role); + ASSERT(role == MASTER, "WRONG ROLE - RY", CNULL, role); + if (send_or_receive != RCVFILE) { + send_or_receive = RCVFILE; + systat(Rmtname, SS_INPROGRESS, "RECEIVING"); + } ret = (*Rddata)(Ifn, fp); - /* ittvax!swatt: (try to) make sure IO successful */ fflush(fp); if (ferror(fp) || fclose(fp)) ret = FAIL; - if (ret != 0) { + if (ret != SUCCESS) { + unlinkdf(Dfile); (*Turnoff)(); - return(FAIL); + USRF(USR_CFAIL); + return FAIL; } /* copy to user directory */ if (isdir(filename)) { @@ -470,25 +535,35 @@ process: sscanf(&msg[2], "%o", &filemode); if (filemode <= 0) filemode = BASEMODE; - chmod(subfile(filename), filemode | BASEMODE); + chmod(subfile(filename), (filemode|BASEMODE)&0777); + USRF(USR_COK); } else { - logent("FAILED", "COPY"); + logent(_FAILED, "COPY"); putinpub(filename, Dfile, W_USER); + USRF(USR_LOCCP); } goto top; } /* SLAVE section of RCVFILE */ - ASSERT(role == SLAVE, "WRONG ROLE", "", role); + ASSERT(role == SLAVE, "WRONG ROLE - SLAVE RCV", CNULL, role); /* request to send file */ strcpy(rqstr, msg); logent(rqstr, "REQUESTED"); /* check permissions */ - i = getargs(msg, wrkvec); - ASSERT(i > 3, "ARG COUNT<4", "", i); + i = getargs(msg, wrkvec, 20); + if (i < 4) { + char *bnp; + bnp = rindex(Wfile, '/'); + sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile); + xmv(Wfile, rqstr); + logent(Wfile, "CMD FILE CORRUPTED"); + Wfile[0] = '\0'; + goto top; + } DEBUG(4, "msg - %s\n", msg); DEBUG(4, "W_FILE1 - %s\n", W_FILE1); strcpy(filename, W_FILE1); @@ -517,17 +592,21 @@ process: i = 1 + (int)(stbuf.st_size / XFRRATE); sprintf(msg, "%s %o", YES, stbuf.st_mode & 0777); WMESG(RCVFILE, msg); + if (send_or_receive != SNDFILE) { + send_or_receive = SNDFILE; + systat(Rmtname, SS_INPROGRESS, "SENDING"); + } ret = (*Wrdata)(fp, Ofn); fclose(fp); - if (ret != 0) { + if (ret != SUCCESS) { (*Turnoff)(); - return(FAIL); + return FAIL; } RMESG(RQSTCMPT, msg, i); goto process; } (*Turnoff)(); - return(FAIL); + return FAIL; } @@ -543,29 +622,31 @@ rmesg(c, msg, n) register char *msg, c; register int n; { - char str[50]; + char str[128]; DEBUG(4, "rmesg - '%c' ", c); - if (n != 1) { - sprintf(str, "%d", n); - logent(str, "PATIENCE"); - } - while ((*Rdmsg)(msg, Ifn) != 0) { - if (--n > 0) + while ((*Rdmsg)(msg, Ifn) != SUCCESS) { + if (--n > 0) { + sprintf(str, "%d", n); + logent(str, "PATIENCE"); continue; - DEBUG(4, "got %s\n", "FAIL"); - sprintf(str, "expected '%c' got FAIL", c); + } + DEBUG(4, "got FAIL\n", CNULL); + if (c != '\0') + sprintf(str, "expected '%c' got FAIL (%d)", c, errno); + else + sprintf(str, "expected ANY got FAIL (%d)", errno); logent(str, "BAD READ"); - return(FAIL); + return FAIL; } if (c != '\0' && msg[0] != c) { DEBUG(4, "got %s\n", msg); - sprintf(str, "expected '%c' got %.25s", c, msg); + sprintf(str, "expected '%c' got %s", c, msg); logent(str, "BAD READ"); - return(FAIL); + return FAIL; } - DEBUG(4, "got %.25s\n", msg); - return(0); + DEBUG(4, "got %s\n", msg); + return SUCCESS; } @@ -579,9 +660,9 @@ register int n; wmesg(m, s) register char *s, m; { - DEBUG(4, "wmesg '%c'", m); - DEBUG(4, "%.25s\n", s); - return((*Wrmsg)(m, s, Ofn)); + DEBUG(4, "wmesg '%c' ", m); + DEBUG(4, "%s\n", s); + return (*Wrmsg)(m, s, Ofn); } @@ -608,9 +689,9 @@ char *user, *file, *sys, *msgcode; i = 0; msg = Em_msg[i]; } - sprintf(str, "file %s, system %s\n%s\n", - file, sys, msg); - mailst(user, str, ""); + sprintf(str, "file %s!%s -- %s\n", + sys,file, msg); + mailst(user, str, CNULL); return; } @@ -624,8 +705,8 @@ lnotify(user, file, mesg) char *user, *file, *mesg; { char mbuf[200]; - sprintf(mbuf, "file %s on %s\n%s\n", file, Myname, mesg); - mailst(user, mbuf, ""); + sprintf(mbuf, "file %s!%s -- %s\n", Myname, file, mesg); + mailst(user, mbuf, CNULL); return; } @@ -648,7 +729,7 @@ int role; { extern (*Rdmsg)(), (*Wrmsg)(); extern char *blptcl(), fptcl(); - char msg[BUFSIZ], str[BUFSIZ]; + char msg[BUFSIZ], str[MAXFULLNAME]; Rdmsg = Imsg; Wrmsg = Omsg; @@ -657,26 +738,26 @@ int role; if ((str[0] = fptcl(&msg[1])) == NULL) { /* no protocol match */ WMESG(USEPTCL, NO); - return(FAIL); + return FAIL; } str[1] = '\0'; WMESG(USEPTCL, str); if (stptcl(str) != 0) - return(FAIL); + return FAIL; DEBUG(4, "protocol %s\n", str); - return(SUCCESS); + return SUCCESS; } else { WMESG(SLTPTCL, blptcl(str)); RMESG(USEPTCL, msg, 1); if (msg[1] == 'N') { - return(FAIL); + return FAIL; } if (stptcl(&msg[1]) != 0) - return(FAIL); + return FAIL; DEBUG(4, "Protocol %s\n", msg); - return(SUCCESS); + return SUCCESS; } } @@ -699,23 +780,22 @@ fptcl(str) register char *str; { register struct Proto *p; - struct stat stbuf; + extern char *Flds[]; - if (fstat(Ifn, &stbuf) < 0) - return ('\0'); for (p = Ptbl; p->P_id != '\0'; p++) { - /* - * Hack to avoid using network protocol if not connected - * to network. - */ - if ((stbuf.st_mode & S_IFMT) != S_IFSOCK && p->P_id == 'n') +#ifdef BSDTCP + if (!IsTcpIp && p->P_id == 't') /* Only use 't' on TCP/IP */ + continue; +#endif BSDTCP + /* only use 'f' protocol on PAD */ + if (strcmp("PAD", Flds[F_LINE]) && p->P_id == 'f') continue; if (index(str, p->P_id) != NULL) { - return(p->P_id); + return p->P_id; } } - return('\0'); + return '\0'; } @@ -738,22 +818,11 @@ register char *str; { register struct Proto *p; register char *s; - struct stat stbuf; - - if (fstat(Ofn, &stbuf) < 0) - stbuf.st_mode = S_IFCHR; - for (p = Ptbl, s = str; p->P_id != '\0'; p++) { - /* - * Hack to avoid using network protocol if not connected - * to network. - */ - if ((stbuf.st_mode & S_IFMT) != S_IFSOCK && p->P_id == 'n') - continue; - *s++ = p->P_id; - } - *s = '\0'; - return(str); + for (p = Ptbl, s = str; (*s++ = p->P_id) != '\0'; p++) + ; + *s = '\0'; + return str; } /*** @@ -784,14 +853,14 @@ register char *c; Wrdata = p->P_wrdata; Turnon = p->P_turnon; Turnoff = p->P_turnoff; - if ((*Turnon)() != 0) - return(FAIL); + if ((*Turnon)() != SUCCESS) + return FAIL; DEBUG(4, "Proto started %c\n", *c); - return(SUCCESS); + return SUCCESS; } } DEBUG(4, "Proto start-fail %c\n", *c); - return(FAIL); + return FAIL; } /*** @@ -811,7 +880,7 @@ register char *file, *user, *tmp; sprintf(fullname, "%s/%s/", PUBDIR, user); if (mkdirs(fullname) != 0) { /* can not make directories */ - return(FAIL); + return FAIL; } strcat(fullname, lastpart(file)); status = xmv(tmp, fullname); @@ -819,7 +888,7 @@ register char *file, *user, *tmp; strcpy(file, fullname); chmod(subfile(fullname), BASEMODE); } - return(status); + return status; } /*** @@ -850,6 +919,6 @@ char *file, *nuser, *rmtsys, *rmtuser; if (!opt) return; sprintf(mbuf, "%s from %s!%s arrived\n", file, rmtsys, rmtuser); - mailst(nuser, mbuf, ""); + mailst(nuser, mbuf, CNULL); return; } diff --git a/usr/src/usr.bin/uucp/uucico/condevs.c b/usr/src/usr.bin/uucp/uucico/condevs.c index 4441f248ae..131d39b89c 100644 --- a/usr/src/usr.bin/uucp/uucico/condevs.c +++ b/usr/src/usr.bin/uucp/uucico/condevs.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)condevs.c 5.7 (Berkeley) %G%"; +static char sccsid[] = "@(#)condevs.c 5.8 (Berkeley) %G%"; #endif /* @@ -14,156 +14,111 @@ static char sccsid[] = "@(#)condevs.c 5.7 (Berkeley) %G%"; * and longjmp-ed to, it loses its register variables (on a pdp11). * What works is if the routine that does the setjmp * calls a routine and it is the *subroutine* that is interrupted. - * + * * Anyway, in conclusion, condevs.c is plagued with register variables * that are used inside * if (setjmp(...)) { * .... * } - * - * THE FIX: In dnopn(), for example, delete the 'register' Devices *dev. - * (That was causing a core dump; deleting register fixed it.) - * Also for dnopn delete 'register' int dnf... . - * In pkopn, delete 'register' flds... . - * There may be others, especially mcm's version of hysopen. - * You could just delete all references to register, that is safest. - * This problem might not occur on 4.1bsd, I am not sure. - * Tom Truscott + * + * THE FIX: Don't declare variables to be register */ -#include -#include -#include -#include -#include -#include "uucp.h" -extern char devSel[]; /* name to pass to delock() in close */ -extern int errno, next_fd; -extern jmp_buf Sjbuf; -extern int alarmtr(); -int nulldev(), nodev(), Acuopn(), diropn(), dircls(); - -#ifdef DATAKIT -int dkopn(); -#endif -#ifdef DN11 -int dnopn(), dncls(); -#endif -#ifdef HAYES -int hysopn(), hyscls(); -#endif -#ifdef HAYESQ -int hysqopn(), hysqcls(); /* a version of hayes that doesn't use ret codes */ -#endif -#ifdef DF02 -int df2opn(), df2cls(); -#endif -#ifdef PNET -int pnetopn(); -#endif -#ifdef VENTEL -int ventopn(), ventcls(); -#endif -#ifdef UNET -#include -#include -int unetopn(), unetcls(); -#endif UNET -#ifdef TCPNET -#include -#include -#include -#ifndef IPPORT_UUCP -#define IPPORT_UUCP 251 -#endif IPPORT_UUCP -int tcpopn(), tcpcls(); -#endif TCPNET -#ifdef VADIC -int vadopn(), vadcls(); -#endif VADIC -#ifdef RVMACS -int rvmacsopn(), rvmacscls(); -#endif -#ifdef MICOM -int micopn(), miccls(); -#endif MICOM +#include "condevs.h" struct condev condevs[] = { -{ "DIR", "direct", diropn, nulldev, dircls }, + { "DIR", "direct", diropn, nulldev, dircls }, #ifdef DATAKIT -{ "DK", "datakit", dkopn, nulldev, nulldev }, -#endif + { "DK", "datakit", dkopn, nulldev, nulldev }, +#endif DATAKIT #ifdef PNET -{ "PNET", "pnet", pnetopn, nulldev, nulldev }, -#endif -#ifdef UNET -{ "UNET", "UNET", unetopn, nulldev, unetcls }, -#endif UNET -#ifdef TCPNET -{ "NET", "tcpnet", tcpopn, nulldev, tcpcls }, -#endif TCPNET + { "PNET", "pnet", pnetopn, nulldev, nulldev }, +#endif PNET +#ifdef UNETTCP + { "TCP", "TCP", unetopn, nulldev, unetcls }, +#endif UNETTCP +#ifdef BSDTCP + { "TCP", "TCP", bsdtcpopn, nulldev, bsdtcpcls }, +#endif BSDTCP #ifdef MICOM -{ "MICOM", "micom", micopn, nulldev, miccls }, + { "MICOM", "micom", micopn, nulldev, miccls }, #endif MICOM #ifdef DN11 -{ "ACU", "dn11", Acuopn, dnopn, dncls }, -#endif + { "ACU", "dn11", Acuopn, dnopn, dncls }, +#endif DN11 #ifdef HAYES -{ "ACU", "hayes", Acuopn, hysopn, hyscls }, + { "ACU", "hayes", Acuopn, hysopn, hyscls }, #endif HAYES #ifdef HAYESQ /* a version of hayes that doesn't use result codes */ -{ "ACU", "hayesq", Acuopn, hysqopn, hysqcls }, + { "ACU", "hayesq", Acuopn, hysqopn, hysqcls }, #endif HATESQ +#ifdef NOVATION + { "ACU", "novation", Acuopn, novopn, novcls}, +#endif NOVATION #ifdef DF02 -{ "ACU", "DF02", Acuopn, df2opn, df2cls }, -#endif + { "ACU", "DF02", Acuopn, df2opn, df2cls }, +#endif DF02 #ifdef VENTEL -{ "ACU", "ventel", Acuopn, ventopn, ventcls }, + { "ACU", "ventel", Acuopn, ventopn, ventcls }, #endif VENTEL #ifdef VADIC -{ "ACU", "vadic", Acuopn, vadopn, vadcls }, + { "ACU", "vadic", Acuopn, vadopn, vadcls }, #endif VADIC +#ifdef VA212 + { "ACU", "va212", Acuopn, va212opn, va212cls }, +#endif VA212 +#ifdef VA811S + { "ACU", "va811s", Acuopn, va811opn, va811cls }, +#endif VA811S +#ifdef VA820 + { "ACU", "va820", Acuopn, va820opn, va820cls }, + { "WATS", "va820", Acuopn, va820opn, va820cls }, + { "LOCAL", "va820", Acuopn, va820opn, va820cls }, +#endif VA820 #ifdef RVMACS -{ "ACU", "rvmacs", Acuopn, rvmacsopn, rvmacscls }, + { "ACU", "rvmacs", Acuopn, rvmacsopn, rvmacscls }, #endif RVMACS +#ifdef VMACS + { "ACU", "vmacs", Acuopn, vmacsopn, vmacscls }, +#endif VMACS +#ifdef SYTEK + { "SYTEK", "sytek", sykopn, nulldev, sykcls }, +#endif SYTEK -/* Insert new entries before this line */ -{ NULL, NULL, NULL, NULL, NULL } }; + /* Insert new entries before this line */ + { NULL, NULL, NULL, NULL, NULL } +}; -/*** +/* * nulldev a null device (returns CF_DIAL) */ -int nulldev() +nulldev() { - return(CF_DIAL); + return CF_DIAL; } -/*** +/* * nodev a null device (returns CF_NODEV) */ -int nodev() +nodev() { - return(CF_NODEV); + return CF_NODEV; } - /* - * The first things in this file are the generic devices. * Generic devices look through L-devices and call the CU_open routines for - * appropriate devices. Some things, like the Unet interface, or direct - * connect, do not use the CU_open entry. ACUs must search to find the' + * appropriate devices. Some things, like the tcp/ip interface, or direct + * connect, do not use the CU_open entry. ACUs must search to find the * right routine to call. */ -/*** +/* * diropn(flds) connect to hardware line - * char *flds[]; * * return codes: - * >0 - file number - ok + * > 0 - file number - ok * FAIL - failed */ - diropn(flds) register char *flds[]; { @@ -171,12 +126,36 @@ register char *flds[]; struct Devices dev; char dcname[20]; FILE *dfp; +#ifdef VMSDTR /* Modem control on vms(works dtr) */ + int modem_control; + short iosb[4]; + int sys$qiow(); /* use this for long reads on vms */ + int ret; + long mode[2]; + modem_control = 0; +#endif dfp = fopen(DEVFILE, "r"); ASSERT(dfp != NULL, "CAN'T OPEN", DEVFILE, 0); while ((status = rddev(dfp, &dev)) != FAIL) { +#ifdef VMSDTR /* Modem control on vms(works dtr) */ + /* If we find MOD in the device type field we go into action */ + if (strcmp(dev.D_type, "MOD") == SAME) { + modem_control = 1; + DEBUG(7, "Setting Modem control to %d",modem_control); + } + if (strcmp(flds[F_CLASS], dev.D_class) != SAME) + continue; + /* + * Modem control on vms(works dtr) Take anything in MOD class. + * It probably should work differently anyway so we can have + * multiple hardwired lines. + */ + if (!modem_control&&strcmp(flds[F_PHONE], dev.D_line) != SAME) +#else !VMSDTR if (strcmp(flds[F_CLASS], dev.D_class) != SAME) continue; if (strcmp(flds[F_PHONE], dev.D_line) != SAME) +#endif !VMSDTR continue; if (mlock(dev.D_line) != FAIL) break; @@ -184,32 +163,54 @@ register char *flds[]; fclose(dfp); if (status == FAIL) { logent("DEVICE", "NO"); - return(CF_NODEV); + return CF_NODEV; } sprintf(dcname, "/dev/%s", dev.D_line); if (setjmp(Sjbuf)) { delock(dev.D_line); - return(FAIL); + return CF_DIAL; } signal(SIGALRM, alarmtr); alarm(10); getnextfd(); errno = 0; + DEBUG(4,"Opening %s",dcname); dcr = open(dcname, 2); /* read/write */ +#ifdef VMSDTR /* Modem control on vms(works dtr) */ + fflush(stdout); + if (modem_control) { /* Did we have MOD in the device type field ? */ + /* Sense the current terminal setup and save it */ + if ((ret = sys$qiow(_$EFN,(fd_fab_pointer[dcr]->fab).fab$l_stv, + IO$_SENSEMODE,iosb,0,0,mode,8,0,0,0,0)) + != SS$_NORMAL) { + DEBUG(7, "ret status on sense failed on Modem sense=%x<", ret); + return CF_DIAL; + } + mode[1] |= TT$M_MODEM; /* Or in modem control(DTR) */ + /* Now set the new terminal characteristics */ + /* This is temporary and will go away when we let go of it */ + if ((ret = sys$qiow(_$EFN,(fd_fab_pointer[dcr]->fab).fab$l_stv, + IO$_SETMODE,iosb,0,0,mode,8,0,0,0,0)) + != SS$_NORMAL) { + DEBUG(7, "ret status on sense failed on Modem setup=%x<", ret); + return CF_DIAL; + } + } +#endif VMSDTR next_fd = -1; if (dcr < 0 && errno == EACCES) logent(dcname, "CAN'T OPEN"); alarm(0); if (dcr < 0) { delock(dev.D_line); - return(FAIL); + return CF_DIAL; } fflush(stdout); fixline(dcr, dev.D_speed); strcpy(devSel, dev.D_line); /* for latter unlock */ CU_end = dircls; - return(dcr); + return dcr; } dircls(fd) @@ -218,323 +219,9 @@ register int fd; if (fd > 0) { close(fd); delock(devSel); - } - } - -#ifdef DATAKIT - -#include -#define DKTRIES 2 - -/*** - * dkopn(flds) make datakit connection - * - * return codes: - * >0 - file number - ok - * FAIL - failed - */ - -dkopn(flds) -char *flds[]; -{ - int dkphone; - register char *cp; - register ret, i; - - if (setjmp(Sjbuf)) - return(FAIL); - - signal(SIGALRM, alarmtr); - dkphone = 0; - cp = flds[F_PHONE]; - while(*cp) - dkphone = 10 * dkphone + (*cp++ - '0'); - DEBUG(4, "dkphone (%d) ", dkphone); - for (i = 0; i < DKTRIES; i++) { - getnextfd(); - ret = dkdial(D_SH, dkphone, 0); - next_fd = -1; - DEBUG(4, "dkdial (%d)\n", ret); - if (ret > -1) - break; - } - return(ret); -} -#endif - -#ifdef PNET -/*** - * pnetopn(flds) - * - * call remote machine via Purdue network - * use dial string as host name, speed as socket number - * Author: Steve Bellovin - */ - -pnetopn(flds) -char *flds[]; -{ - int fd; - int socket; - register char *cp; - - fd = pnetfile(); - DEBUG(4, "pnet fd - %d\n", fd); - if (fd < 0) { - logent("AVAILABLE DEVICE", "NO"); - return(CF_NODEV); - } - socket = 0; - for (cp = flds[F_CLASS]; *cp; cp++) - socket = 10*socket + (*cp - '0'); - DEBUG(4, "socket - %d\n", socket); - if (setjmp(Sjbuf)) { - DEBUG(4, "pnet timeout - %s\n", flds[F_PHONE]); - return(FAIL); - } - signal(SIGALRM, alarmtr); - DEBUG(4, "host - %s\n", flds[F_PHONE]); - alarm(15); - if (pnetscon(fd, flds[F_PHONE], socket) < 0) { - DEBUG(4, "pnet connect failed - %s\n", flds[F_PHONE]); - return(FAIL); - } - alarm(0); - return(fd); -} -#endif PNET - -#ifdef UNET -/*** - * unetopn -- make UNET (tcp-ip) connection - * - * return codes: - * >0 - file number - ok - * FAIL - failed - */ - -/* Default port of uucico server */ -#define DFLTPORT 33 - -unetopn(flds) -register char *flds[]; -{ - register int ret, port; - int unetcls(); - - port = atoi(flds[F_PHONE]); - if (port <= 0 || port > 255) - port = DFLTPORT; - DEBUG(4, "unetopn host %s, ", flds[F_NAME]); - DEBUG(4, "port %d\n", port); - if (setjmp(Sjbuf)) { - logent("tcpopen", "TIMEOUT"); - endhnent(); /* see below */ - return(CF_DIAL); - } - signal(SIGALRM, alarmtr); - alarm(30); - ret = tcpopen(flds[F_NAME], port, 0, TO_ACTIVE, "rw"); - alarm(0); - endhnent(); /* wave magic wand at 3com and incant "eat it, bruce" */ - if (ret < 0) { - DEBUG(5, "tcpopen failed: errno %d\n", errno); - logent("tcpopen", "FAILED"); - return(CF_DIAL); - } - CU_end = unetcls; - return(ret); -} - -/* - * unetcls -- close UNET connection. - */ -unetcls(fd) -register int fd; -{ - DEBUG(4, "UNET CLOSE called\n", 0); - if (fd > 0) { - /* disable this until a timeout is put in - if (ioctl(fd, UIOCCLOSE, STBNULL)) - logent("UNET CLOSE", "FAILED"); - */ - close(fd); - DEBUG(4, "closed fd %d\n", fd); - } -} -#endif UNET - -#ifdef TCPNET -/*** - * tcpopn - establish a network connection to the remote system - * - * return codes: - * >= 0 file descriptor for remote connection - * FAIL unable to establish remote connection - */ - -tcpopn(flds) -char *flds[]; -{ - register struct hostent *hp; - struct sockaddr_in hisaddr; - int nfd, port; - extern int errno; - int tcpcls(); - - hp = gethostbyname(flds[F_NAME]); - if (hp == NULL) { - DEBUG(4, "netcall: Unknown host (%s)\n", flds[F_NAME]); - logent(flds[F_NAME], "Unknown Host"); - return FAIL; - } - port = atoi(flds[F_PHONE]); - if (port == 0) - port = IPPORT_UUCP; - bzero((char *)&hisaddr, sizeof(hisaddr)); - bcopy(hp->h_addr, (char *)&hisaddr.sin_addr, hp->h_length); - hisaddr.sin_family = hp->h_addrtype; - hisaddr.sin_port = htons(port); - DEBUG(4, "Connect to %s ", hp->h_name); - DEBUG(4, "port %d... ", port); - nfd = socket(hp->h_addrtype, SOCK_STREAM, 0); - if (nfd < 0) { - DEBUG(4, "failed, no local sockets (%d)\n", errno); - return FAIL; - } - if (connect(nfd, (char *)&hisaddr, sizeof(hisaddr)) < 0) { - DEBUG(4, "failed, connect error (%d)\n", errno); - return FAIL; - } - DEBUG(4, "succeeded\n", 0); - CU_end = tcpcls; - return nfd; -} - -/* - * tcpcls -- close TCP connection. - */ -tcpcls(fd) -register int fd; -{ - DEBUG(4, "TCP CLOSE called\n", 0); - if (fd > 0) { - /* disable this until a timeout is put in - if (ioctl(fd, UIOCCLOSE, STBNULL)) - logent("TCP CLOSE", "FAILED"); - */ - close(fd); - DEBUG(4, "closed fd %d\n", fd); - } -} -#endif TCPNET - -#ifdef MICOM - -/* - * micopn: establish connection through a micom. - * Returns descriptor open to tty for reading and writing. - * Negative values (-1...-7) denote errors in connmsg. - * Be sure to disconnect tty when done, via HUPCL or stty 0. - */ -micopn(flds) -register char *flds[]; -{ - extern errno; - char *rindex(), *fdig(), dcname[20]; - int dh, ok = 0, speed; - register struct condev *cd; - register FILE *dfp; - struct Devices dev; - - dfp = fopen(DEVFILE, "r"); - ASSERT(dfp != NULL, "Can't open", DEVFILE, 0); - - signal(SIGALRM, alarmtr); - dh = -1; - for(cd = condevs; ((cd->CU_meth != NULL)&&(dh < 0)); cd++) { - if (snccmp(flds[F_LINE], cd->CU_meth) == SAME) { - fseek(dfp, (off_t)0, 0); - while(rddev(dfp, &dev) != FAIL) { - if (strcmp(flds[F_CLASS], dev.D_class) != SAME) - continue; - if (snccmp(flds[F_LINE], dev.D_type) != SAME) - continue; - if (mlock(dev.D_line) == FAIL) - continue; - - sprintf(dcname, "/dev/%s", dev.D_line); - getnextfd(); - alarm(10); - if (setjmp(Sjbuf)) { - delock(dev.D_line); - logent(dev.D_line,"micom open TIMEOUT"); - dh = -1; - break; - } - dh = open(dcname, 2); - alarm(0); - next_fd = -1; - if (dh > 0) { - break; - } - devSel[0] = '\0'; - delock(dev.D_line); - } - } - } - fclose(dfp); - if (dh < 0) - return(CF_NODEV); - - speed = atoi(fdig(flds[F_CLASS])); - fixline(dh, speed); - sleep(1); - - /* negotiate with micom */ - if (speed != 4800) /* damn their eyes! */ - write(dh, "\r", 1); - else - write(dh, " ", 1); - - DEBUG(4, "wanted %s ", "NAME"); - ok = expect("NAME", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok == 0) { - write(dh, flds[F_PHONE], strlen(flds[F_PHONE])); - sleep(1); - write(dh, "\r", 1); - DEBUG(4, "wanted %s ", "GO"); - ok = expect("GO", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); } - - if (ok != 0) { - if (dh > 2) - close(dh); - DEBUG(4, "micom failed\n", ""); - delock(dev.D_line); - return(CF_DIAL); - } else - DEBUG(4, "micom ok\n", ""); - - CU_end = cd->CU_clos; - strcat(devSel, dev.D_line); /* for later unlock */ - return(dh); - } -miccls(fd) -register int fd; -{ - - if (fd > 0) { - close(fd); - delock(devSel); - } - } -#endif MICOM - /*** * Acuopn - open an ACU and dial the number. The condevs table * will be searched until a dialing unit is found that is @@ -543,7 +230,6 @@ register int fd; * return codes: >0 - file number - o.k. * FAIL - failed */ - char devSel[20]; /* used for later unlock() */ Acuopn(flds) @@ -551,9 +237,10 @@ register char *flds[]; { char phone[MAXPH+1]; register struct condev *cd; - register int fd; + register int fd, acustatus; register FILE *dfp; struct Devices dev; + int retval = CF_NODEV; exphone(flds[F_PHONE], phone); devSel[0] = '\0'; @@ -561,10 +248,23 @@ register char *flds[]; dfp = fopen(DEVFILE, "r"); ASSERT(dfp != NULL, "Can't open", DEVFILE, 0); + acustatus = 0; /* none found, none locked */ for(cd = condevs; cd->CU_meth != NULL; cd++) { if (snccmp(flds[F_LINE], cd->CU_meth) == SAME) { - fseek(dfp, (off_t)0, 0); + rewind(dfp); while(rddev(dfp, &dev) != FAIL) { + /* + * for each ACU L.sys line, try at most twice + * (TRYCALLS) to establish carrier. The old way tried every + * available dialer, which on big sites takes forever! + * Sites with a single auto-dialer get one try. + * Sites with multiple dialers get a try on each of two + * different dialers. + * To try 'harder' to connect to a remote site, + * use multiple L.sys entries. + */ + if (acustatus > TRYCALLS) + continue; if (strcmp(flds[F_CLASS], dev.D_class) != SAME) continue; if (snccmp(flds[F_LINE], dev.D_type) != SAME) @@ -573,653 +273,34 @@ register char *flds[]; logent("Acuopn","No 'brand' name on ACU"); else if (snccmp(dev.D_brand, cd->CU_brand) != SAME) continue; + if (acustatus < 1) + acustatus = 1; /* has been found */ if (mlock(dev.D_line) == FAIL) continue; DEBUG(4, "Using %s\n", cd->CU_brand); + acustatus++; fd = (*(cd->CU_open))(phone, flds, &dev); if (fd > 0) { CU_end = cd->CU_clos; /* point CU_end at close func */ fclose(dfp); strcpy(devSel, dev.D_line); /* save for later unlock() */ - return(fd); + return fd; } delock(dev.D_line); + retval = CF_DIAL; } } } fclose(dfp); - return(FAIL); - } - -#ifdef DN11 - -/*** - * dnopn(ph, flds, dev) dial remote machine - * char *ph; - * char *flds[]; - * struct Devices *dev; - * - * return codes: - * file descriptor - succeeded - * FAIL - failed - */ - -dnopn(ph, flds, dev) -char *ph; -char *flds[]; -struct Devices *dev; -{ - char dcname[20], dnname[20], phone[MAXPH+2], c = 0; -#ifdef SYSIII - struct termio ttbuf; -#endif - int dnf, dcf; - int nw, lt, pid, status; - unsigned timelim; - - sprintf(dnname, "/dev/%s", dev->D_calldev); - errno = 0; - - if (setjmp(Sjbuf)) { - logent(dnname, "CAN'T OPEN"); - DEBUG(4, "%s Open timed out\n", dnname); - return(CF_NODEV); - } - signal(SIGALRM, alarmtr); - getnextfd(); - alarm(10); - dnf = open(dnname, 1); - alarm(0); - next_fd = -1; - if (dnf < 0 && errno == EACCES) { - logent(dnname, "CAN'T OPEN"); - logent("DEVICE", "NO"); - return(CF_NODEV); - } - /* rti!trt: avoid passing acu file descriptor to children */ - fioclex(dnf); - - sprintf(dcname, "/dev/%s", dev->D_line); - sprintf(phone, "%s%s", ph, ACULAST); - DEBUG(4, "dc - %s, ", dcname); - DEBUG(4, "acu - %s\n", dnname); - pid = 0; - if (setjmp(Sjbuf)) { - logent("DIALUP DN write", "TIMEOUT"); - if (pid) - kill(pid, 9); - delock(dev->D_line); - if (dnf) - close(dnf); - return(FAIL); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(phone); - alarm(timelim < 30 ? 30 : timelim); - if ((pid = fork()) == 0) { - sleep(2); - fclose(stdin); - fclose(stdout); -#ifdef TIOCFLUSH - ioctl(dnf, TIOCFLUSH, STBNULL); -#endif - nw = write(dnf, phone, lt = strlen(phone)); - if (nw != lt) { - logent("DIALUP ACU write", "FAILED"); - exit(1); - } - DEBUG(4, "ACU write ok%s\n", ""); - exit(0); - } - /* open line - will return on carrier */ - /* RT needs a sleep here because it returns immediately from open */ - -#if RT - sleep(15); -#endif - - getnextfd(); - errno = 0; - dcf = open(dcname, 2); - next_fd = -1; - if (dcf < 0 && errno == EACCES) - logent(dcname, "CAN'T OPEN"); - DEBUG(4, "dcf is %d\n", dcf); - if (dcf < 0) { - logent("DIALUP LINE open", "FAILED"); - alarm(0); - kill(pid, 9); - close(dnf); - delock(dev->D_line); - return(FAIL); - } - /* brl-bmd.351 (Doug Kingston) says the next ioctl is unneeded . */ -/* ioctl(dcf, TIOCHPCL, STBNULL);*/ - while ((nw = wait(<)) != pid && nw != -1) - ; -#ifdef SYSIII - ioctl(dcf, TCGETA, &ttbuf); - if(!(ttbuf.c_cflag & HUPCL)) { - ttbuf.c_cflag |= HUPCL; - ioctl(dcf, TCSETA, &ttbuf); - } -#endif - alarm(0); - fflush(stdout); - fixline(dcf, dev->D_speed); - DEBUG(4, "Fork Stat %o\n", lt); - if (lt != 0) { - close(dcf); - if (dnf) - close(dnf); - delock(dev->D_line); - return(FAIL); - } - return(dcf); -} - -/*** - * dncls() close dn type call unit - * - * return codes: None - */ -dncls(fd) -register int fd; -{ - if (fd > 0) { - close(fd); - sleep(5); - delock(devSel); - } -} -#endif DN11 - -#ifdef DF02 -/*** - * df2opn(ph, flds, dev) dial remote machine - * char *ph; - * char *flds[]; - * struct Devices *dev; - * - * return codes: - * file descriptor - succeeded - * FAIL - failed - * - * Modified 9/28/81 by Bill Shannon (DEC) - * Changed to use DEC DF02 or DF03 ACU - */ - - -df2opn(ph, flds, dev) -char *ph; -char *flds[]; -struct Devices *dev; -{ - char dcname[20], dnname[20], phone[MAXPH+2], c = 0; -#ifdef SYSIII - struct termio ttbuf; -#endif - int dcf, dnf; - int nw, lt, pid, st, status; - unsigned timelim; - - sprintf(dnname, "/dev/%s", dev->D_calldev); - if (setjmp(Sjbuf)) { - logent(dnname, "CAN'T OPEN"); - DEBUG(4, "%s Open timed out\n", dnname); - return(CF_NODEV); - } - signal(SIGALRM, alarmtr); - getnextfd(); - errno = 0; - alarm(10); - dnf = open(dnname, 2 ); - alarm(0); - next_fd = -1; - if (dnf < 0 && errno == EACCES) { - logent(dnname, "CAN'T OPEN"); - delock(dev->D_line); - logent("DEVICE", "NO"); - return(CF_NODEV); - } - /* rti!trt: avoid passing acu file descriptor to children */ - fioclex(dnf); - - sprintf(dcname, "/dev/%s", dev->D_line); - fixline(dnf, dev->D_speed); - sprintf(phone, "\02%s", ph); - DEBUG(4, "dc - %s, ", dcname); - DEBUG(4, "acu - %s\n", dnname); - pid = 0; - if (setjmp(Sjbuf)) { - logent("DIALUP DN write", "TIMEOUT"); - if (pid) - kill(pid, 9); - delock(dev->D_line); - if (dnf) - close(dnf); - return(FAIL); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(phone); - alarm(timelim < 30 ? 30 : timelim); - if ((pid = fork()) == 0) { - sleep(2); - fclose(stdin); - fclose(stdout); -#ifdef TIOCFLUSH - ioctl(dnf, TIOCFLUSH, STBNULL); -#endif - write(dnf, "\01", 1); - sleep(1); - nw = write(dnf, phone, lt = strlen(phone)); - if (nw != lt) { - logent("DIALUP ACU write", "FAILED"); - exit(1); - } - DEBUG(4, "ACU write ok%s\n", ""); - exit(0); - } - /* open line - will return on carrier */ - /* RT needs a sleep here because it returns immediately from open */ - -#if RT - sleep(15); -#endif - - if (read(dnf, &c, 1) != 1 || c != 'A') - dcf = -1; - else - dcf = 0; - DEBUG(4, "dcf is %d\n", dcf); - if (dcf < 0) { - logent("DIALUP LINE open", "FAILED"); - alarm(0); - kill(pid, 9); - close(dnf); - delock(dev->D_line); - return(FAIL); - } - dcf = dnf; - dnf = 0; - /* brl-bmd.351 (Doug Kingston) says the next ioctl is unneeded . */ -/* ioctl(dcf, TIOCHPCL, STBNULL);*/ - while ((nw = wait(<)) != pid && nw != -1) - ; -#ifdef SYSIII - ioctl(dcf, TCGETA, &ttbuf); - if(!(ttbuf.c_cflag & HUPCL)) { - ttbuf.c_cflag |= HUPCL; - ioctl(dcf, TCSETA, &ttbuf); - } -#endif - alarm(0); - fflush(stdout); - fixline(dcf, dev->D_speed); - DEBUG(4, "Fork Stat %o\n", lt); - if (lt != 0) { - close(dcf); - if (dnf) - close(dnf); - delock(dev->D_line); - return(FAIL); - } - return(dcf); -} - -/* - * df2cls() close the DF02/DF03 call unit - * - * return codes: none - */ - -df2cls(fd) -register int fd; -{ - if (fd > 0) { - close(fd); - sleep(5); - delock(devSel); - } -} -#endif DF02 - -#ifdef HAYES -/*** - * hysopn(telno, flds, dev) connect to hayes smartmodem - * char *flds[], *dev[]; - * - * return codes: - * >0 - file number - ok - * CF_DIAL,CF_DEVICE - failed - */ -/* - * Define HAYSTONE if you have touch tone dialing. - */ -/*#define HAYSTONE */ - -hysopn(telno, flds, dev) -char *telno; -char *flds[]; -struct Devices *dev; -{ - int dh = -1; - extern errno; - char dcname[20]; - - sprintf(dcname, "/dev/%s", dev->D_line); - DEBUG(4, "dc - %s\n", dcname); - if (setjmp(Sjbuf)) { - DEBUG(1, "timeout hayes open %s\n", dcname); - logent("hayes open", "TIMEOUT"); - if (dh >= 0) - close(dh); - delock(dev->D_line); - return(CF_DIAL); - } - signal(SIGALRM, alarmtr); - getnextfd(); - alarm(10); - dh = open(dcname, 2); /* read/write */ - alarm(0); - - /* modem is open */ - next_fd = -1; - if (dh >= 0) { - fixline(dh, dev->D_speed); -#ifdef HAYSTONE - write(dh, "\rATDT", 5); -#else - write(dh, "\rATDP", 5); -#endif - write(dh, telno, strlen(telno)); - write(dh, "\r", 1); - - if (expect("CONNECT", dh) != 0) { - logent("HSM no carrier", "FAILED"); - strcpy(devSel, dev->D_line); - hyscls(dh); - return(CF_DIAL); - } - - } - if (dh < 0) { - DEBUG(4, "hayes failed\n", ""); - delock(dev->D_line); - } - DEBUG(4, "hayes ok\n", ""); - return(dh); -} - -hyscls(fd) -int fd; -{ - char dcname[20]; - struct sgttyb hup, sav; - - if (fd > 0) { - sprintf(dcname, "/dev/%s", devSel); - DEBUG(4, "Hanging up fd = %d\n", fd); -/* - * code to drop DTR -- change to 0 baud then back to default. - */ - gtty(fd, &hup); - gtty(fd, &sav); - hup.sg_ispeed = B0; - hup.sg_ospeed = B0; - stty(fd, &hup); - sleep(2); - stty(fd, &sav); -/* - * now raise DTR -- close the device & open it again. - */ - sleep(2); - close(fd); - sleep(2); - fd = open(dcname, 2); -/* - * Since we have a getty sleeping on this line, when it wakes up it sends - * all kinds of garbage to the modem. Unfortunatly, the modem likes to - * execute the previous command when it sees the garbage. The previous - * command was to dial the phone, so let's make the last command reset - * the modem. - */ - sleep(2); - write(fd, "\rATZ\r", 5); - close(fd); - delock(devSel); - } - } - -#endif HAYES - -#ifdef HAYESQ -/* - * New dialout routine to work with Hayes' SMART MODEM - * 13-JUL-82, Mike Mitchell - * Modified 23-MAR-83 to work with Tom Truscott's (rti!trt) - * version of UUCP (ncsu!mcm) - * - * The modem should be set to NOT send any result codes to - * the system (switch 3 up, 4 down). This end will figure out - * what is wrong. - * - * I had lots of problems with the modem sending - * result codes since I am using the same modem for both incomming and - * outgoing calls. I'd occasionally miss the result code (getty would - * grab it), and the connect would fail. Worse yet, the getty would - * think the result code was a user name, and send garbage to it while - * it was in the command state. I turned off ALL result codes, and hope - * for the best. 99% of the time the modem is in the correct state. - * Occassionally it doesn't connect, or the phone was busy, etc., and - * uucico sits there trying to log in. It eventually times out, calling - * clsacu() in the process, so it resets itself for the next attempt. - */ - -/* - * Define HAYSTONE if touch-tone dialing is to be used. If it is not defined, - * Pulse dialing is assumed. - */ -/*#define HAYSTONE*/ - -hysqopn(telno, flds, dev) -char *telno, *flds[]; -struct Devices *dev; -{ - char dcname[20], phone[MAXPH+10], c = 0; -#ifdef SYSIII - struct termio ttbuf; -#endif - int status, dnf; - unsigned timelim; - - signal(SIGALRM, alarmtr); - sprintf(dcname, "/dev/%s", dev->D_line); - - getnextfd(); - if (setjmp(Sjbuf)) { - delock(dev->D_line); - logent("DEVICE", "NO"); - DEBUG(4, "Open timed out %s", dcname); - return(CF_NODEV); - } - alarm(10); - - if ((dnf = open(dcname, 2)) <= 0) { - delock(dev->D_line); - logent("DEVICE", "NO"); - DEBUG(4, "Can't open %s", dcname); - return(CF_NODEV); - } - - alarm(0); - next_fd = -1; - fixline(dnf, dev->D_speed); - DEBUG(4, "Hayes port - %s, ", dcname); - -#ifdef HAYSTONE - sprintf(phone, "\rATDT%s\r", telno); -#else - sprintf(phone, "\rATDP%s\r", telno); -#endif - - write(dnf, phone, strlen(phone)); - -/* calculate delay time for the other system to answer the phone. - * Default is 15 seconds, add 2 seconds for each comma in the phone - * number. - */ - timelim = 150; - while(*telno) { - c = *telno++; - if (c == ',') - timelim += 20; - else { -#ifdef HAYSTONE - timelim += 2; /* .2 seconds per tone */ - } -#else - if (c == '0') timelim += 10; /* .1 second per digit */ - else if (c > '0' && c <= '9') - timelim += (c - '0'); - } -#endif - } - alarm(timelim/10); - if (setjmp(Sjbuf) == 0) { - read(dnf, &c, 1); - alarm(0); - } - - return(dnf); - } - -hysqcls(fd) -int fd; -{ - char dcname[20]; - struct sgttyb hup, sav; - - if (fd > 0) { - sprintf(dcname, "/dev/%s", devSel); - DEBUG(4, "Hanging up fd = %d\n", fd); -/* - * code to drop DTR -- change to 0 baud then back to default. - */ - gtty(fd, &hup); - gtty(fd, &sav); - hup.sg_ispeed = B0; - hup.sg_ospeed = B0; - stty(fd, &hup); - sleep(2); - stty(fd, &sav); -/* - * now raise DTR -- close the device & open it again. - */ - sleep(2); - close(fd); - sleep(2); - fd = open(dcname, 2); -/* - * Since we have a getty sleeping on this line, when it wakes up it sends - * all kinds of garbage to the modem. Unfortunatly, the modem likes to - * execute the previous command when it sees the garbage. The previous - * command was to dial the phone, so let's make the last command reset - * the modem. - */ - sleep(2); - write(fd, "\rATZ\r", 5); - close(fd); - delock(devSel); - } - } - -#endif HAYESQ - -#ifdef VENTEL -ventopn(telno, flds, dev) -char *flds[], *telno; -struct Devices *dev; -{ - int dh; - int i, ok = -1; - char dcname[20]; - - sprintf(dcname, "/dev/%s", dev->D_line); - if (setjmp(Sjbuf)) { - DEBUG(1, "timeout ventel open\n", ""); - logent("ventel open", "TIMEOUT"); - if (dh >= 0) - close(dh); - delock(dev->D_line); - return(CF_NODEV); - } - signal(SIGALRM, alarmtr); - getnextfd(); - alarm(10); - dh = open(dcname, 2); - next_fd = -1; - if (dh < 0) { - DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem"); - delock(dev->D_line); - return(errno == 4 ? CF_DIAL : CF_NODEV); - } - - /* modem is open */ - fixline(dh, dev->D_speed); - - /* translate - to % and = to & for VenTel */ - DEBUG(4, "calling %s -> ", telno); - for (i = 0; i < strlen(telno); ++i) { - switch(telno[i]) { - case '-': /* delay */ - telno[i] = '%'; - break; - case '=': /* await dial tone */ - telno[i] = '&'; - break; - case '<': - telno[i] = '%'; - break; - } - } - DEBUG(4, "%s\n", telno); - sleep(1); - for(i = 0; i < 5; ++i) { /* make up to 5 tries */ - slowrite(dh, "\r\r");/* awake, thou lowly VenTel! */ - - DEBUG(4, "wanted %s ", "$"); - ok = expect("$", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok != 0) - continue; - slowrite(dh, "K"); /* "K" (enter number) command */ - DEBUG(4, "wanted %s ", "DIAL: "); - ok = expect("DIAL: ", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok == 0) - break; - } - - if (ok == 0) { - slowrite(dh, telno); /* send telno, send \r */ - slowrite(dh, "\r"); - DEBUG(4, "wanted %s ", "ONLINE"); - ok = expect("ONLINE!", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - } - if (ok != 0) { - if (dh > 2) - close(dh); - DEBUG(4, "venDial failed\n", ""); - return(CF_DIAL); - } else - DEBUG(4, "venDial ok\n", ""); - return(dh); + if (acustatus == 0) + logent("L-devices", "No appropriate ACU"); + if (acustatus == 1) + logent("DEVICE", "NO"); + return retval; } - +#if defined(VENTEL) || defined(NOVATION) /* * uucpdelay: delay execution for numerator/denominator seconds. */ @@ -1260,10 +341,11 @@ nap (time) ftimedelay(n) { static struct timeb loctime; + register i = loctime.millitm; + ftime(&loctime); - {register i = loctime.millitm; - while (abs((int)(loctime.millitm - i)) 0); } busyloop(n) - { +{ DELAY(n); - } +} #endif BUSYLOOP slowrite(fd, str) register char *str; { - DEBUG(6, "slowrite ", ""); + DEBUG(6, "slowrite ", CNULL); while (*str) { DEBUG(6, "%c", *str); uucpdelay(1,10); /* delay 1/10 second */ write(fd, str, 1); str++; - } - DEBUG(6, "\n", ""); -} - - -ventcls(fd) -int fd; -{ - - if (fd > 0) { - close(fd); - sleep(5); - delock(devSel); - } -} -#endif VENTEL - -#ifdef VADIC - -/* - * vadopn: establish dial-out connection through a Racal-Vadic 3450. - * Returns descriptor open to tty for reading and writing. - * Negative values (-1...-7) denote errors in connmsg. - * Be sure to disconnect tty when done, via HUPCL or stty 0. - */ - -vadopn(telno, flds, dev) -char *telno; -char *flds[]; -struct Devices *dev; -{ - int dh = -1; - int i, ok, er = 0, delay; - extern errno; - char dcname[20]; - char ntelno[64]; - - sprintf(dcname, "/dev/%s", dev->D_line); - if (setjmp(Sjbuf)) { - DEBUG(1, "timeout vadic open\n", ""); - logent("vadic open", "TIMEOUT"); - if (dh >= 0) - close(dh); - delock(dev->D_line); - return(CF_NODEV); - } - signal(SIGALRM, alarmtr); - getnextfd(); - alarm(10); - dh = open(dcname, 2); - alarm(0); - - /* modem is open */ - next_fd = -1; - if (dh < 0) { - delock(dev->D_line); - return(CF_NODEV); - } - fixline(dh, dev->D_speed); - -/* add a delay at the end of the number for the local phone switch */ - sprintf(ntelno, "%s=", telno); -/* translate - to K for Vadic */ - DEBUG(4, "calling %s -> ", ntelno); - delay = 0; - for (i = 0; i < strlen(ntelno); ++i) { - switch(ntelno[i]) { - case '=': /* await dial tone */ - case '-': /* delay */ - case '<': - ntelno[i] = 'K'; - delay += 5; - break; - } - } - DEBUG(4, "%s\n", ntelno); - for(i = 0; i < 5; ++i) { /* make 5 tries */ - /* wake up Vadic */ - sendthem("\005\\d", dh); - DEBUG(4, "wanted %s ", "*"); - ok = expect("*", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok != 0) - continue; - - sendthem("D\\d", dh); /* "D" (enter number) command */ - DEBUG(4, "wanted %s ", "NUMBER?\\r\\n"); - ok = expect("NUMBER?\r\n", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok != 0) - continue; - - /* send telno, send \r */ - sendthem(ntelno, dh); - ok = expect(ntelno, dh); - if (ok == 0) - ok = expect("\r\n", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok != 0) - continue; - - sendthem("", dh); /* confirm number */ - DEBUG(4, "wanted %s ", "DIALING: "); - ok = expect("DIALING: ", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok == 0) - break; - } - - if (ok == 0) { - sleep(10 + delay); /* give vadic some time */ - DEBUG(4, "wanted ON LINE\\r\\n ", 0); - ok = expect("ON LINE\r\n", dh); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - } - - if (ok != 0) { - sendthem("I\\d", dh); /* back to idle */ - if (dh > 2) - close(dh); - DEBUG(4, "vadDial failed\n", ""); - delock(dev->D_line); - return(CF_DIAL); - } - DEBUG(4, "vadic ok\n", ""); - return(dh); -} - -vadcls(fd) { - - if (fd > 0) { - close(fd); - sleep(5); - delock(devSel); - } } - -#endif VADIC - -#ifdef RVMACS -/* - * Racal-Vadic 'RV820' MACS system with 831 adaptor. - * A typical 300 baud L-devices entry is - * ACU /dev/tty10 /dev/tty11,48 300 rvmacs - * where tty10 is the communication line (D_Line), - * tty11 is the dialer line (D_calldev), - * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103), - * and the '8' is the communication port (they are 1-indexed). - * BUGS: - * Only tested with one dialer, one modem - * uses common speed for dialer and communication line. - * UNTESTED - */ - -#define STX 02 /* Access Adaptor */ -#define ETX 03 /* Transfer to Dialer */ -#define SI 017 /* Buffer Empty (end of phone number) */ -#define SOH 01 /* Abort */ - -rvmacsopn(ph, flds, dev) -char *ph, *flds[]; -struct Devices *dev; -{ - register int va, i, child; - register char *p; - char c, acu[20], com[20]; - - child = -1; - if ((p = index(dev->D_calldev, ',')) == NULL) { - DEBUG(2, "No dialer/modem specification\n", 0); - goto failret; - } - *p++ = '\0'; - if (setjmp(Sjbuf)) { - logent("rvmacsopn", "TIMEOUT"); - i = CF_DIAL; - goto ret; - } - DEBUG(4, "STARTING CALL\n", 0); - sprintf(acu, "/dev/%s", dev->D_calldev); - getnextfd(); - signal(SIGALRM, alarmtr); - alarm(30); - if ((va = open(acu, 2)) < 0) { - logent(acu, "CAN'T OPEN"); - i = CF_NODEV; - goto ret; - } - fixline(va, dev->D_speed); - - p_chwrite(va, STX); /* access adaptor */ - i = *p++ - '0'; - if (i < 0 || i > 7) { - logent(p-1, "Bad dialer address/modem type\n"); - goto failret; - } - p_chwrite(va, i); /* Send Dialer Address Digit */ - i = *p - '0'; - if (i <= 0 || i > 14) { - logent(p-1, "Bad modem address\n"); - goto failret; - } - p_chwrite(va, i-1); /* Send Modem Address Digit */ - write(va, ph, strlen(ph)); /* Send Phone Number */ - p_chwrite(va, SI); /* Send Buffer Empty */ - p_chwrite(va, ETX); /* Initiate Call */ - sprintf(com, "/dev/%s", dev->D_line); - - /* create child to open comm line */ - if ((child = fork()) == 0) { - signal(SIGINT, SIG_DFL); - open(com, 0); - sleep(5); - exit(1); - } - - if (read(va, &c, 1) != 1) { - logent("ACU READ", "FAILED"); - goto failret; - } - switch(c) { - case 'A': - /* Fine! */ - break; - case 'B': - DEBUG(2, "CALL ABORTED\n", 0); - goto failret; - case 'D': - DEBUG(2, "Dialer format error\n", 0); - goto failret; - case 'E': - DEBUG(2, "Dialer parity error\n", 0); - goto failret; - case 'F': - DEBUG(2, "Phone number too long\n", 0); - goto failret; - case 'G': - DEBUG(2, "Busy signal\n", 0); - goto failret; - default: - DEBUG(2, "Unknown MACS return code '%c'\n", i); - goto failret; - } - /* - * open line - will return on carrier - */ - if ((i = open(com, 2)) < 0) { - if (errno == EIO) - logent("carrier", "LOST"); - else - logent("dialup open", "FAILED"); - goto failret; - } - fixline(i, dev->D_speed); - goto ret; -failret: - i = CF_DIAL; -ret: - alarm(0); - if (child != -1) - kill(child, SIGKILL); - close(va); - return(i); + DEBUG(6, "\n", CNULL); } - -rvmacscls(fd) -register int fd; -{ - DEBUG(2, "MACS close %d\n", fd); - p_chwrite(fd, SOH); -/* ioctl(fd, TIOCCDTR, NULL);*/ - close(fd); -} -#endif +#endif VENTEL || NOVATION diff --git a/usr/src/usr.bin/uucp/uucico/conn.c b/usr/src/usr.bin/uucp/uucico/conn.c index 70bb420309..08e5155111 100644 --- a/usr/src/usr.bin/uucp/uucico/conn.c +++ b/usr/src/usr.bin/uucp/uucico/conn.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)conn.c 5.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)conn.c 5.4 (Berkeley) %G%"; #endif #include "uucp.h" @@ -7,28 +7,38 @@ static char sccsid[] = "@(#)conn.c 5.3 (Berkeley) %G%"; #include #include #include -#include #include -#ifdef SYSIII +#ifdef USG #include #include #endif -#ifndef SYSIII +#ifndef USG #include #endif +#ifdef BSD4_2 +#include +#else +#include +#endif #define MAXC 1000 extern jmp_buf Sjbuf; +jmp_buf Cjbuf; extern int errno; +extern char *sys_errlist[]; /* Parity control during login procedure */ #define P_ZERO 0 #define P_ONE 1 #define P_EVEN 2 #define P_ODD 3 -char par_tab[128]; /* must be power of two */ +#define ABORT -2 + +char *AbortOn = NULL; +char par_tab[128]; /* must be power of two */ +int linebaudrate; /* used for the sleep test in pk1.c */ int next_fd = -1; /* predicted fd to close interrupted opens */ /* rti!trt, courtesy unc!smb */ /*** @@ -64,28 +74,32 @@ alarmtr() */ int Dcf = -1; +char *Flds[MAXC/10]; +extern int LocalOnly; conn(system) char *system; { int ret, nf; - register int fn, fnd; - char info[MAXC], *flds[MAXC/10]; + register int fn = 0; + char info[MAXC]; register FILE *fsys; int fcode = 0; nf = 0; - fnd = 0; - fsys = fopen(SYSFILE, "r"); ASSERT(fsys != NULL, "CAN'T OPEN", SYSFILE, 0); - DEBUG(4, "finds %s\n", "called"); - while((nf = finds(fsys, system, info, flds)) > 0) { - DEBUG(4, "getto %s\n", "called"); - if ((fn = getto(flds)) > 0) { - fnd = 1; + DEBUG(4, "finds (%s) called\n", system); + while((nf = finds(fsys, system, info, Flds)) > 0) { + if (LocalOnly) { + if (strcmp("TCP", Flds[F_LINE]) + && strcmp("DIR", Flds[F_LINE]) + && strcmp("LOCAL", Flds[F_LINE]) ) + fn = CF_TIME; + } + if (fn != CF_TIME && (fn = getto(Flds)) > 0) { Dcf = fn; break; } @@ -94,17 +108,17 @@ char *system; fclose(fsys); if (nf <= 0) - return(fcode ? fcode : nf); + return fcode ? fcode : nf; DEBUG(4, "login %s\n", "called"); - ret = login(nf, flds, fn); - if (ret < 0) { + ret = login(nf, Flds, fn); + if (ret == FAIL) { clsacu(); - return(CF_LOGIN); + return CF_LOGIN; } /* rti!trt: avoid passing file to children */ fioclex(fn); - return(fn); + return fn; } /*** @@ -122,19 +136,19 @@ register char *flds[]; register struct condev *cd; int nulldev(), diropn(); - DEBUG(4, "call: no. %s ", flds[F_PHONE]); + DEBUG(4, "getto: call no. %s ", flds[F_PHONE]); DEBUG(4, "for sys %s\n", flds[F_NAME]); CU_end = nulldev; for (cd = condevs; cd->CU_meth != NULL; cd++) { if (snccmp(cd->CU_meth, flds[F_LINE]) == SAME) { DEBUG(4, "Using %s to call\n", cd->CU_meth); - return((*(cd->CU_gen))(flds)); - } + return (*(cd->CU_gen))(flds); } - logent(flds[F_LINE], "getto: Can't find, using DIR"); - return(diropn(flds)); /* search failed, so use direct */ } + DEBUG(1, "Can't find %s, assuming DIR", flds[F_LINE]); + return diropn(flds); /* search failed, so use direct */ +} /*** * clsacu() close call unit @@ -145,7 +159,23 @@ register char *flds[]; int (*CU_end)() = nulldev; clsacu() { - (*(CU_end))(Dcf); + /* make *sure* Dcf is no longer exclusive. + * Otherwise dual call-in/call-out modems could get stuck. + * Unfortunately, doing this here is not ideal, but it is the + * easiest place to put the call. + * Hopefully everyone honors the LCK protocol, of course + */ +#ifndef USG + ioctl(Dcf, TIOCNXCL, STBNULL); +#endif + if (setjmp(Sjbuf)) + logent(Rmtname, "CLOSE TIMEOUT"); + else { + signal(SIGALRM, alarmtr); + alarm(20); + (*(CU_end))(Dcf); + alarm(0); + } if (close(Dcf) == 0) { DEBUG(4, "fd %d NOT CLOSED by CU_clos\n", Dcf); logent("clsacu", "NOT CLOSED by CU_clos"); @@ -168,13 +198,13 @@ register char *in, *out; char buf[BUFSIZ]; register char *s1; - if (!isalpha(*in)) { + if (!isascii(*in) || !isalpha(*in)) { strcpy(out, in); return; } s1=pre; - while (isalpha(*in)) + while (isascii(*in) && isalpha(*in)) *s1++ = *in++; *s1 = '\0'; s1 = npart; @@ -187,7 +217,8 @@ register char *in, *out; DEBUG(2, "CAN'T OPEN %s\n", DIALFILE); else { while (cfgets(buf, BUFSIZ, fn)) { - sscanf(buf, "%s%s", p, tpre); + if (sscanf(buf, "%s%s", p, tpre) != 2) + continue; if (strcmp(p, pre) == SAME) goto found; tpre[0] = '\0'; @@ -199,7 +230,6 @@ register char *in, *out; strcpy(out, tpre); strcat(out, npart); - return; } /*** @@ -212,19 +242,19 @@ rddev(fp, dev) register struct Devices *dev; FILE *fp; { - char *fdig(); - char buf[BUFSIZ]; - int na; - - if (!cfgets(buf, BUFSIZ, fp)) - return(FAIL); - - na = sscanf(buf, "%s%s%s%s%s", dev->D_type, dev->D_line, - dev->D_calldev, dev->D_class, dev->D_brand); - ASSERT(na >= 4, "BAD DEVICE ENTRY", buf, 0); - if (na != 5) dev->D_brand[0] = '\0'; + register int na; + + if (!cfgets(dev->D_argbfr, sizeof(dev->D_argbfr), fp)) + return FAIL; + na = getargs(dev->D_argbfr, dev->D_arg, 20); + ASSERT(na >= 4, "BAD DEVICE ENTRY", dev->D_argbfr, 0); + if (na == 4) { + dev->D_brand = ""; + na++; + } dev->D_speed = atoi(fdig(dev->D_class)); - return(0); + dev->D_numargs = na; + return 0; } /*** @@ -252,17 +282,17 @@ FILE *fsys; * etc */ while (cfgets(info, MAXC, fsys) != NULL) { - na = getargs(info, flds); + na = getargs(info, flds, MAXC/10); sprintf(sysn, "%.7s", flds[F_NAME]); if (strcmp(sysnam, sysn) != SAME) continue; if (ifdate(flds[F_TIME])) /* found a good entry */ - return(na); + return na; DEBUG(2, "Wrong time ('%s') to call\n", flds[F_TIME]); fcode = CF_TIME; } - return(fcode ? fcode : CF_SYSTEM); + return fcode ? fcode : CF_SYSTEM; } /*** @@ -281,39 +311,50 @@ int nf, fn; extern char *index(); int k, ok; - ASSERT(nf > 4, "TOO FEW LOG FIELDS", "", nf); + ASSERT(nf > 4, "TOO FEW LOG FIELDS", CNULL, nf); + if (setjmp(Cjbuf)) + return FAIL; + AbortOn = NULL; for (k = F_LOGIN; k < nf; k += 2) { want = flds[k]; ok = FAIL; - while (ok != 0) { + while (ok != SUCCESS) { altern = index(want, '-'); if (altern != NULL) *altern++ = '\0'; - DEBUG(4, "wanted %s ", want); - ok = expect(want, fn); - DEBUG(4, "got %s\n", ok ? "?" : "that"); - if (ok == 0) - break; - if (altern == NULL) { - logent("LOGIN", "FAILED"); - /* close *not* needed here. rti!trt */ - return(FAIL); + if (strcmp(want, "ABORT") == 0) { + AbortOn = flds[k+1]; + DEBUG(4, "ABORT ON: %s\n", AbortOn); + goto nextfield; } - want = index(altern, '-'); - if (want != NULL) - *want++ = '\0'; - sendthem(altern, fn); + DEBUG(4, "wanted: %s\n", want); + ok = expect(want, fn); + DEBUG(4, "got: %s\n", ok ? "?" : "that"); + if (ok == FAIL) { + if (altern == NULL) { + logent("LOGIN", _FAILED); + return FAIL; + } + want = index(altern, '-'); + if (want != NULL) + *want++ = '\0'; + sendthem(altern, fn); + } else + if (ok == ABORT) { + logent("LOGIN ABORTED", _FAILED); + return FAIL; + } } - sleep(2); + sleep(1); if (k+1 < nf) sendthem(flds[k+1], fn); +nextfield: ; } - return(0); + return SUCCESS; } -/* rti!trt: conditional table generation to support odd speeds */ -/* Suggested in n44a.139 by n44!dan (Dan Ts'o) */ +/* conditional table generation to support odd speeds */ struct sg_spds {int sp_val, sp_name;} spds[] = { #ifdef B50 { 50, B50}, @@ -361,7 +402,10 @@ struct sg_spds {int sp_val, sp_name;} spds[] = { {9600, B9600}, #endif #ifdef B19200 - {19200,B19200}, + {19200, B19200}, +#endif +#ifdef EXTA + {19200, EXTA}, #endif {0, 0} }; @@ -376,12 +420,11 @@ struct sg_spds {int sp_val, sp_name;} spds[] = { fixline(tty, spwant) int tty, spwant; { -#ifdef SYSIII +#ifdef USG struct termio ttbuf; -#endif -#ifndef SYSIII +#else !USG struct sgttyb ttbuf; -#endif +#endif !USG register struct sg_spds *ps; int speed = -1; int ret; @@ -389,8 +432,8 @@ int tty, spwant; for (ps = spds; ps->sp_val; ps++) if (ps->sp_val == spwant) speed = ps->sp_name; - ASSERT(speed >= 0, "BAD SPEED", "", speed); -#ifdef SYSIII + ASSERT(speed >= 0, "BAD SPEED", CNULL, speed); +#ifdef USG ioctl(tty, TCGETA, &ttbuf); /* ttbuf.sg_flags = (ANYP|RAW); ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed; */ @@ -401,26 +444,22 @@ int tty, spwant; ttbuf.c_cc[VMIN] = 6; ttbuf.c_cc[VTIME] = 1; ret = ioctl(tty, TCSETA, &ttbuf); -#endif -#ifndef SYSIII +#else !USG ioctl(tty, TIOCGETP, &ttbuf); ttbuf.sg_flags = (ANYP|RAW); ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed; ret = ioctl(tty, TIOCSETP, &ttbuf); #endif - ASSERT(ret >= 0, "RETURN FROM STTY", "", ret); -#ifndef SYSIII + ASSERT(ret >= 0, "RETURN FROM STTY", CNULL, ret); +#ifndef USG ioctl(tty, TIOCHPCL, STBNULL); ioctl(tty, TIOCEXCL, STBNULL); #endif + linebaudrate = spwant; return; } - -/* Bill Shannon recommends MR 2000, but that takes too much space on PDPs */ -/* Actually, the 'expect' algorithm should be rewritten. */ -#define MR 1000 - +#define MR 100 /*** * expect(str, fn) look for expected string @@ -437,43 +476,66 @@ register char *str; int fn; { char rdvec[MR]; - register char *rp = rdvec; - int kr; + register char *rp = rdvec, *strptr; + int kr, cnt_char; char nextch; - if (strcmp(str, "\"\"") == SAME) - return(0); - *rp = 0; - if (setjmp(Sjbuf)) { - return(FAIL); + if (*str == '\0' || strcmp(str, "\"\"") == SAME) + return SUCCESS; + /* Cleanup str, convert \0xx strings to one char */ + for (strptr = str; *strptr; strptr++) { + if (*strptr == '\\') + switch(*++strptr) { + case 's': + DEBUG(5, "BLANK\n", CNULL); + *strptr = ' '; + break; + default: + strptr--; /* back up to backslash */ + sscanf(strptr + 1,"%o", &cnt_char); + DEBUG(6, "BACKSLASHED %02xH\n", cnt_char); + *strptr = (char) (cnt_char); + strcpy(&strptr[1], &strptr[4]); + } } + + *rp = 0; + if (setjmp(Sjbuf)) + return FAIL; signal(SIGALRM, alarmtr); -/* change MAXCHARTIME to MAXMSGTIME, outside while loop -- brl-bmd!dpk */ alarm(MAXMSGTIME); while (notin(str, rdvec)) { + if(AbortOn != NULL && !notin(AbortOn, rdvec)) { + DEBUG(1, "Call aborted on '%s'\n", AbortOn); + alarm(0); + return ABORT; + } kr = read(fn, &nextch, 1); if (kr <= 0) { alarm(0); DEBUG(4, "lost line kr - %d\n, ", kr); logent("LOGIN", "LOST LINE"); - return(FAIL); + return FAIL; } { int c; c = nextch & 0177; DEBUG(4, c >= 040 ? "%c" : "\\%03o", c); + if (c == '\n') + DEBUG(4,"\n", CNULL); } if ((*rp = nextch & 0177) != '\0') rp++; -/* Check rdvec before null termination -- cmcl2!salkind */ if (rp >= rdvec + MR) { - alarm(0); - return(FAIL); + register char *p; + for (p = rdvec+MR/2; p < rp; p++) + *(p-MR/2) = *p; + rp -= MR/2; } *rp = '\0'; } alarm(0); - return(0); + return SUCCESS; } @@ -488,22 +550,20 @@ getnextfd() close(next_fd = open("/", 0)); } -/*** - * sendthem(str, fn) send line of login sequence - * char *str; +/* + * send line of login sequence * * return codes: none */ - sendthem(str, fn) register char *str; int fn; { register char *strptr; int i, n, cr = 1; + register char c; static int p_init = 0; - /* Note: debugging authorized only for privileged users */ DEBUG(5, "send %s\n", str); if (!p_init) { @@ -534,7 +594,6 @@ int fn; return; } - /* LF, CR, and "" courtesy unc!smb */ /* Send a '\n' */ if (strcmp(str, "LF") == SAME) str = "\\n\\c"; @@ -562,55 +621,62 @@ int fn; } /* If "", just send '\r' */ - if (strcmp(str, "\"\"") != SAME) - for (strptr = str; *strptr; strptr++) { - if (*strptr == '\\') switch(*++strptr) { - case 's': - DEBUG(5, "BLANK\n", ""); - *strptr = ' '; - break; - case 'd': - DEBUG(5, "DELAY\n", ""); - sleep(1); - continue; - case 'r': - DEBUG(5, "RETURN\n", ""); - *strptr = '\r'; - break; - case 'b': - if (isdigit(*(strptr+1))) { - i = (*++strptr - '0'); - if (i <= 0 || i > 10) + if (strcmp(str, "\"\"") == SAME) { + p_chwrite(fn, '\r'); + return; + } + + for (strptr = str; c = *strptr++;) { + if (c == '\\') { + switch(*strptr++) { + case 's': + DEBUG(5, "BLANK\n", CNULL); + p_chwrite(fn, ' '); + break; + case 'd': + DEBUG(5, "DELAY\n", CNULL); + sleep(1); + continue; + case 'r': + DEBUG(5, "RETURN\n", CNULL); + p_chwrite(fn, '\r'); + break; + case 'b': + if (isdigit(*strptr)) { + i = (*strptr++ - '0'); + if (i <= 0 || i > 10) + i = 3; + } else i = 3; - } else - i = 3; - /* send break */ - genbrk(fn, i); - continue; - case 'c': - if (*(strptr+1) == '\0') { - DEBUG(5, "NO CR\n", ""); - cr = 0; + /* send break */ + genbrk(fn, i); + if (*strptr == '\0') + cr = 0; continue; - } - DEBUG(5, "NO CR - MIDDLE IGNORED\n", ""); - continue; - default: - if (isdigit(strptr[1])) { - i = 0; - n = 0; - while (isdigit(strptr[1]) && ++n <= 3) - i = i*8 + (*++strptr - '0'); - p_chwrite(fn, i); + case 'c': + if (*strptr == '\0') { + DEBUG(5, "NO CR\n", CNULL); + cr = 0; + continue; + } + DEBUG(5, "NO CR - MIDDLE IGNORED\n", CNULL); continue; + default: + if (isdigit(*strptr)) { + i = 0; + n = 0; + while (isdigit(*strptr) && ++n <= 3) + i = i*8 + (*strptr++ - '0'); + p_chwrite(fn, (char)i); + continue; + } + DEBUG(5, "BACKSLASH\n", CNULL); + --strptr; } - DEBUG(5, "BACKSLASH\n", ""); - strptr--; - } - p_chwrite(fn, *strptr); + } else + p_chwrite(fn, c); } - /* '\n' changed to '\r'--a better default. rti!trt */ if (cr) p_chwrite(fn, '\r'); return; @@ -618,13 +684,13 @@ int fn; p_chwrite(fd, c) int fd; -int c; +char c; { - char t[2]; - - t[0] = par_tab[c&0177]; - t[1] = '\0'; - ASSERT(write(fd, t, 1) == 1, "BAD WRITE", "", t[0]); + c = par_tab[c&0177]; + if (write(fd, &c, 1) != 1) { + logent(sys_errlist[errno], "BAD WRITE"); + longjmp(Cjbuf, 2); + } } /* @@ -659,23 +725,20 @@ genbrk(fn, bnulls) register int fn, bnulls; { register int ret; -#ifdef SYSIII +#ifdef USG ret = ioctl(fn, TCSBRK, STBNULL); DEBUG(5, "break ioctl ret %d\n", ret); -#endif -#ifndef SYSIII +#else !USG #ifdef TIOCSBRK ret = ioctl(fn, TIOCSBRK, STBNULL); DEBUG(5, "break ioctl ret %d\n", ret); #ifdef TIOCCBRK - ret = write(fn, "\0\0\0\0\0\0\0\0\0\0\0\0", bnulls); - ASSERT(ret > 0, "BAD WRITE genbrk", "", ret); sleep(1); ret = ioctl(fn, TIOCCBRK, STBNULL); DEBUG(5, "break ioctl ret %d\n", ret); -#endif - DEBUG(4, "ioctl 1 second break\n", STBNULL); -#else +#endif TIOCCBRK + DEBUG(4, "ioctl %d second break\n", bnulls ); +#else !TIOCSBRK struct sgttyb ttbuf; register int sospeed; @@ -684,17 +747,22 @@ register int fn, bnulls; ttbuf.sg_ospeed = BSPEED; ret = ioctl(fn, TIOCSETP, &ttbuf); ret = write(fn, "\0\0\0\0\0\0\0\0\0\0\0\0", bnulls); - ASSERT(ret > 0, "BAD WRITE genbrk", "", ret); + if (ret != bnulls) { +badbreak: + logent(sys_errlist[errno], "BAD WRITE genbrk"); + alarm(0); + longjmp(Sjbuf, 3); + } ttbuf.sg_ospeed = sospeed; ret = ioctl(fn, TIOCSETP, &ttbuf); ret = write(fn, "@", 1); - ASSERT(ret > 0, "BAD WRITE genbrk", "", ret); + if (ret != 1) + goto badbreak; DEBUG(4, "sent BREAK nulls - %d\n", bnulls); -#endif -#endif +#endif !TIOCSBRK +#endif !USG } - /*** * notin(sh, lg) check for occurrence of substring "sh" * char *sh, *lg; @@ -703,12 +771,10 @@ register int fn, bnulls; * 0 - found the string * 1 - not in the string */ - notin(sh, lg) register char *sh, *lg; { while (*lg != '\0') { - /* Dave Martingale: permit wild cards in 'expect' */ if (wprefix(sh, lg)) return(0); else @@ -717,7 +783,6 @@ register char *sh, *lg; return(1); } - /******* * ifdate(s) * char *s; @@ -738,11 +803,10 @@ char *s; for (p = s; p && (*p == '|' ? *++p : *p); p = index(p, '|')) if (ret = ifadate(p)) - return(ret); - return(0); + return ret; + return 0; } - /******* * ifadate(s) * char *s; @@ -770,7 +834,7 @@ char *s; }; time_t clock; int rtime; - int i, tl, th, tn, flag, dayok=0; + int i, tl, th, tn, dayok=0; struct tm *localtime(); struct tm *tp; char *index(); @@ -780,17 +844,16 @@ char *s; /* global variable Retrytime is set here */ if ((p = index(s, ',')) == NULL) { Retrytime = RETRYTIME; - } - else { + } else { i = sscanf(p+1, "%d", &rtime); - if (i < 1 || rtime < 5) + if (i < 1 || rtime < 0) rtime = 5; Retrytime = rtime * 60; } time(&clock); tp = localtime(&clock); - while (isalpha(*s)) { + while (isascii(*s) && isalpha(*s)) { for (i = 0; days[i]; i++) { if (prefix(days[i], s)) if (tp->tm_wday == i) @@ -802,24 +865,33 @@ char *s; dayok = 1; if (prefix("Any", s)) dayok = 1; + if (prefix("Evening", s)) { + /* Sat or Sun */ + if (tp->tm_wday == 6 || tp->tm_wday == 0 + || tp->tm_hour >= 17 || tp->tm_hour < 8) + dayok = 1; + } + if (prefix("Night", s)) { + if (tp->tm_wday == 6 /* Sat */ + || tp->tm_hour > 23 || tp->tm_hour < 8) + dayok = 1; + } s++; } if (dayok == 0) return(0); i = sscanf(s, "%d-%d", &tl, &th); - tn = tp->tm_hour * 100 + tp->tm_min; if (i < 2) return(1); - if (th < tl) - flag = 0; /* set up for crossover 2400 test */ - else - flag = 1; - if ((tn >= tl && tn <= th) - || (tn >= th && tn <= tl)) /* test for crossover 2400 */ - return(flag); - else - return(!flag); + tn = tp->tm_hour * 100 + tp->tm_min; + if (th < tl) { /* crosses midnight */ + if (tl <= tn || tn < th) + return(1); + } else + if (tl <= tn && tn < th) + return(1); + return(0); } @@ -829,23 +901,21 @@ char *s; * char *s; * */ - char * lastc(s) register char *s; { - while (*s != '\0') s++; - return(s); + while (*s != '\0') + s++; + return s; } - /*** * char * * fdig(cp) find first digit in string * * return - pointer to first digit in string or end of string */ - char * fdig(cp) register char *cp; @@ -855,15 +925,13 @@ register char *cp; for (c = cp; *c; c++) if (*c >= '0' && *c <= '9') break; - return(c); + return c; } - /* * Compare strings: s1>s2: >0 s1==s2: 0 s1D_argbfr)]; + + if (dev->D_numargs <= 5) + return(0); + DEBUG(4, "dochat called %d\n", dev->D_numargs); + for (i = 0; i < dev->D_numargs-5; i++) { + sprintf(bfr, dev->D_arg[D_CHAT+i], flds[F_PHONE]); + if (strcmp(bfr, dev->D_arg[D_CHAT+i])) { + p = malloc((unsigned)strlen(bfr)+1); + if (p != NULL) { + strcpy(p, bfr); + dev->D_arg[D_CHAT+i] = p; + } + } + } + /* following is a kludge because login() arglist is a kludge */ + i = login(dev->D_numargs, &dev->D_arg[D_CHAT-5], fd); + /* + * If login() last did a sendthem(), must pause so things can settle. + * But don't bother if chat failed. + */ + if (i == 0 && (dev->D_numargs&01)) + sleep(2); + return(i); } diff --git a/usr/src/usr.bin/uucp/uucico/gio.c b/usr/src/usr.bin/uucp/uucico/gio.c index c4413697cb..bf956cd648 100644 --- a/usr/src/usr.bin/uucp/uucico/gio.c +++ b/usr/src/usr.bin/uucp/uucico/gio.c @@ -1,17 +1,19 @@ #ifndef lint -static char sccsid[] = "@(#)gio.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)gio.c 5.2 (Berkeley) %G%"; #endif -#define USER 1 -#include "pk.p" #include #include "pk.h" #include #include "uucp.h" +#ifdef USG +#define ftime time +#else V7 +#include +#endif V7 extern time_t time(); - jmp_buf Failbuf; struct pack *Pk; @@ -23,37 +25,22 @@ pkfail() gturnon() { - int ret; struct pack *pkopen(); + if (setjmp(Failbuf)) - return(FAIL); - if (Pkdrvon) { - ret = pkon(Ofn, PACKSIZE); - DEBUG(4, "pkon - %d ", ret); - DEBUG(4, "Ofn - %d\n", Ofn); - if (ret <= 0) - return(FAIL); - } - else { - if (Debug > 4) - pkdebug = 1; - Pk = pkopen(Ifn, Ofn); - if ((int) Pk == NULL) - return(FAIL); - } - return(0); + return FAIL; + Pk = pkopen(Ifn, Ofn); + if (Pk == NULL) + return FAIL; + return SUCCESS; } - gturnoff() { if(setjmp(Failbuf)) return(FAIL); - if (Pkdrvon) - pkoff(Ofn); - else - pkclose(Pk); - return(0); + pkclose(Pk); + return SUCCESS; } @@ -80,29 +67,26 @@ register char *str; bufr[len - 1] = '\0'; } gwrblk(bufr, len, fn); - return(0); + return SUCCESS; } - +/*ARGSUSED*/ grdmsg(str, fn) register char *str; { unsigned len; if(setjmp(Failbuf)) - return(FAIL); + return FAIL; for (;;) { - if (Pkdrvon) - len = read(fn, str, PACKSIZE); - else - len = pkread(Pk, str, PACKSIZE); + len = pkread(Pk, str, PACKSIZE); if (len == 0) continue; str += len; if (*(str - 1) == '\0') break; } - return(0); + return SUCCESS; } @@ -111,31 +95,47 @@ FILE *fp1; { char bufr[BUFSIZ]; register int len; - int ret; + int ret, mil; +#ifdef USG time_t t1, t2; +#else v7 + struct timeb t1, t2; +#endif v7 long bytes; char text[BUFSIZ]; if(setjmp(Failbuf)) - return(FAIL); + return FAIL; bytes = 0L; - time(&t1); - while ((len = fread(bufr, sizeof (char), BUFSIZ, fp1)) > 0) { + ftime(&t1); + while ((len = read(fileno(fp1), bufr, BUFSIZ)) > 0) { bytes += len; ret = gwrblk(bufr, len, fn); if (ret != len) { - return(FAIL); + return FAIL; } if (len != BUFSIZ) break; } ret = gwrblk(bufr, 0, fn); - time(&t2); + ftime(&t2); +#ifndef USG + t2.time -= t1.time; + mil = t2.millitm - t1.millitm; + if (mil < 0) { + --t2.time; + mil += 1000; + } + sprintf(text, "sent data %ld bytes %ld.%03d secs", + bytes, (long)t2.time, mil); + sysacct(bytes, t2.time - t1.time); +#else USG sprintf(text, "sent data %ld bytes %ld secs", bytes, t2 - t1); + sysacct(bytes, t2 - t1); +#endif USG DEBUG(1, "%s\n", text); syslog(text); - sysacct(bytes, t2 - t1); - return(0); + return SUCCESS; } @@ -144,32 +144,48 @@ FILE *fp2; { register int len; char bufr[BUFSIZ]; +#ifdef USG time_t t1, t2; +#else v7 + struct timeb t1, t2; + int mil; +#endif v7 long bytes; char text[BUFSIZ]; if(setjmp(Failbuf)) - return(FAIL); + return FAIL; bytes = 0L; - time(&t1); + ftime(&t1); for (;;) { len = grdblk(bufr, BUFSIZ, fn); if (len < 0) { - return(FAIL); + return FAIL; } bytes += len; - /* ittvax!swatt: check return value of fwrite */ - if (fwrite(bufr, sizeof (char), len, fp2) != len) - return(FAIL); + if (write(fileno(fp2), bufr, len) != len) + return FAIL; if (len < BUFSIZ) break; } - time(&t2); + ftime(&t2); +#ifndef USG + t2.time -= t1.time; + mil = t2.millitm - t1.millitm; + if (mil < 0) { + --t2.time; + mil += 1000; + } + sprintf(text, "received data %ld bytes %ld.%03d secs", + bytes, (long)t2.time, mil); + sysacct(bytes, t2.time - t1.time); +#else USG sprintf(text, "received data %ld bytes %ld secs", bytes, t2 - t1); + sysacct(bytes, t2 - t1); +#endif USG DEBUG(1, "%s\n", text); syslog(text); - sysacct(bytes, t2 - t1); - return(0); + return SUCCESS; } @@ -177,32 +193,30 @@ FILE *fp2; #define TC 20 static int tc = TC; +/*ARGSUSED*/ grdblk(blk, len, fn) register int len; char *blk; { register int i, ret; - /* call ultouch occasionally -- rti!trt */ + /* call ultouch occasionally */ if (--tc < 0) { tc = TC; ultouch(); } for (i = 0; i < len; i += ret) { - if (Pkdrvon) - ret = read(fn, blk, len - i); - else - ret = pkread(Pk, blk, len - i); + ret = pkread(Pk, blk, len - i); if (ret < 0) - return(FAIL); + return FAIL; blk += ret; if (ret == 0) - return(i); + return i; } - return(i); + return i; } - +/*ARGSUSED*/ gwrblk(blk, len, fn) register char *blk; { @@ -213,9 +227,6 @@ register char *blk; tc = TC; ultouch(); } - if (Pkdrvon) - ret = write(fn, blk, len); - else - ret = pkwrite(Pk, blk, len); - return(ret); + ret = pkwrite(Pk, blk, len); + return ret; } diff --git a/usr/src/usr.bin/uucp/uucico/gnsys.c b/usr/src/usr.bin/uucp/uucico/gnsys.c index f47368d505..e8ec4af954 100644 --- a/usr/src/usr.bin/uucp/uucico/gnsys.c +++ b/usr/src/usr.bin/uucp/uucico/gnsys.c @@ -1,15 +1,7 @@ #ifndef lint -static char sccsid[] = "@(#)gnsys.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)gnsys.c 5.3 (Berkeley) %G%"; #endif -/* - * Mods: - * The "retry" code below prevents uucico from calling - * a site which it has called earlier. - * Also, uucico does callok() only once for each system. - * Done by unc!smb - */ - #include "uucp.h" #include #ifdef NDIR @@ -18,19 +10,14 @@ static char sccsid[] = "@(#)gnsys.c 5.2 (Berkeley) %G%"; #include #endif - #define LSIZE 100 /* number of systems to store */ #define WSUFSIZE 6 /* work file name suffix size */ -/******* - * gnsys(sname, dir, pre) - * char *sname, *dir, pre; - * - * gnsys - this routine will return the next - * system name which has work to be done. +/* + * this routine will return the next system name which has work to be done. + * "sname" is a string of size DIRSIZ - WSUFSIZE. * "pre" is the prefix for work files. * "dir" is the directory to search. - * "sname" is a string of size DIRSIZ - WSUFSIZE. * * return codes: * 0 - no more names @@ -55,7 +42,7 @@ retry: if (nitem == base) { /* get list of systems with work */ int i; - dirp = opendir(subdir(dir,pre), "r"); + dirp = opendir(subdir(dir,pre)); ASSERT(dirp != NULL, "BAD DIRECTORY", dir, 0); for (i = base; i < LSIZE; i++) list[i] = NULL; @@ -81,28 +68,22 @@ retry: for (n = 0; n < nitem; n++) if (list[n] != NULL) free(list[n]); - return(0); + return 0; } while(nitem > n) { strcpy(sname, list[n++]); if (callok(sname) == 0) - return(1); + return 1; } base = n = nitem; goto retry; } -/*** - * srchst(name, list, n) - * char *name, **list; - * int n; - * - * srchst - this routine will do a linear search - * of list (list) to find name (name). - * If the name is not found, it is added to the - * list. - * The number of items in the list (n) is - * returned (incremented if a name is added). +/* + * this routine will do a linear search of list (list) to find name (name). + * If the name is not found, it is added to the list. + * The number of items in the list (n) is returned (incremented if a + * name is added). * * return codes: * n - the number of items in the list @@ -122,9 +103,9 @@ int n; if (i >= n) { if ((p = calloc((unsigned)strlen(name) + 1, sizeof (char))) == NULL) - return(n); + return n; strcpy(p, name); list[n++] = p; } - return(n); + return n; } diff --git a/usr/src/usr.bin/uucp/uucico/imsg.c b/usr/src/usr.bin/uucp/uucico/imsg.c index 9e917beae0..71ca3e9668 100644 --- a/usr/src/usr.bin/uucp/uucico/imsg.c +++ b/usr/src/usr.bin/uucp/uucico/imsg.c @@ -1,16 +1,24 @@ #ifndef lint -static char sccsid[] = "@(#)imsg.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)imsg.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" char Msync[2] = "\020"; -/******* - * imsg(msg, fn) - * char *msg; - * int fn; - * - * imsg - this is the initial read message routine - + +/* to talk to both eunice and x.25 without also screwing up tcp/ip + * we must adaptively choose what character to end the msg with + * + * The idea is that initially we send ....\000\n + * Then, after they have sent us a message, we use the first character + * they send. + */ + +int seenend = 0; +char Mend = '\0'; + +/* + * this is the initial read message routine - * used before a protocol is agreed upon. * * return codes: @@ -23,36 +31,49 @@ register char *msg; register int fn; { register int ret; - DEBUG(7, "imsg %s>", ""); + char *amsg; + + DEBUG(5, "imsg %s<", "sync"); while ((ret = read(fn, msg, 1)) == 1) { - *msg &= 0177; /* Turn off parity bit (mhb5b!smb) */ - DEBUG(7, (*msg>037) ? "%c" : "\\%03o", *msg & 0377); + *msg &= 0177; + DEBUG(5, (*msg>037 && *msg<0177) ? "%c" : "\\%03o", *msg & 0377); if (*msg == Msync[0]) break; + fflush(stderr); } - DEBUG(7, "%s\n", "<"); + DEBUG(5, ">got %s\n", ret == 1 ? "it" : "EOF"); if (ret < 1) - return(EOF); + return EOF; + amsg = msg; +resync: + DEBUG(5, "imsg %s<", "input"); while (read(fn, msg, 1) == 1) { *msg &= 0177; - DEBUG(7, (*msg>037) ? "%c" : "\\%03o", *msg & 0377); - if (*msg == '\n') - break; - if (*msg == '\0') + DEBUG(5, (*msg>037 && *msg<0177) ? "%c" : "\\%03o", *msg & 0377); + if (*msg == Msync[0]) { + DEBUG(5, "%s\n", ">found sync"); + msg = amsg; + goto resync; + } + if (*msg == '\n' || *msg == '\0') { + if (!seenend) { + Mend = *msg; + seenend++; + DEBUG(6,"\nUsing \\%o as End of message char\n", Mend); + } break; + } msg++; + fflush(stderr); } *msg = '\0'; - return(0); + DEBUG(5, ">got %d\n", strlen(amsg)); + return 0; } -/*** - * omsg(type, msg, fn) - * char type, *msg; - * int fn; - * - * omsg - this is the initial write message routine - +/* + * this is the initial write message routine - * used before a protocol is agreed upon. * * return code: always 0 @@ -63,15 +84,21 @@ register char *msg; char type; int fn; { - char buf[BUFSIZ]; + char buf[MAXFULLNAME]; register char *c; c = buf; + *c = '\0'; /* avoid pdp 11/23,40 auto-incr stack trap bug */ *c++ = Msync[0]; *c++ = type; while (*msg) *c++ = *msg++; *c++ = '\0'; - write(fn, buf, strlen(buf) + 1); - return(0); + DEBUG(5, "omsg <%s>\n", buf); + if (seenend) + c[-1] = Mend; + else + *c++ = '\n'; + write(fn, buf, (int)(c - buf)); + return 0; } diff --git a/usr/src/usr.bin/uucp/uucico/pk.h b/usr/src/usr.bin/uucp/uucico/pk.h index 7933acc980..c62ac48c6f 100644 --- a/usr/src/usr.bin/uucp/uucico/pk.h +++ b/usr/src/usr.bin/uucp/uucico/pk.h @@ -1,4 +1,4 @@ -/* pk.h 5.1 83/07/02 */ +/* pk.h 5.2 85/01/22 */ struct header { char sync; diff --git a/usr/src/usr.bin/uucp/uucico/pk0.c b/usr/src/usr.bin/uucp/uucico/pk0.c index 166bb61316..b70ed6205b 100644 --- a/usr/src/usr.bin/uucp/uucico/pk0.c +++ b/usr/src/usr.bin/uucp/uucico/pk0.c @@ -1,37 +1,27 @@ #ifndef lint -static char sccsid[] = "@(#)pk0.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)pk0.c 5.2 (Berkeley) %G%"; #endif extern char *malloc(); -#define USER 1 #include -#ifdef SYSIII +#ifdef USG #include -#endif -#include "pk.p" +#endif USG #include #include "pk.h" #include - /* * packet driver */ -char next[8] ={ 1,2,3,4,5,6,7,0}; /* packet sequence numbers */ -char mask[8] ={ 1,2,4,010,020,040,0100,0200 }; +char next[8] = { 1, 2, 3, 4, 5, 6, 7, 0}; /* packet sequence numbers */ +char mask[8] = { 1, 2, 4, 010, 020, 040, 0100, 0200 }; struct pack *pklines[NPLINES]; - -/* - * Here are a couple of strange variables (rti!trt). - * pkactive is only incremented in pkopen. - * perhaps it should be decremented in pkclose? - * And pkdebug is set in gio.c but never used. - */ int pkactive; -int pkdebug; +long chksum(); /* * receive control messages @@ -39,25 +29,22 @@ int pkdebug; pkcntl(c, pk) register struct pack *pk; { -register cntl, val; + register cntl, val; val = c & MOD8; cntl = (c>>3) & MOD8; - if ( ! ISCNTL(c) ) { - fprintf(stderr, "not cntl\n"); + if (!ISCNTL(c)) { + logent("PK0", "not cntl"); return; } - if (pk->p_mode & 02) - fprintf(stderr, "%o ",c); switch(cntl) { - case INITB: val++; pk->p_xsize = pksizes[val]; pk->p_lpsize = val; - pk->p_bits = DTOM(pk->p_xsize); + pk->p_bits = 1; if (pk->p_state & LIVE) { pk->p_msg |= M_INITC; break; @@ -73,7 +60,6 @@ register cntl, val; case INITC: if ((pk->p_state&INITab)==INITab) { pk->p_state = LIVE; - WAKEUP(&pk->p_state); pk->p_rmsg &= ~M_INITB; } else pk->p_msg |= M_INITB; @@ -81,8 +67,8 @@ register cntl, val; pk->p_swindow = val; break; case INITA: - if (val==0 && pk->p_state&LIVE) { - fprintf(stderr, "alloc change not implemented\n"); + if (val == 0 && pk->p_state&LIVE) { + logent("PK0", "alloc change not implemented"); break; } if (val) { @@ -97,50 +83,36 @@ register cntl, val; pk->p_msg |= M_RR; case RR: pk->p_rpr = val; - if (pksack(pk)==0) { - WAKEUP(&pk->p_ps); - } + (void) pksack(pk); break; case SRJ: - fprintf(stderr, "srj not implemented\n"); + logent("PK0", "srj not implemented"); break; case CLOSE: pk->p_state = DOWN+RCLOSE; - SIGNAL; - WAKEUP(&pk->p_pr); - WAKEUP(&pk->p_ps); - WAKEUP(&pk->p_state); return; } -out: if (pk->p_msg) pkoutput(pk); } - - pkaccept(pk) register struct pack *pk; { -register x,seq; -char m, cntl, *p, imask, **bp; -int bad,accept,skip,s,t,h,cc; -unsigned short sum; - + register x, seq; + char m, cntl, *p, imask, **bp; + int bad, accept, skip, t, cc; + unsigned short sum; bad = accept = skip = 0; /* * wait for input */ - LOCK; x = next[pk->p_pr]; - while ((imask=pk->p_imap) == 0 && pk->p_rcount==0) { - PKGETPKT(pk); - SLEEP(&pk->p_pr, PKIPRI); + while ((imask=pk->p_imap) == 0 && pk->p_rcount == 0) { + pkgetpack(pk); } pk->p_imap = 0; - UNLOCK; - /* * determine input window in m. @@ -149,24 +121,20 @@ unsigned short sum; m = t; m |= t>>8; - /* * mark newly accepted input buffers */ for(x=0; x<8; x++) { - if ((imask & mask[x]) == 0) continue; - if (((cntl=pk->p_is[x])&0200)==0) { + if (((cntl=pk->p_is[x])&0200) == 0) { bad++; free: bp = (char **)pk->p_ib[x]; - LOCK; *bp = (char *)pk->p_ipool; pk->p_ipool = bp; pk->p_is[x] = 0; - UNLOCK; continue; } @@ -183,12 +151,10 @@ free: goto free; } if (x != seq) { - LOCK; p = pk->p_ib[x]; pk->p_ib[x] = pk->p_ib[seq]; pk->p_is[x] = pk->p_is[seq]; pk->p_ib[seq] = p; - UNLOCK; } pk->p_is[seq] = B_MARK; accept++; @@ -218,28 +184,19 @@ free: * numbers. */ accept = 0; - for(x=next[pk->p_pr],t=h= -1; m & mask[x]; x = next[x]) { + t = -1; + for(x=next[pk->p_pr]; m & mask[x]; x = next[x]) { if (pk->p_is[x] & B_MARK) pk->p_is[x] |= B_COPY; - /* hole code - if (pk->p_is[x] & B_COPY) { - if (h<0 && t>=0) - h = x; - } else { - if (t<0) - t = x; - } - */ + if (pk->p_is[x] & B_COPY) { if (t >= 0) { bp = (char **)pk->p_ib[x]; - LOCK; *bp = (char *)pk->p_ipool; pk->p_ipool = bp; pk->p_is[x] = 0; - UNLOCK; skip++; - } else + } else accept++; } else { if (t<0) @@ -256,31 +213,32 @@ free: } pk->p_rcount = accept; - return(accept); + return accept; } - -pkread(S) -SDEF; +/*ARGSUSED*/ +pkread(ipk, ibuf, icount) +int icount; +char *ibuf; +struct pack *ipk; { -register struct pack *pk; -register x,s; -int is,cc,xfr,count; -char *cp, **bp; + register struct pack *pk; + register x; + int is, cc, xfr, count; + char *cp, **bp; - pk = PADDR; + pk = ipk; xfr = 0; count = 0; - while (pkaccept(pk)==0); - - - while (UCOUNT) { + while (pkaccept(pk) == 0) + ; + while (icount) { x = next[pk->p_pr]; is = pk->p_is[x]; if (is & B_COPY) { - cc = MIN(pk->p_isum[x], UCOUNT); + cc = MIN(pk->p_isum[x], icount); if (cc==0 && xfr) { break; } @@ -293,19 +251,19 @@ char *cp, **bp; cp++; } } - IOMOVE(cp,cc,B_READ); + pkmove(cp, ibuf, cc, B_READ); + ibuf += cc; + icount -= cc; count += cc; xfr++; pk->p_isum[x] -= cc; if (pk->p_isum[x] == 0) { pk->p_pr = x; bp = (char **)pk->p_ib[x]; - LOCK; *bp = (char *)pk->p_ipool; pk->p_ipool = bp; pk->p_is[x] = 0; pk->p_rcount--; - UNLOCK; pk->p_msg |= M_RR; } else { pk->p_rptr = cp+cc; @@ -317,49 +275,44 @@ char *cp, **bp; break; } pkoutput(pk); - return(count); + return count; } - - - -pkwrite(S) -SDEF; +/*ARGSUSED*/ +pkwrite(ipk, ibuf, icount) +struct pack *ipk; +char *ibuf; +int icount; { -register struct pack *pk; -register x; -int partial; -caddr_t cp; -int cc, s, fc, count; + register struct pack *pk; + register x; + int partial; + caddr_t cp; + int cc, fc, count; - pk = PADDR; + pk = ipk; if (pk->p_state&DOWN || !pk->p_state&LIVE) { - SETERROR; - return(-1); + return -1; } - count = UCOUNT; + count = icount; do { - LOCK; while (pk->p_xcount>=pk->p_swindow) { pkoutput(pk); - PKGETPKT(pk); - SLEEP(&pk->p_ps,PKOPRI); + pkgetpack(pk); } x = next[pk->p_pscopy]; while (pk->p_os[x]!=B_NULL) { - PKGETPKT(pk); - SLEEP(&pk->p_ps,PKOPRI); + pkgetpack(pk); } pk->p_os[x] = B_MARK; pk->p_pscopy = x; pk->p_xcount++; - UNLOCK; - cp = pk->p_ob[x] = GETEPACK; + cp = pk->p_ob[x] = malloc((unsigned)pk->p_xsize); partial = 0; - if ((int)UCOUNT < pk->p_xsize) { - cc = UCOUNT; + if ((int)icount < pk->p_xsize) { + cc = icount; fc = pk->p_xsize - cc; *cp = fc&0177; if (fc > 127) { @@ -370,19 +323,21 @@ int cc, s, fc, count; partial = B_SHORT; } else cc = pk->p_xsize; - IOMOVE(cp,cc,B_WRITE); + pkmove(cp, ibuf, cc, B_WRITE); + ibuf += cc; + icount -= cc; pk->p_osum[x] = chksum(pk->p_ob[x], pk->p_xsize); pk->p_os[x] = B_READY+partial; pkoutput(pk); - } while (UCOUNT); + } while (icount); - return(count); + return count; } pksack(pk) register struct pack *pk; { -register x, i; + register x, i; i = 0; for(x=pk->p_ps; x!=pk->p_rpr; ) { @@ -392,12 +347,11 @@ register x, i; pk->p_os[x] = B_NULL; pk->p_state &= ~WAITO; pk->p_xcount--; - FREEPACK(pk->p_ob[x], pk->p_bits); + free((char *)pk->p_ob[x]); pk->p_ps = x; - WAKEUP(&pk->p_ps); } } - return(i); + return i; } @@ -405,23 +359,14 @@ register x, i; pkoutput(pk) register struct pack *pk; { -register x,rx; -int s; -char bstate; -int i; -SDEF; -int flag; - - flag = 0; - ISYSTEM; - LOCK; - if (pk->p_obusy++ || OBUSY) { + register x; + int i; + char bstate; + + if (pk->p_obusy++) { pk->p_obusy--; - UNLOCK; return; } - UNLOCK; - /* * find seq number and buffer state @@ -429,22 +374,21 @@ int flag; */ if (pk->p_state&RXMIT) { pk->p_nxtps = next[pk->p_rpr]; - flag++; } x = pk->p_nxtps; bstate = pk->p_os[x]; - /* * Send control packet if indicated */ if (pk->p_msg) { if (pk->p_msg & ~M_RR || !(bstate&B_READY) ) { x = pk->p_msg; - for(i=0; i<8; i++) + for(i=0; i<8; i++) if (x&1) - break; else - x >>= 1; + break; + else + x >>= 1; x = i; x <<= 3; switch(i) { @@ -478,7 +422,6 @@ int flag; * Don't send data packets if line is marked dead. */ if (pk->p_state&DOWN) { - WAKEUP(&pk->p_ps); goto out; } /* @@ -509,48 +452,42 @@ int flag; pk->p_state |= WAITO; } else pk->p_state &= ~WAITO; - WAKEUP(&pk->p_ps); out: pk->p_obusy = 0; } - /* * shut down line by * ignoring new input * letting output drain * releasing space and turning off line discipline */ -pkclose(S) -SDEF; +/*ARGSUSED*/ +pkclose(ipk, ibuf, icount) +struct pack *ipk; +char *ibuf; +int icount; { -register struct pack *pk; -register i,s,rbits; -char **bp; -int rcheck; -char *p; - + register struct pack *pk; + register i, rbits; + char **bp; + int rcheck; - pk = PADDR; + pk = ipk; pk->p_state |= DRAINO; - /* * try to flush output */ i = 0; - LOCK; pk->p_timer = 2; while (pk->p_xcount && pk->p_state&LIVE) { if (pk->p_state&(RCLOSE+DOWN) || ++i > 2) break; pkoutput(pk); - SLEEP(&pk->p_ps,PKOPRI); } pk->p_timer = 0; pk->p_state |= DOWN; - UNLOCK; - /* * try to exchange CLOSE messages @@ -560,51 +497,41 @@ char *p; pk->p_msg = M_CLOSE; pk->p_timer = 2; pkoutput(pk); - SLEEP(&pk->p_ps, PKOPRI); i++; } - for(i=0;ip_rsize); + rbits = 1; rcheck = 0; for (i=0;i<8;i++) { - if (pk->p_os[i]!=B_NULL) { - FREEPACK(pk->p_ob[i],pk->p_bits); + if (pk->p_os[i] != B_NULL) { + free((char *)pk->p_ob[i]); pk->p_xcount--; } - if (pk->p_is[i]!=B_NULL) { - FREEPACK(pk->p_ib[i],rbits); + if (pk->p_is[i] != B_NULL) { + free((char *)pk->p_ib[i]); rcheck++; } } - LOCK; while (pk->p_ipool != NULL) { bp = pk->p_ipool; pk->p_ipool = (char **)*bp; rcheck++; - FREEPACK(bp, rbits); + free((char *)bp); } - UNLOCK; - if (rcheck != pk->p_rwindow) { - fprintf(stderr, "r short %d want %d\n",rcheck,pk->p_rwindow); - fprintf(stderr, "rcount = %d\n",pk->p_rcount); - fprintf(stderr, "xcount = %d\n",pk->p_xcount); + if (rcheck != pk->p_rwindow) { + logent("PK0", "pkclose rcheck != p_rwindow"); } - FREEPACK((caddr_t)pk, npbits); + free((char *)pk); } - - pkreset(pk) register struct pack *pk; { @@ -613,58 +540,35 @@ register struct pack *pk; pk->p_nxtps = 1; } -chksum(s,n) -register char *s; -register n; -{ - register unsigned sum, t; - register x; - - sum = -1; - x = 0; - - do { - if (sum&0x8000) { - sum <<= 1; - sum++; - } else - sum <<= 1; - t = sum; - sum += (unsigned)*s++ & 0377; - x += sum^n; - if ((sum&0xffff) <= (t&0xffff)) { - sum ^= x; - } - } while (--n > 0); - - return(sum & 0xffff); -} - pkline(pk) register struct pack *pk; { -register i; + register i; + for(i=0;i>= 5; - for(k=0; n >>= 1; k++); - return(k); + for(k=0; n >>= 1; k++) + ; + return k; } diff --git a/usr/src/usr.bin/uucp/uucico/pk1.c b/usr/src/usr.bin/uucp/uucico/pk1.c index 841a160e04..fe984afcba 100644 --- a/usr/src/usr.bin/uucp/uucico/pk1.c +++ b/usr/src/usr.bin/uucp/uucico/pk1.c @@ -1,29 +1,40 @@ #ifndef lint -static char sccsid[] = "@(#)pk1.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)pk1.c 5.2 (Berkeley) %G%"; #endif -extern char *malloc(); - -#define USER 1 -#include -#ifdef SYSIII +#ifdef USG #include -#endif -#include "pk.p" +#endif USG #include #include "pk.h" +#include "uucp.h" #include #include #include +#ifdef BSD4_2 +#include +#endif BSD4_2 +#ifdef VMS +#include +#include +#include +int iomask[2]; +#endif VMS #define PKMAXSTMSG 40 #define PKTIME 25 +#define CONNODATA 10 +#define NTIMEOUT 10 + extern int Errorrate; +extern int errno; +extern char *sys_errlist[]; +extern jmp_buf Sjbuf; +extern char *malloc(); + int Connodata = 0; int Ntimeout = 0; -#define CONNODATA 10 -#define NTIMEOUT 50 /* * packet driver support routines * @@ -44,23 +55,23 @@ int ifn, ofn; register int i; if (++pkactive >= NPLINES) - return(NULL); + return NULL; if ((pk = (struct pack *) malloc(sizeof (struct pack))) == NULL) - return(NULL); - pkzero((caddr_t) pk, sizeof (struct pack)); + return NULL; + bzero((caddr_t) pk, sizeof (struct pack)); pk->p_ifn = ifn; pk->p_ofn = ofn; pk->p_xsize = pk->p_rsize = PACKSIZE; pk->p_rwindow = pk->p_swindow = WINDOWS; /* allocate input windows */ for (i = 0; i < pk->p_rwindow; i++) { - if ((bp = (char **) GETEPACK) == NULL) + if ((bp = (char **) malloc((unsigned)pk->p_xsize)) == NULL) break; *bp = (char *) pk->p_ipool; pk->p_ipool = bp; } if (i == 0) - return(NULL); + return NULL; pk->p_rwindow = i; /* start synchronization */ @@ -72,26 +83,26 @@ int ifn, ofn; } } if (i >= NPLINES) - return(NULL); + return NULL; pkoutput(pk); for (i = 0; i < PKMAXSTMSG; i++) { - PKGETPKT(pk); + pkgetpack(pk); if ((pk->p_state & LIVE) != 0) break; } if (i >= PKMAXSTMSG) - return(NULL); + return NULL; pkreset(pk); - return(pk); + return pk; } /* * input framing and block checking. * frame layout for most devices is: - * + * * S|K|X|Y|C|Z| ... data ... | * * where S == initial synch byte @@ -115,7 +126,7 @@ int pksizes[] = { pkgetpack(ipk) struct pack *ipk; { - int ret, k, tries; + int k, tries, noise; register char *p; register struct pack *pk; register struct header *h; @@ -124,36 +135,41 @@ struct pack *ipk; char **bp; char hdchk; - pk = PADDR; - if ((pk->p_state & DOWN) || - Connodata > CONNODATA /* || Ntimeout > NTIMEOUT */) + pk = ipk; + if ((pk->p_state & DOWN) || Connodata > CONNODATA || Ntimeout > NTIMEOUT) pkfail(); ifn = pk->p_ifn; /* find HEADER */ - for (tries = 0; tries < GETRIES; ) { + for (tries = 0, noise = 0; tries < GETRIES; ) { p = (caddr_t) &pk->p_ihbuf; - if ((ret = pkcget(ifn, p, 1)) < 0) { - /* set up retransmit or REJ */ - tries++; - pk->p_msg |= pk->p_rmsg; - if (pk->p_msg == 0) - pk->p_msg |= M_RR; - if ((pk->p_state & LIVE) == LIVE) - pk->p_state |= RXMIT; - pkoutput(pk); - continue; + if (pkcget(ifn, p, 1) == SUCCESS) { + if (*p++ == SYN) { + if (pkcget(ifn, p, HDRSIZ-1) == SUCCESS) + break; + } else + if (noise++ < (3*pk->p_rsize)) + continue; + DEBUG(4, "Noisy line - set up RXMIT", ""); + noise = 0; } + /* set up retransmit or REJ */ + tries++; + pk->p_msg |= pk->p_rmsg; + if (pk->p_msg == 0) + pk->p_msg |= M_RR; + if ((pk->p_state & LIVE) == LIVE) + pk->p_state |= RXMIT; + pkoutput(pk); + if (*p != SYN) continue; p++; - ret = pkcget(ifn, p, HDRSIZ - 1); - if (ret == -1) - continue; - break; + if (pkcget(ifn, p, HDRSIZ - 1) == SUCCESS) + break; } if (tries >= GETRIES) { - PKDEBUG(4, "tries = %d\n", tries); + DEBUG(4, "tries = %d\n", tries); pkfail(); } @@ -165,23 +181,22 @@ struct pack *ipk; sum = (unsigned) *p++ & 0377; sum |= (unsigned) *p << 8; h->sum = sum; - PKDEBUG(7, "rec h->cntl %o\n", (unsigned) h->cntl); + DEBUG(7, "rec h->cntl 0%o\n", h->cntl&0xff); k = h->ksize; if (hdchk != h->ccntl) { /* bad header */ - PKDEBUG(7, "bad header %o,", hdchk); - PKDEBUG(7, "h->ccntl %o\n", h->ccntl); + DEBUG(7, "bad header 0%o,", hdchk&0xff); + DEBUG(7, "h->ccntl 0%o\n", h->ccntl&0xff); return; } if (k == 9) { if (((h->sum + h->cntl) & 0xffff) == CHECK) { pkcntl(h->cntl, pk); - PKDEBUG(7, "state - %o\n", pk->p_state); - } - else { + DEBUG(7, "state - 0%o\n", pk->p_state); + } else { /* bad header */ - PKDEBUG(7, "bad header (k==9) %o\n", h->cntl); pk->p_state |= BADFRAME; + DEBUG(7, "bad header (k==9) 0%o\n", h->cntl&0xff); } return; } @@ -190,31 +205,28 @@ struct pack *ipk; pksack(pk); Connodata = 0; bp = pk->p_ipool; - pk->p_ipool = (char **) *bp; if (bp == NULL) { - PKDEBUG(7, "bp NULL %s\n", ""); - return; + DEBUG(7, "bp NULL %s\n", ""); + return; } - } - else { + pk->p_ipool = (char **) *bp; + } else { return; } - ret = pkcget(pk->p_ifn, (char *) bp, pk->p_rsize); - if (ret == 0) + if (pkcget(pk->p_ifn, (char *) bp, pk->p_rsize) == SUCCESS) pkdata(h->cntl, h->sum, pk, (char **) bp); - return; + Ntimeout = 0; } - pkdata(c, sum, pk, bp) char c; unsigned short sum; register struct pack *pk; char **bp; { -register x; -int t; -char m; + register x; + int t; + char m; if (pk->p_state & DRAINO || !(pk->p_state & LIVE)) { pk->p_msg |= pk->p_rmsg; @@ -237,7 +249,6 @@ slot: pk->p_is[x] = c; pk->p_isum[x] = sum; pk->p_ib[x] = (char *)bp; - return; } @@ -245,9 +256,6 @@ slot: /* * setup input transfers */ -pkrstart(pk) -{} - #define PKMAXBUF 128 /* * Start transmission on output device associated with pk. @@ -262,7 +270,6 @@ char cntl; register x; { register char *p; - int ret; short checkword; char hdchk; @@ -284,34 +291,32 @@ register x; *p = cntl; hdchk ^= *p++; *p = hdchk; - /* writes */ -PKDEBUG(7, "send %o\n", (unsigned) cntl); + /* writes */ + DEBUG(7, "send 0%o\n", cntl&0xff); p = (caddr_t) & pk->p_ohbuf; if (x < 0) { -#ifdef PROTODEBUG - GENERROR(p, HDRSIZ); -#endif - ret = write(pk->p_ofn, p, HDRSIZ); - PKASSERT(ret == HDRSIZ, "PKXSTART ret", "", ret); + if(write(pk->p_ofn, p, HDRSIZ) != HDRSIZ) { + alarm(0); + logent("PKXSTART write failed", sys_errlist[errno]); + longjmp(Sjbuf, 4); + } } else { char buf[PKMAXBUF + HDRSIZ], *b; int i; - for (i = 0, b = buf; i < HDRSIZ; i++) + for (i = 0, b = buf; i < HDRSIZ; i++) *b++ = *p++; for (i = 0, p = pk->p_ob[x]; i < pk->p_xsize; i++) *b++ = *p++; -#ifdef PROTODEBUG - GENERROR(buf, pk->p_xsize + HDRSIZ); -#endif - ret = write(pk->p_ofn, buf, pk->p_xsize + HDRSIZ); - PKASSERT(ret == pk->p_xsize + HDRSIZ, - "PKXSTART ret", "", ret); + if (write(pk->p_ofn, buf, pk->p_xsize + HDRSIZ) != (HDRSIZ + pk->p_xsize)) { + alarm(0); + logent("PKXSTART write failed", sys_errlist[errno]); + longjmp(Sjbuf, 5); + } Connodata = 0; } if (pk->p_msg) pkoutput(pk); - return; } @@ -332,7 +337,6 @@ int count, flag; } for (i = 0; i < count; i++) *d++ = *s++; - return; } @@ -348,49 +352,83 @@ int count, flag; */ jmp_buf Getjbuf; -cgalarm() { longjmp(Getjbuf, 1); } +cgalarm() +{ + longjmp(Getjbuf, 1); +} pkcget(fn, b, n) int fn, n; register char *b; { register int nchars, ret; + extern int linebaudrate; +#ifdef BSD4_2 + long r, itime = 0; + struct timeval tv; +#endif BSD4_2 +#ifdef VMS + short iosb[4]; + int SYS$QioW(); /* use this for long reads on vms */ +#endif VMS if (setjmp(Getjbuf)) { Ntimeout++; - PKDEBUG(4, "alarm %d\n", Ntimeout); - return(-1); + DEBUG(4, "pkcget: alarm %d\n", Ntimeout); + return FAIL; } signal(SIGALRM, cgalarm); alarm(PKTIME); - for (nchars = 0; nchars < n; nchars += ret) { + for (nchars = 0; nchars < n; ) { +#ifndef VMS ret = read(fn, b, n - nchars); +#else VMS + _$Cancel_IO_On_Signal = FD_FAB_Pointer[fn]; + ret = SYS$QioW(_$EFN,(FD_FAB_Pointer[fn]->fab).fab$l_stv, + IO$_READVBLK|IO$M_NOFILTR|IO$M_NOECHO, + iosb,0,0,b,n-nchars,0, + iomask,0,0); + _$Cancel_IO_On_Signal = 0; + if (ret == SS$_NORMAL) + ret = iosb[1]+iosb[3]; /* get length of transfer */ + else + ret = 0; +#endif VMS if (ret == 0) { alarm(0); - return(-1); + return FAIL; } - PKASSERT(ret > 0, "PKCGET READ", "", ret); - b += ret; + if (ret <= 0) { + alarm(0); + logent("PKCGET read failed", sys_errlist[errno]); + longjmp(Sjbuf, 6); + } + b += ret; + nchars += ret; + if (nchars < n) +#ifndef BSD4_2 + if (linebaudrate > 0 && linebaudrate < 4800) + sleep(1); +#else BSD4_2 + if (linebaudrate > 0) { + r = (n - nchars) * 100000; + r = r / linebaudrate; + r = (r * 100) - itime; + itime = 0; + /* we predict that more than 1/50th of a + second will go by before the read will + give back all that we want. */ + if (r > 20000) { + tv.tv_sec = r / 1000000L; + tv.tv_usec = r % 1000000L; + DEBUG(11, "PKCGET stall for %d", tv.tv_sec); + DEBUG(11, ".%06d sec\n", tv.tv_usec); + (void) select (fn, (int *)0, (int *)0, (int *)0, &tv); + } + } +#endif BSD4_2 } alarm(0); - return(0); + return SUCCESS; } - - -#ifdef PROTODEBUG -generror(p, s) -char *p; -int s; -{ - int r; - if (Errorrate != 0 && (rand() % Errorrate) == 0) { - r = rand() % s; -fprintf(stderr, "gen err at %o, (%o), ", r, (unsigned) *(p + r)); - *(p + r) += 1; - } - return; -} - - -#endif diff --git a/usr/src/usr.bin/uucp/uuclean/uuclean.c b/usr/src/usr.bin/uucp/uuclean/uuclean.c index 3e9d957705..224493f609 100644 --- a/usr/src/usr.bin/uucp/uuclean/uuclean.c +++ b/usr/src/usr.bin/uucp/uuclean/uuclean.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uuclean.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)uuclean.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" @@ -15,7 +15,6 @@ static char sccsid[] = "@(#)uuclean.c 5.2 (Berkeley) %G%"; extern time_t time(); - /******* * * uuclean - this program will search through the spool @@ -35,9 +34,10 @@ extern time_t time(); * 1 - can not read directory */ -#define DPREFIX "U" #define NOMTIME 72 /* hours to age files before deletion */ +int checkprefix = 0; + main(argc, argv) char *argv[]; { @@ -46,7 +46,6 @@ char *argv[]; time_t nomtime, ptime; struct stat stbuf; int mflg=0; - int orig_uid = getuid(); strcpy(Progname, "uuclean"); uucpname(Myname); @@ -64,11 +63,12 @@ char *argv[]; nomtime = atoi(&argv[1][2]) * (time_t)3600; break; case 'p': + checkprefix = 1; if (&argv[1][2] != '\0') stpre(&argv[1][2]); break; case 'x': - chkdebug(orig_uid); + chkdebug(); Debug = atoi(&argv[1][2]); if (Debug <= 0) Debug = 1; @@ -80,7 +80,10 @@ char *argv[]; } DEBUG(4, "DEBUG# %s\n", "START"); - chdir(Spool); /* NO subdirs in uuclean! rti!trt */ + if (chdir(Spool) < 0) { /* NO subdirs in uuclean! rti!trt */ + printf("%s directory inaccessible\n", Spool); + exit(1); + } if ((dirp = opendir(Spool)) == NULL) { printf("%s directory unreadable\n", Spool); @@ -89,28 +92,25 @@ char *argv[]; time(&ptime); while (gnamef(dirp, file)) { - if (!chkpre(file)) + if (checkprefix && !chkpre(file)) continue; - if (stat(file, &stbuf) == -1) { /* NO subdirs in uuclean! */ - DEBUG(4, "stat on %s failed\n", file); + if (stat(file, &stbuf) == -1) { + DEBUG(4, "stat on %s failed\n", file); continue; } if ((stbuf.st_mode & S_IFMT) == S_IFDIR) continue; -/* - * teklabs.1518, Terry Laskodi, +2s/ctime/mtime/ - * so mv-ing files about does not defeat uuclean - */ if ((ptime - stbuf.st_mtime) < nomtime) continue; if (file[0] == CMDPRE) notfyuser(file); DEBUG(4, "unlink file %s\n", file); unlink(file); - if (mflg) sdmail(file, stbuf.st_uid); + if (mflg) + sdmail(file, stbuf.st_uid); } closedir(dirp); @@ -187,16 +187,14 @@ char *file; if (numrq == 1) { strcat(msg, "REQUEST: "); strcat(msg, frqst); - } - else { + } else { strcat(msg, "FIRST REQUEST: "); strcat(msg, frqst); strcat(msg, "\nLAST REQUEST: "); strcat(msg, lrqst); } - getargs(frqst, args); - mailst(args[3], msg, ""); - return; + getargs(frqst, args, 10); + mailst(args[3], msg, CNULL); } @@ -218,16 +216,14 @@ char *file; char mstr[40]; sprintf(mstr, "uuclean deleted file %s\n", file); - if (pwd->pw_uid == uid) { - mailst(pwd->pw_name, mstr, ""); - return(0); + if (pwd != NULL && pwd->pw_uid == uid) { + mailst(pwd->pw_name, mstr, CNULL); + return; } setpwent(); - if ((pwd = getpwuid(uid)) != NULL) { - mailst(pwd->pw_name, mstr, ""); - } - return(0); + if ((pwd = getpwuid(uid)) != NULL) + mailst(pwd->pw_name, mstr, CNULL); } cleanup(code) diff --git a/usr/src/usr.bin/uucp/uucp/uucp.c b/usr/src/usr.bin/uucp/uucp/uucp.c index b8158b1ba4..708c1fa449 100644 --- a/usr/src/usr.bin/uucp/uucp/uucp.c +++ b/usr/src/usr.bin/uucp/uucp/uucp.c @@ -1,28 +1,33 @@ #ifndef lint -static char sccsid[] = "@(#)uucp.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uucp.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" #include #include +#include "uust.h" /* * uucp */ - int Uid; char *Ropt = " "; char Path[100], Optns[10], Ename[8]; char Grade = 'n'; +#ifdef DONTCOPY +int Copy = 0; +#else !DONTCOPY int Copy = 1; +#endif !DONTCOPY char Nuser[32]; /* variables used to check if talking to more than one system. */ int xsflag = -1; char xsys[8] = 0; -#define MAXCOUNT 20 /* maximun number of commands per C. file */ - +long Nbytes = 0; +#define MAXBYTES 50000 /* maximun number of bytes of data per C. file */ +#define MAXCOUNT 15 /* maximun number of files per C. file */ main(argc, argv) char *argv[]; @@ -30,17 +35,25 @@ char *argv[]; int ret; register char *sysfile1, *sysfl2, *cp; char file1[MAXFULLNAME], file2[MAXFULLNAME]; - int orig_uid = getuid(); + int avoidgwd = 0; strcpy(Progname, "uucp"); uucpname(Myname); umask(WFMASK); Optns[0] = '-'; Optns[1] = 'd'; +#ifdef DONTCOPY + Optns[2] = 'c'; +#else !DONTCOPY Optns[2] = 'C'; +#endif !DONTCOPY Ename[0] = Nuser[0] = Optns[3] = '\0'; while(argc>1 && argv[1][0] == '-'){ switch(argv[1][1]){ + case 'a': + /* efficiency hack; avoid gwd call */ + avoidgwd = 1; + break; case 'C': Copy = 1; Optns[2] = 'C'; @@ -58,7 +71,8 @@ char *argv[]; sprintf(Ename, "%.7s", &argv[1][2]); break; case 'g': - Grade = argv[1][2]; break; + Grade = argv[1][2]; + break; case 'm': strcat(Optns, "m"); break; @@ -71,7 +85,7 @@ char *argv[]; case 's': Spool = &argv[1][2]; break; case 'x': - chkdebug(orig_uid); + chkdebug(); Debug = atoi(&argv[1][2]); if (Debug <= 0) Debug = 1; @@ -82,19 +96,21 @@ char *argv[]; --argc; argv++; } DEBUG(4, "\n\n** %s **\n", "START"); - gwd(Wrkdir); - subchdir(Spool); + if (!avoidgwd) + gwd(Wrkdir); + ret = subchdir(Spool); + ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); Uid = getuid(); ret = guinfo(Uid, User, Path); - ASSERT(ret == 0, "CAN NOT FIND UID", "", Uid); + ASSERT(ret == 0, "CAN NOT FIND UID", CNULL, Uid); DEBUG(4, "UID %d, ", Uid); DEBUG(4, "User %s,", User); DEBUG(4, "Ename (%s) ", Ename); DEBUG(4, "PATH %s\n", Path); if (argc < 3) { fprintf(stderr, "usage uucp from ... to\n"); - cleanup(0); + cleanup(1); } @@ -108,7 +124,13 @@ char *argv[]; sprintf(Rmtname, "%.7s", sysfl2); if (versys(sysfl2) != 0) { fprintf(stderr, "bad system name: %s\n", sysfl2); - cleanup(0); + cleanup(1); + } + /* block multi-hop requests immediately */ + if (index(cp+1, '!') != NULL) { + fprintf(stderr, "uucp handles only adjacent sites.\n"); + fprintf(stderr, "Try uusend for multi-hop delivery.\n"); + cleanup(1); } strcpy(file2, cp + 1); } @@ -164,9 +186,8 @@ int code; } -/*** - * copy(s1, f1, s2, f2) generate copy files - * char *s1, *f1, *s2, *f2; +/* + * generate copy files * * return codes 0 | FAIL */ @@ -200,20 +221,20 @@ register char *s1, *f1, *s2, *f2; /* all work here */ DEBUG(4, "all work here %d\n", type); if (ckexpf(file1)) - return(FAIL); + return FAIL; if (ckexpf(file2)) - return(FAIL); + return FAIL; if (stat(subfile(file1), &stbuf) != 0) { fprintf(stderr, "can't get file status %s \n copy failed\n", file1); - return(0); + return SUCCESS; } statret = stat(subfile(file2), &stbuf1); if (statret == 0 && stbuf.st_ino == stbuf1.st_ino && stbuf.st_dev == stbuf1.st_dev) { fprintf(stderr, "%s %s - same file; can't copy\n", file1, file2); - return(0); + return SUCCESS; } if (chkpth(User, "", file1) != 0 || chkperm(file2, index(Optns, 'd')) @@ -224,33 +245,33 @@ register char *s1, *f1, *s2, *f2; if ((stbuf.st_mode & ANYREAD) == 0) { fprintf(stderr, "can't read file (%s) mode (%o)\n", file1, stbuf.st_mode); - return(FAIL); + return FAIL; } if (statret == 0 && (stbuf1.st_mode & ANYWRITE) == 0) { fprintf(stderr, "can't write file (%s) mode (%o)\n", file2, stbuf.st_mode); - return(FAIL); + return FAIL; } xcp(file1, file2); logent("WORK HERE", "DONE"); - return(0); + return SUCCESS; case 1: /* receive file */ DEBUG(4, "receive file - %d\n", type); chsys(s1); if (file1[0] != '~') if (ckexpf(file1)) - return(FAIL); + return FAIL; if (ckexpf(file2)) - return(FAIL); + return FAIL; if (chkpth(User, "", file2) != 0) { fprintf(stderr, "permission denied\n"); - return(FAIL); + return FAIL; } if (Ename[0] != '\0') { /* execute uux - remote uucp */ xuux(Ename, s1, file1, s2, file2, opts); - return(0); + return SUCCESS; } cfp = gtcfile(s1); @@ -259,30 +280,30 @@ register char *s1, *f1, *s2, *f2; case 2: /* send file */ if (ckexpf(file1)) - return(FAIL); + return FAIL; if (file2[0] != '~') if (ckexpf(file2)) - return(FAIL); + return FAIL; DEBUG(4, "send file - %d\n", type); chsys(s2); if (chkpth(User, "", file1) != 0) { fprintf(stderr, "permission denied %s\n", file1); - return(FAIL); + return FAIL; } if (stat(subfile(file1), &stbuf) != 0) { fprintf(stderr, "can't get status for file %s\n", file1); - return(FAIL); + return FAIL; } if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { fprintf(stderr, "directory name illegal - %s\n", file1); - return(FAIL); + return FAIL; } if ((stbuf.st_mode & ANYREAD) == 0) { fprintf(stderr, "can't read file (%s) mode (%o)\n", file1, stbuf.st_mode); - return(FAIL); + return FAIL; } if ((Nuser[0] != '\0') && (index(Optns, 'n') == NULL)) strcat(Optns, "n"); @@ -291,13 +312,14 @@ register char *s1, *f1, *s2, *f2; if (Nuser[0] != '\0') sprintf(opts, "-n%s", Nuser); xuux(Ename, s1, file1, s2, file2, opts); - return(0); + return SUCCESS; } + Nbytes += stbuf.st_size; if (Copy) { - gename(DATAPRE, s2, Grade, dfile); + gename(DATAPRE, Myname, Grade, dfile); if (xcp(file1, dfile) != 0) { fprintf(stderr, "can't copy %s\n", file1); - return(FAIL); + return FAIL; } } else { @@ -316,26 +338,26 @@ register char *s1, *f1, *s2, *f2; chsys(s1); if (strcmp(s2, Myname) == SAME) { if (ckexpf(file2)) - return(FAIL); + return FAIL; if (chkpth(User, "", file2) != 0) { fprintf(stderr, "permission denied\n"); - return(FAIL); + return FAIL; } } if (Ename[0] != '\0') { /* execute uux - remote uucp */ xuux(Ename, s1, file1, s2, file2, opts); - return(0); + return SUCCESS; } cfp = gtcfile(s1); fprintf(cfp, "X %s %s!%s %s %s\n", file1, s2, file2, User, Optns); break; } - return(0); + return SUCCESS; } -/*** - * xuux(ename, s1, s2, f1, f2, opts) execute uux for remote uucp +/* + * execute uux for remote uucp * * return code - none */ @@ -361,8 +383,8 @@ char *ename, *s1, *s2, *f1, *f2, *opts; FILE *Cfp = NULL; char Cfile[NAMESIZE]; -/*** - * gtcfile(sys) - get a Cfile descriptor +/* + * get a Cfile descriptor * * return an open file descriptor */ @@ -376,24 +398,29 @@ register char *sys; register int savemask; if (strcmp(presys, sys) != SAME /* this is !SAME on first call */ + || Nbytes > MAXBYTES || ++cmdcount > MAXCOUNT) { - cmdcount = 1; + Nbytes = 0; if (presys[0] != '\0') { clscfile(); } gename(CMDPRE, sys, Grade, Cfile); +#ifdef VMS + savemask = umask(~0600); /* vms must have read permission */ +#else !VMS savemask = umask(~0200); +#endif !VMS Cfp = fopen(subfile(Cfile), "w"); umask(savemask); - ASSERT(Cfp != NULL, "CAN'T OPEN", Cfile, 0); + ASSERT(Cfp != NULL, CANTOPEN, Cfile, 0); strcpy(presys, sys); } - return(Cfp); + return Cfp; } -/*** - * clscfile() - close cfile +/* + * close cfile * * return code - none */ @@ -405,19 +432,13 @@ clscfile() fclose(Cfp); chmod(subfile(Cfile), ~WFMASK & 0777); logent(Cfile, "QUE'D"); + US_CRS(Cfile); Cfp = NULL; - return; } -/**** - * - * chsys(s1) compile a list of all systems we are referencing - * char *s1 - * - * no return code -- sets up the xsys array. - * Author: mcnc!swd, Stephen Daniel +/* + * compile a list of all systems we are referencing */ - chsys(s1) register char *s1; { @@ -431,7 +452,7 @@ register char *s1; return; } - if (strcmp(xsys, s1) == SAME) + if (strncmp(xsys, s1, 7) == SAME) return; xsflag++; diff --git a/usr/src/usr.bin/uucp/uulog/uulog.c b/usr/src/usr.bin/uucp/uulog/uulog.c index 569c091f72..0271044096 100644 --- a/usr/src/usr.bin/uucp/uulog/uulog.c +++ b/usr/src/usr.bin/uucp/uulog/uulog.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uulog.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uulog.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" diff --git a/usr/src/usr.bin/uucp/uuname/uuname.c b/usr/src/usr.bin/uucp/uuname/uuname.c index ec91526194..95d4a5fe4b 100644 --- a/usr/src/usr.bin/uucp/uuname/uuname.c +++ b/usr/src/usr.bin/uucp/uuname/uuname.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uuname.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uuname.c 5.2 (Berkeley) %G%"; #endif #include "uucp.h" @@ -17,6 +17,7 @@ main(argc,argv) char *argv[]; int argc; { + int ret; int i; int intrEXIT(); FILE *np; @@ -24,7 +25,8 @@ int argc; char prev[1000]; char s[1000]; - chdir(Spool); + ret = chdir(Spool); + ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); strcpy(Progname, "uuname"); signal(SIGILL, intrEXIT); signal(SIGTRAP, intrEXIT); @@ -39,7 +41,7 @@ int argc; signal(SIGQUIT, intrEXIT); signal(SIGTERM, intrEXIT); - if(argv[1][0] == '-' && argv[1][1] == 'l') { + if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'l') { uucpname(s); printf("%s\n",s); exit(0); @@ -67,3 +69,9 @@ intrEXIT(inter) { exit(inter); } + +cleanup(code) +int code; +{ + exit(code); +} diff --git a/usr/src/usr.bin/uucp/uupoll/uupoll.c b/usr/src/usr.bin/uucp/uupoll/uupoll.c index 12a577c411..cccfd49b53 100644 --- a/usr/src/usr.bin/uucp/uupoll/uupoll.c +++ b/usr/src/usr.bin/uucp/uupoll/uupoll.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uupoll.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uupoll.c 5.2 (Berkeley) %G%"; #endif /* @@ -18,12 +18,17 @@ main(argc, argv) register int argc; register char **argv; { + int ret; + char wrkpre[MAXFULLNAME]; + char file[MAXFULLNAME]; + if (argc < 2) { fprintf(stderr, "usage: uupoll system ...\n"); cleanup(1); } - chdir(Spool); + ret = chdir(Spool); + ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); strcpy(Progname, "uupoll"); uucpname(Myname); @@ -38,7 +43,15 @@ register char **argv; continue; } /* Remove any STST file that might stop the poll */ - rmstat(argv[0]); + sprintf(wrkpre, "LCK..%.7s", argv[0]); + if (access(wrkpre, 0) < 0) + rmstat(argv[0]); + sprintf(wrkpre, "%c.%.7s", CMDPRE, argv[0]); + if (!iswrk(file, "chk", Spool, wrkpre)) { + sprintf(file, "%s/%c.%.7szPOLL", subdir(Spool, CMDPRE), + CMDPRE, argv[0]); + close(creat(file, 0666)); + } /* Attempt the call */ xuucico(argv[0]); } diff --git a/usr/src/usr.bin/uucp/uusend/uusend.c b/usr/src/usr.bin/uucp/uusend/uusend.c index 347e781240..a02850532b 100644 --- a/usr/src/usr.bin/uucp/uusend/uusend.c +++ b/usr/src/usr.bin/uucp/uusend/uusend.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uusend.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uusend.c 5.2 (Berkeley) %G%"; #endif /* @@ -27,17 +27,25 @@ static char sccsid[] = "@(#)uusend.c 5.1 (Berkeley) %G%"; #include #include +/* + * define RECOVER to permit requests like 'uusend file sys1!sys2!~uucp' + * (abbreviation for 'uusend file sys1!sys2!~uucp/file'). + * define DEBUG to keep log of uusend uusage. + * define RUUSEND if neighboring sites permit 'ruusend', + * which they certainly should to avoid security holes + */ #define RECOVER +/*#define DEBUG "/usr/spool/uucp/uusend.log"/**/ FILE *in, *out; FILE *dout; -FILE *popen(); -char *index(), *strcpy(); +extern FILE *popen(); +extern char *index(), *strcpy(), *strcat(), *ctime(); #ifdef RUUSEND int rsend; -#endif +#endif RUUSEND int mode = -1; /* mode to chmod new file to */ char *nextsys; /* next system in the chain */ char dnbuf[200]; /* buffer for result of ~user/file */ @@ -60,40 +68,38 @@ char *filename; /* file name from end of destname */ char *getfname(); /* routine to get filename from destname */ int fflg; char f[100]; /* name of default output file */ -#else +#else !RECOVER char *f = ""; /* so we waste a little space */ -#endif +#endif !RECOVER main(argc, argv) int argc; char **argv; { register int c; - long count = 0; + long count; + extern char **environ; #ifdef DEBUG long t; + umask(022); dout = fopen(DEBUG, "a"); if (dout == NULL) { printf("Cannot append to %s\n", DEBUG); exit(1); } freopen(DEBUG, "a", stdout); -/*xxx - freopen(DEBUG, "a", stderr); - xxx*/ - chmod(DEBUG, 0666); fprintf(dout, "\nuusend run: "); for (c=0; c 1 && argv[1][0] == '-' && argv[1][1]) { switch(argv[1][1]) { case 'm': @@ -109,7 +115,7 @@ char **argv; fflg++; strcpy(f, argv[1]); break; -#endif +#endif RECOVER default: fprintf(stderr, "Bad flag: %s\n", argv[1]); break; @@ -133,7 +139,7 @@ char **argv; fprintf(stderr, "illegal input\n"); exit(2); } -#endif +#endif RUUSEND in = fopen(sourcename, "r"); if (in == NULL) { perror(argv[1]); @@ -159,14 +165,14 @@ char **argv; mode = stbuf.st_mode & 0777; } #ifdef RUUSEND - sprintf(cmdbuf,"uux %s- \"%s!ruusend %s -m %o - (%s)\"", -#else - sprintf(cmdbuf, "uux %s- \"%s!uusend %s -m %o - (%s)\"", -#endif + sprintf(cmdbuf,"uux -gn -z %s- \"%s!ruusend %s -m %o - (%s)\"", +#else !RUUSEND + sprintf(cmdbuf, "uux -gn -z %s- \"%s!uusend %s -m %o - (%s)\"", +#endif !RUUSEND rflg, nextsys, f, mode, destname); #ifdef DEBUG fprintf(dout, "remote: nextsys='%s', destname='%s', cmd='%s'\n", nextsys, destname, cmdbuf); -#endif +#endif DEBUG out = popen(cmdbuf, "w"); } else { /* @@ -176,7 +182,7 @@ char **argv; #ifdef DEBUG fprintf(dout, "before ~: '%s'\n", destname); fflush(dout); -#endif +#endif DEBUG sl = index(destname, '/'); #ifdef RECOVER if (sl == NULL && !fflg) { @@ -185,13 +191,13 @@ fflush(dout); } for (sl = destname; *sl != '\0'; sl++) ; /* boy, is this a hack! */ -#else +#else !RECOVER if (sl == NULL) { fprintf(stderr, "Illegal ~user\n"); exit(3); } *sl++ = 0; -#endif +#endif !RECOVER user = getpwnam(destname+1); if (user == NULL) { fprintf(stderr, "No such user as %s\n", @@ -211,19 +217,19 @@ fflush(dout); strcat(dnbuf, "/"); strcat(dnbuf, sl); } -#else +#else !RECOVER exit(4); } strcpy(dnbuf, user->pw_dir); strcat(dnbuf, "/"); strcat(dnbuf, sl); -#endif +#endif !RECOVER destname = dnbuf; } #ifdef RECOVER else destname = strcpy(dnbuf, destname); -#endif +#endif !RECOVER if(strncmp(UULIB, destname, strlen(UULIB)) == 0) { fprintf(stderr, "illegal file: %s", destname); exit(4); @@ -232,14 +238,14 @@ fflush(dout); if (stat(destname, &stbuf) == 0 && (stbuf.st_mode & S_IFMT) == S_IFDIR && fflg) { - strcat(dnbuf, "/"); - strcat(dnbuf, &f[2]); + strcat(destname, "/"); + strcat(destname, &f[2]); } -#endif +#endif RECOVER out = fopen(destname, "w"); #ifdef DEBUG fprintf(dout, "local, file='%s'\n", destname); -#endif +#endif DEBUG if (out == NULL) { perror(destname); #ifdef RECOVER @@ -252,22 +258,19 @@ fflush(dout); if (user != NULL) { strcat(destname, user->pw_name); if (stat(destname, &stbuf) == -1) { - mkdir(destname); - chmod(destname, 0777); + mkdir(destname, 0777); } strcat(destname, "/"); } -#ifdef RECOVER if (fflg) strcat(destname, &f[2]); else strcat(destname, filename); -#endif if ((out = fopen(destname, "w")) == NULL) exit(5); /* all for naught! */ -#else +#else !RECOVER exit(5); -#endif +#endif !RECOVER } if (mode > 0) chmod(destname, mode); /* don't bother to check it */ @@ -277,6 +280,7 @@ fflush(dout); * Now, in any case, copy from in to out. */ + count = 0; while ((c=getc(in)) != EOF) { putc(c, out); count++; @@ -284,8 +288,8 @@ fflush(dout); #ifdef DEBUG fprintf(dout, "count %ld bytes\n", count); fclose(dout); -#endif - +#endif DEBUG + fclose(in); fclose(out); /* really should pclose in that case */ exit(0); @@ -329,28 +333,32 @@ register char *p; return (p); } -mkdir(dirname) +#ifndef BSD4_2 +makedir(dirname, mode) char *dirname; +int mode; { register int pid; int retcode, status; switch ((pid = fork())) { case -1: /* error */ return (-1); - break; case 0: /* child */ umask(0); - execl("/bin/mkdir", "mkdir", dirname, 0); + execl("/bin/mkdir", "mkdir", dirname, (char *)0); exit(1); - break; + /* NOTREACHED */ default: /* parent */ while ((retcode=wait(&status)) != pid && retcode != -1) ; if (retcode == -1) - return (-1); - else - return (status); - break; + return -1; + else { + chmod(dirname, mode); + return status; + } } + /* NOTREACHED */ } -#endif +#endif !BSD4_2 +#endif RECOVER diff --git a/usr/src/usr.bin/uucp/uusnap/uusnap.c b/usr/src/usr.bin/uucp/uusnap/uusnap.c index 68a178decf..99256e2281 100644 --- a/usr/src/usr.bin/uucp/uusnap/uusnap.c +++ b/usr/src/usr.bin/uucp/uusnap/uusnap.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uusnap.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)uusnap.c 5.3 (Berkeley) %G%"; #endif /* @@ -21,27 +21,15 @@ char SYSBUF[BUFSIZ]; #endif #define NSYSTEM 100 /* max # of systems queued */ -#define SPOOLDR "/usr/spool/uucp" /* Where STST files are */ -#ifdef UUDIR -#define CMDSDIR "/usr/spool/uucp/C." /* Name of commands dir */ -#define DATADIR "/usr/spool/uucp/D." /* Name of data directory */ -#define XEQTDIR "/usr/spool/uucp/X." /* Name of execute dir */ -#else -#define CMDSDIR "/usr/spool/uucp" /* Name of commands dir */ -#define DATADIR "/usr/spool/uucp" /* Name of data directory */ -#define XEQTDIR "/usr/spool/uucp" /* Name of execute dir */ -#endif #define CMDSLEN 5 /* Length of trailer */ #define DATALEN 5 /* Length of trailer */ -/* rti!trt: XEQTLEN was 0, for reverse search, but that did not work. */ #define XEQTLEN 5 /* Length of trailer */ #define NUMCTRS 3 /* # file types to count */ #define CMDTYPE 0 /* Index into scnt.cntr */ #define DATTYPE 1 /* Index into scnt.cntr */ #define XEQTYPE 2 /* Index into scnt.cntr */ -void scandir(), getstst(); extern char *index(), *rindex(), *strcpy(), *strncpy();; extern long atol(); extern time_t time(); @@ -50,7 +38,7 @@ struct scnt { /* System count structure */ char name[16]; /* Name of system */ short cntr[NUMCTRS]; /* Count */ char stst[32]; /* STST Message */ - short locked; /* If LCK..sys present */ + time_t locked; /* If LCK..sys present */ int st_type; /* STST Type */ int st_count; /* STST Count */ time_t st_lastime; /* STST Last time tried */ @@ -59,6 +47,7 @@ struct scnt { /* System count structure */ int sndx; /* Number of systems */ struct scnt sys[NSYSTEM]; /* Systems queued */ +int xqtisrunning = 0; main() { register int i, j, nlen = 0; @@ -68,75 +57,100 @@ main() scandir(CMDSDIR, "C.", CMDSLEN, NULL, CMDTYPE); scandir(DATADIR, "D.", DATALEN, NULL, DATTYPE); scandir(XEQTDIR, "X.", XEQTLEN, 'X', XEQTYPE); - getstst(SPOOLDR); + getstst(SPOOL); time(&curtime); for(i=0; i nlen) nlen = j; - for(i=0; i1?"s":" "); - else printf(" --- "); + else + printf(" --- "); if(sys[i].cntr[DATTYPE]) printf("%3.d Data ", sys[i].cntr[DATTYPE]); - else printf(" --- "); + else + printf(" --- "); if(sys[i].cntr[XEQTYPE]) printf("%3.d Xqt%s ", sys[i].cntr[XEQTYPE], sys[i].cntr[XEQTYPE]>1?"s":" "); - else printf(" --- "); - if(*sys[i].stst == NULL) - { if(sys[i].locked) + else + printf(" --- "); + if(*sys[i].stst == NULL || sys[i].locked > sys[i].st_lastime) { + if(sys[i].locked) printf("LOCKED\n"); - else printf("\n"); + else + printf("\n"); continue; } printf("%s ", sys[i].stst); - if(sys[i].st_type == SS_INPROGRESS) - { printf("\n"); + /* decide if STST info is worth pursuing */ + if (-t < ONEDAY*2 && (sys[i].st_count == 0 + || sys[i].st_type == SS_WRONGTIME + || (sys[i].st_type == SS_INPROGRESS && sys[i].locked))) { + printf("\n"); continue; } t = (sys[i].st_lastime +sys[i].st_retry) - curtime; - if(t <= 0) - printf("Retry time reached "); - else - { if(t < 60) - printf("Retry time %ld sec%s ", (long)(t%60), + if (-t < ONEDAY*2 && sys[i].st_type != SS_FAIL) + t = 0; + + if (sys[i].st_count > MAXRECALLS) + printf("at MAX RECALLS"); + else if (-t >= ONEDAY*2) + printf("%ld days ago", (long)-t/ONEDAY); + else if (t <= 0) + printf("Retry time reached"); + else if (t < 60) + printf("Retry time %ld sec%s", (long)(t%60), (t%60)!=1? "s": ""); - else printf("Retry time %ld min%s ", (long)(t/60), - (t/60)!=1? "s": ""); - } + else + printf("Retry time %ld min%s", (long)(t/60), + (t/60)!=1? "s": ""); if(sys[i].st_count > 1) - printf("Count: %d\n", sys[i].st_count); - else printf("\n"); + printf(" Count: %d\n", sys[i].st_count); + else + printf("\n"); } + if (xqtisrunning) + printf("\nUuxqt is running\n"); exit(0); } -void scandir(dnam, prfx, flen, fchr, type) + +scandir(dnam, prfx, flen, fchr, type) char *dnam, *prfx, fchr; -{ register int i, plen; +{ + register int i, plen; char fnam[MAXNAMLEN+1]; register struct direct *dentp; register DIR *dirp; plen = strlen(prfx); - if(chdir(dnam) < 0) - { perror(dnam); + if(chdir(dnam) < 0) { + perror(dnam); exit(1); } - if ((dirp = opendir(".", "r")) == NULL) - { perror(dnam); + if ((dirp = opendir(".")) == NULL) { + perror(dnam); exit(1); } - while((dentp = readdir(dirp)) != NULL) - { if(*dentp->d_name == '.' || dentp->d_ino == 0) + while((dentp = readdir(dirp)) != NULL) { + if(*dentp->d_name == '.') continue; if(strncmp(dentp->d_name, prfx, plen) != SAME) { -#ifdef UUDIR fprintf(stderr, "strange file (%s) in %s\n", dentp->d_name, dnam); -#endif continue; } strcpy(fnam, &dentp->d_name[plen]); @@ -144,126 +158,140 @@ char *dnam, *prfx, fchr; if(flen > 0) fnam[i -flen] = NULL; else - for(; i>0; --i) - { if(fnam[i] == fchr) - { fnam[i] = NULL; - break; + for(; i>0; --i) { + if(fnam[i] == fchr) { + fnam[i] = NULL; + break; + } } - } - for(i=0; id_ino == 0) + while ((dentp = readdir(dirp)) != NULL) { + if (strcmp(dentp->d_name, X_LOCK) == SAME) { + xqtisrunning++; continue; - if(strncmp(dentp->d_name, "LCK..", 5) == SAME) - { if(strncmp(&dentp->d_name[5], "tty", 3) == SAME || + } + if(strncmp(dentp->d_name, "LCK..", 5) == SAME) { + if(strncmp(&dentp->d_name[5], "tty", 3) == SAME || strncmp(&dentp->d_name[5], "cul", 3) == SAME) continue; strcpy(fnam, dentp->d_name); - for(csys=0; csysd_name, "STST.", 5) == SAME) - { strcpy(fnam, dentp->d_name); - for(csys=0; csysd_name == '.') + continue; + strcpy(fnam, dentp->d_name); + for(csys=0; csys" added. See cbosgd.2611 (Mark Horton) - * no-copy option "-c" added. Suggested by Steve Bellovin - * "-l" is synonym for "-c". - * "X" files use local system name, avoids conflict. Steve Bellovin - */ #include "uucp.h" #define NOSYSPART 0 #define HASSYSPART 1 #define APPCMD(d) {\ -char *p;\ -for (p = d; *p != '\0';) *cmdp++ = *p++;\ -*cmdp++ = ' ';\ -*cmdp = '\0';} +char *p; for (p = d; *p != '\0';) *cmdp++ = *p++; *cmdp++ = ' '; *cmdp = '\0';} #define GENSEND(f, a, b, c, d, e) {\ -fprintf(f, "S %s %s %s -%s %s 0666\n", a, b, c, d, e);\ -} -#define GENRCV(f, a, b, c) {\ -fprintf(f, "R %s %s %s - \n", a, b, c);\ -} - - -/* - * - */ +fprintf(f, "S %s %s %s -%s %s 0666\n", a, b, c, d, e); } +#define GENRCV(f, a, b, c) {fprintf(f, "R %s %s %s - \n", a, b, c);} main(argc, argv) char *argv[]; @@ -42,7 +25,12 @@ char *argv[]; char t2file[NAMESIZE]; /* temporary file name */ int cflag = 0; /* commands in C. file flag */ int rflag = 0; /* C. files for receiving flag */ +#ifdef DONTCOPY + int Copy = 0; /* Don't Copy spool files */ +#else !DONTCOPY int Copy = 1; /* Copy spool files */ +#endif !DONTCOPY + int Linkit = 0; /* Try link before copy */ char buf[BUFSIZ]; char inargs[BUFSIZ]; int pipein = 0; @@ -61,13 +49,18 @@ char *argv[]; char redir = '\0'; int nonoti = 0; int nonzero = 0; - int orig_uid = getuid(); + int link_failed; + char *ReturnTo = NULL; + extern int LocalOnly; strcpy(Progname, "uux"); uucpname(Myname); umask(WFMASK); Ofn = 1; Ifn = 0; +#ifdef VMS + arg_fix(argc, argv); +#endif while (argc>1 && argv[1][0] == '-') { switch(argv[1][1]){ case 'p': @@ -78,14 +71,22 @@ char *argv[]; startjob = 0; break; case 'c': + Copy = 0; + Linkit = 0; + break; case 'l': Copy = 0; + Linkit = 1; + break; + case 'C': + Copy = 1; + Linkit = 0; break; case 'g': Grade = argv[1][2]; break; case 'x': - chkdebug(orig_uid); + chkdebug(); Debug = atoi(&argv[1][2]); if (Debug <= 0) Debug = 1; @@ -96,12 +97,25 @@ char *argv[]; case 'z': nonzero = 1; break; + case 'L': + LocalOnly++; + break; + case 'a': + ReturnTo = &argv[1][2]; + break; default: fprintf(stderr, "unknown flag %s\n", argv[1]); break; } --argc; argv++; } + if (argc > 2) { + ret = gwd(Wrkdir); + if (ret != 0) { + fprintf(stderr, "can't get working directory; will try to continue\n"); + strcpy(Wrkdir, "/UNKNOWN"); + } + } DEBUG(4, "\n\n** %s **\n", "START"); @@ -112,12 +126,8 @@ char *argv[]; strcat(inargs, *argv++); } DEBUG(4, "arg - %s\n", inargs); - ret = gwd(Wrkdir); - if (ret != 0) { - fprintf(stderr, "can't get working directory; will try to continue\n"); - strcpy(Wrkdir, "/UNKNOWN"); - } - subchdir(Spool); + ret = subchdir(Spool); + ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); uid = getuid(); guinfo(uid, User, path); @@ -135,6 +145,9 @@ char *argv[]; fprintf(fprx, "%c\n", X_NONOTI); if (nonzero) fprintf(fprx, "%c\n", X_NONZERO); + if (ReturnTo == NULL || *ReturnTo == '\0') + ReturnTo = User; + fprintf(fprx, "%c %s\n", X_RETURNTO, ReturnTo); /* find remote system name */ ap = inargs; @@ -170,12 +183,14 @@ char *argv[]; fwrite(buf, 1, ret, fpd); } fclose(fpd); + strcpy(tfile, dfile); if (strcmp(local, xsys) != SAME) { - GENSEND(fpc, dfile, dfile, User, "", dfile); + tfile[strlen(local) + 2] = 'S'; + GENSEND(fpc, dfile, tfile, User, "", dfile); cflag++; } - fprintf(fprx, "%c %s\n", X_RQDFILE, dfile); - fprintf(fprx, "%c %s\n", X_STDIN, dfile); + fprintf(fprx, "%c %s\n", X_RQDFILE, tfile); + fprintf(fprx, "%c %s\n", X_STDIN, tfile); } /* parse command */ ap = inargs; @@ -253,14 +268,21 @@ char *argv[]; fprintf(stderr, "permission denied %s\n", rest); cleanup(EX_NOINPUT); } - if (Copy) { + link_failed = 0; + if (Linkit) { + if (link(subfile(rest), subfile(dfile)) != 0) + link_failed++; + else + GENSEND(fpc, rest, dfile, User, "", dfile); + } + if (Copy || link_failed) { if (xcp(rest, dfile) != 0) { fprintf(stderr, "can't copy %s to %s\n", rest, dfile); cleanup(EX_NOINPUT); } GENSEND(fpc, rest, dfile, User, "", dfile); } - else { + if (!Copy && !Linkit) { GENSEND(fpc, rest, dfile, User, "c", "D.0"); } cflag++; @@ -343,13 +365,24 @@ char *argv[]; continue; } + /* + * clean up trailing ' ' in command. + */ + if (cmdp > cmd && cmdp[0] == '\0' && cmdp[-1] == ' ') + *--cmdp = '\0'; + /* block multi-hop uux, which doesn't work */ + for (ap = cmd; *ap && *ap != ' '; ap++) + if (*ap == '!') { + fprintf(stderr, "uux handles only adjacent sites.\n"); + fprintf(stderr, "Try uusend for multi-hop delivery.\n"); + cleanup(1); + } fprintf(fprx, "%c %s\n", X_CMD, cmd); logent(cmd, "XQT QUE'D"); fclose(fprx); - strcpy(tfile, rxfile); - tfile[0] = XQTPRE; + gename(XQTPRE, local, Grade, tfile); if (strcmp(xsys, local) == SAME) { /* rti!trt: xmv() works across filesystems, link(II) doesnt */ xmv(rxfile, tfile); @@ -381,8 +414,8 @@ char *argv[]; char Fname[FTABSIZE][NAMESIZE]; int Fnamect = 0; -/*** - * cleanup - cleanup and unlink if error +/* + * cleanup and unlink if error * * return - none - do exit() */ @@ -403,8 +436,8 @@ int code; exit(code); } -/*** - * ufopen - open file and record name +/* + * open file and record name * * return file pointer. */ @@ -416,5 +449,31 @@ char *file, *mode; strcpy(Fname[Fnamect++], file); else logent("Fname", "TABLE OVERFLOW"); - return(fopen(subfile(file), mode)); + return fopen(subfile(file), mode); +} +#ifdef VMS +/* + * EUNICE bug: + * quotes are not stripped from DCL. Do it here. + * Note if we are running under Unix shell we don't + * do the right thing. + */ +arg_fix(argc, argv) +char **argv; +{ + register char *cp, *tp; + + for (; argc > 0; --argc, argv++) { + cp = *argv; + if (cp == (char *)0 || *cp++ != '"') + continue; + tp = cp; + while (*tp++) ; + tp -= 2; + if (*tp == '"') { + *tp = '\0'; + *argv = cp; + } + } } +#endif VMS diff --git a/usr/src/usr.bin/uucp/uuxqt/uuxqt.c b/usr/src/usr.bin/uucp/uuxqt/uuxqt.c index 63db493c0b..8050e0a530 100644 --- a/usr/src/usr.bin/uucp/uuxqt/uuxqt.c +++ b/usr/src/usr.bin/uucp/uuxqt/uuxqt.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uuxqt.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)uuxqt.c 5.3 (Berkeley) %G%"; #endif #include "uucp.h" @@ -10,12 +10,11 @@ static char sccsid[] = "@(#)uuxqt.c 5.2 (Berkeley) %G%"; #else #include #endif +#include #define APPCMD(d) {\ char *p;\ -for (p = d; *p != '\0';) *cmdp++ = *p++;\ -*cmdp++ = ' ';\ -*cmdp = '\0';} +for (p = d; *p != '\0';) *cmdp++ = *p++; *cmdp++ = ' '; *cmdp = '\0';} /* * uuxqt will execute commands set up by a uux command, @@ -23,27 +22,43 @@ for (p = d; *p != '\0';) *cmdp++ = *p++;\ */ #define NCMDS 50 -char *Cmds[NCMDS]; +char *Cmds[NCMDS+1]; +int Notify[NCMDS+1]; +#define NT_YES 0 /* if should notify on execution */ +#define NT_ERR 1 /* if should notify if non-zero exit status (-z equivalent) */ +#define NT_NO 2 /* if should not notify ever (-n equivalent) */ + +extern int Nfiles; int notiok = 1; int nonzero = 0; -char PATH[MAXFULLNAME] = "PATH=/bin:/usr/bin"; +#ifdef SIGCHLD +#include +reapchild() +{ + union wait status; + + while (wait3(&status,WNOHANG,0) > 0) + ; +} +#endif SIGCHLD + +char PATH[MAXFULLNAME] = "PATH=/bin:/usr/bin:/usr/ucb"; /* to remove restrictions from uuxqt * define ALLOK 1 * * to add allowable commands, add to the file CMDFILE * A line of form "PATH=..." changes the search path */ - - main(argc, argv) char *argv[]; { char xcmd[MAXFULLNAME]; int argnok; - char xfile[MAXFULLNAME], user[32], buf[BUFSIZ]; - char lbuf[30]; + int notiflg; + char xfile[MAXFULLNAME], user[MAXFULLNAME], buf[BUFSIZ]; + char lbuf[MAXFULLNAME]; char cfile[NAMESIZE], dfile[MAXFULLNAME]; char file[NAMESIZE]; char fin[MAXFULLNAME], sysout[NAMESIZE], fout[MAXFULLNAME]; @@ -51,21 +66,19 @@ char *argv[]; FILE *dfp; char path[MAXFULLNAME]; char cmd[BUFSIZ]; - /* set size of prm to something large -- cmcl2!salkind */ char *cmdp, prm[1000], *ptr; char *getprm(), *lastpart(); - int uid, ret, badfiles; + int uid, ret, ret2, badfiles; register int i; int stcico = 0; char retstat[30]; - int orig_uid = getuid(); strcpy(Progname, "uuxqt"); uucpname(Myname); - /* Try to run as uucp -- rti!trt */ - setgid(getegid()); - setuid(geteuid()); +#ifdef SIGCHLD + signal(SIGCHLD, reapchild); +#endif SIGCHLD umask(WFMASK); Ofn = 1; @@ -73,7 +86,7 @@ char *argv[]; while (argc>1 && argv[1][0] == '-') { switch(argv[1][1]){ case 'x': - chkdebug(orig_uid); + chkdebug(); Debug = atoi(&argv[1][2]); if (Debug <= 0) Debug = 1; @@ -86,18 +99,22 @@ char *argv[]; } DEBUG(4, "\n\n** %s **\n", "START"); - subchdir(Spool); + ret = subchdir(Spool); + ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); strcpy(Wrkdir, Spool); uid = getuid(); guinfo(uid, User, path); + /* Try to run as uucp -- rti!trt */ + setgid(getegid()); + setuid(geteuid()); + DEBUG(4, "User - %s\n", User); if (ulockf(X_LOCK, (time_t) X_LOCKTIME) != 0) exit(0); fp = fopen(CMDFILE, "r"); if (fp == NULL) { - /* Fall-back if CMDFILE missing. Sept 1982, rti!trt */ - logent("CAN'T OPEN", CMDFILE); + logent(CANTOPEN, CMDFILE); Cmds[0] = "rmail"; Cmds[1] = "rnews"; Cmds[2] = "ruusend"; @@ -105,39 +122,80 @@ char *argv[]; goto doprocess; } DEBUG(5, "%s opened\n", CMDFILE); - for (i=0; i= 0; --j) + if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') + xcmd[j] = '\0'; + else + break; + /* look for imbedded whitespace */ + for (; j >= 0; --j) + if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') + break; + /* skip this entry if it has embedded whitespace */ + /* This defends against a bad PATH=, for example */ + if (j >= 0) { + logent(xcmd, "BAD WHITESPACE"); + continue; + } if (strncmp(xcmd, "PATH=", 5) == 0) { strcpy(PATH, xcmd); - i--; /* kludge */ + i--; /*kludge */ continue; } DEBUG(5, "xcmd = %s\n", xcmd); - Cmds[i] = malloc((unsigned)(strlen(xcmd)+1)); + + if ((ptr = index(xcmd, ',')) != NULL) { + *ptr++ = '\0'; + if (strncmp(ptr, "Err", 3) == SAME) + Notify[i] = NT_ERR; + else if (strcmp(ptr, "No") == SAME) + Notify[i] = NT_NO; + else + Notify[i] = NT_YES; + } else + Notify[i] = NT_YES; + if ((Cmds[i] = malloc((unsigned)(strlen(xcmd)+1))) == NULL) { + DEBUG(1, "MALLOC FAILED", CNULL); + break; + } strcpy(Cmds[i], xcmd); } - Cmds[i] = 0; + Cmds[i] = CNULL; fclose(fp); doprocess: - DEBUG(4, "process %s\n", ""); + DEBUG(4, "process %s\n", CNULL); while (gtxfile(xfile) > 0) { - ultouch(); /* rti!trt */ + ultouch(); + /* if /etc/nologin exists, exit cleanly */ + if (nologinflag) { + logent(NOLOGIN, "UUXQT SHUTDOWN"); + if (Debug) + logent("debugging", "continuing anyway"); + else + break; + } DEBUG(4, "xfile - %s\n", xfile); xfp = fopen(subfile(xfile), "r"); - ASSERT(xfp != NULL, "CAN'T OPEN", xfile, 0); + ASSERT(xfp != NULL, CANTOPEN, xfile, 0); /* initialize to default */ strcpy(user, User); - strcpy(fin, "/dev/null"); - strcpy(fout, "/dev/null"); + strcpy(fin, DEVNULL); + strcpy(fout, DEVNULL); sprintf(sysout, "%.7s", Myname); - badfiles = 0; /* this was missing -- rti!trt */ + badfiles = 0; while (fgets(buf, BUFSIZ, xfp) != NULL) { switch (buf[0]) { case X_USER: - sscanf(&buf[1], "%s%s", user, Rmtname); + sscanf(&buf[1], "%s %s", user, Rmtname); + break; + case X_RETURNTO: + sscanf(&buf[1], "%s", user); break; case X_STDIN: sscanf(&buf[1], "%s", fin); @@ -186,15 +244,15 @@ doprocess: DEBUG(4, "cmd - %s\n", cmd); /* command execution */ - if (strcmp(fout, "/dev/null") == SAME) - strcpy(dfile,"/dev/null"); + if (strcmp(fout, DEVNULL) == SAME) + strcpy(dfile,DEVNULL); else gename(DATAPRE, sysout, 'O', dfile); /* expand file names where necessary */ expfile(dfile); strcpy(buf, PATH); - strcat(buf, ";export PATH;"); + strcat(buf, " "); cmdp = buf + strlen(buf); ptr = cmd; xcmd[0] = '\0'; @@ -207,7 +265,7 @@ doprocess: continue; } - if ((argnok = argok(xcmd, prm)) != 0) + if ((argnok = argok(xcmd, prm)) != SUCCESS) /* command not valid */ break; @@ -215,6 +273,11 @@ doprocess: expfile(prm); APPCMD(prm); } + /* + * clean up trailing ' ' in command. + */ + if (cmdp > buf && cmdp[0] == '\0' && cmdp[-1] == ' ') + *--cmdp = '\0'; if (argnok || badfiles) { sprintf(lbuf, "%s XQT DENIED", user); logent(cmd, lbuf); @@ -227,50 +290,60 @@ doprocess: DEBUG(4, "cmd %s\n", buf); mvxfiles(xfile); - subchdir(XQTDIR); - ret = shio(buf, fin, dfile, (char *)NULL); -/* watcgl.11, dmmartindale, signal and exit values were reversed */ + ret = subchdir(XQTDIR); + ASSERT(ret >= 0, "CHDIR FAILED", XQTDIR, ret); + ret = shio(buf, fin, dfile, CNULL); sprintf(retstat, "signal %d, exit %d", ret & 0377, (ret>>8) & 0377); if (strcmp(xcmd, "rmail") == SAME) notiok = 0; if (strcmp(xcmd, "rnews") == SAME) nonzero = 1; - if (notiok && (!nonzero || (nonzero && ret != 0))) + notiflg = chknotify(xcmd); + if (notiok && notiflg != NT_NO && + (ret != 0 || (!nonzero && notiflg == NT_YES))) notify(user, Rmtname, cmd, retstat); else if (ret != 0 && strcmp(xcmd, "rmail") == SAME) { /* mail failed - return letter to sender */ - retosndr(user, Rmtname, fin); - sprintf(buf, "ret (%o) from %s!%s", ret, Rmtname, user); +#ifdef DANGEROUS + /* NOT GUARANTEED SAFE!!! */ + if (!nonzero) + retosndr(user, Rmtname, fin); +#else + notify(user, Rmtname, cmd, retstat); +#endif + sprintf(buf, "%s (%s) from %s!%s", buf, retstat, Rmtname, user); logent("MAIL FAIL", buf); } DEBUG(4, "exit cmd - %d\n", ret); - subchdir(Spool); + ret2 = subchdir(Spool); + ASSERT(ret2 >= 0, "CHDIR FAILED", Spool, ret); rmxfiles(xfile); if (ret != 0) { /* exit status not zero */ dfp = fopen(subfile(dfile), "a"); - ASSERT(dfp != NULL, "CAN'T OPEN", dfile, 0); + ASSERT(dfp != NULL, CANTOPEN, dfile, 0); fprintf(dfp, "exit status %d", ret); fclose(dfp); } - if (strcmp(fout, "/dev/null") != SAME) { + if (strcmp(fout, DEVNULL) != SAME) { if (prefix(sysout, Myname)) { xmv(dfile, fout); chmod(fout, BASEMODE); } else { + char *cp = rindex(user, '!'); gename(CMDPRE, sysout, 'O', cfile); fp = fopen(subfile(cfile), "w"); ASSERT(fp != NULL, "OPEN", cfile, 0); - fprintf(fp, "S %s %s %s - %s 0666\n", - dfile, fout, user, lastpart(dfile)); + fprintf(fp, "S %s %s %s - %s 0666\n", dfile, + fout, cp ? cp : user, lastpart(dfile)); fclose(fp); } } rmfiles: xfp = fopen(subfile(xfile), "r"); - ASSERT(xfp != NULL, "CAN'T OPEN", xfile, 0); + ASSERT(xfp != NULL, CANTOPEN, xfile, 0); while (fgets(buf, BUFSIZ, xfp) != NULL) { if (buf[0] != X_RQDFILE) continue; @@ -292,6 +365,13 @@ int code; { logcls(); rmlock(CNULL); +#ifdef VMS + /* + * Since we run as a BATCH job we must wait for all processes to + * to finish + */ + while(wait(0) != -1); +#endif VMS exit(code); } @@ -301,16 +381,16 @@ int code; * char *file; * * return codes: 0 - no file | 1 - file to execute - * Mod to recheck for X-able files. Sept 1982, rti!trt. - * Suggested by utzoo.2458 (utzoo!henry) - * Uses iswrk/gtwrkf to keep files in sequence, May 1983. */ gtxfile(file) register char *file; { char pre[3]; - register int rechecked; + int rechecked; + time_t ystrdy; /* yesterday */ + extern time_t time(); + struct stat stbuf; /* for X file age */ pre[0] = XQTPRE; pre[1] = '.'; @@ -319,20 +399,40 @@ register char *file; retry: if (!gtwrkf(Spool, file)) { if (rechecked) - return(0); + return 0; rechecked = 1; - DEBUG(4, "iswrk\n", ""); + DEBUG(4, "iswrk\n", CNULL); if (!iswrk(file, "get", Spool, pre)) - return(0); + return 0; } DEBUG(4, "file - %s\n", file); -#ifndef UUDIR /* skip spurious subdirectories */ if (strcmp(pre, file) == SAME) goto retry; -#endif if (gotfiles(file)) - return(1); + return 1; + /* check for old X. file with no work files and remove them. */ + if (Nfiles > LLEN/2) { + time(&ystrdy); + ystrdy -= (4 * 3600L); /* 4 hours ago */ + DEBUG(4, "gtxfile: Nfiles > LLEN/2\n", CNULL); + while (gtwrkf(Spool, file) && !gotfiles(file)) { + if (stat(subfile(file), &stbuf) == 0) + if (stbuf.st_mtime <= ystrdy) { + char *bnp, cfilename[NAMESIZE]; + DEBUG(4, "gtxfile: move %s to CORRUPT \n", file); + unlink(subfile(file)); + bnp = rindex(subfile(file), '/'); + sprintf(cfilename, "%s/%s", CORRUPT, + bnp ? bnp + 1 : subfile(file)); + xmv(subfile(file), cfilename); + logent(file, "X. FILE CORRUPTED"); + } + } + DEBUG(4, "iswrk\n", CNULL); + if (!iswrk(file, "get", Spool, pre)) + return 0; + } goto retry; } @@ -353,7 +453,7 @@ register char *file; fp = fopen(subfile(file), "r"); if (fp == NULL) - return(0); + return 0; while (fgets(buf, BUFSIZ, fp) != NULL) { DEBUG(4, "%s\n", buf); @@ -363,12 +463,12 @@ register char *file; expfile(rqfile); if (stat(subfile(rqfile), &stbuf) == -1) { fclose(fp); - return(0); + return 0; } } fclose(fp); - return(1); + return 1; } @@ -427,10 +527,9 @@ char *xfile; continue; expfile(ffile); sprintf(tfull, "%s/%s", XQTDIR, tfile); - /* duke!rti, ncsu!mcm: use xmv, not link(II) */ unlink(subfile(tfull)); ret = xmv(ffile, tfull); - ASSERT(ret == 0, "XQTDIR ERROR", "", ret); + ASSERT(ret == 0, "XQTDIR ERROR", CNULL, ret); } fclose(fp); return; @@ -464,28 +563,64 @@ register char *xc, *cmd; || index(cmd, '^') != NULL || index(cmd, '&') != NULL || index(cmd, '|') != NULL - || index(cmd, '<') != NULL) - return(1); -#endif + || index(cmd, '<') != NULL) { + DEBUG(1,"MAGIC CHARACTER FOUND\n", CNULL); + return FAIL; + } +#endif !ALLOK if (xc[0] != '\0') - return(0); + return SUCCESS; #ifndef ALLOK ptr = Cmds; + DEBUG(9, "Compare %s and\n", cmd); while(*ptr != NULL) { + DEBUG(9, "\t%s\n", *ptr); if (strcmp(cmd, *ptr) == SAME) break; - ptr++; + ptr++; + } + if (*ptr == NULL) { + DEBUG(1,"COMMAND NOT FOUND\n", CNULL); + return FAIL; } - if (*ptr == NULL) - return(1); #endif strcpy(xc, cmd); - return(0); + DEBUG(9, "MATCHED %s\n", xc); + return SUCCESS; +} + + +/*** + * chknotify(cmd) check if notification should be sent for + * successful execution of cmd + * char *cmd; + * + * return NT_YES - do notification + * NT_ERR - do notification if exit status != 0 + * NT_NO - don't do notification ever + */ + +chknotify(cmd) +char *cmd; +{ + register char **ptr; + register int *nptr; + + ptr = Cmds; + nptr = Notify; + while (*ptr != NULL) { + if (strcmp(cmd, *ptr) == SAME) + return *nptr; + ptr++; + nptr++; + } + return NT_YES; /* "shouldn't happen" */ } + /*** * notify send mail to user giving execution results * return code - none @@ -498,12 +633,12 @@ char *user, *rmt, *cmd, *str; char text[MAXFULLNAME]; char ruser[MAXFULLNAME]; - sprintf(text, "uuxqt cmd (%.50s) status (%s)", cmd, str); + sprintf(text, "uuxqt cmd (%s) status (%s)", cmd, str); if (prefix(rmt, Myname)) strcpy(ruser, user); else sprintf(ruser, "%s!%s", rmt, user); - mailst(ruser, text, ""); + mailst(ruser, text, CNULL); return; } @@ -516,7 +651,7 @@ char *user, *rmt, *cmd, *str; retosndr(user, rmt, file) char *user, *rmt, *file; { - char ruser[100]; + char ruser[MAXFULLNAME]; if (strcmp(rmt, Myname) == SAME) strcpy(ruser, user); @@ -526,6 +661,6 @@ char *user, *rmt, *file; if (anyread(file) == 0) mailst(ruser, "Mail failed. Letter returned to sender.\n", file); else - mailst(ruser, "Mail failed. Letter returned to sender.\n", ""); + mailst(ruser, "Mail failed. Letter returned to sender.\n", CNULL); return; } diff --git a/usr/src/usr.bin/uudecode/uudecode.c b/usr/src/usr.bin/uudecode/uudecode.c index 9eb3cd582f..caab3ba937 100644 --- a/usr/src/usr.bin/uudecode/uudecode.c +++ b/usr/src/usr.bin/uudecode/uudecode.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uudecode.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)uudecode.c 5.2 (Berkeley) %G%"; #endif /* diff --git a/usr/src/usr.bin/uuencode/uuencode.c b/usr/src/usr.bin/uuencode/uuencode.c index 5152b1f803..b5f571184c 100644 --- a/usr/src/usr.bin/uuencode/uuencode.c +++ b/usr/src/usr.bin/uuencode/uuencode.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)uuencode.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)uuencode.c 5.3 (Berkeley) %G%"; #endif /* @@ -12,7 +12,7 @@ static char sccsid[] = "@(#)uuencode.c 5.2 (Berkeley) %G%"; #include /* ENC is the basic 1 character encoding function to make a char printing */ -#define ENC(c) (((c) & 077) + ' ') +#define ENC(c) ((c) ? ((c) & 077) + ' ': '`') main(argc, argv) char **argv; @@ -39,8 +39,6 @@ char **argv; /* figure out the input file mode */ fstat(fileno(in), &sbuf); mode = sbuf.st_mode & 0777; - if (in == stdin && mode == 0) - mode = 0600; /* use a reasonable mode in case of pipes */ printf("begin %o %s\n", mode, argv[1]); encode(in, stdout); -- 2.20.1