122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 6*42829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822709Sdist 922709Sdist #ifndef lint 10*42829Sbostic static char sccsid[] = "@(#)readcf.c 5.21 (Berkeley) 06/01/90"; 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 3044432Seric f = fopen(filename, "r"); 3054432Seric if (f == NULL) 3064432Seric { 3074432Seric syserr("cannot open %s", filename); 3084432Seric return; 3094432Seric } 3104432Seric 3114432Seric while (fgets(buf, sizeof buf, f) != NULL) 3124432Seric { 3134432Seric register STAB *s; 31425808Seric register char *p; 31525808Seric # ifdef SCANF 3164432Seric char wordbuf[MAXNAME+1]; 3174432Seric 3184432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3194432Seric continue; 32025808Seric p = wordbuf; 32125808Seric # else SCANF 32225808Seric p = buf; 32325808Seric # endif SCANF 32425808Seric 32525808Seric /* 32625808Seric ** Break up the match into words. 32725808Seric */ 32825808Seric 32925808Seric while (*p != '\0') 33025808Seric { 33125808Seric register char *q; 33225808Seric 33325808Seric /* strip leading spaces */ 33425808Seric while (isspace(*p)) 33525808Seric p++; 33625808Seric if (*p == '\0') 33725808Seric break; 33825808Seric 33925808Seric /* find the end of the word */ 34025808Seric q = p; 34125808Seric while (*p != '\0' && !isspace(*p)) 34225808Seric p++; 34325808Seric if (*p != '\0') 34425808Seric *p++ = '\0'; 34525808Seric 34625808Seric /* enter the word in the symbol table */ 34725808Seric s = stab(q, ST_CLASS, ST_ENTER); 34825808Seric setbitn(class, s->s_class); 34925808Seric } 3504432Seric } 3514432Seric 3524627Seric (void) fclose(f); 3534432Seric } 3544432Seric /* 3554096Seric ** MAKEMAILER -- define a new mailer. 3564096Seric ** 3574096Seric ** Parameters: 35810327Seric ** line -- description of mailer. This is in labeled 35910327Seric ** fields. The fields are: 36010327Seric ** P -- the path to the mailer 36110327Seric ** F -- the flags associated with the mailer 36210327Seric ** A -- the argv for this mailer 36310327Seric ** S -- the sender rewriting set 36410327Seric ** R -- the recipient rewriting set 36510327Seric ** E -- the eol string 36610327Seric ** The first word is the canonical name of the mailer. 3674096Seric ** 3684096Seric ** Returns: 3694096Seric ** none. 3704096Seric ** 3714096Seric ** Side Effects: 3724096Seric ** enters the mailer into the mailer table. 3734096Seric */ 3743308Seric 37521066Seric makemailer(line) 3764096Seric char *line; 3774096Seric { 3784096Seric register char *p; 3798067Seric register struct mailer *m; 3808067Seric register STAB *s; 3818067Seric int i; 38210327Seric char fcode; 3834096Seric extern int NextMailer; 38410327Seric extern char **makeargv(); 38510327Seric extern char *munchstring(); 38610327Seric extern char *DelimChar; 38710701Seric extern long atol(); 3884096Seric 38910327Seric /* allocate a mailer and set up defaults */ 39010327Seric m = (struct mailer *) xalloc(sizeof *m); 39110327Seric bzero((char *) m, sizeof *m); 39210327Seric m->m_mno = NextMailer; 39310327Seric m->m_eol = "\n"; 39410327Seric 39510327Seric /* collect the mailer name */ 39610327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 39710327Seric continue; 39810327Seric if (*p != '\0') 39910327Seric *p++ = '\0'; 40010327Seric m->m_name = newstr(line); 40110327Seric 40210327Seric /* now scan through and assign info from the fields */ 40310327Seric while (*p != '\0') 40410327Seric { 40510327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 40610327Seric p++; 40710327Seric 40810327Seric /* p now points to field code */ 40910327Seric fcode = *p; 41010327Seric while (*p != '\0' && *p != '=' && *p != ',') 41110327Seric p++; 41210327Seric if (*p++ != '=') 41310327Seric { 41410327Seric syserr("`=' expected"); 41510327Seric return; 41610327Seric } 41710327Seric while (isspace(*p)) 41810327Seric p++; 41910327Seric 42010327Seric /* p now points to the field body */ 42110327Seric p = munchstring(p); 42210327Seric 42310327Seric /* install the field into the mailer struct */ 42410327Seric switch (fcode) 42510327Seric { 42610327Seric case 'P': /* pathname */ 42710327Seric m->m_mailer = newstr(p); 42810327Seric break; 42910327Seric 43010327Seric case 'F': /* flags */ 43110687Seric for (; *p != '\0'; p++) 43210687Seric setbitn(*p, m->m_flags); 43310327Seric break; 43410327Seric 43510327Seric case 'S': /* sender rewriting ruleset */ 43610327Seric case 'R': /* recipient rewriting ruleset */ 43710327Seric i = atoi(p); 43810327Seric if (i < 0 || i >= MAXRWSETS) 43910327Seric { 44010327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 44110327Seric return; 44210327Seric } 44310327Seric if (fcode == 'S') 44410327Seric m->m_s_rwset = i; 44510327Seric else 44610327Seric m->m_r_rwset = i; 44710327Seric break; 44810327Seric 44910327Seric case 'E': /* end of line string */ 45010327Seric m->m_eol = newstr(p); 45110327Seric break; 45210327Seric 45310327Seric case 'A': /* argument vector */ 45410327Seric m->m_argv = makeargv(p); 45510327Seric break; 45610701Seric 45710701Seric case 'M': /* maximum message size */ 45810701Seric m->m_maxsize = atol(p); 45910701Seric break; 46010327Seric } 46110327Seric 46210327Seric p = DelimChar; 46310327Seric } 46410327Seric 46510327Seric /* now store the mailer away */ 4664096Seric if (NextMailer >= MAXMAILERS) 4674096Seric { 4689381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4694096Seric return; 4704096Seric } 47110327Seric Mailer[NextMailer++] = m; 47210327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 47310327Seric s->s_mailer = m; 47410327Seric } 47510327Seric /* 47610327Seric ** MUNCHSTRING -- translate a string into internal form. 47710327Seric ** 47810327Seric ** Parameters: 47910327Seric ** p -- the string to munch. 48010327Seric ** 48110327Seric ** Returns: 48210327Seric ** the munched string. 48310327Seric ** 48410327Seric ** Side Effects: 48510327Seric ** Sets "DelimChar" to point to the string that caused us 48610327Seric ** to stop. 48710327Seric */ 4884096Seric 48910327Seric char * 49010327Seric munchstring(p) 49110327Seric register char *p; 49210327Seric { 49310327Seric register char *q; 49410327Seric bool backslash = FALSE; 49510327Seric bool quotemode = FALSE; 49610327Seric static char buf[MAXLINE]; 49710327Seric extern char *DelimChar; 4984096Seric 49910327Seric for (q = buf; *p != '\0'; p++) 5004096Seric { 50110327Seric if (backslash) 50210327Seric { 50310327Seric /* everything is roughly literal */ 50410357Seric backslash = FALSE; 50510327Seric switch (*p) 50610327Seric { 50710327Seric case 'r': /* carriage return */ 50810327Seric *q++ = '\r'; 50910327Seric continue; 51010327Seric 51110327Seric case 'n': /* newline */ 51210327Seric *q++ = '\n'; 51310327Seric continue; 51410327Seric 51510327Seric case 'f': /* form feed */ 51610327Seric *q++ = '\f'; 51710327Seric continue; 51810327Seric 51910327Seric case 'b': /* backspace */ 52010327Seric *q++ = '\b'; 52110327Seric continue; 52210327Seric } 52310327Seric *q++ = *p; 52410327Seric } 52510327Seric else 52610327Seric { 52710327Seric if (*p == '\\') 52810327Seric backslash = TRUE; 52910327Seric else if (*p == '"') 53010327Seric quotemode = !quotemode; 53110327Seric else if (quotemode || *p != ',') 53210327Seric *q++ = *p; 53310327Seric else 53410327Seric break; 53510327Seric } 5364096Seric } 5374096Seric 53810327Seric DelimChar = p; 53910327Seric *q++ = '\0'; 54010327Seric return (buf); 54110327Seric } 54210327Seric /* 54310327Seric ** MAKEARGV -- break up a string into words 54410327Seric ** 54510327Seric ** Parameters: 54610327Seric ** p -- the string to break up. 54710327Seric ** 54810327Seric ** Returns: 54910327Seric ** a char **argv (dynamically allocated) 55010327Seric ** 55110327Seric ** Side Effects: 55210327Seric ** munges p. 55310327Seric */ 5544096Seric 55510327Seric char ** 55610327Seric makeargv(p) 55710327Seric register char *p; 55810327Seric { 55910327Seric char *q; 56010327Seric int i; 56110327Seric char **avp; 56210327Seric char *argv[MAXPV + 1]; 56310327Seric 56410327Seric /* take apart the words */ 56510327Seric i = 0; 56610327Seric while (*p != '\0' && i < MAXPV) 5674096Seric { 56810327Seric q = p; 56910327Seric while (*p != '\0' && !isspace(*p)) 57010327Seric p++; 57110327Seric while (isspace(*p)) 57210327Seric *p++ = '\0'; 57310327Seric argv[i++] = newstr(q); 5744096Seric } 57510327Seric argv[i++] = NULL; 5764096Seric 57710327Seric /* now make a copy of the argv */ 57810327Seric avp = (char **) xalloc(sizeof *avp * i); 57916893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 58010327Seric 58110327Seric return (avp); 5823308Seric } 5833308Seric /* 5843308Seric ** PRINTRULES -- print rewrite rules (for debugging) 5853308Seric ** 5863308Seric ** Parameters: 5873308Seric ** none. 5883308Seric ** 5893308Seric ** Returns: 5903308Seric ** none. 5913308Seric ** 5923308Seric ** Side Effects: 5933308Seric ** prints rewrite rules. 5943308Seric */ 5953308Seric 5963308Seric printrules() 5973308Seric { 5983308Seric register struct rewrite *rwp; 5994072Seric register int ruleset; 6003308Seric 6014072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6023308Seric { 6034072Seric if (RewriteRules[ruleset] == NULL) 6044072Seric continue; 6058067Seric printf("\n----Rule Set %d:", ruleset); 6063308Seric 6074072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6083308Seric { 6098067Seric printf("\nLHS:"); 6108067Seric printav(rwp->r_lhs); 6118067Seric printf("RHS:"); 6128067Seric printav(rwp->r_rhs); 6133308Seric } 6143308Seric } 6153308Seric } 6164319Seric 6174096Seric /* 6188256Seric ** SETOPTION -- set global processing option 6198256Seric ** 6208256Seric ** Parameters: 6218256Seric ** opt -- option name. 6228256Seric ** val -- option value (as a text string). 62321755Seric ** safe -- set if this came from a configuration file. 62421755Seric ** Some options (if set from the command line) will 62521755Seric ** reset the user id to avoid security problems. 6268269Seric ** sticky -- if set, don't let other setoptions override 6278269Seric ** this value. 6288256Seric ** 6298256Seric ** Returns: 6308256Seric ** none. 6318256Seric ** 6328256Seric ** Side Effects: 6338256Seric ** Sets options as implied by the arguments. 6348256Seric */ 6358256Seric 63610687Seric static BITMAP StickyOpt; /* set if option is stuck */ 63725700Seric extern char *NetName; /* name of home (local) network */ 6388269Seric 63921755Seric setoption(opt, val, safe, sticky) 6408256Seric char opt; 6418256Seric char *val; 64221755Seric bool safe; 6438269Seric bool sticky; 6448256Seric { 6458265Seric extern bool atobool(); 64612633Seric extern time_t convtime(); 64714879Seric extern int QueueLA; 64814879Seric extern int RefuseLA; 64917474Seric extern bool trusteduser(); 65017474Seric extern char *username(); 6518256Seric 6528256Seric if (tTd(37, 1)) 6539341Seric printf("setoption %c=%s", opt, val); 6548256Seric 6558256Seric /* 6568269Seric ** See if this option is preset for us. 6578256Seric */ 6588256Seric 65910687Seric if (bitnset(opt, StickyOpt)) 6608269Seric { 6619341Seric if (tTd(37, 1)) 6629341Seric printf(" (ignored)\n"); 6638269Seric return; 6648269Seric } 6658269Seric 66621755Seric /* 66721755Seric ** Check to see if this option can be specified by this user. 66821755Seric */ 66921755Seric 67036238Skarels if (!safe && getuid() == 0) 67121755Seric safe = TRUE; 67221755Seric if (!safe && index("deiLmorsv", opt) == NULL) 67321755Seric { 67439111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 67521755Seric { 67636582Sbostic if (tTd(37, 1)) 67736582Sbostic printf(" (unsafe)"); 67836582Sbostic if (getuid() != geteuid()) 67936582Sbostic { 68036582Sbostic printf("(Resetting uid)\n"); 68136582Sbostic (void) setgid(getgid()); 68236582Sbostic (void) setuid(getuid()); 68336582Sbostic } 68421755Seric } 68521755Seric } 68621755Seric else if (tTd(37, 1)) 68717985Seric printf("\n"); 6888269Seric 6898256Seric switch (opt) 6908256Seric { 6918256Seric case 'A': /* set default alias file */ 6929381Seric if (val[0] == '\0') 6938269Seric AliasFile = "aliases"; 6949381Seric else 6959381Seric AliasFile = newstr(val); 6968256Seric break; 6978256Seric 69817474Seric case 'a': /* look N minutes for "@:@" in alias file */ 69917474Seric if (val[0] == '\0') 70017474Seric SafeAlias = 5; 70117474Seric else 70217474Seric SafeAlias = atoi(val); 70317474Seric break; 70417474Seric 70516843Seric case 'B': /* substitution for blank character */ 70616843Seric SpaceSub = val[0]; 70716843Seric if (SpaceSub == '\0') 70816843Seric SpaceSub = ' '; 70916843Seric break; 71016843Seric 7119284Seric case 'c': /* don't connect to "expensive" mailers */ 7129381Seric NoConnect = atobool(val); 7139284Seric break; 7149284Seric 71524944Seric case 'C': /* checkpoint after N connections */ 71624944Seric CheckPointLimit = atoi(val); 71724944Seric break; 71824944Seric 7199284Seric case 'd': /* delivery mode */ 7209284Seric switch (*val) 7218269Seric { 7229284Seric case '\0': 7239284Seric SendMode = SM_DELIVER; 7248269Seric break; 7258269Seric 72610755Seric case SM_QUEUE: /* queue only */ 72710755Seric #ifndef QUEUE 72810755Seric syserr("need QUEUE to set -odqueue"); 72910755Seric #endif QUEUE 73010755Seric /* fall through..... */ 73110755Seric 7329284Seric case SM_DELIVER: /* do everything */ 7339284Seric case SM_FORK: /* fork after verification */ 7349284Seric SendMode = *val; 7358269Seric break; 7368269Seric 7378269Seric default: 7389284Seric syserr("Unknown delivery mode %c", *val); 7398269Seric exit(EX_USAGE); 7408269Seric } 7418269Seric break; 7428269Seric 7439146Seric case 'D': /* rebuild alias database as needed */ 7449381Seric AutoRebuild = atobool(val); 7459146Seric break; 7469146Seric 7478269Seric case 'e': /* set error processing mode */ 7488269Seric switch (*val) 7498269Seric { 7509381Seric case EM_QUIET: /* be silent about it */ 7519381Seric case EM_MAIL: /* mail back */ 7529381Seric case EM_BERKNET: /* do berknet error processing */ 7539381Seric case EM_WRITE: /* write back (or mail) */ 7548269Seric HoldErrs = TRUE; 7559381Seric /* fall through... */ 7568269Seric 7579381Seric case EM_PRINT: /* print errors normally (default) */ 7589381Seric ErrorMode = *val; 7598269Seric break; 7608269Seric } 7618269Seric break; 7628269Seric 7639049Seric case 'F': /* file mode */ 76417975Seric FileMode = atooct(val) & 0777; 7659049Seric break; 7669049Seric 7678269Seric case 'f': /* save Unix-style From lines on front */ 7689381Seric SaveFrom = atobool(val); 7698269Seric break; 7708269Seric 7718256Seric case 'g': /* default gid */ 77217474Seric DefGid = atoi(val); 7738256Seric break; 7748256Seric 7758256Seric case 'H': /* help file */ 7769381Seric if (val[0] == '\0') 7778269Seric HelpFile = "sendmail.hf"; 7789381Seric else 7799381Seric HelpFile = newstr(val); 7808256Seric break; 7818256Seric 78235651Seric case 'I': /* use internet domain name server */ 78335651Seric UseNameServer = atobool(val); 78435651Seric break; 78535651Seric 7868269Seric case 'i': /* ignore dot lines in message */ 7879381Seric IgnrDot = atobool(val); 7888269Seric break; 7898269Seric 7908256Seric case 'L': /* log level */ 7919381Seric LogLevel = atoi(val); 7928256Seric break; 7938256Seric 7948269Seric case 'M': /* define macro */ 7959381Seric define(val[0], newstr(&val[1]), CurEnv); 79616878Seric sticky = FALSE; 7978269Seric break; 7988269Seric 7998269Seric case 'm': /* send to me too */ 8009381Seric MeToo = atobool(val); 8018269Seric break; 8028269Seric 80325820Seric case 'n': /* validate RHS in newaliases */ 80425820Seric CheckAliases = atobool(val); 80525820Seric break; 80625820Seric 80716143Seric # ifdef DAEMON 80816143Seric case 'N': /* home (local?) network name */ 80916143Seric NetName = newstr(val); 81016143Seric break; 81116143Seric # endif DAEMON 81216143Seric 8138269Seric case 'o': /* assume old style headers */ 8149381Seric if (atobool(val)) 8159341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8169341Seric else 8179341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8188269Seric break; 8198269Seric 82024944Seric case 'P': /* postmaster copy address for returned mail */ 82124944Seric PostMasterCopy = newstr(val); 82224944Seric break; 82324944Seric 82424944Seric case 'q': /* slope of queue only function */ 82524944Seric QueueFactor = atoi(val); 82624944Seric break; 82724944Seric 8288256Seric case 'Q': /* queue directory */ 8299381Seric if (val[0] == '\0') 8308269Seric QueueDir = "mqueue"; 8319381Seric else 8329381Seric QueueDir = newstr(val); 8338256Seric break; 8348256Seric 8358256Seric case 'r': /* read timeout */ 8369381Seric ReadTimeout = convtime(val); 8378256Seric break; 8388256Seric 8398256Seric case 'S': /* status file */ 8409381Seric if (val[0] == '\0') 8418269Seric StatFile = "sendmail.st"; 8429381Seric else 8439381Seric StatFile = newstr(val); 8448256Seric break; 8458256Seric 8468265Seric case 's': /* be super safe, even if expensive */ 8479381Seric SuperSafe = atobool(val); 8488256Seric break; 8498256Seric 8508256Seric case 'T': /* queue timeout */ 8519381Seric TimeOut = convtime(val); 85233936Sbostic /*FALLTHROUGH*/ 8538256Seric 8548265Seric case 't': /* time zone name */ 8558265Seric break; 8568265Seric 8578256Seric case 'u': /* set default uid */ 85817474Seric DefUid = atoi(val); 85940973Sbostic setdefuser(); 8608256Seric break; 8618256Seric 8628269Seric case 'v': /* run in verbose mode */ 8639381Seric Verbose = atobool(val); 8648256Seric break; 8658256Seric 86614879Seric case 'x': /* load avg at which to auto-queue msgs */ 86714879Seric QueueLA = atoi(val); 86814879Seric break; 86914879Seric 87014879Seric case 'X': /* load avg at which to auto-reject connections */ 87114879Seric RefuseLA = atoi(val); 87214879Seric break; 87314879Seric 87424981Seric case 'y': /* work recipient factor */ 87524981Seric WkRecipFact = atoi(val); 87624981Seric break; 87724981Seric 87824981Seric case 'Y': /* fork jobs during queue runs */ 87924952Seric ForkQueueRuns = atobool(val); 88024952Seric break; 88124952Seric 88224981Seric case 'z': /* work message class factor */ 88324981Seric WkClassFact = atoi(val); 88424981Seric break; 88524981Seric 88624981Seric case 'Z': /* work time factor */ 88724981Seric WkTimeFact = atoi(val); 88824981Seric break; 88924981Seric 8908256Seric default: 8918256Seric break; 8928256Seric } 89316878Seric if (sticky) 89416878Seric setbitn(opt, StickyOpt); 8959188Seric return; 8968256Seric } 89710687Seric /* 89810687Seric ** SETCLASS -- set a word into a class 89910687Seric ** 90010687Seric ** Parameters: 90110687Seric ** class -- the class to put the word in. 90210687Seric ** word -- the word to enter 90310687Seric ** 90410687Seric ** Returns: 90510687Seric ** none. 90610687Seric ** 90710687Seric ** Side Effects: 90810687Seric ** puts the word into the symbol table. 90910687Seric */ 91010687Seric 91110687Seric setclass(class, word) 91210687Seric int class; 91310687Seric char *word; 91410687Seric { 91510687Seric register STAB *s; 91610687Seric 91710687Seric s = stab(word, ST_CLASS, ST_ENTER); 91810687Seric setbitn(class, s->s_class); 91910687Seric } 920