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*64923Seric static char sccsid[] = "@(#)readcf.c 8.15 (Berkeley) 11/20/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]; 8616915Seric char pvpbuf[PSBUFSIZE]; 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); 21858333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 21957589Seric nfuzzy = 0; 2205909Seric if (rwp->r_lhs != NULL) 22157589Seric { 22257589Seric register char **ap; 22357589Seric 2245909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22557589Seric 22657589Seric /* count the number of fuzzy matches in LHS */ 22757589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22857589Seric { 22958148Seric char *botch; 23058148Seric 23158148Seric botch = NULL; 23258050Seric switch (**ap & 0377) 23357589Seric { 23457589Seric case MATCHZANY: 23557589Seric case MATCHANY: 23657589Seric case MATCHONE: 23757589Seric case MATCHCLASS: 23857589Seric case MATCHNCLASS: 23957589Seric nfuzzy++; 24058148Seric break; 24158148Seric 24258148Seric case MATCHREPL: 24358148Seric botch = "$0-$9"; 24458148Seric break; 24558148Seric 24658148Seric case CANONNET: 24758148Seric botch = "$#"; 24858148Seric break; 24958148Seric 25058148Seric case CANONUSER: 25158148Seric botch = "$:"; 25258148Seric break; 25358148Seric 25458148Seric case CALLSUBR: 25558148Seric botch = "$>"; 25658148Seric break; 25758148Seric 25858148Seric case CONDIF: 25958148Seric botch = "$?"; 26058148Seric break; 26158148Seric 26258148Seric case CONDELSE: 26358148Seric botch = "$|"; 26458148Seric break; 26558148Seric 26658148Seric case CONDFI: 26758148Seric botch = "$."; 26858148Seric break; 26958148Seric 27058148Seric case HOSTBEGIN: 27158148Seric botch = "$["; 27258148Seric break; 27358148Seric 27458148Seric case HOSTEND: 27558148Seric botch = "$]"; 27658148Seric break; 27758148Seric 27858148Seric case LOOKUPBEGIN: 27958148Seric botch = "$("; 28058148Seric break; 28158148Seric 28258148Seric case LOOKUPEND: 28358148Seric botch = "$)"; 28458148Seric break; 28557589Seric } 28658148Seric if (botch != NULL) 28758148Seric syserr("Inappropriate use of %s on LHS", 28858148Seric botch); 28957589Seric } 29057589Seric } 29156678Seric else 29256678Seric syserr("R line: null LHS"); 2935909Seric 2945909Seric /* expand and save the RHS */ 2955909Seric while (*++p == '\t') 2965909Seric continue; 2977231Seric q = p; 2987231Seric while (*p != '\0' && *p != '\t') 2997231Seric p++; 3007231Seric *p = '\0'; 30155012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 30258333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 3035909Seric if (rwp->r_rhs != NULL) 30457589Seric { 30557589Seric register char **ap; 30657589Seric 3075909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30857589Seric 30957589Seric /* check no out-of-bounds replacements */ 31057589Seric nfuzzy += '0'; 31157589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31257589Seric { 31358148Seric char *botch; 31458148Seric 31558148Seric botch = NULL; 31658148Seric switch (**ap & 0377) 31757589Seric { 31858148Seric case MATCHREPL: 31958148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32058148Seric { 32158148Seric syserr("replacement $%c out of bounds", 32258148Seric (*ap)[1]); 32358148Seric } 32458148Seric break; 32558148Seric 32658148Seric case MATCHZANY: 32758148Seric botch = "$*"; 32858148Seric break; 32958148Seric 33058148Seric case MATCHANY: 33158148Seric botch = "$+"; 33258148Seric break; 33358148Seric 33458148Seric case MATCHONE: 33558148Seric botch = "$-"; 33658148Seric break; 33758148Seric 33858148Seric case MATCHCLASS: 33958148Seric botch = "$="; 34058148Seric break; 34158148Seric 34258148Seric case MATCHNCLASS: 34358148Seric botch = "$~"; 34458148Seric break; 34557589Seric } 34658148Seric if (botch != NULL) 34758148Seric syserr("Inappropriate use of %s on RHS", 34858148Seric botch); 34957589Seric } 35057589Seric } 35156678Seric else 35256678Seric syserr("R line: null RHS"); 3533308Seric break; 3543308Seric 3554072Seric case 'S': /* select rewriting set */ 35664440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 35764440Seric continue; 35864440Seric if (!isascii(*p) || !isdigit(*p)) 35964440Seric { 36064440Seric syserr("invalid argument to S line: \"%.20s\"", 36164440Seric &bp[1]); 36264440Seric break; 36364440Seric } 36464440Seric ruleset = atoi(p); 3658056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3668056Seric { 3679381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3688056Seric ruleset = 0; 3698056Seric } 3704072Seric rwp = NULL; 3714072Seric break; 3724072Seric 3733308Seric case 'D': /* macro definition */ 37464086Seric p = munchstring(&bp[2], NULL); 37564086Seric define(bp[1], newstr(p), e); 3763308Seric break; 3773308Seric 3783387Seric case 'H': /* required header line */ 37957135Seric (void) chompheader(&bp[1], TRUE, e); 3803387Seric break; 3813387Seric 3824061Seric case 'C': /* word class */ 3834432Seric /* scan the list of words and set class for all */ 38464121Seric expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e); 38564121Seric for (p = exbuf; *p != '\0'; ) 3864061Seric { 3874061Seric register char *wd; 3884061Seric char delim; 3894061Seric 39058050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3914061Seric p++; 3924061Seric wd = p; 39358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3944061Seric p++; 3954061Seric delim = *p; 3964061Seric *p = '\0'; 3974061Seric if (wd[0] != '\0') 39857135Seric setclass(bp[1], wd); 3994061Seric *p = delim; 4004061Seric } 4014061Seric break; 4024061Seric 40359272Seric case 'F': /* word class from file */ 40464133Seric for (p = &bp[2]; isascii(*p) && isspace(*p); ) 40564133Seric p++; 40664133Seric if (p[0] == '-' && p[1] == 'o') 40764133Seric { 40864133Seric optional = TRUE; 40964133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41064133Seric p++; 41164133Seric while (isascii(*p) && isspace(*p)) 41264133Seric *p++; 41364133Seric } 41464133Seric else 41564133Seric optional = FALSE; 41664133Seric file = p; 41764133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41864133Seric p++; 41959272Seric if (*p == '\0') 42059272Seric p = "%s"; 42159272Seric else 42259272Seric { 42359272Seric *p = '\0'; 42459272Seric while (isascii(*++p) && isspace(*p)) 42559272Seric continue; 42659272Seric } 42764133Seric fileclass(bp[1], file, p, safe, optional); 42859272Seric break; 42959272Seric 43059156Seric #ifdef XLA 43159156Seric case 'L': /* extended load average description */ 43259156Seric xla_init(&bp[1]); 43359156Seric break; 43459156Seric #endif 43559156Seric 4364096Seric case 'M': /* define mailer */ 43757135Seric makemailer(&bp[1]); 4384096Seric break; 4394096Seric 4408252Seric case 'O': /* set option */ 44158734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4428252Seric break; 4438252Seric 4448252Seric case 'P': /* set precedence */ 4458252Seric if (NumPriorities >= MAXPRIORITIES) 4468252Seric { 4478547Seric toomany('P', MAXPRIORITIES); 4488252Seric break; 4498252Seric } 45057135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4518252Seric continue; 4528252Seric if (*p == '\0') 4538252Seric goto badline; 4548252Seric *p = '\0'; 45557135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4568252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4578252Seric NumPriorities++; 4588252Seric break; 4598252Seric 4608547Seric case 'T': /* trusted user(s) */ 46158161Seric /* this option is obsolete, but will be ignored */ 4628547Seric break; 4638547Seric 46452645Seric case 'V': /* configuration syntax version */ 46564440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 46664440Seric continue; 46764440Seric if (!isascii(*p) || !isdigit(*p)) 46864440Seric { 46964440Seric syserr("invalid argument to V line: \"%.20s\"", 47064440Seric &bp[1]); 47164440Seric break; 47264440Seric } 47364718Seric ConfigLevel = strtol(p, &ep, 10); 47464279Seric if (ConfigLevel >= 5) 47564279Seric { 47664279Seric /* level 5 configs have short name in $w */ 47764279Seric p = macvalue('w', e); 47864279Seric if (p != NULL && (p = strchr(p, '.')) != NULL) 47964279Seric *p = '\0'; 48064279Seric } 48164718Seric if (*ep++ == '/') 48264718Seric { 48364718Seric /* extract vendor code */ 48464718Seric for (p = ep; isascii(*p) && isalpha(*p); ) 48564718Seric p++; 48664718Seric *p = '\0'; 48764718Seric 48864718Seric if (!setvendor(ep)) 48964718Seric syserr("invalid V line vendor code: \"%s\"", 49064718Seric ep); 49164718Seric } 49252645Seric break; 49352645Seric 49453654Seric case 'K': 49557135Seric makemapentry(&bp[1]); 49653654Seric break; 49753654Seric 4983308Seric default: 4994061Seric badline: 50057135Seric syserr("unknown control line \"%s\"", bp); 5013308Seric } 50257135Seric if (bp != buf) 50357135Seric free(bp); 5043308Seric } 50552637Seric if (ferror(cf)) 50652637Seric { 50752647Seric syserr("I/O read error", cfname); 50852637Seric exit(EX_OSFILE); 50952637Seric } 51052637Seric fclose(cf); 5119381Seric FileName = NULL; 51256836Seric 51357076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 51457076Seric { 51557076Seric /* user didn't initialize: set up host map */ 51657076Seric strcpy(buf, "host host"); 51757076Seric if (ConfigLevel >= 2) 51857076Seric strcat(buf, " -a."); 51957076Seric makemapentry(buf); 52057076Seric } 5214096Seric } 5224096Seric /* 5238547Seric ** TOOMANY -- signal too many of some option 5248547Seric ** 5258547Seric ** Parameters: 5268547Seric ** id -- the id of the error line 5278547Seric ** maxcnt -- the maximum possible values 5288547Seric ** 5298547Seric ** Returns: 5308547Seric ** none. 5318547Seric ** 5328547Seric ** Side Effects: 5338547Seric ** gives a syserr. 5348547Seric */ 5358547Seric 5368547Seric toomany(id, maxcnt) 5378547Seric char id; 5388547Seric int maxcnt; 5398547Seric { 5409381Seric syserr("too many %c lines, %d max", id, maxcnt); 5418547Seric } 5428547Seric /* 5434432Seric ** FILECLASS -- read members of a class from a file 5444432Seric ** 5454432Seric ** Parameters: 5464432Seric ** class -- class to define. 5474432Seric ** filename -- name of file to read. 5484432Seric ** fmt -- scanf string to use for match. 54964133Seric ** safe -- if set, this is a safe read. 55064133Seric ** optional -- if set, it is not an error for the file to 55164133Seric ** not exist. 5524432Seric ** 5534432Seric ** Returns: 5544432Seric ** none 5554432Seric ** 5564432Seric ** Side Effects: 5574432Seric ** 5584432Seric ** puts all lines in filename that match a scanf into 5594432Seric ** the named class. 5604432Seric */ 5614432Seric 56264133Seric fileclass(class, filename, fmt, safe, optional) 5634432Seric int class; 5644432Seric char *filename; 5654432Seric char *fmt; 56654973Seric bool safe; 56764133Seric bool optional; 5684432Seric { 56925808Seric FILE *f; 57054973Seric struct stat stbuf; 5714432Seric char buf[MAXLINE]; 5724432Seric 57354973Seric if (stat(filename, &stbuf) < 0) 57454973Seric { 57564133Seric if (!optional) 57664133Seric syserr("fileclass: cannot stat %s", filename); 57754973Seric return; 57854973Seric } 57954973Seric if (!S_ISREG(stbuf.st_mode)) 58054973Seric { 58154973Seric syserr("fileclass: %s not a regular file", filename); 58254973Seric return; 58354973Seric } 58454973Seric if (!safe && access(filename, R_OK) < 0) 58554973Seric { 58654973Seric syserr("fileclass: access denied on %s", filename); 58754973Seric return; 58854973Seric } 58954973Seric f = fopen(filename, "r"); 5904432Seric if (f == NULL) 5914432Seric { 59254973Seric syserr("fileclass: cannot open %s", filename); 5934432Seric return; 5944432Seric } 5954432Seric 5964432Seric while (fgets(buf, sizeof buf, f) != NULL) 5974432Seric { 5984432Seric register STAB *s; 59925808Seric register char *p; 60025808Seric # ifdef SCANF 6014432Seric char wordbuf[MAXNAME+1]; 6024432Seric 6034432Seric if (sscanf(buf, fmt, wordbuf) != 1) 6044432Seric continue; 60525808Seric p = wordbuf; 60656795Seric # else /* SCANF */ 60725808Seric p = buf; 60856795Seric # endif /* SCANF */ 60925808Seric 61025808Seric /* 61125808Seric ** Break up the match into words. 61225808Seric */ 61325808Seric 61425808Seric while (*p != '\0') 61525808Seric { 61625808Seric register char *q; 61725808Seric 61825808Seric /* strip leading spaces */ 61958050Seric while (isascii(*p) && isspace(*p)) 62025808Seric p++; 62125808Seric if (*p == '\0') 62225808Seric break; 62325808Seric 62425808Seric /* find the end of the word */ 62525808Seric q = p; 62658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 62725808Seric p++; 62825808Seric if (*p != '\0') 62925808Seric *p++ = '\0'; 63025808Seric 63125808Seric /* enter the word in the symbol table */ 63225808Seric s = stab(q, ST_CLASS, ST_ENTER); 63325808Seric setbitn(class, s->s_class); 63425808Seric } 6354432Seric } 6364432Seric 63754973Seric (void) fclose(f); 6384432Seric } 6394432Seric /* 6404096Seric ** MAKEMAILER -- define a new mailer. 6414096Seric ** 6424096Seric ** Parameters: 64310327Seric ** line -- description of mailer. This is in labeled 64410327Seric ** fields. The fields are: 64510327Seric ** P -- the path to the mailer 64610327Seric ** F -- the flags associated with the mailer 64710327Seric ** A -- the argv for this mailer 64810327Seric ** S -- the sender rewriting set 64910327Seric ** R -- the recipient rewriting set 65010327Seric ** E -- the eol string 65110327Seric ** The first word is the canonical name of the mailer. 6524096Seric ** 6534096Seric ** Returns: 6544096Seric ** none. 6554096Seric ** 6564096Seric ** Side Effects: 6574096Seric ** enters the mailer into the mailer table. 6584096Seric */ 6593308Seric 66021066Seric makemailer(line) 6614096Seric char *line; 6624096Seric { 6634096Seric register char *p; 6648067Seric register struct mailer *m; 6658067Seric register STAB *s; 6668067Seric int i; 66710327Seric char fcode; 66858020Seric auto char *endp; 6694096Seric extern int NextMailer; 67010327Seric extern char **makeargv(); 67110327Seric extern char *munchstring(); 67210701Seric extern long atol(); 6734096Seric 67410327Seric /* allocate a mailer and set up defaults */ 67510327Seric m = (struct mailer *) xalloc(sizeof *m); 67610327Seric bzero((char *) m, sizeof *m); 67710327Seric m->m_eol = "\n"; 67810327Seric 67910327Seric /* collect the mailer name */ 68058050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 68110327Seric continue; 68210327Seric if (*p != '\0') 68310327Seric *p++ = '\0'; 68410327Seric m->m_name = newstr(line); 68510327Seric 68610327Seric /* now scan through and assign info from the fields */ 68710327Seric while (*p != '\0') 68810327Seric { 68958333Seric auto char *delimptr; 69058333Seric 69158050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 69210327Seric p++; 69310327Seric 69410327Seric /* p now points to field code */ 69510327Seric fcode = *p; 69610327Seric while (*p != '\0' && *p != '=' && *p != ',') 69710327Seric p++; 69810327Seric if (*p++ != '=') 69910327Seric { 70052637Seric syserr("mailer %s: `=' expected", m->m_name); 70110327Seric return; 70210327Seric } 70358050Seric while (isascii(*p) && isspace(*p)) 70410327Seric p++; 70510327Seric 70610327Seric /* p now points to the field body */ 70758333Seric p = munchstring(p, &delimptr); 70810327Seric 70910327Seric /* install the field into the mailer struct */ 71010327Seric switch (fcode) 71110327Seric { 71210327Seric case 'P': /* pathname */ 71310327Seric m->m_mailer = newstr(p); 71410327Seric break; 71510327Seric 71610327Seric case 'F': /* flags */ 71710687Seric for (; *p != '\0'; p++) 71858050Seric if (!(isascii(*p) && isspace(*p))) 71952637Seric setbitn(*p, m->m_flags); 72010327Seric break; 72110327Seric 72210327Seric case 'S': /* sender rewriting ruleset */ 72310327Seric case 'R': /* recipient rewriting ruleset */ 72458020Seric i = strtol(p, &endp, 10); 72510327Seric if (i < 0 || i >= MAXRWSETS) 72610327Seric { 72710327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 72810327Seric return; 72910327Seric } 73010327Seric if (fcode == 'S') 73158020Seric m->m_sh_rwset = m->m_se_rwset = i; 73210327Seric else 73358020Seric m->m_rh_rwset = m->m_re_rwset = i; 73458020Seric 73558020Seric p = endp; 73659985Seric if (*p++ == '/') 73758020Seric { 73858020Seric i = strtol(p, NULL, 10); 73958020Seric if (i < 0 || i >= MAXRWSETS) 74058020Seric { 74158020Seric syserr("invalid rewrite set, %d max", 74258020Seric MAXRWSETS); 74358020Seric return; 74458020Seric } 74558020Seric if (fcode == 'S') 74658020Seric m->m_sh_rwset = i; 74758020Seric else 74858020Seric m->m_rh_rwset = i; 74958020Seric } 75010327Seric break; 75110327Seric 75210327Seric case 'E': /* end of line string */ 75310327Seric m->m_eol = newstr(p); 75410327Seric break; 75510327Seric 75610327Seric case 'A': /* argument vector */ 75710327Seric m->m_argv = makeargv(p); 75810327Seric break; 75910701Seric 76010701Seric case 'M': /* maximum message size */ 76110701Seric m->m_maxsize = atol(p); 76210701Seric break; 76352106Seric 76452106Seric case 'L': /* maximum line length */ 76552106Seric m->m_linelimit = atoi(p); 76652106Seric break; 76758935Seric 76858935Seric case 'D': /* working directory */ 76958935Seric m->m_execdir = newstr(p); 77058935Seric break; 77110327Seric } 77210327Seric 77358333Seric p = delimptr; 77410327Seric } 77510327Seric 77652106Seric /* do some heuristic cleanup for back compatibility */ 77752106Seric if (bitnset(M_LIMITS, m->m_flags)) 77852106Seric { 77952106Seric if (m->m_linelimit == 0) 78052106Seric m->m_linelimit = SMTPLINELIM; 78155418Seric if (ConfigLevel < 2) 78252106Seric setbitn(M_7BITS, m->m_flags); 78352106Seric } 78452106Seric 78558321Seric /* do some rationality checking */ 78658321Seric if (m->m_argv == NULL) 78758321Seric { 78858321Seric syserr("M%s: A= argument required", m->m_name); 78958321Seric return; 79058321Seric } 79158321Seric if (m->m_mailer == NULL) 79258321Seric { 79358321Seric syserr("M%s: P= argument required", m->m_name); 79458321Seric return; 79558321Seric } 79658321Seric 7974096Seric if (NextMailer >= MAXMAILERS) 7984096Seric { 7999381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 8004096Seric return; 8014096Seric } 80257402Seric 80310327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 80457402Seric if (s->s_mailer != NULL) 80557402Seric { 80657402Seric i = s->s_mailer->m_mno; 80757402Seric free(s->s_mailer); 80857402Seric } 80957402Seric else 81057402Seric { 81157402Seric i = NextMailer++; 81257402Seric } 81357402Seric Mailer[i] = s->s_mailer = m; 81457454Seric m->m_mno = i; 81510327Seric } 81610327Seric /* 81710327Seric ** MUNCHSTRING -- translate a string into internal form. 81810327Seric ** 81910327Seric ** Parameters: 82010327Seric ** p -- the string to munch. 82158333Seric ** delimptr -- if non-NULL, set to the pointer of the 82258333Seric ** field delimiter character. 82310327Seric ** 82410327Seric ** Returns: 82510327Seric ** the munched string. 82610327Seric */ 8274096Seric 82810327Seric char * 82958333Seric munchstring(p, delimptr) 83010327Seric register char *p; 83158333Seric char **delimptr; 83210327Seric { 83310327Seric register char *q; 83410327Seric bool backslash = FALSE; 83510327Seric bool quotemode = FALSE; 83610327Seric static char buf[MAXLINE]; 8374096Seric 83810327Seric for (q = buf; *p != '\0'; p++) 8394096Seric { 84010327Seric if (backslash) 84110327Seric { 84210327Seric /* everything is roughly literal */ 84310357Seric backslash = FALSE; 84410327Seric switch (*p) 84510327Seric { 84610327Seric case 'r': /* carriage return */ 84710327Seric *q++ = '\r'; 84810327Seric continue; 84910327Seric 85010327Seric case 'n': /* newline */ 85110327Seric *q++ = '\n'; 85210327Seric continue; 85310327Seric 85410327Seric case 'f': /* form feed */ 85510327Seric *q++ = '\f'; 85610327Seric continue; 85710327Seric 85810327Seric case 'b': /* backspace */ 85910327Seric *q++ = '\b'; 86010327Seric continue; 86110327Seric } 86210327Seric *q++ = *p; 86310327Seric } 86410327Seric else 86510327Seric { 86610327Seric if (*p == '\\') 86710327Seric backslash = TRUE; 86810327Seric else if (*p == '"') 86910327Seric quotemode = !quotemode; 87010327Seric else if (quotemode || *p != ',') 87110327Seric *q++ = *p; 87210327Seric else 87310327Seric break; 87410327Seric } 8754096Seric } 8764096Seric 87758333Seric if (delimptr != NULL) 87858333Seric *delimptr = p; 87910327Seric *q++ = '\0'; 88010327Seric return (buf); 88110327Seric } 88210327Seric /* 88310327Seric ** MAKEARGV -- break up a string into words 88410327Seric ** 88510327Seric ** Parameters: 88610327Seric ** p -- the string to break up. 88710327Seric ** 88810327Seric ** Returns: 88910327Seric ** a char **argv (dynamically allocated) 89010327Seric ** 89110327Seric ** Side Effects: 89210327Seric ** munges p. 89310327Seric */ 8944096Seric 89510327Seric char ** 89610327Seric makeargv(p) 89710327Seric register char *p; 89810327Seric { 89910327Seric char *q; 90010327Seric int i; 90110327Seric char **avp; 90210327Seric char *argv[MAXPV + 1]; 90310327Seric 90410327Seric /* take apart the words */ 90510327Seric i = 0; 90610327Seric while (*p != '\0' && i < MAXPV) 9074096Seric { 90810327Seric q = p; 90958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 91010327Seric p++; 91158050Seric while (isascii(*p) && isspace(*p)) 91210327Seric *p++ = '\0'; 91310327Seric argv[i++] = newstr(q); 9144096Seric } 91510327Seric argv[i++] = NULL; 9164096Seric 91710327Seric /* now make a copy of the argv */ 91810327Seric avp = (char **) xalloc(sizeof *avp * i); 91916893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 92010327Seric 92110327Seric return (avp); 9223308Seric } 9233308Seric /* 9243308Seric ** PRINTRULES -- print rewrite rules (for debugging) 9253308Seric ** 9263308Seric ** Parameters: 9273308Seric ** none. 9283308Seric ** 9293308Seric ** Returns: 9303308Seric ** none. 9313308Seric ** 9323308Seric ** Side Effects: 9333308Seric ** prints rewrite rules. 9343308Seric */ 9353308Seric 9363308Seric printrules() 9373308Seric { 9383308Seric register struct rewrite *rwp; 9394072Seric register int ruleset; 9403308Seric 9414072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9423308Seric { 9434072Seric if (RewriteRules[ruleset] == NULL) 9444072Seric continue; 9458067Seric printf("\n----Rule Set %d:", ruleset); 9463308Seric 9474072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9483308Seric { 9498067Seric printf("\nLHS:"); 9508067Seric printav(rwp->r_lhs); 9518067Seric printf("RHS:"); 9528067Seric printav(rwp->r_rhs); 9533308Seric } 9543308Seric } 9553308Seric } 9564319Seric 9574096Seric /* 9588256Seric ** SETOPTION -- set global processing option 9598256Seric ** 9608256Seric ** Parameters: 9618256Seric ** opt -- option name. 9628256Seric ** val -- option value (as a text string). 96321755Seric ** safe -- set if this came from a configuration file. 96421755Seric ** Some options (if set from the command line) will 96521755Seric ** reset the user id to avoid security problems. 9668269Seric ** sticky -- if set, don't let other setoptions override 9678269Seric ** this value. 96858734Seric ** e -- the main envelope. 9698256Seric ** 9708256Seric ** Returns: 9718256Seric ** none. 9728256Seric ** 9738256Seric ** Side Effects: 9748256Seric ** Sets options as implied by the arguments. 9758256Seric */ 9768256Seric 97710687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9788269Seric 97957207Seric 98057207Seric #ifdef NAMED_BIND 98157207Seric 98257207Seric struct resolverflags 98357207Seric { 98457207Seric char *rf_name; /* name of the flag */ 98557207Seric long rf_bits; /* bits to set/clear */ 98657207Seric } ResolverFlags[] = 98757207Seric { 98857207Seric "debug", RES_DEBUG, 98957207Seric "aaonly", RES_AAONLY, 99057207Seric "usevc", RES_USEVC, 99157207Seric "primary", RES_PRIMARY, 99257207Seric "igntc", RES_IGNTC, 99357207Seric "recurse", RES_RECURSE, 99457207Seric "defnames", RES_DEFNAMES, 99557207Seric "stayopen", RES_STAYOPEN, 99657207Seric "dnsrch", RES_DNSRCH, 99757207Seric NULL, 0 99857207Seric }; 99957207Seric 100057207Seric #endif 100157207Seric 100258734Seric setoption(opt, val, safe, sticky, e) 10038256Seric char opt; 10048256Seric char *val; 100521755Seric bool safe; 10068269Seric bool sticky; 100758734Seric register ENVELOPE *e; 10088256Seric { 100957207Seric register char *p; 10108265Seric extern bool atobool(); 101112633Seric extern time_t convtime(); 101214879Seric extern int QueueLA; 101314879Seric extern int RefuseLA; 101464718Seric extern bool Warn_Q_option; 101517474Seric extern bool trusteduser(); 10168256Seric 10178256Seric if (tTd(37, 1)) 10189341Seric printf("setoption %c=%s", opt, val); 10198256Seric 10208256Seric /* 10218269Seric ** See if this option is preset for us. 10228256Seric */ 10238256Seric 102459731Seric if (!sticky && bitnset(opt, StickyOpt)) 10258269Seric { 10269341Seric if (tTd(37, 1)) 10279341Seric printf(" (ignored)\n"); 10288269Seric return; 10298269Seric } 10308269Seric 103121755Seric /* 103221755Seric ** Check to see if this option can be specified by this user. 103321755Seric */ 103421755Seric 103563787Seric if (!safe && RealUid == 0) 103621755Seric safe = TRUE; 103763837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 103821755Seric { 103939111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 104021755Seric { 104136582Sbostic if (tTd(37, 1)) 104236582Sbostic printf(" (unsafe)"); 104363787Seric if (RealUid != geteuid()) 104436582Sbostic { 104551210Seric if (tTd(37, 1)) 104651210Seric printf("(Resetting uid)"); 104763787Seric (void) setgid(RealGid); 104863787Seric (void) setuid(RealUid); 104936582Sbostic } 105021755Seric } 105121755Seric } 105251210Seric if (tTd(37, 1)) 105317985Seric printf("\n"); 10548269Seric 10558256Seric switch (opt) 10568256Seric { 105759709Seric case '7': /* force seven-bit input */ 105859709Seric SevenBit = atobool(val); 105952106Seric break; 106052106Seric 10618256Seric case 'A': /* set default alias file */ 10629381Seric if (val[0] == '\0') 106359672Seric setalias("aliases"); 10649381Seric else 106559672Seric setalias(val); 10668256Seric break; 10678256Seric 106817474Seric case 'a': /* look N minutes for "@:@" in alias file */ 106917474Seric if (val[0] == '\0') 107064796Seric SafeAlias = 5 * 60; /* five minutes */ 107117474Seric else 107264796Seric SafeAlias = convtime(val, 'm'); 107317474Seric break; 107417474Seric 107516843Seric case 'B': /* substitution for blank character */ 107616843Seric SpaceSub = val[0]; 107716843Seric if (SpaceSub == '\0') 107816843Seric SpaceSub = ' '; 107916843Seric break; 108016843Seric 108159283Seric case 'b': /* min blocks free on queue fs/max msg size */ 108259283Seric p = strchr(val, '/'); 108359283Seric if (p != NULL) 108459283Seric { 108559283Seric *p++ = '\0'; 108659283Seric MaxMessageSize = atol(p); 108759283Seric } 108858082Seric MinBlocksFree = atol(val); 108958082Seric break; 109058082Seric 10919284Seric case 'c': /* don't connect to "expensive" mailers */ 10929381Seric NoConnect = atobool(val); 10939284Seric break; 10949284Seric 109551305Seric case 'C': /* checkpoint every N addresses */ 109651305Seric CheckpointInterval = atoi(val); 109724944Seric break; 109824944Seric 10999284Seric case 'd': /* delivery mode */ 11009284Seric switch (*val) 11018269Seric { 11029284Seric case '\0': 110358734Seric e->e_sendmode = SM_DELIVER; 11048269Seric break; 11058269Seric 110610755Seric case SM_QUEUE: /* queue only */ 110710755Seric #ifndef QUEUE 110810755Seric syserr("need QUEUE to set -odqueue"); 110956795Seric #endif /* QUEUE */ 111010755Seric /* fall through..... */ 111110755Seric 11129284Seric case SM_DELIVER: /* do everything */ 11139284Seric case SM_FORK: /* fork after verification */ 111458734Seric e->e_sendmode = *val; 11158269Seric break; 11168269Seric 11178269Seric default: 11189284Seric syserr("Unknown delivery mode %c", *val); 11198269Seric exit(EX_USAGE); 11208269Seric } 11218269Seric break; 11228269Seric 11239146Seric case 'D': /* rebuild alias database as needed */ 11249381Seric AutoRebuild = atobool(val); 11259146Seric break; 11269146Seric 112755372Seric case 'E': /* error message header/header file */ 112855379Seric if (*val != '\0') 112955379Seric ErrMsgFile = newstr(val); 113055372Seric break; 113155372Seric 11328269Seric case 'e': /* set error processing mode */ 11338269Seric switch (*val) 11348269Seric { 11359381Seric case EM_QUIET: /* be silent about it */ 11369381Seric case EM_MAIL: /* mail back */ 11379381Seric case EM_BERKNET: /* do berknet error processing */ 11389381Seric case EM_WRITE: /* write back (or mail) */ 11398269Seric HoldErrs = TRUE; 11409381Seric /* fall through... */ 11418269Seric 11429381Seric case EM_PRINT: /* print errors normally (default) */ 114358734Seric e->e_errormode = *val; 11448269Seric break; 11458269Seric } 11468269Seric break; 11478269Seric 11489049Seric case 'F': /* file mode */ 114917975Seric FileMode = atooct(val) & 0777; 11509049Seric break; 11519049Seric 11528269Seric case 'f': /* save Unix-style From lines on front */ 11539381Seric SaveFrom = atobool(val); 11548269Seric break; 11558269Seric 115653735Seric case 'G': /* match recipients against GECOS field */ 115753735Seric MatchGecos = atobool(val); 115853735Seric break; 115953735Seric 11608256Seric case 'g': /* default gid */ 116164133Seric if (isascii(*val) && isdigit(*val)) 116264133Seric DefGid = atoi(val); 116364133Seric else 116464133Seric { 116564133Seric register struct group *gr; 116664133Seric 116764133Seric DefGid = -1; 116864133Seric gr = getgrnam(val); 116964133Seric if (gr == NULL) 117064133Seric syserr("readcf: option g: unknown group %s", val); 117164133Seric else 117264133Seric DefGid = gr->gr_gid; 117364133Seric } 11748256Seric break; 11758256Seric 11768256Seric case 'H': /* help file */ 11779381Seric if (val[0] == '\0') 11788269Seric HelpFile = "sendmail.hf"; 11799381Seric else 11809381Seric HelpFile = newstr(val); 11818256Seric break; 11828256Seric 118351305Seric case 'h': /* maximum hop count */ 118451305Seric MaxHopCount = atoi(val); 118551305Seric break; 118651305Seric 118735651Seric case 'I': /* use internet domain name server */ 118857207Seric #ifdef NAMED_BIND 118957207Seric UseNameServer = TRUE; 119057207Seric for (p = val; *p != 0; ) 119157207Seric { 119257207Seric bool clearmode; 119357207Seric char *q; 119457207Seric struct resolverflags *rfp; 119557207Seric 119657207Seric while (*p == ' ') 119757207Seric p++; 119857207Seric if (*p == '\0') 119957207Seric break; 120057207Seric clearmode = FALSE; 120157207Seric if (*p == '-') 120257207Seric clearmode = TRUE; 120357207Seric else if (*p != '+') 120457207Seric p--; 120557207Seric p++; 120657207Seric q = p; 120758050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 120857207Seric p++; 120957207Seric if (*p != '\0') 121057207Seric *p++ = '\0'; 121157207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 121257207Seric { 121357207Seric if (strcasecmp(q, rfp->rf_name) == 0) 121457207Seric break; 121557207Seric } 1216*64923Seric if (rfp->rf_name == NULL) 1217*64923Seric syserr("readcf: I option value %s unrecognized", q); 1218*64923Seric else if (clearmode) 121957207Seric _res.options &= ~rfp->rf_bits; 122057207Seric else 122157207Seric _res.options |= rfp->rf_bits; 122257207Seric } 122357207Seric if (tTd(8, 2)) 122457207Seric printf("_res.options = %x\n", _res.options); 122557207Seric #else 122657207Seric usrerr("name server (I option) specified but BIND not compiled in"); 122757207Seric #endif 122835651Seric break; 122935651Seric 12308269Seric case 'i': /* ignore dot lines in message */ 12319381Seric IgnrDot = atobool(val); 12328269Seric break; 12338269Seric 123459730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 123559730Seric SendMIMEErrors = atobool(val); 123659730Seric break; 123759730Seric 123857136Seric case 'J': /* .forward search path */ 123957136Seric ForwardPath = newstr(val); 124057136Seric break; 124157136Seric 124254967Seric case 'k': /* connection cache size */ 124354967Seric MaxMciCache = atoi(val); 124456215Seric if (MaxMciCache < 0) 124556215Seric MaxMciCache = 0; 124654967Seric break; 124754967Seric 124854967Seric case 'K': /* connection cache timeout */ 124958796Seric MciCacheTimeout = convtime(val, 'm'); 125054967Seric break; 125154967Seric 125261104Seric case 'l': /* use Errors-To: header */ 125361104Seric UseErrorsTo = atobool(val); 125461104Seric break; 125561104Seric 12568256Seric case 'L': /* log level */ 125764140Seric if (safe || LogLevel < atoi(val)) 125864140Seric LogLevel = atoi(val); 12598256Seric break; 12608256Seric 12618269Seric case 'M': /* define macro */ 12629381Seric define(val[0], newstr(&val[1]), CurEnv); 126316878Seric sticky = FALSE; 12648269Seric break; 12658269Seric 12668269Seric case 'm': /* send to me too */ 12679381Seric MeToo = atobool(val); 12688269Seric break; 12698269Seric 127025820Seric case 'n': /* validate RHS in newaliases */ 127125820Seric CheckAliases = atobool(val); 127225820Seric break; 127325820Seric 127461104Seric /* 'N' available -- was "net name" */ 127561104Seric 127658851Seric case 'O': /* daemon options */ 127758851Seric setdaemonoptions(val); 127858851Seric break; 127958851Seric 12808269Seric case 'o': /* assume old style headers */ 12819381Seric if (atobool(val)) 12829341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12839341Seric else 12849341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12858269Seric break; 12868269Seric 128758082Seric case 'p': /* select privacy level */ 128858082Seric p = val; 128958082Seric for (;;) 129058082Seric { 129158082Seric register struct prival *pv; 129258082Seric extern struct prival PrivacyValues[]; 129358082Seric 129458082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 129558082Seric p++; 129658082Seric if (*p == '\0') 129758082Seric break; 129858082Seric val = p; 129958082Seric while (isascii(*p) && isalnum(*p)) 130058082Seric p++; 130158082Seric if (*p != '\0') 130258082Seric *p++ = '\0'; 130358082Seric 130458082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 130558082Seric { 130658082Seric if (strcasecmp(val, pv->pv_name) == 0) 130758082Seric break; 130858082Seric } 130958886Seric if (pv->pv_name == NULL) 131058886Seric syserr("readcf: Op line: %s unrecognized", val); 131158082Seric PrivacyFlags |= pv->pv_flag; 131258082Seric } 131358082Seric break; 131458082Seric 131524944Seric case 'P': /* postmaster copy address for returned mail */ 131624944Seric PostMasterCopy = newstr(val); 131724944Seric break; 131824944Seric 131924944Seric case 'q': /* slope of queue only function */ 132024944Seric QueueFactor = atoi(val); 132124944Seric break; 132224944Seric 13238256Seric case 'Q': /* queue directory */ 13249381Seric if (val[0] == '\0') 13258269Seric QueueDir = "mqueue"; 13269381Seric else 13279381Seric QueueDir = newstr(val); 132858789Seric if (RealUid != 0 && !safe) 132964718Seric Warn_Q_option = TRUE; 13308256Seric break; 13318256Seric 133258148Seric case 'R': /* don't prune routes */ 133358148Seric DontPruneRoutes = atobool(val); 133458148Seric break; 133558148Seric 13368256Seric case 'r': /* read timeout */ 133758112Seric settimeouts(val); 13388256Seric break; 13398256Seric 13408256Seric case 'S': /* status file */ 13419381Seric if (val[0] == '\0') 13428269Seric StatFile = "sendmail.st"; 13439381Seric else 13449381Seric StatFile = newstr(val); 13458256Seric break; 13468256Seric 13478265Seric case 's': /* be super safe, even if expensive */ 13489381Seric SuperSafe = atobool(val); 13498256Seric break; 13508256Seric 13518256Seric case 'T': /* queue timeout */ 135258737Seric p = strchr(val, '/'); 135358737Seric if (p != NULL) 135458737Seric { 135558737Seric *p++ = '\0'; 135658796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 135758737Seric } 135858796Seric TimeOuts.to_q_return = convtime(val, 'h'); 135954967Seric break; 13608256Seric 13618265Seric case 't': /* time zone name */ 136252106Seric TimeZoneSpec = newstr(val); 13638265Seric break; 13648265Seric 136550556Seric case 'U': /* location of user database */ 136651360Seric UdbSpec = newstr(val); 136750556Seric break; 136850556Seric 13698256Seric case 'u': /* set default uid */ 137064133Seric if (isascii(*val) && isdigit(*val)) 137164133Seric DefUid = atoi(val); 137264133Seric else 137364133Seric { 137464133Seric register struct passwd *pw; 137564133Seric 137664133Seric DefUid = -1; 137764133Seric pw = getpwnam(val); 137864133Seric if (pw == NULL) 137964133Seric syserr("readcf: option u: unknown user %s", val); 138064133Seric else 138164133Seric DefUid = pw->pw_uid; 138264133Seric } 138340973Sbostic setdefuser(); 13848256Seric break; 13858256Seric 138658851Seric case 'V': /* fallback MX host */ 138758851Seric FallBackMX = newstr(val); 138858851Seric break; 138958851Seric 13908269Seric case 'v': /* run in verbose mode */ 13919381Seric Verbose = atobool(val); 13928256Seric break; 13938256Seric 139463837Seric case 'w': /* if we are best MX, try host directly */ 139563837Seric TryNullMXList = atobool(val); 139663837Seric break; 139761104Seric 139861104Seric /* 'W' available -- was wizard password */ 139961104Seric 140014879Seric case 'x': /* load avg at which to auto-queue msgs */ 140114879Seric QueueLA = atoi(val); 140214879Seric break; 140314879Seric 140414879Seric case 'X': /* load avg at which to auto-reject connections */ 140514879Seric RefuseLA = atoi(val); 140614879Seric break; 140714879Seric 140824981Seric case 'y': /* work recipient factor */ 140924981Seric WkRecipFact = atoi(val); 141024981Seric break; 141124981Seric 141224981Seric case 'Y': /* fork jobs during queue runs */ 141324952Seric ForkQueueRuns = atobool(val); 141424952Seric break; 141524952Seric 141624981Seric case 'z': /* work message class factor */ 141724981Seric WkClassFact = atoi(val); 141824981Seric break; 141924981Seric 142024981Seric case 'Z': /* work time factor */ 142124981Seric WkTimeFact = atoi(val); 142224981Seric break; 142324981Seric 14248256Seric default: 14258256Seric break; 14268256Seric } 142716878Seric if (sticky) 142816878Seric setbitn(opt, StickyOpt); 14299188Seric return; 14308256Seric } 143110687Seric /* 143210687Seric ** SETCLASS -- set a word into a class 143310687Seric ** 143410687Seric ** Parameters: 143510687Seric ** class -- the class to put the word in. 143610687Seric ** word -- the word to enter 143710687Seric ** 143810687Seric ** Returns: 143910687Seric ** none. 144010687Seric ** 144110687Seric ** Side Effects: 144210687Seric ** puts the word into the symbol table. 144310687Seric */ 144410687Seric 144510687Seric setclass(class, word) 144610687Seric int class; 144710687Seric char *word; 144810687Seric { 144910687Seric register STAB *s; 145010687Seric 145157943Seric if (tTd(37, 8)) 145264326Seric printf("setclass(%c, %s)\n", class, word); 145310687Seric s = stab(word, ST_CLASS, ST_ENTER); 145410687Seric setbitn(class, s->s_class); 145510687Seric } 145653654Seric /* 145753654Seric ** MAKEMAPENTRY -- create a map entry 145853654Seric ** 145953654Seric ** Parameters: 146053654Seric ** line -- the config file line 146153654Seric ** 146253654Seric ** Returns: 146353654Seric ** TRUE if it successfully entered the map entry. 146453654Seric ** FALSE otherwise (usually syntax error). 146553654Seric ** 146653654Seric ** Side Effects: 146753654Seric ** Enters the map into the dictionary. 146853654Seric */ 146953654Seric 147053654Seric void 147153654Seric makemapentry(line) 147253654Seric char *line; 147353654Seric { 147453654Seric register char *p; 147553654Seric char *mapname; 147653654Seric char *classname; 147764078Seric register STAB *s; 147853654Seric STAB *class; 147953654Seric 148058050Seric for (p = line; isascii(*p) && isspace(*p); p++) 148153654Seric continue; 148258050Seric if (!(isascii(*p) && isalnum(*p))) 148353654Seric { 148453654Seric syserr("readcf: config K line: no map name"); 148553654Seric return; 148653654Seric } 148753654Seric 148853654Seric mapname = p; 148958050Seric while (isascii(*++p) && isalnum(*p)) 149053654Seric continue; 149153654Seric if (*p != '\0') 149253654Seric *p++ = '\0'; 149358050Seric while (isascii(*p) && isspace(*p)) 149453654Seric p++; 149558050Seric if (!(isascii(*p) && isalnum(*p))) 149653654Seric { 149753654Seric syserr("readcf: config K line, map %s: no map class", mapname); 149853654Seric return; 149953654Seric } 150053654Seric classname = p; 150158050Seric while (isascii(*++p) && isalnum(*p)) 150253654Seric continue; 150353654Seric if (*p != '\0') 150453654Seric *p++ = '\0'; 150558050Seric while (isascii(*p) && isspace(*p)) 150653654Seric p++; 150753654Seric 150853654Seric /* look up the class */ 150953654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 151053654Seric if (class == NULL) 151153654Seric { 151253654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 151353654Seric return; 151453654Seric } 151553654Seric 151653654Seric /* enter the map */ 151764078Seric s = stab(mapname, ST_MAP, ST_ENTER); 151864078Seric s->s_map.map_class = &class->s_mapclass; 151964078Seric s->s_map.map_mname = newstr(mapname); 152053654Seric 152164078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 152264078Seric s->s_map.map_mflags |= MF_VALID; 152364078Seric 152464078Seric if (tTd(37, 5)) 152564078Seric { 152664078Seric printf("map %s, class %s, flags %x, file %s,\n", 152764078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 152864078Seric s->s_map.map_mflags, 152964078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 153064078Seric printf("\tapp %s, domain %s, rebuild %s\n", 153164078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 153264078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 153364078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 153464078Seric } 153553654Seric } 153658112Seric /* 153758112Seric ** SETTIMEOUTS -- parse and set timeout values 153858112Seric ** 153958112Seric ** Parameters: 154058112Seric ** val -- a pointer to the values. If NULL, do initial 154158112Seric ** settings. 154258112Seric ** 154358112Seric ** Returns: 154458112Seric ** none. 154558112Seric ** 154658112Seric ** Side Effects: 154758112Seric ** Initializes the TimeOuts structure 154858112Seric */ 154958112Seric 155064255Seric #define SECONDS 155158112Seric #define MINUTES * 60 155258112Seric #define HOUR * 3600 155358112Seric 155458112Seric settimeouts(val) 155558112Seric register char *val; 155658112Seric { 155758112Seric register char *p; 155858671Seric extern time_t convtime(); 155958112Seric 156058112Seric if (val == NULL) 156158112Seric { 156258112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 156358112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 156458112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 156558112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 156658112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 156758112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 156858112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 156958112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 157058112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 157158112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 157258112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 157364255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 157458112Seric return; 157558112Seric } 157658112Seric 157758112Seric for (;; val = p) 157858112Seric { 157958112Seric while (isascii(*val) && isspace(*val)) 158058112Seric val++; 158158112Seric if (*val == '\0') 158258112Seric break; 158358112Seric for (p = val; *p != '\0' && *p != ','; p++) 158458112Seric continue; 158558112Seric if (*p != '\0') 158658112Seric *p++ = '\0'; 158758112Seric 158858112Seric if (isascii(*val) && isdigit(*val)) 158958112Seric { 159058112Seric /* old syntax -- set everything */ 159158796Seric TimeOuts.to_mail = convtime(val, 'm'); 159258112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 159358112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 159458112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 159558112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 159658112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 159758112Seric continue; 159858112Seric } 159958112Seric else 160058112Seric { 160158112Seric register char *q = strchr(val, '='); 160258112Seric time_t to; 160358112Seric 160458112Seric if (q == NULL) 160558112Seric { 160658112Seric /* syntax error */ 160758112Seric continue; 160858112Seric } 160958112Seric *q++ = '\0'; 161058796Seric to = convtime(q, 'm'); 161158112Seric 161258112Seric if (strcasecmp(val, "initial") == 0) 161358112Seric TimeOuts.to_initial = to; 161458112Seric else if (strcasecmp(val, "mail") == 0) 161558112Seric TimeOuts.to_mail = to; 161658112Seric else if (strcasecmp(val, "rcpt") == 0) 161758112Seric TimeOuts.to_rcpt = to; 161858112Seric else if (strcasecmp(val, "datainit") == 0) 161958112Seric TimeOuts.to_datainit = to; 162058112Seric else if (strcasecmp(val, "datablock") == 0) 162158112Seric TimeOuts.to_datablock = to; 162258112Seric else if (strcasecmp(val, "datafinal") == 0) 162358112Seric TimeOuts.to_datafinal = to; 162458112Seric else if (strcasecmp(val, "command") == 0) 162558112Seric TimeOuts.to_nextcommand = to; 162658112Seric else if (strcasecmp(val, "rset") == 0) 162758112Seric TimeOuts.to_rset = to; 162858112Seric else if (strcasecmp(val, "helo") == 0) 162958112Seric TimeOuts.to_helo = to; 163058112Seric else if (strcasecmp(val, "quit") == 0) 163158112Seric TimeOuts.to_quit = to; 163258112Seric else if (strcasecmp(val, "misc") == 0) 163358112Seric TimeOuts.to_miscshort = to; 163464255Seric else if (strcasecmp(val, "ident") == 0) 163564255Seric TimeOuts.to_ident = to; 163658112Seric else 163758112Seric syserr("settimeouts: invalid timeout %s", val); 163858112Seric } 163958112Seric } 164058112Seric } 1641