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*52637Seric static char sccsid[] = "@(#)readcf.c 5.32 (Berkeley) 02/21/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 { 80*52637Seric if (buf[0] == '#') 81*52637Seric continue; 82*52637Seric 8316157Seric /* map $ into \001 (ASCII SOH) for macro expansion */ 8416157Seric for (p = buf; *p != '\0'; p++) 8516157Seric { 8616157Seric if (*p != '$') 8716157Seric continue; 8816157Seric 8916157Seric if (p[1] == '$') 9016157Seric { 9116157Seric /* actual dollar sign.... */ 9223111Seric (void) strcpy(p, p + 1); 9316157Seric continue; 9416157Seric } 9516157Seric 9616157Seric /* convert to macro expansion character */ 9716157Seric *p = '\001'; 9816157Seric } 9916157Seric 10016157Seric /* interpret this line */ 1013308Seric switch (buf[0]) 1023308Seric { 1033308Seric case '\0': 1043308Seric case '#': /* comment */ 1053308Seric break; 1063308Seric 1073308Seric case 'R': /* rewriting rule */ 1083308Seric for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 1093308Seric continue; 1103308Seric 1113308Seric if (*p == '\0') 1125909Seric { 1139381Seric syserr("invalid rewrite line \"%s\"", buf); 1145909Seric break; 1155909Seric } 1165909Seric 1175909Seric /* allocate space for the rule header */ 1185909Seric if (rwp == NULL) 1195909Seric { 1205909Seric RewriteRules[ruleset] = rwp = 1215909Seric (struct rewrite *) xalloc(sizeof *rwp); 1225909Seric } 1233308Seric else 1243308Seric { 1255909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 1265909Seric rwp = rwp->r_next; 1275909Seric } 1285909Seric rwp->r_next = NULL; 1293308Seric 1305909Seric /* expand and save the LHS */ 1315909Seric *p = '\0'; 1326991Seric expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv); 13316915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 1345909Seric if (rwp->r_lhs != NULL) 1355909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 1365909Seric 1375909Seric /* expand and save the RHS */ 1385909Seric while (*++p == '\t') 1395909Seric continue; 1407231Seric q = p; 1417231Seric while (*p != '\0' && *p != '\t') 1427231Seric p++; 1437231Seric *p = '\0'; 1447231Seric expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv); 14516915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 1465909Seric if (rwp->r_rhs != NULL) 1475909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 1483308Seric break; 1493308Seric 1504072Seric case 'S': /* select rewriting set */ 1514072Seric ruleset = atoi(&buf[1]); 1528056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 1538056Seric { 1549381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 1558056Seric ruleset = 0; 1568056Seric } 1574072Seric rwp = NULL; 1584072Seric break; 1594072Seric 1603308Seric case 'D': /* macro definition */ 16110709Seric define(buf[1], newstr(munchstring(&buf[2])), CurEnv); 1623308Seric break; 1633308Seric 1643387Seric case 'H': /* required header line */ 1654088Seric (void) chompheader(&buf[1], TRUE); 1663387Seric break; 1673387Seric 1684061Seric case 'C': /* word class */ 1694432Seric case 'F': /* word class from file */ 1704432Seric /* read list of words from argument or file */ 1714432Seric if (buf[0] == 'F') 1724432Seric { 1734432Seric /* read from file */ 1744432Seric for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 1754432Seric continue; 1764432Seric if (*p == '\0') 1774432Seric p = "%s"; 1784432Seric else 1794432Seric { 1804432Seric *p = '\0'; 1814432Seric while (isspace(*++p)) 1824432Seric continue; 1834432Seric } 18410687Seric fileclass(buf[1], &buf[2], p); 1854432Seric break; 1864432Seric } 1874061Seric 1884432Seric /* scan the list of words and set class for all */ 1894061Seric for (p = &buf[2]; *p != '\0'; ) 1904061Seric { 1914061Seric register char *wd; 1924061Seric char delim; 1934061Seric 1944061Seric while (*p != '\0' && isspace(*p)) 1954061Seric p++; 1964061Seric wd = p; 1974061Seric while (*p != '\0' && !isspace(*p)) 1984061Seric p++; 1994061Seric delim = *p; 2004061Seric *p = '\0'; 2014061Seric if (wd[0] != '\0') 20210687Seric setclass(buf[1], wd); 2034061Seric *p = delim; 2044061Seric } 2054061Seric break; 2064061Seric 2074096Seric case 'M': /* define mailer */ 20821066Seric makemailer(&buf[1]); 2094096Seric break; 2104096Seric 2118252Seric case 'O': /* set option */ 21221755Seric setoption(buf[1], &buf[2], TRUE, FALSE); 2138252Seric break; 2148252Seric 2158252Seric case 'P': /* set precedence */ 2168252Seric if (NumPriorities >= MAXPRIORITIES) 2178252Seric { 2188547Seric toomany('P', MAXPRIORITIES); 2198252Seric break; 2208252Seric } 2219381Seric for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 2228252Seric continue; 2238252Seric if (*p == '\0') 2248252Seric goto badline; 2258252Seric *p = '\0'; 2268252Seric Priorities[NumPriorities].pri_name = newstr(&buf[1]); 2278252Seric Priorities[NumPriorities].pri_val = atoi(++p); 2288252Seric NumPriorities++; 2298252Seric break; 2308252Seric 2318547Seric case 'T': /* trusted user(s) */ 2328547Seric p = &buf[1]; 2338547Seric while (*p != '\0') 2348547Seric { 2358547Seric while (isspace(*p)) 2368547Seric p++; 2378547Seric q = p; 2388547Seric while (*p != '\0' && !isspace(*p)) 2398547Seric p++; 2408547Seric if (*p != '\0') 2418547Seric *p++ = '\0'; 2428547Seric if (*q == '\0') 2438547Seric continue; 2448547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 2458547Seric continue; 2468547Seric if (pv >= &TrustedUsers[MAXTRUST]) 2478547Seric { 2488547Seric toomany('T', MAXTRUST); 2498547Seric break; 2508547Seric } 2518547Seric *pv = newstr(q); 2528547Seric } 2538547Seric break; 2548547Seric 2553308Seric default: 2564061Seric badline: 2579381Seric syserr("unknown control line \"%s\"", buf); 2583308Seric } 2593308Seric } 260*52637Seric if (ferror(cf)) 261*52637Seric { 262*52637Seric syserr("Error reading %s", cfname); 263*52637Seric exit(EX_OSFILE); 264*52637Seric } 265*52637Seric fclose(cf); 2669381Seric FileName = NULL; 2674096Seric } 2684096Seric /* 2698547Seric ** TOOMANY -- signal too many of some option 2708547Seric ** 2718547Seric ** Parameters: 2728547Seric ** id -- the id of the error line 2738547Seric ** maxcnt -- the maximum possible values 2748547Seric ** 2758547Seric ** Returns: 2768547Seric ** none. 2778547Seric ** 2788547Seric ** Side Effects: 2798547Seric ** gives a syserr. 2808547Seric */ 2818547Seric 2828547Seric toomany(id, maxcnt) 2838547Seric char id; 2848547Seric int maxcnt; 2858547Seric { 2869381Seric syserr("too many %c lines, %d max", id, maxcnt); 2878547Seric } 2888547Seric /* 2894432Seric ** FILECLASS -- read members of a class from a file 2904432Seric ** 2914432Seric ** Parameters: 2924432Seric ** class -- class to define. 2934432Seric ** filename -- name of file to read. 2944432Seric ** fmt -- scanf string to use for match. 2954432Seric ** 2964432Seric ** Returns: 2974432Seric ** none 2984432Seric ** 2994432Seric ** Side Effects: 3004432Seric ** 3014432Seric ** puts all lines in filename that match a scanf into 3024432Seric ** the named class. 3034432Seric */ 3044432Seric 3054432Seric fileclass(class, filename, fmt) 3064432Seric int class; 3074432Seric char *filename; 3084432Seric char *fmt; 3094432Seric { 31025808Seric FILE *f; 3114432Seric char buf[MAXLINE]; 3124432Seric 31352062Seric if (filename[0] == '|') 31452062Seric f = popen(filename + 1, "r"); 31552062Seric else 31652062Seric f = fopen(filename, "r"); 3174432Seric if (f == NULL) 3184432Seric { 3194432Seric syserr("cannot open %s", filename); 3204432Seric return; 3214432Seric } 3224432Seric 3234432Seric while (fgets(buf, sizeof buf, f) != NULL) 3244432Seric { 3254432Seric register STAB *s; 32625808Seric register char *p; 32725808Seric # ifdef SCANF 3284432Seric char wordbuf[MAXNAME+1]; 3294432Seric 3304432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3314432Seric continue; 33225808Seric p = wordbuf; 33325808Seric # else SCANF 33425808Seric p = buf; 33525808Seric # endif SCANF 33625808Seric 33725808Seric /* 33825808Seric ** Break up the match into words. 33925808Seric */ 34025808Seric 34125808Seric while (*p != '\0') 34225808Seric { 34325808Seric register char *q; 34425808Seric 34525808Seric /* strip leading spaces */ 34625808Seric while (isspace(*p)) 34725808Seric p++; 34825808Seric if (*p == '\0') 34925808Seric break; 35025808Seric 35125808Seric /* find the end of the word */ 35225808Seric q = p; 35325808Seric while (*p != '\0' && !isspace(*p)) 35425808Seric p++; 35525808Seric if (*p != '\0') 35625808Seric *p++ = '\0'; 35725808Seric 35825808Seric /* enter the word in the symbol table */ 35925808Seric s = stab(q, ST_CLASS, ST_ENTER); 36025808Seric setbitn(class, s->s_class); 36125808Seric } 3624432Seric } 3634432Seric 36452062Seric if (filename[0] == '|') 36552062Seric (void) pclose(f); 36652062Seric else 36752062Seric (void) fclose(f); 3684432Seric } 3694432Seric /* 3704096Seric ** MAKEMAILER -- define a new mailer. 3714096Seric ** 3724096Seric ** Parameters: 37310327Seric ** line -- description of mailer. This is in labeled 37410327Seric ** fields. The fields are: 37510327Seric ** P -- the path to the mailer 37610327Seric ** F -- the flags associated with the mailer 37710327Seric ** A -- the argv for this mailer 37810327Seric ** S -- the sender rewriting set 37910327Seric ** R -- the recipient rewriting set 38010327Seric ** E -- the eol string 38110327Seric ** The first word is the canonical name of the mailer. 3824096Seric ** 3834096Seric ** Returns: 3844096Seric ** none. 3854096Seric ** 3864096Seric ** Side Effects: 3874096Seric ** enters the mailer into the mailer table. 3884096Seric */ 3893308Seric 39021066Seric makemailer(line) 3914096Seric char *line; 3924096Seric { 3934096Seric register char *p; 3948067Seric register struct mailer *m; 3958067Seric register STAB *s; 3968067Seric int i; 39710327Seric char fcode; 3984096Seric extern int NextMailer; 39910327Seric extern char **makeargv(); 40010327Seric extern char *munchstring(); 40110327Seric extern char *DelimChar; 40210701Seric extern long atol(); 4034096Seric 40410327Seric /* allocate a mailer and set up defaults */ 40510327Seric m = (struct mailer *) xalloc(sizeof *m); 40610327Seric bzero((char *) m, sizeof *m); 40710327Seric m->m_mno = NextMailer; 40810327Seric m->m_eol = "\n"; 40910327Seric 41010327Seric /* collect the mailer name */ 41110327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 41210327Seric continue; 41310327Seric if (*p != '\0') 41410327Seric *p++ = '\0'; 41510327Seric m->m_name = newstr(line); 41610327Seric 41710327Seric /* now scan through and assign info from the fields */ 41810327Seric while (*p != '\0') 41910327Seric { 42010327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 42110327Seric p++; 42210327Seric 42310327Seric /* p now points to field code */ 42410327Seric fcode = *p; 42510327Seric while (*p != '\0' && *p != '=' && *p != ',') 42610327Seric p++; 42710327Seric if (*p++ != '=') 42810327Seric { 429*52637Seric syserr("mailer %s: `=' expected", m->m_name); 43010327Seric return; 43110327Seric } 43210327Seric while (isspace(*p)) 43310327Seric p++; 43410327Seric 43510327Seric /* p now points to the field body */ 43610327Seric p = munchstring(p); 43710327Seric 43810327Seric /* install the field into the mailer struct */ 43910327Seric switch (fcode) 44010327Seric { 44110327Seric case 'P': /* pathname */ 44210327Seric m->m_mailer = newstr(p); 44310327Seric break; 44410327Seric 44510327Seric case 'F': /* flags */ 44610687Seric for (; *p != '\0'; p++) 447*52637Seric if (!isspace(*p)) 448*52637Seric setbitn(*p, m->m_flags); 44910327Seric break; 45010327Seric 45110327Seric case 'S': /* sender rewriting ruleset */ 45210327Seric case 'R': /* recipient rewriting ruleset */ 45310327Seric i = atoi(p); 45410327Seric if (i < 0 || i >= MAXRWSETS) 45510327Seric { 45610327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 45710327Seric return; 45810327Seric } 45910327Seric if (fcode == 'S') 46010327Seric m->m_s_rwset = i; 46110327Seric else 46210327Seric m->m_r_rwset = i; 46310327Seric break; 46410327Seric 46510327Seric case 'E': /* end of line string */ 46610327Seric m->m_eol = newstr(p); 46710327Seric break; 46810327Seric 46910327Seric case 'A': /* argument vector */ 47010327Seric m->m_argv = makeargv(p); 47110327Seric break; 47210701Seric 47310701Seric case 'M': /* maximum message size */ 47410701Seric m->m_maxsize = atol(p); 47510701Seric break; 47652106Seric 47752106Seric case 'L': /* maximum line length */ 47852106Seric m->m_linelimit = atoi(p); 47952106Seric break; 48010327Seric } 48110327Seric 48210327Seric p = DelimChar; 48310327Seric } 48410327Seric 48552106Seric /* do some heuristic cleanup for back compatibility */ 48652106Seric if (bitnset(M_LIMITS, m->m_flags)) 48752106Seric { 48852106Seric if (m->m_linelimit == 0) 48952106Seric m->m_linelimit = SMTPLINELIM; 49052106Seric if (!bitnset(M_8BITS, m->m_flags)) 49152106Seric setbitn(M_7BITS, m->m_flags); 49252106Seric } 49352106Seric 49410327Seric /* now store the mailer away */ 4954096Seric if (NextMailer >= MAXMAILERS) 4964096Seric { 4979381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4984096Seric return; 4994096Seric } 50010327Seric Mailer[NextMailer++] = m; 50110327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 50210327Seric s->s_mailer = m; 50310327Seric } 50410327Seric /* 50510327Seric ** MUNCHSTRING -- translate a string into internal form. 50610327Seric ** 50710327Seric ** Parameters: 50810327Seric ** p -- the string to munch. 50910327Seric ** 51010327Seric ** Returns: 51110327Seric ** the munched string. 51210327Seric ** 51310327Seric ** Side Effects: 51410327Seric ** Sets "DelimChar" to point to the string that caused us 51510327Seric ** to stop. 51610327Seric */ 5174096Seric 51810327Seric char * 51910327Seric munchstring(p) 52010327Seric register char *p; 52110327Seric { 52210327Seric register char *q; 52310327Seric bool backslash = FALSE; 52410327Seric bool quotemode = FALSE; 52510327Seric static char buf[MAXLINE]; 52610327Seric extern char *DelimChar; 5274096Seric 52810327Seric for (q = buf; *p != '\0'; p++) 5294096Seric { 53010327Seric if (backslash) 53110327Seric { 53210327Seric /* everything is roughly literal */ 53310357Seric backslash = FALSE; 53410327Seric switch (*p) 53510327Seric { 53610327Seric case 'r': /* carriage return */ 53710327Seric *q++ = '\r'; 53810327Seric continue; 53910327Seric 54010327Seric case 'n': /* newline */ 54110327Seric *q++ = '\n'; 54210327Seric continue; 54310327Seric 54410327Seric case 'f': /* form feed */ 54510327Seric *q++ = '\f'; 54610327Seric continue; 54710327Seric 54810327Seric case 'b': /* backspace */ 54910327Seric *q++ = '\b'; 55010327Seric continue; 55110327Seric } 55210327Seric *q++ = *p; 55310327Seric } 55410327Seric else 55510327Seric { 55610327Seric if (*p == '\\') 55710327Seric backslash = TRUE; 55810327Seric else if (*p == '"') 55910327Seric quotemode = !quotemode; 56010327Seric else if (quotemode || *p != ',') 56110327Seric *q++ = *p; 56210327Seric else 56310327Seric break; 56410327Seric } 5654096Seric } 5664096Seric 56710327Seric DelimChar = p; 56810327Seric *q++ = '\0'; 56910327Seric return (buf); 57010327Seric } 57110327Seric /* 57210327Seric ** MAKEARGV -- break up a string into words 57310327Seric ** 57410327Seric ** Parameters: 57510327Seric ** p -- the string to break up. 57610327Seric ** 57710327Seric ** Returns: 57810327Seric ** a char **argv (dynamically allocated) 57910327Seric ** 58010327Seric ** Side Effects: 58110327Seric ** munges p. 58210327Seric */ 5834096Seric 58410327Seric char ** 58510327Seric makeargv(p) 58610327Seric register char *p; 58710327Seric { 58810327Seric char *q; 58910327Seric int i; 59010327Seric char **avp; 59110327Seric char *argv[MAXPV + 1]; 59210327Seric 59310327Seric /* take apart the words */ 59410327Seric i = 0; 59510327Seric while (*p != '\0' && i < MAXPV) 5964096Seric { 59710327Seric q = p; 59810327Seric while (*p != '\0' && !isspace(*p)) 59910327Seric p++; 60010327Seric while (isspace(*p)) 60110327Seric *p++ = '\0'; 60210327Seric argv[i++] = newstr(q); 6034096Seric } 60410327Seric argv[i++] = NULL; 6054096Seric 60610327Seric /* now make a copy of the argv */ 60710327Seric avp = (char **) xalloc(sizeof *avp * i); 60816893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 60910327Seric 61010327Seric return (avp); 6113308Seric } 6123308Seric /* 6133308Seric ** PRINTRULES -- print rewrite rules (for debugging) 6143308Seric ** 6153308Seric ** Parameters: 6163308Seric ** none. 6173308Seric ** 6183308Seric ** Returns: 6193308Seric ** none. 6203308Seric ** 6213308Seric ** Side Effects: 6223308Seric ** prints rewrite rules. 6233308Seric */ 6243308Seric 6253308Seric printrules() 6263308Seric { 6273308Seric register struct rewrite *rwp; 6284072Seric register int ruleset; 6293308Seric 6304072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6313308Seric { 6324072Seric if (RewriteRules[ruleset] == NULL) 6334072Seric continue; 6348067Seric printf("\n----Rule Set %d:", ruleset); 6353308Seric 6364072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6373308Seric { 6388067Seric printf("\nLHS:"); 6398067Seric printav(rwp->r_lhs); 6408067Seric printf("RHS:"); 6418067Seric printav(rwp->r_rhs); 6423308Seric } 6433308Seric } 6443308Seric } 6454319Seric 6464096Seric /* 6478256Seric ** SETOPTION -- set global processing option 6488256Seric ** 6498256Seric ** Parameters: 6508256Seric ** opt -- option name. 6518256Seric ** val -- option value (as a text string). 65221755Seric ** safe -- set if this came from a configuration file. 65321755Seric ** Some options (if set from the command line) will 65421755Seric ** reset the user id to avoid security problems. 6558269Seric ** sticky -- if set, don't let other setoptions override 6568269Seric ** this value. 6578256Seric ** 6588256Seric ** Returns: 6598256Seric ** none. 6608256Seric ** 6618256Seric ** Side Effects: 6628256Seric ** Sets options as implied by the arguments. 6638256Seric */ 6648256Seric 66510687Seric static BITMAP StickyOpt; /* set if option is stuck */ 6668269Seric 66721755Seric setoption(opt, val, safe, sticky) 6688256Seric char opt; 6698256Seric char *val; 67021755Seric bool safe; 6718269Seric bool sticky; 6728256Seric { 6738265Seric extern bool atobool(); 67412633Seric extern time_t convtime(); 67514879Seric extern int QueueLA; 67614879Seric extern int RefuseLA; 67717474Seric extern bool trusteduser(); 67817474Seric extern char *username(); 6798256Seric 6808256Seric if (tTd(37, 1)) 6819341Seric printf("setoption %c=%s", opt, val); 6828256Seric 6838256Seric /* 6848269Seric ** See if this option is preset for us. 6858256Seric */ 6868256Seric 68710687Seric if (bitnset(opt, StickyOpt)) 6888269Seric { 6899341Seric if (tTd(37, 1)) 6909341Seric printf(" (ignored)\n"); 6918269Seric return; 6928269Seric } 6938269Seric 69421755Seric /* 69521755Seric ** Check to see if this option can be specified by this user. 69621755Seric */ 69721755Seric 69836238Skarels if (!safe && getuid() == 0) 69921755Seric safe = TRUE; 70021755Seric if (!safe && index("deiLmorsv", opt) == NULL) 70121755Seric { 70239111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 70321755Seric { 70436582Sbostic if (tTd(37, 1)) 70536582Sbostic printf(" (unsafe)"); 70636582Sbostic if (getuid() != geteuid()) 70736582Sbostic { 70851210Seric if (tTd(37, 1)) 70951210Seric printf("(Resetting uid)"); 71036582Sbostic (void) setgid(getgid()); 71136582Sbostic (void) setuid(getuid()); 71236582Sbostic } 71321755Seric } 71421755Seric } 71551210Seric if (tTd(37, 1)) 71617985Seric printf("\n"); 7178269Seric 7188256Seric switch (opt) 7198256Seric { 72051312Seric case '=': /* config file generation level */ 72151312Seric ConfigLevel = atoi(val); 72251312Seric break; 72351312Seric 72452106Seric case '8': /* allow eight-bit input */ 72552106Seric EightBit = atobool(val); 72652106Seric break; 72752106Seric 7288256Seric case 'A': /* set default alias file */ 7299381Seric if (val[0] == '\0') 7308269Seric AliasFile = "aliases"; 7319381Seric else 7329381Seric AliasFile = newstr(val); 7338256Seric break; 7348256Seric 73517474Seric case 'a': /* look N minutes for "@:@" in alias file */ 73617474Seric if (val[0] == '\0') 73717474Seric SafeAlias = 5; 73817474Seric else 73917474Seric SafeAlias = atoi(val); 74017474Seric break; 74117474Seric 74216843Seric case 'B': /* substitution for blank character */ 74316843Seric SpaceSub = val[0]; 74416843Seric if (SpaceSub == '\0') 74516843Seric SpaceSub = ' '; 74616843Seric break; 74716843Seric 7489284Seric case 'c': /* don't connect to "expensive" mailers */ 7499381Seric NoConnect = atobool(val); 7509284Seric break; 7519284Seric 75251305Seric case 'C': /* checkpoint every N addresses */ 75351305Seric CheckpointInterval = atoi(val); 75424944Seric break; 75524944Seric 7569284Seric case 'd': /* delivery mode */ 7579284Seric switch (*val) 7588269Seric { 7599284Seric case '\0': 7609284Seric SendMode = SM_DELIVER; 7618269Seric break; 7628269Seric 76310755Seric case SM_QUEUE: /* queue only */ 76410755Seric #ifndef QUEUE 76510755Seric syserr("need QUEUE to set -odqueue"); 76610755Seric #endif QUEUE 76710755Seric /* fall through..... */ 76810755Seric 7699284Seric case SM_DELIVER: /* do everything */ 7709284Seric case SM_FORK: /* fork after verification */ 7719284Seric SendMode = *val; 7728269Seric break; 7738269Seric 7748269Seric default: 7759284Seric syserr("Unknown delivery mode %c", *val); 7768269Seric exit(EX_USAGE); 7778269Seric } 7788269Seric break; 7798269Seric 7809146Seric case 'D': /* rebuild alias database as needed */ 7819381Seric AutoRebuild = atobool(val); 7829146Seric break; 7839146Seric 7848269Seric case 'e': /* set error processing mode */ 7858269Seric switch (*val) 7868269Seric { 7879381Seric case EM_QUIET: /* be silent about it */ 7889381Seric case EM_MAIL: /* mail back */ 7899381Seric case EM_BERKNET: /* do berknet error processing */ 7909381Seric case EM_WRITE: /* write back (or mail) */ 7918269Seric HoldErrs = TRUE; 7929381Seric /* fall through... */ 7938269Seric 7949381Seric case EM_PRINT: /* print errors normally (default) */ 7959381Seric ErrorMode = *val; 7968269Seric break; 7978269Seric } 7988269Seric break; 7998269Seric 8009049Seric case 'F': /* file mode */ 80117975Seric FileMode = atooct(val) & 0777; 8029049Seric break; 8039049Seric 8048269Seric case 'f': /* save Unix-style From lines on front */ 8059381Seric SaveFrom = atobool(val); 8068269Seric break; 8078269Seric 8088256Seric case 'g': /* default gid */ 80917474Seric DefGid = atoi(val); 8108256Seric break; 8118256Seric 8128256Seric case 'H': /* help file */ 8139381Seric if (val[0] == '\0') 8148269Seric HelpFile = "sendmail.hf"; 8159381Seric else 8169381Seric HelpFile = newstr(val); 8178256Seric break; 8188256Seric 81951305Seric case 'h': /* maximum hop count */ 82051305Seric MaxHopCount = atoi(val); 82151305Seric break; 82251305Seric 82335651Seric case 'I': /* use internet domain name server */ 82435651Seric UseNameServer = atobool(val); 82535651Seric break; 82635651Seric 8278269Seric case 'i': /* ignore dot lines in message */ 8289381Seric IgnrDot = atobool(val); 8298269Seric break; 8308269Seric 8318256Seric case 'L': /* log level */ 8329381Seric LogLevel = atoi(val); 8338256Seric break; 8348256Seric 8358269Seric case 'M': /* define macro */ 8369381Seric define(val[0], newstr(&val[1]), CurEnv); 83716878Seric sticky = FALSE; 8388269Seric break; 8398269Seric 8408269Seric case 'm': /* send to me too */ 8419381Seric MeToo = atobool(val); 8428269Seric break; 8438269Seric 84425820Seric case 'n': /* validate RHS in newaliases */ 84525820Seric CheckAliases = atobool(val); 84625820Seric break; 84725820Seric 8488269Seric case 'o': /* assume old style headers */ 8499381Seric if (atobool(val)) 8509341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8519341Seric else 8529341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8538269Seric break; 8548269Seric 85524944Seric case 'P': /* postmaster copy address for returned mail */ 85624944Seric PostMasterCopy = newstr(val); 85724944Seric break; 85824944Seric 85924944Seric case 'q': /* slope of queue only function */ 86024944Seric QueueFactor = atoi(val); 86124944Seric break; 86224944Seric 8638256Seric case 'Q': /* queue directory */ 8649381Seric if (val[0] == '\0') 8658269Seric QueueDir = "mqueue"; 8669381Seric else 8679381Seric QueueDir = newstr(val); 8688256Seric break; 8698256Seric 8708256Seric case 'r': /* read timeout */ 8719381Seric ReadTimeout = convtime(val); 8728256Seric break; 8738256Seric 8748256Seric case 'S': /* status file */ 8759381Seric if (val[0] == '\0') 8768269Seric StatFile = "sendmail.st"; 8779381Seric else 8789381Seric StatFile = newstr(val); 8798256Seric break; 8808256Seric 8818265Seric case 's': /* be super safe, even if expensive */ 8829381Seric SuperSafe = atobool(val); 8838256Seric break; 8848256Seric 8858256Seric case 'T': /* queue timeout */ 8869381Seric TimeOut = convtime(val); 88733936Sbostic /*FALLTHROUGH*/ 8888256Seric 8898265Seric case 't': /* time zone name */ 89052106Seric TimeZoneSpec = newstr(val); 8918265Seric break; 8928265Seric 89350556Seric case 'U': /* location of user database */ 89451360Seric UdbSpec = newstr(val); 89550556Seric break; 89650556Seric 8978256Seric case 'u': /* set default uid */ 89817474Seric DefUid = atoi(val); 89940973Sbostic setdefuser(); 9008256Seric break; 9018256Seric 9028269Seric case 'v': /* run in verbose mode */ 9039381Seric Verbose = atobool(val); 9048256Seric break; 9058256Seric 90651216Seric case 'w': /* we don't have wildcard MX records */ 90751216Seric NoWildcardMX = atobool(val); 90850537Seric break; 90950537Seric 91014879Seric case 'x': /* load avg at which to auto-queue msgs */ 91114879Seric QueueLA = atoi(val); 91214879Seric break; 91314879Seric 91414879Seric case 'X': /* load avg at which to auto-reject connections */ 91514879Seric RefuseLA = atoi(val); 91614879Seric break; 91714879Seric 91824981Seric case 'y': /* work recipient factor */ 91924981Seric WkRecipFact = atoi(val); 92024981Seric break; 92124981Seric 92224981Seric case 'Y': /* fork jobs during queue runs */ 92324952Seric ForkQueueRuns = atobool(val); 92424952Seric break; 92524952Seric 92624981Seric case 'z': /* work message class factor */ 92724981Seric WkClassFact = atoi(val); 92824981Seric break; 92924981Seric 93024981Seric case 'Z': /* work time factor */ 93124981Seric WkTimeFact = atoi(val); 93224981Seric break; 93324981Seric 9348256Seric default: 9358256Seric break; 9368256Seric } 93716878Seric if (sticky) 93816878Seric setbitn(opt, StickyOpt); 9399188Seric return; 9408256Seric } 94110687Seric /* 94210687Seric ** SETCLASS -- set a word into a class 94310687Seric ** 94410687Seric ** Parameters: 94510687Seric ** class -- the class to put the word in. 94610687Seric ** word -- the word to enter 94710687Seric ** 94810687Seric ** Returns: 94910687Seric ** none. 95010687Seric ** 95110687Seric ** Side Effects: 95210687Seric ** puts the word into the symbol table. 95310687Seric */ 95410687Seric 95510687Seric setclass(class, word) 95610687Seric int class; 95710687Seric char *word; 95810687Seric { 95910687Seric register STAB *s; 96010687Seric 96110687Seric s = stab(word, ST_CLASS, ST_ENTER); 96210687Seric setbitn(class, s->s_class); 96310687Seric } 964