home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / mail / smail / src / rcs / misc.c,v < prev    next >
Text File  |  1993-12-21  |  11KB  |  587 lines

  1. head    1.5;
  2. access;
  3. symbols
  4.     C_1:1.5;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.5
  10. date    93.11.06.15.59.47;    author Aussem;    state Exp;
  11. branches;
  12. next    1.4;
  13.  
  14. 1.4
  15. date    93.10.18.23.50.32;    author Aussem;    state Exp;
  16. branches;
  17. next    1.3;
  18.  
  19. 1.3
  20. date    93.09.18.16.47.47;    author Aussem;    state Exp;
  21. branches;
  22. next    1.2;
  23.  
  24. 1.2
  25. date    93.09.10.01.51.50;    author Aussem;    state Exp;
  26. branches;
  27. next    1.1;
  28.  
  29. 1.1
  30. date    93.09.08.16.27.13;    author Aussem;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @misc routines
  37. @
  38.  
  39.  
  40. 1.5
  41. log
  42. @maillog() now works better
  43. @
  44. text
  45. @/*
  46.  * Miscellaneous support functions for smail/rmail
  47.  *
  48.  * This program is free software; you can redistribute it and/or
  49.  * modify it under the terms of the GNU General Public License as
  50.  * published by the Free Software Foundation; either version 2 of
  51.  * the License, or (at your option) any later version.
  52.  *
  53.  * This program is distributed in the hope that it will be useful,
  54.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  55.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  56.  * General Public License for more details.
  57.  *
  58.  * You should have received a copy of the GNU General Public License
  59.  * along with this program; if not, write to the Free Software
  60.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  61.  *
  62.  * $Log: misc.c,v $
  63.  * Revision 1.4  1993/10/18  23:50:32  Aussem
  64.  * enforcer hit in record() removed
  65.  *
  66.  * Revision 1.3  1993/09/18  16:47:47  Aussem
  67.  * insert GNU license text in the header
  68.  *
  69.  * Revision 1.2  1993/09/10  01:51:50  Aussem
  70.  * new support for wCNews styled logfile with maillog()
  71.  *
  72.  * Revision 1.1  1993/09/08  16:27:13  Aussem
  73.  * Initial revision
  74.  *
  75.  *
  76.  */
  77.  
  78. static char     *rcsid="$Id: misc.c,v 1.4 1993/10/18 23:50:32 Aussem Exp Aussem $";
  79.  
  80. # include    <stdio.h>
  81. # include    <stdlib.h>
  82. # include    <sys/types.h>
  83. # include    <ctype.h>
  84. # include    "defs.h"
  85. # include    <time.h>
  86.  
  87. extern int  exitstat;        /* set if a forked mailer fails */
  88. extern enum edebug debug;    /* how verbose we are         */ 
  89. extern enum ehandle handle;    /* what we handle        */
  90. extern char *uuxargs;        /* arguments given to uux       */
  91. extern int  queuecost;        /* threshold for queueing mail  */
  92. extern int  maxnoqueue;        /* max number of uucico's       */
  93. extern enum erouting routing;    /* when to route addresses    */
  94. extern char hostdomain[];    /* */
  95. extern char hostname[];        /* */
  96. extern char hostuucp[];        /* */
  97. extern char *pathfile;        /* location of path database    */
  98. extern char *spoolfile;        /* file name of spooled message */
  99. extern FILE *spoolfp;        /* file ptr  to spooled message */
  100. extern int spoolmaster;        /* set if creator of spoolfile  */
  101. extern char logfile[];
  102. extern char sentfile[];
  103. char smarthost[SMLBUF];
  104.  
  105. struct tm *gmt, *loc;        /* GMT and local time structure    */
  106. time_t now;            /* current system time        */
  107. char nows[50];            /* time in ctime format        */
  108. char arpanows[50];        /* time in arpa format        */
  109.  
  110. # ifdef LOG
  111. void
  112. log(command, from, size)
  113. char *command, *from;
  114. long size;
  115. {
  116. writelog(" cmd: \"%s\" from %s",command,from);
  117. }
  118. # endif
  119.  
  120. # ifdef MAILLOG
  121. extern char maillogfile[];
  122.  
  123. void
  124. maillog(to_user,to_host, from, size,okay)
  125. char *to_user,*to_host;
  126. char *from;
  127. long size;
  128. char okay;
  129. {
  130. static FILE *fp=NULL;
  131. char *logtime, buf[SMLBUF];
  132.  
  133. logtime = strcpy(buf, nows);
  134. logtime[19] = '\0';
  135. logtime += 4;
  136.  
  137. fp=fopen(maillogfile,"a");
  138.  
  139. if(fp)
  140.     {
  141.    if(to_host[0]!='\0')
  142.         fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes\n",logtime,okay,from,to_host,to_user,size);
  143.     else
  144.         fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to_user,size);
  145.     fclose(fp);
  146.    }
  147. }
  148. # endif
  149.  
  150. # ifdef RECORD
  151. FILE *
  152. record(command, from, size)
  153. char *command, *from;
  154. long size;
  155. {
  156.     FILE *fd;
  157.     char *logtime, buf[SMLBUF];
  158.  
  159.     logtime = strcpy(buf, nows);
  160.     logtime[19] = '\0';
  161.     logtime += 4;
  162.  
  163.     fd = fopen(sentfile, "a");
  164.     if(!fd)
  165.         return(NULL);
  166.     (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",    
  167.                         logtime, command, from, size);
  168.     while(fgets(buf, sizeof(buf), spoolfp) != NULL) {
  169.         (void) fputs(buf, fd);
  170.     }
  171.     (void) fclose(fd);
  172.     return(NULL);
  173. }
  174. # endif
  175.  
  176.  
  177. setdates()
  178. {
  179.     (void) time(&now);
  180.     (void) strcpy(nows, ctime(&now));
  181.     gmt = gmtime(&now);
  182.     loc = localtime(&now);
  183.     (void) strcpy(arpanows, arpadate(nows));
  184. }
  185.  
  186. /*
  187. **  Note: This routine was taken from sendmail
  188. **
  189. **  ARPADATE -- Create date in ARPANET format
  190. **
  191. **    Parameters:
  192. **        ud -- unix style date string.  if NULL, one is created.
  193. **
  194. **    Returns:
  195. **        pointer to an ARPANET date field
  196. **
  197. **    Side Effects:
  198. **        none
  199. **
  200. **    WARNING:
  201. **        date is stored in a local buffer -- subsequent
  202. **        calls will overwrite.
  203. **
  204. **    Bugs:
  205. **        Timezone is computed from local time, rather than
  206. **        from whereever (and whenever) the message was sent.
  207. **        To do better is very hard.
  208. **
  209. **        Some sites are now inserting the timezone into the
  210. **        local date.  This routine should figure out what
  211. **        the format is and work appropriately.
  212. */
  213.  
  214. #ifdef AMIGA
  215. extern char *_TZ;
  216.  
  217. static short int DaysofMonth[]=
  218.   { 31, 28, 31, 30,
  219.     31, 30, 31, 31,
  220.     30, 31, 30, 31 };
  221.  
  222.  
  223. static char *Weekday[]=
  224. {
  225.   "Sun",
  226.   "Mon",
  227.   "Tue",
  228.   "Wed",
  229.   "Thu",
  230.   "Fri",
  231.   "Sat"
  232. };
  233.  
  234. static char *Month[]=
  235. {
  236.   "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
  237. };
  238.  
  239.  
  240. char *
  241. arpadate(ud)
  242.     register char *ud;
  243. {
  244.   struct tm *Time;
  245.   time_t t;
  246.   static char timestr[40]="";
  247.   char *timezone;
  248.   char *getenv();
  249.  
  250.   timezone=getenv("TZ");
  251.  
  252.   time(&t);
  253.   Time=localtime(&t);
  254.   if(Time)
  255.    sprintf(timestr, "%s, %02d %s %04d %02d:%02d:%02d %s",
  256.                        Weekday[Time->tm_wday],
  257.                        Time->tm_mday,
  258.                        Month[Time->tm_mon],
  259.                        Time->tm_year+1900,
  260.                        Time->tm_hour,
  261.                        Time->tm_min,
  262.                        Time->tm_sec,
  263.                        timezone?timezone:"GMT");
  264.   return timestr;
  265. }
  266. #else
  267. char *
  268. arpadate(ud)
  269.     register char *ud;
  270. {
  271.     register char *p;
  272.     register char *q;
  273.     static char b[40];
  274.     extern char *ctime();
  275.     register int i;
  276. #ifndef BSD
  277.     extern char *tzname[];
  278.     time_t t, time();
  279. #else
  280.     /* V7 and 4BSD */
  281.     struct timeb t;
  282.     extern struct timeb *ftime();
  283.     extern char *timezone();
  284. #endif
  285.  
  286.     /*
  287.     **  Get current time.
  288.     **    This will be used if a null argument is passed and
  289.     **    to resolve the timezone.
  290.     */
  291.  
  292. #ifndef BSD
  293.     (void) time(&t);
  294.     if (ud == NULL)
  295.         ud = ctime(&t);
  296. #else
  297.     /* V7 or 4BSD */
  298.     ftime(&t);
  299.     if (ud == NULL)
  300.         ud = ctime(&t.time);
  301. #endif
  302.  
  303.     /*
  304.     **  Crack the UNIX date line in a singularly unoriginal way.
  305.     */
  306.  
  307.     q = b;
  308.  
  309.     p = &ud[8];        /* 16 */
  310.     if (*p == ' ')
  311.         p++;
  312.     else
  313.         *q++ = *p++;
  314.     *q++ = *p++;
  315.     *q++ = ' ';
  316.  
  317.     p = &ud[4];        /* Sep */
  318.     *q++ = *p++;
  319.     *q++ = *p++;
  320.     *q++ = *p++;
  321.     *q++ = ' ';
  322.  
  323.     p = &ud[22];        /* 1979 */
  324.     *q++ = *p++;
  325.     *q++ = *p++;
  326.     *q++ = ' ';
  327.  
  328.     p = &ud[11];        /* 01:03:52 */
  329.     for (i = 8; i > 0; i--)
  330.         *q++ = *p++;
  331.  
  332.                 /* -PST or -PDT */
  333. #ifndef BSD
  334.     p = tzname[localtime(&t)->tm_isdst];
  335. #else
  336.     p = timezone(t.timezone, localtime(&t.time)->tm_isdst);
  337. #endif
  338.     if (p[3] != '\0')
  339.     {
  340.         /* hours from GMT */
  341.         p += 3;
  342.         *q++ = *p++;
  343.         if (p[1] == ':')
  344.             *q++ = '0';
  345.         else
  346.             *q++ = *p++;
  347.         *q++ = *p++;
  348.         p++;        /* skip ``:'' */
  349.         *q++ = *p++;
  350.         *q++ = *p++;
  351.     }
  352.     else
  353.     {
  354.         *q++ = ' ';
  355.         *q++ = *p++;
  356.         *q++ = *p++;
  357.         *q++ = *p++;
  358.     }
  359.  
  360.     p = &ud[0];        /* Mon */
  361.     *q++ = ' ';
  362.     *q++ = '(';
  363.     *q++ = *p++;
  364.     *q++ = *p++;
  365.     *q++ = *p++;
  366.     *q++ = ')';
  367.  
  368.     *q = '\0';
  369.     return (b);
  370. }
  371. #endif
  372.  
  373. /*
  374.  *    The user name "postmaster" must be accepted regardless of what
  375.  *    combination of upper and lower case is used.  This function is
  376.  *    used to convert all case variants of "postmaster" to all lower
  377.  *    case.  If the user name passed in is not "postmaster", it is
  378.  *    returned unchanged.
  379.  */
  380. char *
  381. postmaster(user)
  382. char *user;
  383. {
  384.     static char *pm = "postmaster";
  385.  
  386.     if(strcmpic(user, pm) == 0) {
  387.         return(pm);
  388.     } else {
  389.         return(user);
  390.     }
  391. }
  392.  
  393. /*
  394.  * Return 1 iff the string is "UUCP" (ignore case).
  395.  */
  396. isuucp(str)
  397. char *str;
  398. {
  399.     if(strcmpic(str, "UUCP") == 0) {
  400.         return(1);
  401.     } else {
  402.         return(0);
  403.     }
  404. }
  405.  
  406. /*
  407. ** sform(form) returns a pointer to a string that tells what 'form' means
  408. */
  409.  
  410. char *
  411. sform(form)
  412. enum eform form;
  413. {
  414.     if(form == ERROR)  return("ERROR");
  415.     if(form == LOCAL)  return("LOCAL");
  416.     if(form == DOMAIN) return("DOMAIN");
  417.     if(form == UUCP)   return("UUCP");
  418.     if(form == ROUTE)  return("ROUTE");
  419.     return("UNKNOWN");
  420. }
  421.  
  422. /*
  423. **
  424. **  getmynames(): what is my host name and host domain?
  425. **
  426. **  Hostname set by -h, failing that by #define HOSTNAME, failing
  427. **  that by gethostname() or uname().
  428. **  
  429. **  Hostdomain set by -h, failing that by #define HOSTDOMAIN,
  430. **  failing that as hostname.MYDOM, or as just hostname.
  431. **
  432. **  See defs.h for the inside story.
  433. **
  434. */
  435.  
  436. getmynames()
  437. {
  438. #ifdef HOSTNAME
  439.     if (!*hostname)
  440.         (void) strcpy(hostname, HOSTNAME);
  441. #endif
  442. #ifdef GETHOSTNAME
  443.     if (!*hostname)
  444.         gethostname(hostname, SMLBUF - 1);
  445. #endif
  446. #ifdef UNAME
  447.     if (!*hostname) {
  448.         struct utsname site;
  449.  
  450.         if (uname(&site) < 0)
  451.             error(EX_SOFTWARE, "uname() call failed", 0);
  452.         (void) strcpy(hostname, site.nodename);
  453.     }
  454. #endif
  455.     if (!*hostname)
  456.         error(EX_SOFTWARE, "can't determine hostname.\n", 0);
  457. #ifdef HOSTDOMAIN
  458.     if (!*hostdomain)
  459.         (void) strcpy(hostdomain, HOSTDOMAIN);
  460. #endif
  461. #ifdef MYDOM
  462.     if (!*hostdomain)
  463.         (void) strcat(strcpy(hostdomain, hostname), MYDOM);
  464. #endif
  465. #ifdef AMIGA
  466.     if (!*hostdomain)
  467.         {
  468.         (void) getdomainname(hostdomain, SMLBUF - 1);
  469.         strins(hostdomain,hostname);
  470.         }
  471. #endif
  472.     if (!*hostdomain)
  473.         (void) strcpy(hostdomain, hostname);
  474.  
  475.     (void) strcat(strcpy(hostuucp, hostname), ".UUCP");
  476. #ifdef AMIGA
  477.     (void) getsmarthost(smarthost,SMLBUF - 1);
  478. #endif
  479.  
  480. }
  481. @
  482.  
  483.  
  484. 1.4
  485. log
  486. @enforcer hit in record() removed
  487. @
  488. text
  489. @d19 3
  490. d34 1
  491. a34 1
  492. static char     *rcsid="$Id: misc.c,v 1.3 1993/09/18 16:47:47 Aussem Exp Aussem $";
  493. d77 2
  494. d80 2
  495. a81 2
  496. maillog(to, from, size,okay)
  497. char *to;
  498. a85 1
  499. extern char maillogfile[];
  500. d93 1
  501. a93 2
  502. if(!fp)
  503.     fp=fopen(maillogfile,"a");
  504. d96 7
  505. a102 2
  506.     fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to,size);
  507.  
  508. @
  509.  
  510.  
  511. 1.3
  512. log
  513. @insert GNU license text in the header
  514. @
  515. text
  516. @d19 3
  517. d31 1
  518. a31 1
  519. static char     *rcsid="$Id: misc.c,v 1.2 1993/09/10 01:51:50 Aussem Exp Aussem $";
  520. d112 4
  521. a115 4
  522.     if (fd != NULL) {
  523.         (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
  524.             logtime, command, from, size);
  525.     }
  526. @
  527.  
  528.  
  529. 1.2
  530. log
  531. @new support for wCNews styled logfile with maillog()
  532. @
  533. text
  534. @d2 1
  535. a2 1
  536.  *  Miscellaneous support functions for smail/rmail
  537. d4 14
  538. d19 3
  539. d28 1
  540. a28 1
  541. static char     *rcsid="$Id: misc.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
  542. @
  543.  
  544.  
  545. 1.1
  546. log
  547. @Initial revision
  548. @
  549. text
  550. @d4 3
  551. a6 1
  552.  * $Log$
  553. d8 1
  554. d11 1
  555. a11 1
  556. static char     *rcsid="$Id$";
  557. a48 1
  558. #ifdef AMIGA
  559. d50 21
  560. a70 4
  561. #else
  562.     FILE *fd;
  563.     char *logtime, tbuf[50];
  564.     int cmask;
  565. d72 2
  566. a73 3
  567.     logtime = strcpy(tbuf, nows);
  568.     logtime[16] = '\0';
  569.     logtime += 4;
  570. a74 9
  571.     cmask = umask(0);
  572.     fd = fopen(logfile, "a");
  573.     (void) umask(cmask);
  574.     if (fd != NULL) {
  575.         (void) fprintf(fd, "%s\t%ld\t%s\t%s\n",
  576.             logtime, size, from, command);
  577.         (void) fclose(fd);
  578.     }
  579. #endif
  580. d88 1
  581. a88 1
  582.     logtime[16] = 0;
  583. d93 1
  584. a93 1
  585.         (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n", 
  586. @
  587.