122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822709Sdist 922709Sdist #ifndef lint 10*60538Seric static char sccsid[] = "@(#)readcf.c 6.41 (Berkeley) 05/28/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1457207Seric #ifdef NAMED_BIND 1557207Seric # include <arpa/nameser.h> 1657207Seric # include <resolv.h> 1757207Seric #endif 183308Seric 193308Seric /* 203308Seric ** READCF -- read control file. 213308Seric ** 223308Seric ** This routine reads the control file and builds the internal 233308Seric ** form. 243308Seric ** 254432Seric ** The file is formatted as a sequence of lines, each taken 264432Seric ** atomically. The first character of each line describes how 274432Seric ** the line is to be interpreted. The lines are: 284432Seric ** Dxval Define macro x to have value val. 294432Seric ** Cxword Put word into class x. 304432Seric ** Fxfile [fmt] Read file for lines to put into 314432Seric ** class x. Use scanf string 'fmt' 324432Seric ** or "%s" if not present. Fmt should 334432Seric ** only produce one string-valued result. 344432Seric ** Hname: value Define header with field-name 'name' 354432Seric ** and value as specified; this will be 364432Seric ** macro expanded immediately before 374432Seric ** use. 384432Seric ** Sn Use rewriting set n. 394432Seric ** Rlhs rhs Rewrite addresses that match lhs to 404432Seric ** be rhs. 4124944Seric ** Mn arg=val... Define mailer. n is the internal name. 4224944Seric ** Args specify mailer parameters. 438252Seric ** Oxvalue Set option x to value. 448252Seric ** Pname=value Set precedence name to value. 4552645Seric ** Vversioncode Version level of configuration syntax. 4653654Seric ** Kmapname mapclass arguments.... 4753654Seric ** Define keyed lookup of a given class. 4853654Seric ** Arguments are class dependent. 494432Seric ** 503308Seric ** Parameters: 513308Seric ** cfname -- control file name. 5254973Seric ** safe -- TRUE if this is the system config file; 5354973Seric ** FALSE otherwise. 5455012Seric ** e -- the main envelope. 553308Seric ** 563308Seric ** Returns: 573308Seric ** none. 583308Seric ** 593308Seric ** Side Effects: 603308Seric ** Builds several internal tables. 613308Seric */ 623308Seric 6355012Seric readcf(cfname, safe, e) 643308Seric char *cfname; 6554973Seric bool safe; 6655012Seric register ENVELOPE *e; 673308Seric { 683308Seric FILE *cf; 698547Seric int ruleset = 0; 708547Seric char *q; 718547Seric char **pv; 729350Seric struct rewrite *rwp = NULL; 7357135Seric char *bp; 7457589Seric int nfuzzy; 753308Seric char buf[MAXLINE]; 763308Seric register char *p; 773308Seric extern char **copyplist(); 7852647Seric struct stat statb; 795909Seric char exbuf[MAXLINE]; 8016915Seric char pvpbuf[PSBUFSIZE]; 8110709Seric extern char *munchstring(); 8253654Seric extern void makemapentry(); 833308Seric 8452647Seric FileName = cfname; 8552647Seric LineNumber = 0; 8652647Seric 873308Seric cf = fopen(cfname, "r"); 883308Seric if (cf == NULL) 893308Seric { 9052647Seric syserr("cannot open"); 913308Seric exit(EX_OSFILE); 923308Seric } 933308Seric 9452647Seric if (fstat(fileno(cf), &statb) < 0) 9552647Seric { 9652647Seric syserr("cannot fstat"); 9752647Seric exit(EX_OSFILE); 9852647Seric } 9952647Seric 10052647Seric if (!S_ISREG(statb.st_mode)) 10152647Seric { 10252647Seric syserr("not a plain file"); 10352647Seric exit(EX_OSFILE); 10452647Seric } 10552647Seric 10652647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 10752647Seric { 10853037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 10953037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 11053037Seric FileName); 11153037Seric #ifdef LOG 11253037Seric if (LogLevel > 0) 11353037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 11453037Seric FileName); 11553037Seric #endif 11652647Seric } 11752647Seric 11859254Seric #ifdef XLA 11959254Seric xla_zero(); 12059254Seric #endif 12159254Seric 12257135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1233308Seric { 12457135Seric if (bp[0] == '#') 12557135Seric { 12657135Seric if (bp != buf) 12757135Seric free(bp); 12852637Seric continue; 12957135Seric } 13052637Seric 13158050Seric /* map $ into \201 for macro expansion */ 13257135Seric for (p = bp; *p != '\0'; p++) 13316157Seric { 13457135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 13552647Seric { 13652647Seric /* this is an on-line comment */ 13752647Seric register char *e; 13852647Seric 13958050Seric switch (*--p & 0377) 14052647Seric { 14158050Seric case MACROEXPAND: 14252647Seric /* it's from $# -- let it go through */ 14352647Seric p++; 14452647Seric break; 14552647Seric 14652647Seric case '\\': 14752647Seric /* it's backslash escaped */ 14852647Seric (void) strcpy(p, p + 1); 14952647Seric break; 15052647Seric 15152647Seric default: 15252647Seric /* delete preceeding white space */ 15358050Seric while (isascii(*p) && isspace(*p) && p > bp) 15452647Seric p--; 15556795Seric if ((e = strchr(++p, '\n')) != NULL) 15652647Seric (void) strcpy(p, e); 15752647Seric else 15852647Seric p[0] = p[1] = '\0'; 15952647Seric break; 16052647Seric } 16152647Seric continue; 16252647Seric } 16352647Seric 16416157Seric if (*p != '$') 16516157Seric continue; 16616157Seric 16716157Seric if (p[1] == '$') 16816157Seric { 16916157Seric /* actual dollar sign.... */ 17023111Seric (void) strcpy(p, p + 1); 17116157Seric continue; 17216157Seric } 17316157Seric 17416157Seric /* convert to macro expansion character */ 17558050Seric *p = MACROEXPAND; 17616157Seric } 17716157Seric 17816157Seric /* interpret this line */ 17957135Seric switch (bp[0]) 1803308Seric { 1813308Seric case '\0': 1823308Seric case '#': /* comment */ 1833308Seric break; 1843308Seric 1853308Seric case 'R': /* rewriting rule */ 18657135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1873308Seric continue; 1883308Seric 1893308Seric if (*p == '\0') 1905909Seric { 19157135Seric syserr("invalid rewrite line \"%s\"", bp); 1925909Seric break; 1935909Seric } 1945909Seric 1955909Seric /* allocate space for the rule header */ 1965909Seric if (rwp == NULL) 1975909Seric { 1985909Seric RewriteRules[ruleset] = rwp = 1995909Seric (struct rewrite *) xalloc(sizeof *rwp); 2005909Seric } 2013308Seric else 2023308Seric { 2035909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2045909Seric rwp = rwp->r_next; 2055909Seric } 2065909Seric rwp->r_next = NULL; 2073308Seric 2085909Seric /* expand and save the LHS */ 2095909Seric *p = '\0'; 21057135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 21158333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 21257589Seric nfuzzy = 0; 2135909Seric if (rwp->r_lhs != NULL) 21457589Seric { 21557589Seric register char **ap; 21657589Seric 2175909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 21857589Seric 21957589Seric /* count the number of fuzzy matches in LHS */ 22057589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22157589Seric { 22258148Seric char *botch; 22358148Seric 22458148Seric botch = NULL; 22558050Seric switch (**ap & 0377) 22657589Seric { 22757589Seric case MATCHZANY: 22857589Seric case MATCHANY: 22957589Seric case MATCHONE: 23057589Seric case MATCHCLASS: 23157589Seric case MATCHNCLASS: 23257589Seric nfuzzy++; 23358148Seric break; 23458148Seric 23558148Seric case MATCHREPL: 23658148Seric botch = "$0-$9"; 23758148Seric break; 23858148Seric 23958148Seric case CANONNET: 24058148Seric botch = "$#"; 24158148Seric break; 24258148Seric 24358148Seric case CANONUSER: 24458148Seric botch = "$:"; 24558148Seric break; 24658148Seric 24758148Seric case CALLSUBR: 24858148Seric botch = "$>"; 24958148Seric break; 25058148Seric 25158148Seric case CONDIF: 25258148Seric botch = "$?"; 25358148Seric break; 25458148Seric 25558148Seric case CONDELSE: 25658148Seric botch = "$|"; 25758148Seric break; 25858148Seric 25958148Seric case CONDFI: 26058148Seric botch = "$."; 26158148Seric break; 26258148Seric 26358148Seric case HOSTBEGIN: 26458148Seric botch = "$["; 26558148Seric break; 26658148Seric 26758148Seric case HOSTEND: 26858148Seric botch = "$]"; 26958148Seric break; 27058148Seric 27158148Seric case LOOKUPBEGIN: 27258148Seric botch = "$("; 27358148Seric break; 27458148Seric 27558148Seric case LOOKUPEND: 27658148Seric botch = "$)"; 27758148Seric break; 27857589Seric } 27958148Seric if (botch != NULL) 28058148Seric syserr("Inappropriate use of %s on LHS", 28158148Seric botch); 28257589Seric } 28357589Seric } 28456678Seric else 28556678Seric syserr("R line: null LHS"); 2865909Seric 2875909Seric /* expand and save the RHS */ 2885909Seric while (*++p == '\t') 2895909Seric continue; 2907231Seric q = p; 2917231Seric while (*p != '\0' && *p != '\t') 2927231Seric p++; 2937231Seric *p = '\0'; 29455012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 29558333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 2965909Seric if (rwp->r_rhs != NULL) 29757589Seric { 29857589Seric register char **ap; 29957589Seric 3005909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30157589Seric 30257589Seric /* check no out-of-bounds replacements */ 30357589Seric nfuzzy += '0'; 30457589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 30557589Seric { 30658148Seric char *botch; 30758148Seric 30858148Seric botch = NULL; 30958148Seric switch (**ap & 0377) 31057589Seric { 31158148Seric case MATCHREPL: 31258148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 31358148Seric { 31458148Seric syserr("replacement $%c out of bounds", 31558148Seric (*ap)[1]); 31658148Seric } 31758148Seric break; 31858148Seric 31958148Seric case MATCHZANY: 32058148Seric botch = "$*"; 32158148Seric break; 32258148Seric 32358148Seric case MATCHANY: 32458148Seric botch = "$+"; 32558148Seric break; 32658148Seric 32758148Seric case MATCHONE: 32858148Seric botch = "$-"; 32958148Seric break; 33058148Seric 33158148Seric case MATCHCLASS: 33258148Seric botch = "$="; 33358148Seric break; 33458148Seric 33558148Seric case MATCHNCLASS: 33658148Seric botch = "$~"; 33758148Seric break; 33857589Seric } 33958148Seric if (botch != NULL) 34058148Seric syserr("Inappropriate use of %s on RHS", 34158148Seric botch); 34257589Seric } 34357589Seric } 34456678Seric else 34556678Seric syserr("R line: null RHS"); 3463308Seric break; 3473308Seric 3484072Seric case 'S': /* select rewriting set */ 34957135Seric ruleset = atoi(&bp[1]); 3508056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3518056Seric { 3529381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3538056Seric ruleset = 0; 3548056Seric } 3554072Seric rwp = NULL; 3564072Seric break; 3574072Seric 3583308Seric case 'D': /* macro definition */ 35958333Seric define(bp[1], newstr(munchstring(&bp[2], NULL)), e); 3603308Seric break; 3613308Seric 3623387Seric case 'H': /* required header line */ 36357135Seric (void) chompheader(&bp[1], TRUE, e); 3643387Seric break; 3653387Seric 3664061Seric case 'C': /* word class */ 3674432Seric /* scan the list of words and set class for all */ 36857135Seric for (p = &bp[2]; *p != '\0'; ) 3694061Seric { 3704061Seric register char *wd; 3714061Seric char delim; 3724061Seric 37358050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3744061Seric p++; 3754061Seric wd = p; 37658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3774061Seric p++; 3784061Seric delim = *p; 3794061Seric *p = '\0'; 3804061Seric if (wd[0] != '\0') 38158148Seric { 38258148Seric if (tTd(37, 2)) 38358148Seric printf("setclass(%c, %s)\n", 38458148Seric bp[1], wd); 38557135Seric setclass(bp[1], wd); 38658148Seric } 3874061Seric *p = delim; 3884061Seric } 3894061Seric break; 3904061Seric 39159272Seric case 'F': /* word class from file */ 39259272Seric /* read list of words from argument or file */ 39359272Seric /* read from file */ 39459272Seric for (p = &bp[2]; 39559272Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 39659272Seric p++) 39759272Seric continue; 39859272Seric if (*p == '\0') 39959272Seric p = "%s"; 40059272Seric else 40159272Seric { 40259272Seric *p = '\0'; 40359272Seric while (isascii(*++p) && isspace(*p)) 40459272Seric continue; 40559272Seric } 40659272Seric fileclass(bp[1], &bp[2], p, safe); 40759272Seric break; 40859272Seric 40959156Seric #ifdef XLA 41059156Seric case 'L': /* extended load average description */ 41159156Seric xla_init(&bp[1]); 41259156Seric break; 41359156Seric #endif 41459156Seric 4154096Seric case 'M': /* define mailer */ 41657135Seric makemailer(&bp[1]); 4174096Seric break; 4184096Seric 4198252Seric case 'O': /* set option */ 42058734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4218252Seric break; 4228252Seric 4238252Seric case 'P': /* set precedence */ 4248252Seric if (NumPriorities >= MAXPRIORITIES) 4258252Seric { 4268547Seric toomany('P', MAXPRIORITIES); 4278252Seric break; 4288252Seric } 42957135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4308252Seric continue; 4318252Seric if (*p == '\0') 4328252Seric goto badline; 4338252Seric *p = '\0'; 43457135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4358252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4368252Seric NumPriorities++; 4378252Seric break; 4388252Seric 4398547Seric case 'T': /* trusted user(s) */ 44058161Seric /* this option is obsolete, but will be ignored */ 4418547Seric break; 4428547Seric 44352645Seric case 'V': /* configuration syntax version */ 44457135Seric ConfigLevel = atoi(&bp[1]); 44552645Seric break; 44652645Seric 44753654Seric case 'K': 44857135Seric makemapentry(&bp[1]); 44953654Seric break; 45053654Seric 4513308Seric default: 4524061Seric badline: 45357135Seric syserr("unknown control line \"%s\"", bp); 4543308Seric } 45557135Seric if (bp != buf) 45657135Seric free(bp); 4573308Seric } 45852637Seric if (ferror(cf)) 45952637Seric { 46052647Seric syserr("I/O read error", cfname); 46152637Seric exit(EX_OSFILE); 46252637Seric } 46352637Seric fclose(cf); 4649381Seric FileName = NULL; 46556836Seric 46657076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 46757076Seric { 46857076Seric /* user didn't initialize: set up host map */ 46957076Seric strcpy(buf, "host host"); 47057076Seric if (ConfigLevel >= 2) 47157076Seric strcat(buf, " -a."); 47257076Seric makemapentry(buf); 47357076Seric } 4744096Seric } 4754096Seric /* 4768547Seric ** TOOMANY -- signal too many of some option 4778547Seric ** 4788547Seric ** Parameters: 4798547Seric ** id -- the id of the error line 4808547Seric ** maxcnt -- the maximum possible values 4818547Seric ** 4828547Seric ** Returns: 4838547Seric ** none. 4848547Seric ** 4858547Seric ** Side Effects: 4868547Seric ** gives a syserr. 4878547Seric */ 4888547Seric 4898547Seric toomany(id, maxcnt) 4908547Seric char id; 4918547Seric int maxcnt; 4928547Seric { 4939381Seric syserr("too many %c lines, %d max", id, maxcnt); 4948547Seric } 4958547Seric /* 4964432Seric ** FILECLASS -- read members of a class from a file 4974432Seric ** 4984432Seric ** Parameters: 4994432Seric ** class -- class to define. 5004432Seric ** filename -- name of file to read. 5014432Seric ** fmt -- scanf string to use for match. 5024432Seric ** 5034432Seric ** Returns: 5044432Seric ** none 5054432Seric ** 5064432Seric ** Side Effects: 5074432Seric ** 5084432Seric ** puts all lines in filename that match a scanf into 5094432Seric ** the named class. 5104432Seric */ 5114432Seric 51254973Seric fileclass(class, filename, fmt, safe) 5134432Seric int class; 5144432Seric char *filename; 5154432Seric char *fmt; 51654973Seric bool safe; 5174432Seric { 51825808Seric FILE *f; 51954973Seric struct stat stbuf; 5204432Seric char buf[MAXLINE]; 5214432Seric 52254973Seric if (stat(filename, &stbuf) < 0) 52354973Seric { 52454973Seric syserr("fileclass: cannot stat %s", filename); 52554973Seric return; 52654973Seric } 52754973Seric if (!S_ISREG(stbuf.st_mode)) 52854973Seric { 52954973Seric syserr("fileclass: %s not a regular file", filename); 53054973Seric return; 53154973Seric } 53254973Seric if (!safe && access(filename, R_OK) < 0) 53354973Seric { 53454973Seric syserr("fileclass: access denied on %s", filename); 53554973Seric return; 53654973Seric } 53754973Seric f = fopen(filename, "r"); 5384432Seric if (f == NULL) 5394432Seric { 54054973Seric syserr("fileclass: cannot open %s", filename); 5414432Seric return; 5424432Seric } 5434432Seric 5444432Seric while (fgets(buf, sizeof buf, f) != NULL) 5454432Seric { 5464432Seric register STAB *s; 54725808Seric register char *p; 54825808Seric # ifdef SCANF 5494432Seric char wordbuf[MAXNAME+1]; 5504432Seric 5514432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5524432Seric continue; 55325808Seric p = wordbuf; 55456795Seric # else /* SCANF */ 55525808Seric p = buf; 55656795Seric # endif /* SCANF */ 55725808Seric 55825808Seric /* 55925808Seric ** Break up the match into words. 56025808Seric */ 56125808Seric 56225808Seric while (*p != '\0') 56325808Seric { 56425808Seric register char *q; 56525808Seric 56625808Seric /* strip leading spaces */ 56758050Seric while (isascii(*p) && isspace(*p)) 56825808Seric p++; 56925808Seric if (*p == '\0') 57025808Seric break; 57125808Seric 57225808Seric /* find the end of the word */ 57325808Seric q = p; 57458050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 57525808Seric p++; 57625808Seric if (*p != '\0') 57725808Seric *p++ = '\0'; 57825808Seric 57925808Seric /* enter the word in the symbol table */ 58025808Seric s = stab(q, ST_CLASS, ST_ENTER); 58125808Seric setbitn(class, s->s_class); 58225808Seric } 5834432Seric } 5844432Seric 58554973Seric (void) fclose(f); 5864432Seric } 5874432Seric /* 5884096Seric ** MAKEMAILER -- define a new mailer. 5894096Seric ** 5904096Seric ** Parameters: 59110327Seric ** line -- description of mailer. This is in labeled 59210327Seric ** fields. The fields are: 59310327Seric ** P -- the path to the mailer 59410327Seric ** F -- the flags associated with the mailer 59510327Seric ** A -- the argv for this mailer 59610327Seric ** S -- the sender rewriting set 59710327Seric ** R -- the recipient rewriting set 59810327Seric ** E -- the eol string 59910327Seric ** The first word is the canonical name of the mailer. 6004096Seric ** 6014096Seric ** Returns: 6024096Seric ** none. 6034096Seric ** 6044096Seric ** Side Effects: 6054096Seric ** enters the mailer into the mailer table. 6064096Seric */ 6073308Seric 60821066Seric makemailer(line) 6094096Seric char *line; 6104096Seric { 6114096Seric register char *p; 6128067Seric register struct mailer *m; 6138067Seric register STAB *s; 6148067Seric int i; 61510327Seric char fcode; 61658020Seric auto char *endp; 6174096Seric extern int NextMailer; 61810327Seric extern char **makeargv(); 61910327Seric extern char *munchstring(); 62010701Seric extern long atol(); 6214096Seric 62210327Seric /* allocate a mailer and set up defaults */ 62310327Seric m = (struct mailer *) xalloc(sizeof *m); 62410327Seric bzero((char *) m, sizeof *m); 62510327Seric m->m_eol = "\n"; 62610327Seric 62710327Seric /* collect the mailer name */ 62858050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 62910327Seric continue; 63010327Seric if (*p != '\0') 63110327Seric *p++ = '\0'; 63210327Seric m->m_name = newstr(line); 63310327Seric 63410327Seric /* now scan through and assign info from the fields */ 63510327Seric while (*p != '\0') 63610327Seric { 63758333Seric auto char *delimptr; 63858333Seric 63958050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 64010327Seric p++; 64110327Seric 64210327Seric /* p now points to field code */ 64310327Seric fcode = *p; 64410327Seric while (*p != '\0' && *p != '=' && *p != ',') 64510327Seric p++; 64610327Seric if (*p++ != '=') 64710327Seric { 64852637Seric syserr("mailer %s: `=' expected", m->m_name); 64910327Seric return; 65010327Seric } 65158050Seric while (isascii(*p) && isspace(*p)) 65210327Seric p++; 65310327Seric 65410327Seric /* p now points to the field body */ 65558333Seric p = munchstring(p, &delimptr); 65610327Seric 65710327Seric /* install the field into the mailer struct */ 65810327Seric switch (fcode) 65910327Seric { 66010327Seric case 'P': /* pathname */ 66110327Seric m->m_mailer = newstr(p); 66210327Seric break; 66310327Seric 66410327Seric case 'F': /* flags */ 66510687Seric for (; *p != '\0'; p++) 66658050Seric if (!(isascii(*p) && isspace(*p))) 66752637Seric setbitn(*p, m->m_flags); 66810327Seric break; 66910327Seric 67010327Seric case 'S': /* sender rewriting ruleset */ 67110327Seric case 'R': /* recipient rewriting ruleset */ 67258020Seric i = strtol(p, &endp, 10); 67310327Seric if (i < 0 || i >= MAXRWSETS) 67410327Seric { 67510327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 67610327Seric return; 67710327Seric } 67810327Seric if (fcode == 'S') 67958020Seric m->m_sh_rwset = m->m_se_rwset = i; 68010327Seric else 68158020Seric m->m_rh_rwset = m->m_re_rwset = i; 68258020Seric 68358020Seric p = endp; 68459985Seric if (*p++ == '/') 68558020Seric { 68658020Seric i = strtol(p, NULL, 10); 68758020Seric if (i < 0 || i >= MAXRWSETS) 68858020Seric { 68958020Seric syserr("invalid rewrite set, %d max", 69058020Seric MAXRWSETS); 69158020Seric return; 69258020Seric } 69358020Seric if (fcode == 'S') 69458020Seric m->m_sh_rwset = i; 69558020Seric else 69658020Seric m->m_rh_rwset = i; 69758020Seric } 69810327Seric break; 69910327Seric 70010327Seric case 'E': /* end of line string */ 70110327Seric m->m_eol = newstr(p); 70210327Seric break; 70310327Seric 70410327Seric case 'A': /* argument vector */ 70510327Seric m->m_argv = makeargv(p); 70610327Seric break; 70710701Seric 70810701Seric case 'M': /* maximum message size */ 70910701Seric m->m_maxsize = atol(p); 71010701Seric break; 71152106Seric 71252106Seric case 'L': /* maximum line length */ 71352106Seric m->m_linelimit = atoi(p); 71452106Seric break; 71558935Seric 71658935Seric case 'D': /* working directory */ 71758935Seric m->m_execdir = newstr(p); 71858935Seric break; 71910327Seric } 72010327Seric 72158333Seric p = delimptr; 72210327Seric } 72310327Seric 72452106Seric /* do some heuristic cleanup for back compatibility */ 72552106Seric if (bitnset(M_LIMITS, m->m_flags)) 72652106Seric { 72752106Seric if (m->m_linelimit == 0) 72852106Seric m->m_linelimit = SMTPLINELIM; 72955418Seric if (ConfigLevel < 2) 73052106Seric setbitn(M_7BITS, m->m_flags); 73152106Seric } 73252106Seric 73358321Seric /* do some rationality checking */ 73458321Seric if (m->m_argv == NULL) 73558321Seric { 73658321Seric syserr("M%s: A= argument required", m->m_name); 73758321Seric return; 73858321Seric } 73958321Seric if (m->m_mailer == NULL) 74058321Seric { 74158321Seric syserr("M%s: P= argument required", m->m_name); 74258321Seric return; 74358321Seric } 74458321Seric 7454096Seric if (NextMailer >= MAXMAILERS) 7464096Seric { 7479381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7484096Seric return; 7494096Seric } 75057402Seric 75110327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 75257402Seric if (s->s_mailer != NULL) 75357402Seric { 75457402Seric i = s->s_mailer->m_mno; 75557402Seric free(s->s_mailer); 75657402Seric } 75757402Seric else 75857402Seric { 75957402Seric i = NextMailer++; 76057402Seric } 76157402Seric Mailer[i] = s->s_mailer = m; 76257454Seric m->m_mno = i; 76310327Seric } 76410327Seric /* 76510327Seric ** MUNCHSTRING -- translate a string into internal form. 76610327Seric ** 76710327Seric ** Parameters: 76810327Seric ** p -- the string to munch. 76958333Seric ** delimptr -- if non-NULL, set to the pointer of the 77058333Seric ** field delimiter character. 77110327Seric ** 77210327Seric ** Returns: 77310327Seric ** the munched string. 77410327Seric */ 7754096Seric 77610327Seric char * 77758333Seric munchstring(p, delimptr) 77810327Seric register char *p; 77958333Seric char **delimptr; 78010327Seric { 78110327Seric register char *q; 78210327Seric bool backslash = FALSE; 78310327Seric bool quotemode = FALSE; 78410327Seric static char buf[MAXLINE]; 7854096Seric 78610327Seric for (q = buf; *p != '\0'; p++) 7874096Seric { 78810327Seric if (backslash) 78910327Seric { 79010327Seric /* everything is roughly literal */ 79110357Seric backslash = FALSE; 79210327Seric switch (*p) 79310327Seric { 79410327Seric case 'r': /* carriage return */ 79510327Seric *q++ = '\r'; 79610327Seric continue; 79710327Seric 79810327Seric case 'n': /* newline */ 79910327Seric *q++ = '\n'; 80010327Seric continue; 80110327Seric 80210327Seric case 'f': /* form feed */ 80310327Seric *q++ = '\f'; 80410327Seric continue; 80510327Seric 80610327Seric case 'b': /* backspace */ 80710327Seric *q++ = '\b'; 80810327Seric continue; 80910327Seric } 81010327Seric *q++ = *p; 81110327Seric } 81210327Seric else 81310327Seric { 81410327Seric if (*p == '\\') 81510327Seric backslash = TRUE; 81610327Seric else if (*p == '"') 81710327Seric quotemode = !quotemode; 81810327Seric else if (quotemode || *p != ',') 81910327Seric *q++ = *p; 82010327Seric else 82110327Seric break; 82210327Seric } 8234096Seric } 8244096Seric 82558333Seric if (delimptr != NULL) 82658333Seric *delimptr = p; 82710327Seric *q++ = '\0'; 82810327Seric return (buf); 82910327Seric } 83010327Seric /* 83110327Seric ** MAKEARGV -- break up a string into words 83210327Seric ** 83310327Seric ** Parameters: 83410327Seric ** p -- the string to break up. 83510327Seric ** 83610327Seric ** Returns: 83710327Seric ** a char **argv (dynamically allocated) 83810327Seric ** 83910327Seric ** Side Effects: 84010327Seric ** munges p. 84110327Seric */ 8424096Seric 84310327Seric char ** 84410327Seric makeargv(p) 84510327Seric register char *p; 84610327Seric { 84710327Seric char *q; 84810327Seric int i; 84910327Seric char **avp; 85010327Seric char *argv[MAXPV + 1]; 85110327Seric 85210327Seric /* take apart the words */ 85310327Seric i = 0; 85410327Seric while (*p != '\0' && i < MAXPV) 8554096Seric { 85610327Seric q = p; 85758050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 85810327Seric p++; 85958050Seric while (isascii(*p) && isspace(*p)) 86010327Seric *p++ = '\0'; 86110327Seric argv[i++] = newstr(q); 8624096Seric } 86310327Seric argv[i++] = NULL; 8644096Seric 86510327Seric /* now make a copy of the argv */ 86610327Seric avp = (char **) xalloc(sizeof *avp * i); 86716893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 86810327Seric 86910327Seric return (avp); 8703308Seric } 8713308Seric /* 8723308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8733308Seric ** 8743308Seric ** Parameters: 8753308Seric ** none. 8763308Seric ** 8773308Seric ** Returns: 8783308Seric ** none. 8793308Seric ** 8803308Seric ** Side Effects: 8813308Seric ** prints rewrite rules. 8823308Seric */ 8833308Seric 8843308Seric printrules() 8853308Seric { 8863308Seric register struct rewrite *rwp; 8874072Seric register int ruleset; 8883308Seric 8894072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8903308Seric { 8914072Seric if (RewriteRules[ruleset] == NULL) 8924072Seric continue; 8938067Seric printf("\n----Rule Set %d:", ruleset); 8943308Seric 8954072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 8963308Seric { 8978067Seric printf("\nLHS:"); 8988067Seric printav(rwp->r_lhs); 8998067Seric printf("RHS:"); 9008067Seric printav(rwp->r_rhs); 9013308Seric } 9023308Seric } 9033308Seric } 9044319Seric 9054096Seric /* 9068256Seric ** SETOPTION -- set global processing option 9078256Seric ** 9088256Seric ** Parameters: 9098256Seric ** opt -- option name. 9108256Seric ** val -- option value (as a text string). 91121755Seric ** safe -- set if this came from a configuration file. 91221755Seric ** Some options (if set from the command line) will 91321755Seric ** reset the user id to avoid security problems. 9148269Seric ** sticky -- if set, don't let other setoptions override 9158269Seric ** this value. 91658734Seric ** e -- the main envelope. 9178256Seric ** 9188256Seric ** Returns: 9198256Seric ** none. 9208256Seric ** 9218256Seric ** Side Effects: 9228256Seric ** Sets options as implied by the arguments. 9238256Seric */ 9248256Seric 92510687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9268269Seric 92757207Seric 92857207Seric #ifdef NAMED_BIND 92957207Seric 93057207Seric struct resolverflags 93157207Seric { 93257207Seric char *rf_name; /* name of the flag */ 93357207Seric long rf_bits; /* bits to set/clear */ 93457207Seric } ResolverFlags[] = 93557207Seric { 93657207Seric "debug", RES_DEBUG, 93757207Seric "aaonly", RES_AAONLY, 93857207Seric "usevc", RES_USEVC, 93957207Seric "primary", RES_PRIMARY, 94057207Seric "igntc", RES_IGNTC, 94157207Seric "recurse", RES_RECURSE, 94257207Seric "defnames", RES_DEFNAMES, 94357207Seric "stayopen", RES_STAYOPEN, 94457207Seric "dnsrch", RES_DNSRCH, 94557207Seric NULL, 0 94657207Seric }; 94757207Seric 94857207Seric #endif 94957207Seric 95058734Seric setoption(opt, val, safe, sticky, e) 9518256Seric char opt; 9528256Seric char *val; 95321755Seric bool safe; 9548269Seric bool sticky; 95558734Seric register ENVELOPE *e; 9568256Seric { 95757207Seric register char *p; 9588265Seric extern bool atobool(); 95912633Seric extern time_t convtime(); 96014879Seric extern int QueueLA; 96114879Seric extern int RefuseLA; 96217474Seric extern bool trusteduser(); 9638256Seric 9648256Seric if (tTd(37, 1)) 9659341Seric printf("setoption %c=%s", opt, val); 9668256Seric 9678256Seric /* 9688269Seric ** See if this option is preset for us. 9698256Seric */ 9708256Seric 97159731Seric if (!sticky && bitnset(opt, StickyOpt)) 9728269Seric { 9739341Seric if (tTd(37, 1)) 9749341Seric printf(" (ignored)\n"); 9758269Seric return; 9768269Seric } 9778269Seric 97821755Seric /* 97921755Seric ** Check to see if this option can be specified by this user. 98021755Seric */ 98121755Seric 98236238Skarels if (!safe && getuid() == 0) 98321755Seric safe = TRUE; 98459730Seric if (!safe && strchr("bdeEijLmoprsvC7", opt) == NULL) 98521755Seric { 98639111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 98721755Seric { 98836582Sbostic if (tTd(37, 1)) 98936582Sbostic printf(" (unsafe)"); 99036582Sbostic if (getuid() != geteuid()) 99136582Sbostic { 99251210Seric if (tTd(37, 1)) 99351210Seric printf("(Resetting uid)"); 99436582Sbostic (void) setgid(getgid()); 99536582Sbostic (void) setuid(getuid()); 99636582Sbostic } 99721755Seric } 99821755Seric } 99951210Seric if (tTd(37, 1)) 100017985Seric printf("\n"); 10018269Seric 10028256Seric switch (opt) 10038256Seric { 100459709Seric case '7': /* force seven-bit input */ 100559709Seric SevenBit = atobool(val); 100652106Seric break; 100752106Seric 10088256Seric case 'A': /* set default alias file */ 10099381Seric if (val[0] == '\0') 101059672Seric setalias("aliases"); 10119381Seric else 101259672Seric setalias(val); 10138256Seric break; 10148256Seric 101517474Seric case 'a': /* look N minutes for "@:@" in alias file */ 101617474Seric if (val[0] == '\0') 101717474Seric SafeAlias = 5; 101817474Seric else 101917474Seric SafeAlias = atoi(val); 102017474Seric break; 102117474Seric 102216843Seric case 'B': /* substitution for blank character */ 102316843Seric SpaceSub = val[0]; 102416843Seric if (SpaceSub == '\0') 102516843Seric SpaceSub = ' '; 102616843Seric break; 102716843Seric 102859283Seric case 'b': /* min blocks free on queue fs/max msg size */ 102959283Seric p = strchr(val, '/'); 103059283Seric if (p != NULL) 103159283Seric { 103259283Seric *p++ = '\0'; 103359283Seric MaxMessageSize = atol(p); 103459283Seric } 103558082Seric MinBlocksFree = atol(val); 103658082Seric break; 103758082Seric 10389284Seric case 'c': /* don't connect to "expensive" mailers */ 10399381Seric NoConnect = atobool(val); 10409284Seric break; 10419284Seric 104251305Seric case 'C': /* checkpoint every N addresses */ 104351305Seric CheckpointInterval = atoi(val); 104424944Seric break; 104524944Seric 10469284Seric case 'd': /* delivery mode */ 10479284Seric switch (*val) 10488269Seric { 10499284Seric case '\0': 105058734Seric e->e_sendmode = SM_DELIVER; 10518269Seric break; 10528269Seric 105310755Seric case SM_QUEUE: /* queue only */ 105410755Seric #ifndef QUEUE 105510755Seric syserr("need QUEUE to set -odqueue"); 105656795Seric #endif /* QUEUE */ 105710755Seric /* fall through..... */ 105810755Seric 10599284Seric case SM_DELIVER: /* do everything */ 10609284Seric case SM_FORK: /* fork after verification */ 106158734Seric e->e_sendmode = *val; 10628269Seric break; 10638269Seric 10648269Seric default: 10659284Seric syserr("Unknown delivery mode %c", *val); 10668269Seric exit(EX_USAGE); 10678269Seric } 10688269Seric break; 10698269Seric 10709146Seric case 'D': /* rebuild alias database as needed */ 10719381Seric AutoRebuild = atobool(val); 10729146Seric break; 10739146Seric 107455372Seric case 'E': /* error message header/header file */ 107555379Seric if (*val != '\0') 107655379Seric ErrMsgFile = newstr(val); 107755372Seric break; 107855372Seric 10798269Seric case 'e': /* set error processing mode */ 10808269Seric switch (*val) 10818269Seric { 10829381Seric case EM_QUIET: /* be silent about it */ 10839381Seric case EM_MAIL: /* mail back */ 10849381Seric case EM_BERKNET: /* do berknet error processing */ 10859381Seric case EM_WRITE: /* write back (or mail) */ 10868269Seric HoldErrs = TRUE; 10879381Seric /* fall through... */ 10888269Seric 10899381Seric case EM_PRINT: /* print errors normally (default) */ 109058734Seric e->e_errormode = *val; 10918269Seric break; 10928269Seric } 10938269Seric break; 10948269Seric 10959049Seric case 'F': /* file mode */ 109617975Seric FileMode = atooct(val) & 0777; 10979049Seric break; 10989049Seric 10998269Seric case 'f': /* save Unix-style From lines on front */ 11009381Seric SaveFrom = atobool(val); 11018269Seric break; 11028269Seric 110353735Seric case 'G': /* match recipients against GECOS field */ 110453735Seric MatchGecos = atobool(val); 110553735Seric break; 110653735Seric 11078256Seric case 'g': /* default gid */ 110817474Seric DefGid = atoi(val); 11098256Seric break; 11108256Seric 11118256Seric case 'H': /* help file */ 11129381Seric if (val[0] == '\0') 11138269Seric HelpFile = "sendmail.hf"; 11149381Seric else 11159381Seric HelpFile = newstr(val); 11168256Seric break; 11178256Seric 111851305Seric case 'h': /* maximum hop count */ 111951305Seric MaxHopCount = atoi(val); 112051305Seric break; 112151305Seric 112235651Seric case 'I': /* use internet domain name server */ 112357207Seric #ifdef NAMED_BIND 112457207Seric UseNameServer = TRUE; 112557207Seric for (p = val; *p != 0; ) 112657207Seric { 112757207Seric bool clearmode; 112857207Seric char *q; 112957207Seric struct resolverflags *rfp; 113057207Seric 113157207Seric while (*p == ' ') 113257207Seric p++; 113357207Seric if (*p == '\0') 113457207Seric break; 113557207Seric clearmode = FALSE; 113657207Seric if (*p == '-') 113757207Seric clearmode = TRUE; 113857207Seric else if (*p != '+') 113957207Seric p--; 114057207Seric p++; 114157207Seric q = p; 114258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114357207Seric p++; 114457207Seric if (*p != '\0') 114557207Seric *p++ = '\0'; 114657207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114757207Seric { 114857207Seric if (strcasecmp(q, rfp->rf_name) == 0) 114957207Seric break; 115057207Seric } 115157207Seric if (clearmode) 115257207Seric _res.options &= ~rfp->rf_bits; 115357207Seric else 115457207Seric _res.options |= rfp->rf_bits; 115557207Seric } 115657207Seric if (tTd(8, 2)) 115757207Seric printf("_res.options = %x\n", _res.options); 115857207Seric #else 115957207Seric usrerr("name server (I option) specified but BIND not compiled in"); 116057207Seric #endif 116135651Seric break; 116235651Seric 11638269Seric case 'i': /* ignore dot lines in message */ 11649381Seric IgnrDot = atobool(val); 11658269Seric break; 11668269Seric 116759730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 116859730Seric SendMIMEErrors = atobool(val); 116959730Seric break; 117059730Seric 117157136Seric case 'J': /* .forward search path */ 117257136Seric ForwardPath = newstr(val); 117357136Seric break; 117457136Seric 117554967Seric case 'k': /* connection cache size */ 117654967Seric MaxMciCache = atoi(val); 117756215Seric if (MaxMciCache < 0) 117856215Seric MaxMciCache = 0; 117954967Seric break; 118054967Seric 118154967Seric case 'K': /* connection cache timeout */ 118258796Seric MciCacheTimeout = convtime(val, 'm'); 118354967Seric break; 118454967Seric 11858256Seric case 'L': /* log level */ 11869381Seric LogLevel = atoi(val); 11878256Seric break; 11888256Seric 11898269Seric case 'M': /* define macro */ 11909381Seric define(val[0], newstr(&val[1]), CurEnv); 119116878Seric sticky = FALSE; 11928269Seric break; 11938269Seric 11948269Seric case 'm': /* send to me too */ 11959381Seric MeToo = atobool(val); 11968269Seric break; 11978269Seric 119825820Seric case 'n': /* validate RHS in newaliases */ 119925820Seric CheckAliases = atobool(val); 120025820Seric break; 120125820Seric 120258851Seric case 'O': /* daemon options */ 120358851Seric setdaemonoptions(val); 120458851Seric break; 120558851Seric 12068269Seric case 'o': /* assume old style headers */ 12079381Seric if (atobool(val)) 12089341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12099341Seric else 12109341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12118269Seric break; 12128269Seric 121358082Seric case 'p': /* select privacy level */ 121458082Seric p = val; 121558082Seric for (;;) 121658082Seric { 121758082Seric register struct prival *pv; 121858082Seric extern struct prival PrivacyValues[]; 121958082Seric 122058082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 122158082Seric p++; 122258082Seric if (*p == '\0') 122358082Seric break; 122458082Seric val = p; 122558082Seric while (isascii(*p) && isalnum(*p)) 122658082Seric p++; 122758082Seric if (*p != '\0') 122858082Seric *p++ = '\0'; 122958082Seric 123058082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 123158082Seric { 123258082Seric if (strcasecmp(val, pv->pv_name) == 0) 123358082Seric break; 123458082Seric } 123558886Seric if (pv->pv_name == NULL) 123658886Seric syserr("readcf: Op line: %s unrecognized", val); 123758082Seric PrivacyFlags |= pv->pv_flag; 123858082Seric } 123958082Seric break; 124058082Seric 124124944Seric case 'P': /* postmaster copy address for returned mail */ 124224944Seric PostMasterCopy = newstr(val); 124324944Seric break; 124424944Seric 124524944Seric case 'q': /* slope of queue only function */ 124624944Seric QueueFactor = atoi(val); 124724944Seric break; 124824944Seric 12498256Seric case 'Q': /* queue directory */ 12509381Seric if (val[0] == '\0') 12518269Seric QueueDir = "mqueue"; 12529381Seric else 12539381Seric QueueDir = newstr(val); 125458789Seric if (RealUid != 0 && !safe) 125558789Seric auth_warning(e, "Processed from queue %s", QueueDir); 12568256Seric break; 12578256Seric 125858148Seric case 'R': /* don't prune routes */ 125958148Seric DontPruneRoutes = atobool(val); 126058148Seric break; 126158148Seric 12628256Seric case 'r': /* read timeout */ 126358112Seric settimeouts(val); 12648256Seric break; 12658256Seric 12668256Seric case 'S': /* status file */ 12679381Seric if (val[0] == '\0') 12688269Seric StatFile = "sendmail.st"; 12699381Seric else 12709381Seric StatFile = newstr(val); 12718256Seric break; 12728256Seric 12738265Seric case 's': /* be super safe, even if expensive */ 12749381Seric SuperSafe = atobool(val); 12758256Seric break; 12768256Seric 12778256Seric case 'T': /* queue timeout */ 127858737Seric p = strchr(val, '/'); 127958737Seric if (p != NULL) 128058737Seric { 128158737Seric *p++ = '\0'; 128258796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 128358737Seric } 128458796Seric TimeOuts.to_q_return = convtime(val, 'h'); 128554967Seric break; 12868256Seric 12878265Seric case 't': /* time zone name */ 128852106Seric TimeZoneSpec = newstr(val); 12898265Seric break; 12908265Seric 129150556Seric case 'U': /* location of user database */ 129251360Seric UdbSpec = newstr(val); 129350556Seric break; 129450556Seric 12958256Seric case 'u': /* set default uid */ 129617474Seric DefUid = atoi(val); 129740973Sbostic setdefuser(); 12988256Seric break; 12998256Seric 130058851Seric case 'V': /* fallback MX host */ 130158851Seric FallBackMX = newstr(val); 130258851Seric break; 130358851Seric 13048269Seric case 'v': /* run in verbose mode */ 13059381Seric Verbose = atobool(val); 13068256Seric break; 13078256Seric 130814879Seric case 'x': /* load avg at which to auto-queue msgs */ 130914879Seric QueueLA = atoi(val); 131014879Seric break; 131114879Seric 131214879Seric case 'X': /* load avg at which to auto-reject connections */ 131314879Seric RefuseLA = atoi(val); 131414879Seric break; 131514879Seric 131624981Seric case 'y': /* work recipient factor */ 131724981Seric WkRecipFact = atoi(val); 131824981Seric break; 131924981Seric 132024981Seric case 'Y': /* fork jobs during queue runs */ 132124952Seric ForkQueueRuns = atobool(val); 132224952Seric break; 132324952Seric 132424981Seric case 'z': /* work message class factor */ 132524981Seric WkClassFact = atoi(val); 132624981Seric break; 132724981Seric 132824981Seric case 'Z': /* work time factor */ 132924981Seric WkTimeFact = atoi(val); 133024981Seric break; 133124981Seric 13328256Seric default: 13338256Seric break; 13348256Seric } 133516878Seric if (sticky) 133616878Seric setbitn(opt, StickyOpt); 13379188Seric return; 13388256Seric } 133910687Seric /* 134010687Seric ** SETCLASS -- set a word into a class 134110687Seric ** 134210687Seric ** Parameters: 134310687Seric ** class -- the class to put the word in. 134410687Seric ** word -- the word to enter 134510687Seric ** 134610687Seric ** Returns: 134710687Seric ** none. 134810687Seric ** 134910687Seric ** Side Effects: 135010687Seric ** puts the word into the symbol table. 135110687Seric */ 135210687Seric 135310687Seric setclass(class, word) 135410687Seric int class; 135510687Seric char *word; 135610687Seric { 135710687Seric register STAB *s; 135810687Seric 135957943Seric if (tTd(37, 8)) 136057943Seric printf("%s added to class %c\n", word, class); 136110687Seric s = stab(word, ST_CLASS, ST_ENTER); 136210687Seric setbitn(class, s->s_class); 136310687Seric } 136453654Seric /* 136553654Seric ** MAKEMAPENTRY -- create a map entry 136653654Seric ** 136753654Seric ** Parameters: 136853654Seric ** line -- the config file line 136953654Seric ** 137053654Seric ** Returns: 137153654Seric ** TRUE if it successfully entered the map entry. 137253654Seric ** FALSE otherwise (usually syntax error). 137353654Seric ** 137453654Seric ** Side Effects: 137553654Seric ** Enters the map into the dictionary. 137653654Seric */ 137753654Seric 137853654Seric void 137953654Seric makemapentry(line) 138053654Seric char *line; 138153654Seric { 138253654Seric register char *p; 138353654Seric char *mapname; 138453654Seric char *classname; 138553654Seric register STAB *map; 138653654Seric STAB *class; 138753654Seric 138858050Seric for (p = line; isascii(*p) && isspace(*p); p++) 138953654Seric continue; 139058050Seric if (!(isascii(*p) && isalnum(*p))) 139153654Seric { 139253654Seric syserr("readcf: config K line: no map name"); 139353654Seric return; 139453654Seric } 139553654Seric 139653654Seric mapname = p; 139758050Seric while (isascii(*++p) && isalnum(*p)) 139853654Seric continue; 139953654Seric if (*p != '\0') 140053654Seric *p++ = '\0'; 140158050Seric while (isascii(*p) && isspace(*p)) 140253654Seric p++; 140358050Seric if (!(isascii(*p) && isalnum(*p))) 140453654Seric { 140553654Seric syserr("readcf: config K line, map %s: no map class", mapname); 140653654Seric return; 140753654Seric } 140853654Seric classname = p; 140958050Seric while (isascii(*++p) && isalnum(*p)) 141053654Seric continue; 141153654Seric if (*p != '\0') 141253654Seric *p++ = '\0'; 141358050Seric while (isascii(*p) && isspace(*p)) 141453654Seric p++; 141553654Seric 141653654Seric /* look up the class */ 141753654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 141853654Seric if (class == NULL) 141953654Seric { 142053654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 142153654Seric return; 142253654Seric } 142353654Seric 142453654Seric /* enter the map */ 142553654Seric map = stab(mapname, ST_MAP, ST_ENTER); 142660207Seric map->s_map.map_class = &class->s_mapclass; 142760089Seric map->s_map.map_mname = newstr(mapname); 142853654Seric 1429*60538Seric if (class->s_mapclass.map_parse(&map->s_map, p)) 1430*60538Seric map->s_map.map_mflags |= MF_VALID; 143153654Seric } 143258112Seric /* 143358112Seric ** SETTIMEOUTS -- parse and set timeout values 143458112Seric ** 143558112Seric ** Parameters: 143658112Seric ** val -- a pointer to the values. If NULL, do initial 143758112Seric ** settings. 143858112Seric ** 143958112Seric ** Returns: 144058112Seric ** none. 144158112Seric ** 144258112Seric ** Side Effects: 144358112Seric ** Initializes the TimeOuts structure 144458112Seric */ 144558112Seric 144658112Seric #define MINUTES * 60 144758112Seric #define HOUR * 3600 144858112Seric 144958112Seric settimeouts(val) 145058112Seric register char *val; 145158112Seric { 145258112Seric register char *p; 145358671Seric extern time_t convtime(); 145458112Seric 145558112Seric if (val == NULL) 145658112Seric { 145758112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 145858112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 145958112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 146058112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 146158112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 146258112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 146358112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 146458112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 146558112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 146658112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 146758112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 146858112Seric return; 146958112Seric } 147058112Seric 147158112Seric for (;; val = p) 147258112Seric { 147358112Seric while (isascii(*val) && isspace(*val)) 147458112Seric val++; 147558112Seric if (*val == '\0') 147658112Seric break; 147758112Seric for (p = val; *p != '\0' && *p != ','; p++) 147858112Seric continue; 147958112Seric if (*p != '\0') 148058112Seric *p++ = '\0'; 148158112Seric 148258112Seric if (isascii(*val) && isdigit(*val)) 148358112Seric { 148458112Seric /* old syntax -- set everything */ 148558796Seric TimeOuts.to_mail = convtime(val, 'm'); 148658112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 148758112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 148858112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 148958112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 149058112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 149158112Seric continue; 149258112Seric } 149358112Seric else 149458112Seric { 149558112Seric register char *q = strchr(val, '='); 149658112Seric time_t to; 149758112Seric 149858112Seric if (q == NULL) 149958112Seric { 150058112Seric /* syntax error */ 150158112Seric continue; 150258112Seric } 150358112Seric *q++ = '\0'; 150458796Seric to = convtime(q, 'm'); 150558112Seric 150658112Seric if (strcasecmp(val, "initial") == 0) 150758112Seric TimeOuts.to_initial = to; 150858112Seric else if (strcasecmp(val, "mail") == 0) 150958112Seric TimeOuts.to_mail = to; 151058112Seric else if (strcasecmp(val, "rcpt") == 0) 151158112Seric TimeOuts.to_rcpt = to; 151258112Seric else if (strcasecmp(val, "datainit") == 0) 151358112Seric TimeOuts.to_datainit = to; 151458112Seric else if (strcasecmp(val, "datablock") == 0) 151558112Seric TimeOuts.to_datablock = to; 151658112Seric else if (strcasecmp(val, "datafinal") == 0) 151758112Seric TimeOuts.to_datafinal = to; 151858112Seric else if (strcasecmp(val, "command") == 0) 151958112Seric TimeOuts.to_nextcommand = to; 152058112Seric else if (strcasecmp(val, "rset") == 0) 152158112Seric TimeOuts.to_rset = to; 152258112Seric else if (strcasecmp(val, "helo") == 0) 152358112Seric TimeOuts.to_helo = to; 152458112Seric else if (strcasecmp(val, "quit") == 0) 152558112Seric TimeOuts.to_quit = to; 152658112Seric else if (strcasecmp(val, "misc") == 0) 152758112Seric TimeOuts.to_miscshort = to; 152858112Seric else 152958112Seric syserr("settimeouts: invalid timeout %s", val); 153058112Seric } 153158112Seric } 153258112Seric } 1533