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_FHDR -- if set, the header that we 65 ** generate will be used literally, so 66 ** we must force it to be correct. The 67 ** effect is that we generate a header 68 ** even if one exists. 69 ** M_NOHOST -- if set, this mailer doesn't care 70 ** about the host part (e.g., the local 71 ** mailer). 72 ** M_STRIPQ -- if set, strip quote (`"') 73 ** characters out of parameters as you 74 ** transliterate them into the argument 75 ** vector. For example, the local mailer 76 ** is called directly, so these should be 77 ** stripped, but the program-mailer (i.e., 78 ** csh) should leave them in. 79 ** - an exit status to use as the code for the 80 ** error message print if the mailer returns 81 ** something we don't understand. 82 ** - A list of names that are to be considered 83 ** "local" (and hence are stripped off) for 84 ** this mailer. 85 ** - An argument vector to be passed to the 86 ** mailer with the following substitutions: 87 ** $f - the from person name. 88 ** $u - the target user name. 89 ** $h - the target user host. 90 ** $c - the hop count. 91 ** >>>>>>>>>> Entry zero must be for the local 92 ** >> NOTE >> mailer and entry one must be for 93 ** >>>>>>>>>> the shell. 94 ** ParseTab -- a table driving the parsing process. Each 95 ** entry contains: 96 ** - a character that will trigger this entry. 97 ** - an index into the Mailer table. 98 ** - a word of flags, described in dlvrmail.h. 99 ** - an argument. If we have P_MAP, it is the 100 ** character to turn the trigger character into. 101 ** If we have P_MOVE, it is the site to send it 102 ** to, using the mailer specified above. 103 ** This table will almost certainly have to be 104 ** changed on your site if you have anything more 105 ** than the UUCP net. 106 */ 107 108 109 110 111 static char SccsId[] = "@(#)conf.c 2.2 11/21/80"; 112 113 114 bool UseMsgId = FALSE; /* don't put message id's in anywhere */ 115 116 # include <whoami.h> /* definitions of machine id's at berkeley */ 117 118 # ifdef BERKELEY 119 char *ArpaHost = "Berkeley"; /* host name of gateway on Arpanet */ 120 # else BERKELEY 121 char *ArpaHost = "[unknown]"; 122 char *MyLocName = sysname; 123 # define HASUUCP /* default to having UUCP net */ 124 char *UucpLocal[] = { sysname, NULL }; 125 # endif BERKELEY 126 127 # ifdef ING70 128 static char *BerkLocal[] = { "i", "ingres", "ing70", NULL }; 129 # define ArpaLocal NULL 130 char *MyLocName = "Ing70"; 131 # define HASARPA 132 # define V6 133 # endif ING70 134 135 # ifdef INGVAX 136 static char *BerkLocal[] = { "j", "ingvax", NULL }; 137 char *MyLocName = "IngVax"; 138 # endif INGVAX 139 140 # ifdef CSVAX 141 static char *BerkLocal[] = { "v", "csvax", "vax", NULL }; 142 static char *UucpLocal[] = { "ucbvax", "ernie", NULL }; 143 char *MyLocName = "CSVAX"; 144 # define HASUUCP 145 # define NETV6MAIL 146 # endif CSVAX 147 148 # ifdef CORY 149 /* untested */ 150 static char *BerkLocal[] = { "y", "cory", NULL }; 151 char *MyLocName = "Cory"; 152 # endif CORY 153 154 # ifdef IMAGE 155 /* untested */ 156 static char *BerkLocal[] = { "m", "image", NULL }; 157 char *MyLocName = "Image"; 158 # define V6 159 # endif IMAGE 160 161 # ifdef ESVAX 162 /* untested */ 163 static char *BerkLocal[] = { "o", "esvax", NULL }; 164 char *MyLocName = "ESVAX"; 165 # endif ESVAX 166 167 # ifdef EECS40 168 /* untested */ 169 static char *BerkLocal[] = { "z", "eecs40", NULL }; 170 char *MyLocName = "EECS40"; 171 # define V6 172 # endif EECS40 173 174 175 # ifndef HASARPA 176 # define ArpaLocal NULL 177 # endif HASARPA 178 179 # ifndef HASUUCP 180 # define UucpLocal NULL 181 # endif HASUUCP 182 183 184 struct mailer Mailer[] = 185 { 186 /* local mail -- must be #0 */ 187 { 188 # ifdef NETV6MAIL 189 "/usr/net/bin/v6mail", 190 # else 191 "/bin/mail", 192 # endif 193 M_ROPT|M_NOHOST|M_STRIPQ, EX_NOUSER, NULL, 194 { "...local%mail", "-d", "$u", NULL } 195 }, 196 /* pipes through programs -- must be #1 */ 197 { 198 "/bin/csh", 199 M_HDR|M_FHDR|M_NOHOST, EX_UNAVAILABLE, NULL, 200 { "...prog%mail", "-fc", "$u", NULL } 201 }, 202 /* local berkeley mail */ 203 { 204 "/usr/net/bin/sendberkmail", 205 M_FOPT|M_HDR|M_STRIPQ, EX_UNAVAILABLE, BerkLocal, 206 { "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL } 207 }, 208 /* arpanet mail */ 209 { 210 "/usr/lib/mailers/arpa", 211 M_STRIPQ, 0, ArpaLocal, 212 { "...arpa%mail", "$f", "$h", "$u", NULL } 213 }, 214 /* uucp mail (cheat & use Bell's v7 mail) */ 215 { 216 "/bin/mail", 217 M_ROPT|M_STRIPQ, EX_NOUSER, UucpLocal, 218 # ifdef DUMBMAIL 219 { "...uucp%mail", "$h!$u", NULL } 220 # else 221 { "...uucp%mail", "-d", "$h!$u", NULL } 222 # endif DUMBMAIL 223 }, 224 }; 225 226 # define M_LOCAL 0 227 # define M_BERK 2 228 # define M_ARPA 3 229 # define M_UUCP 4 230 231 232 233 # ifdef BERKELEY 234 struct parsetab ParseTab[] = 235 { 236 ':', M_BERK, P_ONE, NULL, 237 # ifdef HASARPA 238 '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 239 # else 240 '@', M_BERK, P_HLAST|P_USR_UPPER|P_MOVE, "ing70", 241 # endif HASARPA 242 '^', -1, P_MAP, "!", 243 # ifdef HASUUCP 244 '!', M_UUCP, 0, NULL, 245 # else 246 '!', M_BERK, P_MOVE, "csvax", 247 # endif HASUUCP 248 '.', -1, P_MAP|P_ONE, ":", 249 '\0', M_LOCAL, P_MOVE, "", 250 }; 251 # else BERKELEY 252 struct parsetab ParseTab[] = 253 { 254 # ifdef HASARPA 255 '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 256 # endif HASARPA 257 # ifdef HASUUCP 258 '^', -1, P_MAP, "!", 259 '!', M_UUCP, 0, NULL, 260 # endif HASUUCP 261 '\0', M_LOCAL, P_MOVE, "", 262 }; 263 # endif BERKELEY 264 /* 265 ** GETNAME -- Get the current users login name. 266 ** 267 ** This is in config.c because it is somewhat machine dependent. 268 ** Examine it carefully for your installation. 269 ** 270 ** Algorithm: 271 ** See if the person is logged in. If so, return 272 ** the name s/he is logged in as. 273 ** Look up the user id in /etc/passwd. If found, 274 ** return that name. 275 ** Return NULL. 276 ** 277 ** Parameters: 278 ** none 279 ** 280 ** Returns: 281 ** The login name of this user. 282 ** NULL if this person is noone. 283 ** 284 ** Side Effects: 285 ** none 286 ** 287 ** Called By: 288 ** main 289 */ 290 291 char * 292 getname() 293 { 294 register char *p; 295 register struct passwd *w; 296 extern char *getlogin(); 297 extern struct passwd *getpwuid(); 298 static char namebuf[9]; 299 300 p = getlogin(); 301 if (p != NULL && p[0] != '\0') 302 return (p); 303 # ifdef V6 304 w = getpwuid(getuid() & 0377); 305 # else 306 w = getpwuid(getuid()); 307 # endif V6 308 if (w != NULL) 309 { 310 strcpy(namebuf, w->pw_name); 311 return (namebuf); 312 } 313 return (NULL); 314 } 315 316 # ifdef V6 317 /* 318 ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 319 ** 320 ** Returns the pathname of the user's tty. Returns NULL if 321 ** the user is not logged in or if s/he has write permission 322 ** denied. 323 ** 324 ** Parameters: 325 ** none 326 ** 327 ** Returns: 328 ** pathname of the user's tty. 329 ** NULL if not logged in or write permission denied. 330 ** 331 ** Side Effects: 332 ** none. 333 ** 334 ** WARNING: 335 ** Return value is in a local buffer. 336 ** 337 ** Called By: 338 ** savemail 339 */ 340 341 # include <sys/types.h> 342 # include <sys/stat.h> 343 344 char * 345 ttypath() 346 { 347 struct stat stbuf; 348 register int i; 349 static char pathn[] = "/dev/ttyx"; 350 extern int errno; 351 352 /* compute the pathname of the controlling tty */ 353 if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 354 { 355 errno = 0; 356 return (NULL); 357 } 358 pathn[8] = i; 359 360 /* see if we have write permission */ 361 if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 362 { 363 errno = 0; 364 return (NULL); 365 } 366 367 /* see if the user is logged in */ 368 if (getlogin() == NULL) 369 return (NULL); 370 371 /* looks good */ 372 return (pathn); 373 } 374 /* 375 ** FDOPEN -- Open a stdio file given an open file descriptor. 376 ** 377 ** This is included here because it is standard in v7, but we 378 ** need it in v6. 379 ** 380 ** Algorithm: 381 ** Open /dev/null to create a descriptor. 382 ** Close that descriptor. 383 ** Copy the existing fd into the descriptor. 384 ** 385 ** Parameters: 386 ** fd -- the open file descriptor. 387 ** type -- "r", "w", or whatever. 388 ** 389 ** Returns: 390 ** The file descriptor it creates. 391 ** 392 ** Side Effects: 393 ** none 394 ** 395 ** Called By: 396 ** deliver 397 ** 398 ** Notes: 399 ** The mode of fd must match "type". 400 */ 401 402 FILE * 403 fdopen(fd, type) 404 int fd; 405 char *type; 406 { 407 register FILE *f; 408 409 f = fopen("/dev/null", type); 410 close(fileno(f)); 411 fileno(f) = fd; 412 return (f); 413 } 414 /* 415 ** INDEX -- Return pointer to character in string 416 ** 417 ** For V7 compatibility. 418 ** 419 ** Parameters: 420 ** s -- a string to scan. 421 ** c -- a character to look for. 422 ** 423 ** Returns: 424 ** If c is in s, returns the address of the first 425 ** instance of c in s. 426 ** NULL if c is not in s. 427 ** 428 ** Side Effects: 429 ** none. 430 */ 431 432 index(s, c) 433 register char *s; 434 register char c; 435 { 436 while (*s != '\0') 437 { 438 if (*s++ == c) 439 return (--s); 440 } 441 return (NULL); 442 } 443 # endif V6 444 445 # ifndef V6 446 /* 447 ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 448 ** 449 ** Returns the pathname of the user's tty. Returns NULL if 450 ** the user is not logged in or if s/he has write permission 451 ** denied. 452 ** 453 ** Parameters: 454 ** none 455 ** 456 ** Returns: 457 ** pathname of the user's tty. 458 ** NULL if not logged in or write permission denied. 459 ** 460 ** Side Effects: 461 ** none. 462 ** 463 ** WARNING: 464 ** Return value is in a local buffer. 465 ** 466 ** Called By: 467 ** savemail 468 */ 469 470 # include <sys/types.h> 471 # include <sys/stat.h> 472 473 char * 474 ttypath() 475 { 476 struct stat stbuf; 477 register char *pathn; 478 extern int errno; 479 extern char *ttyname(); 480 481 /* compute the pathname of the controlling tty */ 482 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 483 { 484 errno = 0; 485 return (NULL); 486 } 487 488 /* see if we have write permission */ 489 if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 490 { 491 errno = 0; 492 return (NULL); 493 } 494 495 /* see if the user is logged in */ 496 if (getlogin() == NULL) 497 return (NULL); 498 499 /* looks good */ 500 return (pathn); 501 } 502 # endif V6 503