1: # include <stdio.h> 2: # include <pwd.h> 3: # include "dlvrmail.h" 4: 5: /* 6: ** CONF.C -- Delivermail Configuration Tables. 7: ** 8: ** Defines the configuration of this installation. 9: ** 10: ** Compilation Flags: 11: ** HASARPA -- set if this machine has a connection to 12: ** the Arpanet. 13: ** HASUUCP -- set if this machine has a connection to 14: ** the UUCP network. 15: ** NETV6MAIL -- set if you want to use "v6mail" that 16: ** comes with the Berkeley network. Normally 17: ** /bin/mail will work fine, but around Berkeley 18: ** we use v6mail because it is a "fixed target". 19: ** V6 -- running on a version 6 system. This determines 20: ** whether to define certain routines between 21: ** the two systems. If you are running a funny 22: ** system, e.g., V6 with long tty names, this 23: ** should be checked carefully. 24: ** DUMBMAIL -- set if your /bin/mail doesn't have the 25: ** -d flag. 26: ** 27: ** Configuration Variables: 28: ** ArpaHost -- the arpanet name of the host through 29: ** which arpanet mail will be sent. 30: ** MyLocName -- the name of the host on a local network. 31: ** This is used to disambiguate the contents of 32: ** ArpaHost among many hosts who may be sharing 33: ** a gateway. 34: ** ArpaLocal -- a list of local names for this host on 35: ** the arpanet. Only functional if HASARPA set. 36: ** UucpLocal -- ditto for the Arpanet. 37: ** BerkLocal -- ditto for the Berknet. 38: ** Mailer -- a table of mailers known to the system. 39: ** The fields are: 40: ** - the pathname of the mailer. 41: ** - a list of flags describing the properties 42: ** of this mailer: 43: ** M_FOPT -- if set, the mailer has a picky "-f" 44: ** option. In this mode, the mailer will 45: ** only accept the "-f" option if the 46: ** sender is actually "root", "network", 47: ** and possibly (but not necessarily) if 48: ** the -f argument matches the real sender. 49: ** The effect is that if the "-f" option 50: ** is given to delivermail then it will be 51: ** passed through (as arguments 1 & 2) to 52: ** the mailer. 53: ** M_ROPT -- identical to M_FOPT, except uses 54: ** -r instead. 55: ** M_QUIET -- if set, don't print a message if 56: ** the mailer returns bad status. 57: ** M_RESTR -- if set, this mailer is restricted 58: ** to use by "daemon"; otherwise, we do a 59: ** setuid(getuid()) before calling the 60: ** mailer. 61: ** M_HDR -- if set, the mailer wants us to 62: ** insert a UNIX "From" line before 63: ** outputing. 64: ** M_NOHOST -- if set, this mailer doesn't care 65: ** about the host part (e.g., the local 66: ** mailer). 67: ** M_STRIPQ -- if set, strip quote (`"') 68: ** characters out of parameters as you 69: ** transliterate them into the argument 70: ** vector. For example, the local mailer 71: ** is called directly, so these should be 72: ** stripped, but the program-mailer (i.e., 73: ** csh) should leave them in. 74: ** - an exit status to use as the code for the 75: ** error message print if the mailer returns 76: ** something we don't understand. 77: ** - A list of names that are to be considered 78: ** "local" (and hence are stripped off) for 79: ** this mailer. 80: ** - An argument vector to be passed to the 81: ** mailer with the following substitutions: 82: ** $f - the from person name. 83: ** $u - the target user name. 84: ** $h - the target user host. 85: ** $c - the hop count. 86: ** >>>>>>>>>> Entry zero must be for the local 87: ** >> NOTE >> mailer and entry one must be for 88: ** >>>>>>>>>> the shell. 89: ** ParseTab -- a table driving the parsing process. Each 90: ** entry contains: 91: ** - a character that will trigger this entry. 92: ** - an index into the Mailer table. 93: ** - a word of flags, described in dlvrmail.h. 94: ** - an argument. If we have P_MAP, it is the 95: ** character to turn the trigger character into. 96: ** If we have P_MOVE, it is the site to send it 97: ** to, using the mailer specified above. 98: ** This table will almost certainly have to be 99: ** changed on your site if you have anything more 100: ** than the UUCP net. 101: */ 102: 103: 104: 105: 106: static char SccsId[] = "@(#)conf.c 1.10 10/21/80"; 107: 108: /************ BEGIN CONFIGURATION SECTION ************/ 109: 110: bool UseMsgId = FALSE; /* don't put message id's in anywhere */ 111: 112: # include <whoami.h> /* definitions of machine id's at berkeley */ 113: 114: char *ArpaHost = "[unknown]"; 115: char *MyLocName = sysname; 116: # define HASUUCP /* default to having UUCP net */ 117: char *UucpLocal[] = { sysname, NULL }; 118: /* if you define HASARPA you must include a declaration for ArpaLocal */ 119: 120: /************ END CONFIGURATION SECTION ************/ 121: 122: # ifndef HASARPA 123: # define ArpaLocal NULL 124: # endif HASARPA 125: 126: # ifndef HASUUCP 127: # define UucpLocal NULL 128: # endif HASUUCP 129: 130: # ifndef HASBERK 131: # define BerkLocal NULL 132: # endif HASBERK 133: 134: 135: struct mailer Mailer[] = 136: { 137: /* local mail -- must be #0 */ 138: { 139: # ifdef NETV6MAIL 140: "/usr/net/bin/v6mail", 141: # else 142: "/bin/mail", 143: # endif 144: M_ROPT|M_NOHOST|M_STRIPQ, EX_NOUSER, NULL, 145: { "...local%mail", "-d", "$u", NULL } 146: }, 147: /* pipes through programs -- must be #1 */ 148: { 149: "/bin/csh", 150: M_HDR|M_NOHOST, EX_UNAVAILABLE, NULL, 151: { "...prog%mail", "-fc", "$u", NULL } 152: }, 153: /* local berkeley mail */ 154: { 155: "/usr/net/bin/sendberkmail", 156: M_FOPT|M_HDR|M_STRIPQ, EX_UNAVAILABLE, BerkLocal, 157: { "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL } 158: }, 159: /* arpanet mail */ 160: { 161: "/usr/lib/mailers/arpa", 162: M_STRIPQ, 0, ArpaLocal, 163: { "...arpa%mail", "$f", "$h", "$u", NULL } 164: }, 165: /* uucp mail (cheat & use Bell's v7 mail) */ 166: { 167: "/bin/mail", 168: M_ROPT|M_STRIPQ, EX_NOUSER, UucpLocal, 169: # ifdef DUMBMAIL 170: { "...uucp%mail", "$h!$u", NULL } 171: # else 172: { "...uucp%mail", "-d", "$h!$u", NULL } 173: # endif DUMBMAIL 174: }, 175: }; 176: 177: # define M_LOCAL 0 178: # define M_BERK 2 179: # define M_ARPA 3 180: # define M_UUCP 4 181: 182: 183: 184: struct parsetab ParseTab[] = 185: { 186: # ifdef HASARPA 187: '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 188: # endif HASARPA 189: # ifdef HASUUCP 190: '^', -1, P_MAP, "!", 191: '!', M_UUCP, 0, NULL, 192: # endif HASUUCP 193: '\0', M_LOCAL, P_MOVE, "", 194: }; 195: /* 196: ** GETNAME -- Get the current users login name. 197: ** 198: ** This is in config.c because it is somewhat machine dependent. 199: ** Examine it carefully for your installation. 200: ** 201: ** Algorithm: 202: ** See if the person is logged in. If so, return 203: ** the name s/he is logged in as. 204: ** Look up the user id in /etc/passwd. If found, 205: ** return that name. 206: ** Return NULL. 207: ** 208: ** Parameters: 209: ** none 210: ** 211: ** Returns: 212: ** The login name of this user. 213: ** NULL if this person is noone. 214: ** 215: ** Side Effects: 216: ** none 217: ** 218: ** Called By: 219: ** main 220: */ 221: 222: char * 223: getname() 224: { 225: register char *p; 226: register struct passwd *w; 227: extern struct passwd *getpwuid(); 228: static char namebuf[9]; 229: 230: # ifdef V6 231: w = getpwuid(getuid() & 0377); 232: # else 233: w = getpwuid(getuid()); 234: # endif V6 235: if (w != NULL) 236: { 237: strcpy(namebuf, w->pw_name); 238: return (namebuf); 239: } 240: return (NULL); 241: } 242: 243: # ifdef V6 244: /* 245: ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 246: ** 247: ** Returns the pathname of the user's tty. Returns NULL if 248: ** the user is not logged in or if s/he has write permission 249: ** denied. 250: ** 251: ** Parameters: 252: ** none 253: ** 254: ** Returns: 255: ** pathname of the user's tty. 256: ** NULL if not logged in or write permission denied. 257: ** 258: ** Side Effects: 259: ** none. 260: ** 261: ** WARNING: 262: ** Return value is in a local buffer. 263: ** 264: ** Called By: 265: ** savemail 266: */ 267: 268: # include <sys/types.h> 269: # include <sys/stat.h> 270: 271: char * 272: ttypath() 273: { 274: struct stat stbuf; 275: register int i; 276: static char pathn[] = "/dev/ttyx"; 277: extern int errno; 278: 279: /* compute the pathname of the controlling tty */ 280: if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 281: { 282: errno = 0; 283: return (NULL); 284: } 285: pathn[8] = i; 286: 287: /* see if we have write permission */ 288: if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 289: { 290: errno = 0; 291: return (NULL); 292: } 293: 294: /* see if the user is logged in */ 295: if (getlogin() == NULL) 296: return (NULL); 297: 298: /* looks good */ 299: return (pathn); 300: } 301: /* 302: ** FDOPEN -- Open a stdio file given an open file descriptor. 303: ** 304: ** This is included here because it is standard in v7, but we 305: ** need it in v6. 306: ** 307: ** Algorithm: 308: ** Open /dev/null to create a descriptor. 309: ** Close that descriptor. 310: ** Copy the existing fd into the descriptor. 311: ** 312: ** Parameters: 313: ** fd -- the open file descriptor. 314: ** type -- "r", "w", or whatever. 315: ** 316: ** Returns: 317: ** The file descriptor it creates. 318: ** 319: ** Side Effects: 320: ** none 321: ** 322: ** Called By: 323: ** deliver 324: ** 325: ** Notes: 326: ** The mode of fd must match "type". 327: */ 328: 329: FILE * 330: fdopen(fd, type) 331: int fd; 332: char *type; 333: { 334: register FILE *f; 335: 336: f = fopen("/dev/null", type); 337: close(fileno(f)); 338: fileno(f) = fd; 339: return (f); 340: } 341: /* 342: ** INDEX -- Return pointer to character in string 343: ** 344: ** For V7 compatibility. 345: ** 346: ** Parameters: 347: ** s -- a string to scan. 348: ** c -- a character to look for. 349: ** 350: ** Returns: 351: ** If c is in s, returns the address of the first 352: ** instance of c in s. 353: ** NULL if c is not in s. 354: ** 355: ** Side Effects: 356: ** none. 357: */ 358: 359: index(s, c) 360: register char *s; 361: register char c; 362: { 363: while (*s != '\0') 364: { 365: if (*s++ == c) 366: return (--s); 367: } 368: return (NULL); 369: } 370: # endif V6 371: 372: # ifndef V6 373: /* 374: ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 375: ** 376: ** Returns the pathname of the user's tty. Returns NULL if 377: ** the user is not logged in or if s/he has write permission 378: ** denied. 379: ** 380: ** Parameters: 381: ** none 382: ** 383: ** Returns: 384: ** pathname of the user's tty. 385: ** NULL if not logged in or write permission denied. 386: ** 387: ** Side Effects: 388: ** none. 389: ** 390: ** WARNING: 391: ** Return value is in a local buffer. 392: ** 393: ** Called By: 394: ** savemail 395: */ 396: 397: # include <sys/types.h> 398: # include <sys/stat.h> 399: 400: char * 401: ttypath() 402: { 403: struct stat stbuf; 404: register char *pathn; 405: extern int errno; 406: extern char *ttyname(); 407: 408: /* compute the pathname of the controlling tty */ 409: if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 410: { 411: errno = 0; 412: return (NULL); 413: } 414: 415: /* see if we have write permission */ 416: if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 417: { 418: errno = 0; 419: return (NULL); 420: } 421: 422: /* see if the user is logged in */ 423: if (getlogin() == NULL) 424: return (NULL); 425: 426: /* looks good */ 427: return (pathn); 428: } 429: # endif V6