X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/a68924a6e07d69bc4b8d6106b3af0ac5a7490905..2021bdb7882cc19c9c4d2cbe670a9bc6b8274c54:/usr/src/cmd/uucp/uucp.c diff --git a/usr/src/cmd/uucp/uucp.c b/usr/src/cmd/uucp/uucp.c index 8463592b49..9680d612bd 100644 --- a/usr/src/cmd/uucp/uucp.c +++ b/usr/src/cmd/uucp/uucp.c @@ -1,18 +1,23 @@ + /* uucp 2.7 5/24/79 19:40:13 */ #include "uucp.h" #include "uucpdefs.h" #include #include +static char SiD[] = "@(#)uucp 2.7"; + /* * uucp */ int Uid; -int Startjob = 1; -char Path[100], Optns[10]; +char *Ropt = " "; +char Path[100], Optns[10], Ename[8]; char Grade = 'n'; int Copy = 1; +#define MAXCOUNT 20 /* maximun number of commands per C. file */ + main(argc, argv) char *argv[]; { @@ -21,18 +26,20 @@ char *argv[]; char file1[MAXFULLNAME], file2[MAXFULLNAME]; extern char *index(); + uucpname(Myname); Optns[0] = '-'; - Optns[1] = '\0'; + Ename[0] = Optns[1] = '\0'; while(argc>1 && argv[1][0] == '-'){ switch(argv[1][1]){ case 'c': Copy = 0; + strcat(Optns, "c"); break; case 'd': strcat(Optns, "d"); break; case 'e': - fprintf(stderr, "-e option removed\n"); + sprintf(Ename, "%.7s", &argv[1][2]); break; case 'g': Grade = argv[1][2]; break; @@ -40,7 +47,7 @@ char *argv[]; strcat(Optns, "m"); break; case 'r': - Startjob = 0; + Ropt = argv[1]; break; case 's': Spool = &argv[1][2]; break; @@ -56,7 +63,10 @@ char *argv[]; } DEBUG(4, "\n\n** %s **\n", "START"); ret = gwd(Wrkdir); - ASSERT(ret == 0, "GWD FAILED %d", ret); + if (ret != 0) { + fprintf(stderr, "can't get working directory; will try to continue\n"); + strcpy(Wrkdir, "/UNKNOWN"); + } chdir(Spool); Uid = getuid(); @@ -64,6 +74,7 @@ char *argv[]; ASSERT(ret == 0, "CAN NOT FIND UID %d\n", 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"); @@ -89,6 +100,8 @@ char *argv[]; sysfile2 = Myname; strcpy(file2, argv[argc - 1]); } + if (strlen(sysfile2) > 7) + *(sysfile2 + 7) = '\0'; /* do each from argument */ @@ -96,6 +109,8 @@ char *argv[]; if ((cp = index(argv[1], '!')) != NULL) { sysfile1 = argv[1]; *cp = '\0'; + if (strlen(sysfile1) > 7) + *(sysfile1 + 7) = '\0'; if (*sysfile1 == '\0') sysfile1 = Myname; else @@ -116,7 +131,8 @@ char *argv[]; argv++; } - if (Startjob) + clscfile(); + if (*Ropt != '-') xuucico(""); cleanup(0); } @@ -140,12 +156,13 @@ int code; copy(s1, f1, s2, f2) char *s1, *f1, *s2, *f2; { - int ret, type; - struct stat stbuf; - char cfile[NAMESIZE], dfile[NAMESIZE]; + int ret, type, statret; + struct stat stbuf, stbuf1; + char dfile[NAMESIZE]; char file1[MAXFULLNAME], file2[MAXFULLNAME]; FILE *cfp; extern char *index(); + extern FILE *gtcfile(); type = 0; strcpy(file1, f1); @@ -159,17 +176,40 @@ char *s1, *f1, *s2, *f2; || 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 (stat(file1, &stbuf) != 0) { + fprintf(stderr, "can't get file status %s \n copy failed\n", + file1); + return(0); + } + statret = stat(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); + } if (chkpth(User, "", file1) != 0 - || chkpth(User, "", file2) != 0) { + || chkpth(User, "", file2) != 0) { fprintf(stderr, "permission denied\n"); cleanup(1); } + if ((stbuf.st_mode & ANYREAD) == 0) { + fprintf(stderr, "can't read file (%s) mode (%o)\n", + file1, stbuf.st_mode); + 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); + } xcp(file1, file2); logent("WORK HERE", "DONE"); return(0); @@ -183,13 +223,14 @@ char *s1, *f1, *s2, *f2; 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); + if (Ename[0] != '\0') { + /* execute uux - remote uucp */ + xuux(Ename, s1, file1, s2, file2); + return(0); + } + + cfp = gtcfile(s1); fprintf(cfp, "R %s %s %s %s\n", file1, file2, User, Optns); - fclose(cfp); break; case 2: /* send file */ @@ -198,20 +239,31 @@ char *s1, *f1, *s2, *f2; 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 (stat(file1, &stbuf) != 0) { + fprintf(stderr, "can't get status for file %s\n", file1); + return(FAIL); + } if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { fprintf(stderr, "directory name illegal - %s\n", file1); return(FAIL); } + if ((stbuf.st_mode & ANYREAD) == 0) { + fprintf(stderr, "can't read file (%s) mode (%o)\n", + file1, stbuf.st_mode); + return(FAIL); + } + if (Ename[0] != '\0') { + /* execute uux - remote uucp */ + xuux(Ename, s1, file1, s2, file2); + return(0); + } if (Copy) { + gename(DATAPRE, s2, Grade, dfile); if (xcp(file1, dfile) != 0) { fprintf(stderr, "can't copy %s\n", file1); return(FAIL); @@ -219,22 +271,17 @@ char *s1, *f1, *s2, *f2; chmod(dfile, 0666); } else { - if ((stbuf.st_mode & 04) == 0) { - fprintf(stderr, "uucico can't access %s (-c specified)\n", file1); - return(FAIL); - } + /* make a dummy D. name */ + /* cntrl.c knows names < 6 chars are dummy D. files */ + strcpy(dfile, "D.0"); } - cfp = fopen(cfile, "w"); - ASSERT(cfp != NULL, "CAN NOT OPEN %s", cfile); - chmod(cfile, 0200); + cfp = gtcfile(s2); 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 */ + /* send uucp command for execution on s1 */ DEBUG(4, "send uucp command - %d\n", type); if (strcmp(s2, Myname) == SAME) { expfile(file2); @@ -243,13 +290,87 @@ char *s1, *f1, *s2, *f2; return(FAIL); } } - gename(CMDPRE, s1, Grade, cfile); - cfp = fopen(cfile, "w"); - ASSERT(cfp != NULL, "CAN NOT OPEN %s", cfile); + if (Ename[0] != '\0') { + /* execute uux - remote uucp */ + xuux(Ename, s1, file1, s2, file2); + return(0); + } + cfp = gtcfile(s1); fprintf(cfp, "X %s %s!%s\n", file1, s2, file2); - fclose(cfp); break; } - logent(cfile, "QUEUED"); return(0); } + +/*** + * xuux(ename, s1, s2, f1, f2) execute uux for remote uucp + * + * return code - none + */ + +xuux(ename, s1, f1, s2, f2) +char *ename, *s1, *s2, *f1, *f2; +{ + char cmd[200]; + + DEBUG(4, "Ropt(%s) ", Ropt); + DEBUG(4, "ename(%s) ", ename); + DEBUG(4, "s1(%s) ", s1); + DEBUG(4, "f1(%s) ", f1); + DEBUG(4, "s2(%s) ", s2); + DEBUG(4, "f2(%s)\n", f2); + sprintf(cmd, "uux %s %s!uucp %s!%s \\(%s!%s\\)", + Ropt, ename, s1, f1, s2, f2); + DEBUG(4, "cmd (%s)\n", cmd); + system(cmd); + return; +} + +FILE *Cfp = NULL; +char Cfile[NAMESIZE]; + +/*** + * gtcfile(sys) - get a Cfile descriptor + * + * return an open file descriptor + */ + +FILE * +gtcfile(sys) +char *sys; +{ + static char presys[8] = ""; + static int cmdcount = 0; + + if (strcmp(presys, sys) != SAME /* this is !SAME on first call */ + || ++cmdcount > MAXCOUNT) { + + cmdcount = 1; + if (presys[0] != '\0') { + clscfile(); + } + gename(CMDPRE, sys, Grade, Cfile); + Cfp = fopen(Cfile, "w"); + ASSERT(Cfp != NULL, "CAN'T OPEN %s", Cfile); + chmod(0200, Cfile); + strcpy(presys, sys); + } + return(Cfp); +} + +/*** + * clscfile() - close cfile + * + * return code - none + */ + +clscfile() +{ + if (Cfp == NULL) + return; + fclose(Cfp); + chmod(0666, Cfile); + logent(Cfile, "QUE'D"); + Cfp = NULL; + return; +}