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*67546Seric static char sccsid[] = "@(#)readcf.c 8.26 (Berkeley) 07/23/94"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1464133Seric # include <pwd.h> 1564133Seric # include <grp.h> 1666334Seric #if NAMED_BIND 1757207Seric # include <resolv.h> 1857207Seric #endif 193308Seric 203308Seric /* 213308Seric ** READCF -- read control file. 223308Seric ** 233308Seric ** This routine reads the control file and builds the internal 243308Seric ** form. 253308Seric ** 264432Seric ** The file is formatted as a sequence of lines, each taken 274432Seric ** atomically. The first character of each line describes how 284432Seric ** the line is to be interpreted. The lines are: 294432Seric ** Dxval Define macro x to have value val. 304432Seric ** Cxword Put word into class x. 314432Seric ** Fxfile [fmt] Read file for lines to put into 324432Seric ** class x. Use scanf string 'fmt' 334432Seric ** or "%s" if not present. Fmt should 344432Seric ** only produce one string-valued result. 354432Seric ** Hname: value Define header with field-name 'name' 364432Seric ** and value as specified; this will be 374432Seric ** macro expanded immediately before 384432Seric ** use. 394432Seric ** Sn Use rewriting set n. 404432Seric ** Rlhs rhs Rewrite addresses that match lhs to 414432Seric ** be rhs. 4224944Seric ** Mn arg=val... Define mailer. n is the internal name. 4324944Seric ** Args specify mailer parameters. 448252Seric ** Oxvalue Set option x to value. 458252Seric ** Pname=value Set precedence name to value. 4664718Seric ** Vversioncode[/vendorcode] 4764718Seric ** Version level/vendor name of 4864718Seric ** configuration syntax. 4953654Seric ** Kmapname mapclass arguments.... 5053654Seric ** Define keyed lookup of a given class. 5153654Seric ** Arguments are class dependent. 524432Seric ** 533308Seric ** Parameters: 543308Seric ** cfname -- control file name. 5554973Seric ** safe -- TRUE if this is the system config file; 5654973Seric ** FALSE otherwise. 5755012Seric ** e -- the main envelope. 583308Seric ** 593308Seric ** Returns: 603308Seric ** none. 613308Seric ** 623308Seric ** Side Effects: 633308Seric ** Builds several internal tables. 643308Seric */ 653308Seric 6655012Seric readcf(cfname, safe, e) 673308Seric char *cfname; 6854973Seric bool safe; 6955012Seric register ENVELOPE *e; 703308Seric { 713308Seric FILE *cf; 728547Seric int ruleset = 0; 738547Seric char *q; 749350Seric struct rewrite *rwp = NULL; 7557135Seric char *bp; 7664718Seric auto char *ep; 7757589Seric int nfuzzy; 7864133Seric char *file; 7964133Seric bool optional; 803308Seric char buf[MAXLINE]; 813308Seric register char *p; 823308Seric extern char **copyplist(); 8352647Seric struct stat statb; 845909Seric char exbuf[MAXLINE]; 8565066Seric char pvpbuf[MAXLINE + MAXATOM]; 8610709Seric extern char *munchstring(); 8753654Seric extern void makemapentry(); 883308Seric 8952647Seric FileName = cfname; 9052647Seric LineNumber = 0; 9152647Seric 923308Seric cf = fopen(cfname, "r"); 933308Seric if (cf == NULL) 943308Seric { 9552647Seric syserr("cannot open"); 963308Seric exit(EX_OSFILE); 973308Seric } 983308Seric 9952647Seric if (fstat(fileno(cf), &statb) < 0) 10052647Seric { 10152647Seric syserr("cannot fstat"); 10252647Seric exit(EX_OSFILE); 10352647Seric } 10452647Seric 10552647Seric if (!S_ISREG(statb.st_mode)) 10652647Seric { 10752647Seric syserr("not a plain file"); 10852647Seric exit(EX_OSFILE); 10952647Seric } 11052647Seric 11152647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 11252647Seric { 11353037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 11453037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 11553037Seric FileName); 11653037Seric #ifdef LOG 11753037Seric if (LogLevel > 0) 11853037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 11953037Seric FileName); 12053037Seric #endif 12152647Seric } 12252647Seric 12359254Seric #ifdef XLA 12459254Seric xla_zero(); 12559254Seric #endif 12659254Seric 12757135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1283308Seric { 12957135Seric if (bp[0] == '#') 13057135Seric { 13157135Seric if (bp != buf) 13257135Seric free(bp); 13352637Seric continue; 13457135Seric } 13552637Seric 13658050Seric /* map $ into \201 for macro expansion */ 13757135Seric for (p = bp; *p != '\0'; p++) 13816157Seric { 13957135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14052647Seric { 14152647Seric /* this is an on-line comment */ 14252647Seric register char *e; 14352647Seric 14458050Seric switch (*--p & 0377) 14552647Seric { 14658050Seric case MACROEXPAND: 14752647Seric /* it's from $# -- let it go through */ 14852647Seric p++; 14952647Seric break; 15052647Seric 15152647Seric case '\\': 15252647Seric /* it's backslash escaped */ 15352647Seric (void) strcpy(p, p + 1); 15452647Seric break; 15552647Seric 15652647Seric default: 15752647Seric /* delete preceeding white space */ 15858050Seric while (isascii(*p) && isspace(*p) && p > bp) 15952647Seric p--; 16056795Seric if ((e = strchr(++p, '\n')) != NULL) 16152647Seric (void) strcpy(p, e); 16252647Seric else 16352647Seric p[0] = p[1] = '\0'; 16452647Seric break; 16552647Seric } 16652647Seric continue; 16752647Seric } 16852647Seric 16916157Seric if (*p != '$') 17016157Seric continue; 17116157Seric 17216157Seric if (p[1] == '$') 17316157Seric { 17416157Seric /* actual dollar sign.... */ 17523111Seric (void) strcpy(p, p + 1); 17616157Seric continue; 17716157Seric } 17816157Seric 17916157Seric /* convert to macro expansion character */ 18058050Seric *p = MACROEXPAND; 18116157Seric } 18216157Seric 18316157Seric /* interpret this line */ 18464718Seric errno = 0; 18557135Seric switch (bp[0]) 1863308Seric { 1873308Seric case '\0': 1883308Seric case '#': /* comment */ 1893308Seric break; 1903308Seric 1913308Seric case 'R': /* rewriting rule */ 19257135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1933308Seric continue; 1943308Seric 1953308Seric if (*p == '\0') 1965909Seric { 19765821Seric syserr("invalid rewrite line \"%s\" (tab expected)", bp); 1985909Seric break; 1995909Seric } 2005909Seric 2015909Seric /* allocate space for the rule header */ 2025909Seric if (rwp == NULL) 2035909Seric { 2045909Seric RewriteRules[ruleset] = rwp = 2055909Seric (struct rewrite *) xalloc(sizeof *rwp); 2065909Seric } 2073308Seric else 2083308Seric { 2095909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2105909Seric rwp = rwp->r_next; 2115909Seric } 2125909Seric rwp->r_next = NULL; 2133308Seric 2145909Seric /* expand and save the LHS */ 2155909Seric *p = '\0'; 21657135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 21765066Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, 21865066Seric sizeof 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); 30265066Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, 30365066Seric sizeof pvpbuf, NULL); 3045909Seric if (rwp->r_rhs != NULL) 30557589Seric { 30657589Seric register char **ap; 30757589Seric 3085909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30957589Seric 31057589Seric /* check no out-of-bounds replacements */ 31157589Seric nfuzzy += '0'; 31257589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31357589Seric { 31458148Seric char *botch; 31558148Seric 31658148Seric botch = NULL; 31758148Seric switch (**ap & 0377) 31857589Seric { 31958148Seric case MATCHREPL: 32058148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32158148Seric { 32258148Seric syserr("replacement $%c out of bounds", 32358148Seric (*ap)[1]); 32458148Seric } 32558148Seric break; 32658148Seric 32758148Seric case MATCHZANY: 32858148Seric botch = "$*"; 32958148Seric break; 33058148Seric 33158148Seric case MATCHANY: 33258148Seric botch = "$+"; 33358148Seric break; 33458148Seric 33558148Seric case MATCHONE: 33658148Seric botch = "$-"; 33758148Seric break; 33858148Seric 33958148Seric case MATCHCLASS: 34058148Seric botch = "$="; 34158148Seric break; 34258148Seric 34358148Seric case MATCHNCLASS: 34458148Seric botch = "$~"; 34558148Seric break; 34657589Seric } 34758148Seric if (botch != NULL) 34858148Seric syserr("Inappropriate use of %s on RHS", 34958148Seric botch); 35057589Seric } 35157589Seric } 35256678Seric else 35356678Seric syserr("R line: null RHS"); 3543308Seric break; 3553308Seric 3564072Seric case 'S': /* select rewriting set */ 35764440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 35864440Seric continue; 35964440Seric if (!isascii(*p) || !isdigit(*p)) 36064440Seric { 36164440Seric syserr("invalid argument to S line: \"%.20s\"", 36264440Seric &bp[1]); 36364440Seric break; 36464440Seric } 36564440Seric ruleset = atoi(p); 3668056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3678056Seric { 3689381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3698056Seric ruleset = 0; 3708056Seric } 3714072Seric rwp = NULL; 3724072Seric break; 3734072Seric 3743308Seric case 'D': /* macro definition */ 37564086Seric p = munchstring(&bp[2], NULL); 37664086Seric define(bp[1], newstr(p), e); 3773308Seric break; 3783308Seric 3793387Seric case 'H': /* required header line */ 38057135Seric (void) chompheader(&bp[1], TRUE, e); 3813387Seric break; 3823387Seric 3834061Seric case 'C': /* word class */ 3844432Seric /* scan the list of words and set class for all */ 38564121Seric expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e); 38664121Seric for (p = exbuf; *p != '\0'; ) 3874061Seric { 3884061Seric register char *wd; 3894061Seric char delim; 3904061Seric 39158050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3924061Seric p++; 3934061Seric wd = p; 39458050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3954061Seric p++; 3964061Seric delim = *p; 3974061Seric *p = '\0'; 3984061Seric if (wd[0] != '\0') 39957135Seric setclass(bp[1], wd); 4004061Seric *p = delim; 4014061Seric } 4024061Seric break; 4034061Seric 40459272Seric case 'F': /* word class from file */ 40564133Seric for (p = &bp[2]; isascii(*p) && isspace(*p); ) 40664133Seric p++; 40764133Seric if (p[0] == '-' && p[1] == 'o') 40864133Seric { 40964133Seric optional = TRUE; 41064133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41164133Seric p++; 41264133Seric while (isascii(*p) && isspace(*p)) 41364133Seric *p++; 41464133Seric } 41564133Seric else 41664133Seric optional = FALSE; 41764133Seric file = p; 41864133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41964133Seric p++; 42059272Seric if (*p == '\0') 42159272Seric p = "%s"; 42259272Seric else 42359272Seric { 42459272Seric *p = '\0'; 42559272Seric while (isascii(*++p) && isspace(*p)) 42659272Seric continue; 42759272Seric } 42864133Seric fileclass(bp[1], file, p, safe, optional); 42959272Seric break; 43059272Seric 43159156Seric #ifdef XLA 43259156Seric case 'L': /* extended load average description */ 43359156Seric xla_init(&bp[1]); 43459156Seric break; 43559156Seric #endif 43659156Seric 4374096Seric case 'M': /* define mailer */ 43857135Seric makemailer(&bp[1]); 4394096Seric break; 4404096Seric 4418252Seric case 'O': /* set option */ 44258734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4438252Seric break; 4448252Seric 4458252Seric case 'P': /* set precedence */ 4468252Seric if (NumPriorities >= MAXPRIORITIES) 4478252Seric { 4488547Seric toomany('P', MAXPRIORITIES); 4498252Seric break; 4508252Seric } 45157135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4528252Seric continue; 4538252Seric if (*p == '\0') 4548252Seric goto badline; 4558252Seric *p = '\0'; 45657135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4578252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4588252Seric NumPriorities++; 4598252Seric break; 4608252Seric 4618547Seric case 'T': /* trusted user(s) */ 46258161Seric /* this option is obsolete, but will be ignored */ 4638547Seric break; 4648547Seric 46552645Seric case 'V': /* configuration syntax version */ 46664440Seric for (p = &bp[1]; isascii(*p) && isspace(*p); p++) 46764440Seric continue; 46864440Seric if (!isascii(*p) || !isdigit(*p)) 46964440Seric { 47064440Seric syserr("invalid argument to V line: \"%.20s\"", 47164440Seric &bp[1]); 47264440Seric break; 47364440Seric } 47464718Seric ConfigLevel = strtol(p, &ep, 10); 47564279Seric if (ConfigLevel >= 5) 47664279Seric { 47764279Seric /* level 5 configs have short name in $w */ 47864279Seric p = macvalue('w', e); 47964279Seric if (p != NULL && (p = strchr(p, '.')) != NULL) 48064279Seric *p = '\0'; 48164279Seric } 48264718Seric if (*ep++ == '/') 48364718Seric { 48464718Seric /* extract vendor code */ 48564718Seric for (p = ep; isascii(*p) && isalpha(*p); ) 48664718Seric p++; 48764718Seric *p = '\0'; 48864718Seric 48964718Seric if (!setvendor(ep)) 49064718Seric syserr("invalid V line vendor code: \"%s\"", 49164718Seric ep); 49264718Seric } 49352645Seric break; 49452645Seric 49553654Seric case 'K': 49657135Seric makemapentry(&bp[1]); 49753654Seric break; 49853654Seric 4993308Seric default: 5004061Seric badline: 50157135Seric syserr("unknown control line \"%s\"", bp); 5023308Seric } 50357135Seric if (bp != buf) 50457135Seric free(bp); 5053308Seric } 50652637Seric if (ferror(cf)) 50752637Seric { 50852647Seric syserr("I/O read error", cfname); 50952637Seric exit(EX_OSFILE); 51052637Seric } 51152637Seric fclose(cf); 5129381Seric FileName = NULL; 51356836Seric 51457076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 51557076Seric { 51657076Seric /* user didn't initialize: set up host map */ 51757076Seric strcpy(buf, "host host"); 51866334Seric #if NAMED_BIND 51957076Seric if (ConfigLevel >= 2) 52057076Seric strcat(buf, " -a."); 52164947Seric #endif 52257076Seric makemapentry(buf); 52357076Seric } 5244096Seric } 5254096Seric /* 5268547Seric ** TOOMANY -- signal too many of some option 5278547Seric ** 5288547Seric ** Parameters: 5298547Seric ** id -- the id of the error line 5308547Seric ** maxcnt -- the maximum possible values 5318547Seric ** 5328547Seric ** Returns: 5338547Seric ** none. 5348547Seric ** 5358547Seric ** Side Effects: 5368547Seric ** gives a syserr. 5378547Seric */ 5388547Seric 5398547Seric toomany(id, maxcnt) 5408547Seric char id; 5418547Seric int maxcnt; 5428547Seric { 5439381Seric syserr("too many %c lines, %d max", id, maxcnt); 5448547Seric } 5458547Seric /* 5464432Seric ** FILECLASS -- read members of a class from a file 5474432Seric ** 5484432Seric ** Parameters: 5494432Seric ** class -- class to define. 5504432Seric ** filename -- name of file to read. 5514432Seric ** fmt -- scanf string to use for match. 55264133Seric ** safe -- if set, this is a safe read. 55364133Seric ** optional -- if set, it is not an error for the file to 55464133Seric ** not exist. 5554432Seric ** 5564432Seric ** Returns: 5574432Seric ** none 5584432Seric ** 5594432Seric ** Side Effects: 5604432Seric ** 5614432Seric ** puts all lines in filename that match a scanf into 5624432Seric ** the named class. 5634432Seric */ 5644432Seric 56564133Seric fileclass(class, filename, fmt, safe, optional) 5664432Seric int class; 5674432Seric char *filename; 5684432Seric char *fmt; 56954973Seric bool safe; 57064133Seric bool optional; 5714432Seric { 57225808Seric FILE *f; 57354973Seric struct stat stbuf; 5744432Seric char buf[MAXLINE]; 5754432Seric 57666101Seric if (tTd(37, 2)) 57766101Seric printf("fileclass(%s, fmt=%s)\n", filename, fmt); 57866101Seric 57966031Seric if (filename[0] == '|') 58066031Seric { 58166031Seric syserr("fileclass: pipes (F%c%s) not supported due to security problems", 58266031Seric class, filename); 58366031Seric return; 58466031Seric } 58554973Seric if (stat(filename, &stbuf) < 0) 58654973Seric { 58766101Seric if (tTd(37, 2)) 58866101Seric printf(" cannot stat (%s)\n", errstring(errno)); 58964133Seric if (!optional) 59064133Seric syserr("fileclass: cannot stat %s", filename); 59154973Seric return; 59254973Seric } 59354973Seric if (!S_ISREG(stbuf.st_mode)) 59454973Seric { 59554973Seric syserr("fileclass: %s not a regular file", filename); 59654973Seric return; 59754973Seric } 59854973Seric if (!safe && access(filename, R_OK) < 0) 59954973Seric { 60054973Seric syserr("fileclass: access denied on %s", filename); 60154973Seric return; 60254973Seric } 60354973Seric f = fopen(filename, "r"); 6044432Seric if (f == NULL) 6054432Seric { 60654973Seric syserr("fileclass: cannot open %s", filename); 6074432Seric return; 6084432Seric } 6094432Seric 6104432Seric while (fgets(buf, sizeof buf, f) != NULL) 6114432Seric { 6124432Seric register STAB *s; 61325808Seric register char *p; 61425808Seric # ifdef SCANF 6154432Seric char wordbuf[MAXNAME+1]; 6164432Seric 6174432Seric if (sscanf(buf, fmt, wordbuf) != 1) 6184432Seric continue; 61925808Seric p = wordbuf; 62056795Seric # else /* SCANF */ 62125808Seric p = buf; 62256795Seric # endif /* SCANF */ 62325808Seric 62425808Seric /* 62525808Seric ** Break up the match into words. 62625808Seric */ 62725808Seric 62825808Seric while (*p != '\0') 62925808Seric { 63025808Seric register char *q; 63125808Seric 63225808Seric /* strip leading spaces */ 63358050Seric while (isascii(*p) && isspace(*p)) 63425808Seric p++; 63525808Seric if (*p == '\0') 63625808Seric break; 63725808Seric 63825808Seric /* find the end of the word */ 63925808Seric q = p; 64058050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 64125808Seric p++; 64225808Seric if (*p != '\0') 64325808Seric *p++ = '\0'; 64425808Seric 64525808Seric /* enter the word in the symbol table */ 64666101Seric setclass(class, q); 64725808Seric } 6484432Seric } 6494432Seric 65054973Seric (void) fclose(f); 6514432Seric } 6524432Seric /* 6534096Seric ** MAKEMAILER -- define a new mailer. 6544096Seric ** 6554096Seric ** Parameters: 65610327Seric ** line -- description of mailer. This is in labeled 65710327Seric ** fields. The fields are: 65810327Seric ** P -- the path to the mailer 65910327Seric ** F -- the flags associated with the mailer 66010327Seric ** A -- the argv for this mailer 66110327Seric ** S -- the sender rewriting set 66210327Seric ** R -- the recipient rewriting set 66310327Seric ** E -- the eol string 66410327Seric ** The first word is the canonical name of the mailer. 6654096Seric ** 6664096Seric ** Returns: 6674096Seric ** none. 6684096Seric ** 6694096Seric ** Side Effects: 6704096Seric ** enters the mailer into the mailer table. 6714096Seric */ 6723308Seric 67321066Seric makemailer(line) 6744096Seric char *line; 6754096Seric { 6764096Seric register char *p; 6778067Seric register struct mailer *m; 6788067Seric register STAB *s; 6798067Seric int i; 68010327Seric char fcode; 68158020Seric auto char *endp; 6824096Seric extern int NextMailer; 68310327Seric extern char **makeargv(); 68410327Seric extern char *munchstring(); 68510701Seric extern long atol(); 6864096Seric 68710327Seric /* allocate a mailer and set up defaults */ 68810327Seric m = (struct mailer *) xalloc(sizeof *m); 68910327Seric bzero((char *) m, sizeof *m); 69010327Seric m->m_eol = "\n"; 69110327Seric 69210327Seric /* collect the mailer name */ 69358050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 69410327Seric continue; 69510327Seric if (*p != '\0') 69610327Seric *p++ = '\0'; 69710327Seric m->m_name = newstr(line); 69810327Seric 69910327Seric /* now scan through and assign info from the fields */ 70010327Seric while (*p != '\0') 70110327Seric { 70258333Seric auto char *delimptr; 70358333Seric 70458050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 70510327Seric p++; 70610327Seric 70710327Seric /* p now points to field code */ 70810327Seric fcode = *p; 70910327Seric while (*p != '\0' && *p != '=' && *p != ',') 71010327Seric p++; 71110327Seric if (*p++ != '=') 71210327Seric { 71352637Seric syserr("mailer %s: `=' expected", m->m_name); 71410327Seric return; 71510327Seric } 71658050Seric while (isascii(*p) && isspace(*p)) 71710327Seric p++; 71810327Seric 71910327Seric /* p now points to the field body */ 72058333Seric p = munchstring(p, &delimptr); 72110327Seric 72210327Seric /* install the field into the mailer struct */ 72310327Seric switch (fcode) 72410327Seric { 72510327Seric case 'P': /* pathname */ 72610327Seric m->m_mailer = newstr(p); 72710327Seric break; 72810327Seric 72910327Seric case 'F': /* flags */ 73010687Seric for (; *p != '\0'; p++) 73158050Seric if (!(isascii(*p) && isspace(*p))) 73252637Seric setbitn(*p, m->m_flags); 73310327Seric break; 73410327Seric 73510327Seric case 'S': /* sender rewriting ruleset */ 73610327Seric case 'R': /* recipient rewriting ruleset */ 73758020Seric i = strtol(p, &endp, 10); 73810327Seric if (i < 0 || i >= MAXRWSETS) 73910327Seric { 74010327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 74110327Seric return; 74210327Seric } 74310327Seric if (fcode == 'S') 74458020Seric m->m_sh_rwset = m->m_se_rwset = i; 74510327Seric else 74658020Seric m->m_rh_rwset = m->m_re_rwset = i; 74758020Seric 74858020Seric p = endp; 74959985Seric if (*p++ == '/') 75058020Seric { 75158020Seric i = strtol(p, NULL, 10); 75258020Seric if (i < 0 || i >= MAXRWSETS) 75358020Seric { 75458020Seric syserr("invalid rewrite set, %d max", 75558020Seric MAXRWSETS); 75658020Seric return; 75758020Seric } 75858020Seric if (fcode == 'S') 75958020Seric m->m_sh_rwset = i; 76058020Seric else 76158020Seric m->m_rh_rwset = i; 76258020Seric } 76310327Seric break; 76410327Seric 76510327Seric case 'E': /* end of line string */ 76610327Seric m->m_eol = newstr(p); 76710327Seric break; 76810327Seric 76910327Seric case 'A': /* argument vector */ 77010327Seric m->m_argv = makeargv(p); 77110327Seric break; 77210701Seric 77310701Seric case 'M': /* maximum message size */ 77410701Seric m->m_maxsize = atol(p); 77510701Seric break; 77652106Seric 77752106Seric case 'L': /* maximum line length */ 77852106Seric m->m_linelimit = atoi(p); 77952106Seric break; 78058935Seric 78158935Seric case 'D': /* working directory */ 78258935Seric m->m_execdir = newstr(p); 78358935Seric break; 78410327Seric } 78510327Seric 78658333Seric p = delimptr; 78710327Seric } 78810327Seric 78952106Seric /* do some heuristic cleanup for back compatibility */ 79052106Seric if (bitnset(M_LIMITS, m->m_flags)) 79152106Seric { 79252106Seric if (m->m_linelimit == 0) 79352106Seric m->m_linelimit = SMTPLINELIM; 79455418Seric if (ConfigLevel < 2) 79552106Seric setbitn(M_7BITS, m->m_flags); 79652106Seric } 79752106Seric 79858321Seric /* do some rationality checking */ 79958321Seric if (m->m_argv == NULL) 80058321Seric { 80158321Seric syserr("M%s: A= argument required", m->m_name); 80258321Seric return; 80358321Seric } 80458321Seric if (m->m_mailer == NULL) 80558321Seric { 80658321Seric syserr("M%s: P= argument required", m->m_name); 80758321Seric return; 80858321Seric } 80958321Seric 8104096Seric if (NextMailer >= MAXMAILERS) 8114096Seric { 8129381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 8134096Seric return; 8144096Seric } 81557402Seric 81610327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 81757402Seric if (s->s_mailer != NULL) 81857402Seric { 81957402Seric i = s->s_mailer->m_mno; 82057402Seric free(s->s_mailer); 82157402Seric } 82257402Seric else 82357402Seric { 82457402Seric i = NextMailer++; 82557402Seric } 82657402Seric Mailer[i] = s->s_mailer = m; 82757454Seric m->m_mno = i; 82810327Seric } 82910327Seric /* 83010327Seric ** MUNCHSTRING -- translate a string into internal form. 83110327Seric ** 83210327Seric ** Parameters: 83310327Seric ** p -- the string to munch. 83458333Seric ** delimptr -- if non-NULL, set to the pointer of the 83558333Seric ** field delimiter character. 83610327Seric ** 83710327Seric ** Returns: 83810327Seric ** the munched string. 83910327Seric */ 8404096Seric 84110327Seric char * 84258333Seric munchstring(p, delimptr) 84310327Seric register char *p; 84458333Seric char **delimptr; 84510327Seric { 84610327Seric register char *q; 84710327Seric bool backslash = FALSE; 84810327Seric bool quotemode = FALSE; 84910327Seric static char buf[MAXLINE]; 8504096Seric 85110327Seric for (q = buf; *p != '\0'; p++) 8524096Seric { 85310327Seric if (backslash) 85410327Seric { 85510327Seric /* everything is roughly literal */ 85610357Seric backslash = FALSE; 85710327Seric switch (*p) 85810327Seric { 85910327Seric case 'r': /* carriage return */ 86010327Seric *q++ = '\r'; 86110327Seric continue; 86210327Seric 86310327Seric case 'n': /* newline */ 86410327Seric *q++ = '\n'; 86510327Seric continue; 86610327Seric 86710327Seric case 'f': /* form feed */ 86810327Seric *q++ = '\f'; 86910327Seric continue; 87010327Seric 87110327Seric case 'b': /* backspace */ 87210327Seric *q++ = '\b'; 87310327Seric continue; 87410327Seric } 87510327Seric *q++ = *p; 87610327Seric } 87710327Seric else 87810327Seric { 87910327Seric if (*p == '\\') 88010327Seric backslash = TRUE; 88110327Seric else if (*p == '"') 88210327Seric quotemode = !quotemode; 88310327Seric else if (quotemode || *p != ',') 88410327Seric *q++ = *p; 88510327Seric else 88610327Seric break; 88710327Seric } 8884096Seric } 8894096Seric 89058333Seric if (delimptr != NULL) 89158333Seric *delimptr = p; 89210327Seric *q++ = '\0'; 89310327Seric return (buf); 89410327Seric } 89510327Seric /* 89610327Seric ** MAKEARGV -- break up a string into words 89710327Seric ** 89810327Seric ** Parameters: 89910327Seric ** p -- the string to break up. 90010327Seric ** 90110327Seric ** Returns: 90210327Seric ** a char **argv (dynamically allocated) 90310327Seric ** 90410327Seric ** Side Effects: 90510327Seric ** munges p. 90610327Seric */ 9074096Seric 90810327Seric char ** 90910327Seric makeargv(p) 91010327Seric register char *p; 91110327Seric { 91210327Seric char *q; 91310327Seric int i; 91410327Seric char **avp; 91510327Seric char *argv[MAXPV + 1]; 91610327Seric 91710327Seric /* take apart the words */ 91810327Seric i = 0; 91910327Seric while (*p != '\0' && i < MAXPV) 9204096Seric { 92110327Seric q = p; 92258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 92310327Seric p++; 92458050Seric while (isascii(*p) && isspace(*p)) 92510327Seric *p++ = '\0'; 92610327Seric argv[i++] = newstr(q); 9274096Seric } 92810327Seric argv[i++] = NULL; 9294096Seric 93010327Seric /* now make a copy of the argv */ 93110327Seric avp = (char **) xalloc(sizeof *avp * i); 93216893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 93310327Seric 93410327Seric return (avp); 9353308Seric } 9363308Seric /* 9373308Seric ** PRINTRULES -- print rewrite rules (for debugging) 9383308Seric ** 9393308Seric ** Parameters: 9403308Seric ** none. 9413308Seric ** 9423308Seric ** Returns: 9433308Seric ** none. 9443308Seric ** 9453308Seric ** Side Effects: 9463308Seric ** prints rewrite rules. 9473308Seric */ 9483308Seric 9493308Seric printrules() 9503308Seric { 9513308Seric register struct rewrite *rwp; 9524072Seric register int ruleset; 9533308Seric 9544072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9553308Seric { 9564072Seric if (RewriteRules[ruleset] == NULL) 9574072Seric continue; 9588067Seric printf("\n----Rule Set %d:", ruleset); 9593308Seric 9604072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9613308Seric { 9628067Seric printf("\nLHS:"); 9638067Seric printav(rwp->r_lhs); 9648067Seric printf("RHS:"); 9658067Seric printav(rwp->r_rhs); 9663308Seric } 9673308Seric } 9683308Seric } 9694319Seric 9704096Seric /* 9718256Seric ** SETOPTION -- set global processing option 9728256Seric ** 9738256Seric ** Parameters: 9748256Seric ** opt -- option name. 9758256Seric ** val -- option value (as a text string). 97621755Seric ** safe -- set if this came from a configuration file. 97721755Seric ** Some options (if set from the command line) will 97821755Seric ** reset the user id to avoid security problems. 9798269Seric ** sticky -- if set, don't let other setoptions override 9808269Seric ** this value. 98158734Seric ** e -- the main envelope. 9828256Seric ** 9838256Seric ** Returns: 9848256Seric ** none. 9858256Seric ** 9868256Seric ** Side Effects: 9878256Seric ** Sets options as implied by the arguments. 9888256Seric */ 9898256Seric 99010687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9918269Seric 99257207Seric 99366334Seric #if NAMED_BIND 99457207Seric 99557207Seric struct resolverflags 99657207Seric { 99757207Seric char *rf_name; /* name of the flag */ 99857207Seric long rf_bits; /* bits to set/clear */ 99957207Seric } ResolverFlags[] = 100057207Seric { 100157207Seric "debug", RES_DEBUG, 100257207Seric "aaonly", RES_AAONLY, 100357207Seric "usevc", RES_USEVC, 100457207Seric "primary", RES_PRIMARY, 100557207Seric "igntc", RES_IGNTC, 100657207Seric "recurse", RES_RECURSE, 100757207Seric "defnames", RES_DEFNAMES, 100857207Seric "stayopen", RES_STAYOPEN, 100957207Seric "dnsrch", RES_DNSRCH, 101065583Seric "true", 0, /* to avoid error on old syntax */ 101157207Seric NULL, 0 101257207Seric }; 101357207Seric 101457207Seric #endif 101557207Seric 101658734Seric setoption(opt, val, safe, sticky, e) 10178256Seric char opt; 10188256Seric char *val; 101921755Seric bool safe; 10208269Seric bool sticky; 102158734Seric register ENVELOPE *e; 10228256Seric { 102357207Seric register char *p; 10248265Seric extern bool atobool(); 102512633Seric extern time_t convtime(); 102614879Seric extern int QueueLA; 102714879Seric extern int RefuseLA; 102864718Seric extern bool Warn_Q_option; 102917474Seric extern bool trusteduser(); 10308256Seric 10318256Seric if (tTd(37, 1)) 10329341Seric printf("setoption %c=%s", opt, val); 10338256Seric 10348256Seric /* 10358269Seric ** See if this option is preset for us. 10368256Seric */ 10378256Seric 103859731Seric if (!sticky && bitnset(opt, StickyOpt)) 10398269Seric { 10409341Seric if (tTd(37, 1)) 10419341Seric printf(" (ignored)\n"); 10428269Seric return; 10438269Seric } 10448269Seric 104521755Seric /* 104621755Seric ** Check to see if this option can be specified by this user. 104721755Seric */ 104821755Seric 104963787Seric if (!safe && RealUid == 0) 105021755Seric safe = TRUE; 105166383Scorrigan if (!safe && strchr("bCdeijLmoprsvw7", opt) == NULL) 105221755Seric { 105339111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 105421755Seric { 105536582Sbostic if (tTd(37, 1)) 105636582Sbostic printf(" (unsafe)"); 105763787Seric if (RealUid != geteuid()) 105836582Sbostic { 105951210Seric if (tTd(37, 1)) 106051210Seric printf("(Resetting uid)"); 106163787Seric (void) setgid(RealGid); 106263787Seric (void) setuid(RealUid); 106336582Sbostic } 106421755Seric } 106521755Seric } 106651210Seric if (tTd(37, 1)) 106717985Seric printf("\n"); 10688269Seric 10698256Seric switch (opt) 10708256Seric { 107159709Seric case '7': /* force seven-bit input */ 1072*67546Seric SevenBitInput = atobool(val); 107352106Seric break; 107452106Seric 1075*67546Seric case '8': /* handling of 8-bit input */ 1076*67546Seric switch (*val) 1077*67546Seric { 1078*67546Seric case 'r': /* reject all 8-bit */ 1079*67546Seric MimeMode = 0; 1080*67546Seric break; 1081*67546Seric 1082*67546Seric case 'c': /* convert all 8-bit */ 1083*67546Seric MimeMode = MM_CVTMIME|MM_MIME8BIT; 1084*67546Seric break; 1085*67546Seric 1086*67546Seric case 'm': /* minimal encoding */ 1087*67546Seric MimeMode = MM_PASS8BIT; 1088*67546Seric break; 1089*67546Seric 1090*67546Seric case 'p': /* pass 8 bit, convert MIME */ 1091*67546Seric MimeMode = MM_PASS8BIT|MM_CVTMIME; 1092*67546Seric break; 1093*67546Seric 1094*67546Seric case 's': /* strict adherence */ 1095*67546Seric MimeMode = MM_CVTMIME; 1096*67546Seric break; 1097*67546Seric 1098*67546Seric case 'e': /* encode 8 bit if available */ 1099*67546Seric MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME; 1100*67546Seric break; 1101*67546Seric 1102*67546Seric default: 1103*67546Seric syserr("Unknown 8-bit mode %c", *val); 1104*67546Seric exit(EX_USAGE); 1105*67546Seric } 1106*67546Seric break; 1107*67546Seric 11088256Seric case 'A': /* set default alias file */ 11099381Seric if (val[0] == '\0') 111059672Seric setalias("aliases"); 11119381Seric else 111259672Seric setalias(val); 11138256Seric break; 11148256Seric 111517474Seric case 'a': /* look N minutes for "@:@" in alias file */ 111617474Seric if (val[0] == '\0') 111764796Seric SafeAlias = 5 * 60; /* five minutes */ 111817474Seric else 111964796Seric SafeAlias = convtime(val, 'm'); 112017474Seric break; 112117474Seric 112216843Seric case 'B': /* substitution for blank character */ 112316843Seric SpaceSub = val[0]; 112416843Seric if (SpaceSub == '\0') 112516843Seric SpaceSub = ' '; 112616843Seric break; 112716843Seric 112859283Seric case 'b': /* min blocks free on queue fs/max msg size */ 112959283Seric p = strchr(val, '/'); 113059283Seric if (p != NULL) 113159283Seric { 113259283Seric *p++ = '\0'; 113359283Seric MaxMessageSize = atol(p); 113459283Seric } 113558082Seric MinBlocksFree = atol(val); 113658082Seric break; 113758082Seric 11389284Seric case 'c': /* don't connect to "expensive" mailers */ 11399381Seric NoConnect = atobool(val); 11409284Seric break; 11419284Seric 114251305Seric case 'C': /* checkpoint every N addresses */ 114351305Seric CheckpointInterval = atoi(val); 114424944Seric break; 114524944Seric 11469284Seric case 'd': /* delivery mode */ 11479284Seric switch (*val) 11488269Seric { 11499284Seric case '\0': 115058734Seric e->e_sendmode = SM_DELIVER; 11518269Seric break; 11528269Seric 115310755Seric case SM_QUEUE: /* queue only */ 115410755Seric #ifndef QUEUE 115510755Seric syserr("need QUEUE to set -odqueue"); 115656795Seric #endif /* QUEUE */ 115710755Seric /* fall through..... */ 115810755Seric 11599284Seric case SM_DELIVER: /* do everything */ 11609284Seric case SM_FORK: /* fork after verification */ 116158734Seric e->e_sendmode = *val; 11628269Seric break; 11638269Seric 11648269Seric default: 11659284Seric syserr("Unknown delivery mode %c", *val); 11668269Seric exit(EX_USAGE); 11678269Seric } 11688269Seric break; 11698269Seric 11709146Seric case 'D': /* rebuild alias database as needed */ 11719381Seric AutoRebuild = atobool(val); 11729146Seric break; 11739146Seric 117455372Seric case 'E': /* error message header/header file */ 117555379Seric if (*val != '\0') 117655379Seric ErrMsgFile = newstr(val); 117755372Seric break; 117855372Seric 11798269Seric case 'e': /* set error processing mode */ 11808269Seric switch (*val) 11818269Seric { 11829381Seric case EM_QUIET: /* be silent about it */ 11839381Seric case EM_MAIL: /* mail back */ 11849381Seric case EM_BERKNET: /* do berknet error processing */ 11859381Seric case EM_WRITE: /* write back (or mail) */ 11869381Seric case EM_PRINT: /* print errors normally (default) */ 118758734Seric e->e_errormode = *val; 11888269Seric break; 11898269Seric } 11908269Seric break; 11918269Seric 11929049Seric case 'F': /* file mode */ 119317975Seric FileMode = atooct(val) & 0777; 11949049Seric break; 11959049Seric 11968269Seric case 'f': /* save Unix-style From lines on front */ 11979381Seric SaveFrom = atobool(val); 11988269Seric break; 11998269Seric 120053735Seric case 'G': /* match recipients against GECOS field */ 120153735Seric MatchGecos = atobool(val); 120253735Seric break; 120353735Seric 12048256Seric case 'g': /* default gid */ 120564133Seric if (isascii(*val) && isdigit(*val)) 120664133Seric DefGid = atoi(val); 120764133Seric else 120864133Seric { 120964133Seric register struct group *gr; 121064133Seric 121164133Seric DefGid = -1; 121264133Seric gr = getgrnam(val); 121364133Seric if (gr == NULL) 121464133Seric syserr("readcf: option g: unknown group %s", val); 121564133Seric else 121664133Seric DefGid = gr->gr_gid; 121764133Seric } 12188256Seric break; 12198256Seric 12208256Seric case 'H': /* help file */ 12219381Seric if (val[0] == '\0') 12228269Seric HelpFile = "sendmail.hf"; 12239381Seric else 12249381Seric HelpFile = newstr(val); 12258256Seric break; 12268256Seric 122751305Seric case 'h': /* maximum hop count */ 122851305Seric MaxHopCount = atoi(val); 122951305Seric break; 123051305Seric 123135651Seric case 'I': /* use internet domain name server */ 123266334Seric #if NAMED_BIND 123357207Seric UseNameServer = TRUE; 123457207Seric for (p = val; *p != 0; ) 123557207Seric { 123657207Seric bool clearmode; 123757207Seric char *q; 123857207Seric struct resolverflags *rfp; 123957207Seric 124057207Seric while (*p == ' ') 124157207Seric p++; 124257207Seric if (*p == '\0') 124357207Seric break; 124457207Seric clearmode = FALSE; 124557207Seric if (*p == '-') 124657207Seric clearmode = TRUE; 124757207Seric else if (*p != '+') 124857207Seric p--; 124957207Seric p++; 125057207Seric q = p; 125158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 125257207Seric p++; 125357207Seric if (*p != '\0') 125457207Seric *p++ = '\0'; 125557207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 125657207Seric { 125757207Seric if (strcasecmp(q, rfp->rf_name) == 0) 125857207Seric break; 125957207Seric } 126064923Seric if (rfp->rf_name == NULL) 126164923Seric syserr("readcf: I option value %s unrecognized", q); 126264923Seric else if (clearmode) 126357207Seric _res.options &= ~rfp->rf_bits; 126457207Seric else 126557207Seric _res.options |= rfp->rf_bits; 126657207Seric } 126757207Seric if (tTd(8, 2)) 126857207Seric printf("_res.options = %x\n", _res.options); 126957207Seric #else 127057207Seric usrerr("name server (I option) specified but BIND not compiled in"); 127157207Seric #endif 127235651Seric break; 127335651Seric 12748269Seric case 'i': /* ignore dot lines in message */ 12759381Seric IgnrDot = atobool(val); 12768269Seric break; 12778269Seric 127859730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 127959730Seric SendMIMEErrors = atobool(val); 128059730Seric break; 128159730Seric 128257136Seric case 'J': /* .forward search path */ 128357136Seric ForwardPath = newstr(val); 128457136Seric break; 128557136Seric 128654967Seric case 'k': /* connection cache size */ 128754967Seric MaxMciCache = atoi(val); 128856215Seric if (MaxMciCache < 0) 128956215Seric MaxMciCache = 0; 129054967Seric break; 129154967Seric 129254967Seric case 'K': /* connection cache timeout */ 129358796Seric MciCacheTimeout = convtime(val, 'm'); 129454967Seric break; 129554967Seric 129661104Seric case 'l': /* use Errors-To: header */ 129761104Seric UseErrorsTo = atobool(val); 129861104Seric break; 129961104Seric 13008256Seric case 'L': /* log level */ 130164140Seric if (safe || LogLevel < atoi(val)) 130264140Seric LogLevel = atoi(val); 13038256Seric break; 13048256Seric 13058269Seric case 'M': /* define macro */ 13069381Seric define(val[0], newstr(&val[1]), CurEnv); 130716878Seric sticky = FALSE; 13088269Seric break; 13098269Seric 13108269Seric case 'm': /* send to me too */ 13119381Seric MeToo = atobool(val); 13128269Seric break; 13138269Seric 131425820Seric case 'n': /* validate RHS in newaliases */ 131525820Seric CheckAliases = atobool(val); 131625820Seric break; 131725820Seric 131861104Seric /* 'N' available -- was "net name" */ 131961104Seric 132058851Seric case 'O': /* daemon options */ 132158851Seric setdaemonoptions(val); 132258851Seric break; 132358851Seric 13248269Seric case 'o': /* assume old style headers */ 13259381Seric if (atobool(val)) 13269341Seric CurEnv->e_flags |= EF_OLDSTYLE; 13279341Seric else 13289341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 13298269Seric break; 13308269Seric 133158082Seric case 'p': /* select privacy level */ 133258082Seric p = val; 133358082Seric for (;;) 133458082Seric { 133558082Seric register struct prival *pv; 133658082Seric extern struct prival PrivacyValues[]; 133758082Seric 133858082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 133958082Seric p++; 134058082Seric if (*p == '\0') 134158082Seric break; 134258082Seric val = p; 134358082Seric while (isascii(*p) && isalnum(*p)) 134458082Seric p++; 134558082Seric if (*p != '\0') 134658082Seric *p++ = '\0'; 134758082Seric 134858082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 134958082Seric { 135058082Seric if (strcasecmp(val, pv->pv_name) == 0) 135158082Seric break; 135258082Seric } 135358886Seric if (pv->pv_name == NULL) 135458886Seric syserr("readcf: Op line: %s unrecognized", val); 135558082Seric PrivacyFlags |= pv->pv_flag; 135658082Seric } 135758082Seric break; 135858082Seric 135924944Seric case 'P': /* postmaster copy address for returned mail */ 136024944Seric PostMasterCopy = newstr(val); 136124944Seric break; 136224944Seric 136324944Seric case 'q': /* slope of queue only function */ 136424944Seric QueueFactor = atoi(val); 136524944Seric break; 136624944Seric 13678256Seric case 'Q': /* queue directory */ 13689381Seric if (val[0] == '\0') 13698269Seric QueueDir = "mqueue"; 13709381Seric else 13719381Seric QueueDir = newstr(val); 137258789Seric if (RealUid != 0 && !safe) 137364718Seric Warn_Q_option = TRUE; 13748256Seric break; 13758256Seric 137658148Seric case 'R': /* don't prune routes */ 137758148Seric DontPruneRoutes = atobool(val); 137858148Seric break; 137958148Seric 13808256Seric case 'r': /* read timeout */ 138158112Seric settimeouts(val); 13828256Seric break; 13838256Seric 13848256Seric case 'S': /* status file */ 13859381Seric if (val[0] == '\0') 13868269Seric StatFile = "sendmail.st"; 13879381Seric else 13889381Seric StatFile = newstr(val); 13898256Seric break; 13908256Seric 13918265Seric case 's': /* be super safe, even if expensive */ 13929381Seric SuperSafe = atobool(val); 13938256Seric break; 13948256Seric 13958256Seric case 'T': /* queue timeout */ 139658737Seric p = strchr(val, '/'); 139758737Seric if (p != NULL) 139858737Seric { 139958737Seric *p++ = '\0'; 140058796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 140158737Seric } 140258796Seric TimeOuts.to_q_return = convtime(val, 'h'); 140354967Seric break; 14048256Seric 14058265Seric case 't': /* time zone name */ 140652106Seric TimeZoneSpec = newstr(val); 14078265Seric break; 14088265Seric 140950556Seric case 'U': /* location of user database */ 141051360Seric UdbSpec = newstr(val); 141150556Seric break; 141250556Seric 14138256Seric case 'u': /* set default uid */ 141464133Seric if (isascii(*val) && isdigit(*val)) 141564133Seric DefUid = atoi(val); 141664133Seric else 141764133Seric { 141864133Seric register struct passwd *pw; 141964133Seric 142064133Seric DefUid = -1; 142164133Seric pw = getpwnam(val); 142264133Seric if (pw == NULL) 142364133Seric syserr("readcf: option u: unknown user %s", val); 142464133Seric else 142564133Seric DefUid = pw->pw_uid; 142664133Seric } 142740973Sbostic setdefuser(); 14288256Seric break; 14298256Seric 143058851Seric case 'V': /* fallback MX host */ 143158851Seric FallBackMX = newstr(val); 143258851Seric break; 143358851Seric 14348269Seric case 'v': /* run in verbose mode */ 14359381Seric Verbose = atobool(val); 14368256Seric break; 14378256Seric 143863837Seric case 'w': /* if we are best MX, try host directly */ 143963837Seric TryNullMXList = atobool(val); 144063837Seric break; 144161104Seric 144261104Seric /* 'W' available -- was wizard password */ 144361104Seric 144414879Seric case 'x': /* load avg at which to auto-queue msgs */ 144514879Seric QueueLA = atoi(val); 144614879Seric break; 144714879Seric 144814879Seric case 'X': /* load avg at which to auto-reject connections */ 144914879Seric RefuseLA = atoi(val); 145014879Seric break; 145114879Seric 145224981Seric case 'y': /* work recipient factor */ 145324981Seric WkRecipFact = atoi(val); 145424981Seric break; 145524981Seric 145624981Seric case 'Y': /* fork jobs during queue runs */ 145724952Seric ForkQueueRuns = atobool(val); 145824952Seric break; 145924952Seric 146024981Seric case 'z': /* work message class factor */ 146124981Seric WkClassFact = atoi(val); 146224981Seric break; 146324981Seric 146424981Seric case 'Z': /* work time factor */ 146524981Seric WkTimeFact = atoi(val); 146624981Seric break; 146724981Seric 14688256Seric default: 14698256Seric break; 14708256Seric } 147116878Seric if (sticky) 147216878Seric setbitn(opt, StickyOpt); 14739188Seric return; 14748256Seric } 147510687Seric /* 147610687Seric ** SETCLASS -- set a word into a class 147710687Seric ** 147810687Seric ** Parameters: 147910687Seric ** class -- the class to put the word in. 148010687Seric ** word -- the word to enter 148110687Seric ** 148210687Seric ** Returns: 148310687Seric ** none. 148410687Seric ** 148510687Seric ** Side Effects: 148610687Seric ** puts the word into the symbol table. 148710687Seric */ 148810687Seric 148910687Seric setclass(class, word) 149010687Seric int class; 149110687Seric char *word; 149210687Seric { 149310687Seric register STAB *s; 149410687Seric 149557943Seric if (tTd(37, 8)) 149664326Seric printf("setclass(%c, %s)\n", class, word); 149710687Seric s = stab(word, ST_CLASS, ST_ENTER); 149810687Seric setbitn(class, s->s_class); 149910687Seric } 150053654Seric /* 150153654Seric ** MAKEMAPENTRY -- create a map entry 150253654Seric ** 150353654Seric ** Parameters: 150453654Seric ** line -- the config file line 150553654Seric ** 150653654Seric ** Returns: 150753654Seric ** TRUE if it successfully entered the map entry. 150853654Seric ** FALSE otherwise (usually syntax error). 150953654Seric ** 151053654Seric ** Side Effects: 151153654Seric ** Enters the map into the dictionary. 151253654Seric */ 151353654Seric 151453654Seric void 151553654Seric makemapentry(line) 151653654Seric char *line; 151753654Seric { 151853654Seric register char *p; 151953654Seric char *mapname; 152053654Seric char *classname; 152164078Seric register STAB *s; 152253654Seric STAB *class; 152353654Seric 152458050Seric for (p = line; isascii(*p) && isspace(*p); p++) 152553654Seric continue; 152658050Seric if (!(isascii(*p) && isalnum(*p))) 152753654Seric { 152853654Seric syserr("readcf: config K line: no map name"); 152953654Seric return; 153053654Seric } 153153654Seric 153253654Seric mapname = p; 153358050Seric while (isascii(*++p) && isalnum(*p)) 153453654Seric continue; 153553654Seric if (*p != '\0') 153653654Seric *p++ = '\0'; 153758050Seric while (isascii(*p) && isspace(*p)) 153853654Seric p++; 153958050Seric if (!(isascii(*p) && isalnum(*p))) 154053654Seric { 154153654Seric syserr("readcf: config K line, map %s: no map class", mapname); 154253654Seric return; 154353654Seric } 154453654Seric classname = p; 154558050Seric while (isascii(*++p) && isalnum(*p)) 154653654Seric continue; 154753654Seric if (*p != '\0') 154853654Seric *p++ = '\0'; 154958050Seric while (isascii(*p) && isspace(*p)) 155053654Seric p++; 155153654Seric 155253654Seric /* look up the class */ 155353654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 155453654Seric if (class == NULL) 155553654Seric { 155653654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 155753654Seric return; 155853654Seric } 155953654Seric 156053654Seric /* enter the map */ 156164078Seric s = stab(mapname, ST_MAP, ST_ENTER); 156264078Seric s->s_map.map_class = &class->s_mapclass; 156364078Seric s->s_map.map_mname = newstr(mapname); 156453654Seric 156564078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 156664078Seric s->s_map.map_mflags |= MF_VALID; 156764078Seric 156864078Seric if (tTd(37, 5)) 156964078Seric { 157064078Seric printf("map %s, class %s, flags %x, file %s,\n", 157164078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 157264078Seric s->s_map.map_mflags, 157364078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 157464078Seric printf("\tapp %s, domain %s, rebuild %s\n", 157564078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 157664078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 157764078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 157864078Seric } 157953654Seric } 158058112Seric /* 158158112Seric ** SETTIMEOUTS -- parse and set timeout values 158258112Seric ** 158358112Seric ** Parameters: 158458112Seric ** val -- a pointer to the values. If NULL, do initial 158558112Seric ** settings. 158658112Seric ** 158758112Seric ** Returns: 158858112Seric ** none. 158958112Seric ** 159058112Seric ** Side Effects: 159158112Seric ** Initializes the TimeOuts structure 159258112Seric */ 159358112Seric 159464255Seric #define SECONDS 159558112Seric #define MINUTES * 60 159658112Seric #define HOUR * 3600 159758112Seric 159858112Seric settimeouts(val) 159958112Seric register char *val; 160058112Seric { 160158112Seric register char *p; 160258671Seric extern time_t convtime(); 160358112Seric 160458112Seric if (val == NULL) 160558112Seric { 160658112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 160758112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 160858112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 160958112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 161058112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 161158112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 161258112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 161358112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 161458112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 161558112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 161658112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 161764255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 161858112Seric return; 161958112Seric } 162058112Seric 162158112Seric for (;; val = p) 162258112Seric { 162358112Seric while (isascii(*val) && isspace(*val)) 162458112Seric val++; 162558112Seric if (*val == '\0') 162658112Seric break; 162758112Seric for (p = val; *p != '\0' && *p != ','; p++) 162858112Seric continue; 162958112Seric if (*p != '\0') 163058112Seric *p++ = '\0'; 163158112Seric 163258112Seric if (isascii(*val) && isdigit(*val)) 163358112Seric { 163458112Seric /* old syntax -- set everything */ 163558796Seric TimeOuts.to_mail = convtime(val, 'm'); 163658112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 163758112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 163858112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 163958112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 164058112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 164158112Seric continue; 164258112Seric } 164358112Seric else 164458112Seric { 164558112Seric register char *q = strchr(val, '='); 164658112Seric time_t to; 164758112Seric 164858112Seric if (q == NULL) 164958112Seric { 165058112Seric /* syntax error */ 165158112Seric continue; 165258112Seric } 165358112Seric *q++ = '\0'; 165458796Seric to = convtime(q, 'm'); 165558112Seric 165658112Seric if (strcasecmp(val, "initial") == 0) 165758112Seric TimeOuts.to_initial = to; 165858112Seric else if (strcasecmp(val, "mail") == 0) 165958112Seric TimeOuts.to_mail = to; 166058112Seric else if (strcasecmp(val, "rcpt") == 0) 166158112Seric TimeOuts.to_rcpt = to; 166258112Seric else if (strcasecmp(val, "datainit") == 0) 166358112Seric TimeOuts.to_datainit = to; 166458112Seric else if (strcasecmp(val, "datablock") == 0) 166558112Seric TimeOuts.to_datablock = to; 166658112Seric else if (strcasecmp(val, "datafinal") == 0) 166758112Seric TimeOuts.to_datafinal = to; 166858112Seric else if (strcasecmp(val, "command") == 0) 166958112Seric TimeOuts.to_nextcommand = to; 167058112Seric else if (strcasecmp(val, "rset") == 0) 167158112Seric TimeOuts.to_rset = to; 167258112Seric else if (strcasecmp(val, "helo") == 0) 167358112Seric TimeOuts.to_helo = to; 167458112Seric else if (strcasecmp(val, "quit") == 0) 167558112Seric TimeOuts.to_quit = to; 167658112Seric else if (strcasecmp(val, "misc") == 0) 167758112Seric TimeOuts.to_miscshort = to; 167864255Seric else if (strcasecmp(val, "ident") == 0) 167964255Seric TimeOuts.to_ident = to; 168058112Seric else 168158112Seric syserr("settimeouts: invalid timeout %s", val); 168258112Seric } 168358112Seric } 168458112Seric } 1685