home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- access;
- symbols
- C_1:1.5;
- locks; strict;
- comment @ * @;
-
-
- 1.5
- date 93.11.06.15.59.47; author Aussem; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 93.10.18.23.50.32; author Aussem; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 93.09.18.16.47.47; author Aussem; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 93.09.10.01.51.50; author Aussem; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 93.09.08.16.27.13; author Aussem; state Exp;
- branches;
- next ;
-
-
- desc
- @misc routines
- @
-
-
- 1.5
- log
- @maillog() now works better
- @
- text
- @/*
- * Miscellaneous support functions for smail/rmail
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Log: misc.c,v $
- * Revision 1.4 1993/10/18 23:50:32 Aussem
- * enforcer hit in record() removed
- *
- * Revision 1.3 1993/09/18 16:47:47 Aussem
- * insert GNU license text in the header
- *
- * Revision 1.2 1993/09/10 01:51:50 Aussem
- * new support for wCNews styled logfile with maillog()
- *
- * Revision 1.1 1993/09/08 16:27:13 Aussem
- * Initial revision
- *
- *
- */
-
- static char *rcsid="$Id: misc.c,v 1.4 1993/10/18 23:50:32 Aussem Exp Aussem $";
-
- # include <stdio.h>
- # include <stdlib.h>
- # include <sys/types.h>
- # include <ctype.h>
- # include "defs.h"
- # include <time.h>
-
- extern int exitstat; /* set if a forked mailer fails */
- extern enum edebug debug; /* how verbose we are */
- extern enum ehandle handle; /* what we handle */
- extern char *uuxargs; /* arguments given to uux */
- extern int queuecost; /* threshold for queueing mail */
- extern int maxnoqueue; /* max number of uucico's */
- extern enum erouting routing; /* when to route addresses */
- extern char hostdomain[]; /* */
- extern char hostname[]; /* */
- extern char hostuucp[]; /* */
- extern char *pathfile; /* location of path database */
- extern char *spoolfile; /* file name of spooled message */
- extern FILE *spoolfp; /* file ptr to spooled message */
- extern int spoolmaster; /* set if creator of spoolfile */
- extern char logfile[];
- extern char sentfile[];
- char smarthost[SMLBUF];
-
- struct tm *gmt, *loc; /* GMT and local time structure */
- time_t now; /* current system time */
- char nows[50]; /* time in ctime format */
- char arpanows[50]; /* time in arpa format */
-
- # ifdef LOG
- void
- log(command, from, size)
- char *command, *from;
- long size;
- {
- writelog(" cmd: \"%s\" from %s",command,from);
- }
- # endif
-
- # ifdef MAILLOG
- extern char maillogfile[];
-
- void
- maillog(to_user,to_host, from, size,okay)
- char *to_user,*to_host;
- char *from;
- long size;
- char okay;
- {
- static FILE *fp=NULL;
- char *logtime, buf[SMLBUF];
-
- logtime = strcpy(buf, nows);
- logtime[19] = '\0';
- logtime += 4;
-
- fp=fopen(maillogfile,"a");
-
- if(fp)
- {
- if(to_host[0]!='\0')
- fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes\n",logtime,okay,from,to_host,to_user,size);
- else
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to_user,size);
- fclose(fp);
- }
- }
- # endif
-
- # ifdef RECORD
- FILE *
- record(command, from, size)
- char *command, *from;
- long size;
- {
- FILE *fd;
- char *logtime, buf[SMLBUF];
-
- logtime = strcpy(buf, nows);
- logtime[19] = '\0';
- logtime += 4;
-
- fd = fopen(sentfile, "a");
- if(!fd)
- return(NULL);
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- logtime, command, from, size);
- while(fgets(buf, sizeof(buf), spoolfp) != NULL) {
- (void) fputs(buf, fd);
- }
- (void) fclose(fd);
- return(NULL);
- }
- # endif
-
-
- setdates()
- {
- (void) time(&now);
- (void) strcpy(nows, ctime(&now));
- gmt = gmtime(&now);
- loc = localtime(&now);
- (void) strcpy(arpanows, arpadate(nows));
- }
-
- /*
- ** Note: This routine was taken from sendmail
- **
- ** ARPADATE -- Create date in ARPANET format
- **
- ** Parameters:
- ** ud -- unix style date string. if NULL, one is created.
- **
- ** Returns:
- ** pointer to an ARPANET date field
- **
- ** Side Effects:
- ** none
- **
- ** WARNING:
- ** date is stored in a local buffer -- subsequent
- ** calls will overwrite.
- **
- ** Bugs:
- ** Timezone is computed from local time, rather than
- ** from whereever (and whenever) the message was sent.
- ** To do better is very hard.
- **
- ** Some sites are now inserting the timezone into the
- ** local date. This routine should figure out what
- ** the format is and work appropriately.
- */
-
- #ifdef AMIGA
- extern char *_TZ;
-
- static short int DaysofMonth[]=
- { 31, 28, 31, 30,
- 31, 30, 31, 31,
- 30, 31, 30, 31 };
-
-
- static char *Weekday[]=
- {
- "Sun",
- "Mon",
- "Tue",
- "Wed",
- "Thu",
- "Fri",
- "Sat"
- };
-
- static char *Month[]=
- {
- "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
- };
-
-
- char *
- arpadate(ud)
- register char *ud;
- {
- struct tm *Time;
- time_t t;
- static char timestr[40]="";
- char *timezone;
- char *getenv();
-
- timezone=getenv("TZ");
-
- time(&t);
- Time=localtime(&t);
- if(Time)
- sprintf(timestr, "%s, %02d %s %04d %02d:%02d:%02d %s",
- Weekday[Time->tm_wday],
- Time->tm_mday,
- Month[Time->tm_mon],
- Time->tm_year+1900,
- Time->tm_hour,
- Time->tm_min,
- Time->tm_sec,
- timezone?timezone:"GMT");
- return timestr;
- }
- #else
- char *
- arpadate(ud)
- register char *ud;
- {
- register char *p;
- register char *q;
- static char b[40];
- extern char *ctime();
- register int i;
- #ifndef BSD
- extern char *tzname[];
- time_t t, time();
- #else
- /* V7 and 4BSD */
- struct timeb t;
- extern struct timeb *ftime();
- extern char *timezone();
- #endif
-
- /*
- ** Get current time.
- ** This will be used if a null argument is passed and
- ** to resolve the timezone.
- */
-
- #ifndef BSD
- (void) time(&t);
- if (ud == NULL)
- ud = ctime(&t);
- #else
- /* V7 or 4BSD */
- ftime(&t);
- if (ud == NULL)
- ud = ctime(&t.time);
- #endif
-
- /*
- ** Crack the UNIX date line in a singularly unoriginal way.
- */
-
- q = b;
-
- p = &ud[8]; /* 16 */
- if (*p == ' ')
- p++;
- else
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[4]; /* Sep */
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[22]; /* 1979 */
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[11]; /* 01:03:52 */
- for (i = 8; i > 0; i--)
- *q++ = *p++;
-
- /* -PST or -PDT */
- #ifndef BSD
- p = tzname[localtime(&t)->tm_isdst];
- #else
- p = timezone(t.timezone, localtime(&t.time)->tm_isdst);
- #endif
- if (p[3] != '\0')
- {
- /* hours from GMT */
- p += 3;
- *q++ = *p++;
- if (p[1] == ':')
- *q++ = '0';
- else
- *q++ = *p++;
- *q++ = *p++;
- p++; /* skip ``:'' */
- *q++ = *p++;
- *q++ = *p++;
- }
- else
- {
- *q++ = ' ';
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- }
-
- p = &ud[0]; /* Mon */
- *q++ = ' ';
- *q++ = '(';
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ')';
-
- *q = '\0';
- return (b);
- }
- #endif
-
- /*
- * The user name "postmaster" must be accepted regardless of what
- * combination of upper and lower case is used. This function is
- * used to convert all case variants of "postmaster" to all lower
- * case. If the user name passed in is not "postmaster", it is
- * returned unchanged.
- */
- char *
- postmaster(user)
- char *user;
- {
- static char *pm = "postmaster";
-
- if(strcmpic(user, pm) == 0) {
- return(pm);
- } else {
- return(user);
- }
- }
-
- /*
- * Return 1 iff the string is "UUCP" (ignore case).
- */
- isuucp(str)
- char *str;
- {
- if(strcmpic(str, "UUCP") == 0) {
- return(1);
- } else {
- return(0);
- }
- }
-
- /*
- ** sform(form) returns a pointer to a string that tells what 'form' means
- */
-
- char *
- sform(form)
- enum eform form;
- {
- if(form == ERROR) return("ERROR");
- if(form == LOCAL) return("LOCAL");
- if(form == DOMAIN) return("DOMAIN");
- if(form == UUCP) return("UUCP");
- if(form == ROUTE) return("ROUTE");
- return("UNKNOWN");
- }
-
- /*
- **
- ** getmynames(): what is my host name and host domain?
- **
- ** Hostname set by -h, failing that by #define HOSTNAME, failing
- ** that by gethostname() or uname().
- **
- ** Hostdomain set by -h, failing that by #define HOSTDOMAIN,
- ** failing that as hostname.MYDOM, or as just hostname.
- **
- ** See defs.h for the inside story.
- **
- */
-
- getmynames()
- {
- #ifdef HOSTNAME
- if (!*hostname)
- (void) strcpy(hostname, HOSTNAME);
- #endif
- #ifdef GETHOSTNAME
- if (!*hostname)
- gethostname(hostname, SMLBUF - 1);
- #endif
- #ifdef UNAME
- if (!*hostname) {
- struct utsname site;
-
- if (uname(&site) < 0)
- error(EX_SOFTWARE, "uname() call failed", 0);
- (void) strcpy(hostname, site.nodename);
- }
- #endif
- if (!*hostname)
- error(EX_SOFTWARE, "can't determine hostname.\n", 0);
- #ifdef HOSTDOMAIN
- if (!*hostdomain)
- (void) strcpy(hostdomain, HOSTDOMAIN);
- #endif
- #ifdef MYDOM
- if (!*hostdomain)
- (void) strcat(strcpy(hostdomain, hostname), MYDOM);
- #endif
- #ifdef AMIGA
- if (!*hostdomain)
- {
- (void) getdomainname(hostdomain, SMLBUF - 1);
- strins(hostdomain,hostname);
- }
- #endif
- if (!*hostdomain)
- (void) strcpy(hostdomain, hostname);
-
- (void) strcat(strcpy(hostuucp, hostname), ".UUCP");
- #ifdef AMIGA
- (void) getsmarthost(smarthost,SMLBUF - 1);
- #endif
-
- }
- @
-
-
- 1.4
- log
- @enforcer hit in record() removed
- @
- text
- @d19 3
- d34 1
- a34 1
- static char *rcsid="$Id: misc.c,v 1.3 1993/09/18 16:47:47 Aussem Exp Aussem $";
- d77 2
- d80 2
- a81 2
- maillog(to, from, size,okay)
- char *to;
- a85 1
- extern char maillogfile[];
- d93 1
- a93 2
- if(!fp)
- fp=fopen(maillogfile,"a");
- d96 7
- a102 2
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to,size);
-
- @
-
-
- 1.3
- log
- @insert GNU license text in the header
- @
- text
- @d19 3
- d31 1
- a31 1
- static char *rcsid="$Id: misc.c,v 1.2 1993/09/10 01:51:50 Aussem Exp Aussem $";
- d112 4
- a115 4
- if (fd != NULL) {
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- logtime, command, from, size);
- }
- @
-
-
- 1.2
- log
- @new support for wCNews styled logfile with maillog()
- @
- text
- @d2 1
- a2 1
- * Miscellaneous support functions for smail/rmail
- d4 14
- d19 3
- d28 1
- a28 1
- static char *rcsid="$Id: misc.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d4 3
- a6 1
- * $Log$
- d8 1
- d11 1
- a11 1
- static char *rcsid="$Id$";
- a48 1
- #ifdef AMIGA
- d50 21
- a70 4
- #else
- FILE *fd;
- char *logtime, tbuf[50];
- int cmask;
- d72 2
- a73 3
- logtime = strcpy(tbuf, nows);
- logtime[16] = '\0';
- logtime += 4;
- a74 9
- cmask = umask(0);
- fd = fopen(logfile, "a");
- (void) umask(cmask);
- if (fd != NULL) {
- (void) fprintf(fd, "%s\t%ld\t%s\t%s\n",
- logtime, size, from, command);
- (void) fclose(fd);
- }
- #endif
- d88 1
- a88 1
- logtime[16] = 0;
- d93 1
- a93 1
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- @
-