1294Seric # include <stdio.h> 2294Seric # include <pwd.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 ** NETV6MAIL -- set if you want to use "v6mail" that 121388Seric ** comes with the Berkeley network. Normally 131388Seric ** /bin/mail will work fine, but around Berkeley 141388Seric ** we use v6mail because it is a "fixed target". 152355Seric ** Also, only v6mail has the "/dev/mail" stuff 162355Seric ** in it (for biff(1)). 171388Seric ** V6 -- running on a version 6 system. This determines 181388Seric ** whether to define certain routines between 191388Seric ** the two systems. If you are running a funny 201388Seric ** system, e.g., V6 with long tty names, this 211388Seric ** should be checked carefully. 22294Seric ** 231388Seric ** Configuration Variables: 241388Seric ** Mailer -- a table of mailers known to the system. 25*3438Seric ** This should be fairly static. The fields are: 261388Seric ** - the pathname of the mailer. 271388Seric ** - a list of flags describing the properties 281388Seric ** of this mailer: 291388Seric ** M_FOPT -- if set, the mailer has a picky "-f" 301388Seric ** option. In this mode, the mailer will 311388Seric ** only accept the "-f" option if the 321388Seric ** sender is actually "root", "network", 331388Seric ** and possibly (but not necessarily) if 341388Seric ** the -f argument matches the real sender. 351388Seric ** The effect is that if the "-f" option 363309Seric ** is given to sendmail then it will be 371388Seric ** passed through (as arguments 1 & 2) to 381388Seric ** the mailer. 391388Seric ** M_ROPT -- identical to M_FOPT, except uses 401388Seric ** -r instead. 411388Seric ** M_QUIET -- if set, don't print a message if 421388Seric ** the mailer returns bad status. 431388Seric ** M_RESTR -- if set, this mailer is restricted 441388Seric ** to use by "daemon"; otherwise, we do a 451388Seric ** setuid(getuid()) before calling the 461388Seric ** mailer. 473185Seric ** M_NHDR -- if set, the mailer doesn't want us 483185Seric ** to insert a UNIX "From" line before 491388Seric ** outputing. 501388Seric ** M_NOHOST -- if set, this mailer doesn't care 511388Seric ** about the host part (e.g., the local 521388Seric ** mailer). 531388Seric ** M_STRIPQ -- if set, strip quote (`"') 541388Seric ** characters out of parameters as you 551388Seric ** transliterate them into the argument 561388Seric ** vector. For example, the local mailer 571388Seric ** is called directly, so these should be 581388Seric ** stripped, but the program-mailer (i.e., 591388Seric ** csh) should leave them in. 602897Seric ** M_NEEDDATE -- this mailer requires a Date: 612897Seric ** field in the message. 622897Seric ** M_NEEDFROM -- this mailer requires a From: 632897Seric ** field in the message. 642897Seric ** M_MSGID -- this mailer requires a Message-Id 652897Seric ** field in the message. 663185Seric ** M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID. 671388Seric ** - an exit status to use as the code for the 681388Seric ** error message print if the mailer returns 691388Seric ** something we don't understand. 701388Seric ** - A list of names that are to be considered 711388Seric ** "local" (and hence are stripped off) for 721388Seric ** this mailer. 731388Seric ** - An argument vector to be passed to the 74*3438Seric ** mailer; this is macro substituted. 751388Seric ** >>>>>>>>>> Entry zero must be for the local 761388Seric ** >> NOTE >> mailer and entry one must be for 771388Seric ** >>>>>>>>>> the shell. 782897Seric ** HdrInfo -- a table describing well-known header fields. 792897Seric ** Each entry has the field name and some flags, 802897Seric ** which can be: 813057Seric ** - H_EOH -- this field is equivalent to a blank 823057Seric ** line; i.e., it signifies end of header. 833057Seric ** - H_DELETE -- delete this field. 843057Seric ** There is also a field pointing to a pointer 853057Seric ** that should be set to point to this header. 86294Seric */ 87294Seric 88294Seric 89294Seric 90294Seric 91*3438Seric static char SccsId[] = "@(#)conf.c 3.13 04/01/81"; 92294Seric 931388Seric 941388Seric # include <whoami.h> /* definitions of machine id's at berkeley */ 951388Seric 961573Seric # ifdef BERKELEY 972355Seric # define NETV6MAIL /* use /usr/net/bin/v6mail for local delivery */ 983061Seric # endif BERKELEY 993061Seric 1003061Seric 1013061Seric 1023046Seric /* local mail -- must be #0 */ 1033046Seric static char *LocalArgv[] = 104294Seric { 1053046Seric "...local%mail", 1063046Seric "-d", 1073046Seric "$u", 1083046Seric NULL 1093046Seric }; 1103046Seric 1113046Seric static struct mailer LocalMailer = 1123046Seric { 113294Seric # ifdef NETV6MAIL 1143185Seric "local", "/usr/net/bin/v6mail", 115294Seric # else 1163185Seric "local", "/bin/mail", 117294Seric # endif 1183185Seric M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT|M_MUSER|M_NHDR, 1193185Seric EX_NOUSER, "$f", LocalArgv, NULL, 1203046Seric }; 1213046Seric 1223185Seric /* pipes through programs -- must be #1 -- also used for files */ 1233046Seric static char *ProgArgv[] = 1243046Seric { 1253046Seric "...prog%mail", 1263046Seric "-fc", 1273046Seric "$u", 1283046Seric NULL 1293046Seric }; 1303046Seric 1313046Seric static struct mailer ProgMailer = 1323046Seric { 1333185Seric "prog", "/bin/csh", 1343185Seric M_NOHOST|M_ARPAFMT, 1353185Seric EX_UNAVAILABLE, "$f", ProgArgv, NULL, 1363046Seric }; 1373046Seric 1383046Seric /* local berkeley mail */ 1393046Seric static char *BerkArgv[] = 1403046Seric { 1413046Seric "...berk%mail", 1423046Seric "-m", 1433046Seric "$h", 1443232Seric "-h", 1453232Seric "$c", 1463046Seric "-t", 1473046Seric "$u", 1483046Seric NULL 1493046Seric }; 1503046Seric 1513046Seric static struct mailer BerkMailer = 1523046Seric { 1533185Seric "berk", "/usr/net/bin/sendberkmail", 1543388Seric M_FOPT|M_NEEDDATE|M_FULLNAME|M_STRIPQ, 1553185Seric EX_UNAVAILABLE, "$B:$f", BerkArgv, NULL, 1563046Seric }; 1573046Seric 1583046Seric /* arpanet mail */ 1593046Seric static char *ArpaArgv[] = 1603046Seric { 1613046Seric "...arpa%mail", 1623046Seric "$f", 1633046Seric "$h", 1643046Seric "$u", 1653046Seric NULL 1663046Seric }; 1673046Seric 1683046Seric static struct mailer ArpaMailer = 1693046Seric { 1703185Seric "arpa", "/usr/lib/mailers/arpa", 1713185Seric M_STRIPQ|M_ARPAFMT|M_USR_UPPER, 1723185Seric 0, "$f@$A", ArpaArgv, NULL, 1733046Seric }; 1743046Seric 1753046Seric /* uucp mail (cheat & use Bell's v7 mail) */ 1763046Seric static char *UucpArgv[] = 1773046Seric { 1783046Seric "...uucp%mail", 1793232Seric "-", 1803232Seric "$h!rmail", 1813232Seric "($u)", 1823046Seric NULL 183294Seric }; 184294Seric 1853046Seric static struct mailer UucpMailer = 1863046Seric { 1873232Seric "uucp", "/usr/bin/uux", 1883388Seric M_ROPT|M_STRIPQ|M_NEEDDATE|M_FULLNAME|M_MUSER, 1893185Seric EX_NOUSER, "$U!$f", UucpArgv, NULL, 1903046Seric }; 1913046Seric 1923046Seric struct mailer *Mailer[] = 1933046Seric { 1943046Seric &LocalMailer, /* 0 -- must be 0 */ 1953046Seric &ProgMailer, /* 1 -- must be 1 */ 1963046Seric &BerkMailer, /* 2 */ 1973046Seric &ArpaMailer, /* 3 */ 1983046Seric &UucpMailer, /* 4 */ 1993144Seric NULL 2003046Seric }; 2013046Seric 202294Seric # define M_LOCAL 0 2033046Seric # define M_PROG 1 204294Seric # define M_BERK 2 205294Seric # define M_ARPA 3 206294Seric # define M_UUCP 4 207294Seric 208294Seric 209294Seric 2103046Seric 2112897Seric 2122897Seric /* 2132897Seric ** Header info table 2143057Seric ** Final (null) entry contains the flags used for any other field. 2152897Seric */ 2162897Seric 2172897Seric struct hdrinfo HdrInfo[] = 2182897Seric { 2193384Seric "date", H_CHECK, M_NEEDDATE, 2203384Seric "from", H_CHECK, M_NEEDFROM, 2213388Seric "full-name", H_ACHECK, M_FULLNAME, 2223057Seric "to", 0, NULL, 2233057Seric "cc", 0, NULL, 2243057Seric "subject", 0, NULL, 2253384Seric "message-id", H_CHECK, M_MSGID, 2263057Seric "message", H_EOH, NULL, 2273057Seric NULL, 0, NULL, 2282897Seric }; 229294Seric 230294Seric # ifdef V6 231294Seric /* 232294Seric ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 233294Seric ** 234294Seric ** Returns the pathname of the user's tty. Returns NULL if 235294Seric ** the user is not logged in or if s/he has write permission 236294Seric ** denied. 237294Seric ** 238294Seric ** Parameters: 239294Seric ** none 240294Seric ** 241294Seric ** Returns: 242294Seric ** pathname of the user's tty. 243294Seric ** NULL if not logged in or write permission denied. 244294Seric ** 245294Seric ** Side Effects: 246294Seric ** none. 247294Seric ** 248294Seric ** WARNING: 249294Seric ** Return value is in a local buffer. 250294Seric ** 251294Seric ** Called By: 252294Seric ** savemail 253294Seric */ 254294Seric 255294Seric # include <sys/types.h> 256294Seric # include <sys/stat.h> 257294Seric 258294Seric char * 259294Seric ttypath() 260294Seric { 261294Seric struct stat stbuf; 262294Seric register int i; 263294Seric static char pathn[] = "/dev/ttyx"; 264294Seric extern int errno; 265294Seric 266294Seric /* compute the pathname of the controlling tty */ 267294Seric if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 268294Seric { 269294Seric errno = 0; 270294Seric return (NULL); 271294Seric } 272294Seric pathn[8] = i; 273294Seric 274294Seric /* see if we have write permission */ 2752967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 276294Seric { 277294Seric errno = 0; 278294Seric return (NULL); 279294Seric } 280294Seric 281294Seric /* see if the user is logged in */ 282294Seric if (getlogin() == NULL) 283294Seric return (NULL); 284294Seric 285294Seric /* looks good */ 286294Seric return (pathn); 287294Seric } 288294Seric /* 289294Seric ** FDOPEN -- Open a stdio file given an open file descriptor. 290294Seric ** 291294Seric ** This is included here because it is standard in v7, but we 292294Seric ** need it in v6. 293294Seric ** 294294Seric ** Algorithm: 295294Seric ** Open /dev/null to create a descriptor. 296294Seric ** Close that descriptor. 297294Seric ** Copy the existing fd into the descriptor. 298294Seric ** 299294Seric ** Parameters: 300294Seric ** fd -- the open file descriptor. 301294Seric ** type -- "r", "w", or whatever. 302294Seric ** 303294Seric ** Returns: 304294Seric ** The file descriptor it creates. 305294Seric ** 306294Seric ** Side Effects: 307294Seric ** none 308294Seric ** 309294Seric ** Called By: 310294Seric ** deliver 311294Seric ** 312294Seric ** Notes: 313294Seric ** The mode of fd must match "type". 314294Seric */ 315294Seric 316294Seric FILE * 317294Seric fdopen(fd, type) 318294Seric int fd; 319294Seric char *type; 320294Seric { 321294Seric register FILE *f; 322294Seric 323294Seric f = fopen("/dev/null", type); 324294Seric close(fileno(f)); 325294Seric fileno(f) = fd; 326294Seric return (f); 327294Seric } 328294Seric /* 329294Seric ** INDEX -- Return pointer to character in string 330294Seric ** 331294Seric ** For V7 compatibility. 332294Seric ** 333294Seric ** Parameters: 334294Seric ** s -- a string to scan. 335294Seric ** c -- a character to look for. 336294Seric ** 337294Seric ** Returns: 338294Seric ** If c is in s, returns the address of the first 339294Seric ** instance of c in s. 340294Seric ** NULL if c is not in s. 341294Seric ** 342294Seric ** Side Effects: 343294Seric ** none. 344294Seric */ 345294Seric 346294Seric index(s, c) 347294Seric register char *s; 348294Seric register char c; 349294Seric { 350294Seric while (*s != '\0') 351294Seric { 352294Seric if (*s++ == c) 353294Seric return (--s); 354294Seric } 355294Seric return (NULL); 356294Seric } 357294Seric # endif V6 358294Seric 359294Seric # ifndef V6 360294Seric /* 361294Seric ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 362294Seric ** 363294Seric ** Returns the pathname of the user's tty. Returns NULL if 364294Seric ** the user is not logged in or if s/he has write permission 365294Seric ** denied. 366294Seric ** 367294Seric ** Parameters: 368294Seric ** none 369294Seric ** 370294Seric ** Returns: 371294Seric ** pathname of the user's tty. 372294Seric ** NULL if not logged in or write permission denied. 373294Seric ** 374294Seric ** Side Effects: 375294Seric ** none. 376294Seric ** 377294Seric ** WARNING: 378294Seric ** Return value is in a local buffer. 379294Seric ** 380294Seric ** Called By: 381294Seric ** savemail 382294Seric */ 383294Seric 384294Seric # include <sys/types.h> 385294Seric # include <sys/stat.h> 386294Seric 387294Seric char * 388294Seric ttypath() 389294Seric { 390294Seric struct stat stbuf; 391294Seric register char *pathn; 392294Seric extern int errno; 393294Seric extern char *ttyname(); 394294Seric 395294Seric /* compute the pathname of the controlling tty */ 396294Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 397294Seric { 398294Seric errno = 0; 399294Seric return (NULL); 400294Seric } 401294Seric 402294Seric /* see if we have write permission */ 4032967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 404294Seric { 405294Seric errno = 0; 406294Seric return (NULL); 407294Seric } 408294Seric 409294Seric /* see if the user is logged in */ 410294Seric if (getlogin() == NULL) 411294Seric return (NULL); 412294Seric 413294Seric /* looks good */ 414294Seric return (pathn); 415294Seric } 416294Seric # endif V6 4172967Seric /* 4182967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4192967Seric ** 4202967Seric ** This routine can be supplied on a per-installation basis 4212967Seric ** to determine whether a person is allowed to send a message. 4222967Seric ** This allows restriction of certain types of internet 4232967Seric ** forwarding or registration of users. 4242967Seric ** 4252967Seric ** If the hosts are found to be incompatible, an error 4262967Seric ** message should be given using "usrerr" and FALSE should 4272967Seric ** be returned. 4282967Seric ** 4292967Seric ** Parameters: 4302967Seric ** to -- the person being sent to. 4312967Seric ** 4322967Seric ** Returns: 4332967Seric ** TRUE -- ok to send. 4342967Seric ** FALSE -- not ok. 4352967Seric ** 4362967Seric ** Side Effects: 4372967Seric ** none (unless you include the usrerr stuff) 4382967Seric */ 4392967Seric 4402967Seric bool 4412967Seric checkcompat(to) 4422967Seric register ADDRESS *to; 4432967Seric { 4442967Seric return (TRUE); 4452967Seric } 446