122698Sdist /* 234920Sbostic * Copyright (c) 1983 Eric P. Allman 333728Sbostic * Copyright (c) 1988 Regents of the University of California. 433728Sbostic * All rights reserved. 533728Sbostic * 642825Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822698Sdist 922698Sdist #ifndef lint 10*46928Sbostic static char sccsid[] = "@(#)conf.c 5.27 (Berkeley) 03/02/91"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1314881Seric # include <sys/ioctl.h> 1424943Seric # include <sys/param.h> 1536928Sbostic # include <pwd.h> 163309Seric # include "sendmail.h" 1740980Sbostic # include "pathnames.h" 18404Seric 19294Seric /* 203309Seric ** CONF.C -- Sendmail Configuration Tables. 21294Seric ** 22294Seric ** Defines the configuration of this installation. 23294Seric ** 241388Seric ** Compilation Flags: 2514872Seric ** VMUNIX -- running on a Berkeley UNIX system. 26294Seric ** 271388Seric ** Configuration Variables: 282897Seric ** HdrInfo -- a table describing well-known header fields. 292897Seric ** Each entry has the field name and some flags, 304147Seric ** which are described in sendmail.h. 314093Seric ** 324093Seric ** Notes: 334093Seric ** I have tried to put almost all the reasonable 344093Seric ** configuration information into the configuration 354093Seric ** file read at runtime. My intent is that anything 364093Seric ** here is a function of the version of UNIX you 374093Seric ** are running, or is really static -- for example 384093Seric ** the headers are a superset of widely used 394093Seric ** protocols. If you find yourself playing with 404093Seric ** this file too much, you may be making a mistake! 41294Seric */ 42294Seric 43294Seric 44294Seric 45294Seric 464437Seric /* 472897Seric ** Header info table 483057Seric ** Final (null) entry contains the flags used for any other field. 494147Seric ** 504147Seric ** Not all of these are actually handled specially by sendmail 514147Seric ** at this time. They are included as placeholders, to let 524147Seric ** you know that "someday" I intend to have sendmail do 534147Seric ** something with them. 542897Seric */ 552897Seric 562897Seric struct hdrinfo HdrInfo[] = 572897Seric { 588060Seric /* originator fields, most to least significant */ 5911417Seric "resent-sender", H_FROM|H_RESENT, 6011417Seric "resent-from", H_FROM|H_RESENT, 6125686Seric "resent-reply-to", H_FROM|H_RESENT, 629055Seric "sender", H_FROM, 639055Seric "from", H_FROM, 6425686Seric "reply-to", H_FROM, 659055Seric "full-name", H_ACHECK, 669055Seric "return-receipt-to", H_FROM, 679055Seric "errors-to", H_FROM, 688060Seric /* destination fields */ 699055Seric "to", H_RCPT, 7011417Seric "resent-to", H_RCPT|H_RESENT, 719055Seric "cc", H_RCPT, 7211417Seric "resent-cc", H_RCPT|H_RESENT, 739055Seric "bcc", H_RCPT|H_ACHECK, 7411417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 758060Seric /* message identification and control */ 7611417Seric "message-id", 0, 7711417Seric "resent-message-id", H_RESENT, 789055Seric "message", H_EOH, 799055Seric "text", H_EOH, 8011417Seric /* date fields */ 8111417Seric "date", 0, 8211417Seric "resent-date", H_RESENT, 838060Seric /* trace fields */ 849055Seric "received", H_TRACE|H_FORCE, 859055Seric "via", H_TRACE|H_FORCE, 869055Seric "mail-from", H_TRACE|H_FORCE, 878060Seric 889055Seric NULL, 0, 892897Seric }; 904166Seric 914166Seric 924166Seric /* 934166Seric ** ARPANET error message numbers. 944166Seric */ 954166Seric 967956Seric char Arpa_Info[] = "050"; /* arbitrary info */ 977956Seric char Arpa_TSyserr[] = "451"; /* some (transient) system error */ 987956Seric char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ 997956Seric char Arpa_Usrerr[] = "554"; /* some (fatal) user error */ 1004282Seric 1014282Seric 1024282Seric 1034282Seric /* 1044282Seric ** Location of system files/databases/etc. 1054282Seric */ 1064282Seric 10740980Sbostic char *ConfFile = _PATH_SENDMAILCF; /* runtime configuration */ 10840980Sbostic char *FreezeFile = _PATH_SENDMAILFC; /* frozen version of above */ 1099039Seric 1109064Seric 1119064Seric 1129039Seric /* 11324943Seric ** Miscellaneous stuff. 1149039Seric */ 1159039Seric 11624943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 11740938Srick extern int la; /* load average */ 11824943Seric /* 11924943Seric ** SETDEFAULTS -- set default values 12024943Seric ** 12124943Seric ** Because of the way freezing is done, these must be initialized 12224943Seric ** using direct code. 12324943Seric ** 12424943Seric ** Parameters: 12524943Seric ** none. 12624943Seric ** 12724943Seric ** Returns: 12824943Seric ** none. 12924943Seric ** 13024943Seric ** Side Effects: 13124943Seric ** Initializes a bunch of global variables to their 13224943Seric ** default values. 13324943Seric */ 13424943Seric 13524943Seric setdefaults() 13624943Seric { 13724943Seric QueueLA = 8; 13824943Seric QueueFactor = 10000; 13924943Seric RefuseLA = 12; 14024943Seric SpaceSub = ' '; 14124981Seric WkRecipFact = 1000; 14224981Seric WkClassFact = 1800; 14325812Seric WkTimeFact = 9000; 14424981Seric FileMode = 0644; 14524981Seric DefUid = 1; 14624981Seric DefGid = 1; 14740973Sbostic setdefuser(); 14824943Seric } 149294Seric 15040973Sbostic 1514326Seric /* 15240973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 15340973Sbostic */ 15440973Sbostic 15540973Sbostic setdefuser() 15640973Sbostic { 15740973Sbostic struct passwd *defpwent; 15840973Sbostic 15940973Sbostic if (DefUser != NULL) 16040973Sbostic free(DefUser); 16140973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 16240973Sbostic DefUser = newstr(defpwent->pw_name); 16340973Sbostic else 16440973Sbostic DefUser = newstr("nobody"); 16540973Sbostic } 16640973Sbostic 16740973Sbostic 16840973Sbostic /* 1694326Seric ** GETRUID -- get real user id (V7) 1704326Seric */ 1714326Seric 1724326Seric getruid() 1734326Seric { 1749274Seric if (OpMode == MD_DAEMON) 1754536Seric return (RealUid); 1764536Seric else 1774536Seric return (getuid()); 1784326Seric } 1794326Seric 1804326Seric 1814326Seric /* 1824326Seric ** GETRGID -- get real group id (V7). 1834326Seric */ 1844326Seric 1854326Seric getrgid() 1864326Seric { 1879274Seric if (OpMode == MD_DAEMON) 1884536Seric return (RealGid); 1894536Seric else 1904536Seric return (getgid()); 1914326Seric } 1924326Seric 19333936Sbostic /* 1949369Seric ** USERNAME -- return the user id of the logged in user. 1959369Seric ** 1969369Seric ** Parameters: 1979369Seric ** none. 1989369Seric ** 1999369Seric ** Returns: 2009369Seric ** The login name of the logged in user. 2019369Seric ** 2029369Seric ** Side Effects: 2039369Seric ** none. 2049369Seric ** 2059369Seric ** Notes: 2069369Seric ** The return value is statically allocated. 2079369Seric */ 2089369Seric 2099369Seric char * 2109369Seric username() 2119369Seric { 21217469Seric static char *myname = NULL; 2139369Seric extern char *getlogin(); 21419904Smiriam register struct passwd *pw; 2159369Seric 21617469Seric /* cache the result */ 21717469Seric if (myname == NULL) 21817469Seric { 21917469Seric myname = getlogin(); 22017469Seric if (myname == NULL || myname[0] == '\0') 22117469Seric { 22217469Seric 22317469Seric pw = getpwuid(getruid()); 22417469Seric if (pw != NULL) 22540993Sbostic myname = newstr(pw->pw_name); 22617469Seric } 22719904Smiriam else 22819904Smiriam { 22919873Smiriam 23040993Sbostic myname = newstr(myname); 23140993Sbostic if ((pw = getpwnam(myname)) == NULL || 23240993Sbostic getuid() != pw->pw_uid) 23319904Smiriam { 23419873Smiriam pw = getpwuid(getuid()); 23524945Seric if (pw != NULL) 23640993Sbostic myname = newstr(pw->pw_name); 23719873Smiriam } 23819873Smiriam } 23917469Seric if (myname == NULL || myname[0] == '\0') 24017469Seric { 24117469Seric syserr("Who are you?"); 24217469Seric myname = "postmaster"; 24317469Seric } 24417469Seric } 24517469Seric 24617469Seric return (myname); 2479369Seric } 2489369Seric /* 2494190Seric ** TTYPATH -- Get the path of the user's tty 250294Seric ** 251294Seric ** Returns the pathname of the user's tty. Returns NULL if 252294Seric ** the user is not logged in or if s/he has write permission 253294Seric ** denied. 254294Seric ** 255294Seric ** Parameters: 256294Seric ** none 257294Seric ** 258294Seric ** Returns: 259294Seric ** pathname of the user's tty. 260294Seric ** NULL if not logged in or write permission denied. 261294Seric ** 262294Seric ** Side Effects: 263294Seric ** none. 264294Seric ** 265294Seric ** WARNING: 266294Seric ** Return value is in a local buffer. 267294Seric ** 268294Seric ** Called By: 269294Seric ** savemail 270294Seric */ 271294Seric 272294Seric # include <sys/stat.h> 273294Seric 274294Seric char * 275294Seric ttypath() 276294Seric { 277294Seric struct stat stbuf; 278294Seric register char *pathn; 279294Seric extern char *ttyname(); 2804081Seric extern char *getlogin(); 281294Seric 282294Seric /* compute the pathname of the controlling tty */ 2839369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 2849369Seric (pathn = ttyname(0)) == NULL) 285294Seric { 286294Seric errno = 0; 287294Seric return (NULL); 288294Seric } 289294Seric 290294Seric /* see if we have write permission */ 2912967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 292294Seric { 293294Seric errno = 0; 294294Seric return (NULL); 295294Seric } 296294Seric 297294Seric /* see if the user is logged in */ 298294Seric if (getlogin() == NULL) 299294Seric return (NULL); 300294Seric 301294Seric /* looks good */ 302294Seric return (pathn); 303294Seric } 3042967Seric /* 3052967Seric ** CHECKCOMPAT -- check for From and To person compatible. 3062967Seric ** 3072967Seric ** This routine can be supplied on a per-installation basis 3082967Seric ** to determine whether a person is allowed to send a message. 3092967Seric ** This allows restriction of certain types of internet 3102967Seric ** forwarding or registration of users. 3112967Seric ** 3122967Seric ** If the hosts are found to be incompatible, an error 3132967Seric ** message should be given using "usrerr" and FALSE should 3142967Seric ** be returned. 3152967Seric ** 3164288Seric ** 'NoReturn' can be set to suppress the return-to-sender 3174288Seric ** function; this should be done on huge messages. 3184288Seric ** 3192967Seric ** Parameters: 3202967Seric ** to -- the person being sent to. 3212967Seric ** 3222967Seric ** Returns: 3232967Seric ** TRUE -- ok to send. 3242967Seric ** FALSE -- not ok. 3252967Seric ** 3262967Seric ** Side Effects: 3272967Seric ** none (unless you include the usrerr stuff) 3282967Seric */ 3292967Seric 3302967Seric bool 3312967Seric checkcompat(to) 3322967Seric register ADDRESS *to; 3332967Seric { 33412133Seric # ifdef lint 33512133Seric if (to == NULL) 33612133Seric to++; 33712133Seric # endif lint 33810698Seric # ifdef EXAMPLE_CODE 33910698Seric /* this code is intended as an example only */ 3404437Seric register STAB *s; 3414437Seric 3424437Seric s = stab("arpa", ST_MAILER, ST_FIND); 3439369Seric if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && 3449369Seric to->q_mailer == s->s_mailer) 3454437Seric { 3464437Seric usrerr("No ARPA mail through this machine: see your system administration"); 34710698Seric /* NoReturn = TRUE; to supress return copy */ 3484437Seric return (FALSE); 3494437Seric } 35010698Seric # endif EXAMPLE_CODE 3512967Seric return (TRUE); 3522967Seric } 3539369Seric /* 3549369Seric ** HOLDSIGS -- arrange to hold all signals 3559369Seric ** 3569369Seric ** Parameters: 3579369Seric ** none. 3589369Seric ** 3599369Seric ** Returns: 3609369Seric ** none. 3619369Seric ** 3629369Seric ** Side Effects: 3639369Seric ** Arranges that signals are held. 3649369Seric */ 3659369Seric 3669369Seric holdsigs() 3679369Seric { 3689369Seric } 3699369Seric /* 3709369Seric ** RLSESIGS -- arrange to release all signals 3719369Seric ** 3729369Seric ** This undoes the effect of holdsigs. 3739369Seric ** 3749369Seric ** Parameters: 3759369Seric ** none. 3769369Seric ** 3779369Seric ** Returns: 3789369Seric ** none. 3799369Seric ** 3809369Seric ** Side Effects: 3819369Seric ** Arranges that signals are released. 3829369Seric */ 3839369Seric 3849369Seric rlsesigs() 3859369Seric { 3869369Seric } 38714872Seric /* 38814872Seric ** GETLA -- get the current load average 38914872Seric ** 39014881Seric ** This code stolen from la.c. 39114881Seric ** 39214872Seric ** Parameters: 39314872Seric ** none. 39414872Seric ** 39514872Seric ** Returns: 39614872Seric ** The current load average as an integer. 39714872Seric ** 39814872Seric ** Side Effects: 39914872Seric ** none. 40014872Seric */ 40114872Seric 40238196Smckusick #ifndef sun 40314872Seric 40438196Smckusick getla() 40538196Smckusick { 40638196Smckusick double avenrun[3]; 40738196Smckusick 40838196Smckusick if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 40938196Smckusick return (0); 41038196Smckusick return ((int) (avenrun[0] + 0.5)); 41138196Smckusick } 41238196Smckusick 41338196Smckusick #else /* sun */ 41438196Smckusick 41514872Seric #include <nlist.h> 41614872Seric 41714872Seric struct nlist Nl[] = 41814872Seric { 41914872Seric { "_avenrun" }, 42014872Seric #define X_AVENRUN 0 42114872Seric { 0 }, 42214872Seric }; 42314872Seric 42440930Srick 42540930Srick extern int la; 42640930Srick 42714872Seric getla() 42814872Seric { 42914872Seric static int kmem = -1; 43024943Seric long avenrun[3]; 43125615Seric extern off_t lseek(); 43214872Seric 43314872Seric if (kmem < 0) 43414872Seric { 43524945Seric kmem = open("/dev/kmem", 0, 0); 43614872Seric if (kmem < 0) 43714872Seric return (-1); 43823118Seric (void) ioctl(kmem, (int) FIOCLEX, (char *) 0); 43914872Seric nlist("/vmunix", Nl); 44014872Seric if (Nl[0].n_type == 0) 44114872Seric return (-1); 44214872Seric } 44324945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 44423118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 44519967Seric { 44619967Seric /* thank you Ian */ 44719967Seric return (-1); 44819967Seric } 44924943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 45014872Seric } 45114872Seric 45238196Smckusick #endif /* sun */ 45324943Seric /* 45424943Seric ** SHOULDQUEUE -- should this message be queued or sent? 45524943Seric ** 45624943Seric ** Compares the message cost to the load average to decide. 45724943Seric ** 45824943Seric ** Parameters: 45924943Seric ** pri -- the priority of the message in question. 46024943Seric ** 46124943Seric ** Returns: 46224943Seric ** TRUE -- if this message should be queued up for the 46324943Seric ** time being. 46424943Seric ** FALSE -- if the load is low enough to send this message. 46524943Seric ** 46624943Seric ** Side Effects: 46724943Seric ** none. 46824943Seric */ 46924943Seric 47024943Seric bool 47124943Seric shouldqueue(pri) 47224943Seric long pri; 47324943Seric { 47424943Seric if (la < QueueLA) 47524943Seric return (FALSE); 47624943Seric return (pri > (QueueFactor / (la - QueueLA + 1))); 47724943Seric } 47824943Seric /* 47924943Seric ** SETPROCTITLE -- set process title for ps 48024943Seric ** 48124943Seric ** Parameters: 48224943Seric ** fmt -- a printf style format string. 48324943Seric ** a, b, c -- possible parameters to fmt. 48424943Seric ** 48524943Seric ** Returns: 48624943Seric ** none. 48724943Seric ** 48824943Seric ** Side Effects: 48924943Seric ** Clobbers argv of our main procedure so ps(1) will 49024943Seric ** display the title. 49124943Seric */ 49224943Seric 49324943Seric /*VARARGS1*/ 49424943Seric setproctitle(fmt, a, b, c) 49524943Seric char *fmt; 49624943Seric { 49724943Seric # ifdef SETPROCTITLE 49824943Seric register char *p; 49925049Seric register int i; 50024943Seric extern char **Argv; 50124943Seric extern char *LastArgv; 50225049Seric char buf[MAXLINE]; 50324943Seric 50425049Seric (void) sprintf(buf, fmt, a, b, c); 50524943Seric 50624943Seric /* make ps print "(sendmail)" */ 50725049Seric p = Argv[0]; 50824943Seric *p++ = '-'; 50924943Seric 51025049Seric i = strlen(buf); 51125049Seric if (i > LastArgv - p - 2) 51225049Seric { 51325049Seric i = LastArgv - p - 2; 51425049Seric buf[i] = '\0'; 51525049Seric } 51625049Seric (void) strcpy(p, buf); 51725049Seric p += i; 51824943Seric while (p < LastArgv) 51924943Seric *p++ = ' '; 52024943Seric # endif SETPROCTITLE 52124943Seric } 52225698Seric /* 52325698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 52425698Seric ** 52525698Seric ** Parameters: 52625698Seric ** none. 52725698Seric ** 52825698Seric ** Returns: 52925698Seric ** none. 53025698Seric ** 53125698Seric ** Side Effects: 53225698Seric ** Picks up extant zombies. 53325698Seric */ 53425698Seric 53525698Seric # ifdef VMUNIX 53625698Seric # include <sys/wait.h> 53725698Seric # endif VMUNIX 53825698Seric 539*46928Sbostic void 54025698Seric reapchild() 54125698Seric { 54225698Seric # ifdef WNOHANG 54325698Seric union wait status; 54425698Seric 545*46928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 54625698Seric continue; 54725698Seric # else WNOHANG 54825698Seric auto int status; 54925698Seric 550*46928Sbostic while (wait((int *)&status) > 0) 55125698Seric continue; 55225698Seric # endif WNOHANG 55325698Seric } 554