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