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*65583Seric static char sccsid[] = "@(#)readcf.c 8.18 (Berkeley) 01/09/94"; 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]; 8665066Seric 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); 21865066Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, 21965066Seric 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); 30365066Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, 30465066Seric 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, 1001*65583Seric "true", 0, /* to avoid error on old syntax */ 100257207Seric NULL, 0 100357207Seric }; 100457207Seric 100557207Seric #endif 100657207Seric 100758734Seric setoption(opt, val, safe, sticky, e) 10088256Seric char opt; 10098256Seric char *val; 101021755Seric bool safe; 10118269Seric bool sticky; 101258734Seric register ENVELOPE *e; 10138256Seric { 101457207Seric register char *p; 10158265Seric extern bool atobool(); 101612633Seric extern time_t convtime(); 101714879Seric extern int QueueLA; 101814879Seric extern int RefuseLA; 101964718Seric extern bool Warn_Q_option; 102017474Seric extern bool trusteduser(); 10218256Seric 10228256Seric if (tTd(37, 1)) 10239341Seric printf("setoption %c=%s", opt, val); 10248256Seric 10258256Seric /* 10268269Seric ** See if this option is preset for us. 10278256Seric */ 10288256Seric 102959731Seric if (!sticky && bitnset(opt, StickyOpt)) 10308269Seric { 10319341Seric if (tTd(37, 1)) 10329341Seric printf(" (ignored)\n"); 10338269Seric return; 10348269Seric } 10358269Seric 103621755Seric /* 103721755Seric ** Check to see if this option can be specified by this user. 103821755Seric */ 103921755Seric 104063787Seric if (!safe && RealUid == 0) 104121755Seric safe = TRUE; 104263837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 104321755Seric { 104439111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 104521755Seric { 104636582Sbostic if (tTd(37, 1)) 104736582Sbostic printf(" (unsafe)"); 104863787Seric if (RealUid != geteuid()) 104936582Sbostic { 105051210Seric if (tTd(37, 1)) 105151210Seric printf("(Resetting uid)"); 105263787Seric (void) setgid(RealGid); 105363787Seric (void) setuid(RealUid); 105436582Sbostic } 105521755Seric } 105621755Seric } 105751210Seric if (tTd(37, 1)) 105817985Seric printf("\n"); 10598269Seric 10608256Seric switch (opt) 10618256Seric { 106259709Seric case '7': /* force seven-bit input */ 106359709Seric SevenBit = atobool(val); 106452106Seric break; 106552106Seric 10668256Seric case 'A': /* set default alias file */ 10679381Seric if (val[0] == '\0') 106859672Seric setalias("aliases"); 10699381Seric else 107059672Seric setalias(val); 10718256Seric break; 10728256Seric 107317474Seric case 'a': /* look N minutes for "@:@" in alias file */ 107417474Seric if (val[0] == '\0') 107564796Seric SafeAlias = 5 * 60; /* five minutes */ 107617474Seric else 107764796Seric SafeAlias = convtime(val, 'm'); 107817474Seric break; 107917474Seric 108016843Seric case 'B': /* substitution for blank character */ 108116843Seric SpaceSub = val[0]; 108216843Seric if (SpaceSub == '\0') 108316843Seric SpaceSub = ' '; 108416843Seric break; 108516843Seric 108659283Seric case 'b': /* min blocks free on queue fs/max msg size */ 108759283Seric p = strchr(val, '/'); 108859283Seric if (p != NULL) 108959283Seric { 109059283Seric *p++ = '\0'; 109159283Seric MaxMessageSize = atol(p); 109259283Seric } 109358082Seric MinBlocksFree = atol(val); 109458082Seric break; 109558082Seric 10969284Seric case 'c': /* don't connect to "expensive" mailers */ 10979381Seric NoConnect = atobool(val); 10989284Seric break; 10999284Seric 110051305Seric case 'C': /* checkpoint every N addresses */ 110151305Seric CheckpointInterval = atoi(val); 110224944Seric break; 110324944Seric 11049284Seric case 'd': /* delivery mode */ 11059284Seric switch (*val) 11068269Seric { 11079284Seric case '\0': 110858734Seric e->e_sendmode = SM_DELIVER; 11098269Seric break; 11108269Seric 111110755Seric case SM_QUEUE: /* queue only */ 111210755Seric #ifndef QUEUE 111310755Seric syserr("need QUEUE to set -odqueue"); 111456795Seric #endif /* QUEUE */ 111510755Seric /* fall through..... */ 111610755Seric 11179284Seric case SM_DELIVER: /* do everything */ 11189284Seric case SM_FORK: /* fork after verification */ 111958734Seric e->e_sendmode = *val; 11208269Seric break; 11218269Seric 11228269Seric default: 11239284Seric syserr("Unknown delivery mode %c", *val); 11248269Seric exit(EX_USAGE); 11258269Seric } 11268269Seric break; 11278269Seric 11289146Seric case 'D': /* rebuild alias database as needed */ 11299381Seric AutoRebuild = atobool(val); 11309146Seric break; 11319146Seric 113255372Seric case 'E': /* error message header/header file */ 113355379Seric if (*val != '\0') 113455379Seric ErrMsgFile = newstr(val); 113555372Seric break; 113655372Seric 11378269Seric case 'e': /* set error processing mode */ 11388269Seric switch (*val) 11398269Seric { 11409381Seric case EM_QUIET: /* be silent about it */ 11419381Seric case EM_MAIL: /* mail back */ 11429381Seric case EM_BERKNET: /* do berknet error processing */ 11439381Seric case EM_WRITE: /* write back (or mail) */ 11448269Seric HoldErrs = TRUE; 11459381Seric /* fall through... */ 11468269Seric 11479381Seric case EM_PRINT: /* print errors normally (default) */ 114858734Seric e->e_errormode = *val; 11498269Seric break; 11508269Seric } 11518269Seric break; 11528269Seric 11539049Seric case 'F': /* file mode */ 115417975Seric FileMode = atooct(val) & 0777; 11559049Seric break; 11569049Seric 11578269Seric case 'f': /* save Unix-style From lines on front */ 11589381Seric SaveFrom = atobool(val); 11598269Seric break; 11608269Seric 116153735Seric case 'G': /* match recipients against GECOS field */ 116253735Seric MatchGecos = atobool(val); 116353735Seric break; 116453735Seric 11658256Seric case 'g': /* default gid */ 116664133Seric if (isascii(*val) && isdigit(*val)) 116764133Seric DefGid = atoi(val); 116864133Seric else 116964133Seric { 117064133Seric register struct group *gr; 117164133Seric 117264133Seric DefGid = -1; 117364133Seric gr = getgrnam(val); 117464133Seric if (gr == NULL) 117564133Seric syserr("readcf: option g: unknown group %s", val); 117664133Seric else 117764133Seric DefGid = gr->gr_gid; 117864133Seric } 11798256Seric break; 11808256Seric 11818256Seric case 'H': /* help file */ 11829381Seric if (val[0] == '\0') 11838269Seric HelpFile = "sendmail.hf"; 11849381Seric else 11859381Seric HelpFile = newstr(val); 11868256Seric break; 11878256Seric 118851305Seric case 'h': /* maximum hop count */ 118951305Seric MaxHopCount = atoi(val); 119051305Seric break; 119151305Seric 119235651Seric case 'I': /* use internet domain name server */ 119357207Seric #ifdef NAMED_BIND 119457207Seric UseNameServer = TRUE; 119557207Seric for (p = val; *p != 0; ) 119657207Seric { 119757207Seric bool clearmode; 119857207Seric char *q; 119957207Seric struct resolverflags *rfp; 120057207Seric 120157207Seric while (*p == ' ') 120257207Seric p++; 120357207Seric if (*p == '\0') 120457207Seric break; 120557207Seric clearmode = FALSE; 120657207Seric if (*p == '-') 120757207Seric clearmode = TRUE; 120857207Seric else if (*p != '+') 120957207Seric p--; 121057207Seric p++; 121157207Seric q = p; 121258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 121357207Seric p++; 121457207Seric if (*p != '\0') 121557207Seric *p++ = '\0'; 121657207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 121757207Seric { 121857207Seric if (strcasecmp(q, rfp->rf_name) == 0) 121957207Seric break; 122057207Seric } 122164923Seric if (rfp->rf_name == NULL) 122264923Seric syserr("readcf: I option value %s unrecognized", q); 122364923Seric else if (clearmode) 122457207Seric _res.options &= ~rfp->rf_bits; 122557207Seric else 122657207Seric _res.options |= rfp->rf_bits; 122757207Seric } 122857207Seric if (tTd(8, 2)) 122957207Seric printf("_res.options = %x\n", _res.options); 123057207Seric #else 123157207Seric usrerr("name server (I option) specified but BIND not compiled in"); 123257207Seric #endif 123335651Seric break; 123435651Seric 12358269Seric case 'i': /* ignore dot lines in message */ 12369381Seric IgnrDot = atobool(val); 12378269Seric break; 12388269Seric 123959730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 124059730Seric SendMIMEErrors = atobool(val); 124159730Seric break; 124259730Seric 124357136Seric case 'J': /* .forward search path */ 124457136Seric ForwardPath = newstr(val); 124557136Seric break; 124657136Seric 124754967Seric case 'k': /* connection cache size */ 124854967Seric MaxMciCache = atoi(val); 124956215Seric if (MaxMciCache < 0) 125056215Seric MaxMciCache = 0; 125154967Seric break; 125254967Seric 125354967Seric case 'K': /* connection cache timeout */ 125458796Seric MciCacheTimeout = convtime(val, 'm'); 125554967Seric break; 125654967Seric 125761104Seric case 'l': /* use Errors-To: header */ 125861104Seric UseErrorsTo = atobool(val); 125961104Seric break; 126061104Seric 12618256Seric case 'L': /* log level */ 126264140Seric if (safe || LogLevel < atoi(val)) 126364140Seric LogLevel = atoi(val); 12648256Seric break; 12658256Seric 12668269Seric case 'M': /* define macro */ 12679381Seric define(val[0], newstr(&val[1]), CurEnv); 126816878Seric sticky = FALSE; 12698269Seric break; 12708269Seric 12718269Seric case 'm': /* send to me too */ 12729381Seric MeToo = atobool(val); 12738269Seric break; 12748269Seric 127525820Seric case 'n': /* validate RHS in newaliases */ 127625820Seric CheckAliases = atobool(val); 127725820Seric break; 127825820Seric 127961104Seric /* 'N' available -- was "net name" */ 128061104Seric 128158851Seric case 'O': /* daemon options */ 128258851Seric setdaemonoptions(val); 128358851Seric break; 128458851Seric 12858269Seric case 'o': /* assume old style headers */ 12869381Seric if (atobool(val)) 12879341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12889341Seric else 12899341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12908269Seric break; 12918269Seric 129258082Seric case 'p': /* select privacy level */ 129358082Seric p = val; 129458082Seric for (;;) 129558082Seric { 129658082Seric register struct prival *pv; 129758082Seric extern struct prival PrivacyValues[]; 129858082Seric 129958082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 130058082Seric p++; 130158082Seric if (*p == '\0') 130258082Seric break; 130358082Seric val = p; 130458082Seric while (isascii(*p) && isalnum(*p)) 130558082Seric p++; 130658082Seric if (*p != '\0') 130758082Seric *p++ = '\0'; 130858082Seric 130958082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 131058082Seric { 131158082Seric if (strcasecmp(val, pv->pv_name) == 0) 131258082Seric break; 131358082Seric } 131458886Seric if (pv->pv_name == NULL) 131558886Seric syserr("readcf: Op line: %s unrecognized", val); 131658082Seric PrivacyFlags |= pv->pv_flag; 131758082Seric } 131858082Seric break; 131958082Seric 132024944Seric case 'P': /* postmaster copy address for returned mail */ 132124944Seric PostMasterCopy = newstr(val); 132224944Seric break; 132324944Seric 132424944Seric case 'q': /* slope of queue only function */ 132524944Seric QueueFactor = atoi(val); 132624944Seric break; 132724944Seric 13288256Seric case 'Q': /* queue directory */ 13299381Seric if (val[0] == '\0') 13308269Seric QueueDir = "mqueue"; 13319381Seric else 13329381Seric QueueDir = newstr(val); 133358789Seric if (RealUid != 0 && !safe) 133464718Seric Warn_Q_option = TRUE; 13358256Seric break; 13368256Seric 133758148Seric case 'R': /* don't prune routes */ 133858148Seric DontPruneRoutes = atobool(val); 133958148Seric break; 134058148Seric 13418256Seric case 'r': /* read timeout */ 134258112Seric settimeouts(val); 13438256Seric break; 13448256Seric 13458256Seric case 'S': /* status file */ 13469381Seric if (val[0] == '\0') 13478269Seric StatFile = "sendmail.st"; 13489381Seric else 13499381Seric StatFile = newstr(val); 13508256Seric break; 13518256Seric 13528265Seric case 's': /* be super safe, even if expensive */ 13539381Seric SuperSafe = atobool(val); 13548256Seric break; 13558256Seric 13568256Seric case 'T': /* queue timeout */ 135758737Seric p = strchr(val, '/'); 135858737Seric if (p != NULL) 135958737Seric { 136058737Seric *p++ = '\0'; 136158796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 136258737Seric } 136358796Seric TimeOuts.to_q_return = convtime(val, 'h'); 136454967Seric break; 13658256Seric 13668265Seric case 't': /* time zone name */ 136752106Seric TimeZoneSpec = newstr(val); 13688265Seric break; 13698265Seric 137050556Seric case 'U': /* location of user database */ 137151360Seric UdbSpec = newstr(val); 137250556Seric break; 137350556Seric 13748256Seric case 'u': /* set default uid */ 137564133Seric if (isascii(*val) && isdigit(*val)) 137664133Seric DefUid = atoi(val); 137764133Seric else 137864133Seric { 137964133Seric register struct passwd *pw; 138064133Seric 138164133Seric DefUid = -1; 138264133Seric pw = getpwnam(val); 138364133Seric if (pw == NULL) 138464133Seric syserr("readcf: option u: unknown user %s", val); 138564133Seric else 138664133Seric DefUid = pw->pw_uid; 138764133Seric } 138840973Sbostic setdefuser(); 13898256Seric break; 13908256Seric 139158851Seric case 'V': /* fallback MX host */ 139258851Seric FallBackMX = newstr(val); 139358851Seric break; 139458851Seric 13958269Seric case 'v': /* run in verbose mode */ 13969381Seric Verbose = atobool(val); 13978256Seric break; 13988256Seric 139963837Seric case 'w': /* if we are best MX, try host directly */ 140063837Seric TryNullMXList = atobool(val); 140163837Seric break; 140261104Seric 140361104Seric /* 'W' available -- was wizard password */ 140461104Seric 140514879Seric case 'x': /* load avg at which to auto-queue msgs */ 140614879Seric QueueLA = atoi(val); 140714879Seric break; 140814879Seric 140914879Seric case 'X': /* load avg at which to auto-reject connections */ 141014879Seric RefuseLA = atoi(val); 141114879Seric break; 141214879Seric 141324981Seric case 'y': /* work recipient factor */ 141424981Seric WkRecipFact = atoi(val); 141524981Seric break; 141624981Seric 141724981Seric case 'Y': /* fork jobs during queue runs */ 141824952Seric ForkQueueRuns = atobool(val); 141924952Seric break; 142024952Seric 142124981Seric case 'z': /* work message class factor */ 142224981Seric WkClassFact = atoi(val); 142324981Seric break; 142424981Seric 142524981Seric case 'Z': /* work time factor */ 142624981Seric WkTimeFact = atoi(val); 142724981Seric break; 142824981Seric 14298256Seric default: 14308256Seric break; 14318256Seric } 143216878Seric if (sticky) 143316878Seric setbitn(opt, StickyOpt); 14349188Seric return; 14358256Seric } 143610687Seric /* 143710687Seric ** SETCLASS -- set a word into a class 143810687Seric ** 143910687Seric ** Parameters: 144010687Seric ** class -- the class to put the word in. 144110687Seric ** word -- the word to enter 144210687Seric ** 144310687Seric ** Returns: 144410687Seric ** none. 144510687Seric ** 144610687Seric ** Side Effects: 144710687Seric ** puts the word into the symbol table. 144810687Seric */ 144910687Seric 145010687Seric setclass(class, word) 145110687Seric int class; 145210687Seric char *word; 145310687Seric { 145410687Seric register STAB *s; 145510687Seric 145657943Seric if (tTd(37, 8)) 145764326Seric printf("setclass(%c, %s)\n", class, word); 145810687Seric s = stab(word, ST_CLASS, ST_ENTER); 145910687Seric setbitn(class, s->s_class); 146010687Seric } 146153654Seric /* 146253654Seric ** MAKEMAPENTRY -- create a map entry 146353654Seric ** 146453654Seric ** Parameters: 146553654Seric ** line -- the config file line 146653654Seric ** 146753654Seric ** Returns: 146853654Seric ** TRUE if it successfully entered the map entry. 146953654Seric ** FALSE otherwise (usually syntax error). 147053654Seric ** 147153654Seric ** Side Effects: 147253654Seric ** Enters the map into the dictionary. 147353654Seric */ 147453654Seric 147553654Seric void 147653654Seric makemapentry(line) 147753654Seric char *line; 147853654Seric { 147953654Seric register char *p; 148053654Seric char *mapname; 148153654Seric char *classname; 148264078Seric register STAB *s; 148353654Seric STAB *class; 148453654Seric 148558050Seric for (p = line; isascii(*p) && isspace(*p); p++) 148653654Seric continue; 148758050Seric if (!(isascii(*p) && isalnum(*p))) 148853654Seric { 148953654Seric syserr("readcf: config K line: no map name"); 149053654Seric return; 149153654Seric } 149253654Seric 149353654Seric mapname = p; 149458050Seric while (isascii(*++p) && isalnum(*p)) 149553654Seric continue; 149653654Seric if (*p != '\0') 149753654Seric *p++ = '\0'; 149858050Seric while (isascii(*p) && isspace(*p)) 149953654Seric p++; 150058050Seric if (!(isascii(*p) && isalnum(*p))) 150153654Seric { 150253654Seric syserr("readcf: config K line, map %s: no map class", mapname); 150353654Seric return; 150453654Seric } 150553654Seric classname = p; 150658050Seric while (isascii(*++p) && isalnum(*p)) 150753654Seric continue; 150853654Seric if (*p != '\0') 150953654Seric *p++ = '\0'; 151058050Seric while (isascii(*p) && isspace(*p)) 151153654Seric p++; 151253654Seric 151353654Seric /* look up the class */ 151453654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 151553654Seric if (class == NULL) 151653654Seric { 151753654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 151853654Seric return; 151953654Seric } 152053654Seric 152153654Seric /* enter the map */ 152264078Seric s = stab(mapname, ST_MAP, ST_ENTER); 152364078Seric s->s_map.map_class = &class->s_mapclass; 152464078Seric s->s_map.map_mname = newstr(mapname); 152553654Seric 152664078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 152764078Seric s->s_map.map_mflags |= MF_VALID; 152864078Seric 152964078Seric if (tTd(37, 5)) 153064078Seric { 153164078Seric printf("map %s, class %s, flags %x, file %s,\n", 153264078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 153364078Seric s->s_map.map_mflags, 153464078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 153564078Seric printf("\tapp %s, domain %s, rebuild %s\n", 153664078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 153764078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 153864078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 153964078Seric } 154053654Seric } 154158112Seric /* 154258112Seric ** SETTIMEOUTS -- parse and set timeout values 154358112Seric ** 154458112Seric ** Parameters: 154558112Seric ** val -- a pointer to the values. If NULL, do initial 154658112Seric ** settings. 154758112Seric ** 154858112Seric ** Returns: 154958112Seric ** none. 155058112Seric ** 155158112Seric ** Side Effects: 155258112Seric ** Initializes the TimeOuts structure 155358112Seric */ 155458112Seric 155564255Seric #define SECONDS 155658112Seric #define MINUTES * 60 155758112Seric #define HOUR * 3600 155858112Seric 155958112Seric settimeouts(val) 156058112Seric register char *val; 156158112Seric { 156258112Seric register char *p; 156358671Seric extern time_t convtime(); 156458112Seric 156558112Seric if (val == NULL) 156658112Seric { 156758112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 156858112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 156958112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 157058112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 157158112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 157258112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 157358112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 157458112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 157558112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 157658112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 157758112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 157864255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 157958112Seric return; 158058112Seric } 158158112Seric 158258112Seric for (;; val = p) 158358112Seric { 158458112Seric while (isascii(*val) && isspace(*val)) 158558112Seric val++; 158658112Seric if (*val == '\0') 158758112Seric break; 158858112Seric for (p = val; *p != '\0' && *p != ','; p++) 158958112Seric continue; 159058112Seric if (*p != '\0') 159158112Seric *p++ = '\0'; 159258112Seric 159358112Seric if (isascii(*val) && isdigit(*val)) 159458112Seric { 159558112Seric /* old syntax -- set everything */ 159658796Seric TimeOuts.to_mail = convtime(val, 'm'); 159758112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 159858112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 159958112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 160058112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 160158112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 160258112Seric continue; 160358112Seric } 160458112Seric else 160558112Seric { 160658112Seric register char *q = strchr(val, '='); 160758112Seric time_t to; 160858112Seric 160958112Seric if (q == NULL) 161058112Seric { 161158112Seric /* syntax error */ 161258112Seric continue; 161358112Seric } 161458112Seric *q++ = '\0'; 161558796Seric to = convtime(q, 'm'); 161658112Seric 161758112Seric if (strcasecmp(val, "initial") == 0) 161858112Seric TimeOuts.to_initial = to; 161958112Seric else if (strcasecmp(val, "mail") == 0) 162058112Seric TimeOuts.to_mail = to; 162158112Seric else if (strcasecmp(val, "rcpt") == 0) 162258112Seric TimeOuts.to_rcpt = to; 162358112Seric else if (strcasecmp(val, "datainit") == 0) 162458112Seric TimeOuts.to_datainit = to; 162558112Seric else if (strcasecmp(val, "datablock") == 0) 162658112Seric TimeOuts.to_datablock = to; 162758112Seric else if (strcasecmp(val, "datafinal") == 0) 162858112Seric TimeOuts.to_datafinal = to; 162958112Seric else if (strcasecmp(val, "command") == 0) 163058112Seric TimeOuts.to_nextcommand = to; 163158112Seric else if (strcasecmp(val, "rset") == 0) 163258112Seric TimeOuts.to_rset = to; 163358112Seric else if (strcasecmp(val, "helo") == 0) 163458112Seric TimeOuts.to_helo = to; 163558112Seric else if (strcasecmp(val, "quit") == 0) 163658112Seric TimeOuts.to_quit = to; 163758112Seric else if (strcasecmp(val, "misc") == 0) 163858112Seric TimeOuts.to_miscshort = to; 163964255Seric else if (strcasecmp(val, "ident") == 0) 164064255Seric TimeOuts.to_ident = to; 164158112Seric else 164258112Seric syserr("settimeouts: invalid timeout %s", val); 164358112Seric } 164458112Seric } 164558112Seric } 1646