1294Seric # include <stdio.h> 2294Seric # include <pwd.h> 32967Seric # include "postbox.h" 4404Seric 5294Seric /* 62967Seric ** CONF.C -- Postbox Configuration Tables. 7294Seric ** 8294Seric ** Defines the configuration of this installation. 9294Seric ** 101388Seric ** Compilation Flags: 111388Seric ** HASARPA -- set if this machine has a connection to 121388Seric ** the Arpanet. 131388Seric ** HASUUCP -- set if this machine has a connection to 141388Seric ** the UUCP network. 151388Seric ** NETV6MAIL -- set if you want to use "v6mail" that 161388Seric ** comes with the Berkeley network. Normally 171388Seric ** /bin/mail will work fine, but around Berkeley 181388Seric ** we use v6mail because it is a "fixed target". 192355Seric ** Also, only v6mail has the "/dev/mail" stuff 202355Seric ** in it (for biff(1)). 211388Seric ** V6 -- running on a version 6 system. This determines 221388Seric ** whether to define certain routines between 231388Seric ** the two systems. If you are running a funny 241388Seric ** system, e.g., V6 with long tty names, this 251388Seric ** should be checked carefully. 261573Seric ** DUMBMAIL -- set if your /bin/mail doesn't have the 271573Seric ** -d flag. 28294Seric ** 291388Seric ** Configuration Variables: 301388Seric ** Mailer -- a table of mailers known to the system. 311388Seric ** The fields are: 321388Seric ** - the pathname of the mailer. 331388Seric ** - a list of flags describing the properties 341388Seric ** of this mailer: 351388Seric ** M_FOPT -- if set, the mailer has a picky "-f" 361388Seric ** option. In this mode, the mailer will 371388Seric ** only accept the "-f" option if the 381388Seric ** sender is actually "root", "network", 391388Seric ** and possibly (but not necessarily) if 401388Seric ** the -f argument matches the real sender. 411388Seric ** The effect is that if the "-f" option 422967Seric ** is given to postbox then it will be 431388Seric ** passed through (as arguments 1 & 2) to 441388Seric ** the mailer. 451388Seric ** M_ROPT -- identical to M_FOPT, except uses 461388Seric ** -r instead. 471388Seric ** M_QUIET -- if set, don't print a message if 481388Seric ** the mailer returns bad status. 491388Seric ** M_RESTR -- if set, this mailer is restricted 501388Seric ** to use by "daemon"; otherwise, we do a 511388Seric ** setuid(getuid()) before calling the 521388Seric ** mailer. 53*3185Seric ** M_NHDR -- if set, the mailer doesn't want us 54*3185Seric ** to insert a UNIX "From" line before 551388Seric ** outputing. 561388Seric ** M_NOHOST -- if set, this mailer doesn't care 571388Seric ** about the host part (e.g., the local 581388Seric ** mailer). 591388Seric ** M_STRIPQ -- if set, strip quote (`"') 601388Seric ** characters out of parameters as you 611388Seric ** transliterate them into the argument 621388Seric ** vector. For example, the local mailer 631388Seric ** is called directly, so these should be 641388Seric ** stripped, but the program-mailer (i.e., 651388Seric ** csh) should leave them in. 662897Seric ** M_NEEDDATE -- this mailer requires a Date: 672897Seric ** field in the message. 682897Seric ** M_NEEDFROM -- this mailer requires a From: 692897Seric ** field in the message. 702897Seric ** M_MSGID -- this mailer requires a Message-Id 712897Seric ** field in the message. 72*3185Seric ** M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID. 731388Seric ** - an exit status to use as the code for the 741388Seric ** error message print if the mailer returns 751388Seric ** something we don't understand. 761388Seric ** - A list of names that are to be considered 771388Seric ** "local" (and hence are stripped off) for 781388Seric ** this mailer. 791388Seric ** - An argument vector to be passed to the 801388Seric ** mailer with the following substitutions: 811388Seric ** $f - the from person name. 821388Seric ** $u - the target user name. 831388Seric ** $h - the target user host. 841388Seric ** $c - the hop count. 851388Seric ** >>>>>>>>>> Entry zero must be for the local 861388Seric ** >> NOTE >> mailer and entry one must be for 871388Seric ** >>>>>>>>>> the shell. 882897Seric ** HdrInfo -- a table describing well-known header fields. 892897Seric ** Each entry has the field name and some flags, 902897Seric ** which can be: 913057Seric ** - H_EOH -- this field is equivalent to a blank 923057Seric ** line; i.e., it signifies end of header. 933057Seric ** - H_DELETE -- delete this field. 943057Seric ** There is also a field pointing to a pointer 953057Seric ** that should be set to point to this header. 96294Seric */ 97294Seric 98294Seric 99294Seric 100294Seric 101*3185Seric static char SccsId[] = "@(#)conf.c 3.8 03/11/81"; 102294Seric 1031388Seric 1041388Seric # include <whoami.h> /* definitions of machine id's at berkeley */ 1051388Seric 1061573Seric # ifdef BERKELEY 1072099Seric 1082355Seric # define NETV6MAIL /* use /usr/net/bin/v6mail for local delivery */ 1092099Seric 1102099Seric /* Specific Configurations for Berkeley Machines */ 1112099Seric 1123061Seric /* Berkeley people: mail changes to ingvax:eric or they will be lost! */ 1132099Seric 114294Seric # ifdef ING70 1153061Seric # include "c.ing70.h" 116294Seric # endif ING70 117294Seric 118294Seric # ifdef INGVAX 1193061Seric # include "c.ingvax.h" 120294Seric # endif INGVAX 121294Seric 122294Seric # ifdef CSVAX 1233061Seric # include "c.csvax.h" 124294Seric # endif CSVAX 125294Seric 1262355Seric # ifdef ARPAVAX 1273061Seric # include "c.arpavax.h" 1282355Seric # endif ARPAVAX 1292355Seric 130294Seric # ifdef CORY 1313061Seric # include "c.cory.h" 132294Seric # endif CORY 133294Seric 1342420Seric # ifdef ONYX 1353061Seric # include "c.onyx.h" 1362420Seric # endif ONYX 1372420Seric 138294Seric # ifdef IMAGE 1393061Seric # include "c.image.h" 140294Seric # endif IMAGE 141294Seric 142294Seric # ifdef ESVAX 1433061Seric # include "c.esvax.h" 144294Seric # endif ESVAX 145294Seric 146294Seric # ifdef EECS40 1473061Seric # include "c.eecs40.h" 148294Seric # endif EECS40 149294Seric 1503061Seric # else BERKELEY 151590Seric 1523061Seric # define HASUUCP /* default to having UUCP net */ 1533061Seric 1543061Seric # endif BERKELEY 1553061Seric 1563061Seric 1573061Seric 1583046Seric /* local mail -- must be #0 */ 1593046Seric static char *LocalArgv[] = 160294Seric { 1613046Seric "...local%mail", 1623046Seric "-d", 1633046Seric "$u", 1643046Seric NULL 1653046Seric }; 1663046Seric 1673046Seric static struct mailer LocalMailer = 1683046Seric { 169294Seric # ifdef NETV6MAIL 170*3185Seric "local", "/usr/net/bin/v6mail", 171294Seric # else 172*3185Seric "local", "/bin/mail", 173294Seric # endif 174*3185Seric M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT|M_MUSER|M_NHDR, 175*3185Seric EX_NOUSER, "$f", LocalArgv, NULL, 1763046Seric }; 1773046Seric 178*3185Seric /* pipes through programs -- must be #1 -- also used for files */ 1793046Seric static char *ProgArgv[] = 1803046Seric { 1813046Seric "...prog%mail", 1823046Seric "-fc", 1833046Seric "$u", 1843046Seric NULL 1853046Seric }; 1863046Seric 1873046Seric static struct mailer ProgMailer = 1883046Seric { 189*3185Seric "prog", "/bin/csh", 190*3185Seric M_NOHOST|M_ARPAFMT, 191*3185Seric EX_UNAVAILABLE, "$f", ProgArgv, NULL, 1923046Seric }; 1933046Seric 1943046Seric /* local berkeley mail */ 1953046Seric static char *BerkArgv[] = 1963046Seric { 1973046Seric "...berk%mail", 1983046Seric "-m", 1993046Seric "$h", 2003046Seric "-t", 2013046Seric "$u", 2023046Seric "-h", 2033046Seric "$c", 2043046Seric NULL 2053046Seric }; 2063046Seric 2073046Seric static struct mailer BerkMailer = 2083046Seric { 209*3185Seric "berk", "/usr/net/bin/sendberkmail", 210*3185Seric M_FOPT|M_ARPAFMT|M_STRIPQ|M_MUSER, 211*3185Seric EX_UNAVAILABLE, "$B:$f", BerkArgv, NULL, 2123046Seric }; 2133046Seric 2143046Seric /* arpanet mail */ 2153046Seric static char *ArpaArgv[] = 2163046Seric { 2173046Seric "...arpa%mail", 2183046Seric "$f", 2193046Seric "$h", 2203046Seric "$u", 2213046Seric NULL 2223046Seric }; 2233046Seric 2243046Seric static struct mailer ArpaMailer = 2253046Seric { 226*3185Seric "arpa", "/usr/lib/mailers/arpa", 227*3185Seric M_STRIPQ|M_ARPAFMT|M_USR_UPPER, 228*3185Seric 0, "$f@$A", ArpaArgv, NULL, 2293046Seric }; 2303046Seric 2313046Seric /* uucp mail (cheat & use Bell's v7 mail) */ 2323046Seric static char *UucpArgv[] = 2333046Seric { 2343046Seric "...uucp%mail", 235*3185Seric # ifndef DUMBMAIL 2363046Seric "-d", 237294Seric # endif DUMBMAIL 2383046Seric "$h!$u", 2393046Seric NULL 240294Seric }; 241294Seric 2423046Seric static struct mailer UucpMailer = 2433046Seric { 244*3185Seric "uucp", "/bin/mail", 245*3185Seric M_ROPT|M_STRIPQ|M_ARPAFMT|M_MUSER, 246*3185Seric EX_NOUSER, "$U!$f", UucpArgv, NULL, 2473046Seric }; 2483046Seric 2493046Seric struct mailer *Mailer[] = 2503046Seric { 2513046Seric &LocalMailer, /* 0 -- must be 0 */ 2523046Seric &ProgMailer, /* 1 -- must be 1 */ 2533046Seric &BerkMailer, /* 2 */ 2543046Seric &ArpaMailer, /* 3 */ 2553046Seric &UucpMailer, /* 4 */ 2563144Seric NULL 2573046Seric }; 2583046Seric 259294Seric # define M_LOCAL 0 2603046Seric # define M_PROG 1 261294Seric # define M_BERK 2 262294Seric # define M_ARPA 3 263294Seric # define M_UUCP 4 264294Seric 265294Seric 266294Seric 2673046Seric 2682897Seric 2692897Seric /* 2702897Seric ** Header info table 2713057Seric ** Final (null) entry contains the flags used for any other field. 2722897Seric */ 2732897Seric 2742897Seric struct hdrinfo HdrInfo[] = 2752897Seric { 2763057Seric "date", 0, NULL, 2773057Seric "from", 0, NULL, 2783057Seric "to", 0, NULL, 2793057Seric "cc", 0, NULL, 2803057Seric "subject", 0, NULL, 2813057Seric "message-id", 0, &MsgId, 2823057Seric "message", H_EOH, NULL, 2833057Seric NULL, 0, NULL, 2842897Seric }; 285294Seric 286294Seric # ifdef V6 287294Seric /* 288294Seric ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 289294Seric ** 290294Seric ** Returns the pathname of the user's tty. Returns NULL if 291294Seric ** the user is not logged in or if s/he has write permission 292294Seric ** denied. 293294Seric ** 294294Seric ** Parameters: 295294Seric ** none 296294Seric ** 297294Seric ** Returns: 298294Seric ** pathname of the user's tty. 299294Seric ** NULL if not logged in or write permission denied. 300294Seric ** 301294Seric ** Side Effects: 302294Seric ** none. 303294Seric ** 304294Seric ** WARNING: 305294Seric ** Return value is in a local buffer. 306294Seric ** 307294Seric ** Called By: 308294Seric ** savemail 309294Seric */ 310294Seric 311294Seric # include <sys/types.h> 312294Seric # include <sys/stat.h> 313294Seric 314294Seric char * 315294Seric ttypath() 316294Seric { 317294Seric struct stat stbuf; 318294Seric register int i; 319294Seric static char pathn[] = "/dev/ttyx"; 320294Seric extern int errno; 321294Seric 322294Seric /* compute the pathname of the controlling tty */ 323294Seric if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 324294Seric { 325294Seric errno = 0; 326294Seric return (NULL); 327294Seric } 328294Seric pathn[8] = i; 329294Seric 330294Seric /* see if we have write permission */ 3312967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 332294Seric { 333294Seric errno = 0; 334294Seric return (NULL); 335294Seric } 336294Seric 337294Seric /* see if the user is logged in */ 338294Seric if (getlogin() == NULL) 339294Seric return (NULL); 340294Seric 341294Seric /* looks good */ 342294Seric return (pathn); 343294Seric } 344294Seric /* 345294Seric ** FDOPEN -- Open a stdio file given an open file descriptor. 346294Seric ** 347294Seric ** This is included here because it is standard in v7, but we 348294Seric ** need it in v6. 349294Seric ** 350294Seric ** Algorithm: 351294Seric ** Open /dev/null to create a descriptor. 352294Seric ** Close that descriptor. 353294Seric ** Copy the existing fd into the descriptor. 354294Seric ** 355294Seric ** Parameters: 356294Seric ** fd -- the open file descriptor. 357294Seric ** type -- "r", "w", or whatever. 358294Seric ** 359294Seric ** Returns: 360294Seric ** The file descriptor it creates. 361294Seric ** 362294Seric ** Side Effects: 363294Seric ** none 364294Seric ** 365294Seric ** Called By: 366294Seric ** deliver 367294Seric ** 368294Seric ** Notes: 369294Seric ** The mode of fd must match "type". 370294Seric */ 371294Seric 372294Seric FILE * 373294Seric fdopen(fd, type) 374294Seric int fd; 375294Seric char *type; 376294Seric { 377294Seric register FILE *f; 378294Seric 379294Seric f = fopen("/dev/null", type); 380294Seric close(fileno(f)); 381294Seric fileno(f) = fd; 382294Seric return (f); 383294Seric } 384294Seric /* 385294Seric ** INDEX -- Return pointer to character in string 386294Seric ** 387294Seric ** For V7 compatibility. 388294Seric ** 389294Seric ** Parameters: 390294Seric ** s -- a string to scan. 391294Seric ** c -- a character to look for. 392294Seric ** 393294Seric ** Returns: 394294Seric ** If c is in s, returns the address of the first 395294Seric ** instance of c in s. 396294Seric ** NULL if c is not in s. 397294Seric ** 398294Seric ** Side Effects: 399294Seric ** none. 400294Seric */ 401294Seric 402294Seric index(s, c) 403294Seric register char *s; 404294Seric register char c; 405294Seric { 406294Seric while (*s != '\0') 407294Seric { 408294Seric if (*s++ == c) 409294Seric return (--s); 410294Seric } 411294Seric return (NULL); 412294Seric } 413294Seric # endif V6 414294Seric 415294Seric # ifndef V6 416294Seric /* 417294Seric ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 418294Seric ** 419294Seric ** Returns the pathname of the user's tty. Returns NULL if 420294Seric ** the user is not logged in or if s/he has write permission 421294Seric ** denied. 422294Seric ** 423294Seric ** Parameters: 424294Seric ** none 425294Seric ** 426294Seric ** Returns: 427294Seric ** pathname of the user's tty. 428294Seric ** NULL if not logged in or write permission denied. 429294Seric ** 430294Seric ** Side Effects: 431294Seric ** none. 432294Seric ** 433294Seric ** WARNING: 434294Seric ** Return value is in a local buffer. 435294Seric ** 436294Seric ** Called By: 437294Seric ** savemail 438294Seric */ 439294Seric 440294Seric # include <sys/types.h> 441294Seric # include <sys/stat.h> 442294Seric 443294Seric char * 444294Seric ttypath() 445294Seric { 446294Seric struct stat stbuf; 447294Seric register char *pathn; 448294Seric extern int errno; 449294Seric extern char *ttyname(); 450294Seric 451294Seric /* compute the pathname of the controlling tty */ 452294Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 453294Seric { 454294Seric errno = 0; 455294Seric return (NULL); 456294Seric } 457294Seric 458294Seric /* see if we have write permission */ 4592967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 460294Seric { 461294Seric errno = 0; 462294Seric return (NULL); 463294Seric } 464294Seric 465294Seric /* see if the user is logged in */ 466294Seric if (getlogin() == NULL) 467294Seric return (NULL); 468294Seric 469294Seric /* looks good */ 470294Seric return (pathn); 471294Seric } 472294Seric # endif V6 4732967Seric /* 4742967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4752967Seric ** 4762967Seric ** This routine can be supplied on a per-installation basis 4772967Seric ** to determine whether a person is allowed to send a message. 4782967Seric ** This allows restriction of certain types of internet 4792967Seric ** forwarding or registration of users. 4802967Seric ** 4812967Seric ** If the hosts are found to be incompatible, an error 4822967Seric ** message should be given using "usrerr" and FALSE should 4832967Seric ** be returned. 4842967Seric ** 4852967Seric ** Parameters: 4862967Seric ** to -- the person being sent to. 4872967Seric ** 4882967Seric ** Returns: 4892967Seric ** TRUE -- ok to send. 4902967Seric ** FALSE -- not ok. 4912967Seric ** 4922967Seric ** Side Effects: 4932967Seric ** none (unless you include the usrerr stuff) 4942967Seric */ 4952967Seric 4962967Seric bool 4972967Seric checkcompat(to) 4982967Seric register ADDRESS *to; 4992967Seric { 5002967Seric return (TRUE); 5012967Seric } 502