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*64947Seric static char sccsid[] = "@(#)readcf.c 8.16 (Berkeley) 11/26/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"); 517*64947Seric #ifdef NAMED_BIND 51857076Seric if (ConfigLevel >= 2) 51957076Seric strcat(buf, " -a."); 520*64947Seric #endif 52157076Seric makemapentry(buf); 52257076Seric } 5234096Seric } 5244096Seric /* 5258547Seric ** TOOMANY -- signal too many of some option 5268547Seric ** 5278547Seric ** Parameters: 5288547Seric ** id -- the id of the error line 5298547Seric ** maxcnt -- the maximum possible values 5308547Seric ** 5318547Seric ** Returns: 5328547Seric ** none. 5338547Seric ** 5348547Seric ** Side Effects: 5358547Seric ** gives a syserr. 5368547Seric */ 5378547Seric 5388547Seric toomany(id, maxcnt) 5398547Seric char id; 5408547Seric int maxcnt; 5418547Seric { 5429381Seric syserr("too many %c lines, %d max", id, maxcnt); 5438547Seric } 5448547Seric /* 5454432Seric ** FILECLASS -- read members of a class from a file 5464432Seric ** 5474432Seric ** Parameters: 5484432Seric ** class -- class to define. 5494432Seric ** filename -- name of file to read. 5504432Seric ** fmt -- scanf string to use for match. 55164133Seric ** safe -- if set, this is a safe read. 55264133Seric ** optional -- if set, it is not an error for the file to 55364133Seric ** not exist. 5544432Seric ** 5554432Seric ** Returns: 5564432Seric ** none 5574432Seric ** 5584432Seric ** Side Effects: 5594432Seric ** 5604432Seric ** puts all lines in filename that match a scanf into 5614432Seric ** the named class. 5624432Seric */ 5634432Seric 56464133Seric fileclass(class, filename, fmt, safe, optional) 5654432Seric int class; 5664432Seric char *filename; 5674432Seric char *fmt; 56854973Seric bool safe; 56964133Seric bool optional; 5704432Seric { 57125808Seric FILE *f; 57254973Seric struct stat stbuf; 5734432Seric char buf[MAXLINE]; 5744432Seric 57554973Seric if (stat(filename, &stbuf) < 0) 57654973Seric { 57764133Seric if (!optional) 57864133Seric syserr("fileclass: cannot stat %s", filename); 57954973Seric return; 58054973Seric } 58154973Seric if (!S_ISREG(stbuf.st_mode)) 58254973Seric { 58354973Seric syserr("fileclass: %s not a regular file", filename); 58454973Seric return; 58554973Seric } 58654973Seric if (!safe && access(filename, R_OK) < 0) 58754973Seric { 58854973Seric syserr("fileclass: access denied on %s", filename); 58954973Seric return; 59054973Seric } 59154973Seric f = fopen(filename, "r"); 5924432Seric if (f == NULL) 5934432Seric { 59454973Seric syserr("fileclass: cannot open %s", filename); 5954432Seric return; 5964432Seric } 5974432Seric 5984432Seric while (fgets(buf, sizeof buf, f) != NULL) 5994432Seric { 6004432Seric register STAB *s; 60125808Seric register char *p; 60225808Seric # ifdef SCANF 6034432Seric char wordbuf[MAXNAME+1]; 6044432Seric 6054432Seric if (sscanf(buf, fmt, wordbuf) != 1) 6064432Seric continue; 60725808Seric p = wordbuf; 60856795Seric # else /* SCANF */ 60925808Seric p = buf; 61056795Seric # endif /* SCANF */ 61125808Seric 61225808Seric /* 61325808Seric ** Break up the match into words. 61425808Seric */ 61525808Seric 61625808Seric while (*p != '\0') 61725808Seric { 61825808Seric register char *q; 61925808Seric 62025808Seric /* strip leading spaces */ 62158050Seric while (isascii(*p) && isspace(*p)) 62225808Seric p++; 62325808Seric if (*p == '\0') 62425808Seric break; 62525808Seric 62625808Seric /* find the end of the word */ 62725808Seric q = p; 62858050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 62925808Seric p++; 63025808Seric if (*p != '\0') 63125808Seric *p++ = '\0'; 63225808Seric 63325808Seric /* enter the word in the symbol table */ 63425808Seric s = stab(q, ST_CLASS, ST_ENTER); 63525808Seric setbitn(class, s->s_class); 63625808Seric } 6374432Seric } 6384432Seric 63954973Seric (void) fclose(f); 6404432Seric } 6414432Seric /* 6424096Seric ** MAKEMAILER -- define a new mailer. 6434096Seric ** 6444096Seric ** Parameters: 64510327Seric ** line -- description of mailer. This is in labeled 64610327Seric ** fields. The fields are: 64710327Seric ** P -- the path to the mailer 64810327Seric ** F -- the flags associated with the mailer 64910327Seric ** A -- the argv for this mailer 65010327Seric ** S -- the sender rewriting set 65110327Seric ** R -- the recipient rewriting set 65210327Seric ** E -- the eol string 65310327Seric ** The first word is the canonical name of the mailer. 6544096Seric ** 6554096Seric ** Returns: 6564096Seric ** none. 6574096Seric ** 6584096Seric ** Side Effects: 6594096Seric ** enters the mailer into the mailer table. 6604096Seric */ 6613308Seric 66221066Seric makemailer(line) 6634096Seric char *line; 6644096Seric { 6654096Seric register char *p; 6668067Seric register struct mailer *m; 6678067Seric register STAB *s; 6688067Seric int i; 66910327Seric char fcode; 67058020Seric auto char *endp; 6714096Seric extern int NextMailer; 67210327Seric extern char **makeargv(); 67310327Seric extern char *munchstring(); 67410701Seric extern long atol(); 6754096Seric 67610327Seric /* allocate a mailer and set up defaults */ 67710327Seric m = (struct mailer *) xalloc(sizeof *m); 67810327Seric bzero((char *) m, sizeof *m); 67910327Seric m->m_eol = "\n"; 68010327Seric 68110327Seric /* collect the mailer name */ 68258050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 68310327Seric continue; 68410327Seric if (*p != '\0') 68510327Seric *p++ = '\0'; 68610327Seric m->m_name = newstr(line); 68710327Seric 68810327Seric /* now scan through and assign info from the fields */ 68910327Seric while (*p != '\0') 69010327Seric { 69158333Seric auto char *delimptr; 69258333Seric 69358050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 69410327Seric p++; 69510327Seric 69610327Seric /* p now points to field code */ 69710327Seric fcode = *p; 69810327Seric while (*p != '\0' && *p != '=' && *p != ',') 69910327Seric p++; 70010327Seric if (*p++ != '=') 70110327Seric { 70252637Seric syserr("mailer %s: `=' expected", m->m_name); 70310327Seric return; 70410327Seric } 70558050Seric while (isascii(*p) && isspace(*p)) 70610327Seric p++; 70710327Seric 70810327Seric /* p now points to the field body */ 70958333Seric p = munchstring(p, &delimptr); 71010327Seric 71110327Seric /* install the field into the mailer struct */ 71210327Seric switch (fcode) 71310327Seric { 71410327Seric case 'P': /* pathname */ 71510327Seric m->m_mailer = newstr(p); 71610327Seric break; 71710327Seric 71810327Seric case 'F': /* flags */ 71910687Seric for (; *p != '\0'; p++) 72058050Seric if (!(isascii(*p) && isspace(*p))) 72152637Seric setbitn(*p, m->m_flags); 72210327Seric break; 72310327Seric 72410327Seric case 'S': /* sender rewriting ruleset */ 72510327Seric case 'R': /* recipient rewriting ruleset */ 72658020Seric i = strtol(p, &endp, 10); 72710327Seric if (i < 0 || i >= MAXRWSETS) 72810327Seric { 72910327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 73010327Seric return; 73110327Seric } 73210327Seric if (fcode == 'S') 73358020Seric m->m_sh_rwset = m->m_se_rwset = i; 73410327Seric else 73558020Seric m->m_rh_rwset = m->m_re_rwset = i; 73658020Seric 73758020Seric p = endp; 73859985Seric if (*p++ == '/') 73958020Seric { 74058020Seric i = strtol(p, NULL, 10); 74158020Seric if (i < 0 || i >= MAXRWSETS) 74258020Seric { 74358020Seric syserr("invalid rewrite set, %d max", 74458020Seric MAXRWSETS); 74558020Seric return; 74658020Seric } 74758020Seric if (fcode == 'S') 74858020Seric m->m_sh_rwset = i; 74958020Seric else 75058020Seric m->m_rh_rwset = i; 75158020Seric } 75210327Seric break; 75310327Seric 75410327Seric case 'E': /* end of line string */ 75510327Seric m->m_eol = newstr(p); 75610327Seric break; 75710327Seric 75810327Seric case 'A': /* argument vector */ 75910327Seric m->m_argv = makeargv(p); 76010327Seric break; 76110701Seric 76210701Seric case 'M': /* maximum message size */ 76310701Seric m->m_maxsize = atol(p); 76410701Seric break; 76552106Seric 76652106Seric case 'L': /* maximum line length */ 76752106Seric m->m_linelimit = atoi(p); 76852106Seric break; 76958935Seric 77058935Seric case 'D': /* working directory */ 77158935Seric m->m_execdir = newstr(p); 77258935Seric break; 77310327Seric } 77410327Seric 77558333Seric p = delimptr; 77610327Seric } 77710327Seric 77852106Seric /* do some heuristic cleanup for back compatibility */ 77952106Seric if (bitnset(M_LIMITS, m->m_flags)) 78052106Seric { 78152106Seric if (m->m_linelimit == 0) 78252106Seric m->m_linelimit = SMTPLINELIM; 78355418Seric if (ConfigLevel < 2) 78452106Seric setbitn(M_7BITS, m->m_flags); 78552106Seric } 78652106Seric 78758321Seric /* do some rationality checking */ 78858321Seric if (m->m_argv == NULL) 78958321Seric { 79058321Seric syserr("M%s: A= argument required", m->m_name); 79158321Seric return; 79258321Seric } 79358321Seric if (m->m_mailer == NULL) 79458321Seric { 79558321Seric syserr("M%s: P= argument required", m->m_name); 79658321Seric return; 79758321Seric } 79858321Seric 7994096Seric if (NextMailer >= MAXMAILERS) 8004096Seric { 8019381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 8024096Seric return; 8034096Seric } 80457402Seric 80510327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 80657402Seric if (s->s_mailer != NULL) 80757402Seric { 80857402Seric i = s->s_mailer->m_mno; 80957402Seric free(s->s_mailer); 81057402Seric } 81157402Seric else 81257402Seric { 81357402Seric i = NextMailer++; 81457402Seric } 81557402Seric Mailer[i] = s->s_mailer = m; 81657454Seric m->m_mno = i; 81710327Seric } 81810327Seric /* 81910327Seric ** MUNCHSTRING -- translate a string into internal form. 82010327Seric ** 82110327Seric ** Parameters: 82210327Seric ** p -- the string to munch. 82358333Seric ** delimptr -- if non-NULL, set to the pointer of the 82458333Seric ** field delimiter character. 82510327Seric ** 82610327Seric ** Returns: 82710327Seric ** the munched string. 82810327Seric */ 8294096Seric 83010327Seric char * 83158333Seric munchstring(p, delimptr) 83210327Seric register char *p; 83358333Seric char **delimptr; 83410327Seric { 83510327Seric register char *q; 83610327Seric bool backslash = FALSE; 83710327Seric bool quotemode = FALSE; 83810327Seric static char buf[MAXLINE]; 8394096Seric 84010327Seric for (q = buf; *p != '\0'; p++) 8414096Seric { 84210327Seric if (backslash) 84310327Seric { 84410327Seric /* everything is roughly literal */ 84510357Seric backslash = FALSE; 84610327Seric switch (*p) 84710327Seric { 84810327Seric case 'r': /* carriage return */ 84910327Seric *q++ = '\r'; 85010327Seric continue; 85110327Seric 85210327Seric case 'n': /* newline */ 85310327Seric *q++ = '\n'; 85410327Seric continue; 85510327Seric 85610327Seric case 'f': /* form feed */ 85710327Seric *q++ = '\f'; 85810327Seric continue; 85910327Seric 86010327Seric case 'b': /* backspace */ 86110327Seric *q++ = '\b'; 86210327Seric continue; 86310327Seric } 86410327Seric *q++ = *p; 86510327Seric } 86610327Seric else 86710327Seric { 86810327Seric if (*p == '\\') 86910327Seric backslash = TRUE; 87010327Seric else if (*p == '"') 87110327Seric quotemode = !quotemode; 87210327Seric else if (quotemode || *p != ',') 87310327Seric *q++ = *p; 87410327Seric else 87510327Seric break; 87610327Seric } 8774096Seric } 8784096Seric 87958333Seric if (delimptr != NULL) 88058333Seric *delimptr = p; 88110327Seric *q++ = '\0'; 88210327Seric return (buf); 88310327Seric } 88410327Seric /* 88510327Seric ** MAKEARGV -- break up a string into words 88610327Seric ** 88710327Seric ** Parameters: 88810327Seric ** p -- the string to break up. 88910327Seric ** 89010327Seric ** Returns: 89110327Seric ** a char **argv (dynamically allocated) 89210327Seric ** 89310327Seric ** Side Effects: 89410327Seric ** munges p. 89510327Seric */ 8964096Seric 89710327Seric char ** 89810327Seric makeargv(p) 89910327Seric register char *p; 90010327Seric { 90110327Seric char *q; 90210327Seric int i; 90310327Seric char **avp; 90410327Seric char *argv[MAXPV + 1]; 90510327Seric 90610327Seric /* take apart the words */ 90710327Seric i = 0; 90810327Seric while (*p != '\0' && i < MAXPV) 9094096Seric { 91010327Seric q = p; 91158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 91210327Seric p++; 91358050Seric while (isascii(*p) && isspace(*p)) 91410327Seric *p++ = '\0'; 91510327Seric argv[i++] = newstr(q); 9164096Seric } 91710327Seric argv[i++] = NULL; 9184096Seric 91910327Seric /* now make a copy of the argv */ 92010327Seric avp = (char **) xalloc(sizeof *avp * i); 92116893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 92210327Seric 92310327Seric return (avp); 9243308Seric } 9253308Seric /* 9263308Seric ** PRINTRULES -- print rewrite rules (for debugging) 9273308Seric ** 9283308Seric ** Parameters: 9293308Seric ** none. 9303308Seric ** 9313308Seric ** Returns: 9323308Seric ** none. 9333308Seric ** 9343308Seric ** Side Effects: 9353308Seric ** prints rewrite rules. 9363308Seric */ 9373308Seric 9383308Seric printrules() 9393308Seric { 9403308Seric register struct rewrite *rwp; 9414072Seric register int ruleset; 9423308Seric 9434072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9443308Seric { 9454072Seric if (RewriteRules[ruleset] == NULL) 9464072Seric continue; 9478067Seric printf("\n----Rule Set %d:", ruleset); 9483308Seric 9494072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9503308Seric { 9518067Seric printf("\nLHS:"); 9528067Seric printav(rwp->r_lhs); 9538067Seric printf("RHS:"); 9548067Seric printav(rwp->r_rhs); 9553308Seric } 9563308Seric } 9573308Seric } 9584319Seric 9594096Seric /* 9608256Seric ** SETOPTION -- set global processing option 9618256Seric ** 9628256Seric ** Parameters: 9638256Seric ** opt -- option name. 9648256Seric ** val -- option value (as a text string). 96521755Seric ** safe -- set if this came from a configuration file. 96621755Seric ** Some options (if set from the command line) will 96721755Seric ** reset the user id to avoid security problems. 9688269Seric ** sticky -- if set, don't let other setoptions override 9698269Seric ** this value. 97058734Seric ** e -- the main envelope. 9718256Seric ** 9728256Seric ** Returns: 9738256Seric ** none. 9748256Seric ** 9758256Seric ** Side Effects: 9768256Seric ** Sets options as implied by the arguments. 9778256Seric */ 9788256Seric 97910687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9808269Seric 98157207Seric 98257207Seric #ifdef NAMED_BIND 98357207Seric 98457207Seric struct resolverflags 98557207Seric { 98657207Seric char *rf_name; /* name of the flag */ 98757207Seric long rf_bits; /* bits to set/clear */ 98857207Seric } ResolverFlags[] = 98957207Seric { 99057207Seric "debug", RES_DEBUG, 99157207Seric "aaonly", RES_AAONLY, 99257207Seric "usevc", RES_USEVC, 99357207Seric "primary", RES_PRIMARY, 99457207Seric "igntc", RES_IGNTC, 99557207Seric "recurse", RES_RECURSE, 99657207Seric "defnames", RES_DEFNAMES, 99757207Seric "stayopen", RES_STAYOPEN, 99857207Seric "dnsrch", RES_DNSRCH, 99957207Seric NULL, 0 100057207Seric }; 100157207Seric 100257207Seric #endif 100357207Seric 100458734Seric setoption(opt, val, safe, sticky, e) 10058256Seric char opt; 10068256Seric char *val; 100721755Seric bool safe; 10088269Seric bool sticky; 100958734Seric register ENVELOPE *e; 10108256Seric { 101157207Seric register char *p; 10128265Seric extern bool atobool(); 101312633Seric extern time_t convtime(); 101414879Seric extern int QueueLA; 101514879Seric extern int RefuseLA; 101664718Seric extern bool Warn_Q_option; 101717474Seric extern bool trusteduser(); 10188256Seric 10198256Seric if (tTd(37, 1)) 10209341Seric printf("setoption %c=%s", opt, val); 10218256Seric 10228256Seric /* 10238269Seric ** See if this option is preset for us. 10248256Seric */ 10258256Seric 102659731Seric if (!sticky && bitnset(opt, StickyOpt)) 10278269Seric { 10289341Seric if (tTd(37, 1)) 10299341Seric printf(" (ignored)\n"); 10308269Seric return; 10318269Seric } 10328269Seric 103321755Seric /* 103421755Seric ** Check to see if this option can be specified by this user. 103521755Seric */ 103621755Seric 103763787Seric if (!safe && RealUid == 0) 103821755Seric safe = TRUE; 103963837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 104021755Seric { 104139111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 104221755Seric { 104336582Sbostic if (tTd(37, 1)) 104436582Sbostic printf(" (unsafe)"); 104563787Seric if (RealUid != geteuid()) 104636582Sbostic { 104751210Seric if (tTd(37, 1)) 104851210Seric printf("(Resetting uid)"); 104963787Seric (void) setgid(RealGid); 105063787Seric (void) setuid(RealUid); 105136582Sbostic } 105221755Seric } 105321755Seric } 105451210Seric if (tTd(37, 1)) 105517985Seric printf("\n"); 10568269Seric 10578256Seric switch (opt) 10588256Seric { 105959709Seric case '7': /* force seven-bit input */ 106059709Seric SevenBit = atobool(val); 106152106Seric break; 106252106Seric 10638256Seric case 'A': /* set default alias file */ 10649381Seric if (val[0] == '\0') 106559672Seric setalias("aliases"); 10669381Seric else 106759672Seric setalias(val); 10688256Seric break; 10698256Seric 107017474Seric case 'a': /* look N minutes for "@:@" in alias file */ 107117474Seric if (val[0] == '\0') 107264796Seric SafeAlias = 5 * 60; /* five minutes */ 107317474Seric else 107464796Seric SafeAlias = convtime(val, 'm'); 107517474Seric break; 107617474Seric 107716843Seric case 'B': /* substitution for blank character */ 107816843Seric SpaceSub = val[0]; 107916843Seric if (SpaceSub == '\0') 108016843Seric SpaceSub = ' '; 108116843Seric break; 108216843Seric 108359283Seric case 'b': /* min blocks free on queue fs/max msg size */ 108459283Seric p = strchr(val, '/'); 108559283Seric if (p != NULL) 108659283Seric { 108759283Seric *p++ = '\0'; 108859283Seric MaxMessageSize = atol(p); 108959283Seric } 109058082Seric MinBlocksFree = atol(val); 109158082Seric break; 109258082Seric 10939284Seric case 'c': /* don't connect to "expensive" mailers */ 10949381Seric NoConnect = atobool(val); 10959284Seric break; 10969284Seric 109751305Seric case 'C': /* checkpoint every N addresses */ 109851305Seric CheckpointInterval = atoi(val); 109924944Seric break; 110024944Seric 11019284Seric case 'd': /* delivery mode */ 11029284Seric switch (*val) 11038269Seric { 11049284Seric case '\0': 110558734Seric e->e_sendmode = SM_DELIVER; 11068269Seric break; 11078269Seric 110810755Seric case SM_QUEUE: /* queue only */ 110910755Seric #ifndef QUEUE 111010755Seric syserr("need QUEUE to set -odqueue"); 111156795Seric #endif /* QUEUE */ 111210755Seric /* fall through..... */ 111310755Seric 11149284Seric case SM_DELIVER: /* do everything */ 11159284Seric case SM_FORK: /* fork after verification */ 111658734Seric e->e_sendmode = *val; 11178269Seric break; 11188269Seric 11198269Seric default: 11209284Seric syserr("Unknown delivery mode %c", *val); 11218269Seric exit(EX_USAGE); 11228269Seric } 11238269Seric break; 11248269Seric 11259146Seric case 'D': /* rebuild alias database as needed */ 11269381Seric AutoRebuild = atobool(val); 11279146Seric break; 11289146Seric 112955372Seric case 'E': /* error message header/header file */ 113055379Seric if (*val != '\0') 113155379Seric ErrMsgFile = newstr(val); 113255372Seric break; 113355372Seric 11348269Seric case 'e': /* set error processing mode */ 11358269Seric switch (*val) 11368269Seric { 11379381Seric case EM_QUIET: /* be silent about it */ 11389381Seric case EM_MAIL: /* mail back */ 11399381Seric case EM_BERKNET: /* do berknet error processing */ 11409381Seric case EM_WRITE: /* write back (or mail) */ 11418269Seric HoldErrs = TRUE; 11429381Seric /* fall through... */ 11438269Seric 11449381Seric case EM_PRINT: /* print errors normally (default) */ 114558734Seric e->e_errormode = *val; 11468269Seric break; 11478269Seric } 11488269Seric break; 11498269Seric 11509049Seric case 'F': /* file mode */ 115117975Seric FileMode = atooct(val) & 0777; 11529049Seric break; 11539049Seric 11548269Seric case 'f': /* save Unix-style From lines on front */ 11559381Seric SaveFrom = atobool(val); 11568269Seric break; 11578269Seric 115853735Seric case 'G': /* match recipients against GECOS field */ 115953735Seric MatchGecos = atobool(val); 116053735Seric break; 116153735Seric 11628256Seric case 'g': /* default gid */ 116364133Seric if (isascii(*val) && isdigit(*val)) 116464133Seric DefGid = atoi(val); 116564133Seric else 116664133Seric { 116764133Seric register struct group *gr; 116864133Seric 116964133Seric DefGid = -1; 117064133Seric gr = getgrnam(val); 117164133Seric if (gr == NULL) 117264133Seric syserr("readcf: option g: unknown group %s", val); 117364133Seric else 117464133Seric DefGid = gr->gr_gid; 117564133Seric } 11768256Seric break; 11778256Seric 11788256Seric case 'H': /* help file */ 11799381Seric if (val[0] == '\0') 11808269Seric HelpFile = "sendmail.hf"; 11819381Seric else 11829381Seric HelpFile = newstr(val); 11838256Seric break; 11848256Seric 118551305Seric case 'h': /* maximum hop count */ 118651305Seric MaxHopCount = atoi(val); 118751305Seric break; 118851305Seric 118935651Seric case 'I': /* use internet domain name server */ 119057207Seric #ifdef NAMED_BIND 119157207Seric UseNameServer = TRUE; 119257207Seric for (p = val; *p != 0; ) 119357207Seric { 119457207Seric bool clearmode; 119557207Seric char *q; 119657207Seric struct resolverflags *rfp; 119757207Seric 119857207Seric while (*p == ' ') 119957207Seric p++; 120057207Seric if (*p == '\0') 120157207Seric break; 120257207Seric clearmode = FALSE; 120357207Seric if (*p == '-') 120457207Seric clearmode = TRUE; 120557207Seric else if (*p != '+') 120657207Seric p--; 120757207Seric p++; 120857207Seric q = p; 120958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 121057207Seric p++; 121157207Seric if (*p != '\0') 121257207Seric *p++ = '\0'; 121357207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 121457207Seric { 121557207Seric if (strcasecmp(q, rfp->rf_name) == 0) 121657207Seric break; 121757207Seric } 121864923Seric if (rfp->rf_name == NULL) 121964923Seric syserr("readcf: I option value %s unrecognized", q); 122064923Seric else if (clearmode) 122157207Seric _res.options &= ~rfp->rf_bits; 122257207Seric else 122357207Seric _res.options |= rfp->rf_bits; 122457207Seric } 122557207Seric if (tTd(8, 2)) 122657207Seric printf("_res.options = %x\n", _res.options); 122757207Seric #else 122857207Seric usrerr("name server (I option) specified but BIND not compiled in"); 122957207Seric #endif 123035651Seric break; 123135651Seric 12328269Seric case 'i': /* ignore dot lines in message */ 12339381Seric IgnrDot = atobool(val); 12348269Seric break; 12358269Seric 123659730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 123759730Seric SendMIMEErrors = atobool(val); 123859730Seric break; 123959730Seric 124057136Seric case 'J': /* .forward search path */ 124157136Seric ForwardPath = newstr(val); 124257136Seric break; 124357136Seric 124454967Seric case 'k': /* connection cache size */ 124554967Seric MaxMciCache = atoi(val); 124656215Seric if (MaxMciCache < 0) 124756215Seric MaxMciCache = 0; 124854967Seric break; 124954967Seric 125054967Seric case 'K': /* connection cache timeout */ 125158796Seric MciCacheTimeout = convtime(val, 'm'); 125254967Seric break; 125354967Seric 125461104Seric case 'l': /* use Errors-To: header */ 125561104Seric UseErrorsTo = atobool(val); 125661104Seric break; 125761104Seric 12588256Seric case 'L': /* log level */ 125964140Seric if (safe || LogLevel < atoi(val)) 126064140Seric LogLevel = atoi(val); 12618256Seric break; 12628256Seric 12638269Seric case 'M': /* define macro */ 12649381Seric define(val[0], newstr(&val[1]), CurEnv); 126516878Seric sticky = FALSE; 12668269Seric break; 12678269Seric 12688269Seric case 'm': /* send to me too */ 12699381Seric MeToo = atobool(val); 12708269Seric break; 12718269Seric 127225820Seric case 'n': /* validate RHS in newaliases */ 127325820Seric CheckAliases = atobool(val); 127425820Seric break; 127525820Seric 127661104Seric /* 'N' available -- was "net name" */ 127761104Seric 127858851Seric case 'O': /* daemon options */ 127958851Seric setdaemonoptions(val); 128058851Seric break; 128158851Seric 12828269Seric case 'o': /* assume old style headers */ 12839381Seric if (atobool(val)) 12849341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12859341Seric else 12869341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12878269Seric break; 12888269Seric 128958082Seric case 'p': /* select privacy level */ 129058082Seric p = val; 129158082Seric for (;;) 129258082Seric { 129358082Seric register struct prival *pv; 129458082Seric extern struct prival PrivacyValues[]; 129558082Seric 129658082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 129758082Seric p++; 129858082Seric if (*p == '\0') 129958082Seric break; 130058082Seric val = p; 130158082Seric while (isascii(*p) && isalnum(*p)) 130258082Seric p++; 130358082Seric if (*p != '\0') 130458082Seric *p++ = '\0'; 130558082Seric 130658082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 130758082Seric { 130858082Seric if (strcasecmp(val, pv->pv_name) == 0) 130958082Seric break; 131058082Seric } 131158886Seric if (pv->pv_name == NULL) 131258886Seric syserr("readcf: Op line: %s unrecognized", val); 131358082Seric PrivacyFlags |= pv->pv_flag; 131458082Seric } 131558082Seric break; 131658082Seric 131724944Seric case 'P': /* postmaster copy address for returned mail */ 131824944Seric PostMasterCopy = newstr(val); 131924944Seric break; 132024944Seric 132124944Seric case 'q': /* slope of queue only function */ 132224944Seric QueueFactor = atoi(val); 132324944Seric break; 132424944Seric 13258256Seric case 'Q': /* queue directory */ 13269381Seric if (val[0] == '\0') 13278269Seric QueueDir = "mqueue"; 13289381Seric else 13299381Seric QueueDir = newstr(val); 133058789Seric if (RealUid != 0 && !safe) 133164718Seric Warn_Q_option = TRUE; 13328256Seric break; 13338256Seric 133458148Seric case 'R': /* don't prune routes */ 133558148Seric DontPruneRoutes = atobool(val); 133658148Seric break; 133758148Seric 13388256Seric case 'r': /* read timeout */ 133958112Seric settimeouts(val); 13408256Seric break; 13418256Seric 13428256Seric case 'S': /* status file */ 13439381Seric if (val[0] == '\0') 13448269Seric StatFile = "sendmail.st"; 13459381Seric else 13469381Seric StatFile = newstr(val); 13478256Seric break; 13488256Seric 13498265Seric case 's': /* be super safe, even if expensive */ 13509381Seric SuperSafe = atobool(val); 13518256Seric break; 13528256Seric 13538256Seric case 'T': /* queue timeout */ 135458737Seric p = strchr(val, '/'); 135558737Seric if (p != NULL) 135658737Seric { 135758737Seric *p++ = '\0'; 135858796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 135958737Seric } 136058796Seric TimeOuts.to_q_return = convtime(val, 'h'); 136154967Seric break; 13628256Seric 13638265Seric case 't': /* time zone name */ 136452106Seric TimeZoneSpec = newstr(val); 13658265Seric break; 13668265Seric 136750556Seric case 'U': /* location of user database */ 136851360Seric UdbSpec = newstr(val); 136950556Seric break; 137050556Seric 13718256Seric case 'u': /* set default uid */ 137264133Seric if (isascii(*val) && isdigit(*val)) 137364133Seric DefUid = atoi(val); 137464133Seric else 137564133Seric { 137664133Seric register struct passwd *pw; 137764133Seric 137864133Seric DefUid = -1; 137964133Seric pw = getpwnam(val); 138064133Seric if (pw == NULL) 138164133Seric syserr("readcf: option u: unknown user %s", val); 138264133Seric else 138364133Seric DefUid = pw->pw_uid; 138464133Seric } 138540973Sbostic setdefuser(); 13868256Seric break; 13878256Seric 138858851Seric case 'V': /* fallback MX host */ 138958851Seric FallBackMX = newstr(val); 139058851Seric break; 139158851Seric 13928269Seric case 'v': /* run in verbose mode */ 13939381Seric Verbose = atobool(val); 13948256Seric break; 13958256Seric 139663837Seric case 'w': /* if we are best MX, try host directly */ 139763837Seric TryNullMXList = atobool(val); 139863837Seric break; 139961104Seric 140061104Seric /* 'W' available -- was wizard password */ 140161104Seric 140214879Seric case 'x': /* load avg at which to auto-queue msgs */ 140314879Seric QueueLA = atoi(val); 140414879Seric break; 140514879Seric 140614879Seric case 'X': /* load avg at which to auto-reject connections */ 140714879Seric RefuseLA = atoi(val); 140814879Seric break; 140914879Seric 141024981Seric case 'y': /* work recipient factor */ 141124981Seric WkRecipFact = atoi(val); 141224981Seric break; 141324981Seric 141424981Seric case 'Y': /* fork jobs during queue runs */ 141524952Seric ForkQueueRuns = atobool(val); 141624952Seric break; 141724952Seric 141824981Seric case 'z': /* work message class factor */ 141924981Seric WkClassFact = atoi(val); 142024981Seric break; 142124981Seric 142224981Seric case 'Z': /* work time factor */ 142324981Seric WkTimeFact = atoi(val); 142424981Seric break; 142524981Seric 14268256Seric default: 14278256Seric break; 14288256Seric } 142916878Seric if (sticky) 143016878Seric setbitn(opt, StickyOpt); 14319188Seric return; 14328256Seric } 143310687Seric /* 143410687Seric ** SETCLASS -- set a word into a class 143510687Seric ** 143610687Seric ** Parameters: 143710687Seric ** class -- the class to put the word in. 143810687Seric ** word -- the word to enter 143910687Seric ** 144010687Seric ** Returns: 144110687Seric ** none. 144210687Seric ** 144310687Seric ** Side Effects: 144410687Seric ** puts the word into the symbol table. 144510687Seric */ 144610687Seric 144710687Seric setclass(class, word) 144810687Seric int class; 144910687Seric char *word; 145010687Seric { 145110687Seric register STAB *s; 145210687Seric 145357943Seric if (tTd(37, 8)) 145464326Seric printf("setclass(%c, %s)\n", class, word); 145510687Seric s = stab(word, ST_CLASS, ST_ENTER); 145610687Seric setbitn(class, s->s_class); 145710687Seric } 145853654Seric /* 145953654Seric ** MAKEMAPENTRY -- create a map entry 146053654Seric ** 146153654Seric ** Parameters: 146253654Seric ** line -- the config file line 146353654Seric ** 146453654Seric ** Returns: 146553654Seric ** TRUE if it successfully entered the map entry. 146653654Seric ** FALSE otherwise (usually syntax error). 146753654Seric ** 146853654Seric ** Side Effects: 146953654Seric ** Enters the map into the dictionary. 147053654Seric */ 147153654Seric 147253654Seric void 147353654Seric makemapentry(line) 147453654Seric char *line; 147553654Seric { 147653654Seric register char *p; 147753654Seric char *mapname; 147853654Seric char *classname; 147964078Seric register STAB *s; 148053654Seric STAB *class; 148153654Seric 148258050Seric for (p = line; isascii(*p) && isspace(*p); p++) 148353654Seric continue; 148458050Seric if (!(isascii(*p) && isalnum(*p))) 148553654Seric { 148653654Seric syserr("readcf: config K line: no map name"); 148753654Seric return; 148853654Seric } 148953654Seric 149053654Seric mapname = p; 149158050Seric while (isascii(*++p) && isalnum(*p)) 149253654Seric continue; 149353654Seric if (*p != '\0') 149453654Seric *p++ = '\0'; 149558050Seric while (isascii(*p) && isspace(*p)) 149653654Seric p++; 149758050Seric if (!(isascii(*p) && isalnum(*p))) 149853654Seric { 149953654Seric syserr("readcf: config K line, map %s: no map class", mapname); 150053654Seric return; 150153654Seric } 150253654Seric classname = p; 150358050Seric while (isascii(*++p) && isalnum(*p)) 150453654Seric continue; 150553654Seric if (*p != '\0') 150653654Seric *p++ = '\0'; 150758050Seric while (isascii(*p) && isspace(*p)) 150853654Seric p++; 150953654Seric 151053654Seric /* look up the class */ 151153654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 151253654Seric if (class == NULL) 151353654Seric { 151453654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 151553654Seric return; 151653654Seric } 151753654Seric 151853654Seric /* enter the map */ 151964078Seric s = stab(mapname, ST_MAP, ST_ENTER); 152064078Seric s->s_map.map_class = &class->s_mapclass; 152164078Seric s->s_map.map_mname = newstr(mapname); 152253654Seric 152364078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 152464078Seric s->s_map.map_mflags |= MF_VALID; 152564078Seric 152664078Seric if (tTd(37, 5)) 152764078Seric { 152864078Seric printf("map %s, class %s, flags %x, file %s,\n", 152964078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 153064078Seric s->s_map.map_mflags, 153164078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 153264078Seric printf("\tapp %s, domain %s, rebuild %s\n", 153364078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 153464078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 153564078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 153664078Seric } 153753654Seric } 153858112Seric /* 153958112Seric ** SETTIMEOUTS -- parse and set timeout values 154058112Seric ** 154158112Seric ** Parameters: 154258112Seric ** val -- a pointer to the values. If NULL, do initial 154358112Seric ** settings. 154458112Seric ** 154558112Seric ** Returns: 154658112Seric ** none. 154758112Seric ** 154858112Seric ** Side Effects: 154958112Seric ** Initializes the TimeOuts structure 155058112Seric */ 155158112Seric 155264255Seric #define SECONDS 155358112Seric #define MINUTES * 60 155458112Seric #define HOUR * 3600 155558112Seric 155658112Seric settimeouts(val) 155758112Seric register char *val; 155858112Seric { 155958112Seric register char *p; 156058671Seric extern time_t convtime(); 156158112Seric 156258112Seric if (val == NULL) 156358112Seric { 156458112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 156558112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 156658112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 156758112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 156858112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 156958112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 157058112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 157158112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 157258112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 157358112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 157458112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 157564255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 157658112Seric return; 157758112Seric } 157858112Seric 157958112Seric for (;; val = p) 158058112Seric { 158158112Seric while (isascii(*val) && isspace(*val)) 158258112Seric val++; 158358112Seric if (*val == '\0') 158458112Seric break; 158558112Seric for (p = val; *p != '\0' && *p != ','; p++) 158658112Seric continue; 158758112Seric if (*p != '\0') 158858112Seric *p++ = '\0'; 158958112Seric 159058112Seric if (isascii(*val) && isdigit(*val)) 159158112Seric { 159258112Seric /* old syntax -- set everything */ 159358796Seric TimeOuts.to_mail = convtime(val, 'm'); 159458112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 159558112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 159658112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 159758112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 159858112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 159958112Seric continue; 160058112Seric } 160158112Seric else 160258112Seric { 160358112Seric register char *q = strchr(val, '='); 160458112Seric time_t to; 160558112Seric 160658112Seric if (q == NULL) 160758112Seric { 160858112Seric /* syntax error */ 160958112Seric continue; 161058112Seric } 161158112Seric *q++ = '\0'; 161258796Seric to = convtime(q, 'm'); 161358112Seric 161458112Seric if (strcasecmp(val, "initial") == 0) 161558112Seric TimeOuts.to_initial = to; 161658112Seric else if (strcasecmp(val, "mail") == 0) 161758112Seric TimeOuts.to_mail = to; 161858112Seric else if (strcasecmp(val, "rcpt") == 0) 161958112Seric TimeOuts.to_rcpt = to; 162058112Seric else if (strcasecmp(val, "datainit") == 0) 162158112Seric TimeOuts.to_datainit = to; 162258112Seric else if (strcasecmp(val, "datablock") == 0) 162358112Seric TimeOuts.to_datablock = to; 162458112Seric else if (strcasecmp(val, "datafinal") == 0) 162558112Seric TimeOuts.to_datafinal = to; 162658112Seric else if (strcasecmp(val, "command") == 0) 162758112Seric TimeOuts.to_nextcommand = to; 162858112Seric else if (strcasecmp(val, "rset") == 0) 162958112Seric TimeOuts.to_rset = to; 163058112Seric else if (strcasecmp(val, "helo") == 0) 163158112Seric TimeOuts.to_helo = to; 163258112Seric else if (strcasecmp(val, "quit") == 0) 163358112Seric TimeOuts.to_quit = to; 163458112Seric else if (strcasecmp(val, "misc") == 0) 163558112Seric TimeOuts.to_miscshort = to; 163664255Seric else if (strcasecmp(val, "ident") == 0) 163764255Seric TimeOuts.to_ident = to; 163858112Seric else 163958112Seric syserr("settimeouts: invalid timeout %s", val); 164058112Seric } 164158112Seric } 164258112Seric } 1643