From da6efb0708f15543fb50cdf722204e3dd69edacf Mon Sep 17 00:00:00 2001 From: Tom London Date: Thu, 16 Nov 1978 01:39:19 -0500 Subject: [PATCH] Bell 32V development Work on file usr/src/cmd/uucp/expfile.c Work on file usr/src/cmd/uucp/gename.c Work on file usr/src/cmd/uucp/getpwinfo.c Work on file usr/src/cmd/uucp/getargs.c Work on file usr/src/cmd/uucp/cpmv.c Work on file usr/src/cmd/uucp/getprm.c Work on file usr/src/cmd/uucp/gnxseq.c Work on file usr/src/cmd/uucp/gnsys.c Work on file usr/src/cmd/uucp/imsg.c Work on file usr/src/cmd/uucp/ioctl.c Work on file usr/src/cmd/uucp/gwd.c Work on file usr/src/cmd/uucp/index.c Work on file usr/src/cmd/uucp/pkon.c Work on file usr/src/cmd/uucp/lastpart.c Work on file usr/src/cmd/uucp/sdmail.c Work on file usr/src/cmd/uucp/prefix.c Work on file usr/src/cmd/uucp/ulockf.c Work on file usr/src/cmd/uucp/systat.c Work on file usr/src/cmd/uucp/uuclean.c Work on file usr/src/cmd/uucp/sysacct.c Work on file usr/src/cmd/uucp/shio.c Work on file usr/src/cmd/uucp/uurecover.c Work on file usr/src/cmd/uucp/xqt.c Work on file usr/src/cmd/uucp/versys.c Co-Authored-By: John Reiser Synthesized-from: 32v --- usr/src/cmd/uucp/cpmv.c | 53 ++++++++++ usr/src/cmd/uucp/expfile.c | 94 +++++++++++++++++ usr/src/cmd/uucp/gename.c | 68 ++++++++++++ usr/src/cmd/uucp/getargs.c | 35 +++++++ usr/src/cmd/uucp/getprm.c | 38 +++++++ usr/src/cmd/uucp/getpwinfo.c | 58 +++++++++++ usr/src/cmd/uucp/gnsys.c | 111 ++++++++++++++++++++ usr/src/cmd/uucp/gnxseq.c | 95 +++++++++++++++++ usr/src/cmd/uucp/gwd.c | 26 +++++ usr/src/cmd/uucp/imsg.c | 70 +++++++++++++ usr/src/cmd/uucp/index.c | 24 +++++ usr/src/cmd/uucp/ioctl.c | 31 ++++++ usr/src/cmd/uucp/lastpart.c | 22 ++++ usr/src/cmd/uucp/pkon.c | 2 + usr/src/cmd/uucp/prefix.c | 20 ++++ usr/src/cmd/uucp/sdmail.c | 58 +++++++++++ usr/src/cmd/uucp/shio.c | 44 ++++++++ usr/src/cmd/uucp/sysacct.c | 15 +++ usr/src/cmd/uucp/systat.c | 127 +++++++++++++++++++++++ usr/src/cmd/uucp/ulockf.c | 194 +++++++++++++++++++++++++++++++++++ usr/src/cmd/uucp/uuclean.c | 139 +++++++++++++++++++++++++ usr/src/cmd/uucp/uurecover.c | 70 +++++++++++++ usr/src/cmd/uucp/versys.c | 44 ++++++++ usr/src/cmd/uucp/xqt.c | 86 ++++++++++++++++ 24 files changed, 1524 insertions(+) create mode 100644 usr/src/cmd/uucp/cpmv.c create mode 100644 usr/src/cmd/uucp/expfile.c create mode 100644 usr/src/cmd/uucp/gename.c create mode 100644 usr/src/cmd/uucp/getargs.c create mode 100644 usr/src/cmd/uucp/getprm.c create mode 100644 usr/src/cmd/uucp/getpwinfo.c create mode 100644 usr/src/cmd/uucp/gnsys.c create mode 100644 usr/src/cmd/uucp/gnxseq.c create mode 100644 usr/src/cmd/uucp/gwd.c create mode 100644 usr/src/cmd/uucp/imsg.c create mode 100644 usr/src/cmd/uucp/index.c create mode 100644 usr/src/cmd/uucp/ioctl.c create mode 100644 usr/src/cmd/uucp/lastpart.c create mode 100644 usr/src/cmd/uucp/pkon.c create mode 100644 usr/src/cmd/uucp/prefix.c create mode 100644 usr/src/cmd/uucp/sdmail.c create mode 100644 usr/src/cmd/uucp/shio.c create mode 100644 usr/src/cmd/uucp/sysacct.c create mode 100644 usr/src/cmd/uucp/systat.c create mode 100644 usr/src/cmd/uucp/ulockf.c create mode 100644 usr/src/cmd/uucp/uuclean.c create mode 100644 usr/src/cmd/uucp/uurecover.c create mode 100644 usr/src/cmd/uucp/versys.c create mode 100644 usr/src/cmd/uucp/xqt.c diff --git a/usr/src/cmd/uucp/cpmv.c b/usr/src/cmd/uucp/cpmv.c new file mode 100644 index 0000000000..1c36dd560b --- /dev/null +++ b/usr/src/cmd/uucp/cpmv.c @@ -0,0 +1,53 @@ +#include "uucp.h" + +/*** + * xcp(f1, f2) copy f1 to f2 + * char *f1, *f2; + * + * return - 0 ok | FAIL failed + */ + +xcp(f1, f2) +char *f1, *f2; +{ + char buf[BUFSIZ]; + int len; + FILE *fp1, *fp2; + + if ((fp1 = fopen(f1, "r")) == NULL) + return(FAIL); + if ((fp2 = fopen(f2, "w")) == NULL) { + fclose(fp1); + return(FAIL); + } + while((len = fread(buf, sizeof (char), BUFSIZ, fp1)) > 0) + fwrite(buf, sizeof (char), len, fp2); + fclose(fp1); + fclose(fp2); + chmod(f2, 0666); + return(0); +} + + +/* + * xmv(f1, f2) move f1 to f2 + * char * f1, *f2; + * + * return 0 ok | FAIL failed + */ + +xmv(f1, f2) +char *f1, *f2; +{ + int ret; + + if (link(f1, f2) < 0) { + /* copy file */ + ret = xcp(f1, f2); + if (ret == 0) + unlink(f1); + return(ret); + } + unlink(f1); + return(0); +} diff --git a/usr/src/cmd/uucp/expfile.c b/usr/src/cmd/uucp/expfile.c new file mode 100644 index 0000000000..abb001fb0b --- /dev/null +++ b/usr/src/cmd/uucp/expfile.c @@ -0,0 +1,94 @@ +#include "uucp.h" +#include +#include + + +/******* + * expfile(file) expand file name + * char *file; + * + * return codes: none + */ + +expfile(file) +char *file; +{ + char *fpart; + char user[20], *up; + char full[100]; + int uid; + + switch(file[0]) { + case '/': + return; + case '~': + for (fpart = file + 1, up = user; *fpart != '\0' + && *fpart != '/'; fpart++) + *up++ = *fpart; + *up = '\0'; + if (gninfo(user, &uid, full) != 0) { + strcpy(full, Spool); + } + + strcat(full, fpart); + strcpy(file, full); + return; + default: + strcpy(full, Wrkdir); + strcat(full, "/"); + strcat(full, file); + strcpy(file, full); + return; + } +} + + +/*** + * isdir(name) check if directory name + * char *name; + * + * return codes: 0 - not directory | 1 - is directory + */ + +isdir(name) +char *name; +{ + int ret; + struct stat s; + + ret = stat(name, &s); + if (ret < 0) + return(0); + if ((s.st_mode & S_IFMT) == S_IFDIR) + return(1); + return(0); +} + + +/*** + * mkdirs(name) make all necessary directories + * char *name; + * + * return 0 | FAIL + */ + +mkdirs(name) +char *name; +{ + int ret; + char cmd[100], dir[100], *p; + + for (p = dir + 1;; p++) { + strcpy(dir, name); + if ((p = index(p, '/')) == NULL) + return(0); + *p = '\0'; + if (isdir(dir)) + continue; + sprintf(cmd, "mkdir %s", dir); + DEBUG(4, "mkdir - %s\n", dir); + ret = shio(cmd, NULL, NULL, User); + if (ret != 0) + return(FAIL); + } +} diff --git a/usr/src/cmd/uucp/gename.c b/usr/src/cmd/uucp/gename.c new file mode 100644 index 0000000000..26bd1a472c --- /dev/null +++ b/usr/src/cmd/uucp/gename.c @@ -0,0 +1,68 @@ +#include "uucp.h" + + +/******* + * gename(pre, sys, grade, file) generate file name + * char grade, *sys, pre, *file; + * + * return codes: none + */ + +gename(pre, sys, grade, file) +char pre, *sys, grade, *file; +{ + char sqnum[5]; + + getseq(sqnum); + sprintf(file, "%c.%.7s%c%.4s", pre, sys, grade, sqnum); + DEBUG(4, "file - %s\n", file); + return; +} + + +#define SLOCKTIME 10L +#define SLOCKTRIES 5 +#define SEQLEN 4 + +/******* + * getseq(snum) get next sequence number + * char *snum; + * + * return codes: none + */ + +getseq(snum) +char *snum; +{ + FILE *fp; + int n; + + for (n = 0; n < SLOCKTRIES; n++) { + if (!ulockf( SEQLOCK, SLOCKTIME)) + break; + sleep(5); + } + + ASSERT(n < SLOCKTRIES, "CAN NOT GET %s", SEQLOCK); + + if ((fp = fopen(SEQFILE, "r")) != NULL) { + /* read sequence number file */ + fscanf(fp, "%4d", &n); + fp = freopen(SEQFILE, "w", fp); + ASSERT(fp != NULL, "CAN NOT OPEN %s", SEQFILE); + chmod(SEQFILE, 0666); + } + else { + /* can not read file - create a new one */ + if ((fp = fopen(SEQFILE, "w")) == NULL) + /* can not write new seqeunce file */ + return(FAIL); + chmod(SEQFILE, 0666); + n = 0; + } + + fprintf(fp, "%s", sprintf(snum, "%04d", ++n)); + fclose(fp); + rmlock(SEQLOCK); + return(0); +} diff --git a/usr/src/cmd/uucp/getargs.c b/usr/src/cmd/uucp/getargs.c new file mode 100644 index 0000000000..2f6d330b41 --- /dev/null +++ b/usr/src/cmd/uucp/getargs.c @@ -0,0 +1,35 @@ +#include + + +/******* + * 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. + * + * return - the number of subfields. + */ + +getargs(s, arps) +char *s, *arps[]; +{ + int i; + + i = 0; + while (1) { + arps[i] = NULL; + while (*s == ' ' || *s == '\t') + *s++ = '\0'; + if (*s == '\n') + *s = '\0'; + if (*s == '\0') + break; + arps[i++] = s++; + while (*s != '\0' && *s != ' ' + && *s != '\t' && *s != '\n') + s++; + } + return(i); +} diff --git a/usr/src/cmd/uucp/getprm.c b/usr/src/cmd/uucp/getprm.c new file mode 100644 index 0000000000..4cfd8d7826 --- /dev/null +++ b/usr/src/cmd/uucp/getprm.c @@ -0,0 +1,38 @@ +#include + + +/******* + * char * + * getprm(s, prm) get next parameter from s + * char *s, *prm; + * + * return - pointer to next character in s + */ + +char * +getprm(s, prm) +char *s, *prm; +{ + + while (*s == ' ' || *s == '\t' || *s == '\n') + s++; + + *prm = '\0'; + if (*s == '\0') + return(NULL); + + if (*s == '>' || *s == '<' || *s == '|' + || *s == ';') { + *prm++ = *s++; + *prm = '\0'; + return(s); + } + + while (*s != ' ' && *s != '\t' && *s != '<' + && *s != '>' && *s != '|' && *s != '\0' + && *s != ';' && *s != '\n') + *prm++ = *s++; + *prm = '\0'; + + return(s); +} diff --git a/usr/src/cmd/uucp/getpwinfo.c b/usr/src/cmd/uucp/getpwinfo.c new file mode 100644 index 0000000000..843a9302b4 --- /dev/null +++ b/usr/src/cmd/uucp/getpwinfo.c @@ -0,0 +1,58 @@ +#include "uucp.h" +#include + + +/******* + * guinfo(uid, name, path) get passwd file info for uid + * int uid; + * char *path, *name; + * + * return codes: 0 | FAIL + */ + +guinfo(uid, name, path) +int uid; +char *path, *name; +{ + struct passwd *pwd; + struct passwd *getpwuid(); + + if ((pwd = getpwuid(uid)) == NULL) { + /* can not find uid in passwd file */ + *path = '\0'; + return(FAIL); + } + + strcpy(path, pwd->pw_dir); + strcpy(name, pwd->pw_name); + return(0); +} + + +/*** + * gninfo(name, uid, path) get passwd file info for name + * char *path, *name; + * int *uid; + * + * return codes: 0 | FAIL + */ + +gninfo(name, uid, path) +char *path, *name; +int *uid; +{ + struct passwd *pwd; + struct passwd *getpwnam(); + + if ((pwd = getpwnam(name)) == NULL) { + /* can not find name in passwd file */ + *path = '\0'; + return(FAIL); + } + + strcpy(path, pwd->pw_dir); + *uid = pwd->pw_uid; + return(0); +} + + diff --git a/usr/src/cmd/uucp/gnsys.c b/usr/src/cmd/uucp/gnsys.c new file mode 100644 index 0000000000..7167cfb6c9 --- /dev/null +++ b/usr/src/cmd/uucp/gnsys.c @@ -0,0 +1,111 @@ +#include "uucp.h" + + +#define LSIZE 30 /* 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. + * "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 + * 1 - name returned in sname + * FAIL - bad directory + */ + +gnsys(sname, dir, pre) +char *sname, *dir, pre; +{ + char *s, *p1, *p2; + char px[3]; + static char *list[LSIZE]; + static int nitem=0, n=0; + char sysname[NAMESIZE], filename[NAMESIZE]; + FILE *fp; + + px[0] = pre; + px[1] = '.'; + px[2] = '\0'; + if (nitem == 0) { + /* get list of systems with work */ + int i; + fp = fopen(dir, "r"); + ASSERT(fp != NULL, "BAD DIRECTRY %s\n", dir); + for (i = 0; i < LSIZE; i++) + list[i] = NULL; + while (gnamef(fp, filename) != 0) { + if (!prefix(px, filename)) + continue; + p2 = filename + strlen(filename) + - WSUFSIZE; + p1 = filename + strlen(px); + for(s = sysname; p1 <= p2; p1++) + *s++ = *p1; + *s = '\0'; + if (sysname[0] == '\0') + continue; + if (callok(sysname) == 0) + nitem = srchst(sysname, list, nitem); + if (LSIZE <= nitem) break; + } + + fclose(fp); + } + + if (nitem == 0) + return(0); + if (nitem <= n ) { + for (n = 0; n < nitem; n++) + if (list[n] != NULL) + free(list[n]); + nitem = n = 0; + return(0); + } + + strcpy(sname, list[n++]); + return(1); +} + +/*** + * 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). + * + * return codes: + * n - the number of items in the list + */ + +srchst(name, list, n) +char *name, **list; +int n; +{ + int i; + char *p; + extern char *calloc(); + + for (i = 0; i < n; i++) + if (strcmp(name, list[i]) == 0) + break; + if (i >= n) { + if ((p = calloc(strlen(name) + 1, sizeof (char))) + == NULL) + return(n); + strcpy(p, name); + list[n++] = p; + } + return(n); +} diff --git a/usr/src/cmd/uucp/gnxseq.c b/usr/src/cmd/uucp/gnxseq.c new file mode 100644 index 0000000000..6f18b2cdec --- /dev/null +++ b/usr/src/cmd/uucp/gnxseq.c @@ -0,0 +1,95 @@ +#include "uucp.h" +#include +#include + + + +/******* + * gnxseq(rmtname) get next conversation sequence number + * char *rmtname; + * + * return - 0 no entry | >0 sequence number + */ + +gnxseq(rmtname) +char *rmtname; +{ + int count = 0, ct, ret; + struct tm *tp; + extern struct tm *localtime(); + time_t clock; + FILE *fp0, *fp1; + char buf[BUFSIZ], name[NAMESIZE]; + + if (ulockf(SQLOCK, SQTIME) != 0) + return(0); + if ((fp0 = fopen(SQFILE, "r")) == NULL) + return(0); + if ((fp1 = fopen(SQTMP, "w")) == NULL) { + fclose(fp0); + return(0); + } + chmod(SQTMP, 0400); + + while (fgets(buf, BUFSIZ, fp0) != NULL) { + ret = sscanf(buf, "%s%d", name, &ct); + if (ret < 2) + ct = 0; + name[7] = '\0'; + if (ct > 9998) + ct = 0; + if (strcmp(rmtname, name) != SAME) { + fputs(buf, fp1); + continue; + } + + /* found name */ + count = ++ct; + time(&clock); + tp = localtime(&clock); + fprintf(fp1, "%s %d %d/%d-%d:%d\n", name, ct, + tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, + tp->tm_min); + while (fgets(buf, BUFSIZ, fp0) != NULL) + fputs(buf, fp1); + } + fclose(fp0); + fclose(fp1); + if (count == 0) { + rmlock(SQLOCK); + unlink(SQTMP); + } + return(count); +} + + +/*** + * cmtseq() commit sequence update + * + * return 0 ok | other - link failed + */ + +cmtseq() +{ + int ret; + + if ((ret = access(SQTMP, 0400)) != 0) { + rmlock(SQLOCK); + return(0); + } + unlink(SQFILE); + ret = link(SQTMP, SQFILE); + unlink(SQTMP); + rmlock(SQLOCK); + return(ret); +} + +/*** + * ulkseq() unlock sequence file + */ + +ulkseq() +{ + unlink(SQTMP); + rmlock(SQLOCK); +} diff --git a/usr/src/cmd/uucp/gwd.c b/usr/src/cmd/uucp/gwd.c new file mode 100644 index 0000000000..49adf27a6f --- /dev/null +++ b/usr/src/cmd/uucp/gwd.c @@ -0,0 +1,26 @@ +#include "uucp.h" + +/******* + * gwd(wkdir) get working directory + * + * return codes 0 | FAIL + */ + +gwd(wkdir) +char *wkdir; +{ + FILE *fp; + extern FILE *popen(), *pclose(); + char *c; + + if ((fp = popen("pwd", "r")) == NULL) + return(FAIL); + if (fgets(wkdir, 100, fp) == NULL) { + pclose(fp); + return(FAIL); + } + if (*(c = wkdir + strlen(wkdir) - 1) == '\n') + *c = '\0'; + pclose(fp); + return(0); +} diff --git a/usr/src/cmd/uucp/imsg.c b/usr/src/cmd/uucp/imsg.c new file mode 100644 index 0000000000..a9b5d908d2 --- /dev/null +++ b/usr/src/cmd/uucp/imsg.c @@ -0,0 +1,70 @@ +#include "uucp.h" + + +char Msync[2] = "\020"; +/******* + * imsg(msg, fn) + * char *msg; + * int fn; + * + * imsg - this is the initial read message routine - + * used before a protocol is agreed upon. + * + * return codes: + * EOF - no more messages + * 0 - message returned + */ + +imsg(msg, fn) +char *msg; +int fn; +{ + int ret; + DEBUG(7, "imsg %s>", ""); + while ((ret = read(fn, msg, 1)) == 1) { + DEBUG(7, "%c", (*msg > 037) ? *msg : '-'); + if (*msg == Msync[0]) + break; + } + DEBUG(7, "%s\n", "<"); + if (ret < 1) + return(EOF); + while (read(fn, msg, 1) == 1) { + DEBUG(7, "%c", (*msg > 037) ? *msg : '-'); + if (*msg == '\n') + break; + if (*msg == '\0') + break; + msg++; + } + *msg = '\0'; + return(0); +} + + +/*** + * omsg(type, msg, fn) + * char type, *msg; + * int fn; + * + * omsg - this is the initial write message routine - + * used before a protocol is agreed upon. + * + * return code: always 0 + */ + +omsg(type, msg, fn) +char *msg, type; +int fn; +{ + char buf[BUFSIZ], *c; + + c = buf; + *c++ = Msync[0]; + *c++ = type; + while (*msg) + *c++ = *msg++; + *c++ = '\0'; + write(fn, buf, strlen(buf) + 1); + return(0); +} diff --git a/usr/src/cmd/uucp/index.c b/usr/src/cmd/uucp/index.c new file mode 100644 index 0000000000..c7143df467 --- /dev/null +++ b/usr/src/cmd/uucp/index.c @@ -0,0 +1,24 @@ +#include + + +/******* + * char * + * index(str, c) return pointer to character c + * char c, *str; + * + * return codes: + * NULL - character not found + * pointer - pointer to character + */ + +char * +index(str, c) +char c, *str; +{ + for (; *str != '\0'; str++) { + if (*str == c) + return(str); + } + + return(NULL); +} diff --git a/usr/src/cmd/uucp/ioctl.c b/usr/src/cmd/uucp/ioctl.c new file mode 100644 index 0000000000..4942faf15d --- /dev/null +++ b/usr/src/cmd/uucp/ioctl.c @@ -0,0 +1,31 @@ +#include "uucp.h" +#include + +/******* + * ioctl(fn, com, ttbuf) for machines without ioctl + * int fn, com; + * struct sgttyb *ttbuf; + * + * return codes - same as stty and gtty + */ + +ioctl(fn, com, ttbuf) +int fn, com; +struct sgttyb *ttbuf; +{ + struct sgttyb tb; + + switch (com) { + case TIOCHPCL: + gtty(fn, &tb); + tb.sg_flags |= 1; + return(stty(fn, &tb)); + case TIOCGETP: + return(gtty(fn, ttbuf)); + case TIOCSETP: + return(stty(fn, ttbuf)); + case TIOCEXCL: + default: + return(-1); + } +} diff --git a/usr/src/cmd/uucp/lastpart.c b/usr/src/cmd/uucp/lastpart.c new file mode 100644 index 0000000000..2efee9ceac --- /dev/null +++ b/usr/src/cmd/uucp/lastpart.c @@ -0,0 +1,22 @@ + + +/******* + * char * + * lastpart(file) find last part of file name + * char *file; + * + * return - pointer to last part + */ + +char * +lastpart(file) +char *file; +{ + char *c; + + c = file + strlen(file); + while (c >= file) + if (*(--c) == '/') + break; + return(++c); +} diff --git a/usr/src/cmd/uucp/pkon.c b/usr/src/cmd/uucp/pkon.c new file mode 100644 index 0000000000..9b89e9df40 --- /dev/null +++ b/usr/src/cmd/uucp/pkon.c @@ -0,0 +1,2 @@ +pkon() { } +pkoff() { } diff --git a/usr/src/cmd/uucp/prefix.c b/usr/src/cmd/uucp/prefix.c new file mode 100644 index 0000000000..3db9cb65bb --- /dev/null +++ b/usr/src/cmd/uucp/prefix.c @@ -0,0 +1,20 @@ + + +/******* + * prefix(s1, s2) check s2 for prefix s1 + * char *s1, *s2; + * + * return 0 - != + * return 1 - == + */ + +prefix(s1, s2) +char *s1, *s2; +{ + char c; + + while ((c = *s1++) == *s2++) + if (c == '\0') + return(1); + return(c == '\0'); +} diff --git a/usr/src/cmd/uucp/sdmail.c b/usr/src/cmd/uucp/sdmail.c new file mode 100644 index 0000000000..5da6039e6d --- /dev/null +++ b/usr/src/cmd/uucp/sdmail.c @@ -0,0 +1,58 @@ +#include "uucp.h" +#include + + +/******* + * sdmail(file, uid) + * char *file, *uid; + * + * sdmail - this routine will determine the owner + * of the file (file), create a message string and + * call "mailst" to send the cleanup message. + * This is only implemented for local system + * mail at this time. + */ + +sdmail(file, uid) +char *file, *uid; +{ + static struct passwd *pwd; + struct passwd *getpwuid(); + char mstr[40]; + + sprintf(mstr, "uuclean deleted file %s\n", file); + if (pwd->pw_uid == uid) { + mailst(pwd->pw_name, mstr); + return(0); + } + + setpwent(); + if ((pwd = getpwuid(uid)) != NULL) { + mailst(pwd->pw_name, mstr); + } + return(0); +} + + +/*** + * mailst(user, str) + * char *user, *str; + * + * mailst - this routine will fork and execute + * a mail command sending string (str) to user (user). + */ + +mailst(user, str) +char *user, *str; +{ + FILE *fp; + extern FILE *popen(), *pclose(); + char cmd[100]; + + sprintf(cmd, "mail %s", user); + if ((fp = popen(cmd, "w")) == NULL) + return; + fprintf(fp, "%s", str); + pclose(fp); + return; +} diff --git a/usr/src/cmd/uucp/shio.c b/usr/src/cmd/uucp/shio.c new file mode 100644 index 0000000000..9dd8b90914 --- /dev/null +++ b/usr/src/cmd/uucp/shio.c @@ -0,0 +1,44 @@ +#include "uucp.h" + + +/******* + * shio(cmd, fi, fo, user) execute shell of command with + * char *cmd, *fi, *fo; fi and fo as standard input/output + * char *user; user name + * + * return codes: + * 0 - ok + * non zero - failed - status from child + */ + +shio(cmd, fi, fo, user) +char *cmd, *fi, *fo, *user; +{ + int status, f; + int uid, pid, ret; + char path[MAXFULLNAME]; + + if (fi == NULL) + fi = "/dev/null"; + if (fo == NULL) + fo = "/dev/null"; + + DEBUG(3, "shio - %s\n", cmd); + if ((pid = fork()) == 0) { + close(Ifn); + close(Ofn); + close(0); + f = open(fi, 0); + ASSERT(f == 0, "BAD OPEN fileno %d", f); + close(1); + f = creat(fo, 0666); + ASSERT(f == 1, "BAD OPEN fileno %d", f); + if (gninfo(user, &uid, path) == 0) + setuid(uid); + execl(SHELL, "sh", "-c", cmd, 0); + exit(100); + } + while ((ret = wait(&status)) != pid && ret != -1); + DEBUG(3, "status %d\n", status); + return(status); +} diff --git a/usr/src/cmd/uucp/sysacct.c b/usr/src/cmd/uucp/sysacct.c new file mode 100644 index 0000000000..ad93dc578e --- /dev/null +++ b/usr/src/cmd/uucp/sysacct.c @@ -0,0 +1,15 @@ +#include + + +/******* + * sysacct(bytes, time) output accounting info + * time_t time; + * long bytes; + */ + +sysacct(bytes, time) +time_t time; +long bytes; +{ + return; +} diff --git a/usr/src/cmd/uucp/systat.c b/usr/src/cmd/uucp/systat.c new file mode 100644 index 0000000000..4e8e0db7fe --- /dev/null +++ b/usr/src/cmd/uucp/systat.c @@ -0,0 +1,127 @@ +#include "uucp.h" +#include + +#define STATNAME(f, n) sprintf(f, "%s/%s.%.7s", Spool, "STST", n) +#define S_SIZE 100 + +/******* + * systat(name, type, text) make system status entry + * char *name, *text; + * int type. + * + * return codes: none + */ + +systat(name, type, text) +char *name, *text; +int type; +{ + char filename[MAXFULLNAME], line[S_SIZE]; + int count; + FILE *fp; + time_t prestime; + + if (type == 0) + return; + line[0] = '\0'; + time(&prestime); + count = 0; + STATNAME(filename, name); + + fp = fopen(filename, "r"); + if (fp != NULL) { + fgets(line, S_SIZE, fp); + sscanf(&line[2], "%d", &count); + if (count <= 0) + count = 0; + fclose(fp); + } + + if (type == SS_FAIL) + count++; + + fp = fopen(filename, "w"); + ASSERT(fp != NULL, "SYSTAT OPEN FAIL %s", ""); + chmod(filename, 0666); + fprintf(fp, "%d %d %D %s %s\n", type, count, prestime, text, name); + fclose(fp); + return; +} + +/*** + * rmstat(name) remove system status entry + * char *name; + * + * return codes: none + */ + +rmstat(name) +char *name; +{ + char filename[MAXFULLNAME]; + + STATNAME(filename, name); + unlink(filename); +} + +/*** + * callok(name) check system status for call + * char *name; + * + * return codes 0 - ok | >0 system status + */ + +callok(name) +char *name; +{ + char filename[MAXFULLNAME], line[S_SIZE]; + FILE *fp; + time_t lasttime, prestime; + int count, type; + + STATNAME(filename, name); + fp = fopen(filename, "r"); + if (fp == NULL) + return(SS_OK); + + if (fgets(line, S_SIZE, fp) == NULL) { + /* no data */ + fclose(fp); + unlink(filename); + return(SS_OK); + } + + fclose(fp); + time(&prestime); + sscanf(line, "%d%d%D", &type, &count, &lasttime); + + switch(type) { + case SS_BADSEQ: + case SS_CALLBACK: + return(SS_OK); + case SS_NODEVICE: + return(SS_OK); + + case SS_INPROGRESS: + if (prestime - lasttime < INPROGTIME) + return(type); + else + return(SS_OK); + + + case SS_FAIL: + if (count > MAXRECALLS) { + logent("MAX RECALLS", "NO CALL"); + return(type); + } + + if (prestime - lasttime < RETRYTIME) { + logent("RETRY TIME NOT REACHED", "NO CALL"); + return(type); + } + + return(SS_OK); + default: + return(SS_OK); + } +} diff --git a/usr/src/cmd/uucp/ulockf.c b/usr/src/cmd/uucp/ulockf.c new file mode 100644 index 0000000000..9c6fb2c934 --- /dev/null +++ b/usr/src/cmd/uucp/ulockf.c @@ -0,0 +1,194 @@ +#include "uucp.h" +#include +#include + + +/******* + * 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). + * If it is older, an attempt will be made to unlink it + * and create a new one. + * + * return codes: 0 | FAIL + */ + +ulockf(file, atime) +char *file; +time_t atime; +{ + struct stat stbuf; + time_t ptime; + int ret; + static int pid = -1; + static char tempfile[NAMESIZE]; + + if (pid < 0) { + pid = getpid(); + sprintf(tempfile, "LTMP.%d", pid); + } + if (onelock(pid, tempfile, file) == -1) { + /* lock file exists */ + /* get status to check age of the lock file */ + ret = stat(file, &stbuf); + ASSERT(ret != -1, "LOCK PROBLEM - %s", file); + + time(&ptime); + if ((ptime - stbuf.st_ctime) < atime) { + /* file not old enough to delete */ + return(FAIL); + } + + ret = unlink(file); + ASSERT(ret != -1, "LOCK PROBLEM - %s", file); + + ret = onelock(pid, tempfile, file); + ASSERT(ret == 0, "LOCK PROBLEM - %s", file); + } + stlock(file); + return(0); +} + + +#define MAXLOCKS 10 /* maximum number of lock files */ +char *Lockfile[MAXLOCKS]; +int Nlocks = 0; + +/*** + * stlock(name) put name in list of lock files + * char *name; + * + * return codes: none + */ + +stlock(name) +char *name; +{ + char *p; + extern char *calloc(); + int i; + + for (i = 0; i < Nlocks; i++) { + if (Lockfile[i] == NULL) + break; + } + ASSERT(i < MAXLOCKS, "TOO MANY LOCKS %d", i); + if (i >= Nlocks) + i = Nlocks++; + p = calloc(strlen(name) + 1, sizeof (char)); + ASSERT(p != NULL, "CAN NOT ALLOCATE FOR %s", name); + strcpy(p, name); + Lockfile[i] = p; + return; +} + + +/*** + * rmlock(name) remove all lock files in list + * char *name; or name + * + * return codes: none + */ + +rmlock(name) +char *name; +{ + int i; + + for (i = 0; i < Nlocks; i++) { + if (Lockfile[i] == NULL) + continue; + 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 + on behalf of pid. Tempfile must be in the same + file system as name. */ +/* lock(pid,tempfile,names) either locks all the + names or none of them */ +isalock(name) char *name; +{ + struct stat xstat; + if(stat(name,&xstat)<0) return(0); + if(xstat.st_size!=sizeof(int)) return(0); + return(1); +} +unlock(name) char *name; +{ + if(isalock(name)) return(unlink(name)); + else return(-1); +} +onelock(pid,tempfile,name) char *tempfile,*name; +{ int fd; + fd=creat(tempfile,0444); + if(fd<0) return(-1); + write(fd,&pid,sizeof(int)); + close(fd); + if(link(tempfile,name)<0) + { unlink(tempfile); + return(-1); + } + unlink(tempfile); + return(0); +} +lock(pid,tempfile,names) char *tempfile,**names; +{ int i,j; + for(i=0;names[i]!=0;i++) + { if(onelock(pid,tempfile,names[i])==0) continue; + for(j=0;j +#include +#include +#include +#include + +/******* + * + * uuclean - this program will search through the spool + * directory (Spool) and delete all files with a requested + * prefix which are older than (nomtime) seconds. + * If the -m option is set, the program will try to + * send mail to the usid of the file. + * + * options: + * -m - send mail for deleted file + * -d - directory to clean + * -n - time to age files before delete (in hours) + * -p - prefix for search + * -x - turn on debug outputs + * exit status: + * 0 - normal return + * 1 - can not read directory + */ + +#define DPREFIX "U" +#define NOMTIME 72 /* hours to age files before deletion */ + +main(argc, argv) +char *argv[]; +{ + FILE *pdirf; + char file[NAMESIZE]; + time_t nomtime, ptime; + struct stat stbuf; + int mflg=0; + extern int onintr(); + + nomtime = NOMTIME * 3600L; + + while (argc>1 && argv[1][0] == '-') { + switch (argv[1][1]) { + case 'd': + Spool = &argv[1][2]; + break; + case 'm': + mflg = 1; + break; + case 'n': + nomtime = atoi(&argv[1][2]) * 3600L; + break; + case 'p': + if (&argv[1][2] != '\0') + stpre(&argv[1][2]); + break; + case 'x': + Debug = atoi(&argv[1][2]); + if (Debug <= 0) + Debug = 1; + break; + default: + printf("unknown flag %s\n", argv[1]); break; + } + --argc; argv++; + } + + DEBUG(4, "DEBUG# %s\n", "START"); + chdir(Spool); + + if ((pdirf = fopen(Spool, "r")) == NULL) { + printf("%s directory unreadable\n", Spool); + exit(1); + } + + time(&ptime); + while (gnamef(pdirf, file)) { + if (!chkpre(file)) + continue; + + if (stat(file, &stbuf) == -1) { + DEBUG(4, "stat on %s failed\n", file); + continue; + } + + + if ((stbuf.st_mode & S_IFMT) == S_IFDIR) + continue; + if ((ptime - stbuf.st_ctime) < nomtime) + continue; + DEBUG(4, "unlink file %s\n", file); + unlink(file); + if (mflg) sdmail(file, stbuf.st_uid); + } + + fclose(pdirf); + exit(0); +} + + +#define MAXPRE 10 +char Pre[MAXPRE][DIRSIZ]; +int Npre = 0; +/*** + * chkpre(file) check for prefix + * char *file; + * + * return codes: + * 0 - not prefix + * 1 - is prefix + */ + +chkpre(file) +char *file; +{ + int i; + + for (i = 0; i < Npre; i++) { + if (prefix(Pre[i], file)) + return(1); + } + return(0); +} + +/*** + * stpre(p) store prefix + * char *p; + * + * return codes: none + */ + +stpre(p) +char *p; +{ + if (Npre < MAXPRE - 2) + strcpy(Pre[Npre++], p); + return; +} diff --git a/usr/src/cmd/uucp/uurecover.c b/usr/src/cmd/uucp/uurecover.c new file mode 100644 index 0000000000..31c9f0cb51 --- /dev/null +++ b/usr/src/cmd/uucp/uurecover.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +struct stat xstat; +struct proc mproc[NPROC]; +struct nlist nl[] +{ { "_proc"}, + { ""}, +}; +int err; +main(argc,argv) char **argv; +{ int i,j; + if(argc<=1) exit(0); + for(i=1;i0) + if(isapid(j)) + { fprintf(stderr,"recovery: %s in use\n",argv[i]); + err=1; + } + else unlink(argv[i]); + else fprintf(stderr,"reocvery: %s not a lock\n",argv[i]); + } + exit(err); +} +isalock(s) char *s; +{ int pid,fd; + if(stat(s,&xstat)<0) return(0); + if(xstat.st_size!=2) return(0); + fd=open(s,0); + if(fd<0) return(-1); + read(fd,&pid,2); + close(fd); + return(pid); +} +int gotpids,pids[NPROC]; +isapid(n) +{ int i; + if(gotpids==0) getpids(); + for(i=0;i + + +/******* + * xuucico(rmtname) start up uucico for rmtname + * char *rmtname; + * + * return codes: none + */ + +xuucico(rmtname) +char *rmtname; +{ + if (fork() == 0) { + /* start uucico for rmtname system */ + char opt[100]; + close(0); + close(1); + close(2); + open("/dev/null", 0); + open("/dev/null", 1); + open("/dev/null", 1); + signal(SIGINT, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGKILL, SIG_IGN); + if (rmtname[0] != '\0') + sprintf(opt, "-s%.7s", rmtname); + else + opt[0] = '\0'; + execl(UUCICO, "UUCICO", "-r1", opt, 0); + exit(100); + } + return; +} + + +/******* + * xuuxqt() start up uuxqt + * + * return codes: none + */ + +xuuxqt() +{ + if (fork() == 0) { + /* start uuxqt */ + close(0); + close(1); + close(2); + open("/dev/null", 2); + open("/dev/null", 2); + open("/dev/null", 2); + signal(SIGINT, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGKILL, SIG_IGN); + execl(UUXQT, "UUXQT", 0); + exit(100); + } + return; +} +xuucp(str) +char *str; +{ + char text[300]; + if (fork() == 0) { + /* start uucp */ + close(0); + close(1); + close(2); + open("/dev/null", 0); + open("/dev/null", 1); + open("/dev/null", 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, 0); + exit(100); + } + sleep(15); + return; +} -- 2.20.1