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*64133Seric static char sccsid[] = "@(#)readcf.c 8.7 (Berkeley) 08/07/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 14*64133Seric # include <pwd.h> 15*64133Seric # include <grp.h> 1657207Seric #ifdef NAMED_BIND 1757207Seric # include <arpa/nameser.h> 1857207Seric # include <resolv.h> 1957207Seric #endif 203308Seric 213308Seric /* 223308Seric ** READCF -- read control file. 233308Seric ** 243308Seric ** This routine reads the control file and builds the internal 253308Seric ** form. 263308Seric ** 274432Seric ** The file is formatted as a sequence of lines, each taken 284432Seric ** atomically. The first character of each line describes how 294432Seric ** the line is to be interpreted. The lines are: 304432Seric ** Dxval Define macro x to have value val. 314432Seric ** Cxword Put word into class x. 324432Seric ** Fxfile [fmt] Read file for lines to put into 334432Seric ** class x. Use scanf string 'fmt' 344432Seric ** or "%s" if not present. Fmt should 354432Seric ** only produce one string-valued result. 364432Seric ** Hname: value Define header with field-name 'name' 374432Seric ** and value as specified; this will be 384432Seric ** macro expanded immediately before 394432Seric ** use. 404432Seric ** Sn Use rewriting set n. 414432Seric ** Rlhs rhs Rewrite addresses that match lhs to 424432Seric ** be rhs. 4324944Seric ** Mn arg=val... Define mailer. n is the internal name. 4424944Seric ** Args specify mailer parameters. 458252Seric ** Oxvalue Set option x to value. 468252Seric ** Pname=value Set precedence name to value. 4752645Seric ** Vversioncode Version level of configuration syntax. 4853654Seric ** Kmapname mapclass arguments.... 4953654Seric ** Define keyed lookup of a given class. 5053654Seric ** Arguments are class dependent. 514432Seric ** 523308Seric ** Parameters: 533308Seric ** cfname -- control file name. 5454973Seric ** safe -- TRUE if this is the system config file; 5554973Seric ** FALSE otherwise. 5655012Seric ** e -- the main envelope. 573308Seric ** 583308Seric ** Returns: 593308Seric ** none. 603308Seric ** 613308Seric ** Side Effects: 623308Seric ** Builds several internal tables. 633308Seric */ 643308Seric 6555012Seric readcf(cfname, safe, e) 663308Seric char *cfname; 6754973Seric bool safe; 6855012Seric register ENVELOPE *e; 693308Seric { 703308Seric FILE *cf; 718547Seric int ruleset = 0; 728547Seric char *q; 739350Seric struct rewrite *rwp = NULL; 7457135Seric char *bp; 7557589Seric int nfuzzy; 76*64133Seric char *file; 77*64133Seric bool optional; 783308Seric char buf[MAXLINE]; 793308Seric register char *p; 803308Seric extern char **copyplist(); 8152647Seric struct stat statb; 825909Seric char exbuf[MAXLINE]; 8316915Seric char pvpbuf[PSBUFSIZE]; 8410709Seric extern char *munchstring(); 8553654Seric extern void makemapentry(); 863308Seric 8752647Seric FileName = cfname; 8852647Seric LineNumber = 0; 8952647Seric 903308Seric cf = fopen(cfname, "r"); 913308Seric if (cf == NULL) 923308Seric { 9352647Seric syserr("cannot open"); 943308Seric exit(EX_OSFILE); 953308Seric } 963308Seric 9752647Seric if (fstat(fileno(cf), &statb) < 0) 9852647Seric { 9952647Seric syserr("cannot fstat"); 10052647Seric exit(EX_OSFILE); 10152647Seric } 10252647Seric 10352647Seric if (!S_ISREG(statb.st_mode)) 10452647Seric { 10552647Seric syserr("not a plain file"); 10652647Seric exit(EX_OSFILE); 10752647Seric } 10852647Seric 10952647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 11052647Seric { 11153037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 11253037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 11353037Seric FileName); 11453037Seric #ifdef LOG 11553037Seric if (LogLevel > 0) 11653037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 11753037Seric FileName); 11853037Seric #endif 11952647Seric } 12052647Seric 12159254Seric #ifdef XLA 12259254Seric xla_zero(); 12359254Seric #endif 12459254Seric 12557135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1263308Seric { 12757135Seric if (bp[0] == '#') 12857135Seric { 12957135Seric if (bp != buf) 13057135Seric free(bp); 13152637Seric continue; 13257135Seric } 13352637Seric 13458050Seric /* map $ into \201 for macro expansion */ 13557135Seric for (p = bp; *p != '\0'; p++) 13616157Seric { 13757135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 13852647Seric { 13952647Seric /* this is an on-line comment */ 14052647Seric register char *e; 14152647Seric 14258050Seric switch (*--p & 0377) 14352647Seric { 14458050Seric case MACROEXPAND: 14552647Seric /* it's from $# -- let it go through */ 14652647Seric p++; 14752647Seric break; 14852647Seric 14952647Seric case '\\': 15052647Seric /* it's backslash escaped */ 15152647Seric (void) strcpy(p, p + 1); 15252647Seric break; 15352647Seric 15452647Seric default: 15552647Seric /* delete preceeding white space */ 15658050Seric while (isascii(*p) && isspace(*p) && p > bp) 15752647Seric p--; 15856795Seric if ((e = strchr(++p, '\n')) != NULL) 15952647Seric (void) strcpy(p, e); 16052647Seric else 16152647Seric p[0] = p[1] = '\0'; 16252647Seric break; 16352647Seric } 16452647Seric continue; 16552647Seric } 16652647Seric 16716157Seric if (*p != '$') 16816157Seric continue; 16916157Seric 17016157Seric if (p[1] == '$') 17116157Seric { 17216157Seric /* actual dollar sign.... */ 17323111Seric (void) strcpy(p, p + 1); 17416157Seric continue; 17516157Seric } 17616157Seric 17716157Seric /* convert to macro expansion character */ 17858050Seric *p = MACROEXPAND; 17916157Seric } 18016157Seric 18116157Seric /* interpret this line */ 18257135Seric switch (bp[0]) 1833308Seric { 1843308Seric case '\0': 1853308Seric case '#': /* comment */ 1863308Seric break; 1873308Seric 1883308Seric case 'R': /* rewriting rule */ 18957135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1903308Seric continue; 1913308Seric 1923308Seric if (*p == '\0') 1935909Seric { 19457135Seric syserr("invalid rewrite line \"%s\"", bp); 1955909Seric break; 1965909Seric } 1975909Seric 1985909Seric /* allocate space for the rule header */ 1995909Seric if (rwp == NULL) 2005909Seric { 2015909Seric RewriteRules[ruleset] = rwp = 2025909Seric (struct rewrite *) xalloc(sizeof *rwp); 2035909Seric } 2043308Seric else 2053308Seric { 2065909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2075909Seric rwp = rwp->r_next; 2085909Seric } 2095909Seric rwp->r_next = NULL; 2103308Seric 2115909Seric /* expand and save the LHS */ 2125909Seric *p = '\0'; 21357135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 21458333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 21557589Seric nfuzzy = 0; 2165909Seric if (rwp->r_lhs != NULL) 21757589Seric { 21857589Seric register char **ap; 21957589Seric 2205909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22157589Seric 22257589Seric /* count the number of fuzzy matches in LHS */ 22357589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22457589Seric { 22558148Seric char *botch; 22658148Seric 22758148Seric botch = NULL; 22858050Seric switch (**ap & 0377) 22957589Seric { 23057589Seric case MATCHZANY: 23157589Seric case MATCHANY: 23257589Seric case MATCHONE: 23357589Seric case MATCHCLASS: 23457589Seric case MATCHNCLASS: 23557589Seric nfuzzy++; 23658148Seric break; 23758148Seric 23858148Seric case MATCHREPL: 23958148Seric botch = "$0-$9"; 24058148Seric break; 24158148Seric 24258148Seric case CANONNET: 24358148Seric botch = "$#"; 24458148Seric break; 24558148Seric 24658148Seric case CANONUSER: 24758148Seric botch = "$:"; 24858148Seric break; 24958148Seric 25058148Seric case CALLSUBR: 25158148Seric botch = "$>"; 25258148Seric break; 25358148Seric 25458148Seric case CONDIF: 25558148Seric botch = "$?"; 25658148Seric break; 25758148Seric 25858148Seric case CONDELSE: 25958148Seric botch = "$|"; 26058148Seric break; 26158148Seric 26258148Seric case CONDFI: 26358148Seric botch = "$."; 26458148Seric break; 26558148Seric 26658148Seric case HOSTBEGIN: 26758148Seric botch = "$["; 26858148Seric break; 26958148Seric 27058148Seric case HOSTEND: 27158148Seric botch = "$]"; 27258148Seric break; 27358148Seric 27458148Seric case LOOKUPBEGIN: 27558148Seric botch = "$("; 27658148Seric break; 27758148Seric 27858148Seric case LOOKUPEND: 27958148Seric botch = "$)"; 28058148Seric break; 28157589Seric } 28258148Seric if (botch != NULL) 28358148Seric syserr("Inappropriate use of %s on LHS", 28458148Seric botch); 28557589Seric } 28657589Seric } 28756678Seric else 28856678Seric syserr("R line: null LHS"); 2895909Seric 2905909Seric /* expand and save the RHS */ 2915909Seric while (*++p == '\t') 2925909Seric continue; 2937231Seric q = p; 2947231Seric while (*p != '\0' && *p != '\t') 2957231Seric p++; 2967231Seric *p = '\0'; 29755012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 29858333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 2995909Seric if (rwp->r_rhs != NULL) 30057589Seric { 30157589Seric register char **ap; 30257589Seric 3035909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30457589Seric 30557589Seric /* check no out-of-bounds replacements */ 30657589Seric nfuzzy += '0'; 30757589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 30857589Seric { 30958148Seric char *botch; 31058148Seric 31158148Seric botch = NULL; 31258148Seric switch (**ap & 0377) 31357589Seric { 31458148Seric case MATCHREPL: 31558148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 31658148Seric { 31758148Seric syserr("replacement $%c out of bounds", 31858148Seric (*ap)[1]); 31958148Seric } 32058148Seric break; 32158148Seric 32258148Seric case MATCHZANY: 32358148Seric botch = "$*"; 32458148Seric break; 32558148Seric 32658148Seric case MATCHANY: 32758148Seric botch = "$+"; 32858148Seric break; 32958148Seric 33058148Seric case MATCHONE: 33158148Seric botch = "$-"; 33258148Seric break; 33358148Seric 33458148Seric case MATCHCLASS: 33558148Seric botch = "$="; 33658148Seric break; 33758148Seric 33858148Seric case MATCHNCLASS: 33958148Seric botch = "$~"; 34058148Seric break; 34157589Seric } 34258148Seric if (botch != NULL) 34358148Seric syserr("Inappropriate use of %s on RHS", 34458148Seric botch); 34557589Seric } 34657589Seric } 34756678Seric else 34856678Seric syserr("R line: null RHS"); 3493308Seric break; 3503308Seric 3514072Seric case 'S': /* select rewriting set */ 35257135Seric ruleset = atoi(&bp[1]); 3538056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3548056Seric { 3559381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3568056Seric ruleset = 0; 3578056Seric } 3584072Seric rwp = NULL; 3594072Seric break; 3604072Seric 3613308Seric case 'D': /* macro definition */ 36264086Seric p = munchstring(&bp[2], NULL); 36364086Seric define(bp[1], newstr(p), e); 3643308Seric break; 3653308Seric 3663387Seric case 'H': /* required header line */ 36757135Seric (void) chompheader(&bp[1], TRUE, e); 3683387Seric break; 3693387Seric 3704061Seric case 'C': /* word class */ 3714432Seric /* scan the list of words and set class for all */ 37264121Seric expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e); 37364121Seric for (p = exbuf; *p != '\0'; ) 3744061Seric { 3754061Seric register char *wd; 3764061Seric char delim; 3774061Seric 37858050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3794061Seric p++; 3804061Seric wd = p; 38158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3824061Seric p++; 3834061Seric delim = *p; 3844061Seric *p = '\0'; 3854061Seric if (wd[0] != '\0') 38658148Seric { 38758148Seric if (tTd(37, 2)) 38858148Seric printf("setclass(%c, %s)\n", 38958148Seric bp[1], wd); 39057135Seric setclass(bp[1], wd); 39158148Seric } 3924061Seric *p = delim; 3934061Seric } 3944061Seric break; 3954061Seric 39659272Seric case 'F': /* word class from file */ 397*64133Seric for (p = &bp[2]; isascii(*p) && isspace(*p); ) 398*64133Seric p++; 399*64133Seric if (p[0] == '-' && p[1] == 'o') 400*64133Seric { 401*64133Seric optional = TRUE; 402*64133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 403*64133Seric p++; 404*64133Seric while (isascii(*p) && isspace(*p)) 405*64133Seric *p++; 406*64133Seric } 407*64133Seric else 408*64133Seric optional = FALSE; 409*64133Seric file = p; 410*64133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 411*64133Seric p++; 41259272Seric if (*p == '\0') 41359272Seric p = "%s"; 41459272Seric else 41559272Seric { 41659272Seric *p = '\0'; 41759272Seric while (isascii(*++p) && isspace(*p)) 41859272Seric continue; 41959272Seric } 420*64133Seric fileclass(bp[1], file, p, safe, optional); 42159272Seric break; 42259272Seric 42359156Seric #ifdef XLA 42459156Seric case 'L': /* extended load average description */ 42559156Seric xla_init(&bp[1]); 42659156Seric break; 42759156Seric #endif 42859156Seric 4294096Seric case 'M': /* define mailer */ 43057135Seric makemailer(&bp[1]); 4314096Seric break; 4324096Seric 4338252Seric case 'O': /* set option */ 43458734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4358252Seric break; 4368252Seric 4378252Seric case 'P': /* set precedence */ 4388252Seric if (NumPriorities >= MAXPRIORITIES) 4398252Seric { 4408547Seric toomany('P', MAXPRIORITIES); 4418252Seric break; 4428252Seric } 44357135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4448252Seric continue; 4458252Seric if (*p == '\0') 4468252Seric goto badline; 4478252Seric *p = '\0'; 44857135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4498252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4508252Seric NumPriorities++; 4518252Seric break; 4528252Seric 4538547Seric case 'T': /* trusted user(s) */ 45458161Seric /* this option is obsolete, but will be ignored */ 4558547Seric break; 4568547Seric 45752645Seric case 'V': /* configuration syntax version */ 45857135Seric ConfigLevel = atoi(&bp[1]); 45952645Seric break; 46052645Seric 46153654Seric case 'K': 46257135Seric makemapentry(&bp[1]); 46353654Seric break; 46453654Seric 4653308Seric default: 4664061Seric badline: 46757135Seric syserr("unknown control line \"%s\"", bp); 4683308Seric } 46957135Seric if (bp != buf) 47057135Seric free(bp); 4713308Seric } 47252637Seric if (ferror(cf)) 47352637Seric { 47452647Seric syserr("I/O read error", cfname); 47552637Seric exit(EX_OSFILE); 47652637Seric } 47752637Seric fclose(cf); 4789381Seric FileName = NULL; 47956836Seric 48057076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 48157076Seric { 48257076Seric /* user didn't initialize: set up host map */ 48357076Seric strcpy(buf, "host host"); 48457076Seric if (ConfigLevel >= 2) 48557076Seric strcat(buf, " -a."); 48657076Seric makemapentry(buf); 48757076Seric } 4884096Seric } 4894096Seric /* 4908547Seric ** TOOMANY -- signal too many of some option 4918547Seric ** 4928547Seric ** Parameters: 4938547Seric ** id -- the id of the error line 4948547Seric ** maxcnt -- the maximum possible values 4958547Seric ** 4968547Seric ** Returns: 4978547Seric ** none. 4988547Seric ** 4998547Seric ** Side Effects: 5008547Seric ** gives a syserr. 5018547Seric */ 5028547Seric 5038547Seric toomany(id, maxcnt) 5048547Seric char id; 5058547Seric int maxcnt; 5068547Seric { 5079381Seric syserr("too many %c lines, %d max", id, maxcnt); 5088547Seric } 5098547Seric /* 5104432Seric ** FILECLASS -- read members of a class from a file 5114432Seric ** 5124432Seric ** Parameters: 5134432Seric ** class -- class to define. 5144432Seric ** filename -- name of file to read. 5154432Seric ** fmt -- scanf string to use for match. 516*64133Seric ** safe -- if set, this is a safe read. 517*64133Seric ** optional -- if set, it is not an error for the file to 518*64133Seric ** not exist. 5194432Seric ** 5204432Seric ** Returns: 5214432Seric ** none 5224432Seric ** 5234432Seric ** Side Effects: 5244432Seric ** 5254432Seric ** puts all lines in filename that match a scanf into 5264432Seric ** the named class. 5274432Seric */ 5284432Seric 529*64133Seric fileclass(class, filename, fmt, safe, optional) 5304432Seric int class; 5314432Seric char *filename; 5324432Seric char *fmt; 53354973Seric bool safe; 534*64133Seric bool optional; 5354432Seric { 53625808Seric FILE *f; 53754973Seric struct stat stbuf; 5384432Seric char buf[MAXLINE]; 5394432Seric 54054973Seric if (stat(filename, &stbuf) < 0) 54154973Seric { 542*64133Seric if (!optional) 543*64133Seric syserr("fileclass: cannot stat %s", filename); 54454973Seric return; 54554973Seric } 54654973Seric if (!S_ISREG(stbuf.st_mode)) 54754973Seric { 54854973Seric syserr("fileclass: %s not a regular file", filename); 54954973Seric return; 55054973Seric } 55154973Seric if (!safe && access(filename, R_OK) < 0) 55254973Seric { 55354973Seric syserr("fileclass: access denied on %s", filename); 55454973Seric return; 55554973Seric } 55654973Seric f = fopen(filename, "r"); 5574432Seric if (f == NULL) 5584432Seric { 55954973Seric syserr("fileclass: cannot open %s", filename); 5604432Seric return; 5614432Seric } 5624432Seric 5634432Seric while (fgets(buf, sizeof buf, f) != NULL) 5644432Seric { 5654432Seric register STAB *s; 56625808Seric register char *p; 56725808Seric # ifdef SCANF 5684432Seric char wordbuf[MAXNAME+1]; 5694432Seric 5704432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5714432Seric continue; 57225808Seric p = wordbuf; 57356795Seric # else /* SCANF */ 57425808Seric p = buf; 57556795Seric # endif /* SCANF */ 57625808Seric 57725808Seric /* 57825808Seric ** Break up the match into words. 57925808Seric */ 58025808Seric 58125808Seric while (*p != '\0') 58225808Seric { 58325808Seric register char *q; 58425808Seric 58525808Seric /* strip leading spaces */ 58658050Seric while (isascii(*p) && isspace(*p)) 58725808Seric p++; 58825808Seric if (*p == '\0') 58925808Seric break; 59025808Seric 59125808Seric /* find the end of the word */ 59225808Seric q = p; 59358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 59425808Seric p++; 59525808Seric if (*p != '\0') 59625808Seric *p++ = '\0'; 59725808Seric 59825808Seric /* enter the word in the symbol table */ 59925808Seric s = stab(q, ST_CLASS, ST_ENTER); 60025808Seric setbitn(class, s->s_class); 60125808Seric } 6024432Seric } 6034432Seric 60454973Seric (void) fclose(f); 6054432Seric } 6064432Seric /* 6074096Seric ** MAKEMAILER -- define a new mailer. 6084096Seric ** 6094096Seric ** Parameters: 61010327Seric ** line -- description of mailer. This is in labeled 61110327Seric ** fields. The fields are: 61210327Seric ** P -- the path to the mailer 61310327Seric ** F -- the flags associated with the mailer 61410327Seric ** A -- the argv for this mailer 61510327Seric ** S -- the sender rewriting set 61610327Seric ** R -- the recipient rewriting set 61710327Seric ** E -- the eol string 61810327Seric ** The first word is the canonical name of the mailer. 6194096Seric ** 6204096Seric ** Returns: 6214096Seric ** none. 6224096Seric ** 6234096Seric ** Side Effects: 6244096Seric ** enters the mailer into the mailer table. 6254096Seric */ 6263308Seric 62721066Seric makemailer(line) 6284096Seric char *line; 6294096Seric { 6304096Seric register char *p; 6318067Seric register struct mailer *m; 6328067Seric register STAB *s; 6338067Seric int i; 63410327Seric char fcode; 63558020Seric auto char *endp; 6364096Seric extern int NextMailer; 63710327Seric extern char **makeargv(); 63810327Seric extern char *munchstring(); 63910701Seric extern long atol(); 6404096Seric 64110327Seric /* allocate a mailer and set up defaults */ 64210327Seric m = (struct mailer *) xalloc(sizeof *m); 64310327Seric bzero((char *) m, sizeof *m); 64410327Seric m->m_eol = "\n"; 64510327Seric 64610327Seric /* collect the mailer name */ 64758050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 64810327Seric continue; 64910327Seric if (*p != '\0') 65010327Seric *p++ = '\0'; 65110327Seric m->m_name = newstr(line); 65210327Seric 65310327Seric /* now scan through and assign info from the fields */ 65410327Seric while (*p != '\0') 65510327Seric { 65658333Seric auto char *delimptr; 65758333Seric 65858050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 65910327Seric p++; 66010327Seric 66110327Seric /* p now points to field code */ 66210327Seric fcode = *p; 66310327Seric while (*p != '\0' && *p != '=' && *p != ',') 66410327Seric p++; 66510327Seric if (*p++ != '=') 66610327Seric { 66752637Seric syserr("mailer %s: `=' expected", m->m_name); 66810327Seric return; 66910327Seric } 67058050Seric while (isascii(*p) && isspace(*p)) 67110327Seric p++; 67210327Seric 67310327Seric /* p now points to the field body */ 67458333Seric p = munchstring(p, &delimptr); 67510327Seric 67610327Seric /* install the field into the mailer struct */ 67710327Seric switch (fcode) 67810327Seric { 67910327Seric case 'P': /* pathname */ 68010327Seric m->m_mailer = newstr(p); 68110327Seric break; 68210327Seric 68310327Seric case 'F': /* flags */ 68410687Seric for (; *p != '\0'; p++) 68558050Seric if (!(isascii(*p) && isspace(*p))) 68652637Seric setbitn(*p, m->m_flags); 68710327Seric break; 68810327Seric 68910327Seric case 'S': /* sender rewriting ruleset */ 69010327Seric case 'R': /* recipient rewriting ruleset */ 69158020Seric i = strtol(p, &endp, 10); 69210327Seric if (i < 0 || i >= MAXRWSETS) 69310327Seric { 69410327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 69510327Seric return; 69610327Seric } 69710327Seric if (fcode == 'S') 69858020Seric m->m_sh_rwset = m->m_se_rwset = i; 69910327Seric else 70058020Seric m->m_rh_rwset = m->m_re_rwset = i; 70158020Seric 70258020Seric p = endp; 70359985Seric if (*p++ == '/') 70458020Seric { 70558020Seric i = strtol(p, NULL, 10); 70658020Seric if (i < 0 || i >= MAXRWSETS) 70758020Seric { 70858020Seric syserr("invalid rewrite set, %d max", 70958020Seric MAXRWSETS); 71058020Seric return; 71158020Seric } 71258020Seric if (fcode == 'S') 71358020Seric m->m_sh_rwset = i; 71458020Seric else 71558020Seric m->m_rh_rwset = i; 71658020Seric } 71710327Seric break; 71810327Seric 71910327Seric case 'E': /* end of line string */ 72010327Seric m->m_eol = newstr(p); 72110327Seric break; 72210327Seric 72310327Seric case 'A': /* argument vector */ 72410327Seric m->m_argv = makeargv(p); 72510327Seric break; 72610701Seric 72710701Seric case 'M': /* maximum message size */ 72810701Seric m->m_maxsize = atol(p); 72910701Seric break; 73052106Seric 73152106Seric case 'L': /* maximum line length */ 73252106Seric m->m_linelimit = atoi(p); 73352106Seric break; 73458935Seric 73558935Seric case 'D': /* working directory */ 73658935Seric m->m_execdir = newstr(p); 73758935Seric break; 73810327Seric } 73910327Seric 74058333Seric p = delimptr; 74110327Seric } 74210327Seric 74352106Seric /* do some heuristic cleanup for back compatibility */ 74452106Seric if (bitnset(M_LIMITS, m->m_flags)) 74552106Seric { 74652106Seric if (m->m_linelimit == 0) 74752106Seric m->m_linelimit = SMTPLINELIM; 74855418Seric if (ConfigLevel < 2) 74952106Seric setbitn(M_7BITS, m->m_flags); 75052106Seric } 75152106Seric 75258321Seric /* do some rationality checking */ 75358321Seric if (m->m_argv == NULL) 75458321Seric { 75558321Seric syserr("M%s: A= argument required", m->m_name); 75658321Seric return; 75758321Seric } 75858321Seric if (m->m_mailer == NULL) 75958321Seric { 76058321Seric syserr("M%s: P= argument required", m->m_name); 76158321Seric return; 76258321Seric } 76358321Seric 7644096Seric if (NextMailer >= MAXMAILERS) 7654096Seric { 7669381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7674096Seric return; 7684096Seric } 76957402Seric 77010327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 77157402Seric if (s->s_mailer != NULL) 77257402Seric { 77357402Seric i = s->s_mailer->m_mno; 77457402Seric free(s->s_mailer); 77557402Seric } 77657402Seric else 77757402Seric { 77857402Seric i = NextMailer++; 77957402Seric } 78057402Seric Mailer[i] = s->s_mailer = m; 78157454Seric m->m_mno = i; 78210327Seric } 78310327Seric /* 78410327Seric ** MUNCHSTRING -- translate a string into internal form. 78510327Seric ** 78610327Seric ** Parameters: 78710327Seric ** p -- the string to munch. 78858333Seric ** delimptr -- if non-NULL, set to the pointer of the 78958333Seric ** field delimiter character. 79010327Seric ** 79110327Seric ** Returns: 79210327Seric ** the munched string. 79310327Seric */ 7944096Seric 79510327Seric char * 79658333Seric munchstring(p, delimptr) 79710327Seric register char *p; 79858333Seric char **delimptr; 79910327Seric { 80010327Seric register char *q; 80110327Seric bool backslash = FALSE; 80210327Seric bool quotemode = FALSE; 80310327Seric static char buf[MAXLINE]; 8044096Seric 80510327Seric for (q = buf; *p != '\0'; p++) 8064096Seric { 80710327Seric if (backslash) 80810327Seric { 80910327Seric /* everything is roughly literal */ 81010357Seric backslash = FALSE; 81110327Seric switch (*p) 81210327Seric { 81310327Seric case 'r': /* carriage return */ 81410327Seric *q++ = '\r'; 81510327Seric continue; 81610327Seric 81710327Seric case 'n': /* newline */ 81810327Seric *q++ = '\n'; 81910327Seric continue; 82010327Seric 82110327Seric case 'f': /* form feed */ 82210327Seric *q++ = '\f'; 82310327Seric continue; 82410327Seric 82510327Seric case 'b': /* backspace */ 82610327Seric *q++ = '\b'; 82710327Seric continue; 82810327Seric } 82910327Seric *q++ = *p; 83010327Seric } 83110327Seric else 83210327Seric { 83310327Seric if (*p == '\\') 83410327Seric backslash = TRUE; 83510327Seric else if (*p == '"') 83610327Seric quotemode = !quotemode; 83710327Seric else if (quotemode || *p != ',') 83810327Seric *q++ = *p; 83910327Seric else 84010327Seric break; 84110327Seric } 8424096Seric } 8434096Seric 84458333Seric if (delimptr != NULL) 84558333Seric *delimptr = p; 84610327Seric *q++ = '\0'; 84710327Seric return (buf); 84810327Seric } 84910327Seric /* 85010327Seric ** MAKEARGV -- break up a string into words 85110327Seric ** 85210327Seric ** Parameters: 85310327Seric ** p -- the string to break up. 85410327Seric ** 85510327Seric ** Returns: 85610327Seric ** a char **argv (dynamically allocated) 85710327Seric ** 85810327Seric ** Side Effects: 85910327Seric ** munges p. 86010327Seric */ 8614096Seric 86210327Seric char ** 86310327Seric makeargv(p) 86410327Seric register char *p; 86510327Seric { 86610327Seric char *q; 86710327Seric int i; 86810327Seric char **avp; 86910327Seric char *argv[MAXPV + 1]; 87010327Seric 87110327Seric /* take apart the words */ 87210327Seric i = 0; 87310327Seric while (*p != '\0' && i < MAXPV) 8744096Seric { 87510327Seric q = p; 87658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 87710327Seric p++; 87858050Seric while (isascii(*p) && isspace(*p)) 87910327Seric *p++ = '\0'; 88010327Seric argv[i++] = newstr(q); 8814096Seric } 88210327Seric argv[i++] = NULL; 8834096Seric 88410327Seric /* now make a copy of the argv */ 88510327Seric avp = (char **) xalloc(sizeof *avp * i); 88616893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 88710327Seric 88810327Seric return (avp); 8893308Seric } 8903308Seric /* 8913308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8923308Seric ** 8933308Seric ** Parameters: 8943308Seric ** none. 8953308Seric ** 8963308Seric ** Returns: 8973308Seric ** none. 8983308Seric ** 8993308Seric ** Side Effects: 9003308Seric ** prints rewrite rules. 9013308Seric */ 9023308Seric 9033308Seric printrules() 9043308Seric { 9053308Seric register struct rewrite *rwp; 9064072Seric register int ruleset; 9073308Seric 9084072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9093308Seric { 9104072Seric if (RewriteRules[ruleset] == NULL) 9114072Seric continue; 9128067Seric printf("\n----Rule Set %d:", ruleset); 9133308Seric 9144072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9153308Seric { 9168067Seric printf("\nLHS:"); 9178067Seric printav(rwp->r_lhs); 9188067Seric printf("RHS:"); 9198067Seric printav(rwp->r_rhs); 9203308Seric } 9213308Seric } 9223308Seric } 9234319Seric 9244096Seric /* 9258256Seric ** SETOPTION -- set global processing option 9268256Seric ** 9278256Seric ** Parameters: 9288256Seric ** opt -- option name. 9298256Seric ** val -- option value (as a text string). 93021755Seric ** safe -- set if this came from a configuration file. 93121755Seric ** Some options (if set from the command line) will 93221755Seric ** reset the user id to avoid security problems. 9338269Seric ** sticky -- if set, don't let other setoptions override 9348269Seric ** this value. 93558734Seric ** e -- the main envelope. 9368256Seric ** 9378256Seric ** Returns: 9388256Seric ** none. 9398256Seric ** 9408256Seric ** Side Effects: 9418256Seric ** Sets options as implied by the arguments. 9428256Seric */ 9438256Seric 94410687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9458269Seric 94657207Seric 94757207Seric #ifdef NAMED_BIND 94857207Seric 94957207Seric struct resolverflags 95057207Seric { 95157207Seric char *rf_name; /* name of the flag */ 95257207Seric long rf_bits; /* bits to set/clear */ 95357207Seric } ResolverFlags[] = 95457207Seric { 95557207Seric "debug", RES_DEBUG, 95657207Seric "aaonly", RES_AAONLY, 95757207Seric "usevc", RES_USEVC, 95857207Seric "primary", RES_PRIMARY, 95957207Seric "igntc", RES_IGNTC, 96057207Seric "recurse", RES_RECURSE, 96157207Seric "defnames", RES_DEFNAMES, 96257207Seric "stayopen", RES_STAYOPEN, 96357207Seric "dnsrch", RES_DNSRCH, 96457207Seric NULL, 0 96557207Seric }; 96657207Seric 96757207Seric #endif 96857207Seric 96958734Seric setoption(opt, val, safe, sticky, e) 9708256Seric char opt; 9718256Seric char *val; 97221755Seric bool safe; 9738269Seric bool sticky; 97458734Seric register ENVELOPE *e; 9758256Seric { 97657207Seric register char *p; 9778265Seric extern bool atobool(); 97812633Seric extern time_t convtime(); 97914879Seric extern int QueueLA; 98014879Seric extern int RefuseLA; 98117474Seric extern bool trusteduser(); 9828256Seric 9838256Seric if (tTd(37, 1)) 9849341Seric printf("setoption %c=%s", opt, val); 9858256Seric 9868256Seric /* 9878269Seric ** See if this option is preset for us. 9888256Seric */ 9898256Seric 99059731Seric if (!sticky && bitnset(opt, StickyOpt)) 9918269Seric { 9929341Seric if (tTd(37, 1)) 9939341Seric printf(" (ignored)\n"); 9948269Seric return; 9958269Seric } 9968269Seric 99721755Seric /* 99821755Seric ** Check to see if this option can be specified by this user. 99921755Seric */ 100021755Seric 100163787Seric if (!safe && RealUid == 0) 100221755Seric safe = TRUE; 100363837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 100421755Seric { 100539111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 100621755Seric { 100736582Sbostic if (tTd(37, 1)) 100836582Sbostic printf(" (unsafe)"); 100963787Seric if (RealUid != geteuid()) 101036582Sbostic { 101151210Seric if (tTd(37, 1)) 101251210Seric printf("(Resetting uid)"); 101363787Seric (void) setgid(RealGid); 101463787Seric (void) setuid(RealUid); 101536582Sbostic } 101621755Seric } 101721755Seric } 101851210Seric if (tTd(37, 1)) 101917985Seric printf("\n"); 10208269Seric 10218256Seric switch (opt) 10228256Seric { 102359709Seric case '7': /* force seven-bit input */ 102459709Seric SevenBit = atobool(val); 102552106Seric break; 102652106Seric 10278256Seric case 'A': /* set default alias file */ 10289381Seric if (val[0] == '\0') 102959672Seric setalias("aliases"); 10309381Seric else 103159672Seric setalias(val); 10328256Seric break; 10338256Seric 103417474Seric case 'a': /* look N minutes for "@:@" in alias file */ 103517474Seric if (val[0] == '\0') 103617474Seric SafeAlias = 5; 103717474Seric else 103817474Seric SafeAlias = atoi(val); 103917474Seric break; 104017474Seric 104116843Seric case 'B': /* substitution for blank character */ 104216843Seric SpaceSub = val[0]; 104316843Seric if (SpaceSub == '\0') 104416843Seric SpaceSub = ' '; 104516843Seric break; 104616843Seric 104759283Seric case 'b': /* min blocks free on queue fs/max msg size */ 104859283Seric p = strchr(val, '/'); 104959283Seric if (p != NULL) 105059283Seric { 105159283Seric *p++ = '\0'; 105259283Seric MaxMessageSize = atol(p); 105359283Seric } 105458082Seric MinBlocksFree = atol(val); 105558082Seric break; 105658082Seric 10579284Seric case 'c': /* don't connect to "expensive" mailers */ 10589381Seric NoConnect = atobool(val); 10599284Seric break; 10609284Seric 106151305Seric case 'C': /* checkpoint every N addresses */ 106251305Seric CheckpointInterval = atoi(val); 106324944Seric break; 106424944Seric 10659284Seric case 'd': /* delivery mode */ 10669284Seric switch (*val) 10678269Seric { 10689284Seric case '\0': 106958734Seric e->e_sendmode = SM_DELIVER; 10708269Seric break; 10718269Seric 107210755Seric case SM_QUEUE: /* queue only */ 107310755Seric #ifndef QUEUE 107410755Seric syserr("need QUEUE to set -odqueue"); 107556795Seric #endif /* QUEUE */ 107610755Seric /* fall through..... */ 107710755Seric 10789284Seric case SM_DELIVER: /* do everything */ 10799284Seric case SM_FORK: /* fork after verification */ 108058734Seric e->e_sendmode = *val; 10818269Seric break; 10828269Seric 10838269Seric default: 10849284Seric syserr("Unknown delivery mode %c", *val); 10858269Seric exit(EX_USAGE); 10868269Seric } 10878269Seric break; 10888269Seric 10899146Seric case 'D': /* rebuild alias database as needed */ 10909381Seric AutoRebuild = atobool(val); 10919146Seric break; 10929146Seric 109355372Seric case 'E': /* error message header/header file */ 109455379Seric if (*val != '\0') 109555379Seric ErrMsgFile = newstr(val); 109655372Seric break; 109755372Seric 10988269Seric case 'e': /* set error processing mode */ 10998269Seric switch (*val) 11008269Seric { 11019381Seric case EM_QUIET: /* be silent about it */ 11029381Seric case EM_MAIL: /* mail back */ 11039381Seric case EM_BERKNET: /* do berknet error processing */ 11049381Seric case EM_WRITE: /* write back (or mail) */ 11058269Seric HoldErrs = TRUE; 11069381Seric /* fall through... */ 11078269Seric 11089381Seric case EM_PRINT: /* print errors normally (default) */ 110958734Seric e->e_errormode = *val; 11108269Seric break; 11118269Seric } 11128269Seric break; 11138269Seric 11149049Seric case 'F': /* file mode */ 111517975Seric FileMode = atooct(val) & 0777; 11169049Seric break; 11179049Seric 11188269Seric case 'f': /* save Unix-style From lines on front */ 11199381Seric SaveFrom = atobool(val); 11208269Seric break; 11218269Seric 112253735Seric case 'G': /* match recipients against GECOS field */ 112353735Seric MatchGecos = atobool(val); 112453735Seric break; 112553735Seric 11268256Seric case 'g': /* default gid */ 1127*64133Seric if (isascii(*val) && isdigit(*val)) 1128*64133Seric DefGid = atoi(val); 1129*64133Seric else 1130*64133Seric { 1131*64133Seric register struct group *gr; 1132*64133Seric 1133*64133Seric DefGid = -1; 1134*64133Seric gr = getgrnam(val); 1135*64133Seric if (gr == NULL) 1136*64133Seric syserr("readcf: option g: unknown group %s", val); 1137*64133Seric else 1138*64133Seric DefGid = gr->gr_gid; 1139*64133Seric } 11408256Seric break; 11418256Seric 11428256Seric case 'H': /* help file */ 11439381Seric if (val[0] == '\0') 11448269Seric HelpFile = "sendmail.hf"; 11459381Seric else 11469381Seric HelpFile = newstr(val); 11478256Seric break; 11488256Seric 114951305Seric case 'h': /* maximum hop count */ 115051305Seric MaxHopCount = atoi(val); 115151305Seric break; 115251305Seric 115335651Seric case 'I': /* use internet domain name server */ 115457207Seric #ifdef NAMED_BIND 115557207Seric UseNameServer = TRUE; 115657207Seric for (p = val; *p != 0; ) 115757207Seric { 115857207Seric bool clearmode; 115957207Seric char *q; 116057207Seric struct resolverflags *rfp; 116157207Seric 116257207Seric while (*p == ' ') 116357207Seric p++; 116457207Seric if (*p == '\0') 116557207Seric break; 116657207Seric clearmode = FALSE; 116757207Seric if (*p == '-') 116857207Seric clearmode = TRUE; 116957207Seric else if (*p != '+') 117057207Seric p--; 117157207Seric p++; 117257207Seric q = p; 117358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 117457207Seric p++; 117557207Seric if (*p != '\0') 117657207Seric *p++ = '\0'; 117757207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 117857207Seric { 117957207Seric if (strcasecmp(q, rfp->rf_name) == 0) 118057207Seric break; 118157207Seric } 118257207Seric if (clearmode) 118357207Seric _res.options &= ~rfp->rf_bits; 118457207Seric else 118557207Seric _res.options |= rfp->rf_bits; 118657207Seric } 118757207Seric if (tTd(8, 2)) 118857207Seric printf("_res.options = %x\n", _res.options); 118957207Seric #else 119057207Seric usrerr("name server (I option) specified but BIND not compiled in"); 119157207Seric #endif 119235651Seric break; 119335651Seric 11948269Seric case 'i': /* ignore dot lines in message */ 11959381Seric IgnrDot = atobool(val); 11968269Seric break; 11978269Seric 119859730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 119959730Seric SendMIMEErrors = atobool(val); 120059730Seric break; 120159730Seric 120257136Seric case 'J': /* .forward search path */ 120357136Seric ForwardPath = newstr(val); 120457136Seric break; 120557136Seric 120654967Seric case 'k': /* connection cache size */ 120754967Seric MaxMciCache = atoi(val); 120856215Seric if (MaxMciCache < 0) 120956215Seric MaxMciCache = 0; 121054967Seric break; 121154967Seric 121254967Seric case 'K': /* connection cache timeout */ 121358796Seric MciCacheTimeout = convtime(val, 'm'); 121454967Seric break; 121554967Seric 121661104Seric case 'l': /* use Errors-To: header */ 121761104Seric UseErrorsTo = atobool(val); 121861104Seric break; 121961104Seric 12208256Seric case 'L': /* log level */ 12219381Seric LogLevel = atoi(val); 12228256Seric break; 12238256Seric 12248269Seric case 'M': /* define macro */ 12259381Seric define(val[0], newstr(&val[1]), CurEnv); 122616878Seric sticky = FALSE; 12278269Seric break; 12288269Seric 12298269Seric case 'm': /* send to me too */ 12309381Seric MeToo = atobool(val); 12318269Seric break; 12328269Seric 123325820Seric case 'n': /* validate RHS in newaliases */ 123425820Seric CheckAliases = atobool(val); 123525820Seric break; 123625820Seric 123761104Seric /* 'N' available -- was "net name" */ 123861104Seric 123958851Seric case 'O': /* daemon options */ 124058851Seric setdaemonoptions(val); 124158851Seric break; 124258851Seric 12438269Seric case 'o': /* assume old style headers */ 12449381Seric if (atobool(val)) 12459341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12469341Seric else 12479341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12488269Seric break; 12498269Seric 125058082Seric case 'p': /* select privacy level */ 125158082Seric p = val; 125258082Seric for (;;) 125358082Seric { 125458082Seric register struct prival *pv; 125558082Seric extern struct prival PrivacyValues[]; 125658082Seric 125758082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 125858082Seric p++; 125958082Seric if (*p == '\0') 126058082Seric break; 126158082Seric val = p; 126258082Seric while (isascii(*p) && isalnum(*p)) 126358082Seric p++; 126458082Seric if (*p != '\0') 126558082Seric *p++ = '\0'; 126658082Seric 126758082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 126858082Seric { 126958082Seric if (strcasecmp(val, pv->pv_name) == 0) 127058082Seric break; 127158082Seric } 127258886Seric if (pv->pv_name == NULL) 127358886Seric syserr("readcf: Op line: %s unrecognized", val); 127458082Seric PrivacyFlags |= pv->pv_flag; 127558082Seric } 127658082Seric break; 127758082Seric 127824944Seric case 'P': /* postmaster copy address for returned mail */ 127924944Seric PostMasterCopy = newstr(val); 128024944Seric break; 128124944Seric 128224944Seric case 'q': /* slope of queue only function */ 128324944Seric QueueFactor = atoi(val); 128424944Seric break; 128524944Seric 12868256Seric case 'Q': /* queue directory */ 12879381Seric if (val[0] == '\0') 12888269Seric QueueDir = "mqueue"; 12899381Seric else 12909381Seric QueueDir = newstr(val); 129158789Seric if (RealUid != 0 && !safe) 129258789Seric auth_warning(e, "Processed from queue %s", QueueDir); 12938256Seric break; 12948256Seric 129558148Seric case 'R': /* don't prune routes */ 129658148Seric DontPruneRoutes = atobool(val); 129758148Seric break; 129858148Seric 12998256Seric case 'r': /* read timeout */ 130058112Seric settimeouts(val); 13018256Seric break; 13028256Seric 13038256Seric case 'S': /* status file */ 13049381Seric if (val[0] == '\0') 13058269Seric StatFile = "sendmail.st"; 13069381Seric else 13079381Seric StatFile = newstr(val); 13088256Seric break; 13098256Seric 13108265Seric case 's': /* be super safe, even if expensive */ 13119381Seric SuperSafe = atobool(val); 13128256Seric break; 13138256Seric 13148256Seric case 'T': /* queue timeout */ 131558737Seric p = strchr(val, '/'); 131658737Seric if (p != NULL) 131758737Seric { 131858737Seric *p++ = '\0'; 131958796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 132058737Seric } 132158796Seric TimeOuts.to_q_return = convtime(val, 'h'); 132254967Seric break; 13238256Seric 13248265Seric case 't': /* time zone name */ 132552106Seric TimeZoneSpec = newstr(val); 13268265Seric break; 13278265Seric 132850556Seric case 'U': /* location of user database */ 132951360Seric UdbSpec = newstr(val); 133050556Seric break; 133150556Seric 13328256Seric case 'u': /* set default uid */ 1333*64133Seric if (isascii(*val) && isdigit(*val)) 1334*64133Seric DefUid = atoi(val); 1335*64133Seric else 1336*64133Seric { 1337*64133Seric register struct passwd *pw; 1338*64133Seric 1339*64133Seric DefUid = -1; 1340*64133Seric pw = getpwnam(val); 1341*64133Seric if (pw == NULL) 1342*64133Seric syserr("readcf: option u: unknown user %s", val); 1343*64133Seric else 1344*64133Seric DefUid = pw->pw_uid; 1345*64133Seric } 134640973Sbostic setdefuser(); 13478256Seric break; 13488256Seric 134958851Seric case 'V': /* fallback MX host */ 135058851Seric FallBackMX = newstr(val); 135158851Seric break; 135258851Seric 13538269Seric case 'v': /* run in verbose mode */ 13549381Seric Verbose = atobool(val); 13558256Seric break; 13568256Seric 135763837Seric case 'w': /* if we are best MX, try host directly */ 135863837Seric TryNullMXList = atobool(val); 135963837Seric break; 136061104Seric 136161104Seric /* 'W' available -- was wizard password */ 136261104Seric 136314879Seric case 'x': /* load avg at which to auto-queue msgs */ 136414879Seric QueueLA = atoi(val); 136514879Seric break; 136614879Seric 136714879Seric case 'X': /* load avg at which to auto-reject connections */ 136814879Seric RefuseLA = atoi(val); 136914879Seric break; 137014879Seric 137124981Seric case 'y': /* work recipient factor */ 137224981Seric WkRecipFact = atoi(val); 137324981Seric break; 137424981Seric 137524981Seric case 'Y': /* fork jobs during queue runs */ 137624952Seric ForkQueueRuns = atobool(val); 137724952Seric break; 137824952Seric 137924981Seric case 'z': /* work message class factor */ 138024981Seric WkClassFact = atoi(val); 138124981Seric break; 138224981Seric 138324981Seric case 'Z': /* work time factor */ 138424981Seric WkTimeFact = atoi(val); 138524981Seric break; 138624981Seric 13878256Seric default: 13888256Seric break; 13898256Seric } 139016878Seric if (sticky) 139116878Seric setbitn(opt, StickyOpt); 13929188Seric return; 13938256Seric } 139410687Seric /* 139510687Seric ** SETCLASS -- set a word into a class 139610687Seric ** 139710687Seric ** Parameters: 139810687Seric ** class -- the class to put the word in. 139910687Seric ** word -- the word to enter 140010687Seric ** 140110687Seric ** Returns: 140210687Seric ** none. 140310687Seric ** 140410687Seric ** Side Effects: 140510687Seric ** puts the word into the symbol table. 140610687Seric */ 140710687Seric 140810687Seric setclass(class, word) 140910687Seric int class; 141010687Seric char *word; 141110687Seric { 141210687Seric register STAB *s; 141310687Seric 141457943Seric if (tTd(37, 8)) 141557943Seric printf("%s added to class %c\n", word, class); 141610687Seric s = stab(word, ST_CLASS, ST_ENTER); 141710687Seric setbitn(class, s->s_class); 141810687Seric } 141953654Seric /* 142053654Seric ** MAKEMAPENTRY -- create a map entry 142153654Seric ** 142253654Seric ** Parameters: 142353654Seric ** line -- the config file line 142453654Seric ** 142553654Seric ** Returns: 142653654Seric ** TRUE if it successfully entered the map entry. 142753654Seric ** FALSE otherwise (usually syntax error). 142853654Seric ** 142953654Seric ** Side Effects: 143053654Seric ** Enters the map into the dictionary. 143153654Seric */ 143253654Seric 143353654Seric void 143453654Seric makemapentry(line) 143553654Seric char *line; 143653654Seric { 143753654Seric register char *p; 143853654Seric char *mapname; 143953654Seric char *classname; 144064078Seric register STAB *s; 144153654Seric STAB *class; 144253654Seric 144358050Seric for (p = line; isascii(*p) && isspace(*p); p++) 144453654Seric continue; 144558050Seric if (!(isascii(*p) && isalnum(*p))) 144653654Seric { 144753654Seric syserr("readcf: config K line: no map name"); 144853654Seric return; 144953654Seric } 145053654Seric 145153654Seric mapname = p; 145258050Seric while (isascii(*++p) && isalnum(*p)) 145353654Seric continue; 145453654Seric if (*p != '\0') 145553654Seric *p++ = '\0'; 145658050Seric while (isascii(*p) && isspace(*p)) 145753654Seric p++; 145858050Seric if (!(isascii(*p) && isalnum(*p))) 145953654Seric { 146053654Seric syserr("readcf: config K line, map %s: no map class", mapname); 146153654Seric return; 146253654Seric } 146353654Seric classname = p; 146458050Seric while (isascii(*++p) && isalnum(*p)) 146553654Seric continue; 146653654Seric if (*p != '\0') 146753654Seric *p++ = '\0'; 146858050Seric while (isascii(*p) && isspace(*p)) 146953654Seric p++; 147053654Seric 147153654Seric /* look up the class */ 147253654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 147353654Seric if (class == NULL) 147453654Seric { 147553654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 147653654Seric return; 147753654Seric } 147853654Seric 147953654Seric /* enter the map */ 148064078Seric s = stab(mapname, ST_MAP, ST_ENTER); 148164078Seric s->s_map.map_class = &class->s_mapclass; 148264078Seric s->s_map.map_mname = newstr(mapname); 148353654Seric 148464078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 148564078Seric s->s_map.map_mflags |= MF_VALID; 148664078Seric 148764078Seric if (tTd(37, 5)) 148864078Seric { 148964078Seric printf("map %s, class %s, flags %x, file %s,\n", 149064078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 149164078Seric s->s_map.map_mflags, 149264078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 149364078Seric printf("\tapp %s, domain %s, rebuild %s\n", 149464078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 149564078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 149664078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 149764078Seric } 149853654Seric } 149958112Seric /* 150058112Seric ** SETTIMEOUTS -- parse and set timeout values 150158112Seric ** 150258112Seric ** Parameters: 150358112Seric ** val -- a pointer to the values. If NULL, do initial 150458112Seric ** settings. 150558112Seric ** 150658112Seric ** Returns: 150758112Seric ** none. 150858112Seric ** 150958112Seric ** Side Effects: 151058112Seric ** Initializes the TimeOuts structure 151158112Seric */ 151258112Seric 151358112Seric #define MINUTES * 60 151458112Seric #define HOUR * 3600 151558112Seric 151658112Seric settimeouts(val) 151758112Seric register char *val; 151858112Seric { 151958112Seric register char *p; 152058671Seric extern time_t convtime(); 152158112Seric 152258112Seric if (val == NULL) 152358112Seric { 152458112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 152558112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 152658112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 152758112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 152858112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 152958112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 153058112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 153158112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 153258112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 153358112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 153458112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 153558112Seric return; 153658112Seric } 153758112Seric 153858112Seric for (;; val = p) 153958112Seric { 154058112Seric while (isascii(*val) && isspace(*val)) 154158112Seric val++; 154258112Seric if (*val == '\0') 154358112Seric break; 154458112Seric for (p = val; *p != '\0' && *p != ','; p++) 154558112Seric continue; 154658112Seric if (*p != '\0') 154758112Seric *p++ = '\0'; 154858112Seric 154958112Seric if (isascii(*val) && isdigit(*val)) 155058112Seric { 155158112Seric /* old syntax -- set everything */ 155258796Seric TimeOuts.to_mail = convtime(val, 'm'); 155358112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 155458112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 155558112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 155658112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 155758112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 155858112Seric continue; 155958112Seric } 156058112Seric else 156158112Seric { 156258112Seric register char *q = strchr(val, '='); 156358112Seric time_t to; 156458112Seric 156558112Seric if (q == NULL) 156658112Seric { 156758112Seric /* syntax error */ 156858112Seric continue; 156958112Seric } 157058112Seric *q++ = '\0'; 157158796Seric to = convtime(q, 'm'); 157258112Seric 157358112Seric if (strcasecmp(val, "initial") == 0) 157458112Seric TimeOuts.to_initial = to; 157558112Seric else if (strcasecmp(val, "mail") == 0) 157658112Seric TimeOuts.to_mail = to; 157758112Seric else if (strcasecmp(val, "rcpt") == 0) 157858112Seric TimeOuts.to_rcpt = to; 157958112Seric else if (strcasecmp(val, "datainit") == 0) 158058112Seric TimeOuts.to_datainit = to; 158158112Seric else if (strcasecmp(val, "datablock") == 0) 158258112Seric TimeOuts.to_datablock = to; 158358112Seric else if (strcasecmp(val, "datafinal") == 0) 158458112Seric TimeOuts.to_datafinal = to; 158558112Seric else if (strcasecmp(val, "command") == 0) 158658112Seric TimeOuts.to_nextcommand = to; 158758112Seric else if (strcasecmp(val, "rset") == 0) 158858112Seric TimeOuts.to_rset = to; 158958112Seric else if (strcasecmp(val, "helo") == 0) 159058112Seric TimeOuts.to_helo = to; 159158112Seric else if (strcasecmp(val, "quit") == 0) 159258112Seric TimeOuts.to_quit = to; 159358112Seric else if (strcasecmp(val, "misc") == 0) 159458112Seric TimeOuts.to_miscshort = to; 159558112Seric else 159658112Seric syserr("settimeouts: invalid timeout %s", val); 159758112Seric } 159858112Seric } 159958112Seric } 1600