|
|
1.1 ! root 1: ! 2: /* ! 3: ** Miscellaneous support functions for smail/rmail ! 4: */ ! 5: ! 6: #ifndef lint ! 7: static char *sccsid="@(#)misc.c 2.5 (smail) 9/15/87"; ! 8: #endif ! 9: ! 10: # include <stdio.h> ! 11: # include <sys/types.h> ! 12: # include <ctype.h> ! 13: # include "defs.h" ! 14: #ifdef BSD ! 15: # include <sys/time.h> ! 16: # include <sys/timeb.h> ! 17: #else ! 18: # include <time.h> ! 19: # include <sys/utsname.h> ! 20: #endif ! 21: ! 22: extern int exitstat; /* set if a forked mailer fails */ ! 23: extern enum edebug debug; /* how verbose we are */ ! 24: extern enum ehandle handle; /* what we handle */ ! 25: extern char *uuxargs; /* arguments given to uux */ ! 26: extern int queuecost; /* threshold for queueing mail */ ! 27: extern int maxnoqueue; /* max number of uucico's */ ! 28: extern enum erouting routing; /* when to route addresses */ ! 29: extern char hostdomain[]; /* */ ! 30: extern char hostname[]; /* */ ! 31: extern char hostuucp[]; /* */ ! 32: extern char *pathfile; /* location of path database */ ! 33: extern char *spoolfile; /* file name of spooled message */ ! 34: extern FILE *spoolfp; /* file ptr to spooled message */ ! 35: extern int spoolmaster; /* set if creator of spoolfile */ ! 36: ! 37: extern struct tm *localtime(); ! 38: ! 39: struct tm *gmt, *loc; /* GMT and local time structure */ ! 40: time_t now; /* current system time */ ! 41: char nows[50]; /* time in ctime format */ ! 42: char arpanows[50]; /* time in arpa format */ ! 43: ! 44: # ifdef LOG ! 45: void ! 46: log(command, from, size) ! 47: char *command, *from; ! 48: long size; ! 49: { ! 50: FILE *fd; ! 51: char *logtime, tbuf[50]; ! 52: int cmask; ! 53: ! 54: logtime = strcpy(tbuf, nows); ! 55: logtime[16] = '\0'; ! 56: logtime += 4; ! 57: ! 58: cmask = umask(0); ! 59: fd = fopen(LOG, "a"); ! 60: (void) umask(cmask); ! 61: ! 62: if (fd != NULL) { ! 63: (void) fprintf(fd, "%s\t%ld\t%s\t%s\n", ! 64: logtime, size, from, command); ! 65: (void) fclose(fd); ! 66: } ! 67: } ! 68: # endif ! 69: # ifdef LOG ! 70: void ! 71: error_log(message) ! 72: char *message; ! 73: { ! 74: FILE *fd; ! 75: char *logtime, tbuf[50]; ! 76: char buff[2*MAXCLEN]; ! 77: int cmask; ! 78: ! 79: /* logtime = strcpy(tbuf, nows); */ ! 80: strcpy(tbuf, nows); ! 81: logtime = tbuf; ! 82: logtime[16] = '\0'; ! 83: logtime += 4; ! 84: ! 85: cmask = umask(0); ! 86: fd = fopen(LOG, "a"); /* Open for writing. */ ! 87: /* lseek(fd, 0L, 2); Seek to the end of file. */ ! 88: (void) umask(cmask); ! 89: ! 90: if (fd != -1) { ! 91: (void) fprintf(fd, "%s\tpid:%d\t%s\n", ! 92: tbuf, getpid(), message); ! 93: fflush(fd); ! 94: /* (void) write(fd, buff, strlen(buff)); */ ! 95: (void) fclose(fd); ! 96: } ! 97: } ! 98: # endif ! 99: ! 100: # ifdef RECORD ! 101: FILE * ! 102: record(command, from, size) ! 103: char *command, *from; ! 104: long size; ! 105: { ! 106: FILE *fd; ! 107: char *logtime, buf[SMLBUF]; ! 108: int cmask; ! 109: ! 110: logtime = strcpy(buf, nows); ! 111: logtime[16] = 0; ! 112: logtime += 4; ! 113: ! 114: cmask = umask(0); ! 115: fd = fopen(RECORD, "a"); ! 116: (void) umask(cmask); ! 117: ! 118: if (fd != NULL) { ! 119: (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n", ! 120: logtime, command, from, size); ! 121: } ! 122: while(fgets(buf, sizeof(buf), spoolfp) != NULL) { ! 123: (void) fputs(buf, fd); ! 124: } ! 125: (void) fclose(fd); ! 126: } ! 127: # endif ! 128: ! 129: ! 130: setdates() ! 131: { ! 132: time_t time(); ! 133: struct tm *gmtime(); ! 134: char *ctime(), *arpadate(); ! 135: ! 136: (void) time(&now); ! 137: (void) strcpy(nows, ctime(&now)); ! 138: gmt = gmtime(&now); ! 139: loc = localtime(&now); ! 140: /* (void) strcpy(arpanows, nows); */ ! 141: (void) strcpy(arpanows, arpadate(nows)); ! 142: } ! 143: ! 144: /* ! 145: ** Note: This routine was taken from sendmail ! 146: ** ! 147: ** ARPADATE -- Create date in ARPANET format ! 148: ** ! 149: ** Parameters: ! 150: ** ud -- unix style date string. if NULL, one is created. ! 151: ** ! 152: ** Returns: ! 153: ** pointer to an ARPANET date field ! 154: ** ! 155: ** Side Effects: ! 156: ** none ! 157: ** ! 158: ** WARNING: ! 159: ** date is stored in a local buffer -- subsequent ! 160: ** calls will overwrite. ! 161: ** ! 162: ** Bugs: ! 163: ** Timezone is computed from local time, rather than ! 164: ** from whereever (and whenever) the message was sent. ! 165: ** To do better is very hard. ! 166: ** ! 167: ** Some sites are now inserting the timezone into the ! 168: ** local date. This routine should figure out what ! 169: ** the format is and work appropriately. ! 170: */ ! 171: ! 172: char * ! 173: arpadate(ud) ! 174: register char *ud; ! 175: { ! 176: char errmsg[70]; ! 177: register char *p; ! 178: register char *q; ! 179: static char b[40]; ! 180: extern char *ctime(); ! 181: register int i; ! 182: #ifndef BSD ! 183: extern char *tzname[]; ! 184: time_t t, time(); ! 185: #else ! 186: /* V7 and 4BSD */ ! 187: struct timeb t; ! 188: extern struct timeb *ftime(); ! 189: extern char *timezone(); ! 190: #endif ! 191: ! 192: /* ! 193: ** Get current time. ! 194: ** This will be used if a null argument is passed and ! 195: ** to resolve the timezone. ! 196: */ ! 197: ! 198: #ifndef BSD ! 199: (void) time(&t); ! 200: if (ud == NULL) ! 201: ud = ctime(&t); ! 202: #else ! 203: /* V7 or 4BSD */ ! 204: ftime(&t); ! 205: if (ud == NULL) ! 206: ud = ctime(&t.time); ! 207: #endif ! 208: ! 209: /* ! 210: ** Crack the UNIX date line in a singularly unoriginal way. ! 211: */ ! 212: ! 213: q = b; ! 214: ! 215: p = &ud[8]; /* 16 */ ! 216: if (*p == ' ') ! 217: p++; ! 218: else ! 219: *q++ = *p++; ! 220: *q++ = *p++; ! 221: *q++ = ' '; ! 222: ! 223: p = &ud[4]; /* Sep */ ! 224: *q++ = *p++; ! 225: *q++ = *p++; ! 226: *q++ = *p++; ! 227: *q++ = ' '; ! 228: ! 229: p = &ud[22]; /* 1979 */ ! 230: *q++ = *p++; ! 231: *q++ = *p++; ! 232: *q++ = ' '; ! 233: ! 234: p = &ud[11]; /* 01:03:52 */ ! 235: for (i = 8; i > 0; i--) ! 236: *q++ = *p++; ! 237: ! 238: /* -PST or -PDT */ ! 239: #ifndef BSD ! 240: p = tzname[localtime(&t)->tm_isdst]; ! 241: #else ! 242: p = timezone(t.timezone, localtime(&t.time)->tm_isdst); ! 243: #endif ! 244: if (p[3] != '\0') ! 245: { ! 246: /* hours from GMT */ ! 247: /* ! 248: * p += 3; ! 249: * *q++ = *p++; ! 250: * if (p[1] == ':') ! 251: * *q++ = '0'; ! 252: * else ! 253: * *q++ = *p++; ! 254: * *q++ = *p++; ! 255: * p++; skip ``:'' ! 256: * *q++ = *p++; ! 257: * *q++ = *p++; ! 258: */ ! 259: ! 260: /* this short section of code replaces the above commented code. The ! 261: * reason for this is because the above code wasn't correctly parsing ! 262: * out the hours from GMT returned by the p=tzname... code above. The ! 263: * old code skipped the first 3 characters (example +0800), leaving ! 264: * only the last 2 characters to be added to the string we are building. ! 265: * ! 266: * The real question at this point should be 'is this the right format?' ! 267: * Sorry, no docs available at this time. ! 268: * ! 269: * bob h: 05/11/93. ! 270: */ ! 271: *q++ = ' '; ! 272: do{ ! 273: *q++ = *p; ! 274: } ! 275: while(*p++!= '\0'); ! 276: ! 277: } ! 278: else ! 279: { ! 280: *q++ = ' '; ! 281: *q++ = *p++; ! 282: *q++ = *p++; ! 283: *q++ = *p++; ! 284: } ! 285: ! 286: p = &ud[0]; /* Mon */ ! 287: *q++ = ' '; ! 288: *q++ = '('; ! 289: *q++ = *p++; ! 290: *q++ = *p++; ! 291: *q++ = *p++; ! 292: *q++ = ')'; ! 293: ! 294: *q = '\0'; ! 295: return (b); ! 296: } ! 297: ! 298: /* ! 299: * The user name "postmaster" must be accepted regardless of what ! 300: * combination of upper and lower case is used. This function is ! 301: * used to convert all case variants of "postmaster" to all lower ! 302: * case. If the user name passed in is not "postmaster", it is ! 303: * returned unchanged. ! 304: */ ! 305: char * ! 306: postmaster(user) ! 307: char *user; ! 308: { ! 309: static char *pm = "postmaster"; ! 310: ! 311: if(strcmpic(user, pm) == 0) { ! 312: return(pm); ! 313: } else { ! 314: return(user); ! 315: } ! 316: } ! 317: ! 318: /* ! 319: * Return 1 iff the string is "UUCP" (ignore case). ! 320: */ ! 321: isuucp(str) ! 322: char *str; ! 323: { ! 324: if(strcmpic(str, "UUCP") == 0) { ! 325: return(1); ! 326: } else { ! 327: return(0); ! 328: } ! 329: } ! 330: ! 331: /* ! 332: ** sform(form) returns a pointer to a string that tells what 'form' means ! 333: */ ! 334: ! 335: char * ! 336: sform(form) ! 337: enum eform form; ! 338: { ! 339: if(form == ERROR) return("ERROR"); ! 340: if(form == LOCAL) return("LOCAL"); ! 341: if(form == DOMAIN) return("DOMAIN"); ! 342: if(form == UUCP) return("UUCP"); ! 343: if(form == ROUTE) return("ROUTE"); ! 344: return("UNKNOWN"); ! 345: } ! 346: ! 347: /* ! 348: ** ! 349: ** getmynames(): what is my host name and host domain? ! 350: ** ! 351: ** Hostname set by -h, failing that by #define HOSTNAME, failing ! 352: ** that by gethostname() or uname(). ! 353: ** ! 354: ** Hostdomain set by -h, failing that by #define HOSTDOMAIN, ! 355: ** failing that as hostname.MYDOM, or as just hostname. ! 356: ** ! 357: ** See defs.h for the inside story. ! 358: ** ! 359: */ ! 360: ! 361: getmynames() ! 362: { ! 363: #ifdef HOSTNAME ! 364: if (!*hostname) ! 365: (void) strcpy(hostname, HOSTNAME); ! 366: #endif ! 367: #ifdef GETHOSTNAME ! 368: if (!*hostname) ! 369: gethostname(hostname, SMLBUF - 1); ! 370: #endif ! 371: #ifdef UNAME ! 372: if (!*hostname) { ! 373: struct utsname site; ! 374: ! 375: if (uname(&site) < 0) ! 376: error(EX_SOFTWARE, "uname() call failed", 0); ! 377: (void) strcpy(hostname, site.nodename); ! 378: } ! 379: #endif ! 380: if (!*hostname) ! 381: error(EX_SOFTWARE, "can't determine hostname.\n", 0); ! 382: #ifdef HOSTDOMAIN ! 383: if (!*hostdomain) ! 384: (void) strcpy(hostdomain, HOSTDOMAIN); ! 385: #endif ! 386: #ifdef MYDOM ! 387: if (!*hostdomain) ! 388: (void) strcat(strcpy(hostdomain, hostname), MYDOM); ! 389: #endif ! 390: #ifdef GETDOMAIN ! 391: if (!*hostdomain){ ! 392: unsigned char temp[SMLBUF]; ! 393: ! 394: getdomain(temp, SMLBUF - 1); ! 395: (void) strcat(strcpy(hostdomain, hostname), "."); ! 396: (void) strcat(hostdomain, temp); ! 397: } ! 398: #endif ! 399: if (!*hostdomain) ! 400: (void) strcpy(hostdomain, hostname); ! 401: ! 402: (void) strcat(strcpy(hostuucp, hostname), ".UUCP"); ! 403: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.