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*64279Seric static char sccsid[] = "@(#)readcf.c 8.10 (Berkeley) 08/16/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1464133Seric # include <pwd.h> 1564133Seric # include <grp.h> 1657207Seric #ifdef NAMED_BIND 1757207Seric # include <arpa/nameser.h> 1857207Seric # include <resolv.h> 1957207Seric #endif 203308Seric 213308Seric /* 223308Seric ** READCF -- read control file. 233308Seric ** 243308Seric ** This routine reads the control file and builds the internal 253308Seric ** form. 263308Seric ** 274432Seric ** The file is formatted as a sequence of lines, each taken 284432Seric ** atomically. The first character of each line describes how 294432Seric ** the line is to be interpreted. The lines are: 304432Seric ** Dxval Define macro x to have value val. 314432Seric ** Cxword Put word into class x. 324432Seric ** Fxfile [fmt] Read file for lines to put into 334432Seric ** class x. Use scanf string 'fmt' 344432Seric ** or "%s" if not present. Fmt should 354432Seric ** only produce one string-valued result. 364432Seric ** Hname: value Define header with field-name 'name' 374432Seric ** and value as specified; this will be 384432Seric ** macro expanded immediately before 394432Seric ** use. 404432Seric ** Sn Use rewriting set n. 414432Seric ** Rlhs rhs Rewrite addresses that match lhs to 424432Seric ** be rhs. 4324944Seric ** Mn arg=val... Define mailer. n is the internal name. 4424944Seric ** Args specify mailer parameters. 458252Seric ** Oxvalue Set option x to value. 468252Seric ** Pname=value Set precedence name to value. 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; 7664133Seric char *file; 7764133Seric 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 */ 39764133Seric for (p = &bp[2]; isascii(*p) && isspace(*p); ) 39864133Seric p++; 39964133Seric if (p[0] == '-' && p[1] == 'o') 40064133Seric { 40164133Seric optional = TRUE; 40264133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 40364133Seric p++; 40464133Seric while (isascii(*p) && isspace(*p)) 40564133Seric *p++; 40664133Seric } 40764133Seric else 40864133Seric optional = FALSE; 40964133Seric file = p; 41064133Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 41164133Seric p++; 41259272Seric if (*p == '\0') 41359272Seric p = "%s"; 41459272Seric else 41559272Seric { 41659272Seric *p = '\0'; 41759272Seric while (isascii(*++p) && isspace(*p)) 41859272Seric continue; 41959272Seric } 42064133Seric 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]); 459*64279Seric if (ConfigLevel >= 5) 460*64279Seric { 461*64279Seric /* level 5 configs have short name in $w */ 462*64279Seric p = macvalue('w', e); 463*64279Seric if (p != NULL && (p = strchr(p, '.')) != NULL) 464*64279Seric *p = '\0'; 465*64279Seric } 46652645Seric break; 46752645Seric 46853654Seric case 'K': 46957135Seric makemapentry(&bp[1]); 47053654Seric break; 47153654Seric 4723308Seric default: 4734061Seric badline: 47457135Seric syserr("unknown control line \"%s\"", bp); 4753308Seric } 47657135Seric if (bp != buf) 47757135Seric free(bp); 4783308Seric } 47952637Seric if (ferror(cf)) 48052637Seric { 48152647Seric syserr("I/O read error", cfname); 48252637Seric exit(EX_OSFILE); 48352637Seric } 48452637Seric fclose(cf); 4859381Seric FileName = NULL; 48656836Seric 48757076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 48857076Seric { 48957076Seric /* user didn't initialize: set up host map */ 49057076Seric strcpy(buf, "host host"); 49157076Seric if (ConfigLevel >= 2) 49257076Seric strcat(buf, " -a."); 49357076Seric makemapentry(buf); 49457076Seric } 4954096Seric } 4964096Seric /* 4978547Seric ** TOOMANY -- signal too many of some option 4988547Seric ** 4998547Seric ** Parameters: 5008547Seric ** id -- the id of the error line 5018547Seric ** maxcnt -- the maximum possible values 5028547Seric ** 5038547Seric ** Returns: 5048547Seric ** none. 5058547Seric ** 5068547Seric ** Side Effects: 5078547Seric ** gives a syserr. 5088547Seric */ 5098547Seric 5108547Seric toomany(id, maxcnt) 5118547Seric char id; 5128547Seric int maxcnt; 5138547Seric { 5149381Seric syserr("too many %c lines, %d max", id, maxcnt); 5158547Seric } 5168547Seric /* 5174432Seric ** FILECLASS -- read members of a class from a file 5184432Seric ** 5194432Seric ** Parameters: 5204432Seric ** class -- class to define. 5214432Seric ** filename -- name of file to read. 5224432Seric ** fmt -- scanf string to use for match. 52364133Seric ** safe -- if set, this is a safe read. 52464133Seric ** optional -- if set, it is not an error for the file to 52564133Seric ** not exist. 5264432Seric ** 5274432Seric ** Returns: 5284432Seric ** none 5294432Seric ** 5304432Seric ** Side Effects: 5314432Seric ** 5324432Seric ** puts all lines in filename that match a scanf into 5334432Seric ** the named class. 5344432Seric */ 5354432Seric 53664133Seric fileclass(class, filename, fmt, safe, optional) 5374432Seric int class; 5384432Seric char *filename; 5394432Seric char *fmt; 54054973Seric bool safe; 54164133Seric bool optional; 5424432Seric { 54325808Seric FILE *f; 54454973Seric struct stat stbuf; 5454432Seric char buf[MAXLINE]; 5464432Seric 54754973Seric if (stat(filename, &stbuf) < 0) 54854973Seric { 54964133Seric if (!optional) 55064133Seric syserr("fileclass: cannot stat %s", filename); 55154973Seric return; 55254973Seric } 55354973Seric if (!S_ISREG(stbuf.st_mode)) 55454973Seric { 55554973Seric syserr("fileclass: %s not a regular file", filename); 55654973Seric return; 55754973Seric } 55854973Seric if (!safe && access(filename, R_OK) < 0) 55954973Seric { 56054973Seric syserr("fileclass: access denied on %s", filename); 56154973Seric return; 56254973Seric } 56354973Seric f = fopen(filename, "r"); 5644432Seric if (f == NULL) 5654432Seric { 56654973Seric syserr("fileclass: cannot open %s", filename); 5674432Seric return; 5684432Seric } 5694432Seric 5704432Seric while (fgets(buf, sizeof buf, f) != NULL) 5714432Seric { 5724432Seric register STAB *s; 57325808Seric register char *p; 57425808Seric # ifdef SCANF 5754432Seric char wordbuf[MAXNAME+1]; 5764432Seric 5774432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5784432Seric continue; 57925808Seric p = wordbuf; 58056795Seric # else /* SCANF */ 58125808Seric p = buf; 58256795Seric # endif /* SCANF */ 58325808Seric 58425808Seric /* 58525808Seric ** Break up the match into words. 58625808Seric */ 58725808Seric 58825808Seric while (*p != '\0') 58925808Seric { 59025808Seric register char *q; 59125808Seric 59225808Seric /* strip leading spaces */ 59358050Seric while (isascii(*p) && isspace(*p)) 59425808Seric p++; 59525808Seric if (*p == '\0') 59625808Seric break; 59725808Seric 59825808Seric /* find the end of the word */ 59925808Seric q = p; 60058050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 60125808Seric p++; 60225808Seric if (*p != '\0') 60325808Seric *p++ = '\0'; 60425808Seric 60525808Seric /* enter the word in the symbol table */ 60625808Seric s = stab(q, ST_CLASS, ST_ENTER); 60725808Seric setbitn(class, s->s_class); 60825808Seric } 6094432Seric } 6104432Seric 61154973Seric (void) fclose(f); 6124432Seric } 6134432Seric /* 6144096Seric ** MAKEMAILER -- define a new mailer. 6154096Seric ** 6164096Seric ** Parameters: 61710327Seric ** line -- description of mailer. This is in labeled 61810327Seric ** fields. The fields are: 61910327Seric ** P -- the path to the mailer 62010327Seric ** F -- the flags associated with the mailer 62110327Seric ** A -- the argv for this mailer 62210327Seric ** S -- the sender rewriting set 62310327Seric ** R -- the recipient rewriting set 62410327Seric ** E -- the eol string 62510327Seric ** The first word is the canonical name of the mailer. 6264096Seric ** 6274096Seric ** Returns: 6284096Seric ** none. 6294096Seric ** 6304096Seric ** Side Effects: 6314096Seric ** enters the mailer into the mailer table. 6324096Seric */ 6333308Seric 63421066Seric makemailer(line) 6354096Seric char *line; 6364096Seric { 6374096Seric register char *p; 6388067Seric register struct mailer *m; 6398067Seric register STAB *s; 6408067Seric int i; 64110327Seric char fcode; 64258020Seric auto char *endp; 6434096Seric extern int NextMailer; 64410327Seric extern char **makeargv(); 64510327Seric extern char *munchstring(); 64610701Seric extern long atol(); 6474096Seric 64810327Seric /* allocate a mailer and set up defaults */ 64910327Seric m = (struct mailer *) xalloc(sizeof *m); 65010327Seric bzero((char *) m, sizeof *m); 65110327Seric m->m_eol = "\n"; 65210327Seric 65310327Seric /* collect the mailer name */ 65458050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 65510327Seric continue; 65610327Seric if (*p != '\0') 65710327Seric *p++ = '\0'; 65810327Seric m->m_name = newstr(line); 65910327Seric 66010327Seric /* now scan through and assign info from the fields */ 66110327Seric while (*p != '\0') 66210327Seric { 66358333Seric auto char *delimptr; 66458333Seric 66558050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 66610327Seric p++; 66710327Seric 66810327Seric /* p now points to field code */ 66910327Seric fcode = *p; 67010327Seric while (*p != '\0' && *p != '=' && *p != ',') 67110327Seric p++; 67210327Seric if (*p++ != '=') 67310327Seric { 67452637Seric syserr("mailer %s: `=' expected", m->m_name); 67510327Seric return; 67610327Seric } 67758050Seric while (isascii(*p) && isspace(*p)) 67810327Seric p++; 67910327Seric 68010327Seric /* p now points to the field body */ 68158333Seric p = munchstring(p, &delimptr); 68210327Seric 68310327Seric /* install the field into the mailer struct */ 68410327Seric switch (fcode) 68510327Seric { 68610327Seric case 'P': /* pathname */ 68710327Seric m->m_mailer = newstr(p); 68810327Seric break; 68910327Seric 69010327Seric case 'F': /* flags */ 69110687Seric for (; *p != '\0'; p++) 69258050Seric if (!(isascii(*p) && isspace(*p))) 69352637Seric setbitn(*p, m->m_flags); 69410327Seric break; 69510327Seric 69610327Seric case 'S': /* sender rewriting ruleset */ 69710327Seric case 'R': /* recipient rewriting ruleset */ 69858020Seric i = strtol(p, &endp, 10); 69910327Seric if (i < 0 || i >= MAXRWSETS) 70010327Seric { 70110327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 70210327Seric return; 70310327Seric } 70410327Seric if (fcode == 'S') 70558020Seric m->m_sh_rwset = m->m_se_rwset = i; 70610327Seric else 70758020Seric m->m_rh_rwset = m->m_re_rwset = i; 70858020Seric 70958020Seric p = endp; 71059985Seric if (*p++ == '/') 71158020Seric { 71258020Seric i = strtol(p, NULL, 10); 71358020Seric if (i < 0 || i >= MAXRWSETS) 71458020Seric { 71558020Seric syserr("invalid rewrite set, %d max", 71658020Seric MAXRWSETS); 71758020Seric return; 71858020Seric } 71958020Seric if (fcode == 'S') 72058020Seric m->m_sh_rwset = i; 72158020Seric else 72258020Seric m->m_rh_rwset = i; 72358020Seric } 72410327Seric break; 72510327Seric 72610327Seric case 'E': /* end of line string */ 72710327Seric m->m_eol = newstr(p); 72810327Seric break; 72910327Seric 73010327Seric case 'A': /* argument vector */ 73110327Seric m->m_argv = makeargv(p); 73210327Seric break; 73310701Seric 73410701Seric case 'M': /* maximum message size */ 73510701Seric m->m_maxsize = atol(p); 73610701Seric break; 73752106Seric 73852106Seric case 'L': /* maximum line length */ 73952106Seric m->m_linelimit = atoi(p); 74052106Seric break; 74158935Seric 74258935Seric case 'D': /* working directory */ 74358935Seric m->m_execdir = newstr(p); 74458935Seric break; 74510327Seric } 74610327Seric 74758333Seric p = delimptr; 74810327Seric } 74910327Seric 75052106Seric /* do some heuristic cleanup for back compatibility */ 75152106Seric if (bitnset(M_LIMITS, m->m_flags)) 75252106Seric { 75352106Seric if (m->m_linelimit == 0) 75452106Seric m->m_linelimit = SMTPLINELIM; 75555418Seric if (ConfigLevel < 2) 75652106Seric setbitn(M_7BITS, m->m_flags); 75752106Seric } 75852106Seric 75958321Seric /* do some rationality checking */ 76058321Seric if (m->m_argv == NULL) 76158321Seric { 76258321Seric syserr("M%s: A= argument required", m->m_name); 76358321Seric return; 76458321Seric } 76558321Seric if (m->m_mailer == NULL) 76658321Seric { 76758321Seric syserr("M%s: P= argument required", m->m_name); 76858321Seric return; 76958321Seric } 77058321Seric 7714096Seric if (NextMailer >= MAXMAILERS) 7724096Seric { 7739381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7744096Seric return; 7754096Seric } 77657402Seric 77710327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 77857402Seric if (s->s_mailer != NULL) 77957402Seric { 78057402Seric i = s->s_mailer->m_mno; 78157402Seric free(s->s_mailer); 78257402Seric } 78357402Seric else 78457402Seric { 78557402Seric i = NextMailer++; 78657402Seric } 78757402Seric Mailer[i] = s->s_mailer = m; 78857454Seric m->m_mno = i; 78910327Seric } 79010327Seric /* 79110327Seric ** MUNCHSTRING -- translate a string into internal form. 79210327Seric ** 79310327Seric ** Parameters: 79410327Seric ** p -- the string to munch. 79558333Seric ** delimptr -- if non-NULL, set to the pointer of the 79658333Seric ** field delimiter character. 79710327Seric ** 79810327Seric ** Returns: 79910327Seric ** the munched string. 80010327Seric */ 8014096Seric 80210327Seric char * 80358333Seric munchstring(p, delimptr) 80410327Seric register char *p; 80558333Seric char **delimptr; 80610327Seric { 80710327Seric register char *q; 80810327Seric bool backslash = FALSE; 80910327Seric bool quotemode = FALSE; 81010327Seric static char buf[MAXLINE]; 8114096Seric 81210327Seric for (q = buf; *p != '\0'; p++) 8134096Seric { 81410327Seric if (backslash) 81510327Seric { 81610327Seric /* everything is roughly literal */ 81710357Seric backslash = FALSE; 81810327Seric switch (*p) 81910327Seric { 82010327Seric case 'r': /* carriage return */ 82110327Seric *q++ = '\r'; 82210327Seric continue; 82310327Seric 82410327Seric case 'n': /* newline */ 82510327Seric *q++ = '\n'; 82610327Seric continue; 82710327Seric 82810327Seric case 'f': /* form feed */ 82910327Seric *q++ = '\f'; 83010327Seric continue; 83110327Seric 83210327Seric case 'b': /* backspace */ 83310327Seric *q++ = '\b'; 83410327Seric continue; 83510327Seric } 83610327Seric *q++ = *p; 83710327Seric } 83810327Seric else 83910327Seric { 84010327Seric if (*p == '\\') 84110327Seric backslash = TRUE; 84210327Seric else if (*p == '"') 84310327Seric quotemode = !quotemode; 84410327Seric else if (quotemode || *p != ',') 84510327Seric *q++ = *p; 84610327Seric else 84710327Seric break; 84810327Seric } 8494096Seric } 8504096Seric 85158333Seric if (delimptr != NULL) 85258333Seric *delimptr = p; 85310327Seric *q++ = '\0'; 85410327Seric return (buf); 85510327Seric } 85610327Seric /* 85710327Seric ** MAKEARGV -- break up a string into words 85810327Seric ** 85910327Seric ** Parameters: 86010327Seric ** p -- the string to break up. 86110327Seric ** 86210327Seric ** Returns: 86310327Seric ** a char **argv (dynamically allocated) 86410327Seric ** 86510327Seric ** Side Effects: 86610327Seric ** munges p. 86710327Seric */ 8684096Seric 86910327Seric char ** 87010327Seric makeargv(p) 87110327Seric register char *p; 87210327Seric { 87310327Seric char *q; 87410327Seric int i; 87510327Seric char **avp; 87610327Seric char *argv[MAXPV + 1]; 87710327Seric 87810327Seric /* take apart the words */ 87910327Seric i = 0; 88010327Seric while (*p != '\0' && i < MAXPV) 8814096Seric { 88210327Seric q = p; 88358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 88410327Seric p++; 88558050Seric while (isascii(*p) && isspace(*p)) 88610327Seric *p++ = '\0'; 88710327Seric argv[i++] = newstr(q); 8884096Seric } 88910327Seric argv[i++] = NULL; 8904096Seric 89110327Seric /* now make a copy of the argv */ 89210327Seric avp = (char **) xalloc(sizeof *avp * i); 89316893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 89410327Seric 89510327Seric return (avp); 8963308Seric } 8973308Seric /* 8983308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8993308Seric ** 9003308Seric ** Parameters: 9013308Seric ** none. 9023308Seric ** 9033308Seric ** Returns: 9043308Seric ** none. 9053308Seric ** 9063308Seric ** Side Effects: 9073308Seric ** prints rewrite rules. 9083308Seric */ 9093308Seric 9103308Seric printrules() 9113308Seric { 9123308Seric register struct rewrite *rwp; 9134072Seric register int ruleset; 9143308Seric 9154072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9163308Seric { 9174072Seric if (RewriteRules[ruleset] == NULL) 9184072Seric continue; 9198067Seric printf("\n----Rule Set %d:", ruleset); 9203308Seric 9214072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9223308Seric { 9238067Seric printf("\nLHS:"); 9248067Seric printav(rwp->r_lhs); 9258067Seric printf("RHS:"); 9268067Seric printav(rwp->r_rhs); 9273308Seric } 9283308Seric } 9293308Seric } 9304319Seric 9314096Seric /* 9328256Seric ** SETOPTION -- set global processing option 9338256Seric ** 9348256Seric ** Parameters: 9358256Seric ** opt -- option name. 9368256Seric ** val -- option value (as a text string). 93721755Seric ** safe -- set if this came from a configuration file. 93821755Seric ** Some options (if set from the command line) will 93921755Seric ** reset the user id to avoid security problems. 9408269Seric ** sticky -- if set, don't let other setoptions override 9418269Seric ** this value. 94258734Seric ** e -- the main envelope. 9438256Seric ** 9448256Seric ** Returns: 9458256Seric ** none. 9468256Seric ** 9478256Seric ** Side Effects: 9488256Seric ** Sets options as implied by the arguments. 9498256Seric */ 9508256Seric 95110687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9528269Seric 95357207Seric 95457207Seric #ifdef NAMED_BIND 95557207Seric 95657207Seric struct resolverflags 95757207Seric { 95857207Seric char *rf_name; /* name of the flag */ 95957207Seric long rf_bits; /* bits to set/clear */ 96057207Seric } ResolverFlags[] = 96157207Seric { 96257207Seric "debug", RES_DEBUG, 96357207Seric "aaonly", RES_AAONLY, 96457207Seric "usevc", RES_USEVC, 96557207Seric "primary", RES_PRIMARY, 96657207Seric "igntc", RES_IGNTC, 96757207Seric "recurse", RES_RECURSE, 96857207Seric "defnames", RES_DEFNAMES, 96957207Seric "stayopen", RES_STAYOPEN, 97057207Seric "dnsrch", RES_DNSRCH, 97157207Seric NULL, 0 97257207Seric }; 97357207Seric 97457207Seric #endif 97557207Seric 97658734Seric setoption(opt, val, safe, sticky, e) 9778256Seric char opt; 9788256Seric char *val; 97921755Seric bool safe; 9808269Seric bool sticky; 98158734Seric register ENVELOPE *e; 9828256Seric { 98357207Seric register char *p; 9848265Seric extern bool atobool(); 98512633Seric extern time_t convtime(); 98614879Seric extern int QueueLA; 98714879Seric extern int RefuseLA; 98817474Seric extern bool trusteduser(); 9898256Seric 9908256Seric if (tTd(37, 1)) 9919341Seric printf("setoption %c=%s", opt, val); 9928256Seric 9938256Seric /* 9948269Seric ** See if this option is preset for us. 9958256Seric */ 9968256Seric 99759731Seric if (!sticky && bitnset(opt, StickyOpt)) 9988269Seric { 9999341Seric if (tTd(37, 1)) 10009341Seric printf(" (ignored)\n"); 10018269Seric return; 10028269Seric } 10038269Seric 100421755Seric /* 100521755Seric ** Check to see if this option can be specified by this user. 100621755Seric */ 100721755Seric 100863787Seric if (!safe && RealUid == 0) 100921755Seric safe = TRUE; 101063837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 101121755Seric { 101239111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 101321755Seric { 101436582Sbostic if (tTd(37, 1)) 101536582Sbostic printf(" (unsafe)"); 101663787Seric if (RealUid != geteuid()) 101736582Sbostic { 101851210Seric if (tTd(37, 1)) 101951210Seric printf("(Resetting uid)"); 102063787Seric (void) setgid(RealGid); 102163787Seric (void) setuid(RealUid); 102236582Sbostic } 102321755Seric } 102421755Seric } 102551210Seric if (tTd(37, 1)) 102617985Seric printf("\n"); 10278269Seric 10288256Seric switch (opt) 10298256Seric { 103059709Seric case '7': /* force seven-bit input */ 103159709Seric SevenBit = atobool(val); 103252106Seric break; 103352106Seric 10348256Seric case 'A': /* set default alias file */ 10359381Seric if (val[0] == '\0') 103659672Seric setalias("aliases"); 10379381Seric else 103859672Seric setalias(val); 10398256Seric break; 10408256Seric 104117474Seric case 'a': /* look N minutes for "@:@" in alias file */ 104217474Seric if (val[0] == '\0') 104317474Seric SafeAlias = 5; 104417474Seric else 104517474Seric SafeAlias = atoi(val); 104617474Seric break; 104717474Seric 104816843Seric case 'B': /* substitution for blank character */ 104916843Seric SpaceSub = val[0]; 105016843Seric if (SpaceSub == '\0') 105116843Seric SpaceSub = ' '; 105216843Seric break; 105316843Seric 105459283Seric case 'b': /* min blocks free on queue fs/max msg size */ 105559283Seric p = strchr(val, '/'); 105659283Seric if (p != NULL) 105759283Seric { 105859283Seric *p++ = '\0'; 105959283Seric MaxMessageSize = atol(p); 106059283Seric } 106158082Seric MinBlocksFree = atol(val); 106258082Seric break; 106358082Seric 10649284Seric case 'c': /* don't connect to "expensive" mailers */ 10659381Seric NoConnect = atobool(val); 10669284Seric break; 10679284Seric 106851305Seric case 'C': /* checkpoint every N addresses */ 106951305Seric CheckpointInterval = atoi(val); 107024944Seric break; 107124944Seric 10729284Seric case 'd': /* delivery mode */ 10739284Seric switch (*val) 10748269Seric { 10759284Seric case '\0': 107658734Seric e->e_sendmode = SM_DELIVER; 10778269Seric break; 10788269Seric 107910755Seric case SM_QUEUE: /* queue only */ 108010755Seric #ifndef QUEUE 108110755Seric syserr("need QUEUE to set -odqueue"); 108256795Seric #endif /* QUEUE */ 108310755Seric /* fall through..... */ 108410755Seric 10859284Seric case SM_DELIVER: /* do everything */ 10869284Seric case SM_FORK: /* fork after verification */ 108758734Seric e->e_sendmode = *val; 10888269Seric break; 10898269Seric 10908269Seric default: 10919284Seric syserr("Unknown delivery mode %c", *val); 10928269Seric exit(EX_USAGE); 10938269Seric } 10948269Seric break; 10958269Seric 10969146Seric case 'D': /* rebuild alias database as needed */ 10979381Seric AutoRebuild = atobool(val); 10989146Seric break; 10999146Seric 110055372Seric case 'E': /* error message header/header file */ 110155379Seric if (*val != '\0') 110255379Seric ErrMsgFile = newstr(val); 110355372Seric break; 110455372Seric 11058269Seric case 'e': /* set error processing mode */ 11068269Seric switch (*val) 11078269Seric { 11089381Seric case EM_QUIET: /* be silent about it */ 11099381Seric case EM_MAIL: /* mail back */ 11109381Seric case EM_BERKNET: /* do berknet error processing */ 11119381Seric case EM_WRITE: /* write back (or mail) */ 11128269Seric HoldErrs = TRUE; 11139381Seric /* fall through... */ 11148269Seric 11159381Seric case EM_PRINT: /* print errors normally (default) */ 111658734Seric e->e_errormode = *val; 11178269Seric break; 11188269Seric } 11198269Seric break; 11208269Seric 11219049Seric case 'F': /* file mode */ 112217975Seric FileMode = atooct(val) & 0777; 11239049Seric break; 11249049Seric 11258269Seric case 'f': /* save Unix-style From lines on front */ 11269381Seric SaveFrom = atobool(val); 11278269Seric break; 11288269Seric 112953735Seric case 'G': /* match recipients against GECOS field */ 113053735Seric MatchGecos = atobool(val); 113153735Seric break; 113253735Seric 11338256Seric case 'g': /* default gid */ 113464133Seric if (isascii(*val) && isdigit(*val)) 113564133Seric DefGid = atoi(val); 113664133Seric else 113764133Seric { 113864133Seric register struct group *gr; 113964133Seric 114064133Seric DefGid = -1; 114164133Seric gr = getgrnam(val); 114264133Seric if (gr == NULL) 114364133Seric syserr("readcf: option g: unknown group %s", val); 114464133Seric else 114564133Seric DefGid = gr->gr_gid; 114664133Seric } 11478256Seric break; 11488256Seric 11498256Seric case 'H': /* help file */ 11509381Seric if (val[0] == '\0') 11518269Seric HelpFile = "sendmail.hf"; 11529381Seric else 11539381Seric HelpFile = newstr(val); 11548256Seric break; 11558256Seric 115651305Seric case 'h': /* maximum hop count */ 115751305Seric MaxHopCount = atoi(val); 115851305Seric break; 115951305Seric 116035651Seric case 'I': /* use internet domain name server */ 116157207Seric #ifdef NAMED_BIND 116257207Seric UseNameServer = TRUE; 116357207Seric for (p = val; *p != 0; ) 116457207Seric { 116557207Seric bool clearmode; 116657207Seric char *q; 116757207Seric struct resolverflags *rfp; 116857207Seric 116957207Seric while (*p == ' ') 117057207Seric p++; 117157207Seric if (*p == '\0') 117257207Seric break; 117357207Seric clearmode = FALSE; 117457207Seric if (*p == '-') 117557207Seric clearmode = TRUE; 117657207Seric else if (*p != '+') 117757207Seric p--; 117857207Seric p++; 117957207Seric q = p; 118058050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 118157207Seric p++; 118257207Seric if (*p != '\0') 118357207Seric *p++ = '\0'; 118457207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 118557207Seric { 118657207Seric if (strcasecmp(q, rfp->rf_name) == 0) 118757207Seric break; 118857207Seric } 118957207Seric if (clearmode) 119057207Seric _res.options &= ~rfp->rf_bits; 119157207Seric else 119257207Seric _res.options |= rfp->rf_bits; 119357207Seric } 119457207Seric if (tTd(8, 2)) 119557207Seric printf("_res.options = %x\n", _res.options); 119657207Seric #else 119757207Seric usrerr("name server (I option) specified but BIND not compiled in"); 119857207Seric #endif 119935651Seric break; 120035651Seric 12018269Seric case 'i': /* ignore dot lines in message */ 12029381Seric IgnrDot = atobool(val); 12038269Seric break; 12048269Seric 120559730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 120659730Seric SendMIMEErrors = atobool(val); 120759730Seric break; 120859730Seric 120957136Seric case 'J': /* .forward search path */ 121057136Seric ForwardPath = newstr(val); 121157136Seric break; 121257136Seric 121354967Seric case 'k': /* connection cache size */ 121454967Seric MaxMciCache = atoi(val); 121556215Seric if (MaxMciCache < 0) 121656215Seric MaxMciCache = 0; 121754967Seric break; 121854967Seric 121954967Seric case 'K': /* connection cache timeout */ 122058796Seric MciCacheTimeout = convtime(val, 'm'); 122154967Seric break; 122254967Seric 122361104Seric case 'l': /* use Errors-To: header */ 122461104Seric UseErrorsTo = atobool(val); 122561104Seric break; 122661104Seric 12278256Seric case 'L': /* log level */ 122864140Seric if (safe || LogLevel < atoi(val)) 122964140Seric LogLevel = atoi(val); 12308256Seric break; 12318256Seric 12328269Seric case 'M': /* define macro */ 12339381Seric define(val[0], newstr(&val[1]), CurEnv); 123416878Seric sticky = FALSE; 12358269Seric break; 12368269Seric 12378269Seric case 'm': /* send to me too */ 12389381Seric MeToo = atobool(val); 12398269Seric break; 12408269Seric 124125820Seric case 'n': /* validate RHS in newaliases */ 124225820Seric CheckAliases = atobool(val); 124325820Seric break; 124425820Seric 124561104Seric /* 'N' available -- was "net name" */ 124661104Seric 124758851Seric case 'O': /* daemon options */ 124858851Seric setdaemonoptions(val); 124958851Seric break; 125058851Seric 12518269Seric case 'o': /* assume old style headers */ 12529381Seric if (atobool(val)) 12539341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12549341Seric else 12559341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12568269Seric break; 12578269Seric 125858082Seric case 'p': /* select privacy level */ 125958082Seric p = val; 126058082Seric for (;;) 126158082Seric { 126258082Seric register struct prival *pv; 126358082Seric extern struct prival PrivacyValues[]; 126458082Seric 126558082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 126658082Seric p++; 126758082Seric if (*p == '\0') 126858082Seric break; 126958082Seric val = p; 127058082Seric while (isascii(*p) && isalnum(*p)) 127158082Seric p++; 127258082Seric if (*p != '\0') 127358082Seric *p++ = '\0'; 127458082Seric 127558082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 127658082Seric { 127758082Seric if (strcasecmp(val, pv->pv_name) == 0) 127858082Seric break; 127958082Seric } 128058886Seric if (pv->pv_name == NULL) 128158886Seric syserr("readcf: Op line: %s unrecognized", val); 128258082Seric PrivacyFlags |= pv->pv_flag; 128358082Seric } 128458082Seric break; 128558082Seric 128624944Seric case 'P': /* postmaster copy address for returned mail */ 128724944Seric PostMasterCopy = newstr(val); 128824944Seric break; 128924944Seric 129024944Seric case 'q': /* slope of queue only function */ 129124944Seric QueueFactor = atoi(val); 129224944Seric break; 129324944Seric 12948256Seric case 'Q': /* queue directory */ 12959381Seric if (val[0] == '\0') 12968269Seric QueueDir = "mqueue"; 12979381Seric else 12989381Seric QueueDir = newstr(val); 129958789Seric if (RealUid != 0 && !safe) 130058789Seric auth_warning(e, "Processed from queue %s", QueueDir); 13018256Seric break; 13028256Seric 130358148Seric case 'R': /* don't prune routes */ 130458148Seric DontPruneRoutes = atobool(val); 130558148Seric break; 130658148Seric 13078256Seric case 'r': /* read timeout */ 130858112Seric settimeouts(val); 13098256Seric break; 13108256Seric 13118256Seric case 'S': /* status file */ 13129381Seric if (val[0] == '\0') 13138269Seric StatFile = "sendmail.st"; 13149381Seric else 13159381Seric StatFile = newstr(val); 13168256Seric break; 13178256Seric 13188265Seric case 's': /* be super safe, even if expensive */ 13199381Seric SuperSafe = atobool(val); 13208256Seric break; 13218256Seric 13228256Seric case 'T': /* queue timeout */ 132358737Seric p = strchr(val, '/'); 132458737Seric if (p != NULL) 132558737Seric { 132658737Seric *p++ = '\0'; 132758796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 132858737Seric } 132958796Seric TimeOuts.to_q_return = convtime(val, 'h'); 133054967Seric break; 13318256Seric 13328265Seric case 't': /* time zone name */ 133352106Seric TimeZoneSpec = newstr(val); 13348265Seric break; 13358265Seric 133650556Seric case 'U': /* location of user database */ 133751360Seric UdbSpec = newstr(val); 133850556Seric break; 133950556Seric 13408256Seric case 'u': /* set default uid */ 134164133Seric if (isascii(*val) && isdigit(*val)) 134264133Seric DefUid = atoi(val); 134364133Seric else 134464133Seric { 134564133Seric register struct passwd *pw; 134664133Seric 134764133Seric DefUid = -1; 134864133Seric pw = getpwnam(val); 134964133Seric if (pw == NULL) 135064133Seric syserr("readcf: option u: unknown user %s", val); 135164133Seric else 135264133Seric DefUid = pw->pw_uid; 135364133Seric } 135440973Sbostic setdefuser(); 13558256Seric break; 13568256Seric 135758851Seric case 'V': /* fallback MX host */ 135858851Seric FallBackMX = newstr(val); 135958851Seric break; 136058851Seric 13618269Seric case 'v': /* run in verbose mode */ 13629381Seric Verbose = atobool(val); 13638256Seric break; 13648256Seric 136563837Seric case 'w': /* if we are best MX, try host directly */ 136663837Seric TryNullMXList = atobool(val); 136763837Seric break; 136861104Seric 136961104Seric /* 'W' available -- was wizard password */ 137061104Seric 137114879Seric case 'x': /* load avg at which to auto-queue msgs */ 137214879Seric QueueLA = atoi(val); 137314879Seric break; 137414879Seric 137514879Seric case 'X': /* load avg at which to auto-reject connections */ 137614879Seric RefuseLA = atoi(val); 137714879Seric break; 137814879Seric 137924981Seric case 'y': /* work recipient factor */ 138024981Seric WkRecipFact = atoi(val); 138124981Seric break; 138224981Seric 138324981Seric case 'Y': /* fork jobs during queue runs */ 138424952Seric ForkQueueRuns = atobool(val); 138524952Seric break; 138624952Seric 138724981Seric case 'z': /* work message class factor */ 138824981Seric WkClassFact = atoi(val); 138924981Seric break; 139024981Seric 139124981Seric case 'Z': /* work time factor */ 139224981Seric WkTimeFact = atoi(val); 139324981Seric break; 139424981Seric 13958256Seric default: 13968256Seric break; 13978256Seric } 139816878Seric if (sticky) 139916878Seric setbitn(opt, StickyOpt); 14009188Seric return; 14018256Seric } 140210687Seric /* 140310687Seric ** SETCLASS -- set a word into a class 140410687Seric ** 140510687Seric ** Parameters: 140610687Seric ** class -- the class to put the word in. 140710687Seric ** word -- the word to enter 140810687Seric ** 140910687Seric ** Returns: 141010687Seric ** none. 141110687Seric ** 141210687Seric ** Side Effects: 141310687Seric ** puts the word into the symbol table. 141410687Seric */ 141510687Seric 141610687Seric setclass(class, word) 141710687Seric int class; 141810687Seric char *word; 141910687Seric { 142010687Seric register STAB *s; 142110687Seric 142257943Seric if (tTd(37, 8)) 142357943Seric printf("%s added to class %c\n", word, class); 142410687Seric s = stab(word, ST_CLASS, ST_ENTER); 142510687Seric setbitn(class, s->s_class); 142610687Seric } 142753654Seric /* 142853654Seric ** MAKEMAPENTRY -- create a map entry 142953654Seric ** 143053654Seric ** Parameters: 143153654Seric ** line -- the config file line 143253654Seric ** 143353654Seric ** Returns: 143453654Seric ** TRUE if it successfully entered the map entry. 143553654Seric ** FALSE otherwise (usually syntax error). 143653654Seric ** 143753654Seric ** Side Effects: 143853654Seric ** Enters the map into the dictionary. 143953654Seric */ 144053654Seric 144153654Seric void 144253654Seric makemapentry(line) 144353654Seric char *line; 144453654Seric { 144553654Seric register char *p; 144653654Seric char *mapname; 144753654Seric char *classname; 144864078Seric register STAB *s; 144953654Seric STAB *class; 145053654Seric 145158050Seric for (p = line; isascii(*p) && isspace(*p); p++) 145253654Seric continue; 145358050Seric if (!(isascii(*p) && isalnum(*p))) 145453654Seric { 145553654Seric syserr("readcf: config K line: no map name"); 145653654Seric return; 145753654Seric } 145853654Seric 145953654Seric mapname = p; 146058050Seric while (isascii(*++p) && isalnum(*p)) 146153654Seric continue; 146253654Seric if (*p != '\0') 146353654Seric *p++ = '\0'; 146458050Seric while (isascii(*p) && isspace(*p)) 146553654Seric p++; 146658050Seric if (!(isascii(*p) && isalnum(*p))) 146753654Seric { 146853654Seric syserr("readcf: config K line, map %s: no map class", mapname); 146953654Seric return; 147053654Seric } 147153654Seric classname = p; 147258050Seric while (isascii(*++p) && isalnum(*p)) 147353654Seric continue; 147453654Seric if (*p != '\0') 147553654Seric *p++ = '\0'; 147658050Seric while (isascii(*p) && isspace(*p)) 147753654Seric p++; 147853654Seric 147953654Seric /* look up the class */ 148053654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 148153654Seric if (class == NULL) 148253654Seric { 148353654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 148453654Seric return; 148553654Seric } 148653654Seric 148753654Seric /* enter the map */ 148864078Seric s = stab(mapname, ST_MAP, ST_ENTER); 148964078Seric s->s_map.map_class = &class->s_mapclass; 149064078Seric s->s_map.map_mname = newstr(mapname); 149153654Seric 149264078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 149364078Seric s->s_map.map_mflags |= MF_VALID; 149464078Seric 149564078Seric if (tTd(37, 5)) 149664078Seric { 149764078Seric printf("map %s, class %s, flags %x, file %s,\n", 149864078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 149964078Seric s->s_map.map_mflags, 150064078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 150164078Seric printf("\tapp %s, domain %s, rebuild %s\n", 150264078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 150364078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 150464078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 150564078Seric } 150653654Seric } 150758112Seric /* 150858112Seric ** SETTIMEOUTS -- parse and set timeout values 150958112Seric ** 151058112Seric ** Parameters: 151158112Seric ** val -- a pointer to the values. If NULL, do initial 151258112Seric ** settings. 151358112Seric ** 151458112Seric ** Returns: 151558112Seric ** none. 151658112Seric ** 151758112Seric ** Side Effects: 151858112Seric ** Initializes the TimeOuts structure 151958112Seric */ 152058112Seric 152164255Seric #define SECONDS 152258112Seric #define MINUTES * 60 152358112Seric #define HOUR * 3600 152458112Seric 152558112Seric settimeouts(val) 152658112Seric register char *val; 152758112Seric { 152858112Seric register char *p; 152958671Seric extern time_t convtime(); 153058112Seric 153158112Seric if (val == NULL) 153258112Seric { 153358112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 153458112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 153558112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 153658112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 153758112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 153858112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 153958112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 154058112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 154158112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 154258112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 154358112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 154464255Seric TimeOuts.to_ident = (time_t) 30 SECONDS; 154558112Seric return; 154658112Seric } 154758112Seric 154858112Seric for (;; val = p) 154958112Seric { 155058112Seric while (isascii(*val) && isspace(*val)) 155158112Seric val++; 155258112Seric if (*val == '\0') 155358112Seric break; 155458112Seric for (p = val; *p != '\0' && *p != ','; p++) 155558112Seric continue; 155658112Seric if (*p != '\0') 155758112Seric *p++ = '\0'; 155858112Seric 155958112Seric if (isascii(*val) && isdigit(*val)) 156058112Seric { 156158112Seric /* old syntax -- set everything */ 156258796Seric TimeOuts.to_mail = convtime(val, 'm'); 156358112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 156458112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 156558112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 156658112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 156758112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 156858112Seric continue; 156958112Seric } 157058112Seric else 157158112Seric { 157258112Seric register char *q = strchr(val, '='); 157358112Seric time_t to; 157458112Seric 157558112Seric if (q == NULL) 157658112Seric { 157758112Seric /* syntax error */ 157858112Seric continue; 157958112Seric } 158058112Seric *q++ = '\0'; 158158796Seric to = convtime(q, 'm'); 158258112Seric 158358112Seric if (strcasecmp(val, "initial") == 0) 158458112Seric TimeOuts.to_initial = to; 158558112Seric else if (strcasecmp(val, "mail") == 0) 158658112Seric TimeOuts.to_mail = to; 158758112Seric else if (strcasecmp(val, "rcpt") == 0) 158858112Seric TimeOuts.to_rcpt = to; 158958112Seric else if (strcasecmp(val, "datainit") == 0) 159058112Seric TimeOuts.to_datainit = to; 159158112Seric else if (strcasecmp(val, "datablock") == 0) 159258112Seric TimeOuts.to_datablock = to; 159358112Seric else if (strcasecmp(val, "datafinal") == 0) 159458112Seric TimeOuts.to_datafinal = to; 159558112Seric else if (strcasecmp(val, "command") == 0) 159658112Seric TimeOuts.to_nextcommand = to; 159758112Seric else if (strcasecmp(val, "rset") == 0) 159858112Seric TimeOuts.to_rset = to; 159958112Seric else if (strcasecmp(val, "helo") == 0) 160058112Seric TimeOuts.to_helo = to; 160158112Seric else if (strcasecmp(val, "quit") == 0) 160258112Seric TimeOuts.to_quit = to; 160358112Seric else if (strcasecmp(val, "misc") == 0) 160458112Seric TimeOuts.to_miscshort = to; 160564255Seric else if (strcasecmp(val, "ident") == 0) 160664255Seric TimeOuts.to_ident = to; 160758112Seric else 160858112Seric syserr("settimeouts: invalid timeout %s", val); 160958112Seric } 161058112Seric } 161158112Seric } 1612