122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 362530Sbostic * Copyright (c) 1988, 1993 462530Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822709Sdist 922709Sdist #ifndef lint 10*65066Seric static char sccsid[] = "@(#)readcf.c 8.17 (Berkeley) 12/10/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1464133Seric # include <pwd.h> 1564133Seric # include <grp.h> 1657207Seric #ifdef NAMED_BIND 1757207Seric # include <arpa/nameser.h> 1857207Seric # include <resolv.h> 1957207Seric #endif 203308Seric 213308Seric /* 223308Seric ** READCF -- read control file. 233308Seric ** 243308Seric ** This routine reads the control file and builds the internal 253308Seric ** form. 263308Seric ** 274432Seric ** The file is formatted as a sequence of lines, each taken 284432Seric ** atomically. The first character of each line describes how 294432Seric ** the line is to be interpreted. The lines are: 304432Seric ** Dxval Define macro x to have value val. 314432Seric ** Cxword Put word into class x. 324432Seric ** Fxfile [fmt] Read file for lines to put into 334432Seric ** class x. Use scanf string 'fmt' 344432Seric ** or "%s" if not present. Fmt should 354432Seric ** only produce one string-valued result. 364432Seric ** Hname: value Define header with field-name 'name' 374432Seric ** and value as specified; this will be 384432Seric ** macro expanded immediately before 394432Seric ** use. 404432Seric ** Sn Use rewriting set n. 414432Seric ** Rlhs rhs Rewrite addresses that match lhs to 424432Seric ** be rhs. 4324944Seric ** Mn arg=val... Define mailer. n is the internal name. 4424944Seric ** Args specify mailer parameters. 458252Seric ** Oxvalue Set option x to value. 468252Seric ** Pname=value Set precedence name to value. 4764718Seric ** Vversioncode[/vendorcode] 4864718Seric ** Version level/vendor name of 4964718Seric ** configuration syntax. 5053654Seric ** Kmapname mapclass arguments.... 5153654Seric ** Define keyed lookup of a given class. 5253654Seric ** Arguments are class dependent. 534432Seric ** 543308Seric ** Parameters: 553308Seric ** cfname -- control file name. 5654973Seric ** safe -- TRUE if this is the system config file; 5754973Seric ** FALSE otherwise. 5855012Seric ** e -- the main envelope. 593308Seric ** 603308Seric ** Returns: 613308Seric ** none. 623308Seric ** 633308Seric ** Side Effects: 643308Seric ** Builds several internal tables. 653308Seric */ 663308Seric 6755012Seric readcf(cfname, safe, e) 683308Seric char *cfname; 6954973Seric bool safe; 7055012Seric register ENVELOPE *e; 713308Seric { 723308Seric FILE *cf; 738547Seric int ruleset = 0; 748547Seric char *q; 759350Seric struct rewrite *rwp = NULL; 7657135Seric char *bp; 7764718Seric auto char *ep; 7857589Seric int nfuzzy; 7964133Seric char *file; 8064133Seric bool optional; 813308Seric char buf[MAXLINE]; 823308Seric register char *p; 833308Seric extern char **copyplist(); 8452647Seric struct stat statb; 855909Seric char exbuf[MAXLINE]; 86*65066Seric char pvpbuf[MAXLINE + MAXATOM]; 8710709Seric extern char *munchstring(); 8853654Seric extern void makemapentry(); 893308Seric 9052647Seric FileName = cfname; 9152647Seric LineNumber = 0; 9252647Seric 933308Seric cf = fopen(cfname, "r"); 943308Seric if (cf == NULL) 953308Seric { 9652647Seric syserr("cannot open"); 973308Seric exit(EX_OSFILE); 983308Seric } 993308Seric 10052647Seric if (fstat(fileno(cf), &statb) < 0) 10152647Seric { 10252647Seric syserr("cannot fstat"); 10352647Seric exit(EX_OSFILE); 10452647Seric } 10552647Seric 10652647Seric if (!S_ISREG(statb.st_mode)) 10752647Seric { 10852647Seric syserr("not a plain file"); 10952647Seric exit(EX_OSFILE); 11052647Seric } 11152647Seric 11252647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 11352647Seric { 11453037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 11553037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 11653037Seric FileName); 11753037Seric #ifdef LOG 11853037Seric if (LogLevel > 0) 11953037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 12053037Seric FileName); 12153037Seric #endif 12252647Seric } 12352647Seric 12459254Seric #ifdef XLA 12559254Seric xla_zero(); 12659254Seric #endif 12759254Seric 12857135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1293308Seric { 13057135Seric if (bp[0] == '#') 13157135Seric { 13257135Seric if (bp != buf) 13357135Seric free(bp); 13452637Seric continue; 13557135Seric } 13652637Seric 13758050Seric /* map $ into \201 for macro expansion */ 13857135Seric for (p = bp; *p != '\0'; p++) 13916157Seric { 14057135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14152647Seric { 14252647Seric /* this is an on-line comment */ 14352647Seric register char *e; 14452647Seric 14558050Seric switch (*--p & 0377) 14652647Seric { 14758050Seric case MACROEXPAND: 14852647Seric /* it's from $# -- let it go through */ 14952647Seric p++; 15052647Seric break; 15152647Seric 15252647Seric case '\\': 15352647Seric /* it's backslash escaped */ 15452647Seric (void) strcpy(p, p + 1); 15552647Seric break; 15652647Seric 15752647Seric default: 15852647Seric /* delete preceeding white space */ 15958050Seric while (isascii(*p) && isspace(*p) && p > bp) 16052647Seric p--; 16156795Seric if ((e = strchr(++p, '\n')) != NULL) 16252647Seric (void) strcpy(p, e); 16352647Seric else 16452647Seric p[0] = p[1] = '\0'; 16552647Seric break; 16652647Seric } 16752647Seric continue; 16852647Seric } 16952647Seric 17016157Seric if (*p != '$') 17116157Seric continue; 17216157Seric 17316157Seric if (p[1] == '$') 17416157Seric { 17516157Seric /* actual dollar sign.... */ 17623111Seric (void) strcpy(p, p + 1); 17716157Seric continue; 17816157Seric } 17916157Seric 18016157Seric /* convert to macro expansion character */ 18158050Seric *p = MACROEXPAND; 18216157Seric } 18316157Seric 18416157Seric /* interpret this line */ 18564718Seric errno = 0; 18657135Seric switch (bp[0]) 1873308Seric { 1883308Seric case '\0': 1893308Seric case '#': /* comment */ 1903308Seric break; 1913308Seric 1923308Seric case 'R': /* rewriting rule */ 19357135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1943308Seric continue; 1953308Seric 1963308Seric if (*p == '\0') 1975909Seric { 19857135Seric syserr("invalid rewrite line \"%s\"", bp); 1995909Seric break; 2005909Seric } 2015909Seric 2025909Seric /* allocate space for the rule header */ 2035909Seric if (rwp == NULL) 2045909Seric { 2055909Seric RewriteRules[ruleset] = rwp = 2065909Seric (struct rewrite *) xalloc(sizeof *rwp); 2075909Seric } 2083308Seric else 2093308Seric { 2105909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2115909Seric rwp = rwp->r_next; 2125909Seric } 2135909Seric rwp->r_next = NULL; 2143308Seric 2155909Seric /* expand and save the LHS */ 2165909Seric *p = '\0'; 21757135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 218*65066Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, 219*65066Seric sizeof pvpbuf, NULL); 22057589Seric nfuzzy = 0; 2215909Seric if (rwp->r_lhs != NULL) 22257589Seric { 22357589Seric register char **ap; 22457589Seric 2255909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22657589Seric 22757589Seric /* count the number of fuzzy matches in LHS */ 22857589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22957589Seric { 23058148Seric char *botch; 23158148Seric 23258148Seric botch = NULL; 23358050Seric switch (**ap & 0377) 23457589Seric { 23557589Seric case MATCHZANY: 23657589Seric case MATCHANY: 23757589Seric case MATCHONE: 23857589Seric case MATCHCLASS: 23957589Seric case MATCHNCLASS: 24057589Seric nfuzzy++; 24158148Seric break; 24258148Seric 24358148Seric case MATCHREPL: 24458148Seric botch = "$0-$9"; 24558148Seric break; 24658148Seric 24758148Seric case CANONNET: 24858148Seric botch = "$#"; 24958148Seric break; 25058148Seric 25158148Seric case CANONUSER: 25258148Seric botch = "$:"; 25358148Seric break; 25458148Seric 25558148Seric case CALLSUBR: 25658148Seric botch = "$>"; 25758148Seric break; 25858148Seric 25958148Seric case CONDIF: 26058148Seric botch = "$?"; 26158148Seric break; 26258148Seric 26358148Seric case CONDELSE: 26458148Seric botch = "$|"; 26558148Seric break; 26658148Seric 26758148Seric case CONDFI: 26858148Seric botch = "$."; 26958148Seric break; 27058148Seric 27158148Seric case HOSTBEGIN: 27258148Seric botch = "$["; 27358148Seric break; 27458148Seric 27558148Seric case HOSTEND: 27658148Seric botch = "$]"; 27758148Seric break; 27858148Seric 27958148Seric case LOOKUPBEGIN: 28058148Seric botch = "$("; 28158148Seric break; 28258148Seric 28358148Seric case LOOKUPEND: 28458148Seric botch = "$)"; 28558148Seric break; 28657589Seric } 28758148Seric if (botch != NULL) 28858148Seric syserr("Inappropriate use of %s on LHS", 28958148Seric botch); 29057589Seric } 29157589Seric } 29256678Seric else 29356678Seric syserr("R line: null LHS"); 2945909Seric 2955909Seric /* expand and save the RHS */ 2965909Seric while (*++p == '\t') 2975909Seric continue; 2987231Seric q = p; 2997231Seric while (*p != '\0' && *p != '\t') 3007231Seric p++; 3017231Seric *p = '\0'; 30255012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 303*65066Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, 304*65066Seric sizeof pvpbuf, NULL); 3055909Seric if (rwp->r_rhs != NULL) 30657589Seric { 30757589Seric register char **ap; 30857589Seric 3095909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 31057589Seric 31157589Seric /* check no out-of-bounds replacements */ 31257589Seric nfuzzy += '0'; 31357589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31457589Seric { 31558148Seric char *botch; 31658148Seric 31758148Seric botch = NULL; 31858148Seric switch (**ap & 0377) 31957589Seric { 32058148Seric case MATCHREPL: 32158148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32258148Seric { 32358148Seric syserr("replacement $%c out of bounds", 32458148Seric (*ap)[1]); 32558148Seric } 32658148Seric break; 32758148Seric 32858148Seric case MATCHZANY: 32958148Seric botch = "$*"; 33058148Seric break; 33158148Seric 33258148Seric case MATCHANY: 33358148Seric botch = "$+"; 33458148Seric break; 33558148Seric 33658148Seric case MATCHONE: 33758148Seric botch = "$-"; 33858148Seric break; 33958148Seric 34058148Seric case MATCHCLASS: 34158148Seric botch = "$="; 34258148Seric break; 34358148Seric 34458148Seric case MATCHNCLASS: 34558148Seric botch = "$~"; 34658148Seric break; 34757589Seric } 34858148Seric if (botch != NULL) 34958148Seric syserr("Inappropriate use of %s on RHS", 35058148Seric botch); 35157589Seric } 35257589Seric } 35356678Seric else 35456678Seric syserr("R line: null RHS"); 3553308Seric break; 3563308Seric 3574072Seric case 'S': /* select rewriting set */ 35864440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 35964440Seric continue; 36064440Seric if (!isascii(*p) || !isdigit(*p)) 36164440Seric { 36264440Seric syserr("invalid argument to S line: \"%.20s\"", 36364440Seric &bp[1]); 36464440Seric break; 36564440Seric } 36664440Seric ruleset = atoi(p); 3678056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3688056Seric { 3699381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3708056Seric ruleset = 0; 3718056Seric } 3724072Seric rwp = NULL; 3734072Seric break; 3744072Seric 3753308Seric case 'D': /* macro definition */ 37664086Seric p = munchstring(&bp[2], NULL); 37764086Seric define(bp[1], newstr(p), e); 3783308Seric break; 3793308Seric 3803387Seric case 'H': /* required header line */ 38157135Seric (void) chompheader(&bp[1], TRUE, e); 3823387Seric break; 3833387Seric 3844061Seric case 'C': /* word class */ 3854432Seric /* scan the list of words and set class for all */ 38664121Seric expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e); 38764121Seric for (p = exbuf; *p != '\0'; ) 3884061Seric { 3894061Seric register char *wd; 3904061Seric char delim; 3914061Seric 39258050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3934061Seric p++; 3944061Seric wd = p; 39558050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3964061Seric p++; 3974061Seric delim = *p; 3984061Seric *p = '\0'; 3994061Seric if (wd[0] != '\0') 40057135Seric setclass(bp[1], wd); 4014061Seric *p = delim; 4024061Seric } 4034061Seric break; 4044061Seric 40559272Seric case 'F': /* word class from file */ 40664133Seric for (p = &bp[2]; isascii(*p) && isspace(*p); ) 40764133Seric p++; 40864133Seric if (p[0] == '-' && p[1] == 'o') 40964133Seric { 41064133Seric optional = TRUE; 41164133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41264133Seric p++; 41364133Seric while (isascii(*p) && isspace(*p)) 41464133Seric *p++; 41564133Seric } 41664133Seric else 41764133Seric optional = FALSE; 41864133Seric file = p; 41964133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 42064133Seric p++; 42159272Seric if (*p == '\0') 42259272Seric p = "%s"; 42359272Seric else 42459272Seric { 42559272Seric *p = '\0'; 42659272Seric while (isascii(*++p) && isspace(*p)) 42759272Seric continue; 42859272Seric } 42964133Seric fileclass(bp[1], file, p, safe, optional); 43059272Seric break; 43159272Seric 43259156Seric #ifdef XLA 43359156Seric case 'L': /* extended load average description */ 43459156Seric xla_init(&bp[1]); 43559156Seric break; 43659156Seric #endif 43759156Seric 4384096Seric case 'M': /* define mailer */ 43957135Seric makemailer(&bp[1]); 4404096Seric break; 4414096Seric 4428252Seric case 'O': /* set option */ 44358734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4448252Seric break; 4458252Seric 4468252Seric case 'P': /* set precedence */ 4478252Seric if (NumPriorities >= MAXPRIORITIES) 4488252Seric { 4498547Seric toomany('P', MAXPRIORITIES); 4508252Seric break; 4518252Seric } 45257135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4538252Seric continue; 4548252Seric if (*p == '\0') 4558252Seric goto badline; 4568252Seric *p = '\0'; 45757135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4588252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4598252Seric NumPriorities++; 4608252Seric break; 4618252Seric 4628547Seric case 'T': /* trusted user(s) */ 46358161Seric /* this option is obsolete, but will be ignored */ 4648547Seric break; 4658547Seric 46652645Seric case 'V': /* configuration syntax version */ 46764440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 46864440Seric continue; 46964440Seric if (!isascii(*p) || !isdigit(*p)) 47064440Seric { 47164440Seric syserr("invalid argument to V line: \"%.20s\"", 47264440Seric &bp[1]); 47364440Seric break; 47464440Seric } 47564718Seric ConfigLevel = strtol(p, &ep, 10); 47664279Seric if (ConfigLevel >= 5) 47764279Seric { 47864279Seric /* level 5 configs have short name in $w */ 47964279Seric p = macvalue('w', e); 48064279Seric if (p != NULL && (p = strchr(p, '.')) != NULL) 48164279Seric *p = '\0'; 48264279Seric } 48364718Seric if (*ep++ == '/') 48464718Seric { 48564718Seric /* extract vendor code */ 48664718Seric for (p = ep; isascii(*p) && isalpha(*p); ) 48764718Seric p++; 48864718Seric *p = '\0'; 48964718Seric 49064718Seric if (!setvendor(ep)) 49164718Seric syserr("invalid V line vendor code: \"%s\"", 49264718Seric ep); 49364718Seric } 49452645Seric break; 49552645Seric 49653654Seric case 'K': 49757135Seric makemapentry(&bp[1]); 49853654Seric break; 49953654Seric 5003308Seric default: 5014061Seric badline: 50257135Seric syserr("unknown control line \"%s\"", bp); 5033308Seric } 50457135Seric if (bp != buf) 50557135Seric free(bp); 5063308Seric } 50752637Seric if (ferror(cf)) 50852637Seric { 50952647Seric syserr("I/O read error", cfname); 51052637Seric exit(EX_OSFILE); 51152637Seric } 51252637Seric fclose(cf); 5139381Seric FileName = NULL; 51456836Seric 51557076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 51657076Seric { 51757076Seric /* user didn't initialize: set up host map */ 51857076Seric strcpy(buf, "host host"); 51964947Seric #ifdef NAMED_BIND 52057076Seric if (ConfigLevel >= 2) 52157076Seric strcat(buf, " -a."); 52264947Seric #endif 52357076Seric makemapentry(buf); 52457076Seric } 5254096Seric } 5264096Seric /* 5278547Seric ** TOOMANY -- signal too many of some option 5288547Seric ** 5298547Seric ** Parameters: 5308547Seric ** id -- the id of the error line 5318547Seric ** maxcnt -- the maximum possible values 5328547Seric ** 5338547Seric ** Returns: 5348547Seric ** none. 5358547Seric ** 5368547Seric ** Side Effects: 5378547Seric ** gives a syserr. 5388547Seric */ 5398547Seric 5408547Seric toomany(id, maxcnt) 5418547Seric char id; 5428547Seric int maxcnt; 5438547Seric { 5449381Seric syserr("too many %c lines, %d max", id, maxcnt); 5458547Seric } 5468547Seric /* 5474432Seric ** FILECLASS -- read members of a class from a file 5484432Seric ** 5494432Seric ** Parameters: 5504432Seric ** class -- class to define. 5514432Seric ** filename -- name of file to read. 5524432Seric ** fmt -- scanf string to use for match. 55364133Seric ** safe -- if set, this is a safe read. 55464133Seric ** optional -- if set, it is not an error for the file to 55564133Seric ** not exist. 5564432Seric ** 5574432Seric ** Returns: 5584432Seric ** none 5594432Seric ** 5604432Seric ** Side Effects: 5614432Seric ** 5624432Seric ** puts all lines in filename that match a scanf into 5634432Seric ** the named class. 5644432Seric */ 5654432Seric 56664133Seric fileclass(class, filename, fmt, safe, optional) 5674432Seric int class; 5684432Seric char *filename; 5694432Seric char *fmt; 57054973Seric bool safe; 57164133Seric bool optional; 5724432Seric { 57325808Seric FILE *f; 57454973Seric struct stat stbuf; 5754432Seric char buf[MAXLINE]; 5764432Seric 57754973Seric if (stat(filename, &stbuf) < 0) 57854973Seric { 57964133Seric if (!optional) 58064133Seric syserr("fileclass: cannot stat %s", filename); 58154973Seric return; 58254973Seric } 58354973Seric if (!S_ISREG(stbuf.st_mode)) 58454973Seric { 58554973Seric syserr("fileclass: %s not a regular file", filename); 58654973Seric return; 58754973Seric } 58854973Seric if (!safe && access(filename, R_OK) < 0) 58954973Seric { 59054973Seric syserr("fileclass: access denied on %s", filename); 59154973Seric return; 59254973Seric } 59354973Seric f = fopen(filename, "r"); 5944432Seric if (f == NULL) 5954432Seric { 59654973Seric syserr("fileclass: cannot open %s", filename); 5974432Seric return; 5984432Seric } 5994432Seric 6004432Seric while (fgets(buf, sizeof buf, f) != NULL) 6014432Seric { 6024432Seric register STAB *s; 60325808Seric register char *p; 60425808Seric # ifdef SCANF 6054432Seric char wordbuf[MAXNAME+1]; 6064432Seric 6074432Seric if (sscanf(buf, fmt, wordbuf) != 1) 6084432Seric continue; 60925808Seric p = wordbuf; 61056795Seric # else /* SCANF */ 61125808Seric p = buf; 61256795Seric # endif /* SCANF */ 61325808Seric 61425808Seric /* 61525808Seric ** Break up the match into words. 61625808Seric */ 61725808Seric 61825808Seric while (*p != '\0') 61925808Seric { 62025808Seric register char *q; 62125808Seric 62225808Seric /* strip leading spaces */ 62358050Seric while (isascii(*p) && isspace(*p)) 62425808Seric p++; 62525808Seric if (*p == '\0') 62625808Seric break; 62725808Seric 62825808Seric /* find the end of the word */ 62925808Seric q = p; 63058050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 63125808Seric p++; 63225808Seric if (*p != '\0') 63325808Seric *p++ = '\0'; 63425808Seric 63525808Seric /* enter the word in the symbol table */ 63625808Seric s = stab(q, ST_CLASS, ST_ENTER); 63725808Seric setbitn(class, s->s_class); 63825808Seric } 6394432Seric } 6404432Seric 64154973Seric (void) fclose(f); 6424432Seric } 6434432Seric /* 6444096Seric ** MAKEMAILER -- define a new mailer. 6454096Seric ** 6464096Seric ** Parameters: 64710327Seric ** line -- description of mailer. This is in labeled 64810327Seric ** fields. The fields are: 64910327Seric ** P -- the path to the mailer 65010327Seric ** F -- the flags associated with the mailer 65110327Seric ** A -- the argv for this mailer 65210327Seric ** S -- the sender rewriting set 65310327Seric ** R -- the recipient rewriting set 65410327Seric ** E -- the eol string 65510327Seric ** The first word is the canonical name of the mailer. 6564096Seric ** 6574096Seric ** Returns: 6584096Seric ** none. 6594096Seric ** 6604096Seric ** Side Effects: 6614096Seric ** enters the mailer into the mailer table. 6624096Seric */ 6633308Seric 66421066Seric makemailer(line) 6654096Seric char *line; 6664096Seric { 6674096Seric register char *p; 6688067Seric register struct mailer *m; 6698067Seric register STAB *s; 6708067Seric int i; 67110327Seric char fcode; 67258020Seric auto char *endp; 6734096Seric extern int NextMailer; 67410327Seric extern char **makeargv(); 67510327Seric extern char *munchstring(); 67610701Seric extern long atol(); 6774096Seric 67810327Seric /* allocate a mailer and set up defaults */ 67910327Seric m = (struct mailer *) xalloc(sizeof *m); 68010327Seric bzero((char *) m, sizeof *m); 68110327Seric m->m_eol = "\n"; 68210327Seric 68310327Seric /* collect the mailer name */ 68458050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 68510327Seric continue; 68610327Seric if (*p != '\0') 68710327Seric *p++ = '\0'; 68810327Seric m->m_name = newstr(line); 68910327Seric 69010327Seric /* now scan through and assign info from the fields */ 69110327Seric while (*p != '\0') 69210327Seric { 69358333Seric auto char *delimptr; 69458333Seric 69558050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 69610327Seric p++; 69710327Seric 69810327Seric /* p now points to field code */ 69910327Seric fcode = *p; 70010327Seric while (*p != '\0' && *p != '=' && *p != ',') 70110327Seric p++; 70210327Seric if (*p++ != '=') 70310327Seric { 70452637Seric syserr("mailer %s: `=' expected", m->m_name); 70510327Seric return; 70610327Seric } 70758050Seric while (isascii(*p) && isspace(*p)) 70810327Seric p++; 70910327Seric 71010327Seric /* p now points to the field body */ 71158333Seric p = munchstring(p, &delimptr); 71210327Seric 71310327Seric /* install the field into the mailer struct */ 71410327Seric switch (fcode) 71510327Seric { 71610327Seric case 'P': /* pathname */ 71710327Seric m->m_mailer = newstr(p); 71810327Seric break; 71910327Seric 72010327Seric case 'F': /* flags */ 72110687Seric for (; *p != '\0'; p++) 72258050Seric if (!(isascii(*p) && isspace(*p))) 72352637Seric setbitn(*p, m->m_flags); 72410327Seric break; 72510327Seric 72610327Seric case 'S': /* sender rewriting ruleset */ 72710327Seric case 'R': /* recipient rewriting ruleset */ 72858020Seric i = strtol(p, &endp, 10); 72910327Seric if (i < 0 || i >= MAXRWSETS) 73010327Seric { 73110327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 73210327Seric return; 73310327Seric } 73410327Seric if (fcode == 'S') 73558020Seric m->m_sh_rwset = m->m_se_rwset = i; 73610327Seric else 73758020Seric m->m_rh_rwset = m->m_re_rwset = i; 73858020Seric 73958020Seric p = endp; 74059985Seric if (*p++ == '/') 74158020Seric { 74258020Seric i = strtol(p, NULL, 10); 74358020Seric if (i < 0 || i >= MAXRWSETS) 74458020Seric { 74558020Seric syserr("invalid rewrite set, %d max", 74658020Seric MAXRWSETS); 74758020Seric return; 74858020Seric } 74958020Seric if (fcode == 'S') 75058020Seric m->m_sh_rwset = i; 75158020Seric else 75258020Seric m->m_rh_rwset = i; 75358020Seric } 75410327Seric break; 75510327Seric 75610327Seric case 'E': /* end of line string */ 75710327Seric m->m_eol = newstr(p); 75810327Seric break; 75910327Seric 76010327Seric case 'A': /* argument vector */ 76110327Seric m->m_argv = makeargv(p); 76210327Seric break; 76310701Seric 76410701Seric case 'M': /* maximum message size */ 76510701Seric m->m_maxsize = atol(p); 76610701Seric break; 76752106Seric 76852106Seric case 'L': /* maximum line length */ 76952106Seric m->m_linelimit = atoi(p); 77052106Seric break; 77158935Seric 77258935Seric case 'D': /* working directory */ 77358935Seric m->m_execdir = newstr(p); 77458935Seric break; 77510327Seric } 77610327Seric 77758333Seric p = delimptr; 77810327Seric } 77910327Seric 78052106Seric /* do some heuristic cleanup for back compatibility */ 78152106Seric if (bitnset(M_LIMITS, m->m_flags)) 78252106Seric { 78352106Seric if (m->m_linelimit == 0) 78452106Seric m->m_linelimit = SMTPLINELIM; 78555418Seric if (ConfigLevel < 2) 78652106Seric setbitn(M_7BITS, m->m_flags); 78752106Seric } 78852106Seric 78958321Seric /* do some rationality checking */ 79058321Seric if (m->m_argv == NULL) 79158321Seric { 79258321Seric syserr("M%s: A= argument required", m->m_name); 79358321Seric return; 79458321Seric } 79558321Seric if (m->m_mailer == NULL) 79658321Seric { 79758321Seric syserr("M%s: P= argument required", m->m_name); 79858321Seric return; 79958321Seric } 80058321Seric 8014096Seric if (NextMailer >= MAXMAILERS) 8024096Seric { 8039381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 8044096Seric return; 8054096Seric } 80657402Seric 80710327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 80857402Seric if (s->s_mailer != NULL) 80957402Seric { 81057402Seric i = s->s_mailer->m_mno; 81157402Seric free(s->s_mailer); 81257402Seric } 81357402Seric else 81457402Seric { 81557402Seric i = NextMailer++; 81657402Seric } 81757402Seric Mailer[i] = s->s_mailer = m; 81857454Seric m->m_mno = i; 81910327Seric } 82010327Seric /* 82110327Seric ** MUNCHSTRING -- translate a string into internal form. 82210327Seric ** 82310327Seric ** Parameters: 82410327Seric ** p -- the string to munch. 82558333Seric ** delimptr -- if non-NULL, set to the pointer of the 82658333Seric ** field delimiter character. 82710327Seric ** 82810327Seric ** Returns: 82910327Seric ** the munched string. 83010327Seric */ 8314096Seric 83210327Seric char * 83358333Seric munchstring(p, delimptr) 83410327Seric register char *p; 83558333Seric char **delimptr; 83610327Seric { 83710327Seric register char *q; 83810327Seric bool backslash = FALSE; 83910327Seric bool quotemode = FALSE; 84010327Seric static char buf[MAXLINE]; 8414096Seric 84210327Seric for (q = buf; *p != '\0'; p++) 8434096Seric { 84410327Seric if (backslash) 84510327Seric { 84610327Seric /* everything is roughly literal */ 84710357Seric backslash = FALSE; 84810327Seric switch (*p) 84910327Seric { 85010327Seric case 'r': /* carriage return */ 85110327Seric *q++ = '\r'; 85210327Seric continue; 85310327Seric 85410327Seric case 'n': /* newline */ 85510327Seric *q++ = '\n'; 85610327Seric continue; 85710327Seric 85810327Seric case 'f': /* form feed */ 85910327Seric *q++ = '\f'; 86010327Seric continue; 86110327Seric 86210327Seric case 'b': /* backspace */ 86310327Seric *q++ = '\b'; 86410327Seric continue; 86510327Seric } 86610327Seric *q++ = *p; 86710327Seric } 86810327Seric else 86910327Seric { 87010327Seric if (*p == '\\') 87110327Seric backslash = TRUE; 87210327Seric else if (*p == '"') 87310327Seric quotemode = !quotemode; 87410327Seric else if (quotemode || *p != ',') 87510327Seric *q++ = *p; 87610327Seric else 87710327Seric break; 87810327Seric } 8794096Seric } 8804096Seric 88158333Seric if (delimptr != NULL) 88258333Seric *delimptr = p; 88310327Seric *q++ = '\0'; 88410327Seric return (buf); 88510327Seric } 88610327Seric /* 88710327Seric ** MAKEARGV -- break up a string into words 88810327Seric ** 88910327Seric ** Parameters: 89010327Seric ** p -- the string to break up. 89110327Seric ** 89210327Seric ** Returns: 89310327Seric ** a char **argv (dynamically allocated) 89410327Seric ** 89510327Seric ** Side Effects: 89610327Seric ** munges p. 89710327Seric */ 8984096Seric 89910327Seric char ** 90010327Seric makeargv(p) 90110327Seric register char *p; 90210327Seric { 90310327Seric char *q; 90410327Seric int i; 90510327Seric char **avp; 90610327Seric char *argv[MAXPV + 1]; 90710327Seric 90810327Seric /* take apart the words */ 90910327Seric i = 0; 91010327Seric while (*p != '\0' && i < MAXPV) 9114096Seric { 91210327Seric q = p; 91358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 91410327Seric p++; 91558050Seric while (isascii(*p) && isspace(*p)) 91610327Seric *p++ = '\0'; 91710327Seric argv[i++] = newstr(q); 9184096Seric } 91910327Seric argv[i++] = NULL; 9204096Seric 92110327Seric /* now make a copy of the argv */ 92210327Seric avp = (char **) xalloc(sizeof *avp * i); 92316893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 92410327Seric 92510327Seric return (avp); 9263308Seric } 9273308Seric /* 9283308Seric ** PRINTRULES -- print rewrite rules (for debugging) 9293308Seric ** 9303308Seric ** Parameters: 9313308Seric ** none. 9323308Seric ** 9333308Seric ** Returns: 9343308Seric ** none. 9353308Seric ** 9363308Seric ** Side Effects: 9373308Seric ** prints rewrite rules. 9383308Seric */ 9393308Seric 9403308Seric printrules() 9413308Seric { 9423308Seric register struct rewrite *rwp; 9434072Seric register int ruleset; 9443308Seric 9454072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9463308Seric { 9474072Seric if (RewriteRules[ruleset] == NULL) 9484072Seric continue; 9498067Seric printf("\n----Rule Set %d:", ruleset); 9503308Seric 9514072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9523308Seric { 9538067Seric printf("\nLHS:"); 9548067Seric printav(rwp->r_lhs); 9558067Seric printf("RHS:"); 9568067Seric printav(rwp->r_rhs); 9573308Seric } 9583308Seric } 9593308Seric } 9604319Seric 9614096Seric /* 9628256Seric ** SETOPTION -- set global processing option 9638256Seric ** 9648256Seric ** Parameters: 9658256Seric ** opt -- option name. 9668256Seric ** val -- option value (as a text string). 96721755Seric ** safe -- set if this came from a configuration file. 96821755Seric ** Some options (if set from the command line) will 96921755Seric ** reset the user id to avoid security problems. 9708269Seric ** sticky -- if set, don't let other setoptions override 9718269Seric ** this value. 97258734Seric ** e -- the main envelope. 9738256Seric ** 9748256Seric ** Returns: 9758256Seric ** none. 9768256Seric ** 9778256Seric ** Side Effects: 9788256Seric ** Sets options as implied by the arguments. 9798256Seric */ 9808256Seric 98110687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9828269Seric 98357207Seric 98457207Seric #ifdef NAMED_BIND 98557207Seric 98657207Seric struct resolverflags 98757207Seric { 98857207Seric char *rf_name; /* name of the flag */ 98957207Seric long rf_bits; /* bits to set/clear */ 99057207Seric } ResolverFlags[] = 99157207Seric { 99257207Seric "debug", RES_DEBUG, 99357207Seric "aaonly", RES_AAONLY, 99457207Seric "usevc", RES_USEVC, 99557207Seric "primary", RES_PRIMARY, 99657207Seric "igntc", RES_IGNTC, 99757207Seric "recurse", RES_RECURSE, 99857207Seric "defnames", RES_DEFNAMES, 99957207Seric "stayopen", RES_STAYOPEN, 100057207Seric "dnsrch", RES_DNSRCH, 100157207Seric NULL, 0 100257207Seric }; 100357207Seric 100457207Seric #endif 100557207Seric 100658734Seric setoption(opt, val, safe, sticky, e) 10078256Seric char opt; 10088256Seric char *val; 100921755Seric bool safe; 10108269Seric bool sticky; 101158734Seric register ENVELOPE *e; 10128256Seric { 101357207Seric register char *p; 10148265Seric extern bool atobool(); 101512633Seric extern time_t convtime(); 101614879Seric extern int QueueLA; 101714879Seric extern int RefuseLA; 101864718Seric extern bool Warn_Q_option; 101917474Seric extern bool trusteduser(); 10208256Seric 10218256Seric if (tTd(37, 1)) 10229341Seric printf("setoption %c=%s", opt, val); 10238256Seric 10248256Seric /* 10258269Seric ** See if this option is preset for us. 10268256Seric */ 10278256Seric 102859731Seric if (!sticky && bitnset(opt, StickyOpt)) 10298269Seric { 10309341Seric if (tTd(37, 1)) 10319341Seric printf(" (ignored)\n"); 10328269Seric return; 10338269Seric } 10348269Seric 103521755Seric /* 103621755Seric ** Check to see if this option can be specified by this user. 103721755Seric */ 103821755Seric 103963787Seric if (!safe && RealUid == 0) 104021755Seric safe = TRUE; 104163837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 104221755Seric { 104339111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 104421755Seric { 104536582Sbostic if (tTd(37, 1)) 104636582Sbostic printf(" (unsafe)"); 104763787Seric if (RealUid != geteuid()) 104836582Sbostic { 104951210Seric if (tTd(37, 1)) 105051210Seric printf("(Resetting uid)"); 105163787Seric (void) setgid(RealGid); 105263787Seric (void) setuid(RealUid); 105336582Sbostic } 105421755Seric } 105521755Seric } 105651210Seric if (tTd(37, 1)) 105717985Seric printf("\n"); 10588269Seric 10598256Seric switch (opt) 10608256Seric { 106159709Seric case '7': /* force seven-bit input */ 106259709Seric SevenBit = atobool(val); 106352106Seric break; 106452106Seric 10658256Seric case 'A': /* set default alias file */ 10669381Seric if (val[0] == '\0') 106759672Seric setalias("aliases"); 10689381Seric else 106959672Seric setalias(val); 10708256Seric break; 10718256Seric 107217474Seric case 'a': /* look N minutes for "@:@" in alias file */ 107317474Seric if (val[0] == '\0') 107464796Seric SafeAlias = 5 * 60; /* five minutes */ 107517474Seric else 107664796Seric SafeAlias = convtime(val, 'm'); 107717474Seric break; 107817474Seric 107916843Seric case 'B': /* substitution for blank character */ 108016843Seric SpaceSub = val[0]; 108116843Seric if (SpaceSub == '\0') 108216843Seric SpaceSub = ' '; 108316843Seric break; 108416843Seric 108559283Seric case 'b': /* min blocks free on queue fs/max msg size */ 108659283Seric p = strchr(val, '/'); 108759283Seric if (p != NULL) 108859283Seric { 108959283Seric *p++ = '\0'; 109059283Seric MaxMessageSize = atol(p); 109159283Seric } 109258082Seric MinBlocksFree = atol(val); 109358082Seric break; 109458082Seric 10959284Seric case 'c': /* don't connect to "expensive" mailers */ 10969381Seric NoConnect = atobool(val); 10979284Seric break; 10989284Seric 109951305Seric case 'C': /* checkpoint every N addresses */ 110051305Seric CheckpointInterval = atoi(val); 110124944Seric break; 110224944Seric 11039284Seric case 'd': /* delivery mode */ 11049284Seric switch (*val) 11058269Seric { 11069284Seric case '\0': 110758734Seric e->e_sendmode = SM_DELIVER; 11088269Seric break; 11098269Seric 111010755Seric case SM_QUEUE: /* queue only */ 111110755Seric #ifndef QUEUE 111210755Seric syserr("need QUEUE to set -odqueue"); 111356795Seric #endif /* QUEUE */ 111410755Seric /* fall through..... */ 111510755Seric 11169284Seric case SM_DELIVER: /* do everything */ 11179284Seric case SM_FORK: /* fork after verification */ 111858734Seric e->e_sendmode = *val; 11198269Seric break; 11208269Seric 11218269Seric default: 11229284Seric syserr("Unknown delivery mode %c", *val); 11238269Seric exit(EX_USAGE); 11248269Seric } 11258269Seric break; 11268269Seric 11279146Seric case 'D': /* rebuild alias database as needed */ 11289381Seric AutoRebuild = atobool(val); 11299146Seric break; 11309146Seric 113155372Seric case 'E': /* error message header/header file */ 113255379Seric if (*val != '\0') 113355379Seric ErrMsgFile = newstr(val); 113455372Seric break; 113555372Seric 11368269Seric case 'e': /* set error processing mode */ 11378269Seric switch (*val) 11388269Seric { 11399381Seric case EM_QUIET: /* be silent about it */ 11409381Seric case EM_MAIL: /* mail back */ 11419381Seric case EM_BERKNET: /* do berknet error processing */ 11429381Seric case EM_WRITE: /* write back (or mail) */ 11438269Seric HoldErrs = TRUE; 11449381Seric /* fall through... */ 11458269Seric 11469381Seric case EM_PRINT: /* print errors normally (default) */ 114758734Seric e->e_errormode = *val; 11488269Seric break; 11498269Seric } 11508269Seric break; 11518269Seric 11529049Seric case 'F': /* file mode */ 115317975Seric FileMode = atooct(val) & 0777; 11549049Seric break; 11559049Seric 11568269Seric case 'f': /* save Unix-style From lines on front */ 11579381Seric SaveFrom = atobool(val); 11588269Seric break; 11598269Seric 116053735Seric case 'G': /* match recipients against GECOS field */ 116153735Seric MatchGecos = atobool(val); 116253735Seric break; 116353735Seric 11648256Seric case 'g': /* default gid */ 116564133Seric if (isascii(*val) && isdigit(*val)) 116664133Seric DefGid = atoi(val); 116764133Seric else 116864133Seric { 116964133Seric register struct group *gr; 117064133Seric 117164133Seric DefGid = -1; 117264133Seric gr = getgrnam(val); 117364133Seric if (gr == NULL) 117464133Seric syserr("readcf: option g: unknown group %s", val); 117564133Seric else 117664133Seric DefGid = gr->gr_gid; 117764133Seric } 11788256Seric break; 11798256Seric 11808256Seric case 'H': /* help file */ 11819381Seric if (val[0] == '\0') 11828269Seric HelpFile = "sendmail.hf"; 11839381Seric else 11849381Seric HelpFile = newstr(val); 11858256Seric break; 11868256Seric 118751305Seric case 'h': /* maximum hop count */ 118851305Seric MaxHopCount = atoi(val); 118951305Seric break; 119051305Seric 119135651Seric case 'I': /* use internet domain name server */ 119257207Seric #ifdef NAMED_BIND 119357207Seric UseNameServer = TRUE; 119457207Seric for (p = val; *p != 0; ) 119557207Seric { 119657207Seric bool clearmode; 119757207Seric char *q; 119857207Seric struct resolverflags *rfp; 119957207Seric 120057207Seric while (*p == ' ') 120157207Seric p++; 120257207Seric if (*p == '\0') 120357207Seric break; 120457207Seric clearmode = FALSE; 120557207Seric if (*p == '-') 120657207Seric clearmode = TRUE; 120757207Seric else if (*p != '+') 120857207Seric p--; 120957207Seric p++; 121057207Seric q = p; 121158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 121257207Seric p++; 121357207Seric if (*p != '\0') 121457207Seric *p++ = '\0'; 121557207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 121657207Seric { 121757207Seric if (strcasecmp(q, rfp->rf_name) == 0) 121857207Seric break; 121957207Seric } 122064923Seric if (rfp->rf_name == NULL) 122164923Seric syserr("readcf: I option value %s unrecognized", q); 122264923Seric else if (clearmode) 122357207Seric _res.options &= ~rfp->rf_bits; 122457207Seric else 122557207Seric _res.options |= rfp->rf_bits; 122657207Seric } 122757207Seric if (tTd(8, 2)) 122857207Seric printf("_res.options = %x\n", _res.options); 122957207Seric #else 123057207Seric usrerr("name server (I option) specified but BIND not compiled in"); 123157207Seric #endif 123235651Seric break; 123335651Seric 12348269Seric case 'i': /* ignore dot lines in message */ 12359381Seric IgnrDot = atobool(val); 12368269Seric break; 12378269Seric 123859730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 123959730Seric SendMIMEErrors = atobool(val); 124059730Seric break; 124159730Seric 124257136Seric case 'J': /* .forward search path */ 124357136Seric ForwardPath = newstr(val); 124457136Seric break; 124557136Seric 124654967Seric case 'k': /* connection cache size */ 124754967Seric MaxMciCache = atoi(val); 124856215Seric if (MaxMciCache < 0) 124956215Seric MaxMciCache = 0; 125054967Seric break; 125154967Seric 125254967Seric case 'K': /* connection cache timeout */ 125358796Seric MciCacheTimeout = convtime(val, 'm'); 125454967Seric break; 125554967Seric 125661104Seric case 'l': /* use Errors-To: header */ 125761104Seric UseErrorsTo = atobool(val); 125861104Seric break; 125961104Seric 12608256Seric case 'L': /* log level */ 126164140Seric if (safe || LogLevel < atoi(val)) 126264140Seric LogLevel = atoi(val); 12638256Seric break; 12648256Seric 12658269Seric case 'M': /* define macro */ 12669381Seric define(val[0], newstr(&val[1]), CurEnv); 126716878Seric sticky = FALSE; 12688269Seric break; 12698269Seric 12708269Seric case 'm': /* send to me too */ 12719381Seric MeToo = atobool(val); 12728269Seric break; 12738269Seric 127425820Seric case 'n': /* validate RHS in newaliases */ 127525820Seric CheckAliases = atobool(val); 127625820Seric break; 127725820Seric 127861104Seric /* 'N' available -- was "net name" */ 127961104Seric 128058851Seric case 'O': /* daemon options */ 128158851Seric setdaemonoptions(val); 128258851Seric break; 128358851Seric 12848269Seric case 'o': /* assume old style headers */ 12859381Seric if (atobool(val)) 12869341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12879341Seric else 12889341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12898269Seric break; 12908269Seric 129158082Seric case 'p': /* select privacy level */ 129258082Seric p = val; 129358082Seric for (;;) 129458082Seric { 129558082Seric register struct prival *pv; 129658082Seric extern struct prival PrivacyValues[]; 129758082Seric 129858082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 129958082Seric p++; 130058082Seric if (*p == '\0') 130158082Seric break; 130258082Seric val = p; 130358082Seric while (isascii(*p) && isalnum(*p)) 130458082Seric p++; 130558082Seric if (*p != '\0') 130658082Seric *p++ = '\0'; 130758082Seric 130858082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 130958082Seric { 131058082Seric if (strcasecmp(val, pv->pv_name) == 0) 131158082Seric break; 131258082Seric } 131358886Seric if (pv->pv_name == NULL) 131458886Seric syserr("readcf: Op line: %s unrecognized", val); 131558082Seric PrivacyFlags |= pv->pv_flag; 131658082Seric } 131758082Seric break; 131858082Seric 131924944Seric case 'P': /* postmaster copy address for returned mail */ 132024944Seric PostMasterCopy = newstr(val); 132124944Seric break; 132224944Seric 132324944Seric case 'q': /* slope of queue only function */ 132424944Seric QueueFactor = atoi(val); 132524944Seric break; 132624944Seric 13278256Seric case 'Q': /* queue directory */ 13289381Seric if (val[0] == '\0') 13298269Seric QueueDir = "mqueue"; 13309381Seric else 13319381Seric QueueDir = newstr(val); 133258789Seric if (RealUid != 0 && !safe) 133364718Seric Warn_Q_option = TRUE; 13348256Seric break; 13358256Seric 133658148Seric case 'R': /* don't prune routes */ 133758148Seric DontPruneRoutes = atobool(val); 133858148Seric break; 133958148Seric 13408256Seric case 'r': /* read timeout */ 134158112Seric settimeouts(val); 13428256Seric break; 13438256Seric 13448256Seric case 'S': /* status file */ 13459381Seric if (val[0] == '\0') 13468269Seric StatFile = "sendmail.st"; 13479381Seric else 13489381Seric StatFile = newstr(val); 13498256Seric break; 13508256Seric 13518265Seric case 's': /* be super safe, even if expensive */ 13529381Seric SuperSafe = atobool(val); 13538256Seric break; 13548256Seric 13558256Seric case 'T': /* queue timeout */ 135658737Seric p = strchr(val, '/'); 135758737Seric if (p != NULL) 135858737Seric { 135958737Seric *p++ = '\0'; 136058796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 136158737Seric } 136258796Seric TimeOuts.to_q_return = convtime(val, 'h'); 136354967Seric break; 13648256Seric 13658265Seric case 't': /* time zone name */ 136652106Seric TimeZoneSpec = newstr(val); 13678265Seric break; 13688265Seric 136950556Seric case 'U': /* location of user database */ 137051360Seric UdbSpec = newstr(val); 137150556Seric break; 137250556Seric 13738256Seric case 'u': /* set default uid */ 137464133Seric if (isascii(*val) && isdigit(*val)) 137564133Seric DefUid = atoi(val); 137664133Seric else 137764133Seric { 137864133Seric register struct passwd *pw; 137964133Seric 138064133Seric DefUid = -1; 138164133Seric pw = getpwnam(val); 138264133Seric if (pw == NULL) 138364133Seric syserr("readcf: option u: unknown user %s", val); 138464133Seric else 138564133Seric DefUid = pw->pw_uid; 138664133Seric } 138740973Sbostic setdefuser(); 13888256Seric break; 13898256Seric 139058851Seric case 'V': /* fallback MX host */ 139158851Seric FallBackMX = newstr(val); 139258851Seric break; 139358851Seric 13948269Seric case 'v': /* run in verbose mode */ 13959381Seric Verbose = atobool(val); 13968256Seric break; 13978256Seric 139863837Seric case 'w': /* if we are best MX, try host directly */ 139963837Seric TryNullMXList = atobool(val); 140063837Seric break; 140161104Seric 140261104Seric /* 'W' available -- was wizard password */ 140361104Seric 140414879Seric case 'x': /* load avg at which to auto-queue msgs */ 140514879Seric QueueLA = atoi(val); 140614879Seric break; 140714879Seric 140814879Seric case 'X': /* load avg at which to auto-reject connections */ 140914879Seric RefuseLA = atoi(val); 141014879Seric break; 141114879Seric 141224981Seric case 'y': /* work recipient factor */ 141324981Seric WkRecipFact = atoi(val); 141424981Seric break; 141524981Seric 141624981Seric case 'Y': /* fork jobs during queue runs */ 141724952Seric ForkQueueRuns = atobool(val); 141824952Seric break; 141924952Seric 142024981Seric case 'z': /* work message class factor */ 142124981Seric WkClassFact = atoi(val); 142224981Seric break; 142324981Seric 142424981Seric case 'Z': /* work time factor */ 142524981Seric WkTimeFact = atoi(val); 142624981Seric break; 142724981Seric 14288256Seric default: 14298256Seric break; 14308256Seric } 143116878Seric if (sticky) 143216878Seric setbitn(opt, StickyOpt); 14339188Seric return; 14348256Seric } 143510687Seric /* 143610687Seric ** SETCLASS -- set a word into a class 143710687Seric ** 143810687Seric ** Parameters: 143910687Seric ** class -- the class to put the word in. 144010687Seric ** word -- the word to enter 144110687Seric ** 144210687Seric ** Returns: 144310687Seric ** none. 144410687Seric ** 144510687Seric ** Side Effects: 144610687Seric ** puts the word into the symbol table. 144710687Seric */ 144810687Seric 144910687Seric setclass(class, word) 145010687Seric int class; 145110687Seric char *word; 145210687Seric { 145310687Seric register STAB *s; 145410687Seric 145557943Seric if (tTd(37, 8)) 145664326Seric printf("setclass(%c, %s)\n", class, word); 145710687Seric s = stab(word, ST_CLASS, ST_ENTER); 145810687Seric setbitn(class, s->s_class); 145910687Seric } 146053654Seric /* 146153654Seric ** MAKEMAPENTRY -- create a map entry 146253654Seric ** 146353654Seric ** Parameters: 146453654Seric ** line -- the config file line 146553654Seric ** 146653654Seric ** Returns: 146753654Seric ** TRUE if it successfully entered the map entry. 146853654Seric ** FALSE otherwise (usually syntax error). 146953654Seric ** 147053654Seric ** Side Effects: 147153654Seric ** Enters the map into the dictionary. 147253654Seric */ 147353654Seric 147453654Seric void 147553654Seric makemapentry(line) 147653654Seric char *line; 147753654Seric { 147853654Seric register char *p; 147953654Seric char *mapname; 148053654Seric char *classname; 148164078Seric register STAB *s; 148253654Seric STAB *class; 148353654Seric 148458050Seric for (p = line; isascii(*p) && isspace(*p); p++) 148553654Seric continue; 148658050Seric if (!(isascii(*p) && isalnum(*p))) 148753654Seric { 148853654Seric syserr("readcf: config K line: no map name"); 148953654Seric return; 149053654Seric } 149153654Seric 149253654Seric mapname = p; 149358050Seric while (isascii(*++p) && isalnum(*p)) 149453654Seric continue; 149553654Seric if (*p != '\0') 149653654Seric *p++ = '\0'; 149758050Seric while (isascii(*p) && isspace(*p)) 149853654Seric p++; 149958050Seric if (!(isascii(*p) && isalnum(*p))) 150053654Seric { 150153654Seric syserr("readcf: config K line, map %s: no map class", mapname); 150253654Seric return; 150353654Seric } 150453654Seric classname = p; 150558050Seric while (isascii(*++p) && isalnum(*p)) 150653654Seric continue; 150753654Seric if (*p != '\0') 150853654Seric *p++ = '\0'; 150958050Seric while (isascii(*p) && isspace(*p)) 151053654Seric p++; 151153654Seric 151253654Seric /* look up the class */ 151353654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 151453654Seric if (class == NULL) 151553654Seric { 151653654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 151753654Seric return; 151853654Seric } 151953654Seric 152053654Seric /* enter the map */ 152164078Seric s = stab(mapname, ST_MAP, ST_ENTER); 152264078Seric s->s_map.map_class = &class->s_mapclass; 152364078Seric s->s_map.map_mname = newstr(mapname); 152453654Seric 152564078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 152664078Seric s->s_map.map_mflags |= MF_VALID; 152764078Seric 152864078Seric if (tTd(37, 5)) 152964078Seric { 153064078Seric printf("map %s, class %s, flags %x, file %s,\n", 153164078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 153264078Seric s->s_map.map_mflags, 153364078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 153464078Seric printf("\tapp %s, domain %s, rebuild %s\n", 153564078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 153664078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 153764078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 153864078Seric } 153953654Seric } 154058112Seric /* 154158112Seric ** SETTIMEOUTS -- parse and set timeout values 154258112Seric ** 154358112Seric ** Parameters: 154458112Seric ** val -- a pointer to the values. If NULL, do initial 154558112Seric ** settings. 154658112Seric ** 154758112Seric ** Returns: 154858112Seric ** none. 154958112Seric ** 155058112Seric ** Side Effects: 155158112Seric ** Initializes the TimeOuts structure 155258112Seric */ 155358112Seric 155464255Seric #define SECONDS 155558112Seric #define MINUTES * 60 155658112Seric #define HOUR * 3600 155758112Seric 155858112Seric settimeouts(val) 155958112Seric register char *val; 156058112Seric { 156158112Seric register char *p; 156258671Seric extern time_t convtime(); 156358112Seric 156458112Seric if (val == NULL) 156558112Seric { 156658112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 156758112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 156858112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 156958112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 157058112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 157158112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 157258112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 157358112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 157458112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 157558112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 157658112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 157764255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 157858112Seric return; 157958112Seric } 158058112Seric 158158112Seric for (;; val = p) 158258112Seric { 158358112Seric while (isascii(*val) && isspace(*val)) 158458112Seric val++; 158558112Seric if (*val == '\0') 158658112Seric break; 158758112Seric for (p = val; *p != '\0' && *p != ','; p++) 158858112Seric continue; 158958112Seric if (*p != '\0') 159058112Seric *p++ = '\0'; 159158112Seric 159258112Seric if (isascii(*val) && isdigit(*val)) 159358112Seric { 159458112Seric /* old syntax -- set everything */ 159558796Seric TimeOuts.to_mail = convtime(val, 'm'); 159658112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 159758112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 159858112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 159958112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 160058112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 160158112Seric continue; 160258112Seric } 160358112Seric else 160458112Seric { 160558112Seric register char *q = strchr(val, '='); 160658112Seric time_t to; 160758112Seric 160858112Seric if (q == NULL) 160958112Seric { 161058112Seric /* syntax error */ 161158112Seric continue; 161258112Seric } 161358112Seric *q++ = '\0'; 161458796Seric to = convtime(q, 'm'); 161558112Seric 161658112Seric if (strcasecmp(val, "initial") == 0) 161758112Seric TimeOuts.to_initial = to; 161858112Seric else if (strcasecmp(val, "mail") == 0) 161958112Seric TimeOuts.to_mail = to; 162058112Seric else if (strcasecmp(val, "rcpt") == 0) 162158112Seric TimeOuts.to_rcpt = to; 162258112Seric else if (strcasecmp(val, "datainit") == 0) 162358112Seric TimeOuts.to_datainit = to; 162458112Seric else if (strcasecmp(val, "datablock") == 0) 162558112Seric TimeOuts.to_datablock = to; 162658112Seric else if (strcasecmp(val, "datafinal") == 0) 162758112Seric TimeOuts.to_datafinal = to; 162858112Seric else if (strcasecmp(val, "command") == 0) 162958112Seric TimeOuts.to_nextcommand = to; 163058112Seric else if (strcasecmp(val, "rset") == 0) 163158112Seric TimeOuts.to_rset = to; 163258112Seric else if (strcasecmp(val, "helo") == 0) 163358112Seric TimeOuts.to_helo = to; 163458112Seric else if (strcasecmp(val, "quit") == 0) 163558112Seric TimeOuts.to_quit = to; 163658112Seric else if (strcasecmp(val, "misc") == 0) 163758112Seric TimeOuts.to_miscshort = to; 163864255Seric else if (strcasecmp(val, "ident") == 0) 163964255Seric TimeOuts.to_ident = to; 164058112Seric else 164158112Seric syserr("settimeouts: invalid timeout %s", val); 164258112Seric } 164358112Seric } 164458112Seric } 1645