1294Seric # include <stdio.h> 2294Seric # include <pwd.h> 3294Seric # include "dlvrmail.h" 4404Seric 5294Seric /* 6294Seric ** CONF.C -- Delivermail 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". 191388Seric ** V6 -- running on a version 6 system. This determines 201388Seric ** whether to define certain routines between 211388Seric ** the two systems. If you are running a funny 221388Seric ** system, e.g., V6 with long tty names, this 231388Seric ** should be checked carefully. 241573Seric ** DUMBMAIL -- set if your /bin/mail doesn't have the 251573Seric ** -d flag. 26294Seric ** 271388Seric ** Configuration Variables: 281573Seric ** ArpaHost -- the arpanet name of the host through 291573Seric ** which arpanet mail will be sent. 301388Seric ** MyLocName -- the name of the host on a local network. 311388Seric ** This is used to disambiguate the contents of 321388Seric ** ArpaHost among many hosts who may be sharing 331388Seric ** a gateway. 341573Seric ** ArpaLocal -- a list of local names for this host on 351573Seric ** the arpanet. Only functional if HASARPA set. 361573Seric ** UucpLocal -- ditto for the Arpanet. 371573Seric ** BerkLocal -- ditto for the Berknet. 381388Seric ** Mailer -- a table of mailers known to the system. 391388Seric ** The fields are: 401388Seric ** - the pathname of the mailer. 411388Seric ** - a list of flags describing the properties 421388Seric ** of this mailer: 431388Seric ** M_FOPT -- if set, the mailer has a picky "-f" 441388Seric ** option. In this mode, the mailer will 451388Seric ** only accept the "-f" option if the 461388Seric ** sender is actually "root", "network", 471388Seric ** and possibly (but not necessarily) if 481388Seric ** the -f argument matches the real sender. 491388Seric ** The effect is that if the "-f" option 501388Seric ** is given to delivermail then it will be 511388Seric ** passed through (as arguments 1 & 2) to 521388Seric ** the mailer. 531388Seric ** M_ROPT -- identical to M_FOPT, except uses 541388Seric ** -r instead. 551388Seric ** M_QUIET -- if set, don't print a message if 561388Seric ** the mailer returns bad status. 571388Seric ** M_RESTR -- if set, this mailer is restricted 581388Seric ** to use by "daemon"; otherwise, we do a 591388Seric ** setuid(getuid()) before calling the 601388Seric ** mailer. 611388Seric ** M_HDR -- if set, the mailer wants us to 621388Seric ** insert a UNIX "From" line before 631388Seric ** outputing. 64*1827Seric ** M_FHDR -- if set, the header that we 65*1827Seric ** generate will be used literally, so 66*1827Seric ** we must force it to be correct. The 67*1827Seric ** effect is that we generate a header 68*1827Seric ** even if one exists. 691388Seric ** M_NOHOST -- if set, this mailer doesn't care 701388Seric ** about the host part (e.g., the local 711388Seric ** mailer). 721388Seric ** M_STRIPQ -- if set, strip quote (`"') 731388Seric ** characters out of parameters as you 741388Seric ** transliterate them into the argument 751388Seric ** vector. For example, the local mailer 761388Seric ** is called directly, so these should be 771388Seric ** stripped, but the program-mailer (i.e., 781388Seric ** csh) should leave them in. 791388Seric ** - an exit status to use as the code for the 801388Seric ** error message print if the mailer returns 811388Seric ** something we don't understand. 821388Seric ** - A list of names that are to be considered 831388Seric ** "local" (and hence are stripped off) for 841388Seric ** this mailer. 851388Seric ** - An argument vector to be passed to the 861388Seric ** mailer with the following substitutions: 871388Seric ** $f - the from person name. 881388Seric ** $u - the target user name. 891388Seric ** $h - the target user host. 901388Seric ** $c - the hop count. 911388Seric ** >>>>>>>>>> Entry zero must be for the local 921388Seric ** >> NOTE >> mailer and entry one must be for 931388Seric ** >>>>>>>>>> the shell. 941388Seric ** ParseTab -- a table driving the parsing process. Each 951388Seric ** entry contains: 961388Seric ** - a character that will trigger this entry. 971388Seric ** - an index into the Mailer table. 981388Seric ** - a word of flags, described in dlvrmail.h. 991388Seric ** - an argument. If we have P_MAP, it is the 1001388Seric ** character to turn the trigger character into. 1011388Seric ** If we have P_MOVE, it is the site to send it 1021388Seric ** to, using the mailer specified above. 1031573Seric ** This table will almost certainly have to be 1041573Seric ** changed on your site if you have anything more 1051573Seric ** than the UUCP net. 106294Seric */ 107294Seric 108294Seric 109294Seric 110294Seric 111*1827Seric static char SccsId[] = "@(#)conf.c 2.2 11/21/80"; 112294Seric 1131388Seric 1141388Seric bool UseMsgId = FALSE; /* don't put message id's in anywhere */ 1151388Seric 1161388Seric # include <whoami.h> /* definitions of machine id's at berkeley */ 1171388Seric 1181573Seric # ifdef BERKELEY 1191573Seric char *ArpaHost = "Berkeley"; /* host name of gateway on Arpanet */ 1201573Seric # else BERKELEY 1211573Seric char *ArpaHost = "[unknown]"; 1221573Seric char *MyLocName = sysname; 1231573Seric # define HASUUCP /* default to having UUCP net */ 1241573Seric char *UucpLocal[] = { sysname, NULL }; 1251573Seric # endif BERKELEY 1261573Seric 127294Seric # ifdef ING70 128294Seric static char *BerkLocal[] = { "i", "ingres", "ing70", NULL }; 129590Seric # define ArpaLocal NULL 1301206Seric char *MyLocName = "Ing70"; 131294Seric # define HASARPA 132294Seric # define V6 133294Seric # endif ING70 134294Seric 135294Seric # ifdef INGVAX 136294Seric static char *BerkLocal[] = { "j", "ingvax", NULL }; 1371206Seric char *MyLocName = "IngVax"; 138294Seric # endif INGVAX 139294Seric 140294Seric # ifdef CSVAX 141294Seric static char *BerkLocal[] = { "v", "csvax", "vax", NULL }; 142590Seric static char *UucpLocal[] = { "ucbvax", "ernie", NULL }; 1431206Seric char *MyLocName = "CSVAX"; 144294Seric # define HASUUCP 145294Seric # define NETV6MAIL 146294Seric # endif CSVAX 147294Seric 148294Seric # ifdef CORY 149294Seric /* untested */ 150294Seric static char *BerkLocal[] = { "y", "cory", NULL }; 1511206Seric char *MyLocName = "Cory"; 152294Seric # endif CORY 153294Seric 154294Seric # ifdef IMAGE 155294Seric /* untested */ 156294Seric static char *BerkLocal[] = { "m", "image", NULL }; 1571206Seric char *MyLocName = "Image"; 158294Seric # define V6 159294Seric # endif IMAGE 160294Seric 161294Seric # ifdef ESVAX 162294Seric /* untested */ 163294Seric static char *BerkLocal[] = { "o", "esvax", NULL }; 1641206Seric char *MyLocName = "ESVAX"; 165294Seric # endif ESVAX 166294Seric 167294Seric # ifdef EECS40 168294Seric /* untested */ 169294Seric static char *BerkLocal[] = { "z", "eecs40", NULL }; 1701206Seric char *MyLocName = "EECS40"; 171294Seric # define V6 172294Seric # endif EECS40 173294Seric 174590Seric 175590Seric # ifndef HASARPA 176590Seric # define ArpaLocal NULL 177590Seric # endif HASARPA 178590Seric 179590Seric # ifndef HASUUCP 180590Seric # define UucpLocal NULL 181590Seric # endif HASUUCP 182590Seric 183590Seric 184294Seric struct mailer Mailer[] = 185294Seric { 186294Seric /* local mail -- must be #0 */ 187294Seric { 188294Seric # ifdef NETV6MAIL 189294Seric "/usr/net/bin/v6mail", 190294Seric # else 191294Seric "/bin/mail", 192294Seric # endif 193294Seric M_ROPT|M_NOHOST|M_STRIPQ, EX_NOUSER, NULL, 194294Seric { "...local%mail", "-d", "$u", NULL } 195294Seric }, 196294Seric /* pipes through programs -- must be #1 */ 197294Seric { 198294Seric "/bin/csh", 199*1827Seric M_HDR|M_FHDR|M_NOHOST, EX_UNAVAILABLE, NULL, 200294Seric { "...prog%mail", "-fc", "$u", NULL } 201294Seric }, 202294Seric /* local berkeley mail */ 203294Seric { 204294Seric "/usr/net/bin/sendberkmail", 2051596Seric M_FOPT|M_HDR|M_STRIPQ, EX_UNAVAILABLE, BerkLocal, 206294Seric { "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL } 207294Seric }, 208294Seric /* arpanet mail */ 209294Seric { 210294Seric "/usr/lib/mailers/arpa", 211590Seric M_STRIPQ, 0, ArpaLocal, 212294Seric { "...arpa%mail", "$f", "$h", "$u", NULL } 213294Seric }, 214294Seric /* uucp mail (cheat & use Bell's v7 mail) */ 215294Seric { 216294Seric "/bin/mail", 217917Seric M_ROPT|M_STRIPQ, EX_NOUSER, UucpLocal, 218294Seric # ifdef DUMBMAIL 219294Seric { "...uucp%mail", "$h!$u", NULL } 220294Seric # else 221294Seric { "...uucp%mail", "-d", "$h!$u", NULL } 222294Seric # endif DUMBMAIL 223294Seric }, 224294Seric }; 225294Seric 226294Seric # define M_LOCAL 0 227294Seric # define M_BERK 2 228294Seric # define M_ARPA 3 229294Seric # define M_UUCP 4 230294Seric 231294Seric 232294Seric 2331573Seric # ifdef BERKELEY 234294Seric struct parsetab ParseTab[] = 235294Seric { 236294Seric ':', M_BERK, P_ONE, NULL, 237294Seric # ifdef HASARPA 238294Seric '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 239294Seric # else 240294Seric '@', M_BERK, P_HLAST|P_USR_UPPER|P_MOVE, "ing70", 241294Seric # endif HASARPA 242294Seric '^', -1, P_MAP, "!", 243294Seric # ifdef HASUUCP 244294Seric '!', M_UUCP, 0, NULL, 245294Seric # else 246294Seric '!', M_BERK, P_MOVE, "csvax", 247294Seric # endif HASUUCP 248294Seric '.', -1, P_MAP|P_ONE, ":", 249294Seric '\0', M_LOCAL, P_MOVE, "", 250294Seric }; 2511573Seric # else BERKELEY 2521573Seric struct parsetab ParseTab[] = 2531573Seric { 2541573Seric # ifdef HASARPA 2551573Seric '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 2561573Seric # endif HASARPA 2571573Seric # ifdef HASUUCP 2581573Seric '^', -1, P_MAP, "!", 2591573Seric '!', M_UUCP, 0, NULL, 2601573Seric # endif HASUUCP 2611573Seric '\0', M_LOCAL, P_MOVE, "", 2621573Seric }; 2631573Seric # endif BERKELEY 264294Seric /* 265294Seric ** GETNAME -- Get the current users login name. 266294Seric ** 267294Seric ** This is in config.c because it is somewhat machine dependent. 268294Seric ** Examine it carefully for your installation. 269294Seric ** 270294Seric ** Algorithm: 271294Seric ** See if the person is logged in. If so, return 272294Seric ** the name s/he is logged in as. 273294Seric ** Look up the user id in /etc/passwd. If found, 274294Seric ** return that name. 275294Seric ** Return NULL. 276294Seric ** 277294Seric ** Parameters: 278294Seric ** none 279294Seric ** 280294Seric ** Returns: 281294Seric ** The login name of this user. 282294Seric ** NULL if this person is noone. 283294Seric ** 284294Seric ** Side Effects: 285294Seric ** none 286294Seric ** 287294Seric ** Called By: 288294Seric ** main 289294Seric */ 290294Seric 291294Seric char * 292294Seric getname() 293294Seric { 294294Seric register char *p; 295294Seric register struct passwd *w; 296294Seric extern char *getlogin(); 297294Seric extern struct passwd *getpwuid(); 298294Seric static char namebuf[9]; 299294Seric 300294Seric p = getlogin(); 301294Seric if (p != NULL && p[0] != '\0') 302294Seric return (p); 303294Seric # ifdef V6 304294Seric w = getpwuid(getuid() & 0377); 305294Seric # else 306294Seric w = getpwuid(getuid()); 307294Seric # endif V6 308294Seric if (w != NULL) 309294Seric { 310294Seric strcpy(namebuf, w->pw_name); 311294Seric return (namebuf); 312294Seric } 313294Seric return (NULL); 314294Seric } 315294Seric 316294Seric # ifdef V6 317294Seric /* 318294Seric ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 319294Seric ** 320294Seric ** Returns the pathname of the user's tty. Returns NULL if 321294Seric ** the user is not logged in or if s/he has write permission 322294Seric ** denied. 323294Seric ** 324294Seric ** Parameters: 325294Seric ** none 326294Seric ** 327294Seric ** Returns: 328294Seric ** pathname of the user's tty. 329294Seric ** NULL if not logged in or write permission denied. 330294Seric ** 331294Seric ** Side Effects: 332294Seric ** none. 333294Seric ** 334294Seric ** WARNING: 335294Seric ** Return value is in a local buffer. 336294Seric ** 337294Seric ** Called By: 338294Seric ** savemail 339294Seric */ 340294Seric 341294Seric # include <sys/types.h> 342294Seric # include <sys/stat.h> 343294Seric 344294Seric char * 345294Seric ttypath() 346294Seric { 347294Seric struct stat stbuf; 348294Seric register int i; 349294Seric static char pathn[] = "/dev/ttyx"; 350294Seric extern int errno; 351294Seric 352294Seric /* compute the pathname of the controlling tty */ 353294Seric if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 354294Seric { 355294Seric errno = 0; 356294Seric return (NULL); 357294Seric } 358294Seric pathn[8] = i; 359294Seric 360294Seric /* see if we have write permission */ 361294Seric if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 362294Seric { 363294Seric errno = 0; 364294Seric return (NULL); 365294Seric } 366294Seric 367294Seric /* see if the user is logged in */ 368294Seric if (getlogin() == NULL) 369294Seric return (NULL); 370294Seric 371294Seric /* looks good */ 372294Seric return (pathn); 373294Seric } 374294Seric /* 375294Seric ** FDOPEN -- Open a stdio file given an open file descriptor. 376294Seric ** 377294Seric ** This is included here because it is standard in v7, but we 378294Seric ** need it in v6. 379294Seric ** 380294Seric ** Algorithm: 381294Seric ** Open /dev/null to create a descriptor. 382294Seric ** Close that descriptor. 383294Seric ** Copy the existing fd into the descriptor. 384294Seric ** 385294Seric ** Parameters: 386294Seric ** fd -- the open file descriptor. 387294Seric ** type -- "r", "w", or whatever. 388294Seric ** 389294Seric ** Returns: 390294Seric ** The file descriptor it creates. 391294Seric ** 392294Seric ** Side Effects: 393294Seric ** none 394294Seric ** 395294Seric ** Called By: 396294Seric ** deliver 397294Seric ** 398294Seric ** Notes: 399294Seric ** The mode of fd must match "type". 400294Seric */ 401294Seric 402294Seric FILE * 403294Seric fdopen(fd, type) 404294Seric int fd; 405294Seric char *type; 406294Seric { 407294Seric register FILE *f; 408294Seric 409294Seric f = fopen("/dev/null", type); 410294Seric close(fileno(f)); 411294Seric fileno(f) = fd; 412294Seric return (f); 413294Seric } 414294Seric /* 415294Seric ** INDEX -- Return pointer to character in string 416294Seric ** 417294Seric ** For V7 compatibility. 418294Seric ** 419294Seric ** Parameters: 420294Seric ** s -- a string to scan. 421294Seric ** c -- a character to look for. 422294Seric ** 423294Seric ** Returns: 424294Seric ** If c is in s, returns the address of the first 425294Seric ** instance of c in s. 426294Seric ** NULL if c is not in s. 427294Seric ** 428294Seric ** Side Effects: 429294Seric ** none. 430294Seric */ 431294Seric 432294Seric index(s, c) 433294Seric register char *s; 434294Seric register char c; 435294Seric { 436294Seric while (*s != '\0') 437294Seric { 438294Seric if (*s++ == c) 439294Seric return (--s); 440294Seric } 441294Seric return (NULL); 442294Seric } 443294Seric # endif V6 444294Seric 445294Seric # ifndef V6 446294Seric /* 447294Seric ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 448294Seric ** 449294Seric ** Returns the pathname of the user's tty. Returns NULL if 450294Seric ** the user is not logged in or if s/he has write permission 451294Seric ** denied. 452294Seric ** 453294Seric ** Parameters: 454294Seric ** none 455294Seric ** 456294Seric ** Returns: 457294Seric ** pathname of the user's tty. 458294Seric ** NULL if not logged in or write permission denied. 459294Seric ** 460294Seric ** Side Effects: 461294Seric ** none. 462294Seric ** 463294Seric ** WARNING: 464294Seric ** Return value is in a local buffer. 465294Seric ** 466294Seric ** Called By: 467294Seric ** savemail 468294Seric */ 469294Seric 470294Seric # include <sys/types.h> 471294Seric # include <sys/stat.h> 472294Seric 473294Seric char * 474294Seric ttypath() 475294Seric { 476294Seric struct stat stbuf; 477294Seric register char *pathn; 478294Seric extern int errno; 479294Seric extern char *ttyname(); 480294Seric 481294Seric /* compute the pathname of the controlling tty */ 482294Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 483294Seric { 484294Seric errno = 0; 485294Seric return (NULL); 486294Seric } 487294Seric 488294Seric /* see if we have write permission */ 489294Seric if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 490294Seric { 491294Seric errno = 0; 492294Seric return (NULL); 493294Seric } 494294Seric 495294Seric /* see if the user is logged in */ 496294Seric if (getlogin() == NULL) 497294Seric return (NULL); 498294Seric 499294Seric /* looks good */ 500294Seric return (pathn); 501294Seric } 502294Seric # endif V6 503