|
|
1.1 ! root 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 char *getlogin(); ! 228: extern struct passwd *getpwuid(); ! 229: static char namebuf[9]; ! 230: ! 231: p = getlogin(); ! 232: if (p != NULL && p[0] != '\0') ! 233: return (p); ! 234: # ifdef V6 ! 235: w = getpwuid(getuid() & 0377); ! 236: # else ! 237: w = getpwuid(getuid()); ! 238: # endif V6 ! 239: if (w != NULL) ! 240: { ! 241: strcpy(namebuf, w->pw_name); ! 242: return (namebuf); ! 243: } ! 244: return (NULL); ! 245: } ! 246: ! 247: # ifdef V6 ! 248: /* ! 249: ** TTYPATH -- Get the path of the user's tty -- Version 6 version. ! 250: ** ! 251: ** Returns the pathname of the user's tty. Returns NULL if ! 252: ** the user is not logged in or if s/he has write permission ! 253: ** denied. ! 254: ** ! 255: ** Parameters: ! 256: ** none ! 257: ** ! 258: ** Returns: ! 259: ** pathname of the user's tty. ! 260: ** NULL if not logged in or write permission denied. ! 261: ** ! 262: ** Side Effects: ! 263: ** none. ! 264: ** ! 265: ** WARNING: ! 266: ** Return value is in a local buffer. ! 267: ** ! 268: ** Called By: ! 269: ** savemail ! 270: */ ! 271: ! 272: # include <sys/types.h> ! 273: # include <sys/stat.h> ! 274: ! 275: char * ! 276: ttypath() ! 277: { ! 278: struct stat stbuf; ! 279: register int i; ! 280: static char pathn[] = "/dev/ttyx"; ! 281: extern int errno; ! 282: ! 283: /* compute the pathname of the controlling tty */ ! 284: if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') ! 285: { ! 286: errno = 0; ! 287: return (NULL); ! 288: } ! 289: pathn[8] = i; ! 290: ! 291: /* see if we have write permission */ ! 292: if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) ! 293: { ! 294: errno = 0; ! 295: return (NULL); ! 296: } ! 297: ! 298: /* see if the user is logged in */ ! 299: if (getlogin() == NULL) ! 300: return (NULL); ! 301: ! 302: /* looks good */ ! 303: return (pathn); ! 304: } ! 305: /* ! 306: ** FDOPEN -- Open a stdio file given an open file descriptor. ! 307: ** ! 308: ** This is included here because it is standard in v7, but we ! 309: ** need it in v6. ! 310: ** ! 311: ** Algorithm: ! 312: ** Open /dev/null to create a descriptor. ! 313: ** Close that descriptor. ! 314: ** Copy the existing fd into the descriptor. ! 315: ** ! 316: ** Parameters: ! 317: ** fd -- the open file descriptor. ! 318: ** type -- "r", "w", or whatever. ! 319: ** ! 320: ** Returns: ! 321: ** The file descriptor it creates. ! 322: ** ! 323: ** Side Effects: ! 324: ** none ! 325: ** ! 326: ** Called By: ! 327: ** deliver ! 328: ** ! 329: ** Notes: ! 330: ** The mode of fd must match "type". ! 331: */ ! 332: ! 333: FILE * ! 334: fdopen(fd, type) ! 335: int fd; ! 336: char *type; ! 337: { ! 338: register FILE *f; ! 339: ! 340: f = fopen("/dev/null", type); ! 341: close(fileno(f)); ! 342: fileno(f) = fd; ! 343: return (f); ! 344: } ! 345: /* ! 346: ** INDEX -- Return pointer to character in string ! 347: ** ! 348: ** For V7 compatibility. ! 349: ** ! 350: ** Parameters: ! 351: ** s -- a string to scan. ! 352: ** c -- a character to look for. ! 353: ** ! 354: ** Returns: ! 355: ** If c is in s, returns the address of the first ! 356: ** instance of c in s. ! 357: ** NULL if c is not in s. ! 358: ** ! 359: ** Side Effects: ! 360: ** none. ! 361: */ ! 362: ! 363: index(s, c) ! 364: register char *s; ! 365: register char c; ! 366: { ! 367: while (*s != '\0') ! 368: { ! 369: if (*s++ == c) ! 370: return (--s); ! 371: } ! 372: return (NULL); ! 373: } ! 374: # endif V6 ! 375: ! 376: # ifndef V6 ! 377: /* ! 378: ** TTYPATH -- Get the path of the user's tty -- Version 7 version. ! 379: ** ! 380: ** Returns the pathname of the user's tty. Returns NULL if ! 381: ** the user is not logged in or if s/he has write permission ! 382: ** denied. ! 383: ** ! 384: ** Parameters: ! 385: ** none ! 386: ** ! 387: ** Returns: ! 388: ** pathname of the user's tty. ! 389: ** NULL if not logged in or write permission denied. ! 390: ** ! 391: ** Side Effects: ! 392: ** none. ! 393: ** ! 394: ** WARNING: ! 395: ** Return value is in a local buffer. ! 396: ** ! 397: ** Called By: ! 398: ** savemail ! 399: */ ! 400: ! 401: # include <sys/types.h> ! 402: # include <sys/stat.h> ! 403: ! 404: char * ! 405: ttypath() ! 406: { ! 407: struct stat stbuf; ! 408: register char *pathn; ! 409: extern int errno; ! 410: extern char *ttyname(); ! 411: ! 412: /* compute the pathname of the controlling tty */ ! 413: if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) ! 414: { ! 415: errno = 0; ! 416: return (NULL); ! 417: } ! 418: ! 419: /* see if we have write permission */ ! 420: if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) ! 421: { ! 422: errno = 0; ! 423: return (NULL); ! 424: } ! 425: ! 426: /* see if the user is logged in */ ! 427: if (getlogin() == NULL) ! 428: return (NULL); ! 429: ! 430: /* looks good */ ! 431: return (pathn); ! 432: } ! 433: # endif V6
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.