113697Ssam #ifndef lint 2*17870Sralph static char sccsid[] = "@(#)uuxqt.c 5.4 (Berkeley) 01/28/85"; 313697Ssam #endif 413697Ssam 513697Ssam #include "uucp.h" 613697Ssam #include <sys/types.h> 713697Ssam #include <sys/stat.h> 813697Ssam #ifdef NDIR 913697Ssam #include "ndir.h" 1013697Ssam #else 1113702Ssam #include <sys/dir.h> 1213697Ssam #endif 1317846Sralph #include <signal.h> 1413697Ssam 15*17870Sralph #define BADCHARS "&^|(`\\<>;" 16*17870Sralph 1713697Ssam #define APPCMD(d) {\ 1813697Ssam char *p;\ 1917846Sralph for (p = d; *p != '\0';) *cmdp++ = *p++; *cmdp++ = ' '; *cmdp = '\0';} 2013697Ssam 2113697Ssam /* 2213697Ssam * uuxqt will execute commands set up by a uux command, 2313697Ssam * usually from a remote machine - set by uucp. 2413697Ssam */ 2513697Ssam 2613697Ssam #define NCMDS 50 2717846Sralph char *Cmds[NCMDS+1]; 2817846Sralph int Notify[NCMDS+1]; 2917846Sralph #define NT_YES 0 /* if should notify on execution */ 3017846Sralph #define NT_ERR 1 /* if should notify if non-zero exit status (-z equivalent) */ 3117846Sralph #define NT_NO 2 /* if should not notify ever (-n equivalent) */ 3213697Ssam 3317846Sralph extern int Nfiles; 34*17870Sralph char *sindex(); 3517846Sralph 3613697Ssam int notiok = 1; 3713697Ssam int nonzero = 0; 3813697Ssam 3917846Sralph #ifdef SIGCHLD 4017846Sralph #include <sys/wait.h> 4117846Sralph reapchild() 4217846Sralph { 4317846Sralph union wait status; 4417846Sralph 4517846Sralph while (wait3(&status,WNOHANG,0) > 0) 4617846Sralph ; 4717846Sralph } 4817846Sralph #endif SIGCHLD 4917846Sralph 5017846Sralph char PATH[MAXFULLNAME] = "PATH=/bin:/usr/bin:/usr/ucb"; 5113697Ssam /* to remove restrictions from uuxqt 5213697Ssam * define ALLOK 1 5313697Ssam * 5413697Ssam * to add allowable commands, add to the file CMDFILE 5513697Ssam * A line of form "PATH=..." changes the search path 5613697Ssam */ 5713697Ssam main(argc, argv) 5813697Ssam char *argv[]; 5913697Ssam { 6013697Ssam char xcmd[MAXFULLNAME]; 6113697Ssam int argnok; 6217846Sralph int notiflg; 6317846Sralph char xfile[MAXFULLNAME], user[MAXFULLNAME], buf[BUFSIZ]; 6417846Sralph char lbuf[MAXFULLNAME]; 6513697Ssam char cfile[NAMESIZE], dfile[MAXFULLNAME]; 6613697Ssam char file[NAMESIZE]; 6713697Ssam char fin[MAXFULLNAME], sysout[NAMESIZE], fout[MAXFULLNAME]; 6813697Ssam register FILE *xfp, *fp; 6913697Ssam FILE *dfp; 7013697Ssam char path[MAXFULLNAME]; 7113697Ssam char cmd[BUFSIZ]; 7213697Ssam char *cmdp, prm[1000], *ptr; 7313697Ssam char *getprm(), *lastpart(); 7417846Sralph int uid, ret, ret2, badfiles; 7513697Ssam register int i; 7613697Ssam int stcico = 0; 7713697Ssam char retstat[30]; 7813697Ssam 7913697Ssam strcpy(Progname, "uuxqt"); 8013697Ssam uucpname(Myname); 8113697Ssam 8217846Sralph #ifdef SIGCHLD 8317846Sralph signal(SIGCHLD, reapchild); 8417846Sralph #endif SIGCHLD 8513697Ssam 8613697Ssam umask(WFMASK); 8713697Ssam Ofn = 1; 8813697Ssam Ifn = 0; 8913697Ssam while (argc>1 && argv[1][0] == '-') { 9013697Ssam switch(argv[1][1]){ 9113697Ssam case 'x': 9217846Sralph chkdebug(); 9313697Ssam Debug = atoi(&argv[1][2]); 9413697Ssam if (Debug <= 0) 9513697Ssam Debug = 1; 9613697Ssam break; 9713697Ssam default: 9813697Ssam fprintf(stderr, "unknown flag %s\n", argv[1]); 9913697Ssam break; 10013697Ssam } 10113697Ssam --argc; argv++; 10213697Ssam } 10313697Ssam 10413697Ssam DEBUG(4, "\n\n** %s **\n", "START"); 10517846Sralph ret = subchdir(Spool); 10617846Sralph ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); 10713697Ssam strcpy(Wrkdir, Spool); 10813697Ssam uid = getuid(); 10913697Ssam guinfo(uid, User, path); 11017846Sralph /* Try to run as uucp -- rti!trt */ 11117846Sralph setgid(getegid()); 11217846Sralph setuid(geteuid()); 11317846Sralph 11413697Ssam DEBUG(4, "User - %s\n", User); 11513697Ssam if (ulockf(X_LOCK, (time_t) X_LOCKTIME) != 0) 11613697Ssam exit(0); 11713697Ssam 11813697Ssam fp = fopen(CMDFILE, "r"); 11913697Ssam if (fp == NULL) { 12017846Sralph logent(CANTOPEN, CMDFILE); 12113697Ssam Cmds[0] = "rmail"; 12213697Ssam Cmds[1] = "rnews"; 12313697Ssam Cmds[2] = "ruusend"; 12413697Ssam Cmds[3] = NULL; 12513697Ssam goto doprocess; 12613697Ssam } 12713697Ssam DEBUG(5, "%s opened\n", CMDFILE); 12817846Sralph for (i=0; i<NCMDS && cfgets(xcmd, sizeof(xcmd), fp) != NULL; i++) { 12917846Sralph int j; 13017846Sralph /* strip trailing whitespace */ 13117846Sralph for (j = strlen(xcmd)-1; j >= 0; --j) 13217846Sralph if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') 13317846Sralph xcmd[j] = '\0'; 13417846Sralph else 13517846Sralph break; 13617846Sralph /* look for imbedded whitespace */ 13717846Sralph for (; j >= 0; --j) 13817846Sralph if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') 13917846Sralph break; 14017846Sralph /* skip this entry if it has embedded whitespace */ 14117846Sralph /* This defends against a bad PATH=, for example */ 14217846Sralph if (j >= 0) { 14317846Sralph logent(xcmd, "BAD WHITESPACE"); 14417846Sralph continue; 14517846Sralph } 14613697Ssam if (strncmp(xcmd, "PATH=", 5) == 0) { 14713697Ssam strcpy(PATH, xcmd); 14817846Sralph i--; /*kludge */ 14913697Ssam continue; 15013697Ssam } 15113697Ssam DEBUG(5, "xcmd = %s\n", xcmd); 15217846Sralph 15317846Sralph if ((ptr = index(xcmd, ',')) != NULL) { 15417846Sralph *ptr++ = '\0'; 15517846Sralph if (strncmp(ptr, "Err", 3) == SAME) 15617846Sralph Notify[i] = NT_ERR; 15717846Sralph else if (strcmp(ptr, "No") == SAME) 15817846Sralph Notify[i] = NT_NO; 15917846Sralph else 16017846Sralph Notify[i] = NT_YES; 16117846Sralph } else 16217846Sralph Notify[i] = NT_YES; 16317846Sralph if ((Cmds[i] = malloc((unsigned)(strlen(xcmd)+1))) == NULL) { 16417846Sralph DEBUG(1, "MALLOC FAILED", CNULL); 16517846Sralph break; 16617846Sralph } 16713697Ssam strcpy(Cmds[i], xcmd); 16813697Ssam } 16917846Sralph Cmds[i] = CNULL; 17013697Ssam fclose(fp); 17113697Ssam 17213697Ssam doprocess: 17317846Sralph DEBUG(4, "process %s\n", CNULL); 17413697Ssam while (gtxfile(xfile) > 0) { 17517846Sralph ultouch(); 17617846Sralph /* if /etc/nologin exists, exit cleanly */ 17717846Sralph if (nologinflag) { 17817846Sralph logent(NOLOGIN, "UUXQT SHUTDOWN"); 17917846Sralph if (Debug) 18017846Sralph logent("debugging", "continuing anyway"); 18117846Sralph else 18217846Sralph break; 18317846Sralph } 18413697Ssam DEBUG(4, "xfile - %s\n", xfile); 18513697Ssam 18613697Ssam xfp = fopen(subfile(xfile), "r"); 18717846Sralph ASSERT(xfp != NULL, CANTOPEN, xfile, 0); 18813697Ssam 18913697Ssam /* initialize to default */ 19013697Ssam strcpy(user, User); 19117846Sralph strcpy(fin, DEVNULL); 19217846Sralph strcpy(fout, DEVNULL); 19313697Ssam sprintf(sysout, "%.7s", Myname); 19417846Sralph badfiles = 0; 19513697Ssam while (fgets(buf, BUFSIZ, xfp) != NULL) { 19613697Ssam switch (buf[0]) { 19713697Ssam case X_USER: 19817846Sralph sscanf(&buf[1], "%s %s", user, Rmtname); 19913697Ssam break; 20017846Sralph case X_RETURNTO: 20117846Sralph sscanf(&buf[1], "%s", user); 20217846Sralph break; 20313697Ssam case X_STDIN: 20413697Ssam sscanf(&buf[1], "%s", fin); 20513697Ssam i = expfile(fin); 20613697Ssam /* rti!trt: do not check permissions of 20713697Ssam * vanilla spool file */ 20813697Ssam if (i != 0 20913697Ssam && (chkpth("", "", fin) || anyread(fin) != 0)) 21013697Ssam badfiles = 1; 21113697Ssam break; 21213697Ssam case X_STDOUT: 21313697Ssam sscanf(&buf[1], "%s%s", fout, sysout); 21413697Ssam sysout[7] = '\0'; 21513697Ssam /* rti!trt: do not check permissions of 21613697Ssam * vanilla spool file. DO check permissions 21713697Ssam * of writing on a non-vanilla file */ 21813697Ssam i = 1; 21913697Ssam if (fout[0] != '~' || prefix(sysout, Myname)) 22013697Ssam i = expfile(fout); 22113697Ssam if (i != 0 22213697Ssam && (chkpth("", "", fout) 22313697Ssam || chkperm(fout, (char *)1))) 22413697Ssam badfiles = 1; 22513697Ssam break; 22613697Ssam case X_CMD: 22713697Ssam strcpy(cmd, &buf[2]); 22813697Ssam if (*(cmd + strlen(cmd) - 1) == '\n') 22913697Ssam *(cmd + strlen(cmd) - 1) = '\0'; 23013697Ssam break; 23113697Ssam case X_NONOTI: 23213697Ssam notiok = 0; 23313697Ssam break; 23413697Ssam case X_NONZERO: 23513697Ssam nonzero = 1; 23613697Ssam break; 23713697Ssam default: 23813697Ssam break; 23913697Ssam } 24013697Ssam } 24113697Ssam 24213697Ssam fclose(xfp); 24313697Ssam DEBUG(4, "fin - %s, ", fin); 24413697Ssam DEBUG(4, "fout - %s, ", fout); 24513697Ssam DEBUG(4, "sysout - %s, ", sysout); 24613697Ssam DEBUG(4, "user - %s\n", user); 24713697Ssam DEBUG(4, "cmd - %s\n", cmd); 24813697Ssam 24913697Ssam /* command execution */ 25017846Sralph if (strcmp(fout, DEVNULL) == SAME) 25117846Sralph strcpy(dfile,DEVNULL); 25213697Ssam else 25313697Ssam gename(DATAPRE, sysout, 'O', dfile); 25413697Ssam 25513697Ssam /* expand file names where necessary */ 25613697Ssam expfile(dfile); 25713697Ssam strcpy(buf, PATH); 25817846Sralph strcat(buf, " "); 25913697Ssam cmdp = buf + strlen(buf); 26013697Ssam ptr = cmd; 26113697Ssam xcmd[0] = '\0'; 26213697Ssam argnok = 0; 26313697Ssam while ((ptr = getprm(ptr, prm)) != NULL) { 26413697Ssam if (prm[0] == ';' || prm[0] == '^' 26513697Ssam || prm[0] == '&' || prm[0] == '|') { 26613697Ssam xcmd[0] = '\0'; 26713697Ssam APPCMD(prm); 26813697Ssam continue; 26913697Ssam } 27013697Ssam 27117846Sralph if ((argnok = argok(xcmd, prm)) != SUCCESS) 27213697Ssam /* command not valid */ 27313697Ssam break; 27413697Ssam 27513697Ssam if (prm[0] == '~') 27613697Ssam expfile(prm); 27713697Ssam APPCMD(prm); 27813697Ssam } 27917846Sralph /* 28017846Sralph * clean up trailing ' ' in command. 28117846Sralph */ 28217846Sralph if (cmdp > buf && cmdp[0] == '\0' && cmdp[-1] == ' ') 28317846Sralph *--cmdp = '\0'; 284*17870Sralph if (sindex(user, BADCHARS) != NULL) { 285*17870Sralph sprintf(lbuf, "%s INVALID CHARACTER IN USERNAME", user); 286*17870Sralph logent(cmd, lbuf); 287*17870Sralph strcpy(user, "postmaster"); 288*17870Sralph } 28913697Ssam if (argnok || badfiles) { 29013697Ssam sprintf(lbuf, "%s XQT DENIED", user); 29113697Ssam logent(cmd, lbuf); 29213697Ssam DEBUG(4, "bad command %s\n", prm); 29313697Ssam notify(user, Rmtname, cmd, "DENIED"); 29413697Ssam goto rmfiles; 29513697Ssam } 29613697Ssam sprintf(lbuf, "%s XQT", user); 29713697Ssam logent(buf, lbuf); 29813697Ssam DEBUG(4, "cmd %s\n", buf); 29913697Ssam 30013697Ssam mvxfiles(xfile); 30117846Sralph ret = subchdir(XQTDIR); 30217846Sralph ASSERT(ret >= 0, "CHDIR FAILED", XQTDIR, ret); 30317846Sralph ret = shio(buf, fin, dfile, CNULL); 30413697Ssam sprintf(retstat, "signal %d, exit %d", ret & 0377, 30513697Ssam (ret>>8) & 0377); 30613697Ssam if (strcmp(xcmd, "rmail") == SAME) 30713697Ssam notiok = 0; 30813697Ssam if (strcmp(xcmd, "rnews") == SAME) 30913697Ssam nonzero = 1; 31017846Sralph notiflg = chknotify(xcmd); 31117846Sralph if (notiok && notiflg != NT_NO && 31217846Sralph (ret != 0 || (!nonzero && notiflg == NT_YES))) 31313697Ssam notify(user, Rmtname, cmd, retstat); 31413697Ssam else if (ret != 0 && strcmp(xcmd, "rmail") == SAME) { 31513697Ssam /* mail failed - return letter to sender */ 31617846Sralph #ifdef DANGEROUS 31717846Sralph /* NOT GUARANTEED SAFE!!! */ 31817846Sralph if (!nonzero) 31917846Sralph retosndr(user, Rmtname, fin); 32017846Sralph #else 32117846Sralph notify(user, Rmtname, cmd, retstat); 32217846Sralph #endif 32317846Sralph sprintf(buf, "%s (%s) from %s!%s", buf, retstat, Rmtname, user); 32413697Ssam logent("MAIL FAIL", buf); 32513697Ssam } 32613697Ssam DEBUG(4, "exit cmd - %d\n", ret); 32717846Sralph ret2 = subchdir(Spool); 32817846Sralph ASSERT(ret2 >= 0, "CHDIR FAILED", Spool, ret); 32913697Ssam rmxfiles(xfile); 33013697Ssam if (ret != 0) { 33113697Ssam /* exit status not zero */ 33213697Ssam dfp = fopen(subfile(dfile), "a"); 33317846Sralph ASSERT(dfp != NULL, CANTOPEN, dfile, 0); 33413697Ssam fprintf(dfp, "exit status %d", ret); 33513697Ssam fclose(dfp); 33613697Ssam } 33717846Sralph if (strcmp(fout, DEVNULL) != SAME) { 33813697Ssam if (prefix(sysout, Myname)) { 33913697Ssam xmv(dfile, fout); 34013697Ssam chmod(fout, BASEMODE); 34113697Ssam } 34213697Ssam else { 34317846Sralph char *cp = rindex(user, '!'); 34413697Ssam gename(CMDPRE, sysout, 'O', cfile); 34513697Ssam fp = fopen(subfile(cfile), "w"); 34613697Ssam ASSERT(fp != NULL, "OPEN", cfile, 0); 34717846Sralph fprintf(fp, "S %s %s %s - %s 0666\n", dfile, 34817846Sralph fout, cp ? cp : user, lastpart(dfile)); 34913697Ssam fclose(fp); 35013697Ssam } 35113697Ssam } 35213697Ssam rmfiles: 35313697Ssam xfp = fopen(subfile(xfile), "r"); 35417846Sralph ASSERT(xfp != NULL, CANTOPEN, xfile, 0); 35513697Ssam while (fgets(buf, BUFSIZ, xfp) != NULL) { 35613697Ssam if (buf[0] != X_RQDFILE) 35713697Ssam continue; 35813697Ssam sscanf(&buf[1], "%s", file); 35913697Ssam unlink(subfile(file)); 36013697Ssam } 36113697Ssam unlink(subfile(xfile)); 36213697Ssam fclose(xfp); 36313697Ssam } 36413697Ssam 36513697Ssam if (stcico) 36613697Ssam xuucico(""); 36713697Ssam cleanup(0); 36813697Ssam } 36913697Ssam 37013697Ssam 37113697Ssam cleanup(code) 37213697Ssam int code; 37313697Ssam { 37413697Ssam logcls(); 37513697Ssam rmlock(CNULL); 37617846Sralph #ifdef VMS 37717846Sralph /* 37817846Sralph * Since we run as a BATCH job we must wait for all processes to 37917846Sralph * to finish 38017846Sralph */ 38117846Sralph while(wait(0) != -1); 38217846Sralph #endif VMS 38313697Ssam exit(code); 38413697Ssam } 38513697Ssam 38613697Ssam 38713697Ssam /******* 38813697Ssam * gtxfile(file) get a file to execute 38913697Ssam * char *file; 39013697Ssam * 39113697Ssam * return codes: 0 - no file | 1 - file to execute 39213697Ssam */ 39313697Ssam 39413697Ssam gtxfile(file) 39513697Ssam register char *file; 39613697Ssam { 39713697Ssam char pre[3]; 39817846Sralph int rechecked; 39917846Sralph time_t ystrdy; /* yesterday */ 40017846Sralph extern time_t time(); 40117846Sralph struct stat stbuf; /* for X file age */ 40213697Ssam 40313697Ssam pre[0] = XQTPRE; 40413697Ssam pre[1] = '.'; 40513697Ssam pre[2] = '\0'; 40613697Ssam rechecked = 0; 40713697Ssam retry: 40813697Ssam if (!gtwrkf(Spool, file)) { 40913697Ssam if (rechecked) 41017846Sralph return 0; 41113697Ssam rechecked = 1; 41217846Sralph DEBUG(4, "iswrk\n", CNULL); 41313697Ssam if (!iswrk(file, "get", Spool, pre)) 41417846Sralph return 0; 41513697Ssam } 41613697Ssam DEBUG(4, "file - %s\n", file); 41713697Ssam /* skip spurious subdirectories */ 41813697Ssam if (strcmp(pre, file) == SAME) 41913697Ssam goto retry; 42013697Ssam if (gotfiles(file)) 42117846Sralph return 1; 42217846Sralph /* check for old X. file with no work files and remove them. */ 42317846Sralph if (Nfiles > LLEN/2) { 42417846Sralph time(&ystrdy); 42517846Sralph ystrdy -= (4 * 3600L); /* 4 hours ago */ 42617846Sralph DEBUG(4, "gtxfile: Nfiles > LLEN/2\n", CNULL); 42717846Sralph while (gtwrkf(Spool, file) && !gotfiles(file)) { 42817846Sralph if (stat(subfile(file), &stbuf) == 0) 42917846Sralph if (stbuf.st_mtime <= ystrdy) { 43017846Sralph char *bnp, cfilename[NAMESIZE]; 43117846Sralph DEBUG(4, "gtxfile: move %s to CORRUPT \n", file); 43217846Sralph unlink(subfile(file)); 43317846Sralph bnp = rindex(subfile(file), '/'); 43417846Sralph sprintf(cfilename, "%s/%s", CORRUPT, 43517846Sralph bnp ? bnp + 1 : subfile(file)); 43617846Sralph xmv(subfile(file), cfilename); 43717846Sralph logent(file, "X. FILE CORRUPTED"); 43817846Sralph } 43917846Sralph } 44017846Sralph DEBUG(4, "iswrk\n", CNULL); 44117846Sralph if (!iswrk(file, "get", Spool, pre)) 44217846Sralph return 0; 44317846Sralph } 44413697Ssam goto retry; 44513697Ssam } 44613697Ssam 44713697Ssam 44813697Ssam /*** 44913697Ssam * gotfiles(file) check for needed files 45013697Ssam * char *file; 45113697Ssam * 45213697Ssam * return codes: 0 - not ready | 1 - all files ready 45313697Ssam */ 45413697Ssam 45513697Ssam gotfiles(file) 45613697Ssam register char *file; 45713697Ssam { 45813697Ssam struct stat stbuf; 45913697Ssam register FILE *fp; 46013697Ssam char buf[BUFSIZ], rqfile[MAXFULLNAME]; 46113697Ssam 46213697Ssam fp = fopen(subfile(file), "r"); 46313697Ssam if (fp == NULL) 46417846Sralph return 0; 46513697Ssam 46613697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 46713697Ssam DEBUG(4, "%s\n", buf); 46813697Ssam if (buf[0] != X_RQDFILE) 46913697Ssam continue; 47013697Ssam sscanf(&buf[1], "%s", rqfile); 47113697Ssam expfile(rqfile); 47213697Ssam if (stat(subfile(rqfile), &stbuf) == -1) { 47313697Ssam fclose(fp); 47417846Sralph return 0; 47513697Ssam } 47613697Ssam } 47713697Ssam 47813697Ssam fclose(fp); 47917846Sralph return 1; 48013697Ssam } 48113697Ssam 48213697Ssam 48313697Ssam /*** 48413697Ssam * rmxfiles(xfile) remove execute files to x-directory 48513697Ssam * char *xfile; 48613697Ssam * 48713697Ssam * return codes - none 48813697Ssam */ 48913697Ssam 49013697Ssam rmxfiles(xfile) 49113697Ssam register char *xfile; 49213697Ssam { 49313697Ssam register FILE *fp; 49413697Ssam char buf[BUFSIZ], file[NAMESIZE], tfile[NAMESIZE]; 49513697Ssam char tfull[MAXFULLNAME]; 49613697Ssam 49713697Ssam if((fp = fopen(subfile(xfile), "r")) == NULL) 49813697Ssam return; 49913697Ssam 50013697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 50113697Ssam if (buf[0] != X_RQDFILE) 50213697Ssam continue; 50313697Ssam if (sscanf(&buf[1], "%s%s", file, tfile) < 2) 50413697Ssam continue; 50513697Ssam sprintf(tfull, "%s/%s", XQTDIR, tfile); 50613697Ssam unlink(subfile(tfull)); 50713697Ssam } 50813697Ssam fclose(fp); 50913697Ssam return; 51013697Ssam } 51113697Ssam 51213697Ssam 51313697Ssam /*** 51413697Ssam * mvxfiles(xfile) move execute files to x-directory 51513697Ssam * char *xfile; 51613697Ssam * 51713697Ssam * return codes - none 51813697Ssam */ 51913697Ssam 52013697Ssam mvxfiles(xfile) 52113697Ssam char *xfile; 52213697Ssam { 52313697Ssam register FILE *fp; 52413697Ssam char buf[BUFSIZ], ffile[MAXFULLNAME], tfile[NAMESIZE]; 52513697Ssam char tfull[MAXFULLNAME]; 52613697Ssam int ret; 52713697Ssam 52813697Ssam if((fp = fopen(subfile(xfile), "r")) == NULL) 52913697Ssam return; 53013697Ssam 53113697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 53213697Ssam if (buf[0] != X_RQDFILE) 53313697Ssam continue; 53413697Ssam if (sscanf(&buf[1], "%s%s", ffile, tfile) < 2) 53513697Ssam continue; 53613697Ssam expfile(ffile); 53713697Ssam sprintf(tfull, "%s/%s", XQTDIR, tfile); 53813697Ssam unlink(subfile(tfull)); 53913697Ssam ret = xmv(ffile, tfull); 54017846Sralph ASSERT(ret == 0, "XQTDIR ERROR", CNULL, ret); 54113697Ssam } 54213697Ssam fclose(fp); 54313697Ssam return; 54413697Ssam } 54513697Ssam 54613697Ssam 54713697Ssam /*** 54813697Ssam * argok(xc, cmd) check for valid command/argumanet 54913697Ssam * *NOTE - side effect is to set xc to the 55013697Ssam * command to be executed. 55113697Ssam * char *xc, *cmd; 55213697Ssam * 55313697Ssam * return 0 - ok | 1 nok 55413697Ssam */ 55513697Ssam 55613697Ssam argok(xc, cmd) 55713697Ssam register char *xc, *cmd; 55813697Ssam { 55913697Ssam register char **ptr; 56013697Ssam 56113697Ssam #ifndef ALLOK 562*17870Sralph if (sindex(cmd, BADCHARS) != NULL) { 56317846Sralph DEBUG(1,"MAGIC CHARACTER FOUND\n", CNULL); 56417846Sralph return FAIL; 56517846Sralph } 56617846Sralph #endif !ALLOK 56713697Ssam 56813697Ssam if (xc[0] != '\0') 56917846Sralph return SUCCESS; 57013697Ssam 57113697Ssam #ifndef ALLOK 57213697Ssam ptr = Cmds; 57317846Sralph DEBUG(9, "Compare %s and\n", cmd); 57413697Ssam while(*ptr != NULL) { 57517846Sralph DEBUG(9, "\t%s\n", *ptr); 57613697Ssam if (strcmp(cmd, *ptr) == SAME) 57713697Ssam break; 57817846Sralph ptr++; 57913697Ssam } 58017846Sralph if (*ptr == NULL) { 58117846Sralph DEBUG(1,"COMMAND NOT FOUND\n", CNULL); 58217846Sralph return FAIL; 58317846Sralph } 58413697Ssam #endif 58513697Ssam strcpy(xc, cmd); 58617846Sralph DEBUG(9, "MATCHED %s\n", xc); 58717846Sralph return SUCCESS; 58813697Ssam } 58913697Ssam 59013697Ssam 59113697Ssam /*** 59217846Sralph * chknotify(cmd) check if notification should be sent for 59317846Sralph * successful execution of cmd 59417846Sralph * char *cmd; 59517846Sralph * 59617846Sralph * return NT_YES - do notification 59717846Sralph * NT_ERR - do notification if exit status != 0 59817846Sralph * NT_NO - don't do notification ever 59917846Sralph */ 60017846Sralph 60117846Sralph chknotify(cmd) 60217846Sralph char *cmd; 60317846Sralph { 60417846Sralph register char **ptr; 60517846Sralph register int *nptr; 60617846Sralph 60717846Sralph ptr = Cmds; 60817846Sralph nptr = Notify; 60917846Sralph while (*ptr != NULL) { 61017846Sralph if (strcmp(cmd, *ptr) == SAME) 61117846Sralph return *nptr; 61217846Sralph ptr++; 61317846Sralph nptr++; 61417846Sralph } 61517846Sralph return NT_YES; /* "shouldn't happen" */ 61617846Sralph } 61717846Sralph 61817846Sralph 61917846Sralph 62017846Sralph /*** 62113697Ssam * notify send mail to user giving execution results 62213697Ssam * return code - none 62313697Ssam * This program assumes new mail command - send remote mail 62413697Ssam */ 62513697Ssam 62613697Ssam notify(user, rmt, cmd, str) 62713697Ssam char *user, *rmt, *cmd, *str; 62813697Ssam { 62913697Ssam char text[MAXFULLNAME]; 63013697Ssam char ruser[MAXFULLNAME]; 63113697Ssam 63217846Sralph sprintf(text, "uuxqt cmd (%s) status (%s)", cmd, str); 63313697Ssam if (prefix(rmt, Myname)) 63413697Ssam strcpy(ruser, user); 63513697Ssam else 63613697Ssam sprintf(ruser, "%s!%s", rmt, user); 63717846Sralph mailst(ruser, text, CNULL); 63813697Ssam return; 63913697Ssam } 64013697Ssam 64113697Ssam /*** 64213697Ssam * retosndr - return mail to sender 64313697Ssam * 64413697Ssam * return code - none 64513697Ssam */ 64613697Ssam 64713697Ssam retosndr(user, rmt, file) 64813697Ssam char *user, *rmt, *file; 64913697Ssam { 65017846Sralph char ruser[MAXFULLNAME]; 65113697Ssam 65213697Ssam if (strcmp(rmt, Myname) == SAME) 65313697Ssam strcpy(ruser, user); 65413697Ssam else 65513697Ssam sprintf(ruser, "%s!%s", rmt, user); 65613697Ssam 65713697Ssam if (anyread(file) == 0) 65813697Ssam mailst(ruser, "Mail failed. Letter returned to sender.\n", file); 65913697Ssam else 66017846Sralph mailst(ruser, "Mail failed. Letter returned to sender.\n", CNULL); 66113697Ssam return; 66213697Ssam } 663*17870Sralph 664*17870Sralph /* 665*17870Sralph * this is like index, but takes a string as the second argument 666*17870Sralph */ 667*17870Sralph char * 668*17870Sralph sindex(str, chars) 669*17870Sralph register char *str, *chars; 670*17870Sralph { 671*17870Sralph register char *cp; 672*17870Sralph 673*17870Sralph do { 674*17870Sralph cp = chars - 1; 675*17870Sralph while (*++cp) { 676*17870Sralph if (*str == *cp) 677*17870Sralph return str; 678*17870Sralph } 679*17870Sralph } while (*str++); 680*17870Sralph return NULL; 681*17870Sralph } 682