1294Seric # include <pwd.h> 23309Seric # include "sendmail.h" 3404Seric 4294Seric /* 53309Seric ** CONF.C -- Sendmail Configuration Tables. 6294Seric ** 7294Seric ** Defines the configuration of this installation. 8294Seric ** 91388Seric ** Compilation Flags: 101388Seric ** V6 -- running on a version 6 system. This determines 111388Seric ** whether to define certain routines between 121388Seric ** the two systems. If you are running a funny 131388Seric ** system, e.g., V6 with long tty names, this 141388Seric ** should be checked carefully. 1514872Seric ** VMUNIX -- running on a Berkeley UNIX system. 16294Seric ** 171388Seric ** Configuration Variables: 182897Seric ** HdrInfo -- a table describing well-known header fields. 192897Seric ** Each entry has the field name and some flags, 204147Seric ** which are described in sendmail.h. 214093Seric ** 224093Seric ** Notes: 234093Seric ** I have tried to put almost all the reasonable 244093Seric ** configuration information into the configuration 254093Seric ** file read at runtime. My intent is that anything 264093Seric ** here is a function of the version of UNIX you 274093Seric ** are running, or is really static -- for example 284093Seric ** the headers are a superset of widely used 294093Seric ** protocols. If you find yourself playing with 304093Seric ** this file too much, you may be making a mistake! 31294Seric */ 32294Seric 33294Seric 34294Seric 35294Seric 36*14880Seric SCCSID(@(#)conf.c 4.3 08/28/83); 374437Seric 384437Seric 394437Seric 404437Seric /* 412897Seric ** Header info table 423057Seric ** Final (null) entry contains the flags used for any other field. 434147Seric ** 444147Seric ** Not all of these are actually handled specially by sendmail 454147Seric ** at this time. They are included as placeholders, to let 464147Seric ** you know that "someday" I intend to have sendmail do 474147Seric ** something with them. 482897Seric */ 492897Seric 502897Seric struct hdrinfo HdrInfo[] = 512897Seric { 528060Seric /* originator fields, most to least significant */ 5311417Seric "resent-sender", H_FROM|H_RESENT, 5411417Seric "resent-from", H_FROM|H_RESENT, 559055Seric "sender", H_FROM, 569055Seric "from", H_FROM, 579055Seric "full-name", H_ACHECK, 589055Seric "return-receipt-to", H_FROM, 599055Seric "errors-to", H_FROM, 608060Seric /* destination fields */ 619055Seric "to", H_RCPT, 6211417Seric "resent-to", H_RCPT|H_RESENT, 639055Seric "cc", H_RCPT, 6411417Seric "resent-cc", H_RCPT|H_RESENT, 659055Seric "bcc", H_RCPT|H_ACHECK, 6611417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 678060Seric /* message identification and control */ 6811417Seric "message-id", 0, 6911417Seric "resent-message-id", H_RESENT, 709055Seric "message", H_EOH, 719055Seric "text", H_EOH, 7211417Seric /* date fields */ 7311417Seric "date", 0, 7411417Seric "resent-date", H_RESENT, 758060Seric /* trace fields */ 769055Seric "received", H_TRACE|H_FORCE, 779055Seric "via", H_TRACE|H_FORCE, 789055Seric "mail-from", H_TRACE|H_FORCE, 798060Seric 809055Seric NULL, 0, 812897Seric }; 824166Seric 834166Seric 844166Seric /* 854166Seric ** ARPANET error message numbers. 864166Seric */ 874166Seric 887956Seric char Arpa_Info[] = "050"; /* arbitrary info */ 897956Seric char Arpa_TSyserr[] = "451"; /* some (transient) system error */ 907956Seric char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ 917956Seric char Arpa_Usrerr[] = "554"; /* some (fatal) user error */ 924282Seric 934282Seric 944282Seric 954282Seric /* 964282Seric ** Location of system files/databases/etc. 974282Seric */ 984282Seric 994282Seric char *ConfFile = "/usr/lib/sendmail.cf"; /* runtime configuration */ 1009064Seric char *FreezeFile = "/usr/lib/sendmail.fc"; /* frozen version of above */ 1019039Seric 1029064Seric 1039064Seric 1049039Seric /* 1059039Seric ** Some other configuration.... 1069039Seric */ 1079039Seric 10814872Seric char SpaceSub = '.'; /* character to replace <lwsp> in addrs */ 109*14880Seric int QueueLA = 8; /* load avg > QueueLA -> just queue */ 110*14880Seric int RefuseLA = 12; /* load avg > RefuseLA -> refuse connections */ 111294Seric 112294Seric # ifdef V6 113294Seric /* 1144190Seric ** TTYNAME -- return name of terminal. 115294Seric ** 116294Seric ** Parameters: 1174190Seric ** fd -- file descriptor to check. 118294Seric ** 119294Seric ** Returns: 1204190Seric ** pointer to full path of tty. 1214190Seric ** NULL if no tty. 122294Seric ** 123294Seric ** Side Effects: 124294Seric ** none. 125294Seric */ 126294Seric 127294Seric char * 1284190Seric ttyname(fd) 1294190Seric int fd; 130294Seric { 1314190Seric register char tn; 132294Seric static char pathn[] = "/dev/ttyx"; 133294Seric 134294Seric /* compute the pathname of the controlling tty */ 1354190Seric if ((tn = ttyn(fd)) == NULL) 136294Seric { 137294Seric errno = 0; 138294Seric return (NULL); 139294Seric } 1404190Seric pathn[8] = tn; 141294Seric return (pathn); 142294Seric } 143294Seric /* 144294Seric ** FDOPEN -- Open a stdio file given an open file descriptor. 145294Seric ** 146294Seric ** This is included here because it is standard in v7, but we 147294Seric ** need it in v6. 148294Seric ** 149294Seric ** Algorithm: 150294Seric ** Open /dev/null to create a descriptor. 151294Seric ** Close that descriptor. 152294Seric ** Copy the existing fd into the descriptor. 153294Seric ** 154294Seric ** Parameters: 155294Seric ** fd -- the open file descriptor. 156294Seric ** type -- "r", "w", or whatever. 157294Seric ** 158294Seric ** Returns: 159294Seric ** The file descriptor it creates. 160294Seric ** 161294Seric ** Side Effects: 162294Seric ** none 163294Seric ** 164294Seric ** Called By: 165294Seric ** deliver 166294Seric ** 167294Seric ** Notes: 168294Seric ** The mode of fd must match "type". 169294Seric */ 170294Seric 171294Seric FILE * 172294Seric fdopen(fd, type) 173294Seric int fd; 174294Seric char *type; 175294Seric { 176294Seric register FILE *f; 177294Seric 178294Seric f = fopen("/dev/null", type); 1794081Seric (void) close(fileno(f)); 180294Seric fileno(f) = fd; 181294Seric return (f); 182294Seric } 183294Seric /* 184294Seric ** INDEX -- Return pointer to character in string 185294Seric ** 186294Seric ** For V7 compatibility. 187294Seric ** 188294Seric ** Parameters: 189294Seric ** s -- a string to scan. 190294Seric ** c -- a character to look for. 191294Seric ** 192294Seric ** Returns: 193294Seric ** If c is in s, returns the address of the first 194294Seric ** instance of c in s. 195294Seric ** NULL if c is not in s. 196294Seric ** 197294Seric ** Side Effects: 198294Seric ** none. 199294Seric */ 200294Seric 2014437Seric char * 202294Seric index(s, c) 203294Seric register char *s; 204294Seric register char c; 205294Seric { 206294Seric while (*s != '\0') 207294Seric { 208294Seric if (*s++ == c) 209294Seric return (--s); 210294Seric } 211294Seric return (NULL); 212294Seric } 2134326Seric /* 2144326Seric ** UMASK -- fake the umask system call. 2154326Seric ** 2164326Seric ** Since V6 always acts like the umask is zero, we will just 2174326Seric ** assume the same thing. 2184326Seric */ 2194326Seric 2204326Seric /*ARGSUSED*/ 2214326Seric umask(nmask) 2224326Seric { 2234326Seric return (0); 2244326Seric } 2254326Seric 2264326Seric 2274326Seric /* 2284326Seric ** GETRUID -- get real user id. 2294326Seric */ 2304326Seric 2314326Seric getruid() 2324326Seric { 2334326Seric return (getuid() & 0377); 2344326Seric } 2354326Seric 2364326Seric 2374326Seric /* 2384326Seric ** GETRGID -- get real group id. 2394326Seric */ 2404326Seric 2414326Seric getrgid() 2424326Seric { 2434326Seric return (getgid() & 0377); 2444326Seric } 2454326Seric 2464326Seric 2474326Seric /* 2484326Seric ** GETEUID -- get effective user id. 2494326Seric */ 2504326Seric 2514326Seric geteuid() 2524326Seric { 2534326Seric return ((getuid() >> 8) & 0377); 2544326Seric } 2554326Seric 2564326Seric 2574326Seric /* 2584326Seric ** GETEGID -- get effective group id. 2594326Seric */ 2604326Seric 2614326Seric getegid() 2624326Seric { 2634326Seric return ((getgid() >> 8) & 0377); 2644326Seric } 2654326Seric 266294Seric # endif V6 2674326Seric 2684326Seric # ifndef V6 2694326Seric 2704326Seric /* 2714326Seric ** GETRUID -- get real user id (V7) 2724326Seric */ 2734326Seric 2744326Seric getruid() 2754326Seric { 2769274Seric if (OpMode == MD_DAEMON) 2774536Seric return (RealUid); 2784536Seric else 2794536Seric return (getuid()); 2804326Seric } 2814326Seric 2824326Seric 2834326Seric /* 2844326Seric ** GETRGID -- get real group id (V7). 2854326Seric */ 2864326Seric 2874326Seric getrgid() 2884326Seric { 2899274Seric if (OpMode == MD_DAEMON) 2904536Seric return (RealGid); 2914536Seric else 2924536Seric return (getgid()); 2934326Seric } 2944326Seric 2954326Seric # endif V6 2964190Seric /* 2979369Seric ** USERNAME -- return the user id of the logged in user. 2989369Seric ** 2999369Seric ** Parameters: 3009369Seric ** none. 3019369Seric ** 3029369Seric ** Returns: 3039369Seric ** The login name of the logged in user. 3049369Seric ** 3059369Seric ** Side Effects: 3069369Seric ** none. 3079369Seric ** 3089369Seric ** Notes: 3099369Seric ** The return value is statically allocated. 3109369Seric */ 3119369Seric 3129369Seric char * 3139369Seric username() 3149369Seric { 3159369Seric extern char *getlogin(); 3169369Seric 3179369Seric return (getlogin()); 3189369Seric } 3199369Seric /* 3204190Seric ** TTYPATH -- Get the path of the user's tty 321294Seric ** 322294Seric ** Returns the pathname of the user's tty. Returns NULL if 323294Seric ** the user is not logged in or if s/he has write permission 324294Seric ** denied. 325294Seric ** 326294Seric ** Parameters: 327294Seric ** none 328294Seric ** 329294Seric ** Returns: 330294Seric ** pathname of the user's tty. 331294Seric ** NULL if not logged in or write permission denied. 332294Seric ** 333294Seric ** Side Effects: 334294Seric ** none. 335294Seric ** 336294Seric ** WARNING: 337294Seric ** Return value is in a local buffer. 338294Seric ** 339294Seric ** Called By: 340294Seric ** savemail 341294Seric */ 342294Seric 343294Seric # include <sys/stat.h> 344294Seric 345294Seric char * 346294Seric ttypath() 347294Seric { 348294Seric struct stat stbuf; 349294Seric register char *pathn; 350294Seric extern char *ttyname(); 3514081Seric extern char *getlogin(); 352294Seric 353294Seric /* compute the pathname of the controlling tty */ 3549369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 3559369Seric (pathn = ttyname(0)) == NULL) 356294Seric { 357294Seric errno = 0; 358294Seric return (NULL); 359294Seric } 360294Seric 361294Seric /* see if we have write permission */ 3622967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 363294Seric { 364294Seric errno = 0; 365294Seric return (NULL); 366294Seric } 367294Seric 368294Seric /* see if the user is logged in */ 369294Seric if (getlogin() == NULL) 370294Seric return (NULL); 371294Seric 372294Seric /* looks good */ 373294Seric return (pathn); 374294Seric } 3752967Seric /* 3762967Seric ** CHECKCOMPAT -- check for From and To person compatible. 3772967Seric ** 3782967Seric ** This routine can be supplied on a per-installation basis 3792967Seric ** to determine whether a person is allowed to send a message. 3802967Seric ** This allows restriction of certain types of internet 3812967Seric ** forwarding or registration of users. 3822967Seric ** 3832967Seric ** If the hosts are found to be incompatible, an error 3842967Seric ** message should be given using "usrerr" and FALSE should 3852967Seric ** be returned. 3862967Seric ** 3874288Seric ** 'NoReturn' can be set to suppress the return-to-sender 3884288Seric ** function; this should be done on huge messages. 3894288Seric ** 3902967Seric ** Parameters: 3912967Seric ** to -- the person being sent to. 3922967Seric ** 3932967Seric ** Returns: 3942967Seric ** TRUE -- ok to send. 3952967Seric ** FALSE -- not ok. 3962967Seric ** 3972967Seric ** Side Effects: 3982967Seric ** none (unless you include the usrerr stuff) 3992967Seric */ 4002967Seric 4012967Seric bool 4022967Seric checkcompat(to) 4032967Seric register ADDRESS *to; 4042967Seric { 40512133Seric # ifdef lint 40612133Seric if (to == NULL) 40712133Seric to++; 40812133Seric # endif lint 40910698Seric # ifdef EXAMPLE_CODE 41010698Seric /* this code is intended as an example only */ 4114437Seric register STAB *s; 4124437Seric 4134437Seric s = stab("arpa", ST_MAILER, ST_FIND); 4149369Seric if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && 4159369Seric to->q_mailer == s->s_mailer) 4164437Seric { 4174437Seric usrerr("No ARPA mail through this machine: see your system administration"); 41810698Seric /* NoReturn = TRUE; to supress return copy */ 4194437Seric return (FALSE); 4204437Seric } 42110698Seric # endif EXAMPLE_CODE 4222967Seric return (TRUE); 4232967Seric } 4249369Seric /* 4259369Seric ** HOLDSIGS -- arrange to hold all signals 4269369Seric ** 4279369Seric ** Parameters: 4289369Seric ** none. 4299369Seric ** 4309369Seric ** Returns: 4319369Seric ** none. 4329369Seric ** 4339369Seric ** Side Effects: 4349369Seric ** Arranges that signals are held. 4359369Seric */ 4369369Seric 4379369Seric holdsigs() 4389369Seric { 4399369Seric } 4409369Seric /* 4419369Seric ** RLSESIGS -- arrange to release all signals 4429369Seric ** 4439369Seric ** This undoes the effect of holdsigs. 4449369Seric ** 4459369Seric ** Parameters: 4469369Seric ** none. 4479369Seric ** 4489369Seric ** Returns: 4499369Seric ** none. 4509369Seric ** 4519369Seric ** Side Effects: 4529369Seric ** Arranges that signals are released. 4539369Seric */ 4549369Seric 4559369Seric rlsesigs() 4569369Seric { 4579369Seric } 45814872Seric /* 45914872Seric ** GETLA -- get the current load average 46014872Seric ** 46114872Seric ** Parameters: 46214872Seric ** none. 46314872Seric ** 46414872Seric ** Returns: 46514872Seric ** The current load average as an integer. 46614872Seric ** 46714872Seric ** Side Effects: 46814872Seric ** none. 46914872Seric */ 47014872Seric 47114872Seric #ifdef VMUNIX 47214872Seric 47314872Seric #include <nlist.h> 47414872Seric 47514872Seric struct nlist Nl[] = 47614872Seric { 47714872Seric { "_avenrun" }, 47814872Seric #define X_AVENRUN 0 47914872Seric { 0 }, 48014872Seric }; 48114872Seric 48214872Seric getla() 48314872Seric { 48414872Seric static int kmem = -1; 48514872Seric double avenrun[3]; 48614872Seric 48714872Seric if (kmem < 0) 48814872Seric { 48914872Seric kmem = open("/dev/kmem", 0); 49014872Seric if (kmem < 0) 49114872Seric return (-1); 49214872Seric nlist("/vmunix", Nl); 49314872Seric if (Nl[0].n_type == 0) 49414872Seric return (-1); 49514872Seric } 49614872Seric (void) lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0); 49714872Seric (void) read(kmem, avenrun, sizeof(avenrun)); 49814872Seric return ((int) (avenrun[0] + 0.5)); 49914872Seric } 50014872Seric 50114872Seric #else VMUNIX 50214872Seric 50314872Seric getla() 50414872Seric { 50514872Seric return (0); 50614872Seric } 50714872Seric 50814872Seric #endif VMUNIX 509