1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 */ 8 9 #ifndef lint 10 static char sccsid[] = "@(#)readcf.c 5.51 (Berkeley) 12/11/92"; 11 #endif /* not lint */ 12 13 # include "sendmail.h" 14 # include <sys/stat.h> 15 # include <unistd.h> 16 17 /* 18 ** READCF -- read control file. 19 ** 20 ** This routine reads the control file and builds the internal 21 ** form. 22 ** 23 ** The file is formatted as a sequence of lines, each taken 24 ** atomically. The first character of each line describes how 25 ** the line is to be interpreted. The lines are: 26 ** Dxval Define macro x to have value val. 27 ** Cxword Put word into class x. 28 ** Fxfile [fmt] Read file for lines to put into 29 ** class x. Use scanf string 'fmt' 30 ** or "%s" if not present. Fmt should 31 ** only produce one string-valued result. 32 ** Hname: value Define header with field-name 'name' 33 ** and value as specified; this will be 34 ** macro expanded immediately before 35 ** use. 36 ** Sn Use rewriting set n. 37 ** Rlhs rhs Rewrite addresses that match lhs to 38 ** be rhs. 39 ** Mn arg=val... Define mailer. n is the internal name. 40 ** Args specify mailer parameters. 41 ** Oxvalue Set option x to value. 42 ** Pname=value Set precedence name to value. 43 ** Vversioncode Version level of configuration syntax. 44 ** Kmapname mapclass arguments.... 45 ** Define keyed lookup of a given class. 46 ** Arguments are class dependent. 47 ** 48 ** Parameters: 49 ** cfname -- control file name. 50 ** safe -- TRUE if this is the system config file; 51 ** FALSE otherwise. 52 ** e -- the main envelope. 53 ** 54 ** Returns: 55 ** none. 56 ** 57 ** Side Effects: 58 ** Builds several internal tables. 59 */ 60 61 readcf(cfname, safe, e) 62 char *cfname; 63 bool safe; 64 register ENVELOPE *e; 65 { 66 FILE *cf; 67 int ruleset = 0; 68 char *q; 69 char **pv; 70 struct rewrite *rwp = NULL; 71 char buf[MAXLINE]; 72 register char *p; 73 extern char **prescan(); 74 extern char **copyplist(); 75 struct stat statb; 76 char exbuf[MAXLINE]; 77 char pvpbuf[PSBUFSIZE]; 78 extern char *fgetfolded(); 79 extern char *munchstring(); 80 extern void makemapentry(); 81 82 FileName = cfname; 83 LineNumber = 0; 84 85 cf = fopen(cfname, "r"); 86 if (cf == NULL) 87 { 88 syserr("cannot open"); 89 exit(EX_OSFILE); 90 } 91 92 if (fstat(fileno(cf), &statb) < 0) 93 { 94 syserr("cannot fstat"); 95 exit(EX_OSFILE); 96 } 97 98 if (!S_ISREG(statb.st_mode)) 99 { 100 syserr("not a plain file"); 101 exit(EX_OSFILE); 102 } 103 104 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 105 { 106 if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 107 fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 108 FileName); 109 #ifdef LOG 110 if (LogLevel > 0) 111 syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 112 FileName); 113 #endif 114 } 115 116 while (fgetfolded(buf, sizeof buf, cf) != NULL) 117 { 118 if (buf[0] == '#') 119 continue; 120 121 /* map $ into \001 (ASCII SOH) for macro expansion */ 122 for (p = buf; *p != '\0'; p++) 123 { 124 if (*p == '#' && p > buf && ConfigLevel >= 3) 125 { 126 /* this is an on-line comment */ 127 register char *e; 128 129 switch (*--p) 130 { 131 case '\001': 132 /* it's from $# -- let it go through */ 133 p++; 134 break; 135 136 case '\\': 137 /* it's backslash escaped */ 138 (void) strcpy(p, p + 1); 139 break; 140 141 default: 142 /* delete preceeding white space */ 143 while (isspace(*p) && p > buf) 144 p--; 145 if ((e = strchr(++p, '\n')) != NULL) 146 (void) strcpy(p, e); 147 else 148 p[0] = p[1] = '\0'; 149 break; 150 } 151 continue; 152 } 153 154 if (*p != '$') 155 continue; 156 157 if (p[1] == '$') 158 { 159 /* actual dollar sign.... */ 160 (void) strcpy(p, p + 1); 161 continue; 162 } 163 164 /* convert to macro expansion character */ 165 *p = '\001'; 166 } 167 168 /* interpret this line */ 169 switch (buf[0]) 170 { 171 case '\0': 172 case '#': /* comment */ 173 break; 174 175 case 'R': /* rewriting rule */ 176 for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 177 continue; 178 179 if (*p == '\0') 180 { 181 syserr("invalid rewrite line \"%s\"", buf); 182 break; 183 } 184 185 /* allocate space for the rule header */ 186 if (rwp == NULL) 187 { 188 RewriteRules[ruleset] = rwp = 189 (struct rewrite *) xalloc(sizeof *rwp); 190 } 191 else 192 { 193 rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 194 rwp = rwp->r_next; 195 } 196 rwp->r_next = NULL; 197 198 /* expand and save the LHS */ 199 *p = '\0'; 200 expand(&buf[1], exbuf, &exbuf[sizeof exbuf], e); 201 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 202 if (rwp->r_lhs != NULL) 203 rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 204 else 205 syserr("R line: null LHS"); 206 207 /* expand and save the RHS */ 208 while (*++p == '\t') 209 continue; 210 q = p; 211 while (*p != '\0' && *p != '\t') 212 p++; 213 *p = '\0'; 214 expand(q, exbuf, &exbuf[sizeof exbuf], e); 215 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 216 if (rwp->r_rhs != NULL) 217 rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 218 else 219 syserr("R line: null RHS"); 220 break; 221 222 case 'S': /* select rewriting set */ 223 ruleset = atoi(&buf[1]); 224 if (ruleset >= MAXRWSETS || ruleset < 0) 225 { 226 syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 227 ruleset = 0; 228 } 229 rwp = NULL; 230 break; 231 232 case 'D': /* macro definition */ 233 define(buf[1], newstr(munchstring(&buf[2])), e); 234 break; 235 236 case 'H': /* required header line */ 237 (void) chompheader(&buf[1], TRUE, e); 238 break; 239 240 case 'C': /* word class */ 241 case 'F': /* word class from file */ 242 /* read list of words from argument or file */ 243 if (buf[0] == 'F') 244 { 245 /* read from file */ 246 for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 247 continue; 248 if (*p == '\0') 249 p = "%s"; 250 else 251 { 252 *p = '\0'; 253 while (isspace(*++p)) 254 continue; 255 } 256 fileclass(buf[1], &buf[2], p, safe); 257 break; 258 } 259 260 /* scan the list of words and set class for all */ 261 for (p = &buf[2]; *p != '\0'; ) 262 { 263 register char *wd; 264 char delim; 265 266 while (*p != '\0' && isspace(*p)) 267 p++; 268 wd = p; 269 while (*p != '\0' && !isspace(*p)) 270 p++; 271 delim = *p; 272 *p = '\0'; 273 if (wd[0] != '\0') 274 setclass(buf[1], wd); 275 *p = delim; 276 } 277 break; 278 279 case 'M': /* define mailer */ 280 makemailer(&buf[1]); 281 break; 282 283 case 'O': /* set option */ 284 setoption(buf[1], &buf[2], safe, FALSE); 285 break; 286 287 case 'P': /* set precedence */ 288 if (NumPriorities >= MAXPRIORITIES) 289 { 290 toomany('P', MAXPRIORITIES); 291 break; 292 } 293 for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 294 continue; 295 if (*p == '\0') 296 goto badline; 297 *p = '\0'; 298 Priorities[NumPriorities].pri_name = newstr(&buf[1]); 299 Priorities[NumPriorities].pri_val = atoi(++p); 300 NumPriorities++; 301 break; 302 303 case 'T': /* trusted user(s) */ 304 p = &buf[1]; 305 while (*p != '\0') 306 { 307 while (isspace(*p)) 308 p++; 309 q = p; 310 while (*p != '\0' && !isspace(*p)) 311 p++; 312 if (*p != '\0') 313 *p++ = '\0'; 314 if (*q == '\0') 315 continue; 316 for (pv = TrustedUsers; *pv != NULL; pv++) 317 continue; 318 if (pv >= &TrustedUsers[MAXTRUST]) 319 { 320 toomany('T', MAXTRUST); 321 break; 322 } 323 *pv = newstr(q); 324 } 325 break; 326 327 case 'V': /* configuration syntax version */ 328 ConfigLevel = atoi(&buf[1]); 329 break; 330 331 case 'K': 332 makemapentry(&buf[1]); 333 break; 334 335 default: 336 badline: 337 syserr("unknown control line \"%s\"", buf); 338 } 339 } 340 if (ferror(cf)) 341 { 342 syserr("I/O read error", cfname); 343 exit(EX_OSFILE); 344 } 345 fclose(cf); 346 FileName = NULL; 347 348 if (stab("host", ST_MAP, ST_FIND) == NULL) 349 { 350 /* user didn't initialize: set up host map */ 351 strcpy(buf, "host host"); 352 if (ConfigLevel >= 2) 353 strcat(buf, " -a."); 354 makemapentry(buf); 355 } 356 } 357 /* 358 ** TOOMANY -- signal too many of some option 359 ** 360 ** Parameters: 361 ** id -- the id of the error line 362 ** maxcnt -- the maximum possible values 363 ** 364 ** Returns: 365 ** none. 366 ** 367 ** Side Effects: 368 ** gives a syserr. 369 */ 370 371 toomany(id, maxcnt) 372 char id; 373 int maxcnt; 374 { 375 syserr("too many %c lines, %d max", id, maxcnt); 376 } 377 /* 378 ** FILECLASS -- read members of a class from a file 379 ** 380 ** Parameters: 381 ** class -- class to define. 382 ** filename -- name of file to read. 383 ** fmt -- scanf string to use for match. 384 ** 385 ** Returns: 386 ** none 387 ** 388 ** Side Effects: 389 ** 390 ** puts all lines in filename that match a scanf into 391 ** the named class. 392 */ 393 394 fileclass(class, filename, fmt, safe) 395 int class; 396 char *filename; 397 char *fmt; 398 bool safe; 399 { 400 FILE *f; 401 struct stat stbuf; 402 char buf[MAXLINE]; 403 404 if (stat(filename, &stbuf) < 0) 405 { 406 syserr("fileclass: cannot stat %s", filename); 407 return; 408 } 409 if (!S_ISREG(stbuf.st_mode)) 410 { 411 syserr("fileclass: %s not a regular file", filename); 412 return; 413 } 414 if (!safe && access(filename, R_OK) < 0) 415 { 416 syserr("fileclass: access denied on %s", filename); 417 return; 418 } 419 f = fopen(filename, "r"); 420 if (f == NULL) 421 { 422 syserr("fileclass: cannot open %s", filename); 423 return; 424 } 425 426 while (fgets(buf, sizeof buf, f) != NULL) 427 { 428 register STAB *s; 429 register char *p; 430 # ifdef SCANF 431 char wordbuf[MAXNAME+1]; 432 433 if (sscanf(buf, fmt, wordbuf) != 1) 434 continue; 435 p = wordbuf; 436 # else /* SCANF */ 437 p = buf; 438 # endif /* SCANF */ 439 440 /* 441 ** Break up the match into words. 442 */ 443 444 while (*p != '\0') 445 { 446 register char *q; 447 448 /* strip leading spaces */ 449 while (isspace(*p)) 450 p++; 451 if (*p == '\0') 452 break; 453 454 /* find the end of the word */ 455 q = p; 456 while (*p != '\0' && !isspace(*p)) 457 p++; 458 if (*p != '\0') 459 *p++ = '\0'; 460 461 /* enter the word in the symbol table */ 462 s = stab(q, ST_CLASS, ST_ENTER); 463 setbitn(class, s->s_class); 464 } 465 } 466 467 (void) fclose(f); 468 } 469 /* 470 ** MAKEMAILER -- define a new mailer. 471 ** 472 ** Parameters: 473 ** line -- description of mailer. This is in labeled 474 ** fields. The fields are: 475 ** P -- the path to the mailer 476 ** F -- the flags associated with the mailer 477 ** A -- the argv for this mailer 478 ** S -- the sender rewriting set 479 ** R -- the recipient rewriting set 480 ** E -- the eol string 481 ** The first word is the canonical name of the mailer. 482 ** 483 ** Returns: 484 ** none. 485 ** 486 ** Side Effects: 487 ** enters the mailer into the mailer table. 488 */ 489 490 makemailer(line) 491 char *line; 492 { 493 register char *p; 494 register struct mailer *m; 495 register STAB *s; 496 int i; 497 char fcode; 498 extern int NextMailer; 499 extern char **makeargv(); 500 extern char *munchstring(); 501 extern char *DelimChar; 502 extern long atol(); 503 504 /* allocate a mailer and set up defaults */ 505 m = (struct mailer *) xalloc(sizeof *m); 506 bzero((char *) m, sizeof *m); 507 m->m_mno = NextMailer; 508 m->m_eol = "\n"; 509 510 /* collect the mailer name */ 511 for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 512 continue; 513 if (*p != '\0') 514 *p++ = '\0'; 515 m->m_name = newstr(line); 516 517 /* now scan through and assign info from the fields */ 518 while (*p != '\0') 519 { 520 while (*p != '\0' && (*p == ',' || isspace(*p))) 521 p++; 522 523 /* p now points to field code */ 524 fcode = *p; 525 while (*p != '\0' && *p != '=' && *p != ',') 526 p++; 527 if (*p++ != '=') 528 { 529 syserr("mailer %s: `=' expected", m->m_name); 530 return; 531 } 532 while (isspace(*p)) 533 p++; 534 535 /* p now points to the field body */ 536 p = munchstring(p); 537 538 /* install the field into the mailer struct */ 539 switch (fcode) 540 { 541 case 'P': /* pathname */ 542 m->m_mailer = newstr(p); 543 break; 544 545 case 'F': /* flags */ 546 for (; *p != '\0'; p++) 547 if (!isspace(*p)) 548 setbitn(*p, m->m_flags); 549 break; 550 551 case 'S': /* sender rewriting ruleset */ 552 case 'R': /* recipient rewriting ruleset */ 553 i = atoi(p); 554 if (i < 0 || i >= MAXRWSETS) 555 { 556 syserr("invalid rewrite set, %d max", MAXRWSETS); 557 return; 558 } 559 if (fcode == 'S') 560 m->m_s_rwset = i; 561 else 562 m->m_r_rwset = i; 563 break; 564 565 case 'E': /* end of line string */ 566 m->m_eol = newstr(p); 567 break; 568 569 case 'A': /* argument vector */ 570 m->m_argv = makeargv(p); 571 break; 572 573 case 'M': /* maximum message size */ 574 m->m_maxsize = atol(p); 575 break; 576 577 case 'L': /* maximum line length */ 578 m->m_linelimit = atoi(p); 579 break; 580 } 581 582 p = DelimChar; 583 } 584 585 /* do some heuristic cleanup for back compatibility */ 586 if (bitnset(M_LIMITS, m->m_flags)) 587 { 588 if (m->m_linelimit == 0) 589 m->m_linelimit = SMTPLINELIM; 590 if (ConfigLevel < 2) 591 setbitn(M_7BITS, m->m_flags); 592 } 593 594 /* now store the mailer away */ 595 if (NextMailer >= MAXMAILERS) 596 { 597 syserr("too many mailers defined (%d max)", MAXMAILERS); 598 return; 599 } 600 Mailer[NextMailer++] = m; 601 s = stab(m->m_name, ST_MAILER, ST_ENTER); 602 s->s_mailer = m; 603 } 604 /* 605 ** MUNCHSTRING -- translate a string into internal form. 606 ** 607 ** Parameters: 608 ** p -- the string to munch. 609 ** 610 ** Returns: 611 ** the munched string. 612 ** 613 ** Side Effects: 614 ** Sets "DelimChar" to point to the string that caused us 615 ** to stop. 616 */ 617 618 char * 619 munchstring(p) 620 register char *p; 621 { 622 register char *q; 623 bool backslash = FALSE; 624 bool quotemode = FALSE; 625 static char buf[MAXLINE]; 626 extern char *DelimChar; 627 628 for (q = buf; *p != '\0'; p++) 629 { 630 if (backslash) 631 { 632 /* everything is roughly literal */ 633 backslash = FALSE; 634 switch (*p) 635 { 636 case 'r': /* carriage return */ 637 *q++ = '\r'; 638 continue; 639 640 case 'n': /* newline */ 641 *q++ = '\n'; 642 continue; 643 644 case 'f': /* form feed */ 645 *q++ = '\f'; 646 continue; 647 648 case 'b': /* backspace */ 649 *q++ = '\b'; 650 continue; 651 } 652 *q++ = *p; 653 } 654 else 655 { 656 if (*p == '\\') 657 backslash = TRUE; 658 else if (*p == '"') 659 quotemode = !quotemode; 660 else if (quotemode || *p != ',') 661 *q++ = *p; 662 else 663 break; 664 } 665 } 666 667 DelimChar = p; 668 *q++ = '\0'; 669 return (buf); 670 } 671 /* 672 ** MAKEARGV -- break up a string into words 673 ** 674 ** Parameters: 675 ** p -- the string to break up. 676 ** 677 ** Returns: 678 ** a char **argv (dynamically allocated) 679 ** 680 ** Side Effects: 681 ** munges p. 682 */ 683 684 char ** 685 makeargv(p) 686 register char *p; 687 { 688 char *q; 689 int i; 690 char **avp; 691 char *argv[MAXPV + 1]; 692 693 /* take apart the words */ 694 i = 0; 695 while (*p != '\0' && i < MAXPV) 696 { 697 q = p; 698 while (*p != '\0' && !isspace(*p)) 699 p++; 700 while (isspace(*p)) 701 *p++ = '\0'; 702 argv[i++] = newstr(q); 703 } 704 argv[i++] = NULL; 705 706 /* now make a copy of the argv */ 707 avp = (char **) xalloc(sizeof *avp * i); 708 bcopy((char *) argv, (char *) avp, sizeof *avp * i); 709 710 return (avp); 711 } 712 /* 713 ** PRINTRULES -- print rewrite rules (for debugging) 714 ** 715 ** Parameters: 716 ** none. 717 ** 718 ** Returns: 719 ** none. 720 ** 721 ** Side Effects: 722 ** prints rewrite rules. 723 */ 724 725 printrules() 726 { 727 register struct rewrite *rwp; 728 register int ruleset; 729 730 for (ruleset = 0; ruleset < 10; ruleset++) 731 { 732 if (RewriteRules[ruleset] == NULL) 733 continue; 734 printf("\n----Rule Set %d:", ruleset); 735 736 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 737 { 738 printf("\nLHS:"); 739 printav(rwp->r_lhs); 740 printf("RHS:"); 741 printav(rwp->r_rhs); 742 } 743 } 744 } 745 746 /* 747 ** SETOPTION -- set global processing option 748 ** 749 ** Parameters: 750 ** opt -- option name. 751 ** val -- option value (as a text string). 752 ** safe -- set if this came from a configuration file. 753 ** Some options (if set from the command line) will 754 ** reset the user id to avoid security problems. 755 ** sticky -- if set, don't let other setoptions override 756 ** this value. 757 ** 758 ** Returns: 759 ** none. 760 ** 761 ** Side Effects: 762 ** Sets options as implied by the arguments. 763 */ 764 765 static BITMAP StickyOpt; /* set if option is stuck */ 766 767 setoption(opt, val, safe, sticky) 768 char opt; 769 char *val; 770 bool safe; 771 bool sticky; 772 { 773 extern bool atobool(); 774 extern time_t convtime(); 775 extern int QueueLA; 776 extern int RefuseLA; 777 extern bool trusteduser(); 778 extern char *username(); 779 780 if (tTd(37, 1)) 781 printf("setoption %c=%s", opt, val); 782 783 /* 784 ** See if this option is preset for us. 785 */ 786 787 if (bitnset(opt, StickyOpt)) 788 { 789 if (tTd(37, 1)) 790 printf(" (ignored)\n"); 791 return; 792 } 793 794 /* 795 ** Check to see if this option can be specified by this user. 796 */ 797 798 if (!safe && getuid() == 0) 799 safe = TRUE; 800 if (!safe && strchr("deEiLmorsvC", opt) == NULL) 801 { 802 if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 803 { 804 if (tTd(37, 1)) 805 printf(" (unsafe)"); 806 if (getuid() != geteuid()) 807 { 808 if (tTd(37, 1)) 809 printf("(Resetting uid)"); 810 (void) setgid(getgid()); 811 (void) setuid(getuid()); 812 } 813 } 814 } 815 if (tTd(37, 1)) 816 printf("\n"); 817 818 switch (opt) 819 { 820 case '=': /* config file generation level */ 821 ConfigLevel = atoi(val); 822 break; 823 824 case '8': /* allow eight-bit input */ 825 EightBit = atobool(val); 826 break; 827 828 case 'A': /* set default alias file */ 829 if (val[0] == '\0') 830 AliasFile = "aliases"; 831 else 832 AliasFile = newstr(val); 833 break; 834 835 case 'a': /* look N minutes for "@:@" in alias file */ 836 if (val[0] == '\0') 837 SafeAlias = 5; 838 else 839 SafeAlias = atoi(val); 840 break; 841 842 case 'B': /* substitution for blank character */ 843 SpaceSub = val[0]; 844 if (SpaceSub == '\0') 845 SpaceSub = ' '; 846 break; 847 848 case 'c': /* don't connect to "expensive" mailers */ 849 NoConnect = atobool(val); 850 break; 851 852 case 'C': /* checkpoint every N addresses */ 853 CheckpointInterval = atoi(val); 854 break; 855 856 case 'd': /* delivery mode */ 857 switch (*val) 858 { 859 case '\0': 860 SendMode = SM_DELIVER; 861 break; 862 863 case SM_QUEUE: /* queue only */ 864 #ifndef QUEUE 865 syserr("need QUEUE to set -odqueue"); 866 #endif /* QUEUE */ 867 /* fall through..... */ 868 869 case SM_DELIVER: /* do everything */ 870 case SM_FORK: /* fork after verification */ 871 SendMode = *val; 872 break; 873 874 default: 875 syserr("Unknown delivery mode %c", *val); 876 exit(EX_USAGE); 877 } 878 break; 879 880 case 'D': /* rebuild alias database as needed */ 881 AutoRebuild = atobool(val); 882 break; 883 884 case 'E': /* error message header/header file */ 885 if (*val != '\0') 886 ErrMsgFile = newstr(val); 887 break; 888 889 case 'e': /* set error processing mode */ 890 switch (*val) 891 { 892 case EM_QUIET: /* be silent about it */ 893 case EM_MAIL: /* mail back */ 894 case EM_BERKNET: /* do berknet error processing */ 895 case EM_WRITE: /* write back (or mail) */ 896 HoldErrs = TRUE; 897 /* fall through... */ 898 899 case EM_PRINT: /* print errors normally (default) */ 900 ErrorMode = *val; 901 break; 902 } 903 break; 904 905 case 'F': /* file mode */ 906 FileMode = atooct(val) & 0777; 907 break; 908 909 case 'f': /* save Unix-style From lines on front */ 910 SaveFrom = atobool(val); 911 break; 912 913 case 'G': /* match recipients against GECOS field */ 914 MatchGecos = atobool(val); 915 break; 916 917 case 'g': /* default gid */ 918 DefGid = atoi(val); 919 break; 920 921 case 'H': /* help file */ 922 if (val[0] == '\0') 923 HelpFile = "sendmail.hf"; 924 else 925 HelpFile = newstr(val); 926 break; 927 928 case 'h': /* maximum hop count */ 929 MaxHopCount = atoi(val); 930 break; 931 932 case 'I': /* use internet domain name server */ 933 UseNameServer = atobool(val); 934 break; 935 936 case 'i': /* ignore dot lines in message */ 937 IgnrDot = atobool(val); 938 break; 939 940 case 'k': /* connection cache size */ 941 MaxMciCache = atoi(val); 942 if (MaxMciCache < 0) 943 MaxMciCache = 0; 944 break; 945 946 case 'K': /* connection cache timeout */ 947 MciCacheTimeout = convtime(val); 948 break; 949 950 case 'L': /* log level */ 951 LogLevel = atoi(val); 952 break; 953 954 case 'M': /* define macro */ 955 define(val[0], newstr(&val[1]), CurEnv); 956 sticky = FALSE; 957 break; 958 959 case 'm': /* send to me too */ 960 MeToo = atobool(val); 961 break; 962 963 case 'n': /* validate RHS in newaliases */ 964 CheckAliases = atobool(val); 965 break; 966 967 case 'o': /* assume old style headers */ 968 if (atobool(val)) 969 CurEnv->e_flags |= EF_OLDSTYLE; 970 else 971 CurEnv->e_flags &= ~EF_OLDSTYLE; 972 break; 973 974 case 'P': /* postmaster copy address for returned mail */ 975 PostMasterCopy = newstr(val); 976 break; 977 978 case 'q': /* slope of queue only function */ 979 QueueFactor = atoi(val); 980 break; 981 982 case 'Q': /* queue directory */ 983 if (val[0] == '\0') 984 QueueDir = "mqueue"; 985 else 986 QueueDir = newstr(val); 987 break; 988 989 case 'r': /* read timeout */ 990 ReadTimeout = convtime(val); 991 break; 992 993 case 'S': /* status file */ 994 if (val[0] == '\0') 995 StatFile = "sendmail.st"; 996 else 997 StatFile = newstr(val); 998 break; 999 1000 case 's': /* be super safe, even if expensive */ 1001 SuperSafe = atobool(val); 1002 break; 1003 1004 case 'T': /* queue timeout */ 1005 TimeOut = convtime(val); 1006 break; 1007 1008 case 't': /* time zone name */ 1009 TimeZoneSpec = newstr(val); 1010 break; 1011 1012 case 'U': /* location of user database */ 1013 UdbSpec = newstr(val); 1014 break; 1015 1016 case 'u': /* set default uid */ 1017 DefUid = atoi(val); 1018 setdefuser(); 1019 break; 1020 1021 case 'v': /* run in verbose mode */ 1022 Verbose = atobool(val); 1023 break; 1024 1025 case 'w': /* we don't have wildcard MX records */ 1026 NoWildcardMX = atobool(val); 1027 break; 1028 1029 case 'x': /* load avg at which to auto-queue msgs */ 1030 QueueLA = atoi(val); 1031 break; 1032 1033 case 'X': /* load avg at which to auto-reject connections */ 1034 RefuseLA = atoi(val); 1035 break; 1036 1037 case 'y': /* work recipient factor */ 1038 WkRecipFact = atoi(val); 1039 break; 1040 1041 case 'Y': /* fork jobs during queue runs */ 1042 ForkQueueRuns = atobool(val); 1043 break; 1044 1045 case 'z': /* work message class factor */ 1046 WkClassFact = atoi(val); 1047 break; 1048 1049 case 'Z': /* work time factor */ 1050 WkTimeFact = atoi(val); 1051 break; 1052 1053 default: 1054 break; 1055 } 1056 if (sticky) 1057 setbitn(opt, StickyOpt); 1058 return; 1059 } 1060 /* 1061 ** SETCLASS -- set a word into a class 1062 ** 1063 ** Parameters: 1064 ** class -- the class to put the word in. 1065 ** word -- the word to enter 1066 ** 1067 ** Returns: 1068 ** none. 1069 ** 1070 ** Side Effects: 1071 ** puts the word into the symbol table. 1072 */ 1073 1074 setclass(class, word) 1075 int class; 1076 char *word; 1077 { 1078 register STAB *s; 1079 1080 s = stab(word, ST_CLASS, ST_ENTER); 1081 setbitn(class, s->s_class); 1082 } 1083 /* 1084 ** MAKEMAPENTRY -- create a map entry 1085 ** 1086 ** Parameters: 1087 ** line -- the config file line 1088 ** 1089 ** Returns: 1090 ** TRUE if it successfully entered the map entry. 1091 ** FALSE otherwise (usually syntax error). 1092 ** 1093 ** Side Effects: 1094 ** Enters the map into the dictionary. 1095 */ 1096 1097 void 1098 makemapentry(line) 1099 char *line; 1100 { 1101 register char *p; 1102 char *mapname; 1103 char *classname; 1104 register STAB *map; 1105 STAB *class; 1106 1107 for (p = line; isspace(*p); p++) 1108 continue; 1109 if (!isalnum(*p)) 1110 { 1111 syserr("readcf: config K line: no map name"); 1112 return; 1113 } 1114 1115 mapname = p; 1116 while (isalnum(*++p)) 1117 continue; 1118 if (*p != '\0') 1119 *p++ = '\0'; 1120 while (isspace(*p)) 1121 p++; 1122 if (!isalnum(*p)) 1123 { 1124 syserr("readcf: config K line, map %s: no map class", mapname); 1125 return; 1126 } 1127 classname = p; 1128 while (isalnum(*++p)) 1129 continue; 1130 if (*p != '\0') 1131 *p++ = '\0'; 1132 while (isspace(*p)) 1133 p++; 1134 1135 /* look up the class */ 1136 class = stab(classname, ST_MAPCLASS, ST_FIND); 1137 if (class == NULL) 1138 { 1139 syserr("readcf: map %s: class %s not available", mapname, classname); 1140 return; 1141 } 1142 1143 /* enter the map */ 1144 map = stab(mapname, ST_MAP, ST_ENTER); 1145 map->s_map.map_class = &class->s_mapclass; 1146 1147 if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 1148 map->s_map.map_flags |= MF_VALID; 1149 } 1150