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*60207Seric static char sccsid[] = "@(#)readcf.c 6.38 (Berkeley) 05/21/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 **prescan(); 783308Seric extern char **copyplist(); 7952647Seric struct stat statb; 805909Seric char exbuf[MAXLINE]; 8116915Seric char pvpbuf[PSBUFSIZE]; 829350Seric extern char *fgetfolded(); 8310709Seric extern char *munchstring(); 8453654Seric extern void makemapentry(); 853308Seric 8652647Seric FileName = cfname; 8752647Seric LineNumber = 0; 8852647Seric 893308Seric cf = fopen(cfname, "r"); 903308Seric if (cf == NULL) 913308Seric { 9252647Seric syserr("cannot open"); 933308Seric exit(EX_OSFILE); 943308Seric } 953308Seric 9652647Seric if (fstat(fileno(cf), &statb) < 0) 9752647Seric { 9852647Seric syserr("cannot fstat"); 9952647Seric exit(EX_OSFILE); 10052647Seric } 10152647Seric 10252647Seric if (!S_ISREG(statb.st_mode)) 10352647Seric { 10452647Seric syserr("not a plain file"); 10552647Seric exit(EX_OSFILE); 10652647Seric } 10752647Seric 10852647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 10952647Seric { 11053037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 11153037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 11253037Seric FileName); 11353037Seric #ifdef LOG 11453037Seric if (LogLevel > 0) 11553037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 11653037Seric FileName); 11753037Seric #endif 11852647Seric } 11952647Seric 12059254Seric #ifdef XLA 12159254Seric xla_zero(); 12259254Seric #endif 12359254Seric 12457135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1253308Seric { 12657135Seric if (bp[0] == '#') 12757135Seric { 12857135Seric if (bp != buf) 12957135Seric free(bp); 13052637Seric continue; 13157135Seric } 13252637Seric 13358050Seric /* map $ into \201 for macro expansion */ 13457135Seric for (p = bp; *p != '\0'; p++) 13516157Seric { 13657135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 13752647Seric { 13852647Seric /* this is an on-line comment */ 13952647Seric register char *e; 14052647Seric 14158050Seric switch (*--p & 0377) 14252647Seric { 14358050Seric case MACROEXPAND: 14452647Seric /* it's from $# -- let it go through */ 14552647Seric p++; 14652647Seric break; 14752647Seric 14852647Seric case '\\': 14952647Seric /* it's backslash escaped */ 15052647Seric (void) strcpy(p, p + 1); 15152647Seric break; 15252647Seric 15352647Seric default: 15452647Seric /* delete preceeding white space */ 15558050Seric while (isascii(*p) && isspace(*p) && p > bp) 15652647Seric p--; 15756795Seric if ((e = strchr(++p, '\n')) != NULL) 15852647Seric (void) strcpy(p, e); 15952647Seric else 16052647Seric p[0] = p[1] = '\0'; 16152647Seric break; 16252647Seric } 16352647Seric continue; 16452647Seric } 16552647Seric 16616157Seric if (*p != '$') 16716157Seric continue; 16816157Seric 16916157Seric if (p[1] == '$') 17016157Seric { 17116157Seric /* actual dollar sign.... */ 17223111Seric (void) strcpy(p, p + 1); 17316157Seric continue; 17416157Seric } 17516157Seric 17616157Seric /* convert to macro expansion character */ 17758050Seric *p = MACROEXPAND; 17816157Seric } 17916157Seric 18016157Seric /* interpret this line */ 18157135Seric switch (bp[0]) 1823308Seric { 1833308Seric case '\0': 1843308Seric case '#': /* comment */ 1853308Seric break; 1863308Seric 1873308Seric case 'R': /* rewriting rule */ 18857135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1893308Seric continue; 1903308Seric 1913308Seric if (*p == '\0') 1925909Seric { 19357135Seric syserr("invalid rewrite line \"%s\"", bp); 1945909Seric break; 1955909Seric } 1965909Seric 1975909Seric /* allocate space for the rule header */ 1985909Seric if (rwp == NULL) 1995909Seric { 2005909Seric RewriteRules[ruleset] = rwp = 2015909Seric (struct rewrite *) xalloc(sizeof *rwp); 2025909Seric } 2033308Seric else 2043308Seric { 2055909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2065909Seric rwp = rwp->r_next; 2075909Seric } 2085909Seric rwp->r_next = NULL; 2093308Seric 2105909Seric /* expand and save the LHS */ 2115909Seric *p = '\0'; 21257135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 21358333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 21457589Seric nfuzzy = 0; 2155909Seric if (rwp->r_lhs != NULL) 21657589Seric { 21757589Seric register char **ap; 21857589Seric 2195909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22057589Seric 22157589Seric /* count the number of fuzzy matches in LHS */ 22257589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22357589Seric { 22458148Seric char *botch; 22558148Seric 22658148Seric botch = NULL; 22758050Seric switch (**ap & 0377) 22857589Seric { 22957589Seric case MATCHZANY: 23057589Seric case MATCHANY: 23157589Seric case MATCHONE: 23257589Seric case MATCHCLASS: 23357589Seric case MATCHNCLASS: 23457589Seric nfuzzy++; 23558148Seric break; 23658148Seric 23758148Seric case MATCHREPL: 23858148Seric botch = "$0-$9"; 23958148Seric break; 24058148Seric 24158148Seric case CANONNET: 24258148Seric botch = "$#"; 24358148Seric break; 24458148Seric 24558148Seric case CANONUSER: 24658148Seric botch = "$:"; 24758148Seric break; 24858148Seric 24958148Seric case CALLSUBR: 25058148Seric botch = "$>"; 25158148Seric break; 25258148Seric 25358148Seric case CONDIF: 25458148Seric botch = "$?"; 25558148Seric break; 25658148Seric 25758148Seric case CONDELSE: 25858148Seric botch = "$|"; 25958148Seric break; 26058148Seric 26158148Seric case CONDFI: 26258148Seric botch = "$."; 26358148Seric break; 26458148Seric 26558148Seric case HOSTBEGIN: 26658148Seric botch = "$["; 26758148Seric break; 26858148Seric 26958148Seric case HOSTEND: 27058148Seric botch = "$]"; 27158148Seric break; 27258148Seric 27358148Seric case LOOKUPBEGIN: 27458148Seric botch = "$("; 27558148Seric break; 27658148Seric 27758148Seric case LOOKUPEND: 27858148Seric botch = "$)"; 27958148Seric break; 28057589Seric } 28158148Seric if (botch != NULL) 28258148Seric syserr("Inappropriate use of %s on LHS", 28358148Seric botch); 28457589Seric } 28557589Seric } 28656678Seric else 28756678Seric syserr("R line: null LHS"); 2885909Seric 2895909Seric /* expand and save the RHS */ 2905909Seric while (*++p == '\t') 2915909Seric continue; 2927231Seric q = p; 2937231Seric while (*p != '\0' && *p != '\t') 2947231Seric p++; 2957231Seric *p = '\0'; 29655012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 29758333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 2985909Seric if (rwp->r_rhs != NULL) 29957589Seric { 30057589Seric register char **ap; 30157589Seric 3025909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30357589Seric 30457589Seric /* check no out-of-bounds replacements */ 30557589Seric nfuzzy += '0'; 30657589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 30757589Seric { 30858148Seric char *botch; 30958148Seric 31058148Seric botch = NULL; 31158148Seric switch (**ap & 0377) 31257589Seric { 31358148Seric case MATCHREPL: 31458148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 31558148Seric { 31658148Seric syserr("replacement $%c out of bounds", 31758148Seric (*ap)[1]); 31858148Seric } 31958148Seric break; 32058148Seric 32158148Seric case MATCHZANY: 32258148Seric botch = "$*"; 32358148Seric break; 32458148Seric 32558148Seric case MATCHANY: 32658148Seric botch = "$+"; 32758148Seric break; 32858148Seric 32958148Seric case MATCHONE: 33058148Seric botch = "$-"; 33158148Seric break; 33258148Seric 33358148Seric case MATCHCLASS: 33458148Seric botch = "$="; 33558148Seric break; 33658148Seric 33758148Seric case MATCHNCLASS: 33858148Seric botch = "$~"; 33958148Seric break; 34057589Seric } 34158148Seric if (botch != NULL) 34258148Seric syserr("Inappropriate use of %s on RHS", 34358148Seric botch); 34457589Seric } 34557589Seric } 34656678Seric else 34756678Seric syserr("R line: null RHS"); 3483308Seric break; 3493308Seric 3504072Seric case 'S': /* select rewriting set */ 35157135Seric ruleset = atoi(&bp[1]); 3528056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3538056Seric { 3549381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3558056Seric ruleset = 0; 3568056Seric } 3574072Seric rwp = NULL; 3584072Seric break; 3594072Seric 3603308Seric case 'D': /* macro definition */ 36158333Seric define(bp[1], newstr(munchstring(&bp[2], NULL)), e); 3623308Seric break; 3633308Seric 3643387Seric case 'H': /* required header line */ 36557135Seric (void) chompheader(&bp[1], TRUE, e); 3663387Seric break; 3673387Seric 3684061Seric case 'C': /* word class */ 3694432Seric /* scan the list of words and set class for all */ 37057135Seric for (p = &bp[2]; *p != '\0'; ) 3714061Seric { 3724061Seric register char *wd; 3734061Seric char delim; 3744061Seric 37558050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3764061Seric p++; 3774061Seric wd = p; 37858050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3794061Seric p++; 3804061Seric delim = *p; 3814061Seric *p = '\0'; 3824061Seric if (wd[0] != '\0') 38358148Seric { 38458148Seric if (tTd(37, 2)) 38558148Seric printf("setclass(%c, %s)\n", 38658148Seric bp[1], wd); 38757135Seric setclass(bp[1], wd); 38858148Seric } 3894061Seric *p = delim; 3904061Seric } 3914061Seric break; 3924061Seric 39359272Seric case 'F': /* word class from file */ 39459272Seric /* read list of words from argument or file */ 39559272Seric /* read from file */ 39659272Seric for (p = &bp[2]; 39759272Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 39859272Seric p++) 39959272Seric continue; 40059272Seric if (*p == '\0') 40159272Seric p = "%s"; 40259272Seric else 40359272Seric { 40459272Seric *p = '\0'; 40559272Seric while (isascii(*++p) && isspace(*p)) 40659272Seric continue; 40759272Seric } 40859272Seric fileclass(bp[1], &bp[2], p, safe); 40959272Seric break; 41059272Seric 41159156Seric #ifdef XLA 41259156Seric case 'L': /* extended load average description */ 41359156Seric xla_init(&bp[1]); 41459156Seric break; 41559156Seric #endif 41659156Seric 4174096Seric case 'M': /* define mailer */ 41857135Seric makemailer(&bp[1]); 4194096Seric break; 4204096Seric 4218252Seric case 'O': /* set option */ 42258734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4238252Seric break; 4248252Seric 4258252Seric case 'P': /* set precedence */ 4268252Seric if (NumPriorities >= MAXPRIORITIES) 4278252Seric { 4288547Seric toomany('P', MAXPRIORITIES); 4298252Seric break; 4308252Seric } 43157135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4328252Seric continue; 4338252Seric if (*p == '\0') 4348252Seric goto badline; 4358252Seric *p = '\0'; 43657135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4378252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4388252Seric NumPriorities++; 4398252Seric break; 4408252Seric 4418547Seric case 'T': /* trusted user(s) */ 44258161Seric /* this option is obsolete, but will be ignored */ 4438547Seric break; 4448547Seric 44552645Seric case 'V': /* configuration syntax version */ 44657135Seric ConfigLevel = atoi(&bp[1]); 44752645Seric break; 44852645Seric 44953654Seric case 'K': 45057135Seric makemapentry(&bp[1]); 45153654Seric break; 45253654Seric 4533308Seric default: 4544061Seric badline: 45557135Seric syserr("unknown control line \"%s\"", bp); 4563308Seric } 45757135Seric if (bp != buf) 45857135Seric free(bp); 4593308Seric } 46052637Seric if (ferror(cf)) 46152637Seric { 46252647Seric syserr("I/O read error", cfname); 46352637Seric exit(EX_OSFILE); 46452637Seric } 46552637Seric fclose(cf); 4669381Seric FileName = NULL; 46756836Seric 46857076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 46957076Seric { 47057076Seric /* user didn't initialize: set up host map */ 47157076Seric strcpy(buf, "host host"); 47257076Seric if (ConfigLevel >= 2) 47357076Seric strcat(buf, " -a."); 47457076Seric makemapentry(buf); 47557076Seric } 4764096Seric } 4774096Seric /* 4788547Seric ** TOOMANY -- signal too many of some option 4798547Seric ** 4808547Seric ** Parameters: 4818547Seric ** id -- the id of the error line 4828547Seric ** maxcnt -- the maximum possible values 4838547Seric ** 4848547Seric ** Returns: 4858547Seric ** none. 4868547Seric ** 4878547Seric ** Side Effects: 4888547Seric ** gives a syserr. 4898547Seric */ 4908547Seric 4918547Seric toomany(id, maxcnt) 4928547Seric char id; 4938547Seric int maxcnt; 4948547Seric { 4959381Seric syserr("too many %c lines, %d max", id, maxcnt); 4968547Seric } 4978547Seric /* 4984432Seric ** FILECLASS -- read members of a class from a file 4994432Seric ** 5004432Seric ** Parameters: 5014432Seric ** class -- class to define. 5024432Seric ** filename -- name of file to read. 5034432Seric ** fmt -- scanf string to use for match. 5044432Seric ** 5054432Seric ** Returns: 5064432Seric ** none 5074432Seric ** 5084432Seric ** Side Effects: 5094432Seric ** 5104432Seric ** puts all lines in filename that match a scanf into 5114432Seric ** the named class. 5124432Seric */ 5134432Seric 51454973Seric fileclass(class, filename, fmt, safe) 5154432Seric int class; 5164432Seric char *filename; 5174432Seric char *fmt; 51854973Seric bool safe; 5194432Seric { 52025808Seric FILE *f; 52154973Seric struct stat stbuf; 5224432Seric char buf[MAXLINE]; 5234432Seric 52454973Seric if (stat(filename, &stbuf) < 0) 52554973Seric { 52654973Seric syserr("fileclass: cannot stat %s", filename); 52754973Seric return; 52854973Seric } 52954973Seric if (!S_ISREG(stbuf.st_mode)) 53054973Seric { 53154973Seric syserr("fileclass: %s not a regular file", filename); 53254973Seric return; 53354973Seric } 53454973Seric if (!safe && access(filename, R_OK) < 0) 53554973Seric { 53654973Seric syserr("fileclass: access denied on %s", filename); 53754973Seric return; 53854973Seric } 53954973Seric f = fopen(filename, "r"); 5404432Seric if (f == NULL) 5414432Seric { 54254973Seric syserr("fileclass: cannot open %s", filename); 5434432Seric return; 5444432Seric } 5454432Seric 5464432Seric while (fgets(buf, sizeof buf, f) != NULL) 5474432Seric { 5484432Seric register STAB *s; 54925808Seric register char *p; 55025808Seric # ifdef SCANF 5514432Seric char wordbuf[MAXNAME+1]; 5524432Seric 5534432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5544432Seric continue; 55525808Seric p = wordbuf; 55656795Seric # else /* SCANF */ 55725808Seric p = buf; 55856795Seric # endif /* SCANF */ 55925808Seric 56025808Seric /* 56125808Seric ** Break up the match into words. 56225808Seric */ 56325808Seric 56425808Seric while (*p != '\0') 56525808Seric { 56625808Seric register char *q; 56725808Seric 56825808Seric /* strip leading spaces */ 56958050Seric while (isascii(*p) && isspace(*p)) 57025808Seric p++; 57125808Seric if (*p == '\0') 57225808Seric break; 57325808Seric 57425808Seric /* find the end of the word */ 57525808Seric q = p; 57658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 57725808Seric p++; 57825808Seric if (*p != '\0') 57925808Seric *p++ = '\0'; 58025808Seric 58125808Seric /* enter the word in the symbol table */ 58225808Seric s = stab(q, ST_CLASS, ST_ENTER); 58325808Seric setbitn(class, s->s_class); 58425808Seric } 5854432Seric } 5864432Seric 58754973Seric (void) fclose(f); 5884432Seric } 5894432Seric /* 5904096Seric ** MAKEMAILER -- define a new mailer. 5914096Seric ** 5924096Seric ** Parameters: 59310327Seric ** line -- description of mailer. This is in labeled 59410327Seric ** fields. The fields are: 59510327Seric ** P -- the path to the mailer 59610327Seric ** F -- the flags associated with the mailer 59710327Seric ** A -- the argv for this mailer 59810327Seric ** S -- the sender rewriting set 59910327Seric ** R -- the recipient rewriting set 60010327Seric ** E -- the eol string 60110327Seric ** The first word is the canonical name of the mailer. 6024096Seric ** 6034096Seric ** Returns: 6044096Seric ** none. 6054096Seric ** 6064096Seric ** Side Effects: 6074096Seric ** enters the mailer into the mailer table. 6084096Seric */ 6093308Seric 61021066Seric makemailer(line) 6114096Seric char *line; 6124096Seric { 6134096Seric register char *p; 6148067Seric register struct mailer *m; 6158067Seric register STAB *s; 6168067Seric int i; 61710327Seric char fcode; 61858020Seric auto char *endp; 6194096Seric extern int NextMailer; 62010327Seric extern char **makeargv(); 62110327Seric extern char *munchstring(); 62210701Seric extern long atol(); 6234096Seric 62410327Seric /* allocate a mailer and set up defaults */ 62510327Seric m = (struct mailer *) xalloc(sizeof *m); 62610327Seric bzero((char *) m, sizeof *m); 62710327Seric m->m_eol = "\n"; 62810327Seric 62910327Seric /* collect the mailer name */ 63058050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 63110327Seric continue; 63210327Seric if (*p != '\0') 63310327Seric *p++ = '\0'; 63410327Seric m->m_name = newstr(line); 63510327Seric 63610327Seric /* now scan through and assign info from the fields */ 63710327Seric while (*p != '\0') 63810327Seric { 63958333Seric auto char *delimptr; 64058333Seric 64158050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 64210327Seric p++; 64310327Seric 64410327Seric /* p now points to field code */ 64510327Seric fcode = *p; 64610327Seric while (*p != '\0' && *p != '=' && *p != ',') 64710327Seric p++; 64810327Seric if (*p++ != '=') 64910327Seric { 65052637Seric syserr("mailer %s: `=' expected", m->m_name); 65110327Seric return; 65210327Seric } 65358050Seric while (isascii(*p) && isspace(*p)) 65410327Seric p++; 65510327Seric 65610327Seric /* p now points to the field body */ 65758333Seric p = munchstring(p, &delimptr); 65810327Seric 65910327Seric /* install the field into the mailer struct */ 66010327Seric switch (fcode) 66110327Seric { 66210327Seric case 'P': /* pathname */ 66310327Seric m->m_mailer = newstr(p); 66410327Seric break; 66510327Seric 66610327Seric case 'F': /* flags */ 66710687Seric for (; *p != '\0'; p++) 66858050Seric if (!(isascii(*p) && isspace(*p))) 66952637Seric setbitn(*p, m->m_flags); 67010327Seric break; 67110327Seric 67210327Seric case 'S': /* sender rewriting ruleset */ 67310327Seric case 'R': /* recipient rewriting ruleset */ 67458020Seric i = strtol(p, &endp, 10); 67510327Seric if (i < 0 || i >= MAXRWSETS) 67610327Seric { 67710327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 67810327Seric return; 67910327Seric } 68010327Seric if (fcode == 'S') 68158020Seric m->m_sh_rwset = m->m_se_rwset = i; 68210327Seric else 68358020Seric m->m_rh_rwset = m->m_re_rwset = i; 68458020Seric 68558020Seric p = endp; 68659985Seric if (*p++ == '/') 68758020Seric { 68858020Seric i = strtol(p, NULL, 10); 68958020Seric if (i < 0 || i >= MAXRWSETS) 69058020Seric { 69158020Seric syserr("invalid rewrite set, %d max", 69258020Seric MAXRWSETS); 69358020Seric return; 69458020Seric } 69558020Seric if (fcode == 'S') 69658020Seric m->m_sh_rwset = i; 69758020Seric else 69858020Seric m->m_rh_rwset = i; 69958020Seric } 70010327Seric break; 70110327Seric 70210327Seric case 'E': /* end of line string */ 70310327Seric m->m_eol = newstr(p); 70410327Seric break; 70510327Seric 70610327Seric case 'A': /* argument vector */ 70710327Seric m->m_argv = makeargv(p); 70810327Seric break; 70910701Seric 71010701Seric case 'M': /* maximum message size */ 71110701Seric m->m_maxsize = atol(p); 71210701Seric break; 71352106Seric 71452106Seric case 'L': /* maximum line length */ 71552106Seric m->m_linelimit = atoi(p); 71652106Seric break; 71758935Seric 71858935Seric case 'D': /* working directory */ 71958935Seric m->m_execdir = newstr(p); 72058935Seric break; 72110327Seric } 72210327Seric 72358333Seric p = delimptr; 72410327Seric } 72510327Seric 72652106Seric /* do some heuristic cleanup for back compatibility */ 72752106Seric if (bitnset(M_LIMITS, m->m_flags)) 72852106Seric { 72952106Seric if (m->m_linelimit == 0) 73052106Seric m->m_linelimit = SMTPLINELIM; 73155418Seric if (ConfigLevel < 2) 73252106Seric setbitn(M_7BITS, m->m_flags); 73352106Seric } 73452106Seric 73558321Seric /* do some rationality checking */ 73658321Seric if (m->m_argv == NULL) 73758321Seric { 73858321Seric syserr("M%s: A= argument required", m->m_name); 73958321Seric return; 74058321Seric } 74158321Seric if (m->m_mailer == NULL) 74258321Seric { 74358321Seric syserr("M%s: P= argument required", m->m_name); 74458321Seric return; 74558321Seric } 74658321Seric 7474096Seric if (NextMailer >= MAXMAILERS) 7484096Seric { 7499381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7504096Seric return; 7514096Seric } 75257402Seric 75310327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 75457402Seric if (s->s_mailer != NULL) 75557402Seric { 75657402Seric i = s->s_mailer->m_mno; 75757402Seric free(s->s_mailer); 75857402Seric } 75957402Seric else 76057402Seric { 76157402Seric i = NextMailer++; 76257402Seric } 76357402Seric Mailer[i] = s->s_mailer = m; 76457454Seric m->m_mno = i; 76510327Seric } 76610327Seric /* 76710327Seric ** MUNCHSTRING -- translate a string into internal form. 76810327Seric ** 76910327Seric ** Parameters: 77010327Seric ** p -- the string to munch. 77158333Seric ** delimptr -- if non-NULL, set to the pointer of the 77258333Seric ** field delimiter character. 77310327Seric ** 77410327Seric ** Returns: 77510327Seric ** the munched string. 77610327Seric */ 7774096Seric 77810327Seric char * 77958333Seric munchstring(p, delimptr) 78010327Seric register char *p; 78158333Seric char **delimptr; 78210327Seric { 78310327Seric register char *q; 78410327Seric bool backslash = FALSE; 78510327Seric bool quotemode = FALSE; 78610327Seric static char buf[MAXLINE]; 7874096Seric 78810327Seric for (q = buf; *p != '\0'; p++) 7894096Seric { 79010327Seric if (backslash) 79110327Seric { 79210327Seric /* everything is roughly literal */ 79310357Seric backslash = FALSE; 79410327Seric switch (*p) 79510327Seric { 79610327Seric case 'r': /* carriage return */ 79710327Seric *q++ = '\r'; 79810327Seric continue; 79910327Seric 80010327Seric case 'n': /* newline */ 80110327Seric *q++ = '\n'; 80210327Seric continue; 80310327Seric 80410327Seric case 'f': /* form feed */ 80510327Seric *q++ = '\f'; 80610327Seric continue; 80710327Seric 80810327Seric case 'b': /* backspace */ 80910327Seric *q++ = '\b'; 81010327Seric continue; 81110327Seric } 81210327Seric *q++ = *p; 81310327Seric } 81410327Seric else 81510327Seric { 81610327Seric if (*p == '\\') 81710327Seric backslash = TRUE; 81810327Seric else if (*p == '"') 81910327Seric quotemode = !quotemode; 82010327Seric else if (quotemode || *p != ',') 82110327Seric *q++ = *p; 82210327Seric else 82310327Seric break; 82410327Seric } 8254096Seric } 8264096Seric 82758333Seric if (delimptr != NULL) 82858333Seric *delimptr = p; 82910327Seric *q++ = '\0'; 83010327Seric return (buf); 83110327Seric } 83210327Seric /* 83310327Seric ** MAKEARGV -- break up a string into words 83410327Seric ** 83510327Seric ** Parameters: 83610327Seric ** p -- the string to break up. 83710327Seric ** 83810327Seric ** Returns: 83910327Seric ** a char **argv (dynamically allocated) 84010327Seric ** 84110327Seric ** Side Effects: 84210327Seric ** munges p. 84310327Seric */ 8444096Seric 84510327Seric char ** 84610327Seric makeargv(p) 84710327Seric register char *p; 84810327Seric { 84910327Seric char *q; 85010327Seric int i; 85110327Seric char **avp; 85210327Seric char *argv[MAXPV + 1]; 85310327Seric 85410327Seric /* take apart the words */ 85510327Seric i = 0; 85610327Seric while (*p != '\0' && i < MAXPV) 8574096Seric { 85810327Seric q = p; 85958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 86010327Seric p++; 86158050Seric while (isascii(*p) && isspace(*p)) 86210327Seric *p++ = '\0'; 86310327Seric argv[i++] = newstr(q); 8644096Seric } 86510327Seric argv[i++] = NULL; 8664096Seric 86710327Seric /* now make a copy of the argv */ 86810327Seric avp = (char **) xalloc(sizeof *avp * i); 86916893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 87010327Seric 87110327Seric return (avp); 8723308Seric } 8733308Seric /* 8743308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8753308Seric ** 8763308Seric ** Parameters: 8773308Seric ** none. 8783308Seric ** 8793308Seric ** Returns: 8803308Seric ** none. 8813308Seric ** 8823308Seric ** Side Effects: 8833308Seric ** prints rewrite rules. 8843308Seric */ 8853308Seric 8863308Seric printrules() 8873308Seric { 8883308Seric register struct rewrite *rwp; 8894072Seric register int ruleset; 8903308Seric 8914072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8923308Seric { 8934072Seric if (RewriteRules[ruleset] == NULL) 8944072Seric continue; 8958067Seric printf("\n----Rule Set %d:", ruleset); 8963308Seric 8974072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 8983308Seric { 8998067Seric printf("\nLHS:"); 9008067Seric printav(rwp->r_lhs); 9018067Seric printf("RHS:"); 9028067Seric printav(rwp->r_rhs); 9033308Seric } 9043308Seric } 9053308Seric } 9064319Seric 9074096Seric /* 9088256Seric ** SETOPTION -- set global processing option 9098256Seric ** 9108256Seric ** Parameters: 9118256Seric ** opt -- option name. 9128256Seric ** val -- option value (as a text string). 91321755Seric ** safe -- set if this came from a configuration file. 91421755Seric ** Some options (if set from the command line) will 91521755Seric ** reset the user id to avoid security problems. 9168269Seric ** sticky -- if set, don't let other setoptions override 9178269Seric ** this value. 91858734Seric ** e -- the main envelope. 9198256Seric ** 9208256Seric ** Returns: 9218256Seric ** none. 9228256Seric ** 9238256Seric ** Side Effects: 9248256Seric ** Sets options as implied by the arguments. 9258256Seric */ 9268256Seric 92710687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9288269Seric 92957207Seric 93057207Seric #ifdef NAMED_BIND 93157207Seric 93257207Seric struct resolverflags 93357207Seric { 93457207Seric char *rf_name; /* name of the flag */ 93557207Seric long rf_bits; /* bits to set/clear */ 93657207Seric } ResolverFlags[] = 93757207Seric { 93857207Seric "debug", RES_DEBUG, 93957207Seric "aaonly", RES_AAONLY, 94057207Seric "usevc", RES_USEVC, 94157207Seric "primary", RES_PRIMARY, 94257207Seric "igntc", RES_IGNTC, 94357207Seric "recurse", RES_RECURSE, 94457207Seric "defnames", RES_DEFNAMES, 94557207Seric "stayopen", RES_STAYOPEN, 94657207Seric "dnsrch", RES_DNSRCH, 94757207Seric NULL, 0 94857207Seric }; 94957207Seric 95057207Seric #endif 95157207Seric 95258734Seric setoption(opt, val, safe, sticky, e) 9538256Seric char opt; 9548256Seric char *val; 95521755Seric bool safe; 9568269Seric bool sticky; 95758734Seric register ENVELOPE *e; 9588256Seric { 95957207Seric register char *p; 9608265Seric extern bool atobool(); 96112633Seric extern time_t convtime(); 96214879Seric extern int QueueLA; 96314879Seric extern int RefuseLA; 96417474Seric extern bool trusteduser(); 96517474Seric extern char *username(); 9668256Seric 9678256Seric if (tTd(37, 1)) 9689341Seric printf("setoption %c=%s", opt, val); 9698256Seric 9708256Seric /* 9718269Seric ** See if this option is preset for us. 9728256Seric */ 9738256Seric 97459731Seric if (!sticky && bitnset(opt, StickyOpt)) 9758269Seric { 9769341Seric if (tTd(37, 1)) 9779341Seric printf(" (ignored)\n"); 9788269Seric return; 9798269Seric } 9808269Seric 98121755Seric /* 98221755Seric ** Check to see if this option can be specified by this user. 98321755Seric */ 98421755Seric 98536238Skarels if (!safe && getuid() == 0) 98621755Seric safe = TRUE; 98759730Seric if (!safe && strchr("bdeEijLmoprsvC7", opt) == NULL) 98821755Seric { 98939111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 99021755Seric { 99136582Sbostic if (tTd(37, 1)) 99236582Sbostic printf(" (unsafe)"); 99336582Sbostic if (getuid() != geteuid()) 99436582Sbostic { 99551210Seric if (tTd(37, 1)) 99651210Seric printf("(Resetting uid)"); 99736582Sbostic (void) setgid(getgid()); 99836582Sbostic (void) setuid(getuid()); 99936582Sbostic } 100021755Seric } 100121755Seric } 100251210Seric if (tTd(37, 1)) 100317985Seric printf("\n"); 10048269Seric 10058256Seric switch (opt) 10068256Seric { 100759709Seric case '7': /* force seven-bit input */ 100859709Seric SevenBit = atobool(val); 100952106Seric break; 101052106Seric 10118256Seric case 'A': /* set default alias file */ 10129381Seric if (val[0] == '\0') 101359672Seric setalias("aliases"); 10149381Seric else 101559672Seric setalias(val); 10168256Seric break; 10178256Seric 101817474Seric case 'a': /* look N minutes for "@:@" in alias file */ 101917474Seric if (val[0] == '\0') 102017474Seric SafeAlias = 5; 102117474Seric else 102217474Seric SafeAlias = atoi(val); 102317474Seric break; 102417474Seric 102516843Seric case 'B': /* substitution for blank character */ 102616843Seric SpaceSub = val[0]; 102716843Seric if (SpaceSub == '\0') 102816843Seric SpaceSub = ' '; 102916843Seric break; 103016843Seric 103159283Seric case 'b': /* min blocks free on queue fs/max msg size */ 103259283Seric p = strchr(val, '/'); 103359283Seric if (p != NULL) 103459283Seric { 103559283Seric *p++ = '\0'; 103659283Seric MaxMessageSize = atol(p); 103759283Seric } 103858082Seric MinBlocksFree = atol(val); 103958082Seric break; 104058082Seric 10419284Seric case 'c': /* don't connect to "expensive" mailers */ 10429381Seric NoConnect = atobool(val); 10439284Seric break; 10449284Seric 104551305Seric case 'C': /* checkpoint every N addresses */ 104651305Seric CheckpointInterval = atoi(val); 104724944Seric break; 104824944Seric 10499284Seric case 'd': /* delivery mode */ 10509284Seric switch (*val) 10518269Seric { 10529284Seric case '\0': 105358734Seric e->e_sendmode = SM_DELIVER; 10548269Seric break; 10558269Seric 105610755Seric case SM_QUEUE: /* queue only */ 105710755Seric #ifndef QUEUE 105810755Seric syserr("need QUEUE to set -odqueue"); 105956795Seric #endif /* QUEUE */ 106010755Seric /* fall through..... */ 106110755Seric 10629284Seric case SM_DELIVER: /* do everything */ 10639284Seric case SM_FORK: /* fork after verification */ 106458734Seric e->e_sendmode = *val; 10658269Seric break; 10668269Seric 10678269Seric default: 10689284Seric syserr("Unknown delivery mode %c", *val); 10698269Seric exit(EX_USAGE); 10708269Seric } 10718269Seric break; 10728269Seric 10739146Seric case 'D': /* rebuild alias database as needed */ 10749381Seric AutoRebuild = atobool(val); 10759146Seric break; 10769146Seric 107755372Seric case 'E': /* error message header/header file */ 107855379Seric if (*val != '\0') 107955379Seric ErrMsgFile = newstr(val); 108055372Seric break; 108155372Seric 10828269Seric case 'e': /* set error processing mode */ 10838269Seric switch (*val) 10848269Seric { 10859381Seric case EM_QUIET: /* be silent about it */ 10869381Seric case EM_MAIL: /* mail back */ 10879381Seric case EM_BERKNET: /* do berknet error processing */ 10889381Seric case EM_WRITE: /* write back (or mail) */ 10898269Seric HoldErrs = TRUE; 10909381Seric /* fall through... */ 10918269Seric 10929381Seric case EM_PRINT: /* print errors normally (default) */ 109358734Seric e->e_errormode = *val; 10948269Seric break; 10958269Seric } 10968269Seric break; 10978269Seric 10989049Seric case 'F': /* file mode */ 109917975Seric FileMode = atooct(val) & 0777; 11009049Seric break; 11019049Seric 11028269Seric case 'f': /* save Unix-style From lines on front */ 11039381Seric SaveFrom = atobool(val); 11048269Seric break; 11058269Seric 110653735Seric case 'G': /* match recipients against GECOS field */ 110753735Seric MatchGecos = atobool(val); 110853735Seric break; 110953735Seric 11108256Seric case 'g': /* default gid */ 111117474Seric DefGid = atoi(val); 11128256Seric break; 11138256Seric 11148256Seric case 'H': /* help file */ 11159381Seric if (val[0] == '\0') 11168269Seric HelpFile = "sendmail.hf"; 11179381Seric else 11189381Seric HelpFile = newstr(val); 11198256Seric break; 11208256Seric 112151305Seric case 'h': /* maximum hop count */ 112251305Seric MaxHopCount = atoi(val); 112351305Seric break; 112451305Seric 112535651Seric case 'I': /* use internet domain name server */ 112657207Seric #ifdef NAMED_BIND 112757207Seric UseNameServer = TRUE; 112857207Seric for (p = val; *p != 0; ) 112957207Seric { 113057207Seric bool clearmode; 113157207Seric char *q; 113257207Seric struct resolverflags *rfp; 113357207Seric 113457207Seric while (*p == ' ') 113557207Seric p++; 113657207Seric if (*p == '\0') 113757207Seric break; 113857207Seric clearmode = FALSE; 113957207Seric if (*p == '-') 114057207Seric clearmode = TRUE; 114157207Seric else if (*p != '+') 114257207Seric p--; 114357207Seric p++; 114457207Seric q = p; 114558050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114657207Seric p++; 114757207Seric if (*p != '\0') 114857207Seric *p++ = '\0'; 114957207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 115057207Seric { 115157207Seric if (strcasecmp(q, rfp->rf_name) == 0) 115257207Seric break; 115357207Seric } 115457207Seric if (clearmode) 115557207Seric _res.options &= ~rfp->rf_bits; 115657207Seric else 115757207Seric _res.options |= rfp->rf_bits; 115857207Seric } 115957207Seric if (tTd(8, 2)) 116057207Seric printf("_res.options = %x\n", _res.options); 116157207Seric #else 116257207Seric usrerr("name server (I option) specified but BIND not compiled in"); 116357207Seric #endif 116435651Seric break; 116535651Seric 11668269Seric case 'i': /* ignore dot lines in message */ 11679381Seric IgnrDot = atobool(val); 11688269Seric break; 11698269Seric 117059730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 117159730Seric SendMIMEErrors = atobool(val); 117259730Seric break; 117359730Seric 117457136Seric case 'J': /* .forward search path */ 117557136Seric ForwardPath = newstr(val); 117657136Seric break; 117757136Seric 117854967Seric case 'k': /* connection cache size */ 117954967Seric MaxMciCache = atoi(val); 118056215Seric if (MaxMciCache < 0) 118156215Seric MaxMciCache = 0; 118254967Seric break; 118354967Seric 118454967Seric case 'K': /* connection cache timeout */ 118558796Seric MciCacheTimeout = convtime(val, 'm'); 118654967Seric break; 118754967Seric 11888256Seric case 'L': /* log level */ 11899381Seric LogLevel = atoi(val); 11908256Seric break; 11918256Seric 11928269Seric case 'M': /* define macro */ 11939381Seric define(val[0], newstr(&val[1]), CurEnv); 119416878Seric sticky = FALSE; 11958269Seric break; 11968269Seric 11978269Seric case 'm': /* send to me too */ 11989381Seric MeToo = atobool(val); 11998269Seric break; 12008269Seric 120125820Seric case 'n': /* validate RHS in newaliases */ 120225820Seric CheckAliases = atobool(val); 120325820Seric break; 120425820Seric 120558851Seric case 'O': /* daemon options */ 120658851Seric setdaemonoptions(val); 120758851Seric break; 120858851Seric 12098269Seric case 'o': /* assume old style headers */ 12109381Seric if (atobool(val)) 12119341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12129341Seric else 12139341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12148269Seric break; 12158269Seric 121658082Seric case 'p': /* select privacy level */ 121758082Seric p = val; 121858082Seric for (;;) 121958082Seric { 122058082Seric register struct prival *pv; 122158082Seric extern struct prival PrivacyValues[]; 122258082Seric 122358082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 122458082Seric p++; 122558082Seric if (*p == '\0') 122658082Seric break; 122758082Seric val = p; 122858082Seric while (isascii(*p) && isalnum(*p)) 122958082Seric p++; 123058082Seric if (*p != '\0') 123158082Seric *p++ = '\0'; 123258082Seric 123358082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 123458082Seric { 123558082Seric if (strcasecmp(val, pv->pv_name) == 0) 123658082Seric break; 123758082Seric } 123858886Seric if (pv->pv_name == NULL) 123958886Seric syserr("readcf: Op line: %s unrecognized", val); 124058082Seric PrivacyFlags |= pv->pv_flag; 124158082Seric } 124258082Seric break; 124358082Seric 124424944Seric case 'P': /* postmaster copy address for returned mail */ 124524944Seric PostMasterCopy = newstr(val); 124624944Seric break; 124724944Seric 124824944Seric case 'q': /* slope of queue only function */ 124924944Seric QueueFactor = atoi(val); 125024944Seric break; 125124944Seric 12528256Seric case 'Q': /* queue directory */ 12539381Seric if (val[0] == '\0') 12548269Seric QueueDir = "mqueue"; 12559381Seric else 12569381Seric QueueDir = newstr(val); 125758789Seric if (RealUid != 0 && !safe) 125858789Seric auth_warning(e, "Processed from queue %s", QueueDir); 12598256Seric break; 12608256Seric 126158148Seric case 'R': /* don't prune routes */ 126258148Seric DontPruneRoutes = atobool(val); 126358148Seric break; 126458148Seric 12658256Seric case 'r': /* read timeout */ 126658112Seric settimeouts(val); 12678256Seric break; 12688256Seric 12698256Seric case 'S': /* status file */ 12709381Seric if (val[0] == '\0') 12718269Seric StatFile = "sendmail.st"; 12729381Seric else 12739381Seric StatFile = newstr(val); 12748256Seric break; 12758256Seric 12768265Seric case 's': /* be super safe, even if expensive */ 12779381Seric SuperSafe = atobool(val); 12788256Seric break; 12798256Seric 12808256Seric case 'T': /* queue timeout */ 128158737Seric p = strchr(val, '/'); 128258737Seric if (p != NULL) 128358737Seric { 128458737Seric *p++ = '\0'; 128558796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 128658737Seric } 128758796Seric TimeOuts.to_q_return = convtime(val, 'h'); 128854967Seric break; 12898256Seric 12908265Seric case 't': /* time zone name */ 129152106Seric TimeZoneSpec = newstr(val); 12928265Seric break; 12938265Seric 129450556Seric case 'U': /* location of user database */ 129551360Seric UdbSpec = newstr(val); 129650556Seric break; 129750556Seric 12988256Seric case 'u': /* set default uid */ 129917474Seric DefUid = atoi(val); 130040973Sbostic setdefuser(); 13018256Seric break; 13028256Seric 130358851Seric case 'V': /* fallback MX host */ 130458851Seric FallBackMX = newstr(val); 130558851Seric break; 130658851Seric 13078269Seric case 'v': /* run in verbose mode */ 13089381Seric Verbose = atobool(val); 13098256Seric break; 13108256Seric 131114879Seric case 'x': /* load avg at which to auto-queue msgs */ 131214879Seric QueueLA = atoi(val); 131314879Seric break; 131414879Seric 131514879Seric case 'X': /* load avg at which to auto-reject connections */ 131614879Seric RefuseLA = atoi(val); 131714879Seric break; 131814879Seric 131924981Seric case 'y': /* work recipient factor */ 132024981Seric WkRecipFact = atoi(val); 132124981Seric break; 132224981Seric 132324981Seric case 'Y': /* fork jobs during queue runs */ 132424952Seric ForkQueueRuns = atobool(val); 132524952Seric break; 132624952Seric 132724981Seric case 'z': /* work message class factor */ 132824981Seric WkClassFact = atoi(val); 132924981Seric break; 133024981Seric 133124981Seric case 'Z': /* work time factor */ 133224981Seric WkTimeFact = atoi(val); 133324981Seric break; 133424981Seric 13358256Seric default: 13368256Seric break; 13378256Seric } 133816878Seric if (sticky) 133916878Seric setbitn(opt, StickyOpt); 13409188Seric return; 13418256Seric } 134210687Seric /* 134310687Seric ** SETCLASS -- set a word into a class 134410687Seric ** 134510687Seric ** Parameters: 134610687Seric ** class -- the class to put the word in. 134710687Seric ** word -- the word to enter 134810687Seric ** 134910687Seric ** Returns: 135010687Seric ** none. 135110687Seric ** 135210687Seric ** Side Effects: 135310687Seric ** puts the word into the symbol table. 135410687Seric */ 135510687Seric 135610687Seric setclass(class, word) 135710687Seric int class; 135810687Seric char *word; 135910687Seric { 136010687Seric register STAB *s; 136110687Seric 136257943Seric if (tTd(37, 8)) 136357943Seric printf("%s added to class %c\n", word, class); 136410687Seric s = stab(word, ST_CLASS, ST_ENTER); 136510687Seric setbitn(class, s->s_class); 136610687Seric } 136753654Seric /* 136853654Seric ** MAKEMAPENTRY -- create a map entry 136953654Seric ** 137053654Seric ** Parameters: 137153654Seric ** line -- the config file line 137253654Seric ** 137353654Seric ** Returns: 137453654Seric ** TRUE if it successfully entered the map entry. 137553654Seric ** FALSE otherwise (usually syntax error). 137653654Seric ** 137753654Seric ** Side Effects: 137853654Seric ** Enters the map into the dictionary. 137953654Seric */ 138053654Seric 138153654Seric void 138253654Seric makemapentry(line) 138353654Seric char *line; 138453654Seric { 138553654Seric register char *p; 138653654Seric char *mapname; 138753654Seric char *classname; 138853654Seric register STAB *map; 138953654Seric STAB *class; 139053654Seric 139158050Seric for (p = line; isascii(*p) && isspace(*p); p++) 139253654Seric continue; 139358050Seric if (!(isascii(*p) && isalnum(*p))) 139453654Seric { 139553654Seric syserr("readcf: config K line: no map name"); 139653654Seric return; 139753654Seric } 139853654Seric 139953654Seric mapname = p; 140058050Seric while (isascii(*++p) && isalnum(*p)) 140153654Seric continue; 140253654Seric if (*p != '\0') 140353654Seric *p++ = '\0'; 140458050Seric while (isascii(*p) && isspace(*p)) 140553654Seric p++; 140658050Seric if (!(isascii(*p) && isalnum(*p))) 140753654Seric { 140853654Seric syserr("readcf: config K line, map %s: no map class", mapname); 140953654Seric return; 141053654Seric } 141153654Seric classname = p; 141258050Seric while (isascii(*++p) && isalnum(*p)) 141353654Seric continue; 141453654Seric if (*p != '\0') 141553654Seric *p++ = '\0'; 141658050Seric while (isascii(*p) && isspace(*p)) 141753654Seric p++; 141853654Seric 141953654Seric /* look up the class */ 142053654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 142153654Seric if (class == NULL) 142253654Seric { 142353654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 142453654Seric return; 142553654Seric } 142653654Seric 142753654Seric /* enter the map */ 142853654Seric map = stab(mapname, ST_MAP, ST_ENTER); 1429*60207Seric map->s_map.map_class = &class->s_mapclass; 143060089Seric map->s_map.map_mname = newstr(mapname); 143153654Seric 1432*60207Seric if ((*class->s_mapclass.map_parse)(&map->s_map, p)) 1433*60207Seric map->s_map.map_mflags |= MF_VALID; 143453654Seric } 143558112Seric /* 143658112Seric ** SETTIMEOUTS -- parse and set timeout values 143758112Seric ** 143858112Seric ** Parameters: 143958112Seric ** val -- a pointer to the values. If NULL, do initial 144058112Seric ** settings. 144158112Seric ** 144258112Seric ** Returns: 144358112Seric ** none. 144458112Seric ** 144558112Seric ** Side Effects: 144658112Seric ** Initializes the TimeOuts structure 144758112Seric */ 144858112Seric 144958112Seric #define MINUTES * 60 145058112Seric #define HOUR * 3600 145158112Seric 145258112Seric settimeouts(val) 145358112Seric register char *val; 145458112Seric { 145558112Seric register char *p; 145658671Seric extern time_t convtime(); 145758112Seric 145858112Seric if (val == NULL) 145958112Seric { 146058112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 146158112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 146258112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 146358112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 146458112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 146558112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 146658112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 146758112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 146858112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 146958112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 147058112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 147158112Seric return; 147258112Seric } 147358112Seric 147458112Seric for (;; val = p) 147558112Seric { 147658112Seric while (isascii(*val) && isspace(*val)) 147758112Seric val++; 147858112Seric if (*val == '\0') 147958112Seric break; 148058112Seric for (p = val; *p != '\0' && *p != ','; p++) 148158112Seric continue; 148258112Seric if (*p != '\0') 148358112Seric *p++ = '\0'; 148458112Seric 148558112Seric if (isascii(*val) && isdigit(*val)) 148658112Seric { 148758112Seric /* old syntax -- set everything */ 148858796Seric TimeOuts.to_mail = convtime(val, 'm'); 148958112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 149058112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 149158112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 149258112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 149358112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 149458112Seric continue; 149558112Seric } 149658112Seric else 149758112Seric { 149858112Seric register char *q = strchr(val, '='); 149958112Seric time_t to; 150058112Seric 150158112Seric if (q == NULL) 150258112Seric { 150358112Seric /* syntax error */ 150458112Seric continue; 150558112Seric } 150658112Seric *q++ = '\0'; 150758796Seric to = convtime(q, 'm'); 150858112Seric 150958112Seric if (strcasecmp(val, "initial") == 0) 151058112Seric TimeOuts.to_initial = to; 151158112Seric else if (strcasecmp(val, "mail") == 0) 151258112Seric TimeOuts.to_mail = to; 151358112Seric else if (strcasecmp(val, "rcpt") == 0) 151458112Seric TimeOuts.to_rcpt = to; 151558112Seric else if (strcasecmp(val, "datainit") == 0) 151658112Seric TimeOuts.to_datainit = to; 151758112Seric else if (strcasecmp(val, "datablock") == 0) 151858112Seric TimeOuts.to_datablock = to; 151958112Seric else if (strcasecmp(val, "datafinal") == 0) 152058112Seric TimeOuts.to_datafinal = to; 152158112Seric else if (strcasecmp(val, "command") == 0) 152258112Seric TimeOuts.to_nextcommand = to; 152358112Seric else if (strcasecmp(val, "rset") == 0) 152458112Seric TimeOuts.to_rset = to; 152558112Seric else if (strcasecmp(val, "helo") == 0) 152658112Seric TimeOuts.to_helo = to; 152758112Seric else if (strcasecmp(val, "quit") == 0) 152858112Seric TimeOuts.to_quit = to; 152958112Seric else if (strcasecmp(val, "misc") == 0) 153058112Seric TimeOuts.to_miscshort = to; 153158112Seric else 153258112Seric syserr("settimeouts: invalid timeout %s", val); 153358112Seric } 153458112Seric } 153558112Seric } 1536