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. 15294Seric ** 161388Seric ** Configuration Variables: 172897Seric ** HdrInfo -- a table describing well-known header fields. 182897Seric ** Each entry has the field name and some flags, 194147Seric ** which are described in sendmail.h. 204093Seric ** 214093Seric ** Notes: 224093Seric ** I have tried to put almost all the reasonable 234093Seric ** configuration information into the configuration 244093Seric ** file read at runtime. My intent is that anything 254093Seric ** here is a function of the version of UNIX you 264093Seric ** are running, or is really static -- for example 274093Seric ** the headers are a superset of widely used 284093Seric ** protocols. If you find yourself playing with 294093Seric ** this file too much, you may be making a mistake! 30294Seric */ 31294Seric 32294Seric 33294Seric 34294Seric 35*9369Seric SCCSID(@(#)conf.c 3.65 11/28/82); 364437Seric 374437Seric 384437Seric 394437Seric /* 402897Seric ** Header info table 413057Seric ** Final (null) entry contains the flags used for any other field. 424147Seric ** 434147Seric ** Not all of these are actually handled specially by sendmail 444147Seric ** at this time. They are included as placeholders, to let 454147Seric ** you know that "someday" I intend to have sendmail do 464147Seric ** something with them. 472897Seric */ 482897Seric 492897Seric struct hdrinfo HdrInfo[] = 502897Seric { 518060Seric /* originator fields, most to least significant */ 529055Seric "resent-sender", H_FROM, 539055Seric "resent-from", H_FROM, 549055Seric "sender", H_FROM, 559055Seric "from", H_FROM, 569055Seric "full-name", H_ACHECK, 579055Seric "return-receipt-to", H_FROM, 589055Seric "errors-to", H_FROM, 598060Seric /* destination fields */ 609055Seric "to", H_RCPT, 619055Seric "resent-to", H_RCPT, 629055Seric "cc", H_RCPT, 639055Seric "resent-cc", H_RCPT, 649055Seric "bcc", H_RCPT|H_ACHECK, 659055Seric "resent-bcc", H_RCPT|H_ACHECK, 668060Seric /* message identification and control */ 679055Seric "message", H_EOH, 689055Seric "text", H_EOH, 698060Seric /* trace fields */ 709055Seric "received", H_TRACE|H_FORCE, 719055Seric "via", H_TRACE|H_FORCE, 729055Seric "mail-from", H_TRACE|H_FORCE, 738060Seric 749055Seric NULL, 0, 752897Seric }; 764166Seric 774166Seric 784166Seric /* 794166Seric ** ARPANET error message numbers. 804166Seric */ 814166Seric 827956Seric char Arpa_Info[] = "050"; /* arbitrary info */ 837956Seric char Arpa_TSyserr[] = "451"; /* some (transient) system error */ 847956Seric char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ 857956Seric char Arpa_Usrerr[] = "554"; /* some (fatal) user error */ 864282Seric 874282Seric 884282Seric 894282Seric /* 904282Seric ** Location of system files/databases/etc. 914282Seric */ 924282Seric 934282Seric char *ConfFile = "/usr/lib/sendmail.cf"; /* runtime configuration */ 949064Seric char *FreezeFile = "/usr/lib/sendmail.fc"; /* frozen version of above */ 959039Seric 969064Seric 979064Seric 989039Seric /* 999039Seric ** Some other configuration.... 1009039Seric */ 1019039Seric 1029039Seric char SpaceSub = '.'; 103294Seric 104294Seric # ifdef V6 105294Seric /* 1064190Seric ** TTYNAME -- return name of terminal. 107294Seric ** 108294Seric ** Parameters: 1094190Seric ** fd -- file descriptor to check. 110294Seric ** 111294Seric ** Returns: 1124190Seric ** pointer to full path of tty. 1134190Seric ** NULL if no tty. 114294Seric ** 115294Seric ** Side Effects: 116294Seric ** none. 117294Seric */ 118294Seric 119294Seric char * 1204190Seric ttyname(fd) 1214190Seric int fd; 122294Seric { 1234190Seric register char tn; 124294Seric static char pathn[] = "/dev/ttyx"; 125294Seric 126294Seric /* compute the pathname of the controlling tty */ 1274190Seric if ((tn = ttyn(fd)) == NULL) 128294Seric { 129294Seric errno = 0; 130294Seric return (NULL); 131294Seric } 1324190Seric pathn[8] = tn; 133294Seric return (pathn); 134294Seric } 135294Seric /* 136294Seric ** FDOPEN -- Open a stdio file given an open file descriptor. 137294Seric ** 138294Seric ** This is included here because it is standard in v7, but we 139294Seric ** need it in v6. 140294Seric ** 141294Seric ** Algorithm: 142294Seric ** Open /dev/null to create a descriptor. 143294Seric ** Close that descriptor. 144294Seric ** Copy the existing fd into the descriptor. 145294Seric ** 146294Seric ** Parameters: 147294Seric ** fd -- the open file descriptor. 148294Seric ** type -- "r", "w", or whatever. 149294Seric ** 150294Seric ** Returns: 151294Seric ** The file descriptor it creates. 152294Seric ** 153294Seric ** Side Effects: 154294Seric ** none 155294Seric ** 156294Seric ** Called By: 157294Seric ** deliver 158294Seric ** 159294Seric ** Notes: 160294Seric ** The mode of fd must match "type". 161294Seric */ 162294Seric 163294Seric FILE * 164294Seric fdopen(fd, type) 165294Seric int fd; 166294Seric char *type; 167294Seric { 168294Seric register FILE *f; 169294Seric 170294Seric f = fopen("/dev/null", type); 1714081Seric (void) close(fileno(f)); 172294Seric fileno(f) = fd; 173294Seric return (f); 174294Seric } 175294Seric /* 176294Seric ** INDEX -- Return pointer to character in string 177294Seric ** 178294Seric ** For V7 compatibility. 179294Seric ** 180294Seric ** Parameters: 181294Seric ** s -- a string to scan. 182294Seric ** c -- a character to look for. 183294Seric ** 184294Seric ** Returns: 185294Seric ** If c is in s, returns the address of the first 186294Seric ** instance of c in s. 187294Seric ** NULL if c is not in s. 188294Seric ** 189294Seric ** Side Effects: 190294Seric ** none. 191294Seric */ 192294Seric 1934437Seric char * 194294Seric index(s, c) 195294Seric register char *s; 196294Seric register char c; 197294Seric { 198294Seric while (*s != '\0') 199294Seric { 200294Seric if (*s++ == c) 201294Seric return (--s); 202294Seric } 203294Seric return (NULL); 204294Seric } 2054326Seric /* 2064326Seric ** UMASK -- fake the umask system call. 2074326Seric ** 2084326Seric ** Since V6 always acts like the umask is zero, we will just 2094326Seric ** assume the same thing. 2104326Seric */ 2114326Seric 2124326Seric /*ARGSUSED*/ 2134326Seric umask(nmask) 2144326Seric { 2154326Seric return (0); 2164326Seric } 2174326Seric 2184326Seric 2194326Seric /* 2204326Seric ** GETRUID -- get real user id. 2214326Seric */ 2224326Seric 2234326Seric getruid() 2244326Seric { 2254326Seric return (getuid() & 0377); 2264326Seric } 2274326Seric 2284326Seric 2294326Seric /* 2304326Seric ** GETRGID -- get real group id. 2314326Seric */ 2324326Seric 2334326Seric getrgid() 2344326Seric { 2354326Seric return (getgid() & 0377); 2364326Seric } 2374326Seric 2384326Seric 2394326Seric /* 2404326Seric ** GETEUID -- get effective user id. 2414326Seric */ 2424326Seric 2434326Seric geteuid() 2444326Seric { 2454326Seric return ((getuid() >> 8) & 0377); 2464326Seric } 2474326Seric 2484326Seric 2494326Seric /* 2504326Seric ** GETEGID -- get effective group id. 2514326Seric */ 2524326Seric 2534326Seric getegid() 2544326Seric { 2554326Seric return ((getgid() >> 8) & 0377); 2564326Seric } 2574326Seric 258294Seric # endif V6 2594326Seric 2604326Seric # ifndef V6 2614326Seric 2624326Seric /* 2634326Seric ** GETRUID -- get real user id (V7) 2644326Seric */ 2654326Seric 2664326Seric getruid() 2674326Seric { 2689274Seric if (OpMode == MD_DAEMON) 2694536Seric return (RealUid); 2704536Seric else 2714536Seric return (getuid()); 2724326Seric } 2734326Seric 2744326Seric 2754326Seric /* 2764326Seric ** GETRGID -- get real group id (V7). 2774326Seric */ 2784326Seric 2794326Seric getrgid() 2804326Seric { 2819274Seric if (OpMode == MD_DAEMON) 2824536Seric return (RealGid); 2834536Seric else 2844536Seric return (getgid()); 2854326Seric } 2864326Seric 2874326Seric # endif V6 2884190Seric /* 289*9369Seric ** USERNAME -- return the user id of the logged in user. 290*9369Seric ** 291*9369Seric ** Parameters: 292*9369Seric ** none. 293*9369Seric ** 294*9369Seric ** Returns: 295*9369Seric ** The login name of the logged in user. 296*9369Seric ** 297*9369Seric ** Side Effects: 298*9369Seric ** none. 299*9369Seric ** 300*9369Seric ** Notes: 301*9369Seric ** The return value is statically allocated. 302*9369Seric */ 303*9369Seric 304*9369Seric char * 305*9369Seric username() 306*9369Seric { 307*9369Seric extern char *getlogin(); 308*9369Seric 309*9369Seric return (getlogin()); 310*9369Seric } 311*9369Seric /* 3124190Seric ** TTYPATH -- Get the path of the user's tty 313294Seric ** 314294Seric ** Returns the pathname of the user's tty. Returns NULL if 315294Seric ** the user is not logged in or if s/he has write permission 316294Seric ** denied. 317294Seric ** 318294Seric ** Parameters: 319294Seric ** none 320294Seric ** 321294Seric ** Returns: 322294Seric ** pathname of the user's tty. 323294Seric ** NULL if not logged in or write permission denied. 324294Seric ** 325294Seric ** Side Effects: 326294Seric ** none. 327294Seric ** 328294Seric ** WARNING: 329294Seric ** Return value is in a local buffer. 330294Seric ** 331294Seric ** Called By: 332294Seric ** savemail 333294Seric */ 334294Seric 335294Seric # include <sys/stat.h> 336294Seric 337294Seric char * 338294Seric ttypath() 339294Seric { 340294Seric struct stat stbuf; 341294Seric register char *pathn; 342294Seric extern char *ttyname(); 3434081Seric extern char *getlogin(); 344294Seric 345294Seric /* compute the pathname of the controlling tty */ 346*9369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 347*9369Seric (pathn = ttyname(0)) == NULL) 348294Seric { 349294Seric errno = 0; 350294Seric return (NULL); 351294Seric } 352294Seric 353294Seric /* see if we have write permission */ 3542967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 355294Seric { 356294Seric errno = 0; 357294Seric return (NULL); 358294Seric } 359294Seric 360294Seric /* see if the user is logged in */ 361294Seric if (getlogin() == NULL) 362294Seric return (NULL); 363294Seric 364294Seric /* looks good */ 365294Seric return (pathn); 366294Seric } 3672967Seric /* 3682967Seric ** CHECKCOMPAT -- check for From and To person compatible. 3692967Seric ** 3702967Seric ** This routine can be supplied on a per-installation basis 3712967Seric ** to determine whether a person is allowed to send a message. 3722967Seric ** This allows restriction of certain types of internet 3732967Seric ** forwarding or registration of users. 3742967Seric ** 3752967Seric ** If the hosts are found to be incompatible, an error 3762967Seric ** message should be given using "usrerr" and FALSE should 3772967Seric ** be returned. 3782967Seric ** 3794288Seric ** 'NoReturn' can be set to suppress the return-to-sender 3804288Seric ** function; this should be done on huge messages. 3814288Seric ** 3822967Seric ** Parameters: 3832967Seric ** to -- the person being sent to. 3842967Seric ** 3852967Seric ** Returns: 3862967Seric ** TRUE -- ok to send. 3872967Seric ** FALSE -- not ok. 3882967Seric ** 3892967Seric ** Side Effects: 3902967Seric ** none (unless you include the usrerr stuff) 3912967Seric */ 3922967Seric 3932967Seric bool 3942967Seric checkcompat(to) 3952967Seric register ADDRESS *to; 3962967Seric { 3974620Seric # ifdef ING70 3984437Seric register STAB *s; 3994620Seric # endif ING70 4004437Seric 4016899Seric if (to->q_mailer != LocalMailer && CurEnv->e_msgsize > 100000) 4024288Seric { 4034288Seric usrerr("Message exceeds 100000 bytes"); 4044288Seric NoReturn++; 4054288Seric return (FALSE); 4064288Seric } 4074437Seric # ifdef ING70 4084437Seric s = stab("arpa", ST_MAILER, ST_FIND); 409*9369Seric if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && 410*9369Seric to->q_mailer == s->s_mailer) 4114437Seric { 4124437Seric usrerr("No ARPA mail through this machine: see your system administration"); 4134437Seric return (FALSE); 4144437Seric } 4154437Seric # endif ING70 4162967Seric return (TRUE); 4172967Seric } 418*9369Seric /* 419*9369Seric ** HOLDSIGS -- arrange to hold all signals 420*9369Seric ** 421*9369Seric ** Parameters: 422*9369Seric ** none. 423*9369Seric ** 424*9369Seric ** Returns: 425*9369Seric ** none. 426*9369Seric ** 427*9369Seric ** Side Effects: 428*9369Seric ** Arranges that signals are held. 429*9369Seric */ 430*9369Seric 431*9369Seric holdsigs() 432*9369Seric { 433*9369Seric } 434*9369Seric /* 435*9369Seric ** RLSESIGS -- arrange to release all signals 436*9369Seric ** 437*9369Seric ** This undoes the effect of holdsigs. 438*9369Seric ** 439*9369Seric ** Parameters: 440*9369Seric ** none. 441*9369Seric ** 442*9369Seric ** Returns: 443*9369Seric ** none. 444*9369Seric ** 445*9369Seric ** Side Effects: 446*9369Seric ** Arranges that signals are released. 447*9369Seric */ 448*9369Seric 449*9369Seric rlsesigs() 450*9369Seric { 451*9369Seric } 452