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*67604Seric static char sccsid[] = "@(#)readcf.c 8.28 (Berkeley) 08/07/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"; 691*67604Seric m->m_uid = m->m_gid = 0; 69210327Seric 69310327Seric /* collect the mailer name */ 69458050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 69510327Seric continue; 69610327Seric if (*p != '\0') 69710327Seric *p++ = '\0'; 69810327Seric m->m_name = newstr(line); 69910327Seric 70010327Seric /* now scan through and assign info from the fields */ 70110327Seric while (*p != '\0') 70210327Seric { 70358333Seric auto char *delimptr; 70458333Seric 70558050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 70610327Seric p++; 70710327Seric 70810327Seric /* p now points to field code */ 70910327Seric fcode = *p; 71010327Seric while (*p != '\0' && *p != '=' && *p != ',') 71110327Seric p++; 71210327Seric if (*p++ != '=') 71310327Seric { 71452637Seric syserr("mailer %s: `=' expected", m->m_name); 71510327Seric return; 71610327Seric } 71758050Seric while (isascii(*p) && isspace(*p)) 71810327Seric p++; 71910327Seric 72010327Seric /* p now points to the field body */ 72158333Seric p = munchstring(p, &delimptr); 72210327Seric 72310327Seric /* install the field into the mailer struct */ 72410327Seric switch (fcode) 72510327Seric { 72610327Seric case 'P': /* pathname */ 72710327Seric m->m_mailer = newstr(p); 72810327Seric break; 72910327Seric 73010327Seric case 'F': /* flags */ 73110687Seric for (; *p != '\0'; p++) 73258050Seric if (!(isascii(*p) && isspace(*p))) 73352637Seric setbitn(*p, m->m_flags); 73410327Seric break; 73510327Seric 73610327Seric case 'S': /* sender rewriting ruleset */ 73710327Seric case 'R': /* recipient rewriting ruleset */ 73858020Seric i = strtol(p, &endp, 10); 73910327Seric if (i < 0 || i >= MAXRWSETS) 74010327Seric { 74110327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 74210327Seric return; 74310327Seric } 74410327Seric if (fcode == 'S') 74558020Seric m->m_sh_rwset = m->m_se_rwset = i; 74610327Seric else 74758020Seric m->m_rh_rwset = m->m_re_rwset = i; 74858020Seric 74958020Seric p = endp; 75059985Seric if (*p++ == '/') 75158020Seric { 75258020Seric i = strtol(p, NULL, 10); 75358020Seric if (i < 0 || i >= MAXRWSETS) 75458020Seric { 75558020Seric syserr("invalid rewrite set, %d max", 75658020Seric MAXRWSETS); 75758020Seric return; 75858020Seric } 75958020Seric if (fcode == 'S') 76058020Seric m->m_sh_rwset = i; 76158020Seric else 76258020Seric m->m_rh_rwset = i; 76358020Seric } 76410327Seric break; 76510327Seric 76610327Seric case 'E': /* end of line string */ 76710327Seric m->m_eol = newstr(p); 76810327Seric break; 76910327Seric 77010327Seric case 'A': /* argument vector */ 77110327Seric m->m_argv = makeargv(p); 77210327Seric break; 77310701Seric 77410701Seric case 'M': /* maximum message size */ 77510701Seric m->m_maxsize = atol(p); 77610701Seric break; 77752106Seric 77852106Seric case 'L': /* maximum line length */ 77952106Seric m->m_linelimit = atoi(p); 78052106Seric break; 78158935Seric 78258935Seric case 'D': /* working directory */ 78358935Seric m->m_execdir = newstr(p); 78458935Seric break; 785*67604Seric 786*67604Seric case 'U': /* user id */ 787*67604Seric if (isascii(*p) && !isdigit(*p)) 788*67604Seric { 789*67604Seric char *q = p; 790*67604Seric struct passwd *pw; 791*67604Seric 792*67604Seric while (isascii(*p) && isalnum(*p)) 793*67604Seric p++; 794*67604Seric while (isascii(*p) && isspace(*p)) 795*67604Seric *p++ = '\0'; 796*67604Seric if (*p != '\0') 797*67604Seric *p++ = '\0'; 798*67604Seric pw = getpwnam(q); 799*67604Seric if (pw == NULL) 800*67604Seric syserr("readcf: mailer U= flag: unknown user %s", q); 801*67604Seric else 802*67604Seric { 803*67604Seric m->m_uid = pw->pw_uid; 804*67604Seric m->m_gid = pw->pw_gid; 805*67604Seric } 806*67604Seric } 807*67604Seric else 808*67604Seric { 809*67604Seric auto char *q; 810*67604Seric 811*67604Seric m->m_uid = strtol(p, &q, 0); 812*67604Seric p = q; 813*67604Seric } 814*67604Seric while (isascii(*p) && isspace(*p)) 815*67604Seric p++; 816*67604Seric if (*p == '\0') 817*67604Seric break; 818*67604Seric if (isascii(*p) && !isdigit(*p)) 819*67604Seric { 820*67604Seric char *q = p; 821*67604Seric struct group *gr; 822*67604Seric 823*67604Seric while (isascii(*p) && isalnum(*p)) 824*67604Seric p++; 825*67604Seric *p++ = '\0'; 826*67604Seric gr = getgrnam(q); 827*67604Seric if (gr == NULL) 828*67604Seric syserr("readcf: mailer U= flag: unknown group %s", q); 829*67604Seric else 830*67604Seric m->m_gid = gr->gr_gid; 831*67604Seric } 832*67604Seric else 833*67604Seric { 834*67604Seric m->m_gid = strtol(p, NULL, 0); 835*67604Seric } 836*67604Seric setbitn(M_SPECIFIC_UID, m->m_flags); 837*67604Seric break; 83810327Seric } 83910327Seric 84058333Seric p = delimptr; 84110327Seric } 84210327Seric 84352106Seric /* do some heuristic cleanup for back compatibility */ 84452106Seric if (bitnset(M_LIMITS, m->m_flags)) 84552106Seric { 84652106Seric if (m->m_linelimit == 0) 84752106Seric m->m_linelimit = SMTPLINELIM; 84855418Seric if (ConfigLevel < 2) 84952106Seric setbitn(M_7BITS, m->m_flags); 85052106Seric } 85152106Seric 85258321Seric /* do some rationality checking */ 85358321Seric if (m->m_argv == NULL) 85458321Seric { 85558321Seric syserr("M%s: A= argument required", m->m_name); 85658321Seric return; 85758321Seric } 85858321Seric if (m->m_mailer == NULL) 85958321Seric { 86058321Seric syserr("M%s: P= argument required", m->m_name); 86158321Seric return; 86258321Seric } 86358321Seric 8644096Seric if (NextMailer >= MAXMAILERS) 8654096Seric { 8669381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 8674096Seric return; 8684096Seric } 86957402Seric 87010327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 87157402Seric if (s->s_mailer != NULL) 87257402Seric { 87357402Seric i = s->s_mailer->m_mno; 87457402Seric free(s->s_mailer); 87557402Seric } 87657402Seric else 87757402Seric { 87857402Seric i = NextMailer++; 87957402Seric } 88057402Seric Mailer[i] = s->s_mailer = m; 88157454Seric m->m_mno = i; 88210327Seric } 88310327Seric /* 88410327Seric ** MUNCHSTRING -- translate a string into internal form. 88510327Seric ** 88610327Seric ** Parameters: 88710327Seric ** p -- the string to munch. 88858333Seric ** delimptr -- if non-NULL, set to the pointer of the 88958333Seric ** field delimiter character. 89010327Seric ** 89110327Seric ** Returns: 89210327Seric ** the munched string. 89310327Seric */ 8944096Seric 89510327Seric char * 89658333Seric munchstring(p, delimptr) 89710327Seric register char *p; 89858333Seric char **delimptr; 89910327Seric { 90010327Seric register char *q; 90110327Seric bool backslash = FALSE; 90210327Seric bool quotemode = FALSE; 90310327Seric static char buf[MAXLINE]; 9044096Seric 90510327Seric for (q = buf; *p != '\0'; p++) 9064096Seric { 90710327Seric if (backslash) 90810327Seric { 90910327Seric /* everything is roughly literal */ 91010357Seric backslash = FALSE; 91110327Seric switch (*p) 91210327Seric { 91310327Seric case 'r': /* carriage return */ 91410327Seric *q++ = '\r'; 91510327Seric continue; 91610327Seric 91710327Seric case 'n': /* newline */ 91810327Seric *q++ = '\n'; 91910327Seric continue; 92010327Seric 92110327Seric case 'f': /* form feed */ 92210327Seric *q++ = '\f'; 92310327Seric continue; 92410327Seric 92510327Seric case 'b': /* backspace */ 92610327Seric *q++ = '\b'; 92710327Seric continue; 92810327Seric } 92910327Seric *q++ = *p; 93010327Seric } 93110327Seric else 93210327Seric { 93310327Seric if (*p == '\\') 93410327Seric backslash = TRUE; 93510327Seric else if (*p == '"') 93610327Seric quotemode = !quotemode; 93710327Seric else if (quotemode || *p != ',') 93810327Seric *q++ = *p; 93910327Seric else 94010327Seric break; 94110327Seric } 9424096Seric } 9434096Seric 94458333Seric if (delimptr != NULL) 94558333Seric *delimptr = p; 94610327Seric *q++ = '\0'; 94710327Seric return (buf); 94810327Seric } 94910327Seric /* 95010327Seric ** MAKEARGV -- break up a string into words 95110327Seric ** 95210327Seric ** Parameters: 95310327Seric ** p -- the string to break up. 95410327Seric ** 95510327Seric ** Returns: 95610327Seric ** a char **argv (dynamically allocated) 95710327Seric ** 95810327Seric ** Side Effects: 95910327Seric ** munges p. 96010327Seric */ 9614096Seric 96210327Seric char ** 96310327Seric makeargv(p) 96410327Seric register char *p; 96510327Seric { 96610327Seric char *q; 96710327Seric int i; 96810327Seric char **avp; 96910327Seric char *argv[MAXPV + 1]; 97010327Seric 97110327Seric /* take apart the words */ 97210327Seric i = 0; 97310327Seric while (*p != '\0' && i < MAXPV) 9744096Seric { 97510327Seric q = p; 97658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 97710327Seric p++; 97858050Seric while (isascii(*p) && isspace(*p)) 97910327Seric *p++ = '\0'; 98010327Seric argv[i++] = newstr(q); 9814096Seric } 98210327Seric argv[i++] = NULL; 9834096Seric 98410327Seric /* now make a copy of the argv */ 98510327Seric avp = (char **) xalloc(sizeof *avp * i); 98616893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 98710327Seric 98810327Seric return (avp); 9893308Seric } 9903308Seric /* 9913308Seric ** PRINTRULES -- print rewrite rules (for debugging) 9923308Seric ** 9933308Seric ** Parameters: 9943308Seric ** none. 9953308Seric ** 9963308Seric ** Returns: 9973308Seric ** none. 9983308Seric ** 9993308Seric ** Side Effects: 10003308Seric ** prints rewrite rules. 10013308Seric */ 10023308Seric 10033308Seric printrules() 10043308Seric { 10053308Seric register struct rewrite *rwp; 10064072Seric register int ruleset; 10073308Seric 10084072Seric for (ruleset = 0; ruleset < 10; ruleset++) 10093308Seric { 10104072Seric if (RewriteRules[ruleset] == NULL) 10114072Seric continue; 10128067Seric printf("\n----Rule Set %d:", ruleset); 10133308Seric 10144072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 10153308Seric { 10168067Seric printf("\nLHS:"); 10178067Seric printav(rwp->r_lhs); 10188067Seric printf("RHS:"); 10198067Seric printav(rwp->r_rhs); 10203308Seric } 10213308Seric } 10223308Seric } 10234319Seric 10244096Seric /* 10258256Seric ** SETOPTION -- set global processing option 10268256Seric ** 10278256Seric ** Parameters: 10288256Seric ** opt -- option name. 10298256Seric ** val -- option value (as a text string). 103021755Seric ** safe -- set if this came from a configuration file. 103121755Seric ** Some options (if set from the command line) will 103221755Seric ** reset the user id to avoid security problems. 10338269Seric ** sticky -- if set, don't let other setoptions override 10348269Seric ** this value. 103558734Seric ** e -- the main envelope. 10368256Seric ** 10378256Seric ** Returns: 10388256Seric ** none. 10398256Seric ** 10408256Seric ** Side Effects: 10418256Seric ** Sets options as implied by the arguments. 10428256Seric */ 10438256Seric 104410687Seric static BITMAP StickyOpt; /* set if option is stuck */ 10458269Seric 104657207Seric 104766334Seric #if NAMED_BIND 104857207Seric 104957207Seric struct resolverflags 105057207Seric { 105157207Seric char *rf_name; /* name of the flag */ 105257207Seric long rf_bits; /* bits to set/clear */ 105357207Seric } ResolverFlags[] = 105457207Seric { 105557207Seric "debug", RES_DEBUG, 105657207Seric "aaonly", RES_AAONLY, 105757207Seric "usevc", RES_USEVC, 105857207Seric "primary", RES_PRIMARY, 105957207Seric "igntc", RES_IGNTC, 106057207Seric "recurse", RES_RECURSE, 106157207Seric "defnames", RES_DEFNAMES, 106257207Seric "stayopen", RES_STAYOPEN, 106357207Seric "dnsrch", RES_DNSRCH, 106465583Seric "true", 0, /* to avoid error on old syntax */ 106557207Seric NULL, 0 106657207Seric }; 106757207Seric 106857207Seric #endif 106957207Seric 107058734Seric setoption(opt, val, safe, sticky, e) 10718256Seric char opt; 10728256Seric char *val; 107321755Seric bool safe; 10748269Seric bool sticky; 107558734Seric register ENVELOPE *e; 10768256Seric { 107757207Seric register char *p; 10788265Seric extern bool atobool(); 107912633Seric extern time_t convtime(); 108014879Seric extern int QueueLA; 108114879Seric extern int RefuseLA; 108264718Seric extern bool Warn_Q_option; 108317474Seric extern bool trusteduser(); 10848256Seric 10858256Seric if (tTd(37, 1)) 10869341Seric printf("setoption %c=%s", opt, val); 10878256Seric 10888256Seric /* 10898269Seric ** See if this option is preset for us. 10908256Seric */ 10918256Seric 109259731Seric if (!sticky && bitnset(opt, StickyOpt)) 10938269Seric { 10949341Seric if (tTd(37, 1)) 10959341Seric printf(" (ignored)\n"); 10968269Seric return; 10978269Seric } 10988269Seric 109921755Seric /* 110021755Seric ** Check to see if this option can be specified by this user. 110121755Seric */ 110221755Seric 110363787Seric if (!safe && RealUid == 0) 110421755Seric safe = TRUE; 110566383Scorrigan if (!safe && strchr("bCdeijLmoprsvw7", opt) == NULL) 110621755Seric { 110739111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 110821755Seric { 110936582Sbostic if (tTd(37, 1)) 111036582Sbostic printf(" (unsafe)"); 111163787Seric if (RealUid != geteuid()) 111236582Sbostic { 111351210Seric if (tTd(37, 1)) 111451210Seric printf("(Resetting uid)"); 111563787Seric (void) setgid(RealGid); 111663787Seric (void) setuid(RealUid); 111736582Sbostic } 111821755Seric } 111921755Seric } 112051210Seric if (tTd(37, 1)) 112117985Seric printf("\n"); 11228269Seric 11238256Seric switch (opt) 11248256Seric { 112559709Seric case '7': /* force seven-bit input */ 112667546Seric SevenBitInput = atobool(val); 112752106Seric break; 112852106Seric 112967546Seric case '8': /* handling of 8-bit input */ 113067546Seric switch (*val) 113167546Seric { 113267547Seric case 'r': /* reject 8-bit, don't convert MIME */ 113367546Seric MimeMode = 0; 113467546Seric break; 113567546Seric 113667547Seric case 'm': /* convert 8-bit, convert MIME */ 113767546Seric MimeMode = MM_CVTMIME|MM_MIME8BIT; 113867546Seric break; 113967546Seric 114067547Seric case 'j': /* "just send 8" */ 114167546Seric MimeMode = MM_PASS8BIT; 114267546Seric break; 114367546Seric 114467546Seric case 'p': /* pass 8 bit, convert MIME */ 114567546Seric MimeMode = MM_PASS8BIT|MM_CVTMIME; 114667546Seric break; 114767546Seric 114867546Seric case 's': /* strict adherence */ 114967546Seric MimeMode = MM_CVTMIME; 115067546Seric break; 115167546Seric 115267547Seric case 'a': /* encode 8 bit if available */ 115367546Seric MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME; 115467546Seric break; 115567546Seric 115667547Seric case 'c': /* convert 8 bit to MIME, never 7 bit */ 115767547Seric MimeMode = MM_MIME8BIT; 115867547Seric break; 115967547Seric 116067546Seric default: 116167546Seric syserr("Unknown 8-bit mode %c", *val); 116267546Seric exit(EX_USAGE); 116367546Seric } 116467546Seric break; 116567546Seric 11668256Seric case 'A': /* set default alias file */ 11679381Seric if (val[0] == '\0') 116859672Seric setalias("aliases"); 11699381Seric else 117059672Seric setalias(val); 11718256Seric break; 11728256Seric 117317474Seric case 'a': /* look N minutes for "@:@" in alias file */ 117417474Seric if (val[0] == '\0') 117564796Seric SafeAlias = 5 * 60; /* five minutes */ 117617474Seric else 117764796Seric SafeAlias = convtime(val, 'm'); 117817474Seric break; 117917474Seric 118016843Seric case 'B': /* substitution for blank character */ 118116843Seric SpaceSub = val[0]; 118216843Seric if (SpaceSub == '\0') 118316843Seric SpaceSub = ' '; 118416843Seric break; 118516843Seric 118659283Seric case 'b': /* min blocks free on queue fs/max msg size */ 118759283Seric p = strchr(val, '/'); 118859283Seric if (p != NULL) 118959283Seric { 119059283Seric *p++ = '\0'; 119159283Seric MaxMessageSize = atol(p); 119259283Seric } 119358082Seric MinBlocksFree = atol(val); 119458082Seric break; 119558082Seric 11969284Seric case 'c': /* don't connect to "expensive" mailers */ 11979381Seric NoConnect = atobool(val); 11989284Seric break; 11999284Seric 120051305Seric case 'C': /* checkpoint every N addresses */ 120151305Seric CheckpointInterval = atoi(val); 120224944Seric break; 120324944Seric 12049284Seric case 'd': /* delivery mode */ 12059284Seric switch (*val) 12068269Seric { 12079284Seric case '\0': 120858734Seric e->e_sendmode = SM_DELIVER; 12098269Seric break; 12108269Seric 121110755Seric case SM_QUEUE: /* queue only */ 121210755Seric #ifndef QUEUE 121310755Seric syserr("need QUEUE to set -odqueue"); 121456795Seric #endif /* QUEUE */ 121510755Seric /* fall through..... */ 121610755Seric 12179284Seric case SM_DELIVER: /* do everything */ 12189284Seric case SM_FORK: /* fork after verification */ 121958734Seric e->e_sendmode = *val; 12208269Seric break; 12218269Seric 12228269Seric default: 12239284Seric syserr("Unknown delivery mode %c", *val); 12248269Seric exit(EX_USAGE); 12258269Seric } 12268269Seric break; 12278269Seric 12289146Seric case 'D': /* rebuild alias database as needed */ 12299381Seric AutoRebuild = atobool(val); 12309146Seric break; 12319146Seric 123255372Seric case 'E': /* error message header/header file */ 123355379Seric if (*val != '\0') 123455379Seric ErrMsgFile = newstr(val); 123555372Seric break; 123655372Seric 12378269Seric case 'e': /* set error processing mode */ 12388269Seric switch (*val) 12398269Seric { 12409381Seric case EM_QUIET: /* be silent about it */ 12419381Seric case EM_MAIL: /* mail back */ 12429381Seric case EM_BERKNET: /* do berknet error processing */ 12439381Seric case EM_WRITE: /* write back (or mail) */ 12449381Seric case EM_PRINT: /* print errors normally (default) */ 124558734Seric e->e_errormode = *val; 12468269Seric break; 12478269Seric } 12488269Seric break; 12498269Seric 12509049Seric case 'F': /* file mode */ 125117975Seric FileMode = atooct(val) & 0777; 12529049Seric break; 12539049Seric 12548269Seric case 'f': /* save Unix-style From lines on front */ 12559381Seric SaveFrom = atobool(val); 12568269Seric break; 12578269Seric 125853735Seric case 'G': /* match recipients against GECOS field */ 125953735Seric MatchGecos = atobool(val); 126053735Seric break; 126153735Seric 12628256Seric case 'g': /* default gid */ 126364133Seric if (isascii(*val) && isdigit(*val)) 126464133Seric DefGid = atoi(val); 126564133Seric else 126664133Seric { 126764133Seric register struct group *gr; 126864133Seric 126964133Seric DefGid = -1; 127064133Seric gr = getgrnam(val); 127164133Seric if (gr == NULL) 127264133Seric syserr("readcf: option g: unknown group %s", val); 127364133Seric else 127464133Seric DefGid = gr->gr_gid; 127564133Seric } 12768256Seric break; 12778256Seric 12788256Seric case 'H': /* help file */ 12799381Seric if (val[0] == '\0') 12808269Seric HelpFile = "sendmail.hf"; 12819381Seric else 12829381Seric HelpFile = newstr(val); 12838256Seric break; 12848256Seric 128551305Seric case 'h': /* maximum hop count */ 128651305Seric MaxHopCount = atoi(val); 128751305Seric break; 128851305Seric 128935651Seric case 'I': /* use internet domain name server */ 129066334Seric #if NAMED_BIND 129157207Seric UseNameServer = TRUE; 129257207Seric for (p = val; *p != 0; ) 129357207Seric { 129457207Seric bool clearmode; 129557207Seric char *q; 129657207Seric struct resolverflags *rfp; 129757207Seric 129857207Seric while (*p == ' ') 129957207Seric p++; 130057207Seric if (*p == '\0') 130157207Seric break; 130257207Seric clearmode = FALSE; 130357207Seric if (*p == '-') 130457207Seric clearmode = TRUE; 130557207Seric else if (*p != '+') 130657207Seric p--; 130757207Seric p++; 130857207Seric q = p; 130958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 131057207Seric p++; 131157207Seric if (*p != '\0') 131257207Seric *p++ = '\0'; 131357207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 131457207Seric { 131557207Seric if (strcasecmp(q, rfp->rf_name) == 0) 131657207Seric break; 131757207Seric } 131864923Seric if (rfp->rf_name == NULL) 131964923Seric syserr("readcf: I option value %s unrecognized", q); 132064923Seric else if (clearmode) 132157207Seric _res.options &= ~rfp->rf_bits; 132257207Seric else 132357207Seric _res.options |= rfp->rf_bits; 132457207Seric } 132557207Seric if (tTd(8, 2)) 132657207Seric printf("_res.options = %x\n", _res.options); 132757207Seric #else 132857207Seric usrerr("name server (I option) specified but BIND not compiled in"); 132957207Seric #endif 133035651Seric break; 133135651Seric 13328269Seric case 'i': /* ignore dot lines in message */ 13339381Seric IgnrDot = atobool(val); 13348269Seric break; 13358269Seric 133659730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 133759730Seric SendMIMEErrors = atobool(val); 133859730Seric break; 133959730Seric 134057136Seric case 'J': /* .forward search path */ 134157136Seric ForwardPath = newstr(val); 134257136Seric break; 134357136Seric 134454967Seric case 'k': /* connection cache size */ 134554967Seric MaxMciCache = atoi(val); 134656215Seric if (MaxMciCache < 0) 134756215Seric MaxMciCache = 0; 134854967Seric break; 134954967Seric 135054967Seric case 'K': /* connection cache timeout */ 135158796Seric MciCacheTimeout = convtime(val, 'm'); 135254967Seric break; 135354967Seric 135461104Seric case 'l': /* use Errors-To: header */ 135561104Seric UseErrorsTo = atobool(val); 135661104Seric break; 135761104Seric 13588256Seric case 'L': /* log level */ 135964140Seric if (safe || LogLevel < atoi(val)) 136064140Seric LogLevel = atoi(val); 13618256Seric break; 13628256Seric 13638269Seric case 'M': /* define macro */ 13649381Seric define(val[0], newstr(&val[1]), CurEnv); 136516878Seric sticky = FALSE; 13668269Seric break; 13678269Seric 13688269Seric case 'm': /* send to me too */ 13699381Seric MeToo = atobool(val); 13708269Seric break; 13718269Seric 137225820Seric case 'n': /* validate RHS in newaliases */ 137325820Seric CheckAliases = atobool(val); 137425820Seric break; 137525820Seric 137661104Seric /* 'N' available -- was "net name" */ 137761104Seric 137858851Seric case 'O': /* daemon options */ 137958851Seric setdaemonoptions(val); 138058851Seric break; 138158851Seric 13828269Seric case 'o': /* assume old style headers */ 13839381Seric if (atobool(val)) 13849341Seric CurEnv->e_flags |= EF_OLDSTYLE; 13859341Seric else 13869341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 13878269Seric break; 13888269Seric 138958082Seric case 'p': /* select privacy level */ 139058082Seric p = val; 139158082Seric for (;;) 139258082Seric { 139358082Seric register struct prival *pv; 139458082Seric extern struct prival PrivacyValues[]; 139558082Seric 139658082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 139758082Seric p++; 139858082Seric if (*p == '\0') 139958082Seric break; 140058082Seric val = p; 140158082Seric while (isascii(*p) && isalnum(*p)) 140258082Seric p++; 140358082Seric if (*p != '\0') 140458082Seric *p++ = '\0'; 140558082Seric 140658082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 140758082Seric { 140858082Seric if (strcasecmp(val, pv->pv_name) == 0) 140958082Seric break; 141058082Seric } 141158886Seric if (pv->pv_name == NULL) 141258886Seric syserr("readcf: Op line: %s unrecognized", val); 141358082Seric PrivacyFlags |= pv->pv_flag; 141458082Seric } 141558082Seric break; 141658082Seric 141724944Seric case 'P': /* postmaster copy address for returned mail */ 141824944Seric PostMasterCopy = newstr(val); 141924944Seric break; 142024944Seric 142124944Seric case 'q': /* slope of queue only function */ 142224944Seric QueueFactor = atoi(val); 142324944Seric break; 142424944Seric 14258256Seric case 'Q': /* queue directory */ 14269381Seric if (val[0] == '\0') 14278269Seric QueueDir = "mqueue"; 14289381Seric else 14299381Seric QueueDir = newstr(val); 143058789Seric if (RealUid != 0 && !safe) 143164718Seric Warn_Q_option = TRUE; 14328256Seric break; 14338256Seric 143458148Seric case 'R': /* don't prune routes */ 143558148Seric DontPruneRoutes = atobool(val); 143658148Seric break; 143758148Seric 14388256Seric case 'r': /* read timeout */ 143958112Seric settimeouts(val); 14408256Seric break; 14418256Seric 14428256Seric case 'S': /* status file */ 14439381Seric if (val[0] == '\0') 14448269Seric StatFile = "sendmail.st"; 14459381Seric else 14469381Seric StatFile = newstr(val); 14478256Seric break; 14488256Seric 14498265Seric case 's': /* be super safe, even if expensive */ 14509381Seric SuperSafe = atobool(val); 14518256Seric break; 14528256Seric 14538256Seric case 'T': /* queue timeout */ 145458737Seric p = strchr(val, '/'); 145558737Seric if (p != NULL) 145658737Seric { 145758737Seric *p++ = '\0'; 145858796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 145958737Seric } 146058796Seric TimeOuts.to_q_return = convtime(val, 'h'); 146154967Seric break; 14628256Seric 14638265Seric case 't': /* time zone name */ 146452106Seric TimeZoneSpec = newstr(val); 14658265Seric break; 14668265Seric 146750556Seric case 'U': /* location of user database */ 146851360Seric UdbSpec = newstr(val); 146950556Seric break; 147050556Seric 14718256Seric case 'u': /* set default uid */ 147264133Seric if (isascii(*val) && isdigit(*val)) 147364133Seric DefUid = atoi(val); 147464133Seric else 147564133Seric { 147664133Seric register struct passwd *pw; 147764133Seric 147864133Seric DefUid = -1; 147964133Seric pw = getpwnam(val); 148064133Seric if (pw == NULL) 148164133Seric syserr("readcf: option u: unknown user %s", val); 148264133Seric else 148364133Seric DefUid = pw->pw_uid; 148464133Seric } 148540973Sbostic setdefuser(); 14868256Seric break; 14878256Seric 148858851Seric case 'V': /* fallback MX host */ 148958851Seric FallBackMX = newstr(val); 149058851Seric break; 149158851Seric 14928269Seric case 'v': /* run in verbose mode */ 14939381Seric Verbose = atobool(val); 14948256Seric break; 14958256Seric 149663837Seric case 'w': /* if we are best MX, try host directly */ 149763837Seric TryNullMXList = atobool(val); 149863837Seric break; 149961104Seric 150061104Seric /* 'W' available -- was wizard password */ 150161104Seric 150214879Seric case 'x': /* load avg at which to auto-queue msgs */ 150314879Seric QueueLA = atoi(val); 150414879Seric break; 150514879Seric 150614879Seric case 'X': /* load avg at which to auto-reject connections */ 150714879Seric RefuseLA = atoi(val); 150814879Seric break; 150914879Seric 151024981Seric case 'y': /* work recipient factor */ 151124981Seric WkRecipFact = atoi(val); 151224981Seric break; 151324981Seric 151424981Seric case 'Y': /* fork jobs during queue runs */ 151524952Seric ForkQueueRuns = atobool(val); 151624952Seric break; 151724952Seric 151824981Seric case 'z': /* work message class factor */ 151924981Seric WkClassFact = atoi(val); 152024981Seric break; 152124981Seric 152224981Seric case 'Z': /* work time factor */ 152324981Seric WkTimeFact = atoi(val); 152424981Seric break; 152524981Seric 15268256Seric default: 15278256Seric break; 15288256Seric } 152916878Seric if (sticky) 153016878Seric setbitn(opt, StickyOpt); 15319188Seric return; 15328256Seric } 153310687Seric /* 153410687Seric ** SETCLASS -- set a word into a class 153510687Seric ** 153610687Seric ** Parameters: 153710687Seric ** class -- the class to put the word in. 153810687Seric ** word -- the word to enter 153910687Seric ** 154010687Seric ** Returns: 154110687Seric ** none. 154210687Seric ** 154310687Seric ** Side Effects: 154410687Seric ** puts the word into the symbol table. 154510687Seric */ 154610687Seric 154710687Seric setclass(class, word) 154810687Seric int class; 154910687Seric char *word; 155010687Seric { 155110687Seric register STAB *s; 155210687Seric 155357943Seric if (tTd(37, 8)) 155464326Seric printf("setclass(%c, %s)\n", class, word); 155510687Seric s = stab(word, ST_CLASS, ST_ENTER); 155610687Seric setbitn(class, s->s_class); 155710687Seric } 155853654Seric /* 155953654Seric ** MAKEMAPENTRY -- create a map entry 156053654Seric ** 156153654Seric ** Parameters: 156253654Seric ** line -- the config file line 156353654Seric ** 156453654Seric ** Returns: 156553654Seric ** TRUE if it successfully entered the map entry. 156653654Seric ** FALSE otherwise (usually syntax error). 156753654Seric ** 156853654Seric ** Side Effects: 156953654Seric ** Enters the map into the dictionary. 157053654Seric */ 157153654Seric 157253654Seric void 157353654Seric makemapentry(line) 157453654Seric char *line; 157553654Seric { 157653654Seric register char *p; 157753654Seric char *mapname; 157853654Seric char *classname; 157964078Seric register STAB *s; 158053654Seric STAB *class; 158153654Seric 158258050Seric for (p = line; isascii(*p) && isspace(*p); p++) 158353654Seric continue; 158458050Seric if (!(isascii(*p) && isalnum(*p))) 158553654Seric { 158653654Seric syserr("readcf: config K line: no map name"); 158753654Seric return; 158853654Seric } 158953654Seric 159053654Seric mapname = p; 159158050Seric while (isascii(*++p) && isalnum(*p)) 159253654Seric continue; 159353654Seric if (*p != '\0') 159453654Seric *p++ = '\0'; 159558050Seric while (isascii(*p) && isspace(*p)) 159653654Seric p++; 159758050Seric if (!(isascii(*p) && isalnum(*p))) 159853654Seric { 159953654Seric syserr("readcf: config K line, map %s: no map class", mapname); 160053654Seric return; 160153654Seric } 160253654Seric classname = p; 160358050Seric while (isascii(*++p) && isalnum(*p)) 160453654Seric continue; 160553654Seric if (*p != '\0') 160653654Seric *p++ = '\0'; 160758050Seric while (isascii(*p) && isspace(*p)) 160853654Seric p++; 160953654Seric 161053654Seric /* look up the class */ 161153654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 161253654Seric if (class == NULL) 161353654Seric { 161453654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 161553654Seric return; 161653654Seric } 161753654Seric 161853654Seric /* enter the map */ 161964078Seric s = stab(mapname, ST_MAP, ST_ENTER); 162064078Seric s->s_map.map_class = &class->s_mapclass; 162164078Seric s->s_map.map_mname = newstr(mapname); 162253654Seric 162364078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 162464078Seric s->s_map.map_mflags |= MF_VALID; 162564078Seric 162664078Seric if (tTd(37, 5)) 162764078Seric { 162864078Seric printf("map %s, class %s, flags %x, file %s,\n", 162964078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 163064078Seric s->s_map.map_mflags, 163164078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 163264078Seric printf("\tapp %s, domain %s, rebuild %s\n", 163364078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 163464078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 163564078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 163664078Seric } 163753654Seric } 163858112Seric /* 163958112Seric ** SETTIMEOUTS -- parse and set timeout values 164058112Seric ** 164158112Seric ** Parameters: 164258112Seric ** val -- a pointer to the values. If NULL, do initial 164358112Seric ** settings. 164458112Seric ** 164558112Seric ** Returns: 164658112Seric ** none. 164758112Seric ** 164858112Seric ** Side Effects: 164958112Seric ** Initializes the TimeOuts structure 165058112Seric */ 165158112Seric 165264255Seric #define SECONDS 165358112Seric #define MINUTES * 60 165458112Seric #define HOUR * 3600 165558112Seric 165658112Seric settimeouts(val) 165758112Seric register char *val; 165858112Seric { 165958112Seric register char *p; 166058671Seric extern time_t convtime(); 166158112Seric 166258112Seric if (val == NULL) 166358112Seric { 166458112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 166558112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 166658112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 166758112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 166858112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 166958112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 167058112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 167158112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 167258112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 167358112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 167458112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 167564255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 167658112Seric return; 167758112Seric } 167858112Seric 167958112Seric for (;; val = p) 168058112Seric { 168158112Seric while (isascii(*val) && isspace(*val)) 168258112Seric val++; 168358112Seric if (*val == '\0') 168458112Seric break; 168558112Seric for (p = val; *p != '\0' && *p != ','; p++) 168658112Seric continue; 168758112Seric if (*p != '\0') 168858112Seric *p++ = '\0'; 168958112Seric 169058112Seric if (isascii(*val) && isdigit(*val)) 169158112Seric { 169258112Seric /* old syntax -- set everything */ 169358796Seric TimeOuts.to_mail = convtime(val, 'm'); 169458112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 169558112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 169658112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 169758112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 169858112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 169958112Seric continue; 170058112Seric } 170158112Seric else 170258112Seric { 170358112Seric register char *q = strchr(val, '='); 170458112Seric time_t to; 170558112Seric 170658112Seric if (q == NULL) 170758112Seric { 170858112Seric /* syntax error */ 170958112Seric continue; 171058112Seric } 171158112Seric *q++ = '\0'; 171258796Seric to = convtime(q, 'm'); 171358112Seric 171458112Seric if (strcasecmp(val, "initial") == 0) 171558112Seric TimeOuts.to_initial = to; 171658112Seric else if (strcasecmp(val, "mail") == 0) 171758112Seric TimeOuts.to_mail = to; 171858112Seric else if (strcasecmp(val, "rcpt") == 0) 171958112Seric TimeOuts.to_rcpt = to; 172058112Seric else if (strcasecmp(val, "datainit") == 0) 172158112Seric TimeOuts.to_datainit = to; 172258112Seric else if (strcasecmp(val, "datablock") == 0) 172358112Seric TimeOuts.to_datablock = to; 172458112Seric else if (strcasecmp(val, "datafinal") == 0) 172558112Seric TimeOuts.to_datafinal = to; 172658112Seric else if (strcasecmp(val, "command") == 0) 172758112Seric TimeOuts.to_nextcommand = to; 172858112Seric else if (strcasecmp(val, "rset") == 0) 172958112Seric TimeOuts.to_rset = to; 173058112Seric else if (strcasecmp(val, "helo") == 0) 173158112Seric TimeOuts.to_helo = to; 173258112Seric else if (strcasecmp(val, "quit") == 0) 173358112Seric TimeOuts.to_quit = to; 173458112Seric else if (strcasecmp(val, "misc") == 0) 173558112Seric TimeOuts.to_miscshort = to; 173664255Seric else if (strcasecmp(val, "ident") == 0) 173764255Seric TimeOuts.to_ident = to; 173858112Seric else 173958112Seric syserr("settimeouts: invalid timeout %s", val); 174058112Seric } 174158112Seric } 174258112Seric } 1743