122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822709Sdist 922709Sdist #ifndef lint 10*52106Seric static char sccsid[] = "@(#)readcf.c 5.31 (Berkeley) 01/04/92"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 143308Seric 153308Seric /* 163308Seric ** READCF -- read control file. 173308Seric ** 183308Seric ** This routine reads the control file and builds the internal 193308Seric ** form. 203308Seric ** 214432Seric ** The file is formatted as a sequence of lines, each taken 224432Seric ** atomically. The first character of each line describes how 234432Seric ** the line is to be interpreted. The lines are: 244432Seric ** Dxval Define macro x to have value val. 254432Seric ** Cxword Put word into class x. 264432Seric ** Fxfile [fmt] Read file for lines to put into 274432Seric ** class x. Use scanf string 'fmt' 284432Seric ** or "%s" if not present. Fmt should 294432Seric ** only produce one string-valued result. 304432Seric ** Hname: value Define header with field-name 'name' 314432Seric ** and value as specified; this will be 324432Seric ** macro expanded immediately before 334432Seric ** use. 344432Seric ** Sn Use rewriting set n. 354432Seric ** Rlhs rhs Rewrite addresses that match lhs to 364432Seric ** be rhs. 3724944Seric ** Mn arg=val... Define mailer. n is the internal name. 3824944Seric ** Args specify mailer parameters. 398252Seric ** Oxvalue Set option x to value. 408252Seric ** Pname=value Set precedence name to value. 414432Seric ** 423308Seric ** Parameters: 433308Seric ** cfname -- control file name. 443308Seric ** 453308Seric ** Returns: 463308Seric ** none. 473308Seric ** 483308Seric ** Side Effects: 493308Seric ** Builds several internal tables. 503308Seric */ 513308Seric 5221066Seric readcf(cfname) 533308Seric char *cfname; 543308Seric { 553308Seric FILE *cf; 568547Seric int ruleset = 0; 578547Seric char *q; 588547Seric char **pv; 599350Seric struct rewrite *rwp = NULL; 603308Seric char buf[MAXLINE]; 613308Seric register char *p; 623308Seric extern char **prescan(); 633308Seric extern char **copyplist(); 645909Seric char exbuf[MAXLINE]; 6516915Seric char pvpbuf[PSBUFSIZE]; 669350Seric extern char *fgetfolded(); 6710709Seric extern char *munchstring(); 683308Seric 693308Seric cf = fopen(cfname, "r"); 703308Seric if (cf == NULL) 713308Seric { 723308Seric syserr("cannot open %s", cfname); 733308Seric exit(EX_OSFILE); 743308Seric } 753308Seric 769381Seric FileName = cfname; 778056Seric LineNumber = 0; 787854Seric while (fgetfolded(buf, sizeof buf, cf) != NULL) 793308Seric { 8016157Seric /* map $ into \001 (ASCII SOH) for macro expansion */ 8116157Seric for (p = buf; *p != '\0'; p++) 8216157Seric { 8316157Seric if (*p != '$') 8416157Seric continue; 8516157Seric 8616157Seric if (p[1] == '$') 8716157Seric { 8816157Seric /* actual dollar sign.... */ 8923111Seric (void) strcpy(p, p + 1); 9016157Seric continue; 9116157Seric } 9216157Seric 9316157Seric /* convert to macro expansion character */ 9416157Seric *p = '\001'; 9516157Seric } 9616157Seric 9716157Seric /* interpret this line */ 983308Seric switch (buf[0]) 993308Seric { 1003308Seric case '\0': 1013308Seric case '#': /* comment */ 1023308Seric break; 1033308Seric 1043308Seric case 'R': /* rewriting rule */ 1053308Seric for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 1063308Seric continue; 1073308Seric 1083308Seric if (*p == '\0') 1095909Seric { 1109381Seric syserr("invalid rewrite line \"%s\"", buf); 1115909Seric break; 1125909Seric } 1135909Seric 1145909Seric /* allocate space for the rule header */ 1155909Seric if (rwp == NULL) 1165909Seric { 1175909Seric RewriteRules[ruleset] = rwp = 1185909Seric (struct rewrite *) xalloc(sizeof *rwp); 1195909Seric } 1203308Seric else 1213308Seric { 1225909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 1235909Seric rwp = rwp->r_next; 1245909Seric } 1255909Seric rwp->r_next = NULL; 1263308Seric 1275909Seric /* expand and save the LHS */ 1285909Seric *p = '\0'; 1296991Seric expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv); 13016915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 1315909Seric if (rwp->r_lhs != NULL) 1325909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 1335909Seric 1345909Seric /* expand and save the RHS */ 1355909Seric while (*++p == '\t') 1365909Seric continue; 1377231Seric q = p; 1387231Seric while (*p != '\0' && *p != '\t') 1397231Seric p++; 1407231Seric *p = '\0'; 1417231Seric expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv); 14216915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 1435909Seric if (rwp->r_rhs != NULL) 1445909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 1453308Seric break; 1463308Seric 1474072Seric case 'S': /* select rewriting set */ 1484072Seric ruleset = atoi(&buf[1]); 1498056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 1508056Seric { 1519381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 1528056Seric ruleset = 0; 1538056Seric } 1544072Seric rwp = NULL; 1554072Seric break; 1564072Seric 1573308Seric case 'D': /* macro definition */ 15810709Seric define(buf[1], newstr(munchstring(&buf[2])), CurEnv); 1593308Seric break; 1603308Seric 1613387Seric case 'H': /* required header line */ 1624088Seric (void) chompheader(&buf[1], TRUE); 1633387Seric break; 1643387Seric 1654061Seric case 'C': /* word class */ 1664432Seric case 'F': /* word class from file */ 1674432Seric /* read list of words from argument or file */ 1684432Seric if (buf[0] == 'F') 1694432Seric { 1704432Seric /* read from file */ 1714432Seric for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 1724432Seric continue; 1734432Seric if (*p == '\0') 1744432Seric p = "%s"; 1754432Seric else 1764432Seric { 1774432Seric *p = '\0'; 1784432Seric while (isspace(*++p)) 1794432Seric continue; 1804432Seric } 18110687Seric fileclass(buf[1], &buf[2], p); 1824432Seric break; 1834432Seric } 1844061Seric 1854432Seric /* scan the list of words and set class for all */ 1864061Seric for (p = &buf[2]; *p != '\0'; ) 1874061Seric { 1884061Seric register char *wd; 1894061Seric char delim; 1904061Seric 1914061Seric while (*p != '\0' && isspace(*p)) 1924061Seric p++; 1934061Seric wd = p; 1944061Seric while (*p != '\0' && !isspace(*p)) 1954061Seric p++; 1964061Seric delim = *p; 1974061Seric *p = '\0'; 1984061Seric if (wd[0] != '\0') 19910687Seric setclass(buf[1], wd); 2004061Seric *p = delim; 2014061Seric } 2024061Seric break; 2034061Seric 2044096Seric case 'M': /* define mailer */ 20521066Seric makemailer(&buf[1]); 2064096Seric break; 2074096Seric 2088252Seric case 'O': /* set option */ 20921755Seric setoption(buf[1], &buf[2], TRUE, FALSE); 2108252Seric break; 2118252Seric 2128252Seric case 'P': /* set precedence */ 2138252Seric if (NumPriorities >= MAXPRIORITIES) 2148252Seric { 2158547Seric toomany('P', MAXPRIORITIES); 2168252Seric break; 2178252Seric } 2189381Seric for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 2198252Seric continue; 2208252Seric if (*p == '\0') 2218252Seric goto badline; 2228252Seric *p = '\0'; 2238252Seric Priorities[NumPriorities].pri_name = newstr(&buf[1]); 2248252Seric Priorities[NumPriorities].pri_val = atoi(++p); 2258252Seric NumPriorities++; 2268252Seric break; 2278252Seric 2288547Seric case 'T': /* trusted user(s) */ 2298547Seric p = &buf[1]; 2308547Seric while (*p != '\0') 2318547Seric { 2328547Seric while (isspace(*p)) 2338547Seric p++; 2348547Seric q = p; 2358547Seric while (*p != '\0' && !isspace(*p)) 2368547Seric p++; 2378547Seric if (*p != '\0') 2388547Seric *p++ = '\0'; 2398547Seric if (*q == '\0') 2408547Seric continue; 2418547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 2428547Seric continue; 2438547Seric if (pv >= &TrustedUsers[MAXTRUST]) 2448547Seric { 2458547Seric toomany('T', MAXTRUST); 2468547Seric break; 2478547Seric } 2488547Seric *pv = newstr(q); 2498547Seric } 2508547Seric break; 2518547Seric 2523308Seric default: 2534061Seric badline: 2549381Seric syserr("unknown control line \"%s\"", buf); 2553308Seric } 2563308Seric } 2579381Seric FileName = NULL; 2584096Seric } 2594096Seric /* 2608547Seric ** TOOMANY -- signal too many of some option 2618547Seric ** 2628547Seric ** Parameters: 2638547Seric ** id -- the id of the error line 2648547Seric ** maxcnt -- the maximum possible values 2658547Seric ** 2668547Seric ** Returns: 2678547Seric ** none. 2688547Seric ** 2698547Seric ** Side Effects: 2708547Seric ** gives a syserr. 2718547Seric */ 2728547Seric 2738547Seric toomany(id, maxcnt) 2748547Seric char id; 2758547Seric int maxcnt; 2768547Seric { 2779381Seric syserr("too many %c lines, %d max", id, maxcnt); 2788547Seric } 2798547Seric /* 2804432Seric ** FILECLASS -- read members of a class from a file 2814432Seric ** 2824432Seric ** Parameters: 2834432Seric ** class -- class to define. 2844432Seric ** filename -- name of file to read. 2854432Seric ** fmt -- scanf string to use for match. 2864432Seric ** 2874432Seric ** Returns: 2884432Seric ** none 2894432Seric ** 2904432Seric ** Side Effects: 2914432Seric ** 2924432Seric ** puts all lines in filename that match a scanf into 2934432Seric ** the named class. 2944432Seric */ 2954432Seric 2964432Seric fileclass(class, filename, fmt) 2974432Seric int class; 2984432Seric char *filename; 2994432Seric char *fmt; 3004432Seric { 30125808Seric FILE *f; 3024432Seric char buf[MAXLINE]; 3034432Seric 30452062Seric if (filename[0] == '|') 30552062Seric f = popen(filename + 1, "r"); 30652062Seric else 30752062Seric f = fopen(filename, "r"); 3084432Seric if (f == NULL) 3094432Seric { 3104432Seric syserr("cannot open %s", filename); 3114432Seric return; 3124432Seric } 3134432Seric 3144432Seric while (fgets(buf, sizeof buf, f) != NULL) 3154432Seric { 3164432Seric register STAB *s; 31725808Seric register char *p; 31825808Seric # ifdef SCANF 3194432Seric char wordbuf[MAXNAME+1]; 3204432Seric 3214432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3224432Seric continue; 32325808Seric p = wordbuf; 32425808Seric # else SCANF 32525808Seric p = buf; 32625808Seric # endif SCANF 32725808Seric 32825808Seric /* 32925808Seric ** Break up the match into words. 33025808Seric */ 33125808Seric 33225808Seric while (*p != '\0') 33325808Seric { 33425808Seric register char *q; 33525808Seric 33625808Seric /* strip leading spaces */ 33725808Seric while (isspace(*p)) 33825808Seric p++; 33925808Seric if (*p == '\0') 34025808Seric break; 34125808Seric 34225808Seric /* find the end of the word */ 34325808Seric q = p; 34425808Seric while (*p != '\0' && !isspace(*p)) 34525808Seric p++; 34625808Seric if (*p != '\0') 34725808Seric *p++ = '\0'; 34825808Seric 34925808Seric /* enter the word in the symbol table */ 35025808Seric s = stab(q, ST_CLASS, ST_ENTER); 35125808Seric setbitn(class, s->s_class); 35225808Seric } 3534432Seric } 3544432Seric 35552062Seric if (filename[0] == '|') 35652062Seric (void) pclose(f); 35752062Seric else 35852062Seric (void) fclose(f); 3594432Seric } 3604432Seric /* 3614096Seric ** MAKEMAILER -- define a new mailer. 3624096Seric ** 3634096Seric ** Parameters: 36410327Seric ** line -- description of mailer. This is in labeled 36510327Seric ** fields. The fields are: 36610327Seric ** P -- the path to the mailer 36710327Seric ** F -- the flags associated with the mailer 36810327Seric ** A -- the argv for this mailer 36910327Seric ** S -- the sender rewriting set 37010327Seric ** R -- the recipient rewriting set 37110327Seric ** E -- the eol string 37210327Seric ** The first word is the canonical name of the mailer. 3734096Seric ** 3744096Seric ** Returns: 3754096Seric ** none. 3764096Seric ** 3774096Seric ** Side Effects: 3784096Seric ** enters the mailer into the mailer table. 3794096Seric */ 3803308Seric 38121066Seric makemailer(line) 3824096Seric char *line; 3834096Seric { 3844096Seric register char *p; 3858067Seric register struct mailer *m; 3868067Seric register STAB *s; 3878067Seric int i; 38810327Seric char fcode; 3894096Seric extern int NextMailer; 39010327Seric extern char **makeargv(); 39110327Seric extern char *munchstring(); 39210327Seric extern char *DelimChar; 39310701Seric extern long atol(); 3944096Seric 39510327Seric /* allocate a mailer and set up defaults */ 39610327Seric m = (struct mailer *) xalloc(sizeof *m); 39710327Seric bzero((char *) m, sizeof *m); 39810327Seric m->m_mno = NextMailer; 39910327Seric m->m_eol = "\n"; 40010327Seric 40110327Seric /* collect the mailer name */ 40210327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 40310327Seric continue; 40410327Seric if (*p != '\0') 40510327Seric *p++ = '\0'; 40610327Seric m->m_name = newstr(line); 40710327Seric 40810327Seric /* now scan through and assign info from the fields */ 40910327Seric while (*p != '\0') 41010327Seric { 41110327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 41210327Seric p++; 41310327Seric 41410327Seric /* p now points to field code */ 41510327Seric fcode = *p; 41610327Seric while (*p != '\0' && *p != '=' && *p != ',') 41710327Seric p++; 41810327Seric if (*p++ != '=') 41910327Seric { 42010327Seric syserr("`=' expected"); 42110327Seric return; 42210327Seric } 42310327Seric while (isspace(*p)) 42410327Seric p++; 42510327Seric 42610327Seric /* p now points to the field body */ 42710327Seric p = munchstring(p); 42810327Seric 42910327Seric /* install the field into the mailer struct */ 43010327Seric switch (fcode) 43110327Seric { 43210327Seric case 'P': /* pathname */ 43310327Seric m->m_mailer = newstr(p); 43410327Seric break; 43510327Seric 43610327Seric case 'F': /* flags */ 43710687Seric for (; *p != '\0'; p++) 43810687Seric setbitn(*p, m->m_flags); 43910327Seric break; 44010327Seric 44110327Seric case 'S': /* sender rewriting ruleset */ 44210327Seric case 'R': /* recipient rewriting ruleset */ 44310327Seric i = atoi(p); 44410327Seric if (i < 0 || i >= MAXRWSETS) 44510327Seric { 44610327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 44710327Seric return; 44810327Seric } 44910327Seric if (fcode == 'S') 45010327Seric m->m_s_rwset = i; 45110327Seric else 45210327Seric m->m_r_rwset = i; 45310327Seric break; 45410327Seric 45510327Seric case 'E': /* end of line string */ 45610327Seric m->m_eol = newstr(p); 45710327Seric break; 45810327Seric 45910327Seric case 'A': /* argument vector */ 46010327Seric m->m_argv = makeargv(p); 46110327Seric break; 46210701Seric 46310701Seric case 'M': /* maximum message size */ 46410701Seric m->m_maxsize = atol(p); 46510701Seric break; 466*52106Seric 467*52106Seric case 'L': /* maximum line length */ 468*52106Seric m->m_linelimit = atoi(p); 469*52106Seric break; 47010327Seric } 47110327Seric 47210327Seric p = DelimChar; 47310327Seric } 47410327Seric 475*52106Seric /* do some heuristic cleanup for back compatibility */ 476*52106Seric if (bitnset(M_LIMITS, m->m_flags)) 477*52106Seric { 478*52106Seric if (m->m_linelimit == 0) 479*52106Seric m->m_linelimit = SMTPLINELIM; 480*52106Seric if (!bitnset(M_8BITS, m->m_flags)) 481*52106Seric setbitn(M_7BITS, m->m_flags); 482*52106Seric } 483*52106Seric 48410327Seric /* now store the mailer away */ 4854096Seric if (NextMailer >= MAXMAILERS) 4864096Seric { 4879381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4884096Seric return; 4894096Seric } 49010327Seric Mailer[NextMailer++] = m; 49110327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 49210327Seric s->s_mailer = m; 49310327Seric } 49410327Seric /* 49510327Seric ** MUNCHSTRING -- translate a string into internal form. 49610327Seric ** 49710327Seric ** Parameters: 49810327Seric ** p -- the string to munch. 49910327Seric ** 50010327Seric ** Returns: 50110327Seric ** the munched string. 50210327Seric ** 50310327Seric ** Side Effects: 50410327Seric ** Sets "DelimChar" to point to the string that caused us 50510327Seric ** to stop. 50610327Seric */ 5074096Seric 50810327Seric char * 50910327Seric munchstring(p) 51010327Seric register char *p; 51110327Seric { 51210327Seric register char *q; 51310327Seric bool backslash = FALSE; 51410327Seric bool quotemode = FALSE; 51510327Seric static char buf[MAXLINE]; 51610327Seric extern char *DelimChar; 5174096Seric 51810327Seric for (q = buf; *p != '\0'; p++) 5194096Seric { 52010327Seric if (backslash) 52110327Seric { 52210327Seric /* everything is roughly literal */ 52310357Seric backslash = FALSE; 52410327Seric switch (*p) 52510327Seric { 52610327Seric case 'r': /* carriage return */ 52710327Seric *q++ = '\r'; 52810327Seric continue; 52910327Seric 53010327Seric case 'n': /* newline */ 53110327Seric *q++ = '\n'; 53210327Seric continue; 53310327Seric 53410327Seric case 'f': /* form feed */ 53510327Seric *q++ = '\f'; 53610327Seric continue; 53710327Seric 53810327Seric case 'b': /* backspace */ 53910327Seric *q++ = '\b'; 54010327Seric continue; 54110327Seric } 54210327Seric *q++ = *p; 54310327Seric } 54410327Seric else 54510327Seric { 54610327Seric if (*p == '\\') 54710327Seric backslash = TRUE; 54810327Seric else if (*p == '"') 54910327Seric quotemode = !quotemode; 55010327Seric else if (quotemode || *p != ',') 55110327Seric *q++ = *p; 55210327Seric else 55310327Seric break; 55410327Seric } 5554096Seric } 5564096Seric 55710327Seric DelimChar = p; 55810327Seric *q++ = '\0'; 55910327Seric return (buf); 56010327Seric } 56110327Seric /* 56210327Seric ** MAKEARGV -- break up a string into words 56310327Seric ** 56410327Seric ** Parameters: 56510327Seric ** p -- the string to break up. 56610327Seric ** 56710327Seric ** Returns: 56810327Seric ** a char **argv (dynamically allocated) 56910327Seric ** 57010327Seric ** Side Effects: 57110327Seric ** munges p. 57210327Seric */ 5734096Seric 57410327Seric char ** 57510327Seric makeargv(p) 57610327Seric register char *p; 57710327Seric { 57810327Seric char *q; 57910327Seric int i; 58010327Seric char **avp; 58110327Seric char *argv[MAXPV + 1]; 58210327Seric 58310327Seric /* take apart the words */ 58410327Seric i = 0; 58510327Seric while (*p != '\0' && i < MAXPV) 5864096Seric { 58710327Seric q = p; 58810327Seric while (*p != '\0' && !isspace(*p)) 58910327Seric p++; 59010327Seric while (isspace(*p)) 59110327Seric *p++ = '\0'; 59210327Seric argv[i++] = newstr(q); 5934096Seric } 59410327Seric argv[i++] = NULL; 5954096Seric 59610327Seric /* now make a copy of the argv */ 59710327Seric avp = (char **) xalloc(sizeof *avp * i); 59816893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 59910327Seric 60010327Seric return (avp); 6013308Seric } 6023308Seric /* 6033308Seric ** PRINTRULES -- print rewrite rules (for debugging) 6043308Seric ** 6053308Seric ** Parameters: 6063308Seric ** none. 6073308Seric ** 6083308Seric ** Returns: 6093308Seric ** none. 6103308Seric ** 6113308Seric ** Side Effects: 6123308Seric ** prints rewrite rules. 6133308Seric */ 6143308Seric 6153308Seric printrules() 6163308Seric { 6173308Seric register struct rewrite *rwp; 6184072Seric register int ruleset; 6193308Seric 6204072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6213308Seric { 6224072Seric if (RewriteRules[ruleset] == NULL) 6234072Seric continue; 6248067Seric printf("\n----Rule Set %d:", ruleset); 6253308Seric 6264072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6273308Seric { 6288067Seric printf("\nLHS:"); 6298067Seric printav(rwp->r_lhs); 6308067Seric printf("RHS:"); 6318067Seric printav(rwp->r_rhs); 6323308Seric } 6333308Seric } 6343308Seric } 6354319Seric 6364096Seric /* 6378256Seric ** SETOPTION -- set global processing option 6388256Seric ** 6398256Seric ** Parameters: 6408256Seric ** opt -- option name. 6418256Seric ** val -- option value (as a text string). 64221755Seric ** safe -- set if this came from a configuration file. 64321755Seric ** Some options (if set from the command line) will 64421755Seric ** reset the user id to avoid security problems. 6458269Seric ** sticky -- if set, don't let other setoptions override 6468269Seric ** this value. 6478256Seric ** 6488256Seric ** Returns: 6498256Seric ** none. 6508256Seric ** 6518256Seric ** Side Effects: 6528256Seric ** Sets options as implied by the arguments. 6538256Seric */ 6548256Seric 65510687Seric static BITMAP StickyOpt; /* set if option is stuck */ 6568269Seric 65721755Seric setoption(opt, val, safe, sticky) 6588256Seric char opt; 6598256Seric char *val; 66021755Seric bool safe; 6618269Seric bool sticky; 6628256Seric { 6638265Seric extern bool atobool(); 66412633Seric extern time_t convtime(); 66514879Seric extern int QueueLA; 66614879Seric extern int RefuseLA; 66717474Seric extern bool trusteduser(); 66817474Seric extern char *username(); 6698256Seric 6708256Seric if (tTd(37, 1)) 6719341Seric printf("setoption %c=%s", opt, val); 6728256Seric 6738256Seric /* 6748269Seric ** See if this option is preset for us. 6758256Seric */ 6768256Seric 67710687Seric if (bitnset(opt, StickyOpt)) 6788269Seric { 6799341Seric if (tTd(37, 1)) 6809341Seric printf(" (ignored)\n"); 6818269Seric return; 6828269Seric } 6838269Seric 68421755Seric /* 68521755Seric ** Check to see if this option can be specified by this user. 68621755Seric */ 68721755Seric 68836238Skarels if (!safe && getuid() == 0) 68921755Seric safe = TRUE; 69021755Seric if (!safe && index("deiLmorsv", opt) == NULL) 69121755Seric { 69239111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 69321755Seric { 69436582Sbostic if (tTd(37, 1)) 69536582Sbostic printf(" (unsafe)"); 69636582Sbostic if (getuid() != geteuid()) 69736582Sbostic { 69851210Seric if (tTd(37, 1)) 69951210Seric printf("(Resetting uid)"); 70036582Sbostic (void) setgid(getgid()); 70136582Sbostic (void) setuid(getuid()); 70236582Sbostic } 70321755Seric } 70421755Seric } 70551210Seric if (tTd(37, 1)) 70617985Seric printf("\n"); 7078269Seric 7088256Seric switch (opt) 7098256Seric { 71051312Seric case '=': /* config file generation level */ 71151312Seric ConfigLevel = atoi(val); 71251312Seric break; 71351312Seric 714*52106Seric case '8': /* allow eight-bit input */ 715*52106Seric EightBit = atobool(val); 716*52106Seric break; 717*52106Seric 7188256Seric case 'A': /* set default alias file */ 7199381Seric if (val[0] == '\0') 7208269Seric AliasFile = "aliases"; 7219381Seric else 7229381Seric AliasFile = newstr(val); 7238256Seric break; 7248256Seric 72517474Seric case 'a': /* look N minutes for "@:@" in alias file */ 72617474Seric if (val[0] == '\0') 72717474Seric SafeAlias = 5; 72817474Seric else 72917474Seric SafeAlias = atoi(val); 73017474Seric break; 73117474Seric 73216843Seric case 'B': /* substitution for blank character */ 73316843Seric SpaceSub = val[0]; 73416843Seric if (SpaceSub == '\0') 73516843Seric SpaceSub = ' '; 73616843Seric break; 73716843Seric 7389284Seric case 'c': /* don't connect to "expensive" mailers */ 7399381Seric NoConnect = atobool(val); 7409284Seric break; 7419284Seric 74251305Seric case 'C': /* checkpoint every N addresses */ 74351305Seric CheckpointInterval = atoi(val); 74424944Seric break; 74524944Seric 7469284Seric case 'd': /* delivery mode */ 7479284Seric switch (*val) 7488269Seric { 7499284Seric case '\0': 7509284Seric SendMode = SM_DELIVER; 7518269Seric break; 7528269Seric 75310755Seric case SM_QUEUE: /* queue only */ 75410755Seric #ifndef QUEUE 75510755Seric syserr("need QUEUE to set -odqueue"); 75610755Seric #endif QUEUE 75710755Seric /* fall through..... */ 75810755Seric 7599284Seric case SM_DELIVER: /* do everything */ 7609284Seric case SM_FORK: /* fork after verification */ 7619284Seric SendMode = *val; 7628269Seric break; 7638269Seric 7648269Seric default: 7659284Seric syserr("Unknown delivery mode %c", *val); 7668269Seric exit(EX_USAGE); 7678269Seric } 7688269Seric break; 7698269Seric 7709146Seric case 'D': /* rebuild alias database as needed */ 7719381Seric AutoRebuild = atobool(val); 7729146Seric break; 7739146Seric 7748269Seric case 'e': /* set error processing mode */ 7758269Seric switch (*val) 7768269Seric { 7779381Seric case EM_QUIET: /* be silent about it */ 7789381Seric case EM_MAIL: /* mail back */ 7799381Seric case EM_BERKNET: /* do berknet error processing */ 7809381Seric case EM_WRITE: /* write back (or mail) */ 7818269Seric HoldErrs = TRUE; 7829381Seric /* fall through... */ 7838269Seric 7849381Seric case EM_PRINT: /* print errors normally (default) */ 7859381Seric ErrorMode = *val; 7868269Seric break; 7878269Seric } 7888269Seric break; 7898269Seric 7909049Seric case 'F': /* file mode */ 79117975Seric FileMode = atooct(val) & 0777; 7929049Seric break; 7939049Seric 7948269Seric case 'f': /* save Unix-style From lines on front */ 7959381Seric SaveFrom = atobool(val); 7968269Seric break; 7978269Seric 7988256Seric case 'g': /* default gid */ 79917474Seric DefGid = atoi(val); 8008256Seric break; 8018256Seric 8028256Seric case 'H': /* help file */ 8039381Seric if (val[0] == '\0') 8048269Seric HelpFile = "sendmail.hf"; 8059381Seric else 8069381Seric HelpFile = newstr(val); 8078256Seric break; 8088256Seric 80951305Seric case 'h': /* maximum hop count */ 81051305Seric MaxHopCount = atoi(val); 81151305Seric break; 81251305Seric 81335651Seric case 'I': /* use internet domain name server */ 81435651Seric UseNameServer = atobool(val); 81535651Seric break; 81635651Seric 8178269Seric case 'i': /* ignore dot lines in message */ 8189381Seric IgnrDot = atobool(val); 8198269Seric break; 8208269Seric 8218256Seric case 'L': /* log level */ 8229381Seric LogLevel = atoi(val); 8238256Seric break; 8248256Seric 8258269Seric case 'M': /* define macro */ 8269381Seric define(val[0], newstr(&val[1]), CurEnv); 82716878Seric sticky = FALSE; 8288269Seric break; 8298269Seric 8308269Seric case 'm': /* send to me too */ 8319381Seric MeToo = atobool(val); 8328269Seric break; 8338269Seric 83425820Seric case 'n': /* validate RHS in newaliases */ 83525820Seric CheckAliases = atobool(val); 83625820Seric break; 83725820Seric 8388269Seric case 'o': /* assume old style headers */ 8399381Seric if (atobool(val)) 8409341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8419341Seric else 8429341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8438269Seric break; 8448269Seric 84524944Seric case 'P': /* postmaster copy address for returned mail */ 84624944Seric PostMasterCopy = newstr(val); 84724944Seric break; 84824944Seric 84924944Seric case 'q': /* slope of queue only function */ 85024944Seric QueueFactor = atoi(val); 85124944Seric break; 85224944Seric 8538256Seric case 'Q': /* queue directory */ 8549381Seric if (val[0] == '\0') 8558269Seric QueueDir = "mqueue"; 8569381Seric else 8579381Seric QueueDir = newstr(val); 8588256Seric break; 8598256Seric 8608256Seric case 'r': /* read timeout */ 8619381Seric ReadTimeout = convtime(val); 8628256Seric break; 8638256Seric 8648256Seric case 'S': /* status file */ 8659381Seric if (val[0] == '\0') 8668269Seric StatFile = "sendmail.st"; 8679381Seric else 8689381Seric StatFile = newstr(val); 8698256Seric break; 8708256Seric 8718265Seric case 's': /* be super safe, even if expensive */ 8729381Seric SuperSafe = atobool(val); 8738256Seric break; 8748256Seric 8758256Seric case 'T': /* queue timeout */ 8769381Seric TimeOut = convtime(val); 87733936Sbostic /*FALLTHROUGH*/ 8788256Seric 8798265Seric case 't': /* time zone name */ 880*52106Seric TimeZoneSpec = newstr(val); 8818265Seric break; 8828265Seric 88350556Seric case 'U': /* location of user database */ 88451360Seric UdbSpec = newstr(val); 88550556Seric break; 88650556Seric 8878256Seric case 'u': /* set default uid */ 88817474Seric DefUid = atoi(val); 88940973Sbostic setdefuser(); 8908256Seric break; 8918256Seric 8928269Seric case 'v': /* run in verbose mode */ 8939381Seric Verbose = atobool(val); 8948256Seric break; 8958256Seric 89651216Seric case 'w': /* we don't have wildcard MX records */ 89751216Seric NoWildcardMX = atobool(val); 89850537Seric break; 89950537Seric 90014879Seric case 'x': /* load avg at which to auto-queue msgs */ 90114879Seric QueueLA = atoi(val); 90214879Seric break; 90314879Seric 90414879Seric case 'X': /* load avg at which to auto-reject connections */ 90514879Seric RefuseLA = atoi(val); 90614879Seric break; 90714879Seric 90824981Seric case 'y': /* work recipient factor */ 90924981Seric WkRecipFact = atoi(val); 91024981Seric break; 91124981Seric 91224981Seric case 'Y': /* fork jobs during queue runs */ 91324952Seric ForkQueueRuns = atobool(val); 91424952Seric break; 91524952Seric 91624981Seric case 'z': /* work message class factor */ 91724981Seric WkClassFact = atoi(val); 91824981Seric break; 91924981Seric 92024981Seric case 'Z': /* work time factor */ 92124981Seric WkTimeFact = atoi(val); 92224981Seric break; 92324981Seric 9248256Seric default: 9258256Seric break; 9268256Seric } 92716878Seric if (sticky) 92816878Seric setbitn(opt, StickyOpt); 9299188Seric return; 9308256Seric } 93110687Seric /* 93210687Seric ** SETCLASS -- set a word into a class 93310687Seric ** 93410687Seric ** Parameters: 93510687Seric ** class -- the class to put the word in. 93610687Seric ** word -- the word to enter 93710687Seric ** 93810687Seric ** Returns: 93910687Seric ** none. 94010687Seric ** 94110687Seric ** Side Effects: 94210687Seric ** puts the word into the symbol table. 94310687Seric */ 94410687Seric 94510687Seric setclass(class, word) 94610687Seric int class; 94710687Seric char *word; 94810687Seric { 94910687Seric register STAB *s; 95010687Seric 95110687Seric s = stab(word, ST_CLASS, ST_ENTER); 95210687Seric setbitn(class, s->s_class); 95310687Seric } 954