| 1 | /* |
| 2 | ** Sendmail |
| 3 | ** Copyright (c) 1983 Eric P. Allman |
| 4 | ** Berkeley, California |
| 5 | ** |
| 6 | ** Copyright (c) 1983 Regents of the University of California. |
| 7 | ** All rights reserved. The Berkeley software License Agreement |
| 8 | ** specifies the terms and conditions for redistribution. |
| 9 | */ |
| 10 | |
| 11 | #ifndef lint |
| 12 | static char SccsId[] = "@(#)conf.c 5.1 (Berkeley) %G%"; |
| 13 | #endif not lint |
| 14 | |
| 15 | # include <pwd.h> |
| 16 | # include <sys/ioctl.h> |
| 17 | # include "sendmail.h" |
| 18 | |
| 19 | /* |
| 20 | ** CONF.C -- Sendmail Configuration Tables. |
| 21 | ** |
| 22 | ** Defines the configuration of this installation. |
| 23 | ** |
| 24 | ** Compilation Flags: |
| 25 | ** V6 -- running on a version 6 system. This determines |
| 26 | ** whether to define certain routines between |
| 27 | ** the two systems. If you are running a funny |
| 28 | ** system, e.g., V6 with long tty names, this |
| 29 | ** should be checked carefully. |
| 30 | ** VMUNIX -- running on a Berkeley UNIX system. |
| 31 | ** |
| 32 | ** Configuration Variables: |
| 33 | ** HdrInfo -- a table describing well-known header fields. |
| 34 | ** Each entry has the field name and some flags, |
| 35 | ** which are described in sendmail.h. |
| 36 | ** |
| 37 | ** Notes: |
| 38 | ** I have tried to put almost all the reasonable |
| 39 | ** configuration information into the configuration |
| 40 | ** file read at runtime. My intent is that anything |
| 41 | ** here is a function of the version of UNIX you |
| 42 | ** are running, or is really static -- for example |
| 43 | ** the headers are a superset of widely used |
| 44 | ** protocols. If you find yourself playing with |
| 45 | ** this file too much, you may be making a mistake! |
| 46 | */ |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | SCCSID(@(#)conf.c 5.1 %G%); |
| 52 | \f/* |
| 53 | ** Header info table |
| 54 | ** Final (null) entry contains the flags used for any other field. |
| 55 | ** |
| 56 | ** Not all of these are actually handled specially by sendmail |
| 57 | ** at this time. They are included as placeholders, to let |
| 58 | ** you know that "someday" I intend to have sendmail do |
| 59 | ** something with them. |
| 60 | */ |
| 61 | |
| 62 | struct hdrinfo HdrInfo[] = |
| 63 | { |
| 64 | /* originator fields, most to least significant */ |
| 65 | "resent-sender", H_FROM|H_RESENT, |
| 66 | "resent-from", H_FROM|H_RESENT, |
| 67 | "sender", H_FROM, |
| 68 | "from", H_FROM, |
| 69 | "full-name", H_ACHECK, |
| 70 | "return-receipt-to", H_FROM, |
| 71 | "errors-to", H_FROM, |
| 72 | /* destination fields */ |
| 73 | "to", H_RCPT, |
| 74 | "resent-to", H_RCPT|H_RESENT, |
| 75 | "cc", H_RCPT, |
| 76 | "resent-cc", H_RCPT|H_RESENT, |
| 77 | "bcc", H_RCPT|H_ACHECK, |
| 78 | "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, |
| 79 | /* message identification and control */ |
| 80 | "message-id", 0, |
| 81 | "resent-message-id", H_RESENT, |
| 82 | "message", H_EOH, |
| 83 | "text", H_EOH, |
| 84 | /* date fields */ |
| 85 | "date", 0, |
| 86 | "resent-date", H_RESENT, |
| 87 | /* trace fields */ |
| 88 | "received", H_TRACE|H_FORCE, |
| 89 | "via", H_TRACE|H_FORCE, |
| 90 | "mail-from", H_TRACE|H_FORCE, |
| 91 | |
| 92 | NULL, 0, |
| 93 | }; |
| 94 | |
| 95 | |
| 96 | /* |
| 97 | ** ARPANET error message numbers. |
| 98 | */ |
| 99 | |
| 100 | char Arpa_Info[] = "050"; /* arbitrary info */ |
| 101 | char Arpa_TSyserr[] = "451"; /* some (transient) system error */ |
| 102 | char Arpa_PSyserr[] = "554"; /* some (permanent) system error */ |
| 103 | char Arpa_Usrerr[] = "554"; /* some (fatal) user error */ |
| 104 | |
| 105 | |
| 106 | |
| 107 | /* |
| 108 | ** Location of system files/databases/etc. |
| 109 | */ |
| 110 | |
| 111 | char *ConfFile = "/usr/lib/sendmail.cf"; /* runtime configuration */ |
| 112 | char *FreezeFile = "/usr/lib/sendmail.fc"; /* frozen version of above */ |
| 113 | |
| 114 | |
| 115 | |
| 116 | /* |
| 117 | ** Some other configuration.... |
| 118 | */ |
| 119 | |
| 120 | char SpaceSub; /* character to replace <lwsp> in addrs */ |
| 121 | int QueueLA; /* load avg > QueueLA -> just queue */ |
| 122 | int RefuseLA; /* load avg > RefuseLA -> refuse connections */ |
| 123 | \f |
| 124 | # ifdef V6 |
| 125 | /* |
| 126 | ** TTYNAME -- return name of terminal. |
| 127 | ** |
| 128 | ** Parameters: |
| 129 | ** fd -- file descriptor to check. |
| 130 | ** |
| 131 | ** Returns: |
| 132 | ** pointer to full path of tty. |
| 133 | ** NULL if no tty. |
| 134 | ** |
| 135 | ** Side Effects: |
| 136 | ** none. |
| 137 | */ |
| 138 | |
| 139 | char * |
| 140 | ttyname(fd) |
| 141 | int fd; |
| 142 | { |
| 143 | register char tn; |
| 144 | static char pathn[] = "/dev/ttyx"; |
| 145 | |
| 146 | /* compute the pathname of the controlling tty */ |
| 147 | if ((tn = ttyn(fd)) == NULL) |
| 148 | { |
| 149 | errno = 0; |
| 150 | return (NULL); |
| 151 | } |
| 152 | pathn[8] = tn; |
| 153 | return (pathn); |
| 154 | } |
| 155 | \f/* |
| 156 | ** FDOPEN -- Open a stdio file given an open file descriptor. |
| 157 | ** |
| 158 | ** This is included here because it is standard in v7, but we |
| 159 | ** need it in v6. |
| 160 | ** |
| 161 | ** Algorithm: |
| 162 | ** Open /dev/null to create a descriptor. |
| 163 | ** Close that descriptor. |
| 164 | ** Copy the existing fd into the descriptor. |
| 165 | ** |
| 166 | ** Parameters: |
| 167 | ** fd -- the open file descriptor. |
| 168 | ** type -- "r", "w", or whatever. |
| 169 | ** |
| 170 | ** Returns: |
| 171 | ** The file descriptor it creates. |
| 172 | ** |
| 173 | ** Side Effects: |
| 174 | ** none |
| 175 | ** |
| 176 | ** Called By: |
| 177 | ** deliver |
| 178 | ** |
| 179 | ** Notes: |
| 180 | ** The mode of fd must match "type". |
| 181 | */ |
| 182 | |
| 183 | FILE * |
| 184 | fdopen(fd, type) |
| 185 | int fd; |
| 186 | char *type; |
| 187 | { |
| 188 | register FILE *f; |
| 189 | |
| 190 | f = fopen("/dev/null", type); |
| 191 | (void) close(fileno(f)); |
| 192 | fileno(f) = fd; |
| 193 | return (f); |
| 194 | } |
| 195 | \f/* |
| 196 | ** INDEX -- Return pointer to character in string |
| 197 | ** |
| 198 | ** For V7 compatibility. |
| 199 | ** |
| 200 | ** Parameters: |
| 201 | ** s -- a string to scan. |
| 202 | ** c -- a character to look for. |
| 203 | ** |
| 204 | ** Returns: |
| 205 | ** If c is in s, returns the address of the first |
| 206 | ** instance of c in s. |
| 207 | ** NULL if c is not in s. |
| 208 | ** |
| 209 | ** Side Effects: |
| 210 | ** none. |
| 211 | */ |
| 212 | |
| 213 | char * |
| 214 | index(s, c) |
| 215 | register char *s; |
| 216 | register char c; |
| 217 | { |
| 218 | while (*s != '\0') |
| 219 | { |
| 220 | if (*s++ == c) |
| 221 | return (--s); |
| 222 | } |
| 223 | return (NULL); |
| 224 | } |
| 225 | \f/* |
| 226 | ** UMASK -- fake the umask system call. |
| 227 | ** |
| 228 | ** Since V6 always acts like the umask is zero, we will just |
| 229 | ** assume the same thing. |
| 230 | */ |
| 231 | |
| 232 | /*ARGSUSED*/ |
| 233 | umask(nmask) |
| 234 | { |
| 235 | return (0); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* |
| 240 | ** GETRUID -- get real user id. |
| 241 | */ |
| 242 | |
| 243 | getruid() |
| 244 | { |
| 245 | return (getuid() & 0377); |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /* |
| 250 | ** GETRGID -- get real group id. |
| 251 | */ |
| 252 | |
| 253 | getrgid() |
| 254 | { |
| 255 | return (getgid() & 0377); |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /* |
| 260 | ** GETEUID -- get effective user id. |
| 261 | */ |
| 262 | |
| 263 | geteuid() |
| 264 | { |
| 265 | return ((getuid() >> 8) & 0377); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /* |
| 270 | ** GETEGID -- get effective group id. |
| 271 | */ |
| 272 | |
| 273 | getegid() |
| 274 | { |
| 275 | return ((getgid() >> 8) & 0377); |
| 276 | } |
| 277 | |
| 278 | # endif V6 |
| 279 | \f |
| 280 | # ifndef V6 |
| 281 | |
| 282 | /* |
| 283 | ** GETRUID -- get real user id (V7) |
| 284 | */ |
| 285 | |
| 286 | getruid() |
| 287 | { |
| 288 | if (OpMode == MD_DAEMON) |
| 289 | return (RealUid); |
| 290 | else |
| 291 | return (getuid()); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | /* |
| 296 | ** GETRGID -- get real group id (V7). |
| 297 | */ |
| 298 | |
| 299 | getrgid() |
| 300 | { |
| 301 | if (OpMode == MD_DAEMON) |
| 302 | return (RealGid); |
| 303 | else |
| 304 | return (getgid()); |
| 305 | } |
| 306 | |
| 307 | # endif V6 |
| 308 | \f/* |
| 309 | ** USERNAME -- return the user id of the logged in user. |
| 310 | ** |
| 311 | ** Parameters: |
| 312 | ** none. |
| 313 | ** |
| 314 | ** Returns: |
| 315 | ** The login name of the logged in user. |
| 316 | ** |
| 317 | ** Side Effects: |
| 318 | ** none. |
| 319 | ** |
| 320 | ** Notes: |
| 321 | ** The return value is statically allocated. |
| 322 | */ |
| 323 | |
| 324 | char * |
| 325 | username() |
| 326 | { |
| 327 | static char *myname = NULL; |
| 328 | extern char *getlogin(); |
| 329 | register struct passwd *pw; |
| 330 | extern struct passwd *getpwuid(); |
| 331 | |
| 332 | /* cache the result */ |
| 333 | if (myname == NULL) |
| 334 | { |
| 335 | myname = getlogin(); |
| 336 | if (myname == NULL || myname[0] == '\0') |
| 337 | { |
| 338 | |
| 339 | pw = getpwuid(getruid()); |
| 340 | if (pw != NULL) |
| 341 | myname = pw->pw_name; |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | |
| 346 | pw = getpwnam(myname); |
| 347 | if(getuid() != pw->pw_uid) |
| 348 | { |
| 349 | pw = getpwuid(getuid()); |
| 350 | myname = pw->pw_name; |
| 351 | } |
| 352 | } |
| 353 | if (myname == NULL || myname[0] == '\0') |
| 354 | { |
| 355 | syserr("Who are you?"); |
| 356 | myname = "postmaster"; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return (myname); |
| 361 | } |
| 362 | \f/* |
| 363 | ** TTYPATH -- Get the path of the user's tty |
| 364 | ** |
| 365 | ** Returns the pathname of the user's tty. Returns NULL if |
| 366 | ** the user is not logged in or if s/he has write permission |
| 367 | ** denied. |
| 368 | ** |
| 369 | ** Parameters: |
| 370 | ** none |
| 371 | ** |
| 372 | ** Returns: |
| 373 | ** pathname of the user's tty. |
| 374 | ** NULL if not logged in or write permission denied. |
| 375 | ** |
| 376 | ** Side Effects: |
| 377 | ** none. |
| 378 | ** |
| 379 | ** WARNING: |
| 380 | ** Return value is in a local buffer. |
| 381 | ** |
| 382 | ** Called By: |
| 383 | ** savemail |
| 384 | */ |
| 385 | |
| 386 | # include <sys/stat.h> |
| 387 | |
| 388 | char * |
| 389 | ttypath() |
| 390 | { |
| 391 | struct stat stbuf; |
| 392 | register char *pathn; |
| 393 | extern char *ttyname(); |
| 394 | extern char *getlogin(); |
| 395 | |
| 396 | /* compute the pathname of the controlling tty */ |
| 397 | if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && |
| 398 | (pathn = ttyname(0)) == NULL) |
| 399 | { |
| 400 | errno = 0; |
| 401 | return (NULL); |
| 402 | } |
| 403 | |
| 404 | /* see if we have write permission */ |
| 405 | if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) |
| 406 | { |
| 407 | errno = 0; |
| 408 | return (NULL); |
| 409 | } |
| 410 | |
| 411 | /* see if the user is logged in */ |
| 412 | if (getlogin() == NULL) |
| 413 | return (NULL); |
| 414 | |
| 415 | /* looks good */ |
| 416 | return (pathn); |
| 417 | } |
| 418 | \f/* |
| 419 | ** CHECKCOMPAT -- check for From and To person compatible. |
| 420 | ** |
| 421 | ** This routine can be supplied on a per-installation basis |
| 422 | ** to determine whether a person is allowed to send a message. |
| 423 | ** This allows restriction of certain types of internet |
| 424 | ** forwarding or registration of users. |
| 425 | ** |
| 426 | ** If the hosts are found to be incompatible, an error |
| 427 | ** message should be given using "usrerr" and FALSE should |
| 428 | ** be returned. |
| 429 | ** |
| 430 | ** 'NoReturn' can be set to suppress the return-to-sender |
| 431 | ** function; this should be done on huge messages. |
| 432 | ** |
| 433 | ** Parameters: |
| 434 | ** to -- the person being sent to. |
| 435 | ** |
| 436 | ** Returns: |
| 437 | ** TRUE -- ok to send. |
| 438 | ** FALSE -- not ok. |
| 439 | ** |
| 440 | ** Side Effects: |
| 441 | ** none (unless you include the usrerr stuff) |
| 442 | */ |
| 443 | |
| 444 | bool |
| 445 | checkcompat(to) |
| 446 | register ADDRESS *to; |
| 447 | { |
| 448 | # ifdef lint |
| 449 | if (to == NULL) |
| 450 | to++; |
| 451 | # endif lint |
| 452 | # ifdef EXAMPLE_CODE |
| 453 | /* this code is intended as an example only */ |
| 454 | register STAB *s; |
| 455 | |
| 456 | s = stab("arpa", ST_MAILER, ST_FIND); |
| 457 | if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && |
| 458 | to->q_mailer == s->s_mailer) |
| 459 | { |
| 460 | usrerr("No ARPA mail through this machine: see your system administration"); |
| 461 | /* NoReturn = TRUE; to supress return copy */ |
| 462 | return (FALSE); |
| 463 | } |
| 464 | # endif EXAMPLE_CODE |
| 465 | return (TRUE); |
| 466 | } |
| 467 | \f/* |
| 468 | ** HOLDSIGS -- arrange to hold all signals |
| 469 | ** |
| 470 | ** Parameters: |
| 471 | ** none. |
| 472 | ** |
| 473 | ** Returns: |
| 474 | ** none. |
| 475 | ** |
| 476 | ** Side Effects: |
| 477 | ** Arranges that signals are held. |
| 478 | */ |
| 479 | |
| 480 | holdsigs() |
| 481 | { |
| 482 | } |
| 483 | \f/* |
| 484 | ** RLSESIGS -- arrange to release all signals |
| 485 | ** |
| 486 | ** This undoes the effect of holdsigs. |
| 487 | ** |
| 488 | ** Parameters: |
| 489 | ** none. |
| 490 | ** |
| 491 | ** Returns: |
| 492 | ** none. |
| 493 | ** |
| 494 | ** Side Effects: |
| 495 | ** Arranges that signals are released. |
| 496 | */ |
| 497 | |
| 498 | rlsesigs() |
| 499 | { |
| 500 | } |
| 501 | \f/* |
| 502 | ** GETLA -- get the current load average |
| 503 | ** |
| 504 | ** This code stolen from la.c. |
| 505 | ** |
| 506 | ** Parameters: |
| 507 | ** none. |
| 508 | ** |
| 509 | ** Returns: |
| 510 | ** The current load average as an integer. |
| 511 | ** |
| 512 | ** Side Effects: |
| 513 | ** none. |
| 514 | */ |
| 515 | |
| 516 | #ifdef VMUNIX |
| 517 | |
| 518 | #include <nlist.h> |
| 519 | |
| 520 | struct nlist Nl[] = |
| 521 | { |
| 522 | { "_avenrun" }, |
| 523 | #define X_AVENRUN 0 |
| 524 | { 0 }, |
| 525 | }; |
| 526 | |
| 527 | getla() |
| 528 | { |
| 529 | static int kmem = -1; |
| 530 | double avenrun[3]; |
| 531 | |
| 532 | if (kmem < 0) |
| 533 | { |
| 534 | kmem = open("/dev/kmem", 0); |
| 535 | if (kmem < 0) |
| 536 | return (-1); |
| 537 | (void) ioctl(kmem, FIOCLEX, 0); |
| 538 | nlist("/vmunix", Nl); |
| 539 | if (Nl[0].n_type == 0) |
| 540 | return (-1); |
| 541 | } |
| 542 | if (lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0) < 0 || |
| 543 | read(kmem, avenrun, sizeof(avenrun)) < sizeof(avenrun)) |
| 544 | { |
| 545 | /* thank you Ian */ |
| 546 | return (-1); |
| 547 | } |
| 548 | return ((int) (avenrun[0] + 0.5)); |
| 549 | } |
| 550 | |
| 551 | #else VMUNIX |
| 552 | |
| 553 | getla() |
| 554 | { |
| 555 | return (0); |
| 556 | } |
| 557 | |
| 558 | #endif VMUNIX |
| 559 | \f/* |
| 560 | ** DBMCLOSE -- close the DBM file |
| 561 | ** |
| 562 | ** This depends on the implementation of the DBM library. It |
| 563 | ** seems to work for all versions that I have come across. |
| 564 | ** |
| 565 | ** Parameters: |
| 566 | ** none. |
| 567 | ** |
| 568 | ** Returns: |
| 569 | ** none. |
| 570 | ** |
| 571 | ** Side Effects: |
| 572 | ** Closes the current DBM file; dbminit must be |
| 573 | ** called again to continue using the DBM routines. |
| 574 | */ |
| 575 | |
| 576 | dbmclose() |
| 577 | { |
| 578 | extern int pagf, dirf; /* defined in the DBM package */ |
| 579 | |
| 580 | (void) close(pagf); |
| 581 | (void) close(dirf); |
| 582 | } |