Bell 32V development
authorTom London <tbl@research.uucp>
Tue, 20 Feb 1979 15:19:43 +0000 (10:19 -0500)
committerTom London <tbl@research.uucp>
Tue, 20 Feb 1979 15:19:43 +0000 (10:19 -0500)
Work on file usr/src/cmd/uucp/uucp.c
Work on file usr/src/cmd/uucp/uux.c

Co-Authored-By: John Reiser <jfr@research.uucp>
Synthesized-from: 32v

usr/src/cmd/uucp/uucp.c [new file with mode: 0644]
usr/src/cmd/uucp/uux.c [new file with mode: 0644]

diff --git a/usr/src/cmd/uucp/uucp.c b/usr/src/cmd/uucp/uucp.c
new file mode 100644 (file)
index 0000000..8463592
--- /dev/null
@@ -0,0 +1,255 @@
+#include "uucp.h"
+#include "uucpdefs.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*
+ *     uucp
+ */
+
+int Uid;
+int Startjob = 1;
+char Path[100], Optns[10];
+char Grade = 'n';
+int Copy = 1;
+
+main(argc, argv)
+char *argv[];
+{
+       int ret;
+       char *sysfile1, *sysfile2, *cp;
+       char file1[MAXFULLNAME], file2[MAXFULLNAME];
+       extern char *index();
+
+       Optns[0] = '-';
+       Optns[1] = '\0';
+       while(argc>1 && argv[1][0] == '-'){
+               switch(argv[1][1]){
+               case 'c':
+                       Copy = 0;
+                       break;
+               case 'd':
+                       strcat(Optns, "d");
+                       break;
+               case 'e':
+                       fprintf(stderr, "-e option removed\n");
+                       break;
+               case 'g':
+                       Grade = argv[1][2]; break;
+               case 'm':
+                       strcat(Optns, "m");
+                       break;
+               case 'r':
+                       Startjob = 0;
+                       break;
+               case 's':
+                       Spool = &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, "\n\n** %s **\n", "START");
+       ret = gwd(Wrkdir);
+       ASSERT(ret == 0, "GWD FAILED %d", ret);
+       chdir(Spool);
+
+       Uid = getuid();
+       ret = guinfo(Uid, User, Path);
+       ASSERT(ret == 0, "CAN NOT FIND UID %d\n", Uid);
+       DEBUG(4, "UID %d, ", Uid);
+       DEBUG(4, "User %s,", User);
+       DEBUG(4, "PATH %s\n", Path);
+       if (argc < 3) {
+               fprintf(stderr, "usage uucp from ... to\n");
+               cleanup(0);
+       }
+
+
+       /*  set up "to" system and file names  */
+       if ((cp = index(argv[argc - 1], '!')) != NULL) {
+               sysfile2 = argv[argc - 1];
+               *cp = '\0';
+               if (*sysfile2 == '\0')
+                       sysfile2 = Myname;
+               else
+                       sprintf(Rmtname, "%.7s", sysfile2);
+               if (versys(sysfile2) != 0) {
+                       fprintf(stderr, "bad system name: %s\n", sysfile2);
+                       cleanup(0);
+               }
+               strcpy(file2, cp + 1);
+       }
+       else {
+               sysfile2 = Myname;
+               strcpy(file2, argv[argc - 1]);
+       }
+
+
+       /*  do each from argument  */
+       while (argc > 2) {
+               if ((cp = index(argv[1], '!')) != NULL) {
+                       sysfile1 = argv[1];
+                       *cp = '\0';
+                       if (*sysfile1 == '\0')
+                               sysfile1 = Myname;
+                       else
+                               sprintf(Rmtname, "%.7s", sysfile1);
+                       if (versys(sysfile1) != 0) {
+                               fprintf(stderr, "bad system name: %s\n", sysfile1);
+                               cleanup(0);
+                       }
+                       strcpy(file1, cp + 1);
+               }
+               else {
+                       sysfile1 = Myname;
+                       strcpy(file1, argv[1]);
+               }
+               DEBUG(4, "file1 - %s\n", file1);
+               copy(sysfile1, file1, sysfile2, file2);
+               --argc;
+               argv++;
+       }
+
+       if (Startjob)
+               xuucico("");
+       cleanup(0);
+}
+
+cleanup(code)
+int code;
+{
+       logcls();
+       rmlock(NULL);
+       exit(code);
+}
+
+
+/***
+ *     copy(s1, f1, s2, f2)    generate copy files
+ *     char *s1, *f1, *s2, *f2;
+ *
+ *     return codes 0  |  FAIL
+ */
+
+copy(s1, f1, s2, f2)
+char *s1, *f1, *s2, *f2;
+{
+       int ret, type;
+       struct stat stbuf;
+       char cfile[NAMESIZE], dfile[NAMESIZE];
+       char file1[MAXFULLNAME], file2[MAXFULLNAME];
+       FILE *cfp;
+       extern char *index();
+
+       type = 0;
+       strcpy(file1, f1);
+       strcpy(file2, f2);
+       if (strcmp(s1, Myname) != SAME)
+               type = 1;
+       if (strcmp(s2, Myname) != SAME)
+               type += 2;
+       if (type & 01)
+               if ((index(file1, '*') != NULL
+                 || index(file1, '?') != NULL
+                 || index(file1, '[') != NULL))
+                       type = 4;
+       switch (type) {
+       case 0:
+               /* all work here */
+               DEBUG(4, "all work here %d\n", type);
+               expfile(file1);
+               expfile(file2);
+               if (chkpth(User, "", file1) != 0
+               || chkpth(User, "", file2) != 0) {
+                       fprintf(stderr, "permission denied\n");
+                       cleanup(1);
+               }
+               xcp(file1, file2);
+               logent("WORK HERE", "DONE");
+               return(0);
+       case 1:
+               /* receive file */
+               DEBUG(4, "receive file - %d\n", type);
+               if (file1[0] != '~')
+                       expfile(file1);
+               expfile(file2);
+               if (chkpth(User, "", file2) != 0) {
+                       fprintf(stderr, "permission denied\n");
+                       return(FAIL);
+               }
+               gename(CMDPRE, s1, Grade, cfile);
+               strcpy(dfile, cfile);
+               dfile[0] = DATAPRE;
+               cfp = fopen(cfile, "w");
+               ASSERT(cfp != NULL, "CAN NOT OPEN %s", cfile);
+               fprintf(cfp, "R %s %s %s %s\n", file1, file2, User, Optns);
+               fclose(cfp);
+               break;
+       case 2:
+               /* send file */
+               expfile(file1);
+               if (file2[0] != '~')
+                       expfile(file2);
+               DEBUG(4, "send file - %d\n", type);
+
+               gename(CMDPRE, s2, Grade, cfile);
+               strcpy(dfile, cfile);
+               dfile[0] = DATAPRE;
+               if (chkpth(User, "", file1) != 0) {
+                       fprintf(stderr, "permission denied %s\n", file1);
+                       return(FAIL);
+               }
+               ret = stat(file1, &stbuf);
+               if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
+                       fprintf(stderr, "directory name illegal - %s\n",
+                         file1);
+                       return(FAIL);
+               }
+               if (Copy) {
+                       if (xcp(file1, dfile) != 0) {
+                               fprintf(stderr, "can't copy %s\n", file1);
+                               return(FAIL);
+                       }
+                       chmod(dfile, 0666);
+               }
+               else {
+                       if ((stbuf.st_mode & 04) == 0) {
+                               fprintf(stderr, "uucico can't access %s (-c specified)\n", file1);
+                               return(FAIL);
+                       }
+               }
+               cfp = fopen(cfile, "w");
+               ASSERT(cfp != NULL, "CAN NOT OPEN %s", cfile);
+               chmod(cfile, 0200);
+               fprintf(cfp, "S %s %s %s %s %s %o\n", file1, file2,
+                       User, Optns, dfile, stbuf.st_mode & 0777);
+               fclose(cfp);
+               chmod(cfile, 0666);
+               break;
+       case 3:
+       case 4:
+               /*  send uucp command for execution on s2  */
+               DEBUG(4, "send uucp command - %d\n", type);
+               if (strcmp(s2,  Myname) == SAME) {
+                       expfile(file2);
+                       if (chkpth(User, "", file2) != 0) {
+                               fprintf(stderr, "permission denied\n");
+                               return(FAIL);
+                       }
+               }
+               gename(CMDPRE, s1, Grade, cfile);
+               cfp = fopen(cfile, "w");
+               ASSERT(cfp != NULL, "CAN NOT OPEN %s", cfile);
+               fprintf(cfp, "X %s %s!%s\n", file1, s2, file2);
+               fclose(cfp);
+               break;
+       }
+       logent(cfile, "QUEUED");
+       return(0);
+}
diff --git a/usr/src/cmd/uucp/uux.c b/usr/src/cmd/uucp/uux.c
new file mode 100644 (file)
index 0000000..96e2cb5
--- /dev/null
@@ -0,0 +1,358 @@
+#include "uucp.h"
+#include "uucpdefs.h"
+
+#define NOSYSPART 0
+#define HASSYSPART 1
+
+#define APPCMD(d) {\
+char *p;\
+for (p = d; *p != '\0';) *cmdp++ = *p++;\
+*cmdp++ = ' ';\
+*cmdp = '\0';}
+
+#define GENSEND(f, a, b, c, d) {\
+fprintf(f, "S %s %s %s - %s 0666\n", a, b, c, d);\
+}
+#define GENRCV(f, a, b, c) {\
+fprintf(f, "R %s %s %s - \n", a, b, c);\
+}
+/*
+ *     
+ */
+
+main(argc, argv)
+char *argv[];
+{
+       char cfile[NAMESIZE];   /* send commands for files from here */
+       char dfile[NAMESIZE];   /* used for all data files from here */
+       char rxfile[NAMESIZE];  /* to be sent to xqt file (X. ...) */
+       char tfile[NAMESIZE];   /* temporary file name */
+       char tcfile[NAMESIZE];  /* temporary file name */
+       char t2file[NAMESIZE];  /* temporary file name */
+       int cflag = 0;          /*  commands in C. file flag  */
+       int rflag = 0;          /*  C. files for receiving flag  */
+       char buf[BUFSIZ];
+       char inargs[BUFSIZ];
+       int pipein = 0;
+       int startjob = 1;
+       char path[MAXFULLNAME];
+       char cmd[BUFSIZ];
+       char *ap, *cmdp;
+       char prm[BUFSIZ];
+       char syspart[8], rest[MAXFULLNAME];
+       char xsys[8], local[8];
+       FILE *fprx, *fpc, *fpd, *fp;
+       FILE *xqtstr();
+       extern char *getprm(), *index(), *lastpart();
+       int uid, ret;
+       char redir = '\0';
+
+       Debug = 0;
+       Ofn = 1;
+       Ifn = 0;
+       while (argc>1 && argv[1][0] == '-') {
+               switch(argv[1][1]){
+               case 'p':
+               case '\0':
+                       pipein = 1;
+                       break;
+               case 'r':
+                       startjob = 0;
+                       break;
+               case 'x':
+                       Debug = atoi(&argv[1][2]);
+                       if (Debug <= 0)
+                               Debug = 1;
+                       break;
+               default:
+                       sprintf(stderr, "unknown flag %s\n", argv[1]);
+                               break;
+               }
+               --argc;  argv++;
+       }
+
+       DEBUG(4, "\n\n** %s **\n", "START");
+
+       inargs[0] = '\0';
+       for (argv++; argc > 1; argc--) {
+               DEBUG(4, "arg - %s:", *argv);
+               strcat(inargs, " ");
+               strcat(inargs, *argv++);
+       }
+       DEBUG(4, "arg - %s\n", inargs);
+       ret = gwd(Wrkdir);
+       ASSERT(ret == 0, "GWD FAILED %d", ret);
+       chdir(Spool);
+       uid = getuid();
+       guinfo(uid, User, path);
+
+       sprintf(local, "%.7s", Myname);
+       cmdp = cmd;
+       *cmdp = '\0';
+       gename(DATAPRE, local, 'X', rxfile);
+       fprx = fopen(rxfile, "w");
+       ASSERT(fprx != NULL, "CAN'T OPEN %s", rxfile);
+       chmod(rxfile, 0666);
+       gename(DATAPRE, local, 'T', tcfile);
+       fpc = fopen(tcfile, "w");
+       ASSERT(fpc != NULL, "CAN'T OPEN %s", tcfile);
+       chmod(tcfile, 0666);
+       fprintf(fprx, "%c %s %s\n", X_USER, User, local);
+
+       /* find remote system name */
+       ap = inargs;
+       while ((ap = getprm(ap, prm)) != NULL) {
+               if (prm[0] == '>' || prm[0] == '<') {
+                       ap = getprm(ap, prm);
+                       continue;
+               }
+
+               if (prm[0] == ';') {
+                       APPCMD(prm);
+                       continue;
+               }
+
+               split(prm, xsys, rest);
+               if (xsys[0] == '\0')
+                       strcpy(xsys, local);
+               break;
+       }
+       DEBUG(4, "xsys %s\n", xsys);
+       if (versys(xsys) != 0) {
+               /*  bad system name  */
+               fprintf(stderr, "bad system name: %s\n", xsys);
+               fclose(fprx);
+               fclose(fpc);
+               unlink(rxfile);
+               unlink(tcfile);
+               cleanup(101);
+       }
+
+       if (pipein) {
+               gename(DATAPRE, xsys, 'B', dfile);
+               fpd = fopen(dfile, "w");
+               ASSERT(fpd != NULL, "CAN'T OPEN %s", dfile);
+               chmod(dfile, 0666);
+               while (fgets(buf, BUFSIZ, stdin) != NULL)
+                       fputs(buf, fpd);
+               fclose(fpd);
+               if (strcmp(local, xsys) != SAME) {
+                       GENSEND(fpc, dfile, dfile, User, dfile);
+                       cflag++;
+               }
+               fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
+               fprintf(fprx, "%c %s\n", X_STDIN, dfile);
+       }
+       /* parse command */
+       ap = inargs;
+       while ((ap = getprm(ap, prm)) != NULL) {
+               DEBUG(4, "prm - %s\n", prm);
+               if (prm[0] == '>' || prm[0] == '<') {
+                       redir = prm[0];
+                       continue;
+               }
+
+               if (prm[0] == '|' || prm[0] == '^') {
+                       if (cmdp != cmd)
+                               APPCMD(prm);
+                       continue;
+               }
+
+               /* process command or file or option */
+               ret = split(prm, syspart, rest);
+               DEBUG(4, "s - %s, ", syspart);
+               DEBUG(4, "r - %s, ", rest);
+               DEBUG(4, "ret - %d\n", ret);
+               if (syspart[0] == '\0')
+                       strcpy(syspart, local);
+
+               if (cmdp == cmd && redir == '\0') {
+                       /* command */
+                       APPCMD(rest);
+                       continue;
+               }
+
+               /* process file or option */
+               DEBUG(4, "file s- %s, ", syspart);
+               DEBUG(4, "local - %s\n", local);
+               /* process file */
+               if (redir == '>') {
+                       if (rest[0] != '~')
+                               expfile(rest);
+                       fprintf(fprx, "%c %s %s\n", X_STDOUT, rest,
+                        syspart);
+                       redir = '\0';
+                       continue;
+               }
+
+               if (ret == NOSYSPART) {
+                       /* option */
+                       APPCMD(rest);
+                       continue;
+               }
+
+               if (strcmp(xsys, local) == SAME
+                && strcmp(xsys, syspart) == SAME) {
+                       expfile(rest);
+                       if (redir == '<')
+                               fprintf(fprx, "%c %s\n", X_STDIN, rest);
+                       else
+                               APPCMD(rest);
+                       redir = '\0';
+                       continue;
+               }
+
+               if (strcmp(syspart, local) == SAME) {
+                       /*  generate send file */
+                       expfile(rest);
+                       gename(DATAPRE, xsys, 'A', dfile);
+                       if (redir == '<') {
+                               fprintf(fprx, "%c %s\n", X_STDIN, dfile);
+                       }
+                       DEBUG(4, "rest %s\n", rest);
+                       if (chkpth(User, "", rest) != 0) {
+                               fprintf(stderr, "permission denied %s\n", rest);
+                               cleanup(1);
+                       }
+                       if (xcp(rest, dfile) != 0)
+                               cleanup(1);
+                       GENSEND(fpc, rest, dfile, User, dfile);
+                       cflag++;
+                       fprintf(fprx, "%c %s %s\n", X_RQDFILE,
+                        dfile, lastpart(rest));
+                       if (redir != '<')
+                               APPCMD(lastpart(rest));
+                       redir = '\0';
+                       continue;
+               }
+
+               if (strcmp(local, xsys) == SAME) {
+                       /*  generate local receive  */
+                       gename(CMDPRE, syspart, 'R', tfile);
+                       strcpy(dfile, tfile);
+                       dfile[0] = DATAPRE;
+                       fp = fopen(tfile, "w");
+                       ASSERT(fp != NULL, "CAN'T OPEN %s", tfile);
+                       chmod(tfile, 0666);
+                       expfile(rest);
+                       GENRCV(fp, rest, dfile, User);
+                       fclose(fp);
+                       rflag++;
+                       fprintf(fprx, "%c %s %s\n", X_RQDFILE, dfile,
+                         lastpart(rest));
+                       if (rest[0] != '~')
+                               expfile(rest);
+                       if (redir == '<')
+                               fprintf(fprx, "%c %s\n", X_STDIN, dfile);
+                       else
+                               APPCMD(lastpart(rest));
+                       redir = '\0';
+                       continue;
+               }
+
+               if (strcmp(syspart, xsys) != SAME) {
+                       /* generate remote receives */
+                       gename(DATAPRE, syspart, 'R', dfile);
+                       strcpy(tfile, dfile);
+                       tfile[0] = CMDPRE;
+                       fpd = fopen(dfile, "w");
+                       ASSERT(fpd != NULL, "CAN'T OPEN %s", dfile);
+                       chmod(dfile, 0666);
+                       gename(DATAPRE, xsys, 'T', t2file);
+                       GENRCV(fpd, rest, t2file, User);
+                       fclose(fpd);
+                       GENSEND(fpc, dfile, tfile, User, dfile);
+                       cflag++;
+                       fprintf(fprx, "%c %s %s\n", X_RQDFILE, t2file,
+                         lastpart(rest));
+                       if (redir == '<')
+                               fprintf(fprx, "%c %s\n", X_STDIN, t2file);
+                       else
+                               APPCMD(lastpart(rest));
+                       redir = '\0';
+                       continue;
+               }
+
+               /* file on remote system */
+               if (rest[0] != '~')
+                       expfile(rest);
+               if (redir == '<')
+                       fprintf(fprx, "%c %s\n", X_STDIN, rest);
+               else
+                       APPCMD(rest);
+               redir = '\0';
+               continue;
+
+       }
+
+       fprintf(fprx, "%c %s\n", X_CMD, cmd);
+       fclose(fprx);
+
+       strcpy(tfile, rxfile);
+       tfile[0] = XQTPRE;
+       if (strcmp(xsys, local) == SAME) {
+               link(rxfile, tfile);
+               unlink(rxfile);
+               if (startjob)
+                       if (rflag)
+                               xuucico("");
+                       else
+                               xuuxqt();
+       }
+       else {
+               GENSEND(fpc, rxfile, tfile, User, rxfile);
+               cflag++;
+       }
+
+       fclose(fpc);
+       if (cflag) {
+               gename(CMDPRE, xsys, 'A', cfile);
+               link(tcfile, cfile);
+               unlink(tcfile);
+               if (startjob)
+                       xuucico(xsys);
+               cleanup(0);
+       }
+       else
+               unlink(tcfile);
+}
+
+
+cleanup(code)
+int code;
+{
+       rmlock(NULL);
+       DEBUG(1, "exit code %d\n", code);
+       exit(code);
+}
+
+/***
+ *     split(name, sys, rest)  split into system and file part
+ *     char *name, *sys, *rest;
+
+ *
+ *     return codes:
+ *             NOSYSPART
+ *             HASSYSPART
+ */
+
+split(name, sys, rest)
+char *name, *sys, *rest;
+{
+       char *c;
+       int i;
+
+       if ((c = index(name, '!')) == NULL) {
+               strcpy(rest, name);
+               *sys = '\0';
+               return(NOSYSPART);
+       }
+
+       *c = '\0';
+       for (i = 0; i < 7; i++)
+               if ((*sys++ = *name++) == '\0')
+                       break;
+
+       strcpy(rest, ++c);
+       return(HASSYSPART);
+}