|
|
1.1 ! root 1: /* ! 2: * $Header: /newbits/usr/bin/uucpstuff/dcp/RCS/dcpxf2.c,v 1.7 92/11/20 14:40:16 bin Exp Locker: bin $ ! 3: * $Log: dcpxf2.c,v $ ! 4: * Revision 1.7 92/11/20 14:40:16 bin ! 5: * bob h: restricted permissions, cleanup problems with ports not closing and ! 6: * parsing of CLINE when permissions field is not used. ! 7: * ! 8: * Revision 1.6 92/07/10 08:46:17 bin ! 9: * bob h: fixed placement of an endif _I386 ! 10: * ! 11: * Revision 1.5 92/07/02 12:57:55 bin ! 12: * make missing spool directory when we begin receiving files and ! 13: * have already determined that proper permissions exist. ! 14: * ! 15: * Revision 1.4 91/08/15 13:24:56 bin ! 16: * changes by epstein for 7bit sites ! 17: * ! 18: * Revision 1.6 90/03/29 10:54:13 wgl ! 19: * Add check of the -d option and fail to create directory if option absent. ! 20: * ! 21: * Revision 1.5 90/03/26 13:45:37 wgl ! 22: * Add routine 'rebuildfn' to rebuild file name as needed on receive. ! 23: * ! 24: * Revision 1.4 90/03/23 09:30:39 wgl ! 25: * Add routines for cheking read and write permissions. ! 26: * ! 27: * Revision 1.3 90/03/22 12:11:08 wgl ! 28: * Add 'canwrite'. ! 29: * ! 30: * Revision 1.2 90/03/22 08:59:23 wgl ! 31: * Fixed error in from/to file reporting in status mail message. ! 32: * ! 33: */ ! 34: ! 35: #include "dcp.h" ! 36: #include <signal.h> ! 37: #include <ctype.h> ! 38: #include <sys/timeb.h> ! 39: #include <sys/stat.h> ! 40: #include <access.h> ! 41: #include <pwd.h> ! 42: #include "perm.h" ! 43: ! 44: static char uuxbuf [64]; ! 45: static char allowed [80]; ! 46: static char disallowed[80]; ! 47: static char *successmsg [2] = { ! 48: "FAILED", ! 49: "Successfully" ! 50: }; ! 51: ! 52: static char tmpfilename[BUFSIZ]; /* Holds the converted file name */ ! 53: extern char reason[]; ! 54: extern char *strtok(); ! 55: ! 56: notifystatus(fromfilep, xtofile, sending, success, cdotctl) ! 57: char *fromfilep, *xtofile; ! 58: int success, cdotctl, sending; ! 59: { ! 60: if (cdotctl) { ! 61: if (index(optionp, 'm') != NULL) ! 62: l3statmail(fromfilep, xtofile, sending, success); ! 63: } else { ! 64: if (index(optionp, 'n') != NULL) ! 65: notify2mail(fromfilep, xtofile, success); ! 66: } ! 67: } ! 68: ! 69: l3statmail(from, to, sending, success) ! 70: char *from; ! 71: char *to; ! 72: int sending; ! 73: int success; ! 74: { ! 75: FILE *fmp; ! 76: ! 77: (void) signal(SIGPIPE, SIG_IGN); ! 78: sprintf(uuxbuf, "mail -auucp %s", usernamep); ! 79: plog(M_TRANSFER, "Posting local status mail to user \"%s\"", usernamep); ! 80: if ((fmp = popen(uuxbuf, "w")) == NULL) ! 81: plog(M_TRANSFER, "Cannot send status mail"); ! 82: else { ! 83: static char *succp; ! 84: fprintf(fmp, "From: UUCP V%s\n", version); ! 85: fprintf(fmp, "Subject: UUCP file transfer status\n\n"); ! 86: succp = successmsg [success]; ! 87: if (sending) { ! 88: fprintf (fmp, "Sent file:\t%s\n", from); ! 89: fprintf (fmp, " to:\t%s!%s\n%s\n", ! 90: rmtname, to, succp); ! 91: } else { ! 92: fprintf (fmp,"Received file:\t%s\n", to); ! 93: fprintf (fmp, " from:\t%s!%s\n%s\n", ! 94: rmtname, from, succp); ! 95: } ! 96: if (!success) ! 97: fprintf(fmp, "Reason: %s\n", reason); ! 98: if (pclose(fmp) != 0) ! 99: plog(M_TRANSFER, "Status mail failed."); ! 100: } ! 101: } ! 102: ! 103: notify2mail(from, to, success) ! 104: char *from; ! 105: char *to; ! 106: int success; ! 107: { ! 108: FILE *fmp; ! 109: int status; ! 110: ! 111: (void) signal(SIGPIPE, SIG_IGN); ! 112: sprintf(uuxbuf, "mail -auucp %s", notifyp); ! 113: plog(M_TRANSFER, "Notifying user \"%s\".", notifyp); ! 114: if ((fmp = popen(uuxbuf, "w")) == NULL) ! 115: plog(M_TRANSFER, "Cannot send notify mail (popen)"); ! 116: else { ! 117: fprintf(fmp, "From: UUCP V%s\n", version); ! 118: fprintf(fmp, "\nThe file:\t%s\nReceived from:\t%s!%s\n", ! 119: to, rmtname, from); ! 120: fprintf(fmp, "%s\n", successmsg [success]); ! 121: if (!success) ! 122: fprintf(fmp, "Reason: %s\n", reason); ! 123: if ((status = pclose(fmp)) != 0) { ! 124: plog(M_TRANSFER, ! 125: "Notify mail fails (pclose), code %d", status); ! 126: } ! 127: } ! 128: } ! 129: ! 130: getoct(s) ! 131: char *s; ! 132: { ! 133: char *cp; ! 134: char c; ! 135: int n; ! 136: ! 137: cp = s; ! 138: n = 0; ! 139: while ((c = *cp) != '\0') { ! 140: n = (n * 8) + *cp++ -'0'; ! 141: } ! 142: return n; ! 143: } ! 144: ! 145: int ! 146: cantsend() ! 147: { ! 148: plog(M_TRANSFER, "Cannot send packet"); ! 149: printmsg(M_TRANSFER, "Cannot send packet (cantsend)"); ! 150: terminatelevel++; ! 151: return 'Y'; ! 152: } ! 153: ! 154: int ! 155: cantread() ! 156: { ! 157: plog(M_TRANSFER, "Cannot read packet"); ! 158: printmsg(M_TRANSFER, "Cannot read packet (cantread)"); ! 159: terminatelevel++; ! 160: return 'Y'; ! 161: } ! 162: ! 163: int ! 164: canwrite(fn) ! 165: char *fn; ! 166: { ! 167: static dirname [120]; ! 168: struct stat statbuf; ! 169: char *cp; ! 170: ! 171: strcpy(dirname, fn); ! 172: if ((cp = rindex(dirname, '/')) != NULL) { ! 173: *cp = '\0'; ! 174: if (index(optionp, 'd') != NULL) { ! 175: if (!ckdir(dirname)) { ! 176: plog(M_SPOOL, "unable to create directory %s", ! 177: dirname); ! 178: return 0; ! 179: } ! 180: } ! 181: } ! 182: if (stat(fn, &statbuf) == -1) ! 183: return 1; ! 184: if (access(fn, 0) == 0) ! 185: return 1; ! 186: return 0; ! 187: } ! 188: ! 189: perm_write(fn) ! 190: char *fn; ! 191: { ! 192: strcpy(allowed, perm_value(write_e)); ! 193: strcpy(disallowed, perm_value(nowrite_e)); ! 194: return allowed_or_not(fn); ! 195: } ! 196: ! 197: perm_read(fn) ! 198: char *fn; ! 199: { ! 200: strcpy(allowed, perm_value(read_e)); ! 201: strcpy(disallowed, perm_value(noread_e)); ! 202: return allowed_or_not(fn); ! 203: } ! 204: ! 205: static int ! 206: allowed_or_not(fn) ! 207: char *fn; ! 208: { ! 209: char *sp, *cp; ! 210: ! 211: strcat(allowed, ":/usr/spool/uucp"); ! 212: sp = disallowed; ! 213: while ((cp = strtok(sp, ":")) != NULL) { ! 214: sp = NULL; ! 215: if (strncmp(fn, cp, strlen(cp)) == 0) ! 216: return 0; ! 217: } ! 218: sp = allowed; ! 219: while ((cp = strtok(sp, ":")) != NULL) { ! 220: sp = NULL; ! 221: if (strncmp(fn, cp, strlen(cp)) == 0) ! 222: return 1; ! 223: } ! 224: return 0; ! 225: } ! 226: ! 227: /* ! 228: * rebuildfn ! 229: * rebuild the destination file name for a transfer, handling ! 230: * directories and so on. ! 231: */ ! 232: char * ! 233: rebuildfn(destfile) ! 234: char *destfile; ! 235: { ! 236: struct passwd *pwp; ! 237: struct stat statbuf; ! 238: char *cp; ! 239: char spooldir_name [32]; /* used to test for spool directory */ ! 240: ! 241: if (*destfile == '~') { ! 242: if (*(destfile + 1) == '/') ! 243: sprintf(tmpfilename, "%s/%s", PUBDIR, destfile + 2); ! 244: else { ! 245: static char user [20]; ! 246: strcpy(tmpfilename, destfile + 1); ! 247: if ((cp = strtok(tmpfilename, "/\n")) == NULL) ! 248: cp = tmpfilename; ! 249: strcpy(user, tmpfilename); ! 250: if ((pwp = getpwnam(user)) == NULL) ! 251: return NULL; ! 252: if ((cp = index(destfile, "/")) == NULL) ! 253: cp = ""; ! 254: sprintf(tmpfilename, "%s/%s", pwp->pw_dir, cp); ! 255: } ! 256: } else{ if (*destfile == '/') ! 257: sprintf(tmpfilename, "%s", destfile); ! 258: else{ ! 259: sprintf(tmpfilename, "%s/%s/%s", SPOOLDIR, rmtname, destfile); ! 260: /* test for existence of spool directory and create ! 261: * one if necessary. ! 262: */ ! 263: ! 264: /* build spooldir name */ ! 265: sprintf(spooldir_name,"%s/%s", SPOOLDIR, rmtname); ! 266: ! 267: if (stat(spooldir_name, & statbuf)){ ! 268: /* spooldir doesn't exist, build a mkdir ! 269: * command to pass to system. We use ! 270: * a mkdir() system call, to ensure that we ! 271: * get useable permissions ! 272: */ ! 273: plog (M_CALL,"Spool directory %s missing...", spooldir_name); ! 274: #ifdef _I386 ! 275: plog (M_CALL,"Creating missing spool directory."); ! 276: mkdir(spooldir_name, 0744); ! 277: #endif /* _I386 */ ! 278: } ! 279: } ! 280: } ! 281: ! 282: if ((cp = index(tmpfilename, '\n')) != NULL) ! 283: *cp = '\0'; ! 284: if (((stat(tmpfilename, &statbuf) != -1) && ! 285: ((statbuf.st_mode & S_IFDIR) != 0)) || ! 286: (tmpfilename[strlen(tmpfilename) - 1] == '/')) { ! 287: if ((cp = rindex(fromfilep, '/')) == NULL) ! 288: cp = fromfilep; ! 289: else ! 290: cp++; ! 291: if (tmpfilename[strlen(tmpfilename) - 1] != '/') ! 292: strcat(tmpfilename, "/"); ! 293: strcat(tmpfilename, cp); ! 294: } ! 295: return tmpfilename; ! 296: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.