Annotation of coherent/a/tmp/smail/misc.c, revision 1.1.1.1

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:        int fd;
                     75:        char *logtime, tbuf[50];
                     76:        char buff[2*MAXCLEN];
                     77:        int cmask;
                     78: 
                     79:        logtime = strcpy(tbuf, nows);
                     80:        logtime[16] = '\0';
                     81:        logtime += 4;
                     82: 
                     83:        cmask = umask(0);
                     84:        fd = open(LOG, 1); /* Open for writing.  */
                     85:        lseek(fd, 0L, 2); /* Seek to the end of file.  */
                     86:        (void) umask(cmask);
                     87: 
                     88:        if (fd != -1) {
                     89:                (void) sprintf(buff, "%s\tpid:%d\t%s\n",
                     90:                        logtime, getpid(), message);
                     91:                (void) write(fd, buff, strlen(buff));
                     92:                (void) close(fd);
                     93:        }
                     94: }
                     95: # endif
                     96: 
                     97: # ifdef RECORD
                     98: FILE *
                     99: record(command, from, size)
                    100: char *command, *from;
                    101: long size;
                    102: {
                    103:        FILE *fd;
                    104:        char *logtime, buf[SMLBUF];
                    105:        int cmask;
                    106: 
                    107:        logtime = strcpy(buf, nows);
                    108:        logtime[16] = 0;
                    109:        logtime += 4;
                    110: 
                    111:        cmask = umask(0);
                    112:        fd = fopen(RECORD, "a");
                    113:        (void) umask(cmask);
                    114: 
                    115:        if (fd != NULL) {
                    116:                (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n", 
                    117:                        logtime, command, from, size);
                    118:        }
                    119:        while(fgets(buf, sizeof(buf), spoolfp) != NULL) {
                    120:                (void) fputs(buf, fd);
                    121:        }
                    122:        (void) fclose(fd);
                    123: }
                    124: # endif
                    125: 
                    126: 
                    127: setdates()
                    128: {
                    129:        time_t time();
                    130:        struct tm *gmtime();
                    131:        char *ctime(), *arpadate();
                    132: 
                    133:        (void) time(&now);
                    134:        (void) strcpy(nows, ctime(&now));
                    135:        gmt = gmtime(&now);
                    136:        loc = localtime(&now);
                    137:        (void) strcpy(arpanows, arpadate(nows));
                    138: }
                    139: 
                    140: /*
                    141: **  Note: This routine was taken from sendmail
                    142: **
                    143: **  ARPADATE -- Create date in ARPANET format
                    144: **
                    145: **     Parameters:
                    146: **             ud -- unix style date string.  if NULL, one is created.
                    147: **
                    148: **     Returns:
                    149: **             pointer to an ARPANET date field
                    150: **
                    151: **     Side Effects:
                    152: **             none
                    153: **
                    154: **     WARNING:
                    155: **             date is stored in a local buffer -- subsequent
                    156: **             calls will overwrite.
                    157: **
                    158: **     Bugs:
                    159: **             Timezone is computed from local time, rather than
                    160: **             from whereever (and whenever) the message was sent.
                    161: **             To do better is very hard.
                    162: **
                    163: **             Some sites are now inserting the timezone into the
                    164: **             local date.  This routine should figure out what
                    165: **             the format is and work appropriately.
                    166: */
                    167: 
                    168: char *
                    169: arpadate(ud)
                    170:        register char *ud;
                    171: {
                    172:        register char *p;
                    173:        register char *q;
                    174:        static char b[40];
                    175:        extern char *ctime();
                    176:        register int i;
                    177: #ifndef BSD
                    178:        extern char *tzname[];
                    179:        time_t t, time();
                    180: #else
                    181:        /* V7 and 4BSD */
                    182:        struct timeb t;
                    183:        extern struct timeb *ftime();
                    184:        extern char *timezone();
                    185: #endif
                    186: 
                    187:        /*
                    188:        **  Get current time.
                    189:        **      This will be used if a null argument is passed and
                    190:        **      to resolve the timezone.
                    191:        */
                    192: 
                    193: #ifndef BSD
                    194:        (void) time(&t);
                    195:        if (ud == NULL)
                    196:                ud = ctime(&t);
                    197: #else
                    198:        /* V7 or 4BSD */
                    199:        ftime(&t);
                    200:        if (ud == NULL)
                    201:                ud = ctime(&t.time);
                    202: #endif
                    203: 
                    204:        /*
                    205:        **  Crack the UNIX date line in a singularly unoriginal way.
                    206:        */
                    207: 
                    208:        q = b;
                    209: 
                    210:        p = &ud[8];             /* 16 */
                    211:        if (*p == ' ')
                    212:                p++;
                    213:        else
                    214:                *q++ = *p++;
                    215:        *q++ = *p++;
                    216:        *q++ = ' ';
                    217: 
                    218:        p = &ud[4];             /* Sep */
                    219:        *q++ = *p++;
                    220:        *q++ = *p++;
                    221:        *q++ = *p++;
                    222:        *q++ = ' ';
                    223: 
                    224:        p = &ud[22];            /* 1979 */
                    225:        *q++ = *p++;
                    226:        *q++ = *p++;
                    227:        *q++ = ' ';
                    228: 
                    229:        p = &ud[11];            /* 01:03:52 */
                    230:        for (i = 8; i > 0; i--)
                    231:                *q++ = *p++;
                    232: 
                    233:                                /* -PST or -PDT */
                    234: #ifndef BSD
                    235:        p = tzname[localtime(&t)->tm_isdst];
                    236: #else
                    237:        p = timezone(t.timezone, localtime(&t.time)->tm_isdst);
                    238: #endif
                    239:        if (p[3] != '\0')
                    240:        {
                    241:                /* hours from GMT */
                    242:                p += 3;
                    243:                *q++ = *p++;
                    244:                if (p[1] == ':')
                    245:                        *q++ = '0';
                    246:                else
                    247:                        *q++ = *p++;
                    248:                *q++ = *p++;
                    249:                p++;            /* skip ``:'' */
                    250:                *q++ = *p++;
                    251:                *q++ = *p++;
                    252:        }
                    253:        else
                    254:        {
                    255:                *q++ = ' ';
                    256:                *q++ = *p++;
                    257:                *q++ = *p++;
                    258:                *q++ = *p++;
                    259:        }
                    260: 
                    261:        p = &ud[0];             /* Mon */
                    262:        *q++ = ' ';
                    263:        *q++ = '(';
                    264:        *q++ = *p++;
                    265:        *q++ = *p++;
                    266:        *q++ = *p++;
                    267:        *q++ = ')';
                    268: 
                    269:        *q = '\0';
                    270:        return (b);
                    271: }
                    272: 
                    273: /*
                    274:  *     The user name "postmaster" must be accepted regardless of what
                    275:  *     combination of upper and lower case is used.  This function is
                    276:  *     used to convert all case variants of "postmaster" to all lower
                    277:  *     case.  If the user name passed in is not "postmaster", it is
                    278:  *     returned unchanged.
                    279:  */
                    280: char *
                    281: postmaster(user)
                    282: char *user;
                    283: {
                    284:        static char *pm = "postmaster";
                    285: 
                    286:        if(strcmpic(user, pm) == 0) {
                    287:                return(pm);
                    288:        } else {
                    289:                return(user);
                    290:        }
                    291: }
                    292: 
                    293: /*
                    294:  * Return 1 iff the string is "UUCP" (ignore case).
                    295:  */
                    296: isuucp(str)
                    297: char *str;
                    298: {
                    299:        if(strcmpic(str, "UUCP") == 0) {
                    300:                return(1);
                    301:        } else {
                    302:                return(0);
                    303:        }
                    304: }
                    305: 
                    306: /*
                    307: ** sform(form) returns a pointer to a string that tells what 'form' means
                    308: */
                    309: 
                    310: char *
                    311: sform(form)
                    312: enum eform form;
                    313: {
                    314:        if(form == ERROR)  return("ERROR");
                    315:        if(form == LOCAL)  return("LOCAL");
                    316:        if(form == DOMAIN) return("DOMAIN");
                    317:        if(form == UUCP)   return("UUCP");
                    318:        if(form == ROUTE)  return("ROUTE");
                    319:        return("UNKNOWN");
                    320: }
                    321: 
                    322: /*
                    323: **
                    324: **  getmynames(): what is my host name and host domain?
                    325: **
                    326: **  Hostname set by -h, failing that by #define HOSTNAME, failing
                    327: **  that by gethostname() or uname().
                    328: **  
                    329: **  Hostdomain set by -h, failing that by #define HOSTDOMAIN,
                    330: **  failing that as hostname.MYDOM, or as just hostname.
                    331: **
                    332: **  See defs.h for the inside story.
                    333: **
                    334: */
                    335: 
                    336: getmynames()
                    337: {
                    338: #ifdef HOSTNAME
                    339:        if (!*hostname)
                    340:                (void) strcpy(hostname, HOSTNAME);
                    341: #endif
                    342: #ifdef GETHOSTNAME
                    343:        if (!*hostname)
                    344:                gethostname(hostname, SMLBUF - 1);
                    345: #endif
                    346: #ifdef UNAME
                    347:        if (!*hostname) {
                    348:                struct utsname site;
                    349: 
                    350:                if (uname(&site) < 0)
                    351:                        error(EX_SOFTWARE, "uname() call failed", 0);
                    352:                (void) strcpy(hostname, site.nodename);
                    353:        }
                    354: #endif
                    355:        if (!*hostname)
                    356:                error(EX_SOFTWARE, "can't determine hostname.\n", 0);
                    357: #ifdef HOSTDOMAIN
                    358:        if (!*hostdomain)
                    359:                (void) strcpy(hostdomain, HOSTDOMAIN);
                    360: #endif
                    361: #ifdef MYDOM
                    362:        if (!*hostdomain)
                    363:                (void) strcat(strcpy(hostdomain, hostname), MYDOM);
                    364: #endif
                    365: #ifdef GETDOMAIN
                    366:        if (!*hostdomain){
                    367:                unsigned char temp[SMLBUF];
                    368: 
                    369:                getdomain(temp, SMLBUF - 1);
                    370:                (void) strcat(strcpy(hostdomain, hostname), ".");
                    371:                (void) strcat(hostdomain, temp);
                    372:        }
                    373: #endif
                    374:        if (!*hostdomain)
                    375:                (void) strcpy(hostdomain, hostname);
                    376: 
                    377:        (void) strcat(strcpy(hostuucp, hostname), ".UUCP");
                    378: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.