|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <sys/stat.h> ! 3: #include <access.h> ! 4: #include "mail.h" ! 5: #include <time.h> ! 6: #include <sys/types.h> ! 7: ! 8: char *parent(); ! 9: char keyname[64]; /* Destination public key file name */ ! 10: ! 11: /* ! 12: * Miscellaneous Routines ! 13: */ ! 14: ! 15: char * ! 16: myalloc(size) ! 17: unsigned int size; ! 18: { ! 19: register char *cp; ! 20: extern char *malloc(); ! 21: ! 22: if ( (cp=malloc(size)) == NULL ) ! 23: merr("Out of memory"); ! 24: return(cp); ! 25: } ! 26: ! 27: fatal(x) ! 28: { ! 29: fprintf(stderr, "Fatal Error: %r\n", &x); ! 30: fflush(stderr); ! 31: rmexit(1); ! 32: } ! 33: ! 34: /* ! 35: * Check access on a file. ! 36: */ ! 37: maccess(name) ! 38: char *name; ! 39: { ! 40: struct stat sb; ! 41: ! 42: if (stat(name, &sb) < 0) { ! 43: if (access(parent(name), ACREAT) < 0) ! 44: return (-1); ! 45: } else if (access(name, AWRITE) < 0) ! 46: return (-1); ! 47: return (0); ! 48: } ! 49: ! 50: /* ! 51: * Check enrollment for xmail. ! 52: */ ! 53: xaccess(name) char *name; ! 54: { ! 55: struct stat sb; ! 56: sprintf(keyname, "%s%s", PUBKEYDIR, name); ! 57: return stat(keyname, &sb) >= 0; ! 58: } ! 59: /* ! 60: * Find the parent directory for access permissions. ! 61: */ ! 62: char * ! 63: parent(name) ! 64: char *name; ! 65: { ! 66: register char *cp, *xp; ! 67: static char p[256]; ! 68: ! 69: xp = rindex(name, '/'); ! 70: if (xp == NULL) ! 71: return ("."); ! 72: if (xp == name) ! 73: return ("/"); ! 74: if (xp - name >= 256) ! 75: return (""); ! 76: cp = p; ! 77: while (name < xp) ! 78: *cp++ = *name++; ! 79: *cp = 0; ! 80: return (p); ! 81: } ! 82: ! 83: /* ! 84: * Copy from the file stream `ifp' (starting at ! 85: * position `start' and ending at `end' or EOF) ! 86: * to the file stream `ofp' which is assumed ! 87: * to be already correctly positioned. ! 88: * Returns non-zero on errors. ! 89: * intstop == 1 means stop on interrupt ! 90: * intstop == 0 means ignore interrupt ! 91: */ ! 92: mcopy(ifp, ofp, start, end, intstop) ! 93: register FILE *ifp, *ofp; ! 94: fsize_t start, end; ! 95: { ! 96: register int c; ! 97: ! 98: fseek(ifp, start, 0); ! 99: end -= start; ! 100: if (intstop) ! 101: while (!intcheck() && end-- > 0 && (c = getc(ifp))!=EOF) ! 102: putc(c, ofp); ! 103: else ! 104: while (end-- > 0 && (c = getc(ifp))!=EOF) ! 105: putc(c, ofp); ! 106: fflush(ofp); ! 107: if (ferror(ofp)) ! 108: return (1); ! 109: return (0); ! 110: } ! 111: ! 112: #if XMAIL ! 113: ! 114: char helpmessage[] = "\ ! 115: \ ! 116: mail -- computer mail\n\ ! 117: xmail -- secret computer mail\n\ ! 118: Usage: mail [ options ] [ user ... ]\n\ ! 119: or: xmail [ options ] user [ ... ]\n\ ! 120: Options:\n\ ! 121: -f file Print mail from 'file' instead of the default\n\ ! 122: -p Print mail non-interactively\n\ ! 123: -q Exit on interrupt, leaving mail unchanged\n\ ! 124: -r Print mail in reverse order, latest first\n\ ! 125: -v Verbose commentary on alias expansion\n\ ! 126: If 'user' is present, send each a mail message read from standard input.\n\ ! 127: If 'xmail' is the command, use xencode to encrypt the mail messages.\n\ ! 128: Mail message ends with EOF of a line containing only '.'. Otherwise, read\n\ ! 129: and print the invoking user's mailbox.\n\ ! 130: \ ! 131: "; ! 132: ! 133: #else ! 134: ! 135: char helpmessage[] = "\ ! 136: \ ! 137: mail -- computer mail\n\ ! 138: Usage: mail [ options ] [ user ... ]\n\ ! 139: Options:\n\ ! 140: -f file Print mail from 'file' instead of the default\n\ ! 141: -p Print mail non-interactively\n\ ! 142: -q Exit on interrupt, leaving mail unchanged\n\ ! 143: -r Print mail in reverse order, latest first\n\ ! 144: -v Verbose commentary on alias expansion\n\ ! 145: If 'user' is present, send each a mail message read from standard input.\n\ ! 146: Mail message ends with EOF of a line containing only '.'. Otherwise, read\n\ ! 147: and print the invoking user's mailbox.\n\ ! 148: \ ! 149: "; ! 150: #endif ! 151: ! 152: usage() ! 153: { ! 154: mmsg(helpmessage); ! 155: rmexit(1); ! 156: } ! 157: ! 158: #if 0 ! 159: ! 160: #define LOGFILE "/usr/spool/uucppublic/mail/debug.log" ! 161: ! 162: static char *logfile = LOGFILE; ! 163: static FILE *logfp = NULL; ! 164: ! 165: logopen() ! 166: { ! 167: time_t t; ! 168: ! 169: time(&t); ! 170: if ( (logfp=fopen(logfile, "a")) == NULL ) ! 171: fatal("Can't open Log File: \"%s\"", logfile); ! 172: logdump("------------------\n"); ! 173: logdump(ctime(&t)); ! 174: } ! 175: ! 176: logclose() ! 177: { ! 178: if ( logfp != NULL ) ! 179: fclose(logfp); ! 180: } ! 181: ! 182: logdump(x) ! 183: { ! 184: if ( logfp != NULL ) ! 185: fprintf(logfp, "%r", &x); ! 186: } ! 187: ! 188: #else ! 189: ! 190: logopen() ! 191: {} ! 192: ! 193: logclose() ! 194: {} ! 195: ! 196: logdump() ! 197: {} ! 198: ! 199: #endif ! 200: /* ! 201: * This function takes the two argv-style lists of mail targets, ! 202: * the "To:"-list and the "CC:"-list, and returns a total ! 203: * combined list of all target to whom the mail message will be sent. ! 204: */ ! 205: ! 206: char ** ! 207: listcat(tolist, cclist) ! 208: char **tolist, **cclist; ! 209: { ! 210: ! 211: static char *recips[MAXRECIP]; ! 212: int numrecip = 0; ! 213: register char **listpp; ! 214: ! 215: for (listpp=tolist; *listpp != NULL; listpp++) { ! 216: recips[numrecip++] = *listpp; ! 217: } ! 218: for (listpp=cclist; *listpp != NULL; listpp++) { ! 219: recips[numrecip++] = *listpp; ! 220: } ! 221: recips[numrecip] = NULL; ! 222: ! 223: return(recips); ! 224: } ! 225: ! 226: /* ! 227: * tmp_copy() ! 228: * Make a temporary copy of a file stream. ! 229: * The file pointer returned points to an unlinked copy of the ! 230: * stream from the argument. This way, the file need only be ! 231: * closed to remove it. ! 232: */ ! 233: ! 234: FILE * ! 235: tmp_copy(fp) ! 236: FILE *fp; ! 237: { ! 238: FILE *new_fp; ! 239: char *filename; ! 240: ! 241: if((filename = tempnam(NULL, "mail")) == (FILE *)NULL) { ! 242: merr("Can't create temporary file name."); ! 243: } ! 244: ! 245: /* We are going to want to read from new_fp later. */ ! 246: if((new_fp = fopen(filename, "w+")) == NULL) { ! 247: /* filename does not get free()'d on this error. */ ! 248: merr("Can't open temporary file %s.", filename); ! 249: } ! 250: unlink(filename); ! 251: ! 252: /* Copy all of fp to new_fp. */ ! 253: mcopy(fp, new_fp, (fsize_t)0, (fsize_t)MAXLONG, 0); ! 254: ! 255: free(filename); ! 256: return(new_fp); ! 257: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.