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*52062Seric static char sccsid[] = "@(#)readcf.c 5.30 (Berkeley) 12/24/91"; 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 304*52062Seric if (filename[0] == '|') 305*52062Seric f = popen(filename + 1, "r"); 306*52062Seric else 307*52062Seric 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 355*52062Seric if (filename[0] == '|') 356*52062Seric (void) pclose(f); 357*52062Seric else 358*52062Seric (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; 46610327Seric } 46710327Seric 46810327Seric p = DelimChar; 46910327Seric } 47010327Seric 47110327Seric /* now store the mailer away */ 4724096Seric if (NextMailer >= MAXMAILERS) 4734096Seric { 4749381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4754096Seric return; 4764096Seric } 47710327Seric Mailer[NextMailer++] = m; 47810327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 47910327Seric s->s_mailer = m; 48010327Seric } 48110327Seric /* 48210327Seric ** MUNCHSTRING -- translate a string into internal form. 48310327Seric ** 48410327Seric ** Parameters: 48510327Seric ** p -- the string to munch. 48610327Seric ** 48710327Seric ** Returns: 48810327Seric ** the munched string. 48910327Seric ** 49010327Seric ** Side Effects: 49110327Seric ** Sets "DelimChar" to point to the string that caused us 49210327Seric ** to stop. 49310327Seric */ 4944096Seric 49510327Seric char * 49610327Seric munchstring(p) 49710327Seric register char *p; 49810327Seric { 49910327Seric register char *q; 50010327Seric bool backslash = FALSE; 50110327Seric bool quotemode = FALSE; 50210327Seric static char buf[MAXLINE]; 50310327Seric extern char *DelimChar; 5044096Seric 50510327Seric for (q = buf; *p != '\0'; p++) 5064096Seric { 50710327Seric if (backslash) 50810327Seric { 50910327Seric /* everything is roughly literal */ 51010357Seric backslash = FALSE; 51110327Seric switch (*p) 51210327Seric { 51310327Seric case 'r': /* carriage return */ 51410327Seric *q++ = '\r'; 51510327Seric continue; 51610327Seric 51710327Seric case 'n': /* newline */ 51810327Seric *q++ = '\n'; 51910327Seric continue; 52010327Seric 52110327Seric case 'f': /* form feed */ 52210327Seric *q++ = '\f'; 52310327Seric continue; 52410327Seric 52510327Seric case 'b': /* backspace */ 52610327Seric *q++ = '\b'; 52710327Seric continue; 52810327Seric } 52910327Seric *q++ = *p; 53010327Seric } 53110327Seric else 53210327Seric { 53310327Seric if (*p == '\\') 53410327Seric backslash = TRUE; 53510327Seric else if (*p == '"') 53610327Seric quotemode = !quotemode; 53710327Seric else if (quotemode || *p != ',') 53810327Seric *q++ = *p; 53910327Seric else 54010327Seric break; 54110327Seric } 5424096Seric } 5434096Seric 54410327Seric DelimChar = p; 54510327Seric *q++ = '\0'; 54610327Seric return (buf); 54710327Seric } 54810327Seric /* 54910327Seric ** MAKEARGV -- break up a string into words 55010327Seric ** 55110327Seric ** Parameters: 55210327Seric ** p -- the string to break up. 55310327Seric ** 55410327Seric ** Returns: 55510327Seric ** a char **argv (dynamically allocated) 55610327Seric ** 55710327Seric ** Side Effects: 55810327Seric ** munges p. 55910327Seric */ 5604096Seric 56110327Seric char ** 56210327Seric makeargv(p) 56310327Seric register char *p; 56410327Seric { 56510327Seric char *q; 56610327Seric int i; 56710327Seric char **avp; 56810327Seric char *argv[MAXPV + 1]; 56910327Seric 57010327Seric /* take apart the words */ 57110327Seric i = 0; 57210327Seric while (*p != '\0' && i < MAXPV) 5734096Seric { 57410327Seric q = p; 57510327Seric while (*p != '\0' && !isspace(*p)) 57610327Seric p++; 57710327Seric while (isspace(*p)) 57810327Seric *p++ = '\0'; 57910327Seric argv[i++] = newstr(q); 5804096Seric } 58110327Seric argv[i++] = NULL; 5824096Seric 58310327Seric /* now make a copy of the argv */ 58410327Seric avp = (char **) xalloc(sizeof *avp * i); 58516893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 58610327Seric 58710327Seric return (avp); 5883308Seric } 5893308Seric /* 5903308Seric ** PRINTRULES -- print rewrite rules (for debugging) 5913308Seric ** 5923308Seric ** Parameters: 5933308Seric ** none. 5943308Seric ** 5953308Seric ** Returns: 5963308Seric ** none. 5973308Seric ** 5983308Seric ** Side Effects: 5993308Seric ** prints rewrite rules. 6003308Seric */ 6013308Seric 6023308Seric printrules() 6033308Seric { 6043308Seric register struct rewrite *rwp; 6054072Seric register int ruleset; 6063308Seric 6074072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6083308Seric { 6094072Seric if (RewriteRules[ruleset] == NULL) 6104072Seric continue; 6118067Seric printf("\n----Rule Set %d:", ruleset); 6123308Seric 6134072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6143308Seric { 6158067Seric printf("\nLHS:"); 6168067Seric printav(rwp->r_lhs); 6178067Seric printf("RHS:"); 6188067Seric printav(rwp->r_rhs); 6193308Seric } 6203308Seric } 6213308Seric } 6224319Seric 6234096Seric /* 6248256Seric ** SETOPTION -- set global processing option 6258256Seric ** 6268256Seric ** Parameters: 6278256Seric ** opt -- option name. 6288256Seric ** val -- option value (as a text string). 62921755Seric ** safe -- set if this came from a configuration file. 63021755Seric ** Some options (if set from the command line) will 63121755Seric ** reset the user id to avoid security problems. 6328269Seric ** sticky -- if set, don't let other setoptions override 6338269Seric ** this value. 6348256Seric ** 6358256Seric ** Returns: 6368256Seric ** none. 6378256Seric ** 6388256Seric ** Side Effects: 6398256Seric ** Sets options as implied by the arguments. 6408256Seric */ 6418256Seric 64210687Seric static BITMAP StickyOpt; /* set if option is stuck */ 64325700Seric extern char *NetName; /* name of home (local) network */ 6448269Seric 64521755Seric setoption(opt, val, safe, sticky) 6468256Seric char opt; 6478256Seric char *val; 64821755Seric bool safe; 6498269Seric bool sticky; 6508256Seric { 6518265Seric extern bool atobool(); 65212633Seric extern time_t convtime(); 65314879Seric extern int QueueLA; 65414879Seric extern int RefuseLA; 65517474Seric extern bool trusteduser(); 65617474Seric extern char *username(); 6578256Seric 6588256Seric if (tTd(37, 1)) 6599341Seric printf("setoption %c=%s", opt, val); 6608256Seric 6618256Seric /* 6628269Seric ** See if this option is preset for us. 6638256Seric */ 6648256Seric 66510687Seric if (bitnset(opt, StickyOpt)) 6668269Seric { 6679341Seric if (tTd(37, 1)) 6689341Seric printf(" (ignored)\n"); 6698269Seric return; 6708269Seric } 6718269Seric 67221755Seric /* 67321755Seric ** Check to see if this option can be specified by this user. 67421755Seric */ 67521755Seric 67636238Skarels if (!safe && getuid() == 0) 67721755Seric safe = TRUE; 67821755Seric if (!safe && index("deiLmorsv", opt) == NULL) 67921755Seric { 68039111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 68121755Seric { 68236582Sbostic if (tTd(37, 1)) 68336582Sbostic printf(" (unsafe)"); 68436582Sbostic if (getuid() != geteuid()) 68536582Sbostic { 68651210Seric if (tTd(37, 1)) 68751210Seric printf("(Resetting uid)"); 68836582Sbostic (void) setgid(getgid()); 68936582Sbostic (void) setuid(getuid()); 69036582Sbostic } 69121755Seric } 69221755Seric } 69351210Seric if (tTd(37, 1)) 69417985Seric printf("\n"); 6958269Seric 6968256Seric switch (opt) 6978256Seric { 69851312Seric case '=': /* config file generation level */ 69951312Seric ConfigLevel = atoi(val); 70051312Seric break; 70151312Seric 7028256Seric case 'A': /* set default alias file */ 7039381Seric if (val[0] == '\0') 7048269Seric AliasFile = "aliases"; 7059381Seric else 7069381Seric AliasFile = newstr(val); 7078256Seric break; 7088256Seric 70917474Seric case 'a': /* look N minutes for "@:@" in alias file */ 71017474Seric if (val[0] == '\0') 71117474Seric SafeAlias = 5; 71217474Seric else 71317474Seric SafeAlias = atoi(val); 71417474Seric break; 71517474Seric 71616843Seric case 'B': /* substitution for blank character */ 71716843Seric SpaceSub = val[0]; 71816843Seric if (SpaceSub == '\0') 71916843Seric SpaceSub = ' '; 72016843Seric break; 72116843Seric 7229284Seric case 'c': /* don't connect to "expensive" mailers */ 7239381Seric NoConnect = atobool(val); 7249284Seric break; 7259284Seric 72651305Seric case 'C': /* checkpoint every N addresses */ 72751305Seric CheckpointInterval = atoi(val); 72824944Seric break; 72924944Seric 7309284Seric case 'd': /* delivery mode */ 7319284Seric switch (*val) 7328269Seric { 7339284Seric case '\0': 7349284Seric SendMode = SM_DELIVER; 7358269Seric break; 7368269Seric 73710755Seric case SM_QUEUE: /* queue only */ 73810755Seric #ifndef QUEUE 73910755Seric syserr("need QUEUE to set -odqueue"); 74010755Seric #endif QUEUE 74110755Seric /* fall through..... */ 74210755Seric 7439284Seric case SM_DELIVER: /* do everything */ 7449284Seric case SM_FORK: /* fork after verification */ 7459284Seric SendMode = *val; 7468269Seric break; 7478269Seric 7488269Seric default: 7499284Seric syserr("Unknown delivery mode %c", *val); 7508269Seric exit(EX_USAGE); 7518269Seric } 7528269Seric break; 7538269Seric 7549146Seric case 'D': /* rebuild alias database as needed */ 7559381Seric AutoRebuild = atobool(val); 7569146Seric break; 7579146Seric 7588269Seric case 'e': /* set error processing mode */ 7598269Seric switch (*val) 7608269Seric { 7619381Seric case EM_QUIET: /* be silent about it */ 7629381Seric case EM_MAIL: /* mail back */ 7639381Seric case EM_BERKNET: /* do berknet error processing */ 7649381Seric case EM_WRITE: /* write back (or mail) */ 7658269Seric HoldErrs = TRUE; 7669381Seric /* fall through... */ 7678269Seric 7689381Seric case EM_PRINT: /* print errors normally (default) */ 7699381Seric ErrorMode = *val; 7708269Seric break; 7718269Seric } 7728269Seric break; 7738269Seric 7749049Seric case 'F': /* file mode */ 77517975Seric FileMode = atooct(val) & 0777; 7769049Seric break; 7779049Seric 7788269Seric case 'f': /* save Unix-style From lines on front */ 7799381Seric SaveFrom = atobool(val); 7808269Seric break; 7818269Seric 7828256Seric case 'g': /* default gid */ 78317474Seric DefGid = atoi(val); 7848256Seric break; 7858256Seric 7868256Seric case 'H': /* help file */ 7879381Seric if (val[0] == '\0') 7888269Seric HelpFile = "sendmail.hf"; 7899381Seric else 7909381Seric HelpFile = newstr(val); 7918256Seric break; 7928256Seric 79351305Seric case 'h': /* maximum hop count */ 79451305Seric MaxHopCount = atoi(val); 79551305Seric break; 79651305Seric 79735651Seric case 'I': /* use internet domain name server */ 79835651Seric UseNameServer = atobool(val); 79935651Seric break; 80035651Seric 8018269Seric case 'i': /* ignore dot lines in message */ 8029381Seric IgnrDot = atobool(val); 8038269Seric break; 8048269Seric 8058256Seric case 'L': /* log level */ 8069381Seric LogLevel = atoi(val); 8078256Seric break; 8088256Seric 8098269Seric case 'M': /* define macro */ 8109381Seric define(val[0], newstr(&val[1]), CurEnv); 81116878Seric sticky = FALSE; 8128269Seric break; 8138269Seric 8148269Seric case 'm': /* send to me too */ 8159381Seric MeToo = atobool(val); 8168269Seric break; 8178269Seric 81825820Seric case 'n': /* validate RHS in newaliases */ 81925820Seric CheckAliases = atobool(val); 82025820Seric break; 82125820Seric 82216143Seric # ifdef DAEMON 82316143Seric case 'N': /* home (local?) network name */ 82416143Seric NetName = newstr(val); 82516143Seric break; 82616143Seric # endif DAEMON 82716143Seric 8288269Seric case 'o': /* assume old style headers */ 8299381Seric if (atobool(val)) 8309341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8319341Seric else 8329341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8338269Seric break; 8348269Seric 83524944Seric case 'P': /* postmaster copy address for returned mail */ 83624944Seric PostMasterCopy = newstr(val); 83724944Seric break; 83824944Seric 83924944Seric case 'q': /* slope of queue only function */ 84024944Seric QueueFactor = atoi(val); 84124944Seric break; 84224944Seric 8438256Seric case 'Q': /* queue directory */ 8449381Seric if (val[0] == '\0') 8458269Seric QueueDir = "mqueue"; 8469381Seric else 8479381Seric QueueDir = newstr(val); 8488256Seric break; 8498256Seric 8508256Seric case 'r': /* read timeout */ 8519381Seric ReadTimeout = convtime(val); 8528256Seric break; 8538256Seric 8548256Seric case 'S': /* status file */ 8559381Seric if (val[0] == '\0') 8568269Seric StatFile = "sendmail.st"; 8579381Seric else 8589381Seric StatFile = newstr(val); 8598256Seric break; 8608256Seric 8618265Seric case 's': /* be super safe, even if expensive */ 8629381Seric SuperSafe = atobool(val); 8638256Seric break; 8648256Seric 8658256Seric case 'T': /* queue timeout */ 8669381Seric TimeOut = convtime(val); 86733936Sbostic /*FALLTHROUGH*/ 8688256Seric 8698265Seric case 't': /* time zone name */ 8708265Seric break; 8718265Seric 87250556Seric case 'U': /* location of user database */ 87351360Seric UdbSpec = newstr(val); 87450556Seric break; 87550556Seric 8768256Seric case 'u': /* set default uid */ 87717474Seric DefUid = atoi(val); 87840973Sbostic setdefuser(); 8798256Seric break; 8808256Seric 8818269Seric case 'v': /* run in verbose mode */ 8829381Seric Verbose = atobool(val); 8838256Seric break; 8848256Seric 88551216Seric case 'w': /* we don't have wildcard MX records */ 88651216Seric NoWildcardMX = atobool(val); 88750537Seric break; 88850537Seric 88914879Seric case 'x': /* load avg at which to auto-queue msgs */ 89014879Seric QueueLA = atoi(val); 89114879Seric break; 89214879Seric 89314879Seric case 'X': /* load avg at which to auto-reject connections */ 89414879Seric RefuseLA = atoi(val); 89514879Seric break; 89614879Seric 89724981Seric case 'y': /* work recipient factor */ 89824981Seric WkRecipFact = atoi(val); 89924981Seric break; 90024981Seric 90124981Seric case 'Y': /* fork jobs during queue runs */ 90224952Seric ForkQueueRuns = atobool(val); 90324952Seric break; 90424952Seric 90524981Seric case 'z': /* work message class factor */ 90624981Seric WkClassFact = atoi(val); 90724981Seric break; 90824981Seric 90924981Seric case 'Z': /* work time factor */ 91024981Seric WkTimeFact = atoi(val); 91124981Seric break; 91224981Seric 9138256Seric default: 9148256Seric break; 9158256Seric } 91616878Seric if (sticky) 91716878Seric setbitn(opt, StickyOpt); 9189188Seric return; 9198256Seric } 92010687Seric /* 92110687Seric ** SETCLASS -- set a word into a class 92210687Seric ** 92310687Seric ** Parameters: 92410687Seric ** class -- the class to put the word in. 92510687Seric ** word -- the word to enter 92610687Seric ** 92710687Seric ** Returns: 92810687Seric ** none. 92910687Seric ** 93010687Seric ** Side Effects: 93110687Seric ** puts the word into the symbol table. 93210687Seric */ 93310687Seric 93410687Seric setclass(class, word) 93510687Seric int class; 93610687Seric char *word; 93710687Seric { 93810687Seric register STAB *s; 93910687Seric 94010687Seric s = stab(word, ST_CLASS, ST_ENTER); 94110687Seric setbitn(class, s->s_class); 94210687Seric } 943