122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 633731Sbostic * Redistribution and use in source and binary forms are permitted 734921Sbostic * provided that the above copyright notice and this paragraph are 834921Sbostic * duplicated in all such forms and that any documentation, 934921Sbostic * advertising materials, and other materials related to such 1034921Sbostic * distribution and use acknowledge that the software was developed 1134921Sbostic * by the University of California, Berkeley. The name of the 1234921Sbostic * University may not be used to endorse or promote products derived 1334921Sbostic * from this software without specific prior written permission. 1434921Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1534921Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1634921Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1733731Sbostic */ 1822709Sdist 1922709Sdist #ifndef lint 20*40973Sbostic static char sccsid[] = "@(#)readcf.c 5.20 (Berkeley) 04/18/90"; 2133731Sbostic #endif /* not lint */ 2222709Sdist 233313Seric # include "sendmail.h" 243308Seric 253308Seric /* 263308Seric ** READCF -- read control file. 273308Seric ** 283308Seric ** This routine reads the control file and builds the internal 293308Seric ** form. 303308Seric ** 314432Seric ** The file is formatted as a sequence of lines, each taken 324432Seric ** atomically. The first character of each line describes how 334432Seric ** the line is to be interpreted. The lines are: 344432Seric ** Dxval Define macro x to have value val. 354432Seric ** Cxword Put word into class x. 364432Seric ** Fxfile [fmt] Read file for lines to put into 374432Seric ** class x. Use scanf string 'fmt' 384432Seric ** or "%s" if not present. Fmt should 394432Seric ** only produce one string-valued result. 404432Seric ** Hname: value Define header with field-name 'name' 414432Seric ** and value as specified; this will be 424432Seric ** macro expanded immediately before 434432Seric ** use. 444432Seric ** Sn Use rewriting set n. 454432Seric ** Rlhs rhs Rewrite addresses that match lhs to 464432Seric ** be rhs. 4724944Seric ** Mn arg=val... Define mailer. n is the internal name. 4824944Seric ** Args specify mailer parameters. 498252Seric ** Oxvalue Set option x to value. 508252Seric ** Pname=value Set precedence name to value. 514432Seric ** 523308Seric ** Parameters: 533308Seric ** cfname -- control file name. 543308Seric ** 553308Seric ** Returns: 563308Seric ** none. 573308Seric ** 583308Seric ** Side Effects: 593308Seric ** Builds several internal tables. 603308Seric */ 613308Seric 6221066Seric readcf(cfname) 633308Seric char *cfname; 643308Seric { 653308Seric FILE *cf; 668547Seric int ruleset = 0; 678547Seric char *q; 688547Seric char **pv; 699350Seric struct rewrite *rwp = NULL; 703308Seric char buf[MAXLINE]; 713308Seric register char *p; 723308Seric extern char **prescan(); 733308Seric extern char **copyplist(); 745909Seric char exbuf[MAXLINE]; 7516915Seric char pvpbuf[PSBUFSIZE]; 769350Seric extern char *fgetfolded(); 7710709Seric extern char *munchstring(); 783308Seric 793308Seric cf = fopen(cfname, "r"); 803308Seric if (cf == NULL) 813308Seric { 823308Seric syserr("cannot open %s", cfname); 833308Seric exit(EX_OSFILE); 843308Seric } 853308Seric 869381Seric FileName = cfname; 878056Seric LineNumber = 0; 887854Seric while (fgetfolded(buf, sizeof buf, cf) != NULL) 893308Seric { 9016157Seric /* map $ into \001 (ASCII SOH) for macro expansion */ 9116157Seric for (p = buf; *p != '\0'; p++) 9216157Seric { 9316157Seric if (*p != '$') 9416157Seric continue; 9516157Seric 9616157Seric if (p[1] == '$') 9716157Seric { 9816157Seric /* actual dollar sign.... */ 9923111Seric (void) strcpy(p, p + 1); 10016157Seric continue; 10116157Seric } 10216157Seric 10316157Seric /* convert to macro expansion character */ 10416157Seric *p = '\001'; 10516157Seric } 10616157Seric 10716157Seric /* interpret this line */ 1083308Seric switch (buf[0]) 1093308Seric { 1103308Seric case '\0': 1113308Seric case '#': /* comment */ 1123308Seric break; 1133308Seric 1143308Seric case 'R': /* rewriting rule */ 1153308Seric for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 1163308Seric continue; 1173308Seric 1183308Seric if (*p == '\0') 1195909Seric { 1209381Seric syserr("invalid rewrite line \"%s\"", buf); 1215909Seric break; 1225909Seric } 1235909Seric 1245909Seric /* allocate space for the rule header */ 1255909Seric if (rwp == NULL) 1265909Seric { 1275909Seric RewriteRules[ruleset] = rwp = 1285909Seric (struct rewrite *) xalloc(sizeof *rwp); 1295909Seric } 1303308Seric else 1313308Seric { 1325909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 1335909Seric rwp = rwp->r_next; 1345909Seric } 1355909Seric rwp->r_next = NULL; 1363308Seric 1375909Seric /* expand and save the LHS */ 1385909Seric *p = '\0'; 1396991Seric expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv); 14016915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 1415909Seric if (rwp->r_lhs != NULL) 1425909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 1435909Seric 1445909Seric /* expand and save the RHS */ 1455909Seric while (*++p == '\t') 1465909Seric continue; 1477231Seric q = p; 1487231Seric while (*p != '\0' && *p != '\t') 1497231Seric p++; 1507231Seric *p = '\0'; 1517231Seric expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv); 15216915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 1535909Seric if (rwp->r_rhs != NULL) 1545909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 1553308Seric break; 1563308Seric 1574072Seric case 'S': /* select rewriting set */ 1584072Seric ruleset = atoi(&buf[1]); 1598056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 1608056Seric { 1619381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 1628056Seric ruleset = 0; 1638056Seric } 1644072Seric rwp = NULL; 1654072Seric break; 1664072Seric 1673308Seric case 'D': /* macro definition */ 16810709Seric define(buf[1], newstr(munchstring(&buf[2])), CurEnv); 1693308Seric break; 1703308Seric 1713387Seric case 'H': /* required header line */ 1724088Seric (void) chompheader(&buf[1], TRUE); 1733387Seric break; 1743387Seric 1754061Seric case 'C': /* word class */ 1764432Seric case 'F': /* word class from file */ 1774432Seric /* read list of words from argument or file */ 1784432Seric if (buf[0] == 'F') 1794432Seric { 1804432Seric /* read from file */ 1814432Seric for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 1824432Seric continue; 1834432Seric if (*p == '\0') 1844432Seric p = "%s"; 1854432Seric else 1864432Seric { 1874432Seric *p = '\0'; 1884432Seric while (isspace(*++p)) 1894432Seric continue; 1904432Seric } 19110687Seric fileclass(buf[1], &buf[2], p); 1924432Seric break; 1934432Seric } 1944061Seric 1954432Seric /* scan the list of words and set class for all */ 1964061Seric for (p = &buf[2]; *p != '\0'; ) 1974061Seric { 1984061Seric register char *wd; 1994061Seric char delim; 2004061Seric 2014061Seric while (*p != '\0' && isspace(*p)) 2024061Seric p++; 2034061Seric wd = p; 2044061Seric while (*p != '\0' && !isspace(*p)) 2054061Seric p++; 2064061Seric delim = *p; 2074061Seric *p = '\0'; 2084061Seric if (wd[0] != '\0') 20910687Seric setclass(buf[1], wd); 2104061Seric *p = delim; 2114061Seric } 2124061Seric break; 2134061Seric 2144096Seric case 'M': /* define mailer */ 21521066Seric makemailer(&buf[1]); 2164096Seric break; 2174096Seric 2188252Seric case 'O': /* set option */ 21921755Seric setoption(buf[1], &buf[2], TRUE, FALSE); 2208252Seric break; 2218252Seric 2228252Seric case 'P': /* set precedence */ 2238252Seric if (NumPriorities >= MAXPRIORITIES) 2248252Seric { 2258547Seric toomany('P', MAXPRIORITIES); 2268252Seric break; 2278252Seric } 2289381Seric for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 2298252Seric continue; 2308252Seric if (*p == '\0') 2318252Seric goto badline; 2328252Seric *p = '\0'; 2338252Seric Priorities[NumPriorities].pri_name = newstr(&buf[1]); 2348252Seric Priorities[NumPriorities].pri_val = atoi(++p); 2358252Seric NumPriorities++; 2368252Seric break; 2378252Seric 2388547Seric case 'T': /* trusted user(s) */ 2398547Seric p = &buf[1]; 2408547Seric while (*p != '\0') 2418547Seric { 2428547Seric while (isspace(*p)) 2438547Seric p++; 2448547Seric q = p; 2458547Seric while (*p != '\0' && !isspace(*p)) 2468547Seric p++; 2478547Seric if (*p != '\0') 2488547Seric *p++ = '\0'; 2498547Seric if (*q == '\0') 2508547Seric continue; 2518547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 2528547Seric continue; 2538547Seric if (pv >= &TrustedUsers[MAXTRUST]) 2548547Seric { 2558547Seric toomany('T', MAXTRUST); 2568547Seric break; 2578547Seric } 2588547Seric *pv = newstr(q); 2598547Seric } 2608547Seric break; 2618547Seric 2623308Seric default: 2634061Seric badline: 2649381Seric syserr("unknown control line \"%s\"", buf); 2653308Seric } 2663308Seric } 2679381Seric FileName = NULL; 2684096Seric } 2694096Seric /* 2708547Seric ** TOOMANY -- signal too many of some option 2718547Seric ** 2728547Seric ** Parameters: 2738547Seric ** id -- the id of the error line 2748547Seric ** maxcnt -- the maximum possible values 2758547Seric ** 2768547Seric ** Returns: 2778547Seric ** none. 2788547Seric ** 2798547Seric ** Side Effects: 2808547Seric ** gives a syserr. 2818547Seric */ 2828547Seric 2838547Seric toomany(id, maxcnt) 2848547Seric char id; 2858547Seric int maxcnt; 2868547Seric { 2879381Seric syserr("too many %c lines, %d max", id, maxcnt); 2888547Seric } 2898547Seric /* 2904432Seric ** FILECLASS -- read members of a class from a file 2914432Seric ** 2924432Seric ** Parameters: 2934432Seric ** class -- class to define. 2944432Seric ** filename -- name of file to read. 2954432Seric ** fmt -- scanf string to use for match. 2964432Seric ** 2974432Seric ** Returns: 2984432Seric ** none 2994432Seric ** 3004432Seric ** Side Effects: 3014432Seric ** 3024432Seric ** puts all lines in filename that match a scanf into 3034432Seric ** the named class. 3044432Seric */ 3054432Seric 3064432Seric fileclass(class, filename, fmt) 3074432Seric int class; 3084432Seric char *filename; 3094432Seric char *fmt; 3104432Seric { 31125808Seric FILE *f; 3124432Seric char buf[MAXLINE]; 3134432Seric 3144432Seric f = fopen(filename, "r"); 3154432Seric if (f == NULL) 3164432Seric { 3174432Seric syserr("cannot open %s", filename); 3184432Seric return; 3194432Seric } 3204432Seric 3214432Seric while (fgets(buf, sizeof buf, f) != NULL) 3224432Seric { 3234432Seric register STAB *s; 32425808Seric register char *p; 32525808Seric # ifdef SCANF 3264432Seric char wordbuf[MAXNAME+1]; 3274432Seric 3284432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3294432Seric continue; 33025808Seric p = wordbuf; 33125808Seric # else SCANF 33225808Seric p = buf; 33325808Seric # endif SCANF 33425808Seric 33525808Seric /* 33625808Seric ** Break up the match into words. 33725808Seric */ 33825808Seric 33925808Seric while (*p != '\0') 34025808Seric { 34125808Seric register char *q; 34225808Seric 34325808Seric /* strip leading spaces */ 34425808Seric while (isspace(*p)) 34525808Seric p++; 34625808Seric if (*p == '\0') 34725808Seric break; 34825808Seric 34925808Seric /* find the end of the word */ 35025808Seric q = p; 35125808Seric while (*p != '\0' && !isspace(*p)) 35225808Seric p++; 35325808Seric if (*p != '\0') 35425808Seric *p++ = '\0'; 35525808Seric 35625808Seric /* enter the word in the symbol table */ 35725808Seric s = stab(q, ST_CLASS, ST_ENTER); 35825808Seric setbitn(class, s->s_class); 35925808Seric } 3604432Seric } 3614432Seric 3624627Seric (void) fclose(f); 3634432Seric } 3644432Seric /* 3654096Seric ** MAKEMAILER -- define a new mailer. 3664096Seric ** 3674096Seric ** Parameters: 36810327Seric ** line -- description of mailer. This is in labeled 36910327Seric ** fields. The fields are: 37010327Seric ** P -- the path to the mailer 37110327Seric ** F -- the flags associated with the mailer 37210327Seric ** A -- the argv for this mailer 37310327Seric ** S -- the sender rewriting set 37410327Seric ** R -- the recipient rewriting set 37510327Seric ** E -- the eol string 37610327Seric ** The first word is the canonical name of the mailer. 3774096Seric ** 3784096Seric ** Returns: 3794096Seric ** none. 3804096Seric ** 3814096Seric ** Side Effects: 3824096Seric ** enters the mailer into the mailer table. 3834096Seric */ 3843308Seric 38521066Seric makemailer(line) 3864096Seric char *line; 3874096Seric { 3884096Seric register char *p; 3898067Seric register struct mailer *m; 3908067Seric register STAB *s; 3918067Seric int i; 39210327Seric char fcode; 3934096Seric extern int NextMailer; 39410327Seric extern char **makeargv(); 39510327Seric extern char *munchstring(); 39610327Seric extern char *DelimChar; 39710701Seric extern long atol(); 3984096Seric 39910327Seric /* allocate a mailer and set up defaults */ 40010327Seric m = (struct mailer *) xalloc(sizeof *m); 40110327Seric bzero((char *) m, sizeof *m); 40210327Seric m->m_mno = NextMailer; 40310327Seric m->m_eol = "\n"; 40410327Seric 40510327Seric /* collect the mailer name */ 40610327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 40710327Seric continue; 40810327Seric if (*p != '\0') 40910327Seric *p++ = '\0'; 41010327Seric m->m_name = newstr(line); 41110327Seric 41210327Seric /* now scan through and assign info from the fields */ 41310327Seric while (*p != '\0') 41410327Seric { 41510327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 41610327Seric p++; 41710327Seric 41810327Seric /* p now points to field code */ 41910327Seric fcode = *p; 42010327Seric while (*p != '\0' && *p != '=' && *p != ',') 42110327Seric p++; 42210327Seric if (*p++ != '=') 42310327Seric { 42410327Seric syserr("`=' expected"); 42510327Seric return; 42610327Seric } 42710327Seric while (isspace(*p)) 42810327Seric p++; 42910327Seric 43010327Seric /* p now points to the field body */ 43110327Seric p = munchstring(p); 43210327Seric 43310327Seric /* install the field into the mailer struct */ 43410327Seric switch (fcode) 43510327Seric { 43610327Seric case 'P': /* pathname */ 43710327Seric m->m_mailer = newstr(p); 43810327Seric break; 43910327Seric 44010327Seric case 'F': /* flags */ 44110687Seric for (; *p != '\0'; p++) 44210687Seric setbitn(*p, m->m_flags); 44310327Seric break; 44410327Seric 44510327Seric case 'S': /* sender rewriting ruleset */ 44610327Seric case 'R': /* recipient rewriting ruleset */ 44710327Seric i = atoi(p); 44810327Seric if (i < 0 || i >= MAXRWSETS) 44910327Seric { 45010327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 45110327Seric return; 45210327Seric } 45310327Seric if (fcode == 'S') 45410327Seric m->m_s_rwset = i; 45510327Seric else 45610327Seric m->m_r_rwset = i; 45710327Seric break; 45810327Seric 45910327Seric case 'E': /* end of line string */ 46010327Seric m->m_eol = newstr(p); 46110327Seric break; 46210327Seric 46310327Seric case 'A': /* argument vector */ 46410327Seric m->m_argv = makeargv(p); 46510327Seric break; 46610701Seric 46710701Seric case 'M': /* maximum message size */ 46810701Seric m->m_maxsize = atol(p); 46910701Seric break; 47010327Seric } 47110327Seric 47210327Seric p = DelimChar; 47310327Seric } 47410327Seric 47510327Seric /* now store the mailer away */ 4764096Seric if (NextMailer >= MAXMAILERS) 4774096Seric { 4789381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4794096Seric return; 4804096Seric } 48110327Seric Mailer[NextMailer++] = m; 48210327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 48310327Seric s->s_mailer = m; 48410327Seric } 48510327Seric /* 48610327Seric ** MUNCHSTRING -- translate a string into internal form. 48710327Seric ** 48810327Seric ** Parameters: 48910327Seric ** p -- the string to munch. 49010327Seric ** 49110327Seric ** Returns: 49210327Seric ** the munched string. 49310327Seric ** 49410327Seric ** Side Effects: 49510327Seric ** Sets "DelimChar" to point to the string that caused us 49610327Seric ** to stop. 49710327Seric */ 4984096Seric 49910327Seric char * 50010327Seric munchstring(p) 50110327Seric register char *p; 50210327Seric { 50310327Seric register char *q; 50410327Seric bool backslash = FALSE; 50510327Seric bool quotemode = FALSE; 50610327Seric static char buf[MAXLINE]; 50710327Seric extern char *DelimChar; 5084096Seric 50910327Seric for (q = buf; *p != '\0'; p++) 5104096Seric { 51110327Seric if (backslash) 51210327Seric { 51310327Seric /* everything is roughly literal */ 51410357Seric backslash = FALSE; 51510327Seric switch (*p) 51610327Seric { 51710327Seric case 'r': /* carriage return */ 51810327Seric *q++ = '\r'; 51910327Seric continue; 52010327Seric 52110327Seric case 'n': /* newline */ 52210327Seric *q++ = '\n'; 52310327Seric continue; 52410327Seric 52510327Seric case 'f': /* form feed */ 52610327Seric *q++ = '\f'; 52710327Seric continue; 52810327Seric 52910327Seric case 'b': /* backspace */ 53010327Seric *q++ = '\b'; 53110327Seric continue; 53210327Seric } 53310327Seric *q++ = *p; 53410327Seric } 53510327Seric else 53610327Seric { 53710327Seric if (*p == '\\') 53810327Seric backslash = TRUE; 53910327Seric else if (*p == '"') 54010327Seric quotemode = !quotemode; 54110327Seric else if (quotemode || *p != ',') 54210327Seric *q++ = *p; 54310327Seric else 54410327Seric break; 54510327Seric } 5464096Seric } 5474096Seric 54810327Seric DelimChar = p; 54910327Seric *q++ = '\0'; 55010327Seric return (buf); 55110327Seric } 55210327Seric /* 55310327Seric ** MAKEARGV -- break up a string into words 55410327Seric ** 55510327Seric ** Parameters: 55610327Seric ** p -- the string to break up. 55710327Seric ** 55810327Seric ** Returns: 55910327Seric ** a char **argv (dynamically allocated) 56010327Seric ** 56110327Seric ** Side Effects: 56210327Seric ** munges p. 56310327Seric */ 5644096Seric 56510327Seric char ** 56610327Seric makeargv(p) 56710327Seric register char *p; 56810327Seric { 56910327Seric char *q; 57010327Seric int i; 57110327Seric char **avp; 57210327Seric char *argv[MAXPV + 1]; 57310327Seric 57410327Seric /* take apart the words */ 57510327Seric i = 0; 57610327Seric while (*p != '\0' && i < MAXPV) 5774096Seric { 57810327Seric q = p; 57910327Seric while (*p != '\0' && !isspace(*p)) 58010327Seric p++; 58110327Seric while (isspace(*p)) 58210327Seric *p++ = '\0'; 58310327Seric argv[i++] = newstr(q); 5844096Seric } 58510327Seric argv[i++] = NULL; 5864096Seric 58710327Seric /* now make a copy of the argv */ 58810327Seric avp = (char **) xalloc(sizeof *avp * i); 58916893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 59010327Seric 59110327Seric return (avp); 5923308Seric } 5933308Seric /* 5943308Seric ** PRINTRULES -- print rewrite rules (for debugging) 5953308Seric ** 5963308Seric ** Parameters: 5973308Seric ** none. 5983308Seric ** 5993308Seric ** Returns: 6003308Seric ** none. 6013308Seric ** 6023308Seric ** Side Effects: 6033308Seric ** prints rewrite rules. 6043308Seric */ 6053308Seric 6063308Seric printrules() 6073308Seric { 6083308Seric register struct rewrite *rwp; 6094072Seric register int ruleset; 6103308Seric 6114072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6123308Seric { 6134072Seric if (RewriteRules[ruleset] == NULL) 6144072Seric continue; 6158067Seric printf("\n----Rule Set %d:", ruleset); 6163308Seric 6174072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6183308Seric { 6198067Seric printf("\nLHS:"); 6208067Seric printav(rwp->r_lhs); 6218067Seric printf("RHS:"); 6228067Seric printav(rwp->r_rhs); 6233308Seric } 6243308Seric } 6253308Seric } 6264319Seric 6274096Seric /* 6288256Seric ** SETOPTION -- set global processing option 6298256Seric ** 6308256Seric ** Parameters: 6318256Seric ** opt -- option name. 6328256Seric ** val -- option value (as a text string). 63321755Seric ** safe -- set if this came from a configuration file. 63421755Seric ** Some options (if set from the command line) will 63521755Seric ** reset the user id to avoid security problems. 6368269Seric ** sticky -- if set, don't let other setoptions override 6378269Seric ** this value. 6388256Seric ** 6398256Seric ** Returns: 6408256Seric ** none. 6418256Seric ** 6428256Seric ** Side Effects: 6438256Seric ** Sets options as implied by the arguments. 6448256Seric */ 6458256Seric 64610687Seric static BITMAP StickyOpt; /* set if option is stuck */ 64725700Seric extern char *NetName; /* name of home (local) network */ 6488269Seric 64921755Seric setoption(opt, val, safe, sticky) 6508256Seric char opt; 6518256Seric char *val; 65221755Seric bool safe; 6538269Seric bool sticky; 6548256Seric { 6558265Seric extern bool atobool(); 65612633Seric extern time_t convtime(); 65714879Seric extern int QueueLA; 65814879Seric extern int RefuseLA; 65917474Seric extern bool trusteduser(); 66017474Seric extern char *username(); 6618256Seric 6628256Seric if (tTd(37, 1)) 6639341Seric printf("setoption %c=%s", opt, val); 6648256Seric 6658256Seric /* 6668269Seric ** See if this option is preset for us. 6678256Seric */ 6688256Seric 66910687Seric if (bitnset(opt, StickyOpt)) 6708269Seric { 6719341Seric if (tTd(37, 1)) 6729341Seric printf(" (ignored)\n"); 6738269Seric return; 6748269Seric } 6758269Seric 67621755Seric /* 67721755Seric ** Check to see if this option can be specified by this user. 67821755Seric */ 67921755Seric 68036238Skarels if (!safe && getuid() == 0) 68121755Seric safe = TRUE; 68221755Seric if (!safe && index("deiLmorsv", opt) == NULL) 68321755Seric { 68439111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 68521755Seric { 68636582Sbostic if (tTd(37, 1)) 68736582Sbostic printf(" (unsafe)"); 68836582Sbostic if (getuid() != geteuid()) 68936582Sbostic { 69036582Sbostic printf("(Resetting uid)\n"); 69136582Sbostic (void) setgid(getgid()); 69236582Sbostic (void) setuid(getuid()); 69336582Sbostic } 69421755Seric } 69521755Seric } 69621755Seric else if (tTd(37, 1)) 69717985Seric printf("\n"); 6988269Seric 6998256Seric switch (opt) 7008256Seric { 7018256Seric case 'A': /* set default alias file */ 7029381Seric if (val[0] == '\0') 7038269Seric AliasFile = "aliases"; 7049381Seric else 7059381Seric AliasFile = newstr(val); 7068256Seric break; 7078256Seric 70817474Seric case 'a': /* look N minutes for "@:@" in alias file */ 70917474Seric if (val[0] == '\0') 71017474Seric SafeAlias = 5; 71117474Seric else 71217474Seric SafeAlias = atoi(val); 71317474Seric break; 71417474Seric 71516843Seric case 'B': /* substitution for blank character */ 71616843Seric SpaceSub = val[0]; 71716843Seric if (SpaceSub == '\0') 71816843Seric SpaceSub = ' '; 71916843Seric break; 72016843Seric 7219284Seric case 'c': /* don't connect to "expensive" mailers */ 7229381Seric NoConnect = atobool(val); 7239284Seric break; 7249284Seric 72524944Seric case 'C': /* checkpoint after N connections */ 72624944Seric CheckPointLimit = atoi(val); 72724944Seric break; 72824944Seric 7299284Seric case 'd': /* delivery mode */ 7309284Seric switch (*val) 7318269Seric { 7329284Seric case '\0': 7339284Seric SendMode = SM_DELIVER; 7348269Seric break; 7358269Seric 73610755Seric case SM_QUEUE: /* queue only */ 73710755Seric #ifndef QUEUE 73810755Seric syserr("need QUEUE to set -odqueue"); 73910755Seric #endif QUEUE 74010755Seric /* fall through..... */ 74110755Seric 7429284Seric case SM_DELIVER: /* do everything */ 7439284Seric case SM_FORK: /* fork after verification */ 7449284Seric SendMode = *val; 7458269Seric break; 7468269Seric 7478269Seric default: 7489284Seric syserr("Unknown delivery mode %c", *val); 7498269Seric exit(EX_USAGE); 7508269Seric } 7518269Seric break; 7528269Seric 7539146Seric case 'D': /* rebuild alias database as needed */ 7549381Seric AutoRebuild = atobool(val); 7559146Seric break; 7569146Seric 7578269Seric case 'e': /* set error processing mode */ 7588269Seric switch (*val) 7598269Seric { 7609381Seric case EM_QUIET: /* be silent about it */ 7619381Seric case EM_MAIL: /* mail back */ 7629381Seric case EM_BERKNET: /* do berknet error processing */ 7639381Seric case EM_WRITE: /* write back (or mail) */ 7648269Seric HoldErrs = TRUE; 7659381Seric /* fall through... */ 7668269Seric 7679381Seric case EM_PRINT: /* print errors normally (default) */ 7689381Seric ErrorMode = *val; 7698269Seric break; 7708269Seric } 7718269Seric break; 7728269Seric 7739049Seric case 'F': /* file mode */ 77417975Seric FileMode = atooct(val) & 0777; 7759049Seric break; 7769049Seric 7778269Seric case 'f': /* save Unix-style From lines on front */ 7789381Seric SaveFrom = atobool(val); 7798269Seric break; 7808269Seric 7818256Seric case 'g': /* default gid */ 78217474Seric DefGid = atoi(val); 7838256Seric break; 7848256Seric 7858256Seric case 'H': /* help file */ 7869381Seric if (val[0] == '\0') 7878269Seric HelpFile = "sendmail.hf"; 7889381Seric else 7899381Seric HelpFile = newstr(val); 7908256Seric break; 7918256Seric 79235651Seric case 'I': /* use internet domain name server */ 79335651Seric UseNameServer = atobool(val); 79435651Seric break; 79535651Seric 7968269Seric case 'i': /* ignore dot lines in message */ 7979381Seric IgnrDot = atobool(val); 7988269Seric break; 7998269Seric 8008256Seric case 'L': /* log level */ 8019381Seric LogLevel = atoi(val); 8028256Seric break; 8038256Seric 8048269Seric case 'M': /* define macro */ 8059381Seric define(val[0], newstr(&val[1]), CurEnv); 80616878Seric sticky = FALSE; 8078269Seric break; 8088269Seric 8098269Seric case 'm': /* send to me too */ 8109381Seric MeToo = atobool(val); 8118269Seric break; 8128269Seric 81325820Seric case 'n': /* validate RHS in newaliases */ 81425820Seric CheckAliases = atobool(val); 81525820Seric break; 81625820Seric 81716143Seric # ifdef DAEMON 81816143Seric case 'N': /* home (local?) network name */ 81916143Seric NetName = newstr(val); 82016143Seric break; 82116143Seric # endif DAEMON 82216143Seric 8238269Seric case 'o': /* assume old style headers */ 8249381Seric if (atobool(val)) 8259341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8269341Seric else 8279341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8288269Seric break; 8298269Seric 83024944Seric case 'P': /* postmaster copy address for returned mail */ 83124944Seric PostMasterCopy = newstr(val); 83224944Seric break; 83324944Seric 83424944Seric case 'q': /* slope of queue only function */ 83524944Seric QueueFactor = atoi(val); 83624944Seric break; 83724944Seric 8388256Seric case 'Q': /* queue directory */ 8399381Seric if (val[0] == '\0') 8408269Seric QueueDir = "mqueue"; 8419381Seric else 8429381Seric QueueDir = newstr(val); 8438256Seric break; 8448256Seric 8458256Seric case 'r': /* read timeout */ 8469381Seric ReadTimeout = convtime(val); 8478256Seric break; 8488256Seric 8498256Seric case 'S': /* status file */ 8509381Seric if (val[0] == '\0') 8518269Seric StatFile = "sendmail.st"; 8529381Seric else 8539381Seric StatFile = newstr(val); 8548256Seric break; 8558256Seric 8568265Seric case 's': /* be super safe, even if expensive */ 8579381Seric SuperSafe = atobool(val); 8588256Seric break; 8598256Seric 8608256Seric case 'T': /* queue timeout */ 8619381Seric TimeOut = convtime(val); 86233936Sbostic /*FALLTHROUGH*/ 8638256Seric 8648265Seric case 't': /* time zone name */ 8658265Seric break; 8668265Seric 8678256Seric case 'u': /* set default uid */ 86817474Seric DefUid = atoi(val); 869*40973Sbostic setdefuser(); 8708256Seric break; 8718256Seric 8728269Seric case 'v': /* run in verbose mode */ 8739381Seric Verbose = atobool(val); 8748256Seric break; 8758256Seric 87614879Seric case 'x': /* load avg at which to auto-queue msgs */ 87714879Seric QueueLA = atoi(val); 87814879Seric break; 87914879Seric 88014879Seric case 'X': /* load avg at which to auto-reject connections */ 88114879Seric RefuseLA = atoi(val); 88214879Seric break; 88314879Seric 88424981Seric case 'y': /* work recipient factor */ 88524981Seric WkRecipFact = atoi(val); 88624981Seric break; 88724981Seric 88824981Seric case 'Y': /* fork jobs during queue runs */ 88924952Seric ForkQueueRuns = atobool(val); 89024952Seric break; 89124952Seric 89224981Seric case 'z': /* work message class factor */ 89324981Seric WkClassFact = atoi(val); 89424981Seric break; 89524981Seric 89624981Seric case 'Z': /* work time factor */ 89724981Seric WkTimeFact = atoi(val); 89824981Seric break; 89924981Seric 9008256Seric default: 9018256Seric break; 9028256Seric } 90316878Seric if (sticky) 90416878Seric setbitn(opt, StickyOpt); 9059188Seric return; 9068256Seric } 90710687Seric /* 90810687Seric ** SETCLASS -- set a word into a class 90910687Seric ** 91010687Seric ** Parameters: 91110687Seric ** class -- the class to put the word in. 91210687Seric ** word -- the word to enter 91310687Seric ** 91410687Seric ** Returns: 91510687Seric ** none. 91610687Seric ** 91710687Seric ** Side Effects: 91810687Seric ** puts the word into the symbol table. 91910687Seric */ 92010687Seric 92110687Seric setclass(class, word) 92210687Seric int class; 92310687Seric char *word; 92410687Seric { 92510687Seric register STAB *s; 92610687Seric 92710687Seric s = stab(word, ST_CLASS, ST_ENTER); 92810687Seric setbitn(class, s->s_class); 92910687Seric } 930