122709Sdist /* 222709Sdist ** Sendmail 322709Sdist ** Copyright (c) 1983 Eric P. Allman 422709Sdist ** Berkeley, California 522709Sdist ** 622709Sdist ** Copyright (c) 1983 Regents of the University of California. 722709Sdist ** All rights reserved. The Berkeley software License Agreement 822709Sdist ** specifies the terms and conditions for redistribution. 922709Sdist */ 1022709Sdist 1122709Sdist #ifndef lint 12*25808Seric static char SccsId[] = "@(#)readcf.c 5.9 (Berkeley) 01/10/86"; 1322709Sdist #endif not lint 1422709Sdist 153313Seric # include "sendmail.h" 163308Seric 173308Seric /* 183308Seric ** READCF -- read control file. 193308Seric ** 203308Seric ** This routine reads the control file and builds the internal 213308Seric ** form. 223308Seric ** 234432Seric ** The file is formatted as a sequence of lines, each taken 244432Seric ** atomically. The first character of each line describes how 254432Seric ** the line is to be interpreted. The lines are: 264432Seric ** Dxval Define macro x to have value val. 274432Seric ** Cxword Put word into class x. 284432Seric ** Fxfile [fmt] Read file for lines to put into 294432Seric ** class x. Use scanf string 'fmt' 304432Seric ** or "%s" if not present. Fmt should 314432Seric ** only produce one string-valued result. 324432Seric ** Hname: value Define header with field-name 'name' 334432Seric ** and value as specified; this will be 344432Seric ** macro expanded immediately before 354432Seric ** use. 364432Seric ** Sn Use rewriting set n. 374432Seric ** Rlhs rhs Rewrite addresses that match lhs to 384432Seric ** be rhs. 3924944Seric ** Mn arg=val... Define mailer. n is the internal name. 4024944Seric ** Args specify mailer parameters. 418252Seric ** Oxvalue Set option x to value. 428252Seric ** Pname=value Set precedence name to value. 434432Seric ** 443308Seric ** Parameters: 453308Seric ** cfname -- control file name. 463308Seric ** 473308Seric ** Returns: 483308Seric ** none. 493308Seric ** 503308Seric ** Side Effects: 513308Seric ** Builds several internal tables. 523308Seric */ 533308Seric 5421066Seric readcf(cfname) 553308Seric char *cfname; 563308Seric { 573308Seric FILE *cf; 588547Seric int ruleset = 0; 598547Seric char *q; 608547Seric char **pv; 619350Seric struct rewrite *rwp = NULL; 623308Seric char buf[MAXLINE]; 633308Seric register char *p; 643308Seric extern char **prescan(); 653308Seric extern char **copyplist(); 665909Seric char exbuf[MAXLINE]; 6716915Seric char pvpbuf[PSBUFSIZE]; 689350Seric extern char *fgetfolded(); 6910709Seric extern char *munchstring(); 703308Seric 713308Seric cf = fopen(cfname, "r"); 723308Seric if (cf == NULL) 733308Seric { 743308Seric syserr("cannot open %s", cfname); 753308Seric exit(EX_OSFILE); 763308Seric } 773308Seric 789381Seric FileName = cfname; 798056Seric LineNumber = 0; 807854Seric while (fgetfolded(buf, sizeof buf, cf) != NULL) 813308Seric { 8216157Seric /* map $ into \001 (ASCII SOH) for macro expansion */ 8316157Seric for (p = buf; *p != '\0'; p++) 8416157Seric { 8516157Seric if (*p != '$') 8616157Seric continue; 8716157Seric 8816157Seric if (p[1] == '$') 8916157Seric { 9016157Seric /* actual dollar sign.... */ 9123111Seric (void) strcpy(p, p + 1); 9216157Seric continue; 9316157Seric } 9416157Seric 9516157Seric /* convert to macro expansion character */ 9616157Seric *p = '\001'; 9716157Seric } 9816157Seric 9916157Seric /* interpret this line */ 1003308Seric switch (buf[0]) 1013308Seric { 1023308Seric case '\0': 1033308Seric case '#': /* comment */ 1043308Seric break; 1053308Seric 1063308Seric case 'R': /* rewriting rule */ 1073308Seric for (p = &buf[1]; *p != '\0' && *p != '\t'; p++) 1083308Seric continue; 1093308Seric 1103308Seric if (*p == '\0') 1115909Seric { 1129381Seric syserr("invalid rewrite line \"%s\"", buf); 1135909Seric break; 1145909Seric } 1155909Seric 1165909Seric /* allocate space for the rule header */ 1175909Seric if (rwp == NULL) 1185909Seric { 1195909Seric RewriteRules[ruleset] = rwp = 1205909Seric (struct rewrite *) xalloc(sizeof *rwp); 1215909Seric } 1223308Seric else 1233308Seric { 1245909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 1255909Seric rwp = rwp->r_next; 1265909Seric } 1275909Seric rwp->r_next = NULL; 1283308Seric 1295909Seric /* expand and save the LHS */ 1305909Seric *p = '\0'; 1316991Seric expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv); 13216915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 1335909Seric if (rwp->r_lhs != NULL) 1345909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 1355909Seric 1365909Seric /* expand and save the RHS */ 1375909Seric while (*++p == '\t') 1385909Seric continue; 1397231Seric q = p; 1407231Seric while (*p != '\0' && *p != '\t') 1417231Seric p++; 1427231Seric *p = '\0'; 1437231Seric expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv); 14416915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 1455909Seric if (rwp->r_rhs != NULL) 1465909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 1473308Seric break; 1483308Seric 1494072Seric case 'S': /* select rewriting set */ 1504072Seric ruleset = atoi(&buf[1]); 1518056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 1528056Seric { 1539381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 1548056Seric ruleset = 0; 1558056Seric } 1564072Seric rwp = NULL; 1574072Seric break; 1584072Seric 1593308Seric case 'D': /* macro definition */ 16010709Seric define(buf[1], newstr(munchstring(&buf[2])), CurEnv); 1613308Seric break; 1623308Seric 1633387Seric case 'H': /* required header line */ 1644088Seric (void) chompheader(&buf[1], TRUE); 1653387Seric break; 1663387Seric 1674061Seric case 'C': /* word class */ 1684432Seric case 'F': /* word class from file */ 1694432Seric /* read list of words from argument or file */ 1704432Seric if (buf[0] == 'F') 1714432Seric { 1724432Seric /* read from file */ 1734432Seric for (p = &buf[2]; *p != '\0' && !isspace(*p); p++) 1744432Seric continue; 1754432Seric if (*p == '\0') 1764432Seric p = "%s"; 1774432Seric else 1784432Seric { 1794432Seric *p = '\0'; 1804432Seric while (isspace(*++p)) 1814432Seric continue; 1824432Seric } 18310687Seric fileclass(buf[1], &buf[2], p); 1844432Seric break; 1854432Seric } 1864061Seric 1874432Seric /* scan the list of words and set class for all */ 1884061Seric for (p = &buf[2]; *p != '\0'; ) 1894061Seric { 1904061Seric register char *wd; 1914061Seric char delim; 1924061Seric 1934061Seric while (*p != '\0' && isspace(*p)) 1944061Seric p++; 1954061Seric wd = p; 1964061Seric while (*p != '\0' && !isspace(*p)) 1974061Seric p++; 1984061Seric delim = *p; 1994061Seric *p = '\0'; 2004061Seric if (wd[0] != '\0') 20110687Seric setclass(buf[1], wd); 2024061Seric *p = delim; 2034061Seric } 2044061Seric break; 2054061Seric 2064096Seric case 'M': /* define mailer */ 20721066Seric makemailer(&buf[1]); 2084096Seric break; 2094096Seric 2108252Seric case 'O': /* set option */ 21121755Seric setoption(buf[1], &buf[2], TRUE, FALSE); 2128252Seric break; 2138252Seric 2148252Seric case 'P': /* set precedence */ 2158252Seric if (NumPriorities >= MAXPRIORITIES) 2168252Seric { 2178547Seric toomany('P', MAXPRIORITIES); 2188252Seric break; 2198252Seric } 2209381Seric for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 2218252Seric continue; 2228252Seric if (*p == '\0') 2238252Seric goto badline; 2248252Seric *p = '\0'; 2258252Seric Priorities[NumPriorities].pri_name = newstr(&buf[1]); 2268252Seric Priorities[NumPriorities].pri_val = atoi(++p); 2278252Seric NumPriorities++; 2288252Seric break; 2298252Seric 2308547Seric case 'T': /* trusted user(s) */ 2318547Seric p = &buf[1]; 2328547Seric while (*p != '\0') 2338547Seric { 2348547Seric while (isspace(*p)) 2358547Seric p++; 2368547Seric q = p; 2378547Seric while (*p != '\0' && !isspace(*p)) 2388547Seric p++; 2398547Seric if (*p != '\0') 2408547Seric *p++ = '\0'; 2418547Seric if (*q == '\0') 2428547Seric continue; 2438547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 2448547Seric continue; 2458547Seric if (pv >= &TrustedUsers[MAXTRUST]) 2468547Seric { 2478547Seric toomany('T', MAXTRUST); 2488547Seric break; 2498547Seric } 2508547Seric *pv = newstr(q); 2518547Seric } 2528547Seric break; 2538547Seric 2543308Seric default: 2554061Seric badline: 2569381Seric syserr("unknown control line \"%s\"", buf); 2573308Seric } 2583308Seric } 2599381Seric FileName = NULL; 2604096Seric } 2614096Seric /* 2628547Seric ** TOOMANY -- signal too many of some option 2638547Seric ** 2648547Seric ** Parameters: 2658547Seric ** id -- the id of the error line 2668547Seric ** maxcnt -- the maximum possible values 2678547Seric ** 2688547Seric ** Returns: 2698547Seric ** none. 2708547Seric ** 2718547Seric ** Side Effects: 2728547Seric ** gives a syserr. 2738547Seric */ 2748547Seric 2758547Seric toomany(id, maxcnt) 2768547Seric char id; 2778547Seric int maxcnt; 2788547Seric { 2799381Seric syserr("too many %c lines, %d max", id, maxcnt); 2808547Seric } 2818547Seric /* 2824432Seric ** FILECLASS -- read members of a class from a file 2834432Seric ** 2844432Seric ** Parameters: 2854432Seric ** class -- class to define. 2864432Seric ** filename -- name of file to read. 2874432Seric ** fmt -- scanf string to use for match. 2884432Seric ** 2894432Seric ** Returns: 2904432Seric ** none 2914432Seric ** 2924432Seric ** Side Effects: 2934432Seric ** 2944432Seric ** puts all lines in filename that match a scanf into 2954432Seric ** the named class. 2964432Seric */ 2974432Seric 2984432Seric fileclass(class, filename, fmt) 2994432Seric int class; 3004432Seric char *filename; 3014432Seric char *fmt; 3024432Seric { 303*25808Seric FILE *f; 3044432Seric char buf[MAXLINE]; 3054432Seric 3064432Seric f = fopen(filename, "r"); 3074432Seric if (f == NULL) 3084432Seric { 3094432Seric syserr("cannot open %s", filename); 3104432Seric return; 3114432Seric } 3124432Seric 3134432Seric while (fgets(buf, sizeof buf, f) != NULL) 3144432Seric { 3154432Seric register STAB *s; 316*25808Seric register char *p; 317*25808Seric # ifdef SCANF 3184432Seric char wordbuf[MAXNAME+1]; 3194432Seric 3204432Seric if (sscanf(buf, fmt, wordbuf) != 1) 3214432Seric continue; 322*25808Seric p = wordbuf; 323*25808Seric # else SCANF 324*25808Seric p = buf; 325*25808Seric # endif SCANF 326*25808Seric 327*25808Seric /* 328*25808Seric ** Break up the match into words. 329*25808Seric */ 330*25808Seric 331*25808Seric while (*p != '\0') 332*25808Seric { 333*25808Seric register char *q; 334*25808Seric 335*25808Seric /* strip leading spaces */ 336*25808Seric while (isspace(*p)) 337*25808Seric p++; 338*25808Seric if (*p == '\0') 339*25808Seric break; 340*25808Seric 341*25808Seric /* find the end of the word */ 342*25808Seric q = p; 343*25808Seric while (*p != '\0' && !isspace(*p)) 344*25808Seric p++; 345*25808Seric if (*p != '\0') 346*25808Seric *p++ = '\0'; 347*25808Seric 348*25808Seric /* enter the word in the symbol table */ 349*25808Seric s = stab(q, ST_CLASS, ST_ENTER); 350*25808Seric setbitn(class, s->s_class); 351*25808Seric } 3524432Seric } 3534432Seric 3544627Seric (void) fclose(f); 3554432Seric } 3564432Seric /* 3574096Seric ** MAKEMAILER -- define a new mailer. 3584096Seric ** 3594096Seric ** Parameters: 36010327Seric ** line -- description of mailer. This is in labeled 36110327Seric ** fields. The fields are: 36210327Seric ** P -- the path to the mailer 36310327Seric ** F -- the flags associated with the mailer 36410327Seric ** A -- the argv for this mailer 36510327Seric ** S -- the sender rewriting set 36610327Seric ** R -- the recipient rewriting set 36710327Seric ** E -- the eol string 36810327Seric ** The first word is the canonical name of the mailer. 3694096Seric ** 3704096Seric ** Returns: 3714096Seric ** none. 3724096Seric ** 3734096Seric ** Side Effects: 3744096Seric ** enters the mailer into the mailer table. 3754096Seric */ 3763308Seric 37721066Seric makemailer(line) 3784096Seric char *line; 3794096Seric { 3804096Seric register char *p; 3818067Seric register struct mailer *m; 3828067Seric register STAB *s; 3838067Seric int i; 38410327Seric char fcode; 3854096Seric extern int NextMailer; 38610327Seric extern char **makeargv(); 38710327Seric extern char *munchstring(); 38810327Seric extern char *DelimChar; 38910701Seric extern long atol(); 3904096Seric 39110327Seric /* allocate a mailer and set up defaults */ 39210327Seric m = (struct mailer *) xalloc(sizeof *m); 39310327Seric bzero((char *) m, sizeof *m); 39410327Seric m->m_mno = NextMailer; 39510327Seric m->m_eol = "\n"; 39610327Seric 39710327Seric /* collect the mailer name */ 39810327Seric for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++) 39910327Seric continue; 40010327Seric if (*p != '\0') 40110327Seric *p++ = '\0'; 40210327Seric m->m_name = newstr(line); 40310327Seric 40410327Seric /* now scan through and assign info from the fields */ 40510327Seric while (*p != '\0') 40610327Seric { 40710327Seric while (*p != '\0' && (*p == ',' || isspace(*p))) 40810327Seric p++; 40910327Seric 41010327Seric /* p now points to field code */ 41110327Seric fcode = *p; 41210327Seric while (*p != '\0' && *p != '=' && *p != ',') 41310327Seric p++; 41410327Seric if (*p++ != '=') 41510327Seric { 41610327Seric syserr("`=' expected"); 41710327Seric return; 41810327Seric } 41910327Seric while (isspace(*p)) 42010327Seric p++; 42110327Seric 42210327Seric /* p now points to the field body */ 42310327Seric p = munchstring(p); 42410327Seric 42510327Seric /* install the field into the mailer struct */ 42610327Seric switch (fcode) 42710327Seric { 42810327Seric case 'P': /* pathname */ 42910327Seric m->m_mailer = newstr(p); 43010327Seric break; 43110327Seric 43210327Seric case 'F': /* flags */ 43310687Seric for (; *p != '\0'; p++) 43410687Seric setbitn(*p, m->m_flags); 43510327Seric break; 43610327Seric 43710327Seric case 'S': /* sender rewriting ruleset */ 43810327Seric case 'R': /* recipient rewriting ruleset */ 43910327Seric i = atoi(p); 44010327Seric if (i < 0 || i >= MAXRWSETS) 44110327Seric { 44210327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 44310327Seric return; 44410327Seric } 44510327Seric if (fcode == 'S') 44610327Seric m->m_s_rwset = i; 44710327Seric else 44810327Seric m->m_r_rwset = i; 44910327Seric break; 45010327Seric 45110327Seric case 'E': /* end of line string */ 45210327Seric m->m_eol = newstr(p); 45310327Seric break; 45410327Seric 45510327Seric case 'A': /* argument vector */ 45610327Seric m->m_argv = makeargv(p); 45710327Seric break; 45810701Seric 45910701Seric case 'M': /* maximum message size */ 46010701Seric m->m_maxsize = atol(p); 46110701Seric break; 46210327Seric } 46310327Seric 46410327Seric p = DelimChar; 46510327Seric } 46610327Seric 46710327Seric /* now store the mailer away */ 4684096Seric if (NextMailer >= MAXMAILERS) 4694096Seric { 4709381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 4714096Seric return; 4724096Seric } 47310327Seric Mailer[NextMailer++] = m; 47410327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 47510327Seric s->s_mailer = m; 47610327Seric } 47710327Seric /* 47810327Seric ** MUNCHSTRING -- translate a string into internal form. 47910327Seric ** 48010327Seric ** Parameters: 48110327Seric ** p -- the string to munch. 48210327Seric ** 48310327Seric ** Returns: 48410327Seric ** the munched string. 48510327Seric ** 48610327Seric ** Side Effects: 48710327Seric ** Sets "DelimChar" to point to the string that caused us 48810327Seric ** to stop. 48910327Seric */ 4904096Seric 49110327Seric char * 49210327Seric munchstring(p) 49310327Seric register char *p; 49410327Seric { 49510327Seric register char *q; 49610327Seric bool backslash = FALSE; 49710327Seric bool quotemode = FALSE; 49810327Seric static char buf[MAXLINE]; 49910327Seric extern char *DelimChar; 5004096Seric 50110327Seric for (q = buf; *p != '\0'; p++) 5024096Seric { 50310327Seric if (backslash) 50410327Seric { 50510327Seric /* everything is roughly literal */ 50610357Seric backslash = FALSE; 50710327Seric switch (*p) 50810327Seric { 50910327Seric case 'r': /* carriage return */ 51010327Seric *q++ = '\r'; 51110327Seric continue; 51210327Seric 51310327Seric case 'n': /* newline */ 51410327Seric *q++ = '\n'; 51510327Seric continue; 51610327Seric 51710327Seric case 'f': /* form feed */ 51810327Seric *q++ = '\f'; 51910327Seric continue; 52010327Seric 52110327Seric case 'b': /* backspace */ 52210327Seric *q++ = '\b'; 52310327Seric continue; 52410327Seric } 52510327Seric *q++ = *p; 52610327Seric } 52710327Seric else 52810327Seric { 52910327Seric if (*p == '\\') 53010327Seric backslash = TRUE; 53110327Seric else if (*p == '"') 53210327Seric quotemode = !quotemode; 53310327Seric else if (quotemode || *p != ',') 53410327Seric *q++ = *p; 53510327Seric else 53610327Seric break; 53710327Seric } 5384096Seric } 5394096Seric 54010327Seric DelimChar = p; 54110327Seric *q++ = '\0'; 54210327Seric return (buf); 54310327Seric } 54410327Seric /* 54510327Seric ** MAKEARGV -- break up a string into words 54610327Seric ** 54710327Seric ** Parameters: 54810327Seric ** p -- the string to break up. 54910327Seric ** 55010327Seric ** Returns: 55110327Seric ** a char **argv (dynamically allocated) 55210327Seric ** 55310327Seric ** Side Effects: 55410327Seric ** munges p. 55510327Seric */ 5564096Seric 55710327Seric char ** 55810327Seric makeargv(p) 55910327Seric register char *p; 56010327Seric { 56110327Seric char *q; 56210327Seric int i; 56310327Seric char **avp; 56410327Seric char *argv[MAXPV + 1]; 56510327Seric 56610327Seric /* take apart the words */ 56710327Seric i = 0; 56810327Seric while (*p != '\0' && i < MAXPV) 5694096Seric { 57010327Seric q = p; 57110327Seric while (*p != '\0' && !isspace(*p)) 57210327Seric p++; 57310327Seric while (isspace(*p)) 57410327Seric *p++ = '\0'; 57510327Seric argv[i++] = newstr(q); 5764096Seric } 57710327Seric argv[i++] = NULL; 5784096Seric 57910327Seric /* now make a copy of the argv */ 58010327Seric avp = (char **) xalloc(sizeof *avp * i); 58116893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 58210327Seric 58310327Seric return (avp); 5843308Seric } 5853308Seric /* 5863308Seric ** PRINTRULES -- print rewrite rules (for debugging) 5873308Seric ** 5883308Seric ** Parameters: 5893308Seric ** none. 5903308Seric ** 5913308Seric ** Returns: 5923308Seric ** none. 5933308Seric ** 5943308Seric ** Side Effects: 5953308Seric ** prints rewrite rules. 5963308Seric */ 5973308Seric 5984319Seric # ifdef DEBUG 5994319Seric 6003308Seric printrules() 6013308Seric { 6023308Seric register struct rewrite *rwp; 6034072Seric register int ruleset; 6043308Seric 6054072Seric for (ruleset = 0; ruleset < 10; ruleset++) 6063308Seric { 6074072Seric if (RewriteRules[ruleset] == NULL) 6084072Seric continue; 6098067Seric printf("\n----Rule Set %d:", ruleset); 6103308Seric 6114072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 6123308Seric { 6138067Seric printf("\nLHS:"); 6148067Seric printav(rwp->r_lhs); 6158067Seric printf("RHS:"); 6168067Seric printav(rwp->r_rhs); 6173308Seric } 6183308Seric } 6193308Seric } 6204319Seric 6214319Seric # endif DEBUG 6224096Seric /* 6238256Seric ** SETOPTION -- set global processing option 6248256Seric ** 6258256Seric ** Parameters: 6268256Seric ** opt -- option name. 6278256Seric ** val -- option value (as a text string). 62821755Seric ** safe -- set if this came from a configuration file. 62921755Seric ** Some options (if set from the command line) will 63021755Seric ** reset the user id to avoid security problems. 6318269Seric ** sticky -- if set, don't let other setoptions override 6328269Seric ** this value. 6338256Seric ** 6348256Seric ** Returns: 6358256Seric ** none. 6368256Seric ** 6378256Seric ** Side Effects: 6388256Seric ** Sets options as implied by the arguments. 6398256Seric */ 6408256Seric 64110687Seric static BITMAP StickyOpt; /* set if option is stuck */ 64225700Seric extern char *NetName; /* name of home (local) network */ 64325700Seric # ifdef SMTP 64425700Seric # ifdef WIZ 64510687Seric extern char *WizWord; /* the stored wizard password */ 64625700Seric # endif WIZ 64725700Seric # endif SMTP 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 # ifdef DEBUG 6638256Seric if (tTd(37, 1)) 6649341Seric printf("setoption %c=%s", opt, val); 6658256Seric # endif DEBUG 6668256Seric 6678256Seric /* 6688269Seric ** See if this option is preset for us. 6698256Seric */ 6708256Seric 67110687Seric if (bitnset(opt, StickyOpt)) 6728269Seric { 6738269Seric # ifdef DEBUG 6749341Seric if (tTd(37, 1)) 6759341Seric printf(" (ignored)\n"); 6768269Seric # endif DEBUG 6778269Seric return; 6788269Seric } 6798269Seric 68021755Seric /* 68121755Seric ** Check to see if this option can be specified by this user. 68221755Seric */ 68321755Seric 68425567Seric if (!safe && getruid() == 0) 68521755Seric safe = TRUE; 68621755Seric if (!safe && index("deiLmorsv", opt) == NULL) 68721755Seric { 68821755Seric # ifdef DEBUG 68921755Seric if (tTd(37, 1)) 69021755Seric printf(" (unsafe)"); 69121755Seric # endif DEBUG 69221755Seric if (getruid() != geteuid()) 69321755Seric { 69421755Seric printf("(Resetting uid)\n"); 69523111Seric (void) setgid(getgid()); 69623111Seric (void) setuid(getuid()); 69721755Seric } 69821755Seric } 69917985Seric #ifdef DEBUG 70021755Seric else if (tTd(37, 1)) 70117985Seric printf("\n"); 70217985Seric #endif DEBUG 7038269Seric 7048256Seric switch (opt) 7058256Seric { 7068256Seric case 'A': /* set default alias file */ 7079381Seric if (val[0] == '\0') 7088269Seric AliasFile = "aliases"; 7099381Seric else 7109381Seric AliasFile = newstr(val); 7118256Seric break; 7128256Seric 71317474Seric case 'a': /* look N minutes for "@:@" in alias file */ 71417474Seric if (val[0] == '\0') 71517474Seric SafeAlias = 5; 71617474Seric else 71717474Seric SafeAlias = atoi(val); 71817474Seric break; 71917474Seric 72016843Seric case 'B': /* substitution for blank character */ 72116843Seric SpaceSub = val[0]; 72216843Seric if (SpaceSub == '\0') 72316843Seric SpaceSub = ' '; 72416843Seric break; 72516843Seric 7269284Seric case 'c': /* don't connect to "expensive" mailers */ 7279381Seric NoConnect = atobool(val); 7289284Seric break; 7299284Seric 73024944Seric case 'C': /* checkpoint after N connections */ 73124944Seric CheckPointLimit = atoi(val); 73224944Seric break; 73324944Seric 7349284Seric case 'd': /* delivery mode */ 7359284Seric switch (*val) 7368269Seric { 7379284Seric case '\0': 7389284Seric SendMode = SM_DELIVER; 7398269Seric break; 7408269Seric 74110755Seric case SM_QUEUE: /* queue only */ 74210755Seric #ifndef QUEUE 74310755Seric syserr("need QUEUE to set -odqueue"); 74410755Seric #endif QUEUE 74510755Seric /* fall through..... */ 74610755Seric 7479284Seric case SM_DELIVER: /* do everything */ 7489284Seric case SM_FORK: /* fork after verification */ 7499284Seric SendMode = *val; 7508269Seric break; 7518269Seric 7528269Seric default: 7539284Seric syserr("Unknown delivery mode %c", *val); 7548269Seric exit(EX_USAGE); 7558269Seric } 7568269Seric break; 7578269Seric 7589146Seric case 'D': /* rebuild alias database as needed */ 7599381Seric AutoRebuild = atobool(val); 7609146Seric break; 7619146Seric 7628269Seric case 'e': /* set error processing mode */ 7638269Seric switch (*val) 7648269Seric { 7659381Seric case EM_QUIET: /* be silent about it */ 7669381Seric case EM_MAIL: /* mail back */ 7679381Seric case EM_BERKNET: /* do berknet error processing */ 7689381Seric case EM_WRITE: /* write back (or mail) */ 7698269Seric HoldErrs = TRUE; 7709381Seric /* fall through... */ 7718269Seric 7729381Seric case EM_PRINT: /* print errors normally (default) */ 7739381Seric ErrorMode = *val; 7748269Seric break; 7758269Seric } 7768269Seric break; 7778269Seric 7789049Seric case 'F': /* file mode */ 77917975Seric FileMode = atooct(val) & 0777; 7809049Seric break; 7819049Seric 7828269Seric case 'f': /* save Unix-style From lines on front */ 7839381Seric SaveFrom = atobool(val); 7848269Seric break; 7858269Seric 7868256Seric case 'g': /* default gid */ 78717474Seric DefGid = atoi(val); 7888256Seric break; 7898256Seric 7908256Seric case 'H': /* help file */ 7919381Seric if (val[0] == '\0') 7928269Seric HelpFile = "sendmail.hf"; 7939381Seric else 7949381Seric HelpFile = newstr(val); 7958256Seric break; 7968256Seric 7978269Seric case 'i': /* ignore dot lines in message */ 7989381Seric IgnrDot = atobool(val); 7998269Seric break; 8008269Seric 8018256Seric case 'L': /* log level */ 8029381Seric LogLevel = atoi(val); 8038256Seric break; 8048256Seric 8058269Seric case 'M': /* define macro */ 8069381Seric define(val[0], newstr(&val[1]), CurEnv); 80716878Seric sticky = FALSE; 8088269Seric break; 8098269Seric 8108269Seric case 'm': /* send to me too */ 8119381Seric MeToo = atobool(val); 8128269Seric break; 8138269Seric 81416143Seric # ifdef DAEMON 81516143Seric case 'N': /* home (local?) network name */ 81616143Seric NetName = newstr(val); 81716143Seric break; 81816143Seric # endif DAEMON 81916143Seric 8208269Seric case 'o': /* assume old style headers */ 8219381Seric if (atobool(val)) 8229341Seric CurEnv->e_flags |= EF_OLDSTYLE; 8239341Seric else 8249341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 8258269Seric break; 8268269Seric 82724944Seric case 'P': /* postmaster copy address for returned mail */ 82824944Seric PostMasterCopy = newstr(val); 82924944Seric break; 83024944Seric 83124944Seric case 'q': /* slope of queue only function */ 83224944Seric QueueFactor = atoi(val); 83324944Seric break; 83424944Seric 8358256Seric case 'Q': /* queue directory */ 8369381Seric if (val[0] == '\0') 8378269Seric QueueDir = "mqueue"; 8389381Seric else 8399381Seric QueueDir = newstr(val); 8408256Seric break; 8418256Seric 8428256Seric case 'r': /* read timeout */ 8439381Seric ReadTimeout = convtime(val); 8448256Seric break; 8458256Seric 8468256Seric case 'S': /* status file */ 8479381Seric if (val[0] == '\0') 8488269Seric StatFile = "sendmail.st"; 8499381Seric else 8509381Seric StatFile = newstr(val); 8518256Seric break; 8528256Seric 8538265Seric case 's': /* be super safe, even if expensive */ 8549381Seric SuperSafe = atobool(val); 8558256Seric break; 8568256Seric 8578256Seric case 'T': /* queue timeout */ 8589381Seric TimeOut = convtime(val); 8598256Seric break; 8608256Seric 8618265Seric case 't': /* time zone name */ 8628265Seric # ifdef V6 8639381Seric StdTimezone = newstr(val); 8649381Seric DstTimezone = index(StdTimeZone, ','); 8658265Seric if (DstTimezone == NULL) 8669381Seric syserr("bad time zone spec"); 8679381Seric else 8689381Seric *DstTimezone++ = '\0'; 8698265Seric # endif V6 8708265Seric break; 8718265Seric 8728256Seric case 'u': /* set default uid */ 87317474Seric DefUid = atoi(val); 8748256Seric break; 8758256Seric 8768269Seric case 'v': /* run in verbose mode */ 8779381Seric Verbose = atobool(val); 8788256Seric break; 8798256Seric 88025700Seric # ifdef SMTP 88125700Seric # ifdef WIZ 8828544Seric case 'W': /* set the wizards password */ 88317474Seric WizWord = newstr(val); 8848544Seric break; 88525700Seric # endif WIZ 88625700Seric # endif SMTP 8878544Seric 88814879Seric case 'x': /* load avg at which to auto-queue msgs */ 88914879Seric QueueLA = atoi(val); 89014879Seric break; 89114879Seric 89214879Seric case 'X': /* load avg at which to auto-reject connections */ 89314879Seric RefuseLA = atoi(val); 89414879Seric break; 89514879Seric 89624981Seric case 'y': /* work recipient factor */ 89724981Seric WkRecipFact = atoi(val); 89824981Seric break; 89924981Seric 90024981Seric case 'Y': /* fork jobs during queue runs */ 90124952Seric ForkQueueRuns = atobool(val); 90224952Seric break; 90324952Seric 90424981Seric case 'z': /* work message class factor */ 90524981Seric WkClassFact = atoi(val); 90624981Seric break; 90724981Seric 90824981Seric case 'Z': /* work time factor */ 90924981Seric WkTimeFact = atoi(val); 91024981Seric break; 91124981Seric 9128256Seric default: 9138256Seric break; 9148256Seric } 91516878Seric if (sticky) 91616878Seric setbitn(opt, StickyOpt); 9179188Seric return; 9188256Seric } 91910687Seric /* 92010687Seric ** SETCLASS -- set a word into a class 92110687Seric ** 92210687Seric ** Parameters: 92310687Seric ** class -- the class to put the word in. 92410687Seric ** word -- the word to enter 92510687Seric ** 92610687Seric ** Returns: 92710687Seric ** none. 92810687Seric ** 92910687Seric ** Side Effects: 93010687Seric ** puts the word into the symbol table. 93110687Seric */ 93210687Seric 93310687Seric setclass(class, word) 93410687Seric int class; 93510687Seric char *word; 93610687Seric { 93710687Seric register STAB *s; 93810687Seric 93910687Seric s = stab(word, ST_CLASS, ST_ENTER); 94010687Seric setbitn(class, s->s_class); 94110687Seric } 942