113697Ssam #ifndef lint 2*23692Sbloom static char sccsid[] = "@(#)uuxqt.c 5.6 (Berkeley) 06/23/85"; 313697Ssam #endif 413697Ssam 513697Ssam #include "uucp.h" 613697Ssam #include <sys/stat.h> 713697Ssam #ifdef NDIR 813697Ssam #include "ndir.h" 913697Ssam #else 1013702Ssam #include <sys/dir.h> 1113697Ssam #endif 1217846Sralph #include <signal.h> 1313697Ssam 1418628Sralph #define BADCHARS "&^|(`\\<>;\"{}\n'" 1518628Sralph #define RECHECKTIME 60*10 /* 10 minutes */ 1617870Sralph 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; 3417846Sralph 3518628Sralph int TransferSucceeded = 1; 3613697Ssam int notiok = 1; 3713697Ssam int nonzero = 0; 3813697Ssam 3918628Sralph char PATH[MAXFULLNAME] = "PATH=/bin:/usr/bin:/usr/ucb"; 4018628Sralph char Shell[MAXFULLNAME]; 4118628Sralph char HOME[MAXFULLNAME]; 4217846Sralph 4318628Sralph extern char **environ; 4418628Sralph char *nenv[] = { 4518628Sralph PATH, 4618628Sralph Shell, 4718628Sralph HOME, 4818628Sralph 0 4918628Sralph }; 5017846Sralph 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; 7718628Sralph time_t xstart, xnow; 7813697Ssam char retstat[30]; 7918628Sralph char **ep; 8013697Ssam 8113697Ssam strcpy(Progname, "uuxqt"); 8213697Ssam uucpname(Myname); 8313697Ssam 8413697Ssam umask(WFMASK); 8513697Ssam Ofn = 1; 8613697Ssam Ifn = 0; 8713697Ssam while (argc>1 && argv[1][0] == '-') { 8813697Ssam switch(argv[1][1]){ 8913697Ssam case 'x': 9017846Sralph chkdebug(); 9113697Ssam Debug = atoi(&argv[1][2]); 9213697Ssam if (Debug <= 0) 9313697Ssam Debug = 1; 9413697Ssam break; 9513697Ssam default: 9613697Ssam fprintf(stderr, "unknown flag %s\n", argv[1]); 9713697Ssam break; 9813697Ssam } 9913697Ssam --argc; argv++; 10013697Ssam } 10113697Ssam 10218628Sralph DEBUG(4, "\n\n** START **\n", CNULL); 10317846Sralph ret = subchdir(Spool); 10417846Sralph ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret); 10513697Ssam strcpy(Wrkdir, Spool); 10613697Ssam uid = getuid(); 10713697Ssam guinfo(uid, User, path); 10817846Sralph setgid(getegid()); 10917846Sralph setuid(geteuid()); 11017846Sralph 11113697Ssam DEBUG(4, "User - %s\n", User); 112*23692Sbloom if (ulockf(X_LOCK, X_LOCKTIME) != 0) 11313697Ssam exit(0); 11413697Ssam 11513697Ssam fp = fopen(CMDFILE, "r"); 11613697Ssam if (fp == NULL) { 11717846Sralph logent(CANTOPEN, CMDFILE); 11813697Ssam Cmds[0] = "rmail"; 11913697Ssam Cmds[1] = "rnews"; 12013697Ssam Cmds[2] = "ruusend"; 12113697Ssam Cmds[3] = NULL; 12213697Ssam goto doprocess; 12313697Ssam } 12413697Ssam DEBUG(5, "%s opened\n", CMDFILE); 12517846Sralph for (i=0; i<NCMDS && cfgets(xcmd, sizeof(xcmd), fp) != NULL; i++) { 12617846Sralph int j; 12717846Sralph /* strip trailing whitespace */ 12817846Sralph for (j = strlen(xcmd)-1; j >= 0; --j) 12917846Sralph if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') 13017846Sralph xcmd[j] = '\0'; 13117846Sralph else 13217846Sralph break; 13317846Sralph /* look for imbedded whitespace */ 13417846Sralph for (; j >= 0; --j) 13517846Sralph if (xcmd[j] == '\n' || xcmd[j] == ' ' || xcmd[j] == '\t') 13617846Sralph break; 13717846Sralph /* skip this entry if it has embedded whitespace */ 13817846Sralph /* This defends against a bad PATH=, for example */ 13917846Sralph if (j >= 0) { 14017846Sralph logent(xcmd, "BAD WHITESPACE"); 14117846Sralph continue; 14217846Sralph } 14313697Ssam if (strncmp(xcmd, "PATH=", 5) == 0) { 14413697Ssam strcpy(PATH, xcmd); 14517846Sralph i--; /*kludge */ 14613697Ssam continue; 14713697Ssam } 14813697Ssam DEBUG(5, "xcmd = %s\n", xcmd); 14917846Sralph 15017846Sralph if ((ptr = index(xcmd, ',')) != NULL) { 15117846Sralph *ptr++ = '\0'; 15217846Sralph if (strncmp(ptr, "Err", 3) == SAME) 15317846Sralph Notify[i] = NT_ERR; 15417846Sralph else if (strcmp(ptr, "No") == SAME) 15517846Sralph Notify[i] = NT_NO; 15617846Sralph else 15717846Sralph Notify[i] = NT_YES; 15817846Sralph } else 15917846Sralph Notify[i] = NT_YES; 16017846Sralph if ((Cmds[i] = malloc((unsigned)(strlen(xcmd)+1))) == NULL) { 16117846Sralph DEBUG(1, "MALLOC FAILED", CNULL); 16217846Sralph break; 16317846Sralph } 16413697Ssam strcpy(Cmds[i], xcmd); 16513697Ssam } 16617846Sralph Cmds[i] = CNULL; 16713697Ssam fclose(fp); 16813697Ssam 16913697Ssam doprocess: 17018628Sralph 17118628Sralph (void) sprintf(HOME, "HOME=%s", Spool); 17218628Sralph (void) sprintf(Shell, "SHELL=%s", SHELL); 17318628Sralph environ = nenv; /* force use if our environment */ 17418628Sralph 17518628Sralph DEBUG(11,"path = %s\n", getenv("PATH")); 17618628Sralph 17717846Sralph DEBUG(4, "process %s\n", CNULL); 17818628Sralph time(&xstart); 17913697Ssam while (gtxfile(xfile) > 0) { 18017846Sralph ultouch(); 18117846Sralph /* if /etc/nologin exists, exit cleanly */ 18217846Sralph if (nologinflag) { 18317846Sralph logent(NOLOGIN, "UUXQT SHUTDOWN"); 18417846Sralph if (Debug) 18517846Sralph logent("debugging", "continuing anyway"); 18617846Sralph else 18717846Sralph break; 18817846Sralph } 18913697Ssam DEBUG(4, "xfile - %s\n", xfile); 19013697Ssam 19113697Ssam xfp = fopen(subfile(xfile), "r"); 19217846Sralph ASSERT(xfp != NULL, CANTOPEN, xfile, 0); 19313697Ssam 19413697Ssam /* initialize to default */ 19513697Ssam strcpy(user, User); 19617846Sralph strcpy(fin, DEVNULL); 19717846Sralph strcpy(fout, DEVNULL); 198*23692Sbloom strcpy(sysout, Myname); 19917846Sralph badfiles = 0; 20013697Ssam while (fgets(buf, BUFSIZ, xfp) != NULL) { 20113697Ssam switch (buf[0]) { 20213697Ssam case X_USER: 20317846Sralph sscanf(&buf[1], "%s %s", user, Rmtname); 20413697Ssam break; 20517846Sralph case X_RETURNTO: 20617846Sralph sscanf(&buf[1], "%s", user); 20717846Sralph break; 20813697Ssam case X_STDIN: 20913697Ssam sscanf(&buf[1], "%s", fin); 21013697Ssam i = expfile(fin); 21113697Ssam /* rti!trt: do not check permissions of 21213697Ssam * vanilla spool file */ 21313697Ssam if (i != 0 21413697Ssam && (chkpth("", "", fin) || anyread(fin) != 0)) 21513697Ssam badfiles = 1; 21613697Ssam break; 21713697Ssam case X_STDOUT: 21813697Ssam sscanf(&buf[1], "%s%s", fout, sysout); 219*23692Sbloom sysout[MAXBASENAME] = '\0'; 22013697Ssam /* rti!trt: do not check permissions of 22113697Ssam * vanilla spool file. DO check permissions 22213697Ssam * of writing on a non-vanilla file */ 22313697Ssam i = 1; 22413697Ssam if (fout[0] != '~' || prefix(sysout, Myname)) 22513697Ssam i = expfile(fout); 22613697Ssam if (i != 0 22713697Ssam && (chkpth("", "", fout) 22813697Ssam || chkperm(fout, (char *)1))) 22913697Ssam badfiles = 1; 23013697Ssam break; 23113697Ssam case X_CMD: 23213697Ssam strcpy(cmd, &buf[2]); 23313697Ssam if (*(cmd + strlen(cmd) - 1) == '\n') 23413697Ssam *(cmd + strlen(cmd) - 1) = '\0'; 23513697Ssam break; 23613697Ssam case X_NONOTI: 23713697Ssam notiok = 0; 23813697Ssam break; 23913697Ssam case X_NONZERO: 24013697Ssam nonzero = 1; 24113697Ssam break; 24213697Ssam default: 24313697Ssam break; 24413697Ssam } 24513697Ssam } 24613697Ssam 24713697Ssam fclose(xfp); 24813697Ssam DEBUG(4, "fin - %s, ", fin); 24913697Ssam DEBUG(4, "fout - %s, ", fout); 25013697Ssam DEBUG(4, "sysout - %s, ", sysout); 25113697Ssam DEBUG(4, "user - %s\n", user); 25213697Ssam DEBUG(4, "cmd - %s\n", cmd); 25313697Ssam 25413697Ssam /* command execution */ 25517846Sralph if (strcmp(fout, DEVNULL) == SAME) 25617846Sralph strcpy(dfile,DEVNULL); 25713697Ssam else 25813697Ssam gename(DATAPRE, sysout, 'O', dfile); 25913697Ssam 26013697Ssam /* expand file names where necessary */ 26113697Ssam expfile(dfile); 26218628Sralph cmdp = buf; 26313697Ssam ptr = cmd; 26413697Ssam xcmd[0] = '\0'; 26513697Ssam argnok = 0; 26613697Ssam while ((ptr = getprm(ptr, prm)) != NULL) { 26713697Ssam if (prm[0] == ';' || prm[0] == '^' 26813697Ssam || prm[0] == '&' || prm[0] == '|') { 26913697Ssam xcmd[0] = '\0'; 27013697Ssam APPCMD(prm); 27113697Ssam continue; 27213697Ssam } 27313697Ssam 27417846Sralph if ((argnok = argok(xcmd, prm)) != SUCCESS) 27513697Ssam /* command not valid */ 27613697Ssam break; 27713697Ssam 27813697Ssam if (prm[0] == '~') 27913697Ssam expfile(prm); 28013697Ssam APPCMD(prm); 28113697Ssam } 28217846Sralph /* 28317846Sralph * clean up trailing ' ' in command. 28417846Sralph */ 28517846Sralph if (cmdp > buf && cmdp[0] == '\0' && cmdp[-1] == ' ') 28617846Sralph *--cmdp = '\0'; 28718628Sralph if (strpbrk(user, BADCHARS) != NULL) { 28817870Sralph sprintf(lbuf, "%s INVALID CHARACTER IN USERNAME", user); 28917870Sralph logent(cmd, lbuf); 29017870Sralph strcpy(user, "postmaster"); 29117870Sralph } 29213697Ssam if (argnok || badfiles) { 29313697Ssam sprintf(lbuf, "%s XQT DENIED", user); 29413697Ssam logent(cmd, lbuf); 29513697Ssam DEBUG(4, "bad command %s\n", prm); 29613697Ssam notify(user, Rmtname, cmd, "DENIED"); 29713697Ssam goto rmfiles; 29813697Ssam } 29913697Ssam sprintf(lbuf, "%s XQT", user); 30013697Ssam logent(buf, lbuf); 30113697Ssam DEBUG(4, "cmd %s\n", buf); 30213697Ssam 30313697Ssam mvxfiles(xfile); 30417846Sralph ret = subchdir(XQTDIR); 30517846Sralph ASSERT(ret >= 0, "CHDIR FAILED", XQTDIR, ret); 30618628Sralph ret = shio(buf, fin, dfile); 30713697Ssam sprintf(retstat, "signal %d, exit %d", ret & 0377, 30813697Ssam (ret>>8) & 0377); 30913697Ssam if (strcmp(xcmd, "rmail") == SAME) 31013697Ssam notiok = 0; 31113697Ssam if (strcmp(xcmd, "rnews") == SAME) 31213697Ssam nonzero = 1; 31317846Sralph notiflg = chknotify(xcmd); 31417846Sralph if (notiok && notiflg != NT_NO && 31517846Sralph (ret != 0 || (!nonzero && notiflg == NT_YES))) 31613697Ssam notify(user, Rmtname, cmd, retstat); 31713697Ssam else if (ret != 0 && strcmp(xcmd, "rmail") == SAME) { 31813697Ssam /* mail failed - return letter to sender */ 31917846Sralph #ifdef DANGEROUS 32017846Sralph /* NOT GUARANTEED SAFE!!! */ 32117846Sralph if (!nonzero) 32217846Sralph retosndr(user, Rmtname, fin); 32317846Sralph #else 32417846Sralph notify(user, Rmtname, cmd, retstat); 32517846Sralph #endif 32617846Sralph sprintf(buf, "%s (%s) from %s!%s", buf, retstat, Rmtname, user); 32713697Ssam logent("MAIL FAIL", buf); 32813697Ssam } 32913697Ssam DEBUG(4, "exit cmd - %d\n", ret); 33017846Sralph ret2 = subchdir(Spool); 33117846Sralph ASSERT(ret2 >= 0, "CHDIR FAILED", Spool, ret); 33213697Ssam rmxfiles(xfile); 33313697Ssam if (ret != 0) { 33413697Ssam /* exit status not zero */ 33513697Ssam dfp = fopen(subfile(dfile), "a"); 33617846Sralph ASSERT(dfp != NULL, CANTOPEN, dfile, 0); 33713697Ssam fprintf(dfp, "exit status %d", ret); 33813697Ssam fclose(dfp); 33913697Ssam } 34017846Sralph if (strcmp(fout, DEVNULL) != SAME) { 34113697Ssam if (prefix(sysout, Myname)) { 34213697Ssam xmv(dfile, fout); 34313697Ssam chmod(fout, BASEMODE); 34418628Sralph } else { 34517846Sralph char *cp = rindex(user, '!'); 34613697Ssam gename(CMDPRE, sysout, 'O', cfile); 34713697Ssam fp = fopen(subfile(cfile), "w"); 34813697Ssam ASSERT(fp != NULL, "OPEN", cfile, 0); 34917846Sralph fprintf(fp, "S %s %s %s - %s 0666\n", dfile, 35017846Sralph fout, cp ? cp : user, lastpart(dfile)); 35113697Ssam fclose(fp); 35213697Ssam } 35313697Ssam } 35413697Ssam rmfiles: 35513697Ssam xfp = fopen(subfile(xfile), "r"); 35617846Sralph ASSERT(xfp != NULL, CANTOPEN, xfile, 0); 35713697Ssam while (fgets(buf, BUFSIZ, xfp) != NULL) { 35813697Ssam if (buf[0] != X_RQDFILE) 35913697Ssam continue; 36013697Ssam sscanf(&buf[1], "%s", file); 36113697Ssam unlink(subfile(file)); 36213697Ssam } 36313697Ssam unlink(subfile(xfile)); 36413697Ssam fclose(xfp); 36518628Sralph 36618628Sralph /* rescan X. for new work every RECHECKTIME seconds */ 36718628Sralph time(&xnow); 36818628Sralph if (xnow > (xstart + RECHECKTIME)) { 36918628Sralph extern int Nfiles; 37018628Sralph Nfiles = 0; /*force rescan for new work */ 37118628Sralph } 37218628Sralph xstart = xnow; 37313697Ssam } 37413697Ssam 37513697Ssam if (stcico) 37613697Ssam xuucico(""); 37713697Ssam cleanup(0); 37813697Ssam } 37913697Ssam 38013697Ssam 38113697Ssam cleanup(code) 38213697Ssam int code; 38313697Ssam { 38413697Ssam logcls(); 38513697Ssam rmlock(CNULL); 38617846Sralph #ifdef VMS 38717846Sralph /* 38817846Sralph * Since we run as a BATCH job we must wait for all processes to 38917846Sralph * to finish 39017846Sralph */ 39118628Sralph while(wait(0) != -1) 39218628Sralph ; 39317846Sralph #endif VMS 39413697Ssam exit(code); 39513697Ssam } 39613697Ssam 39713697Ssam 39818628Sralph /* 39918628Sralph * get a file to execute 40013697Ssam * 40113697Ssam * return codes: 0 - no file | 1 - file to execute 40213697Ssam */ 40313697Ssam 40413697Ssam gtxfile(file) 40513697Ssam register char *file; 40613697Ssam { 40713697Ssam char pre[3]; 40817846Sralph int rechecked; 40917846Sralph time_t ystrdy; /* yesterday */ 41017846Sralph struct stat stbuf; /* for X file age */ 41113697Ssam 41213697Ssam pre[0] = XQTPRE; 41313697Ssam pre[1] = '.'; 41413697Ssam pre[2] = '\0'; 41513697Ssam rechecked = 0; 41613697Ssam retry: 41713697Ssam if (!gtwrkf(Spool, file)) { 41813697Ssam if (rechecked) 41917846Sralph return 0; 42013697Ssam rechecked = 1; 42117846Sralph DEBUG(4, "iswrk\n", CNULL); 42213697Ssam if (!iswrk(file, "get", Spool, pre)) 42317846Sralph return 0; 42413697Ssam } 42513697Ssam DEBUG(4, "file - %s\n", file); 42613697Ssam /* skip spurious subdirectories */ 42713697Ssam if (strcmp(pre, file) == SAME) 42813697Ssam goto retry; 42913697Ssam if (gotfiles(file)) 43017846Sralph return 1; 43117846Sralph /* check for old X. file with no work files and remove them. */ 43217846Sralph if (Nfiles > LLEN/2) { 43317846Sralph time(&ystrdy); 43417846Sralph ystrdy -= (4 * 3600L); /* 4 hours ago */ 43517846Sralph DEBUG(4, "gtxfile: Nfiles > LLEN/2\n", CNULL); 43617846Sralph while (gtwrkf(Spool, file) && !gotfiles(file)) { 43717846Sralph if (stat(subfile(file), &stbuf) == 0) 43817846Sralph if (stbuf.st_mtime <= ystrdy) { 43917846Sralph char *bnp, cfilename[NAMESIZE]; 44017846Sralph DEBUG(4, "gtxfile: move %s to CORRUPT \n", file); 44117846Sralph unlink(subfile(file)); 44217846Sralph bnp = rindex(subfile(file), '/'); 44317846Sralph sprintf(cfilename, "%s/%s", CORRUPT, 44417846Sralph bnp ? bnp + 1 : subfile(file)); 44517846Sralph xmv(subfile(file), cfilename); 44617846Sralph logent(file, "X. FILE CORRUPTED"); 44717846Sralph } 44817846Sralph } 44917846Sralph DEBUG(4, "iswrk\n", CNULL); 45017846Sralph if (!iswrk(file, "get", Spool, pre)) 45117846Sralph return 0; 45217846Sralph } 45313697Ssam goto retry; 45413697Ssam } 45513697Ssam 45618628Sralph /* 45718628Sralph * check for needed files 45813697Ssam * 45913697Ssam * return codes: 0 - not ready | 1 - all files ready 46013697Ssam */ 46113697Ssam 46213697Ssam gotfiles(file) 46313697Ssam register char *file; 46413697Ssam { 46513697Ssam struct stat stbuf; 46613697Ssam register FILE *fp; 46713697Ssam char buf[BUFSIZ], rqfile[MAXFULLNAME]; 46813697Ssam 46913697Ssam fp = fopen(subfile(file), "r"); 47013697Ssam if (fp == NULL) 47117846Sralph return 0; 47213697Ssam 47313697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 47413697Ssam DEBUG(4, "%s\n", buf); 47513697Ssam if (buf[0] != X_RQDFILE) 47613697Ssam continue; 47713697Ssam sscanf(&buf[1], "%s", rqfile); 47813697Ssam expfile(rqfile); 47913697Ssam if (stat(subfile(rqfile), &stbuf) == -1) { 48013697Ssam fclose(fp); 48117846Sralph return 0; 48213697Ssam } 48313697Ssam } 48413697Ssam 48513697Ssam fclose(fp); 48617846Sralph return 1; 48713697Ssam } 48813697Ssam 48913697Ssam 49018628Sralph /* 49118628Sralph * remove execute files to x-directory 49213697Ssam */ 49313697Ssam 49413697Ssam rmxfiles(xfile) 49513697Ssam register char *xfile; 49613697Ssam { 49713697Ssam register FILE *fp; 49813697Ssam char buf[BUFSIZ], file[NAMESIZE], tfile[NAMESIZE]; 49913697Ssam char tfull[MAXFULLNAME]; 50013697Ssam 50113697Ssam if((fp = fopen(subfile(xfile), "r")) == NULL) 50213697Ssam return; 50313697Ssam 50413697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 50513697Ssam if (buf[0] != X_RQDFILE) 50613697Ssam continue; 50713697Ssam if (sscanf(&buf[1], "%s%s", file, tfile) < 2) 50813697Ssam continue; 50913697Ssam sprintf(tfull, "%s/%s", XQTDIR, tfile); 51013697Ssam unlink(subfile(tfull)); 51113697Ssam } 51213697Ssam fclose(fp); 51313697Ssam return; 51413697Ssam } 51513697Ssam 51613697Ssam 51718628Sralph /* 51818628Sralph * move execute files to x-directory 51913697Ssam */ 52013697Ssam 52113697Ssam mvxfiles(xfile) 52213697Ssam char *xfile; 52313697Ssam { 52413697Ssam register FILE *fp; 52513697Ssam char buf[BUFSIZ], ffile[MAXFULLNAME], tfile[NAMESIZE]; 52613697Ssam char tfull[MAXFULLNAME]; 52713697Ssam int ret; 52813697Ssam 52913697Ssam if((fp = fopen(subfile(xfile), "r")) == NULL) 53013697Ssam return; 53113697Ssam 53213697Ssam while (fgets(buf, BUFSIZ, fp) != NULL) { 53313697Ssam if (buf[0] != X_RQDFILE) 53413697Ssam continue; 53513697Ssam if (sscanf(&buf[1], "%s%s", ffile, tfile) < 2) 53613697Ssam continue; 53713697Ssam expfile(ffile); 53813697Ssam sprintf(tfull, "%s/%s", XQTDIR, tfile); 53913697Ssam unlink(subfile(tfull)); 54013697Ssam ret = xmv(ffile, tfull); 54117846Sralph ASSERT(ret == 0, "XQTDIR ERROR", CNULL, ret); 54213697Ssam } 54313697Ssam fclose(fp); 54413697Ssam } 54513697Ssam 54618628Sralph /* 54718628Sralph * check for valid command/argument 54818628Sralph * *NOTE - side effect is to set xc to the command to be executed. 54913697Ssam * 55013697Ssam * return 0 - ok | 1 nok 55113697Ssam */ 55213697Ssam 55313697Ssam argok(xc, cmd) 55413697Ssam register char *xc, *cmd; 55513697Ssam { 55613697Ssam register char **ptr; 55713697Ssam 55813697Ssam #ifndef ALLOK 55918628Sralph if (strpbrk(cmd, BADCHARS) != NULL) { 56017846Sralph DEBUG(1,"MAGIC CHARACTER FOUND\n", CNULL); 56118628Sralph logent(cmd, "NASTY MAGIC CHARACTER FOUND"); 56217846Sralph return FAIL; 56317846Sralph } 56417846Sralph #endif !ALLOK 56513697Ssam 56613697Ssam if (xc[0] != '\0') 56717846Sralph return SUCCESS; 56813697Ssam 56913697Ssam #ifndef ALLOK 57013697Ssam ptr = Cmds; 57117846Sralph DEBUG(9, "Compare %s and\n", cmd); 57213697Ssam while(*ptr != NULL) { 57317846Sralph DEBUG(9, "\t%s\n", *ptr); 57413697Ssam if (strcmp(cmd, *ptr) == SAME) 57513697Ssam break; 57617846Sralph ptr++; 57713697Ssam } 57817846Sralph if (*ptr == NULL) { 57917846Sralph DEBUG(1,"COMMAND NOT FOUND\n", CNULL); 58017846Sralph return FAIL; 58117846Sralph } 58213697Ssam #endif 58313697Ssam strcpy(xc, cmd); 58417846Sralph DEBUG(9, "MATCHED %s\n", xc); 58517846Sralph return SUCCESS; 58613697Ssam } 58713697Ssam 58813697Ssam 58918628Sralph /* 59018628Sralph * if notification should be sent for successful execution of cmd 59117846Sralph * 59217846Sralph * return NT_YES - do notification 59317846Sralph * NT_ERR - do notification if exit status != 0 59417846Sralph * NT_NO - don't do notification ever 59517846Sralph */ 59617846Sralph 59717846Sralph chknotify(cmd) 59817846Sralph char *cmd; 59917846Sralph { 60017846Sralph register char **ptr; 60117846Sralph register int *nptr; 60217846Sralph 60317846Sralph ptr = Cmds; 60417846Sralph nptr = Notify; 60517846Sralph while (*ptr != NULL) { 60617846Sralph if (strcmp(cmd, *ptr) == SAME) 60717846Sralph return *nptr; 60817846Sralph ptr++; 60917846Sralph nptr++; 61017846Sralph } 61117846Sralph return NT_YES; /* "shouldn't happen" */ 61217846Sralph } 61317846Sralph 61417846Sralph 61517846Sralph 61618628Sralph /* 61718628Sralph * send mail to user giving execution results 61813697Ssam */ 61913697Ssam 62013697Ssam notify(user, rmt, cmd, str) 62113697Ssam char *user, *rmt, *cmd, *str; 62213697Ssam { 62313697Ssam char text[MAXFULLNAME]; 62413697Ssam char ruser[MAXFULLNAME]; 62513697Ssam 62617846Sralph sprintf(text, "uuxqt cmd (%s) status (%s)", cmd, str); 62713697Ssam if (prefix(rmt, Myname)) 62813697Ssam strcpy(ruser, user); 62913697Ssam else 63013697Ssam sprintf(ruser, "%s!%s", rmt, user); 63117846Sralph mailst(ruser, text, CNULL); 63213697Ssam return; 63313697Ssam } 63413697Ssam 63518628Sralph /* 63618628Sralph * return mail to sender 63713697Ssam * 63813697Ssam */ 63913697Ssam 64013697Ssam retosndr(user, rmt, file) 64113697Ssam char *user, *rmt, *file; 64213697Ssam { 64317846Sralph char ruser[MAXFULLNAME]; 64413697Ssam 64513697Ssam if (strcmp(rmt, Myname) == SAME) 64613697Ssam strcpy(ruser, user); 64713697Ssam else 64813697Ssam sprintf(ruser, "%s!%s", rmt, user); 64913697Ssam 65013697Ssam if (anyread(file) == 0) 65113697Ssam mailst(ruser, "Mail failed. Letter returned to sender.\n", file); 65213697Ssam else 65317846Sralph mailst(ruser, "Mail failed. Letter returned to sender.\n", CNULL); 65413697Ssam return; 65513697Ssam } 65617870Sralph 65717870Sralph /* 65818628Sralph * execute shell of command with fi and fo as standard input/output 65918628Sralph */ 66018628Sralph 66118628Sralph shio(cmd, fi, fo) 66218628Sralph char *cmd, *fi, *fo; 66318628Sralph { 66418628Sralph int status, f; 66518628Sralph int uid, pid, ret; 66618628Sralph char path[MAXFULLNAME]; 66718628Sralph char *args[20]; 66818628Sralph extern int errno; 66918628Sralph 67018628Sralph if (fi == NULL) 67118628Sralph fi = DEVNULL; 67218628Sralph if (fo == NULL) 67318628Sralph fo = DEVNULL; 67418628Sralph 67518628Sralph getargs(cmd, args, 20); 67618628Sralph DEBUG(3, "shio - %s\n", cmd); 67718628Sralph #ifdef SIGCHLD 67818628Sralph signal(SIGCHLD, SIG_IGN); 67918628Sralph #endif SIGCHLD 68018628Sralph if ((pid = fork()) == 0) { 68118628Sralph signal(SIGINT, SIG_IGN); 68218628Sralph signal(SIGHUP, SIG_IGN); 68318628Sralph signal(SIGQUIT, SIG_IGN); 68418628Sralph signal(SIGKILL, SIG_IGN); 68518628Sralph close(Ifn); 68618628Sralph close(Ofn); 68718628Sralph close(0); 68818628Sralph setuid(getuid()); 68918628Sralph f = open(subfile(fi), 0); 69018628Sralph if (f != 0) { 69118628Sralph logent(fi, "CAN'T READ"); 69218628Sralph exit(-errno); 69318628Sralph } 69418628Sralph close(1); 69518628Sralph f = creat(subfile(fo), 0666); 69618628Sralph if (f != 1) { 69718628Sralph logent(fo, "CAN'T WRITE"); 69818628Sralph exit(-errno); 69918628Sralph } 70018628Sralph execvp(args[0], args); 70118628Sralph exit(100+errno); 70218628Sralph } 70318628Sralph while ((ret = wait(&status)) != pid && ret != -1) 70418628Sralph ; 70518628Sralph DEBUG(3, "status %d\n", status); 70618628Sralph return status; 70718628Sralph } 708