122709Sdist /* 233731Sbostic * Copyright (c) 1988 Regents of the University of California. 333731Sbostic * All rights reserved. 433731Sbostic * 533731Sbostic * Redistribution and use in source and binary forms are permitted 633731Sbostic * provided that this notice is preserved and that due credit is given 733731Sbostic * to the University of California at Berkeley. The name of the University 833731Sbostic * may not be used to endorse or promote products derived from this 933731Sbostic * software without specific prior written permission. This software 1033731Sbostic * is provided ``as is'' without express or implied warranty. 1133731Sbostic * 1233731Sbostic * Sendmail 1333731Sbostic * Copyright (c) 1983 Eric P. Allman 1433731Sbostic * Berkeley, California 1533731Sbostic */ 1622709Sdist 1722709Sdist #ifndef lint 18*33936Sbostic static char sccsid[] = "@(#)readcf.c 5.12 (Berkeley) 04/01/88"; 1933731Sbostic #endif /* not lint */ 2022709Sdist 213313Seric # include "sendmail.h" 223308Seric 233308Seric /* 243308Seric ** READCF -- read control file. 253308Seric ** 263308Seric ** This routine reads the control file and builds the internal 273308Seric ** form. 283308Seric ** 294432Seric ** The file is formatted as a sequence of lines, each taken 304432Seric ** atomically. The first character of each line describes how 314432Seric ** the line is to be interpreted. The lines are: 324432Seric ** Dxval Define macro x to have value val. 334432Seric ** Cxword Put word into class x. 344432Seric ** Fxfile [fmt] Read file for lines to put into 354432Seric ** class x. Use scanf string 'fmt' 364432Seric ** or "%s" if not present. Fmt should 374432Seric ** only produce one string-valued result. 384432Seric ** Hname: value Define header with field-name 'name' 394432Seric ** and value as specified; this will be 404432Seric ** macro expanded immediately before 414432Seric ** use. 424432Seric ** Sn Use rewriting set n. 434432Seric ** Rlhs rhs Rewrite addresses that match lhs to 444432Seric ** be rhs. 4524944Seric ** Mn arg=val... Define mailer. n is the internal name. 4624944Seric ** Args specify mailer parameters. 478252Seric ** Oxvalue Set option x to value. 488252Seric ** Pname=value Set precedence name to value. 494432Seric ** 503308Seric ** Parameters: 513308Seric ** cfname -- control file name. 523308Seric ** 533308Seric ** Returns: 543308Seric ** none. 553308Seric ** 563308Seric ** Side Effects: 573308Seric ** Builds several internal tables. 583308Seric */ 593308Seric 6021066Seric readcf(cfname) 613308Seric char *cfname; 623308Seric { 633308Seric FILE *cf; 648547Seric int ruleset = 0; 658547Seric char *q; 668547Seric char **pv; 679350Seric struct rewrite *rwp = NULL; 683308Seric char buf[MAXLINE]; 693308Seric register char *p; 703308Seric extern char **prescan(); 713308Seric extern char **copyplist(); 725909Seric char exbuf[MAXLINE]; 7316915Seric char pvpbuf[PSBUFSIZE]; 749350Seric extern char *fgetfolded(); 7510709Seric extern char *munchstring(); 763308Seric 773308Seric cf = fopen(cfname, "r"); 783308Seric if (cf == NULL) 793308Seric { 803308Seric syserr("cannot open %s", cfname); 813308Seric exit(EX_OSFILE); 823308Seric } 833308Seric 849381Seric FileName = cfname; 858056Seric LineNumber = 0; 867854Seric while (fgetfolded(buf, sizeof buf, cf) != NULL) 873308Seric { 8816157Seric /* map $ into \001 (ASCII SOH) for macro expansion */ 8916157Seric for (p = buf; *p != '\0'; p++) 9016157Seric { 9116157Seric if (*p != '$') 9216157Seric continue; 9316157Seric 9416157Seric if (p[1] == '$') 9516157Seric { 9616157Seric /* actual dollar sign.... */ 9723111Seric (void) strcpy(p, p + 1); 9816157Seric continue; 9916157Seric } 10016157Seric 10116157Seric /* convert to macro expansion character */ 10216157Seric *p = '\001'; 10316157Seric } 10416157Seric 10516157Seric /* interpret this line */ 1063308Seric switch (buf[0]) 1073308Seric { 1083308Seric case '\0': 1093308Seric case '#': /* comment */ 1103308Seric break; 1113308Seric 1123308Seric case 'R': /* rewriting rule */ 1133308Seric for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 1143308Seric continue; 1153308Seric 1163308Seric if (*p == '\0') 1175909Seric { 1189381Seric syserr("invalid rewrite line \"%s\"", buf); 1195909Seric break; 1205909Seric } 1215909Seric 1225909Seric /* allocate space for the rule header */ 1235909Seric if (rwp == NULL) 1245909Seric { 1255909Seric RewriteRules[ruleset] = rwp = 1265909Seric (struct rewrite *) xalloc(sizeof *rwp); 1275909Seric } 1283308Seric else 1293308Seric { 1305909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 1315909Seric rwp = rwp->r_next; 1325909Seric } 1335909Seric rwp->r_next = NULL; 1343308Seric 1355909Seric /* expand and save the LHS */ 1365909Seric *p = '\0'; 1376991Seric expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv); 13816915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 1395909Seric if (rwp->r_lhs != NULL) 1405909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 1415909Seric 1425909Seric /* expand and save the RHS */ 1435909Seric while (*++p == '\t') 1445909Seric continue; 1457231Seric q = p; 1467231Seric while (*p != '\0' && *p != '\t') 1477231Seric p++; 1487231Seric *p = '\0'; 1497231Seric expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv); 15016915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 1515909Seric if (rwp->r_rhs != NULL) 1525909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 1533308Seric break; 1543308Seric 1554072Seric case 'S': /* select rewriting set */ 1564072Seric ruleset = atoi(&buf[1]); 1578056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 1588056Seric { 1599381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 1608056Seric ruleset = 0; 1618056Seric } 1624072Seric rwp = NULL; 1634072Seric break; 1644072Seric 1653308Seric case 'D': /* macro definition */ 16610709Seric define(buf[1], newstr(munchstring(&buf[2])), CurEnv); 1673308Seric break; 1683308Seric 1693387Seric case 'H': /* required header line */ 1704088Seric (void) chompheader(&buf[1], TRUE); 1713387Seric break; 1723387Seric 1734061Seric case 'C': /* word class */ 1744432Seric case 'F': /* word class from file */ 1754432Seric /* read list of words from argument or file */ 1764432Seric if (buf[0] == 'F') 1774432Seric { 1784432Seric /* read from file */ 1794432Seric for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 1804432Seric continue; 1814432Seric if (*p == '\0') 1824432Seric p = "%s"; 1834432Seric else 1844432Seric { 1854432Seric *p = '\0'; 1864432Seric while (isspace(*++p)) 1874432Seric continue; 1884432Seric } 18910687Seric fileclass(buf[1], &buf[2], p); 1904432Seric break; 1914432Seric } 1924061Seric 1934432Seric /* scan the list of words and set class for all */ 1944061Seric for (p = &buf[2]; *p != '\0'; ) 1954061Seric { 1964061Seric register char *wd; 1974061Seric char delim; 1984061Seric 1994061Seric while (*p != '\0' && isspace(*p)) 2004061Seric p++; 2014061Seric wd = p; 2024061Seric while (*p != '\0' && !isspace(*p)) 2034061Seric p++; 2044061Seric delim = *p; 2054061Seric *p = '\0'; 2064061Seric if (wd[0] != '\0') 20710687Seric setclass(buf[1], wd); 2084061Seric *p = delim; 2094061Seric } 2104061Seric break; 2114061Seric 2124096Seric case 'M': /* define mailer */ 21321066Seric makemailer(&buf[1]); 2144096Seric break; 2154096Seric 2168252Seric case 'O': /* set option */ 21721755Seric setoption(buf[1], &buf[2], TRUE, FALSE); 2188252Seric break; 2198252Seric 2208252Seric case 'P': /* set precedence */ 2218252Seric if (NumPriorities >= MAXPRIORITIES) 2228252Seric { 2238547Seric toomany('P', MAXPRIORITIES); 2248252Seric break; 2258252Seric } 2269381Seric for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 2278252Seric continue; 2288252Seric if (*p == '\0') 2298252Seric goto badline; 2308252Seric *p = '\0'; 2318252Seric Priorities[NumPriorities].pri_name = newstr(&buf[1]); 2328252Seric Priorities[NumPriorities].pri_val = atoi(++p); 2338252Seric NumPriorities++; 2348252Seric break; 2358252Seric 2368547Seric case 'T': /* trusted user(s) */ 2378547Seric p = &buf[1]; 2388547Seric while (*p != '\0') 2398547Seric { 2408547Seric while (isspace(*p)) 2418547Seric p++; 2428547Seric q = p; 2438547Seric while (*p != '\0' && !isspace(*p)) 2448547Seric p++; 2458547Seric if (*p != '\0') 2468547Seric *p++ = '\0'; 2478547Seric if (*q == '\0') 2488547Seric continue; 2498547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 2508547Seric continue; 2518547Seric if (pv >= &TrustedUsers[MAXTRUST]) 2528547Seric { 2538547Seric toomany('T', MAXTRUST); 2548547Seric break; 2558547Seric } 2568547Seric *pv = newstr(q); 2578547Seric } 2588547Seric break; 2598547Seric 2603308Seric default: 2614061Seric badline: 2629381Seric syserr("unknown control line \"%s\"", buf); 2633308Seric } 2643308Seric } 2659381Seric FileName = NULL; 2664096Seric } 2674096Seric /* 2688547Seric ** TOOMANY -- signal too many of some option 2698547Seric ** 2708547Seric ** Parameters: 2718547Seric ** id -- the id of the error line 2728547Seric ** maxcnt -- the maximum possible values 2738547Seric ** 2748547Seric ** Returns: 2758547Seric ** none. 2768547Seric ** 2778547Seric ** Side Effects: 2788547Seric ** gives a syserr. 2798547Seric */ 2808547Seric 2818547Seric toomany(id, maxcnt) 2828547Seric char id; 2838547Seric int maxcnt; 2848547Seric { 2859381Seric syserr("too many %c lines, %d max", id, maxcnt); 2868547Seric } 2878547Seric /* 2884432Seric ** FILECLASS -- read members of a class from a file 2894432Seric ** 2904432Seric ** Parameters: 2914432Seric ** class -- class to define. 2924432Seric ** filename -- name of file to read. 2934432Seric ** fmt -- scanf string to use for match. 2944432Seric ** 2954432Seric ** Returns: 2964432Seric ** none 2974432Seric ** 2984432Seric ** Side Effects: 2994432Seric ** 3004432Seric ** puts all lines in filename that match a scanf into 3014432Seric ** the named class. 3024432Seric */ 3034432Seric 3044432Seric fileclass(class, filename, fmt) 3054432Seric int class; 3064432Seric char *filename; 3074432Seric char *fmt; 3084432Seric { 30925808Seric FILE *f; 3104432Seric char buf[MAXLINE]; 3114432Seric 3124432Seric f = fopen(filename, "r"); 3134432Seric if (f == NULL) 3144432Seric { 3154432Seric syserr("cannot open %s", filename); 3164432Seric return; 3174432Seric } 3184432Seric 3194432Seric while (fgets(buf, sizeof buf, f) != NULL) 3204432Seric { 3214432Seric register STAB *s; 32225808Seric register char *p; 32325808Seric # ifdef SCANF 3244432Seric char wordbuf[MAXNAME+1]; 3254432Seric 3264432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3274432Seric continue; 32825808Seric p = wordbuf; 32925808Seric # else SCANF 33025808Seric p = buf; 33125808Seric # endif SCANF 33225808Seric 33325808Seric /* 33425808Seric ** Break up the match into words. 33525808Seric */ 33625808Seric 33725808Seric while (*p != '\0') 33825808Seric { 33925808Seric register char *q; 34025808Seric 34125808Seric /* strip leading spaces */ 34225808Seric while (isspace(*p)) 34325808Seric p++; 34425808Seric if (*p == '\0') 34525808Seric break; 34625808Seric 34725808Seric /* find the end of the word */ 34825808Seric q = p; 34925808Seric while (*p != '\0' && !isspace(*p)) 35025808Seric p++; 35125808Seric if (*p != '\0') 35225808Seric *p++ = '\0'; 35325808Seric 35425808Seric /* enter the word in the symbol table */ 35525808Seric s = stab(q, ST_CLASS, ST_ENTER); 35625808Seric setbitn(class, s->s_class); 35725808Seric } 3584432Seric } 3594432Seric 3604627Seric (void) fclose(f); 3614432Seric } 3624432Seric /* 3634096Seric ** MAKEMAILER -- define a new mailer. 3644096Seric ** 3654096Seric ** Parameters: 36610327Seric ** line -- description of mailer. This is in labeled 36710327Seric ** fields. The fields are: 36810327Seric ** P -- the path to the mailer 36910327Seric ** F -- the flags associated with the mailer 37010327Seric ** A -- the argv for this mailer 37110327Seric ** S -- the sender rewriting set 37210327Seric ** R -- the recipient rewriting set 37310327Seric ** E -- the eol string 37410327Seric ** The first word is the canonical name of the mailer. 3754096Seric ** 3764096Seric ** Returns: 3774096Seric ** none. 3784096Seric ** 3794096Seric ** Side Effects: 3804096Seric ** enters the mailer into the mailer table. 3814096Seric */ 3823308Seric 38321066Seric makemailer(line) 3844096Seric char *line; 3854096Seric { 3864096Seric register char *p; 3878067Seric register struct mailer *m; 3888067Seric register STAB *s; 3898067Seric int i; 39010327Seric char fcode; 3914096Seric extern int NextMailer; 39210327Seric extern char **makeargv(); 39310327Seric extern char *munchstring(); 39410327Seric extern char *DelimChar; 39510701Seric extern long atol(); 3964096Seric 39710327Seric /* allocate a mailer and set up defaults */ 39810327Seric m = (struct mailer *) xalloc(sizeof *m); 39910327Seric bzero((char *) m, sizeof *m); 40010327Seric m->m_mno = NextMailer; 40110327Seric m->m_eol = "\n"; 40210327Seric 40310327Seric /* collect the mailer name */ 40410327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 40510327Seric continue; 40610327Seric if (*p != '\0') 40710327Seric *p++ = '\0'; 40810327Seric m->m_name = newstr(line); 40910327Seric 41010327Seric /* now scan through and assign info from the fields */ 41110327Seric while (*p != '\0') 41210327Seric { 41310327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 41410327Seric p++; 41510327Seric 41610327Seric /* p now points to field code */ 41710327Seric fcode = *p; 41810327Seric while (*p != '\0' && *p != '=' && *p != ',') 41910327Seric p++; 42010327Seric if (*p++ != '=') 42110327Seric { 42210327Seric syserr("`=' expected"); 42310327Seric return; 42410327Seric } 42510327Seric while (isspace(*p)) 42610327Seric p++; 42710327Seric 42810327Seric /* p now points to the field body */ 42910327Seric p = munchstring(p); 43010327Seric 43110327Seric /* install the field into the mailer struct */ 43210327Seric switch (fcode) 43310327Seric { 43410327Seric case 'P': /* pathname */ 43510327Seric m->m_mailer = newstr(p); 43610327Seric break; 43710327Seric 43810327Seric case 'F': /* flags */ 43910687Seric for (; *p != '\0'; p++) 44010687Seric setbitn(*p, m->m_flags); 44110327Seric break; 44210327Seric 44310327Seric case 'S': /* sender rewriting ruleset */ 44410327Seric case 'R': /* recipient rewriting ruleset */ 44510327Seric i = atoi(p); 44610327Seric if (i < 0 || i >= MAXRWSETS) 44710327Seric { 44810327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 44910327Seric return; 45010327Seric } 45110327Seric if (fcode == 'S') 45210327Seric m->m_s_rwset = i; 45310327Seric else 45410327Seric m->m_r_rwset = i; 45510327Seric break; 45610327Seric 45710327Seric case 'E': /* end of line string */ 45810327Seric m->m_eol = newstr(p); 45910327Seric break; 46010327Seric 46110327Seric case 'A': /* argument vector */ 46210327Seric m->m_argv = makeargv(p); 46310327Seric break; 46410701Seric 46510701Seric case 'M': /* maximum message size */ 46610701Seric m->m_maxsize = atol(p); 46710701Seric break; 46810327Seric } 46910327Seric 47010327Seric p = DelimChar; 47110327Seric } 47210327Seric 47310327Seric /* now store the mailer away */ 4744096Seric if (NextMailer >= MAXMAILERS) 4754096Seric { 4769381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4774096Seric return; 4784096Seric } 47910327Seric Mailer[NextMailer++] = m; 48010327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 48110327Seric s->s_mailer = m; 48210327Seric } 48310327Seric /* 48410327Seric ** MUNCHSTRING -- translate a string into internal form. 48510327Seric ** 48610327Seric ** Parameters: 48710327Seric ** p -- the string to munch. 48810327Seric ** 48910327Seric ** Returns: 49010327Seric ** the munched string. 49110327Seric ** 49210327Seric ** Side Effects: 49310327Seric ** Sets "DelimChar" to point to the string that caused us 49410327Seric ** to stop. 49510327Seric */ 4964096Seric 49710327Seric char * 49810327Seric munchstring(p) 49910327Seric register char *p; 50010327Seric { 50110327Seric register char *q; 50210327Seric bool backslash = FALSE; 50310327Seric bool quotemode = FALSE; 50410327Seric static char buf[MAXLINE]; 50510327Seric extern char *DelimChar; 5064096Seric 50710327Seric for (q = buf; *p != '\0'; p++) 5084096Seric { 50910327Seric if (backslash) 51010327Seric { 51110327Seric /* everything is roughly literal */ 51210357Seric backslash = FALSE; 51310327Seric switch (*p) 51410327Seric { 51510327Seric case 'r': /* carriage return */ 51610327Seric *q++ = '\r'; 51710327Seric continue; 51810327Seric 51910327Seric case 'n': /* newline */ 52010327Seric *q++ = '\n'; 52110327Seric continue; 52210327Seric 52310327Seric case 'f': /* form feed */ 52410327Seric *q++ = '\f'; 52510327Seric continue; 52610327Seric 52710327Seric case 'b': /* backspace */ 52810327Seric *q++ = '\b'; 52910327Seric continue; 53010327Seric } 53110327Seric *q++ = *p; 53210327Seric } 53310327Seric else 53410327Seric { 53510327Seric if (*p == '\\') 53610327Seric backslash = TRUE; 53710327Seric else if (*p == '"') 53810327Seric quotemode = !quotemode; 53910327Seric else if (quotemode || *p != ',') 54010327Seric *q++ = *p; 54110327Seric else 54210327Seric break; 54310327Seric } 5444096Seric } 5454096Seric 54610327Seric DelimChar = p; 54710327Seric *q++ = '\0'; 54810327Seric return (buf); 54910327Seric } 55010327Seric /* 55110327Seric ** MAKEARGV -- break up a string into words 55210327Seric ** 55310327Seric ** Parameters: 55410327Seric ** p -- the string to break up. 55510327Seric ** 55610327Seric ** Returns: 55710327Seric ** a char **argv (dynamically allocated) 55810327Seric ** 55910327Seric ** Side Effects: 56010327Seric ** munges p. 56110327Seric */ 5624096Seric 56310327Seric char ** 56410327Seric makeargv(p) 56510327Seric register char *p; 56610327Seric { 56710327Seric char *q; 56810327Seric int i; 56910327Seric char **avp; 57010327Seric char *argv[MAXPV + 1]; 57110327Seric 57210327Seric /* take apart the words */ 57310327Seric i = 0; 57410327Seric while (*p != '\0' && i < MAXPV) 5754096Seric { 57610327Seric q = p; 57710327Seric while (*p != '\0' && !isspace(*p)) 57810327Seric p++; 57910327Seric while (isspace(*p)) 58010327Seric *p++ = '\0'; 58110327Seric argv[i++] = newstr(q); 5824096Seric } 58310327Seric argv[i++] = NULL; 5844096Seric 58510327Seric /* now make a copy of the argv */ 58610327Seric avp = (char **) xalloc(sizeof *avp * i); 58716893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 58810327Seric 58910327Seric return (avp); 5903308Seric } 5913308Seric /* 5923308Seric ** PRINTRULES -- print rewrite rules (for debugging) 5933308Seric ** 5943308Seric ** Parameters: 5953308Seric ** none. 5963308Seric ** 5973308Seric ** Returns: 5983308Seric ** none. 5993308Seric ** 6003308Seric ** Side Effects: 6013308Seric ** prints rewrite rules. 6023308Seric */ 6033308Seric 6044319Seric # ifdef DEBUG 6054319Seric 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 6274319Seric # endif DEBUG 6284096Seric /* 6298256Seric ** SETOPTION -- set global processing option 6308256Seric ** 6318256Seric ** Parameters: 6328256Seric ** opt -- option name. 6338256Seric ** val -- option value (as a text string). 63421755Seric ** safe -- set if this came from a configuration file. 63521755Seric ** Some options (if set from the command line) will 63621755Seric ** reset the user id to avoid security problems. 6378269Seric ** sticky -- if set, don't let other setoptions override 6388269Seric ** this value. 6398256Seric ** 6408256Seric ** Returns: 6418256Seric ** none. 6428256Seric ** 6438256Seric ** Side Effects: 6448256Seric ** Sets options as implied by the arguments. 6458256Seric */ 6468256Seric 64710687Seric static BITMAP StickyOpt; /* set if option is stuck */ 64825700Seric extern char *NetName; /* name of home (local) network */ 64925700Seric # ifdef SMTP 65025700Seric # ifdef WIZ 65110687Seric extern char *WizWord; /* the stored wizard password */ 65225700Seric # endif WIZ 65325700Seric # endif SMTP 6548269Seric 65521755Seric setoption(opt, val, safe, sticky) 6568256Seric char opt; 6578256Seric char *val; 65821755Seric bool safe; 6598269Seric bool sticky; 6608256Seric { 6618265Seric extern bool atobool(); 66212633Seric extern time_t convtime(); 66314879Seric extern int QueueLA; 66414879Seric extern int RefuseLA; 66517474Seric extern bool trusteduser(); 66617474Seric extern char *username(); 6678256Seric 6688256Seric # ifdef DEBUG 6698256Seric if (tTd(37, 1)) 6709341Seric printf("setoption %c=%s", opt, val); 6718256Seric # endif DEBUG 6728256Seric 6738256Seric /* 6748269Seric ** See if this option is preset for us. 6758256Seric */ 6768256Seric 67710687Seric if (bitnset(opt, StickyOpt)) 6788269Seric { 6798269Seric # ifdef DEBUG 6809341Seric if (tTd(37, 1)) 6819341Seric printf(" (ignored)\n"); 6828269Seric # endif DEBUG 6838269Seric return; 6848269Seric } 6858269Seric 68621755Seric /* 68721755Seric ** Check to see if this option can be specified by this user. 68821755Seric */ 68921755Seric 69025567Seric if (!safe && getruid() == 0) 69121755Seric safe = TRUE; 69221755Seric if (!safe && index("deiLmorsv", opt) == NULL) 69321755Seric { 69421755Seric # ifdef DEBUG 69521755Seric if (tTd(37, 1)) 69621755Seric printf(" (unsafe)"); 69721755Seric # endif DEBUG 69821755Seric if (getruid() != geteuid()) 69921755Seric { 70021755Seric printf("(Resetting uid)\n"); 70123111Seric (void) setgid(getgid()); 70223111Seric (void) setuid(getuid()); 70321755Seric } 70421755Seric } 70517985Seric #ifdef DEBUG 70621755Seric else if (tTd(37, 1)) 70717985Seric printf("\n"); 70817985Seric #endif DEBUG 7098269Seric 7108256Seric switch (opt) 7118256Seric { 7128256Seric case 'A': /* set default alias file */ 7139381Seric if (val[0] == '\0') 7148269Seric AliasFile = "aliases"; 7159381Seric else 7169381Seric AliasFile = newstr(val); 7178256Seric break; 7188256Seric 71917474Seric case 'a': /* look N minutes for "@:@" in alias file */ 72017474Seric if (val[0] == '\0') 72117474Seric SafeAlias = 5; 72217474Seric else 72317474Seric SafeAlias = atoi(val); 72417474Seric break; 72517474Seric 72616843Seric case 'B': /* substitution for blank character */ 72716843Seric SpaceSub = val[0]; 72816843Seric if (SpaceSub == '\0') 72916843Seric SpaceSub = ' '; 73016843Seric break; 73116843Seric 7329284Seric case 'c': /* don't connect to "expensive" mailers */ 7339381Seric NoConnect = atobool(val); 7349284Seric break; 7359284Seric 73624944Seric case 'C': /* checkpoint after N connections */ 73724944Seric CheckPointLimit = atoi(val); 73824944Seric break; 73924944Seric 7409284Seric case 'd': /* delivery mode */ 7419284Seric switch (*val) 7428269Seric { 7439284Seric case '\0': 7449284Seric SendMode = SM_DELIVER; 7458269Seric break; 7468269Seric 74710755Seric case SM_QUEUE: /* queue only */ 74810755Seric #ifndef QUEUE 74910755Seric syserr("need QUEUE to set -odqueue"); 75010755Seric #endif QUEUE 75110755Seric /* fall through..... */ 75210755Seric 7539284Seric case SM_DELIVER: /* do everything */ 7549284Seric case SM_FORK: /* fork after verification */ 7559284Seric SendMode = *val; 7568269Seric break; 7578269Seric 7588269Seric default: 7599284Seric syserr("Unknown delivery mode %c", *val); 7608269Seric exit(EX_USAGE); 7618269Seric } 7628269Seric break; 7638269Seric 7649146Seric case 'D': /* rebuild alias database as needed */ 7659381Seric AutoRebuild = atobool(val); 7669146Seric break; 7679146Seric 7688269Seric case 'e': /* set error processing mode */ 7698269Seric switch (*val) 7708269Seric { 7719381Seric case EM_QUIET: /* be silent about it */ 7729381Seric case EM_MAIL: /* mail back */ 7739381Seric case EM_BERKNET: /* do berknet error processing */ 7749381Seric case EM_WRITE: /* write back (or mail) */ 7758269Seric HoldErrs = TRUE; 7769381Seric /* fall through... */ 7778269Seric 7789381Seric case EM_PRINT: /* print errors normally (default) */ 7799381Seric ErrorMode = *val; 7808269Seric break; 7818269Seric } 7828269Seric break; 7838269Seric 7849049Seric case 'F': /* file mode */ 78517975Seric FileMode = atooct(val) & 0777; 7869049Seric break; 7879049Seric 7888269Seric case 'f': /* save Unix-style From lines on front */ 7899381Seric SaveFrom = atobool(val); 7908269Seric break; 7918269Seric 7928256Seric case 'g': /* default gid */ 79317474Seric DefGid = atoi(val); 7948256Seric break; 7958256Seric 7968256Seric case 'H': /* help file */ 7979381Seric if (val[0] == '\0') 7988269Seric HelpFile = "sendmail.hf"; 7999381Seric else 8009381Seric HelpFile = newstr(val); 8018256Seric break; 8028256Seric 8038269Seric case 'i': /* ignore dot lines in message */ 8049381Seric IgnrDot = atobool(val); 8058269Seric break; 8068269Seric 8078256Seric case 'L': /* log level */ 8089381Seric LogLevel = atoi(val); 8098256Seric break; 8108256Seric 8118269Seric case 'M': /* define macro */ 8129381Seric define(val[0], newstr(&val[1]), CurEnv); 81316878Seric sticky = FALSE; 8148269Seric break; 8158269Seric 8168269Seric case 'm': /* send to me too */ 8179381Seric MeToo = atobool(val); 8188269Seric break; 8198269Seric 82025820Seric case 'n': /* validate RHS in newaliases */ 82125820Seric CheckAliases = atobool(val); 82225820Seric break; 82325820Seric 82416143Seric # ifdef DAEMON 82516143Seric case 'N': /* home (local?) network name */ 82616143Seric NetName = newstr(val); 82716143Seric break; 82816143Seric # endif DAEMON 82916143Seric 8308269Seric case 'o': /* assume old style headers */ 8319381Seric if (atobool(val)) 8329341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8339341Seric else 8349341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8358269Seric break; 8368269Seric 83724944Seric case 'P': /* postmaster copy address for returned mail */ 83824944Seric PostMasterCopy = newstr(val); 83924944Seric break; 84024944Seric 84124944Seric case 'q': /* slope of queue only function */ 84224944Seric QueueFactor = atoi(val); 84324944Seric break; 84424944Seric 8458256Seric case 'Q': /* queue directory */ 8469381Seric if (val[0] == '\0') 8478269Seric QueueDir = "mqueue"; 8489381Seric else 8499381Seric QueueDir = newstr(val); 8508256Seric break; 8518256Seric 8528256Seric case 'r': /* read timeout */ 8539381Seric ReadTimeout = convtime(val); 8548256Seric break; 8558256Seric 8568256Seric case 'S': /* status file */ 8579381Seric if (val[0] == '\0') 8588269Seric StatFile = "sendmail.st"; 8599381Seric else 8609381Seric StatFile = newstr(val); 8618256Seric break; 8628256Seric 8638265Seric case 's': /* be super safe, even if expensive */ 8649381Seric SuperSafe = atobool(val); 8658256Seric break; 8668256Seric 8678256Seric case 'T': /* queue timeout */ 8689381Seric TimeOut = convtime(val); 869*33936Sbostic /*FALLTHROUGH*/ 8708256Seric 8718265Seric case 't': /* time zone name */ 8728265Seric break; 8738265Seric 8748256Seric case 'u': /* set default uid */ 87517474Seric DefUid = atoi(val); 8768256Seric break; 8778256Seric 8788269Seric case 'v': /* run in verbose mode */ 8799381Seric Verbose = atobool(val); 8808256Seric break; 8818256Seric 88225700Seric # ifdef SMTP 88325700Seric # ifdef WIZ 8848544Seric case 'W': /* set the wizards password */ 88517474Seric WizWord = newstr(val); 8868544Seric break; 88725700Seric # endif WIZ 88825700Seric # endif SMTP 8898544Seric 89014879Seric case 'x': /* load avg at which to auto-queue msgs */ 89114879Seric QueueLA = atoi(val); 89214879Seric break; 89314879Seric 89414879Seric case 'X': /* load avg at which to auto-reject connections */ 89514879Seric RefuseLA = atoi(val); 89614879Seric break; 89714879Seric 89824981Seric case 'y': /* work recipient factor */ 89924981Seric WkRecipFact = atoi(val); 90024981Seric break; 90124981Seric 90224981Seric case 'Y': /* fork jobs during queue runs */ 90324952Seric ForkQueueRuns = atobool(val); 90424952Seric break; 90524952Seric 90624981Seric case 'z': /* work message class factor */ 90724981Seric WkClassFact = atoi(val); 90824981Seric break; 90924981Seric 91024981Seric case 'Z': /* work time factor */ 91124981Seric WkTimeFact = atoi(val); 91224981Seric break; 91324981Seric 9148256Seric default: 9158256Seric break; 9168256Seric } 91716878Seric if (sticky) 91816878Seric setbitn(opt, StickyOpt); 9199188Seric return; 9208256Seric } 92110687Seric /* 92210687Seric ** SETCLASS -- set a word into a class 92310687Seric ** 92410687Seric ** Parameters: 92510687Seric ** class -- the class to put the word in. 92610687Seric ** word -- the word to enter 92710687Seric ** 92810687Seric ** Returns: 92910687Seric ** none. 93010687Seric ** 93110687Seric ** Side Effects: 93210687Seric ** puts the word into the symbol table. 93310687Seric */ 93410687Seric 93510687Seric setclass(class, word) 93610687Seric int class; 93710687Seric char *word; 93810687Seric { 93910687Seric register STAB *s; 94010687Seric 94110687Seric s = stab(word, ST_CLASS, ST_ENTER); 94210687Seric setbitn(class, s->s_class); 94310687Seric } 944