1: #include "uucp.h" 2: #include "uucpdefs.h" 3: #include <sys/types.h> 4: #include <sys/stat.h> 5: #include <sys/dir.h> 6: 7: #define APPCMD(d) {\ 8: char *p;\ 9: for (p = d; *p != '\0';) *cmdp++ = *p++;\ 10: *cmdp++ = ' ';\ 11: *cmdp = '\0';} 12: 13: /* 14: * uuxqt will execute commands set up by a uux command, 15: * usually from a remote machine - set by uucp. 16: */ 17: 18: char *Cmds[] = { 19: "mail", 20: "rmail", 21: "lpr", 22: "opr", 23: "fsend", 24: "fget", 25: NULL 26: }; 27: #define CMDOK(a, b) cmdok(a,b) 28: #define PATH "PATH=/bin:/usr/bin;" 29: /* to remove restrictions from uuxqt 30: * redefine CMDOK 0 31: * 32: * to add allowable commands, add to the list under Cmds[] 33: */ 34: 35: main(argc, argv) 36: char *argv[]; 37: { 38: char xcmd[100]; 39: int cmdnok; 40: char xfile[MAXFULLNAME], user[10], buf[BUFSIZ]; 41: char lbuf[30]; 42: char cfile[NAMESIZE], dfile[MAXFULLNAME]; 43: char file[NAMESIZE]; 44: char fin[MAXFULLNAME], sysout[NAMESIZE], fout[MAXFULLNAME]; 45: FILE *xfp, *dfp, *fp; 46: char path[MAXFULLNAME]; 47: char cmd[BUFSIZ]; 48: char *cmdp, prm[MAXFULLNAME], *ptr; 49: char *getprm(); 50: int uid, ret; 51: int stcico = 0; 52: Debug = 0; 53: Ofn = 1; 54: Ifn = 0; 55: while (argc>1 && argv[1][0] == '-') { 56: switch(argv[1][1]){ 57: case 'x': 58: Debug = atoi(&argv[1][2]); 59: if (Debug <= 0) 60: Debug = 1; 61: break; 62: default: 63: sprintf(stderr, "unknown flag %s\n", argv[1]); 64: break; 65: } 66: --argc; argv++; 67: } 68: 69: DEBUG(4, "\n\n** %s **\n", "START"); 70: chdir(Spool); 71: strcpy(Wrkdir, Spool); 72: uid = getuid(); 73: guinfo(uid, User, path); 74: DEBUG(4, "User - %s\n", User); 75: if (ulockf(X_LOCK, X_LOCKTIME) != 0) 76: exit(0); 77: 78: DEBUG(4, "process %s\n", ""); 79: while (gtxfile(xfile) > 0) { 80: DEBUG(4, "xfile - %s\n", xfile); 81: 82: xfp = fopen(xfile, "r"); 83: ASSERT(xfp != NULL, "CAN'T OPEN %s", xfile); 84: 85: /* initialize to default */ 86: strcpy(user, User); 87: strcpy(fin, "/dev/null"); 88: strcpy(fout, "/dev/null"); 89: sprintf(sysout, "%.7s", Myname); 90: while (fgets(buf, BUFSIZ, xfp) != NULL) { 91: switch (buf[0]) { 92: case X_USER: 93: sscanf(&buf[1], "%s%s", user, Rmtname); 94: break; 95: case X_STDIN: 96: sscanf(&buf[1], "%s", fin); 97: expfile(fin); 98: break; 99: case X_STDOUT: 100: sscanf(&buf[1], "%s%s", fout, sysout); 101: sysout[7] = '\0'; 102: if (fout[0] != '~' || prefix(sysout, Myname)) 103: expfile(fout); 104: break; 105: case X_CMD: 106: strcpy(cmd, &buf[2]); 107: if (*(cmd + strlen(cmd) - 1) == '\n') 108: *(cmd + strlen(cmd) - 1) = '\0'; 109: break; 110: default: 111: break; 112: } 113: } 114: 115: fclose(xfp); 116: DEBUG(4, "fin - %s, ", fin); 117: DEBUG(4, "fout - %s, ", fout); 118: DEBUG(4, "sysout - %s, ", sysout); 119: DEBUG(4, "user - %s\n", user); 120: DEBUG(4, "cmd - %s\n", cmd); 121: 122: /* command execution */ 123: if (strcmp(fout, "/dev/null") == SAME) 124: strcpy(dfile,"/dev/null"); 125: else 126: gename(DATAPRE, sysout, 'O', dfile); 127: 128: /* expand file names where necessary */ 129: expfile(dfile); 130: strcpy(buf, PATH); 131: cmdp = buf + strlen(buf); 132: ptr = cmd; 133: xcmd[0] = '\0'; 134: cmdnok = 0; 135: while ((ptr = getprm(ptr, prm)) != NULL) { 136: if (prm[0] == ';' || prm[0] == '^' 137: || prm[0] == '|') { 138: xcmd[0] = '\0'; 139: APPCMD(prm); 140: continue; 141: } 142: if ((cmdnok = CMDOK(xcmd, prm)) != 0) 143: /* command not valid */ 144: break; 145: 146: if (prm[0] == '~') 147: expfile(prm); 148: APPCMD(prm); 149: } 150: if (cmdnok) { 151: sprintf(lbuf, "%s XQT DENIED", user); 152: logent(cmd, lbuf); 153: DEBUG(4, "bad command %s\n", prm); 154: goto rmfiles; 155: } 156: sprintf(lbuf, "%s XQT", user); 157: logent(buf, lbuf); 158: DEBUG(4, "cmd %s\n", buf); 159: 160: mvxfiles(xfile); 161: chdir(XQTDIR); 162: ret = shio(buf, fin, dfile, user); 163: DEBUG(4, "exit cmd - %d\n", ret); 164: chdir(Spool); 165: rmxfiles(xfile); 166: if (ret != 0) { 167: /* exit status not zero */ 168: dfp = fopen(dfile, "a"); 169: ASSERT(dfp != NULL, "CAN'T OPEN %s", dfile); 170: fprintf(dfp, "exit status %d", ret); 171: fclose(dfp); 172: } 173: if (strcmp(fout, "/dev/null") != SAME) { 174: if (prefix(sysout, Myname)) { 175: xmv(dfile, fout); 176: } 177: else { 178: gename(CMDPRE, sysout, 'O', cfile); 179: fp = fopen(cfile, "w"); 180: ASSERT(fp != NULL, "OPEN %s", cfile); 181: chmod(cfile, 0666); 182: fprintf(fp, "S %s %s %s - %s 0666\n", 183: dfile, fout, user, lastpart(dfile)); 184: fclose(fp); 185: } 186: } 187: rmfiles: 188: xfp = fopen(xfile, "r"); 189: ASSERT(xfp != NULL, "CAN'T OPEN %s", xfile); 190: while (fgets(buf, BUFSIZ, xfp) != NULL) { 191: if (buf[0] != X_RQDFILE) 192: continue; 193: sscanf(&buf[1], "%s", file); 194: unlink(file); 195: } 196: unlink(xfile); 197: } 198: 199: if (stcico) 200: xuucico(""); 201: cleanup(0); 202: } 203: 204: 205: cleanup(code) 206: int code; 207: { 208: logcls(); 209: rmlock(NULL); 210: exit(code); 211: } 212: 213: 214: /******* 215: * gtxfile(file) get a file to execute 216: * char *file; 217: * 218: * return codes: 0 - no file | 1 - file to execute 219: */ 220: 221: gtxfile(file) 222: char *file; 223: { 224: static FILE *pdir; 225: char pre[2]; 226: 227: if (pdir == NULL) { 228: pdir = fopen(Spool, "r"); 229: ASSERT(pdir != NULL, "GTXFILE CAN'T OPEN %s", Spool); 230: } 231: 232: pre[0] = XQTPRE; 233: pre[1] = '\0'; 234: while (gnamef(pdir, file) != 0) { 235: DEBUG(4, "file - %s\n", file); 236: if (!prefix(pre, file)) 237: continue; 238: if (gotfiles(file)) 239: /* return file to execute */ 240: return(1); 241: } 242: 243: fclose(pdir); 244: return(0); 245: } 246: 247: 248: /*** 249: * gotfiles(file) check for needed files 250: * char *file; 251: * 252: * return codes: 0 - not ready | 1 - all files ready 253: */ 254: 255: gotfiles(file) 256: char *file; 257: { 258: struct stat stbuf; 259: FILE *fp; 260: char buf[BUFSIZ], rqfile[MAXFULLNAME]; 261: 262: fp = fopen(file, "r"); 263: if (fp == NULL) 264: return(0); 265: 266: while (fgets(buf, BUFSIZ, fp) != NULL) { 267: DEBUG(4, "%s\n", buf); 268: if (buf[0] != X_RQDFILE) 269: continue; 270: sscanf(&buf[1], "%s", rqfile); 271: expfile(rqfile); 272: if (stat(rqfile, &stbuf) == -1) { 273: fclose(fp); 274: return(0); 275: } 276: } 277: 278: fclose(fp); 279: return(1); 280: } 281: 282: 283: /*** 284: * rmxfiles(xfile) remove execute files to x-directory 285: * char *xfile; 286: * 287: * return codes - none 288: */ 289: 290: rmxfiles(xfile) 291: char *xfile; 292: { 293: FILE *fp; 294: char buf[BUFSIZ], file[NAMESIZE], tfile[NAMESIZE]; 295: char tfull[MAXFULLNAME]; 296: 297: if((fp = fopen(xfile, "r")) == NULL) 298: return; 299: 300: while (fgets(buf, BUFSIZ, fp) != NULL) { 301: if (buf[0] != X_RQDFILE) 302: continue; 303: if (sscanf(&buf[1], "%s%s", file, tfile) < 2) 304: continue; 305: sprintf(tfull, "%s/%s", XQTDIR, tfile); 306: unlink(tfull); 307: } 308: fclose(fp); 309: return; 310: } 311: 312: 313: /*** 314: * mvxfiles(xfile) move execute files to x-directory 315: * char *xfile; 316: * 317: * return codes - none 318: */ 319: 320: mvxfiles(xfile) 321: char *xfile; 322: { 323: FILE *fp; 324: char buf[BUFSIZ], ffile[MAXFULLNAME], tfile[NAMESIZE]; 325: char tfull[MAXFULLNAME]; 326: int ret; 327: 328: if((fp = fopen(xfile, "r")) == NULL) 329: return; 330: 331: while (fgets(buf, BUFSIZ, fp) != NULL) { 332: if (buf[0] != X_RQDFILE) 333: continue; 334: if (sscanf(&buf[1], "%s%s", ffile, tfile) < 2) 335: continue; 336: expfile(ffile); 337: sprintf(tfull, "%s/%s", XQTDIR, tfile); 338: unlink(tfull); 339: ret = link(ffile, tfull); 340: ASSERT(ret == 0, "LINK RET-%d", ret); 341: unlink(ffile); 342: } 343: fclose(fp); 344: return; 345: } 346: 347: 348: /*** 349: * cmdok(xc, cmd) check for valid command 350: * char *xc, *cmd; 351: * 352: * return 0 - ok | 1 nok 353: */ 354: 355: cmdok(xc, cmd) 356: char *xc, *cmd; 357: { 358: char **ptr; 359: 360: if (xc[0] != '\0') 361: return(0); 362: ptr = Cmds; 363: while(*ptr != NULL) { 364: DEBUG(4, "cmd %s, ", cmd); 365: DEBUG(4, "ptr %s\n", *ptr); 366: if (strcmp(cmd, *ptr) == SAME) 367: break; 368: ptr++; 369: } 370: if (*ptr == NULL) 371: return(1); 372: strcpy(xc, cmd); 373: return(0); 374: }