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*58734Seric static char sccsid[] = "@(#)readcf.c 6.18 (Berkeley) 03/19/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1452647Seric # include <sys/stat.h> 1557207Seric #ifdef NAMED_BIND 1657207Seric # include <arpa/nameser.h> 1757207Seric # include <resolv.h> 1857207Seric #endif 193308Seric 2057736Seric /* System 5 compatibility */ 2157736Seric #ifndef S_ISREG 2257736Seric #define S_ISREG(foo) ((foo & S_IFREG) == S_IFREG) 2357736Seric #endif 2457736Seric #ifndef S_IWGRP 2557736Seric #define S_IWGRP 020 2657736Seric #endif 2757736Seric #ifndef S_IWOTH 2857736Seric #define S_IWOTH 002 2957736Seric #endif 3057736Seric 313308Seric /* 323308Seric ** READCF -- read control file. 333308Seric ** 343308Seric ** This routine reads the control file and builds the internal 353308Seric ** form. 363308Seric ** 374432Seric ** The file is formatted as a sequence of lines, each taken 384432Seric ** atomically. The first character of each line describes how 394432Seric ** the line is to be interpreted. The lines are: 404432Seric ** Dxval Define macro x to have value val. 414432Seric ** Cxword Put word into class x. 424432Seric ** Fxfile [fmt] Read file for lines to put into 434432Seric ** class x. Use scanf string 'fmt' 444432Seric ** or "%s" if not present. Fmt should 454432Seric ** only produce one string-valued result. 464432Seric ** Hname: value Define header with field-name 'name' 474432Seric ** and value as specified; this will be 484432Seric ** macro expanded immediately before 494432Seric ** use. 504432Seric ** Sn Use rewriting set n. 514432Seric ** Rlhs rhs Rewrite addresses that match lhs to 524432Seric ** be rhs. 5324944Seric ** Mn arg=val... Define mailer. n is the internal name. 5424944Seric ** Args specify mailer parameters. 558252Seric ** Oxvalue Set option x to value. 568252Seric ** Pname=value Set precedence name to value. 5752645Seric ** Vversioncode Version level of configuration syntax. 5853654Seric ** Kmapname mapclass arguments.... 5953654Seric ** Define keyed lookup of a given class. 6053654Seric ** Arguments are class dependent. 614432Seric ** 623308Seric ** Parameters: 633308Seric ** cfname -- control file name. 6454973Seric ** safe -- TRUE if this is the system config file; 6554973Seric ** FALSE otherwise. 6655012Seric ** e -- the main envelope. 673308Seric ** 683308Seric ** Returns: 693308Seric ** none. 703308Seric ** 713308Seric ** Side Effects: 723308Seric ** Builds several internal tables. 733308Seric */ 743308Seric 7555012Seric readcf(cfname, safe, e) 763308Seric char *cfname; 7754973Seric bool safe; 7855012Seric register ENVELOPE *e; 793308Seric { 803308Seric FILE *cf; 818547Seric int ruleset = 0; 828547Seric char *q; 838547Seric char **pv; 849350Seric struct rewrite *rwp = NULL; 8557135Seric char *bp; 8657589Seric int nfuzzy; 873308Seric char buf[MAXLINE]; 883308Seric register char *p; 893308Seric extern char **prescan(); 903308Seric extern char **copyplist(); 9152647Seric struct stat statb; 925909Seric char exbuf[MAXLINE]; 9316915Seric char pvpbuf[PSBUFSIZE]; 949350Seric extern char *fgetfolded(); 9510709Seric extern char *munchstring(); 9653654Seric extern void makemapentry(); 973308Seric 9852647Seric FileName = cfname; 9952647Seric LineNumber = 0; 10052647Seric 1013308Seric cf = fopen(cfname, "r"); 1023308Seric if (cf == NULL) 1033308Seric { 10452647Seric syserr("cannot open"); 1053308Seric exit(EX_OSFILE); 1063308Seric } 1073308Seric 10852647Seric if (fstat(fileno(cf), &statb) < 0) 10952647Seric { 11052647Seric syserr("cannot fstat"); 11152647Seric exit(EX_OSFILE); 11252647Seric } 11352647Seric 11452647Seric if (!S_ISREG(statb.st_mode)) 11552647Seric { 11652647Seric syserr("not a plain file"); 11752647Seric exit(EX_OSFILE); 11852647Seric } 11952647Seric 12052647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 12152647Seric { 12253037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 12353037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 12453037Seric FileName); 12553037Seric #ifdef LOG 12653037Seric if (LogLevel > 0) 12753037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 12853037Seric FileName); 12953037Seric #endif 13052647Seric } 13152647Seric 13257135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1333308Seric { 13457135Seric if (bp[0] == '#') 13557135Seric { 13657135Seric if (bp != buf) 13757135Seric free(bp); 13852637Seric continue; 13957135Seric } 14052637Seric 14158050Seric /* map $ into \201 for macro expansion */ 14257135Seric for (p = bp; *p != '\0'; p++) 14316157Seric { 14457135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14552647Seric { 14652647Seric /* this is an on-line comment */ 14752647Seric register char *e; 14852647Seric 14958050Seric switch (*--p & 0377) 15052647Seric { 15158050Seric case MACROEXPAND: 15252647Seric /* it's from $# -- let it go through */ 15352647Seric p++; 15452647Seric break; 15552647Seric 15652647Seric case '\\': 15752647Seric /* it's backslash escaped */ 15852647Seric (void) strcpy(p, p + 1); 15952647Seric break; 16052647Seric 16152647Seric default: 16252647Seric /* delete preceeding white space */ 16358050Seric while (isascii(*p) && isspace(*p) && p > bp) 16452647Seric p--; 16556795Seric if ((e = strchr(++p, '\n')) != NULL) 16652647Seric (void) strcpy(p, e); 16752647Seric else 16852647Seric p[0] = p[1] = '\0'; 16952647Seric break; 17052647Seric } 17152647Seric continue; 17252647Seric } 17352647Seric 17416157Seric if (*p != '$') 17516157Seric continue; 17616157Seric 17716157Seric if (p[1] == '$') 17816157Seric { 17916157Seric /* actual dollar sign.... */ 18023111Seric (void) strcpy(p, p + 1); 18116157Seric continue; 18216157Seric } 18316157Seric 18416157Seric /* convert to macro expansion character */ 18558050Seric *p = MACROEXPAND; 18616157Seric } 18716157Seric 18816157Seric /* interpret this line */ 18957135Seric switch (bp[0]) 1903308Seric { 1913308Seric case '\0': 1923308Seric case '#': /* comment */ 1933308Seric break; 1943308Seric 1953308Seric case 'R': /* rewriting rule */ 19657135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1973308Seric continue; 1983308Seric 1993308Seric if (*p == '\0') 2005909Seric { 20157135Seric syserr("invalid rewrite line \"%s\"", bp); 2025909Seric break; 2035909Seric } 2045909Seric 2055909Seric /* allocate space for the rule header */ 2065909Seric if (rwp == NULL) 2075909Seric { 2085909Seric RewriteRules[ruleset] = rwp = 2095909Seric (struct rewrite *) xalloc(sizeof *rwp); 2105909Seric } 2113308Seric else 2123308Seric { 2135909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2145909Seric rwp = rwp->r_next; 2155909Seric } 2165909Seric rwp->r_next = NULL; 2173308Seric 2185909Seric /* expand and save the LHS */ 2195909Seric *p = '\0'; 22057135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 22158333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 22257589Seric nfuzzy = 0; 2235909Seric if (rwp->r_lhs != NULL) 22457589Seric { 22557589Seric register char **ap; 22657589Seric 2275909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22857589Seric 22957589Seric /* count the number of fuzzy matches in LHS */ 23057589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 23157589Seric { 23258148Seric char *botch; 23358148Seric 23458148Seric botch = NULL; 23558050Seric switch (**ap & 0377) 23657589Seric { 23757589Seric case MATCHZANY: 23857589Seric case MATCHANY: 23957589Seric case MATCHONE: 24057589Seric case MATCHCLASS: 24157589Seric case MATCHNCLASS: 24258173Seric case CANONHOST: 24357589Seric nfuzzy++; 24458148Seric break; 24558148Seric 24658148Seric case MATCHREPL: 24758148Seric botch = "$0-$9"; 24858148Seric break; 24958148Seric 25058148Seric case CANONNET: 25158148Seric botch = "$#"; 25258148Seric break; 25358148Seric 25458148Seric case CANONUSER: 25558148Seric botch = "$:"; 25658148Seric break; 25758148Seric 25858148Seric case CALLSUBR: 25958148Seric botch = "$>"; 26058148Seric break; 26158148Seric 26258148Seric case CONDIF: 26358148Seric botch = "$?"; 26458148Seric break; 26558148Seric 26658148Seric case CONDELSE: 26758148Seric botch = "$|"; 26858148Seric break; 26958148Seric 27058148Seric case CONDFI: 27158148Seric botch = "$."; 27258148Seric break; 27358148Seric 27458148Seric case HOSTBEGIN: 27558148Seric botch = "$["; 27658148Seric break; 27758148Seric 27858148Seric case HOSTEND: 27958148Seric botch = "$]"; 28058148Seric break; 28158148Seric 28258148Seric case LOOKUPBEGIN: 28358148Seric botch = "$("; 28458148Seric break; 28558148Seric 28658148Seric case LOOKUPEND: 28758148Seric botch = "$)"; 28858148Seric break; 28957589Seric } 29058148Seric if (botch != NULL) 29158148Seric syserr("Inappropriate use of %s on LHS", 29258148Seric botch); 29357589Seric } 29457589Seric } 29556678Seric else 29656678Seric syserr("R line: null LHS"); 2975909Seric 2985909Seric /* expand and save the RHS */ 2995909Seric while (*++p == '\t') 3005909Seric continue; 3017231Seric q = p; 3027231Seric while (*p != '\0' && *p != '\t') 3037231Seric p++; 3047231Seric *p = '\0'; 30555012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 30658333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 3075909Seric if (rwp->r_rhs != NULL) 30857589Seric { 30957589Seric register char **ap; 31057589Seric 3115909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 31257589Seric 31357589Seric /* check no out-of-bounds replacements */ 31457589Seric nfuzzy += '0'; 31557589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31657589Seric { 31758148Seric char *botch; 31858148Seric 31958148Seric botch = NULL; 32058148Seric switch (**ap & 0377) 32157589Seric { 32258148Seric case MATCHREPL: 32358148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32458148Seric { 32558148Seric syserr("replacement $%c out of bounds", 32658148Seric (*ap)[1]); 32758148Seric } 32858148Seric break; 32958148Seric 33058148Seric case MATCHZANY: 33158148Seric botch = "$*"; 33258148Seric break; 33358148Seric 33458148Seric case MATCHANY: 33558148Seric botch = "$+"; 33658148Seric break; 33758148Seric 33858148Seric case MATCHONE: 33958148Seric botch = "$-"; 34058148Seric break; 34158148Seric 34258148Seric case MATCHCLASS: 34358148Seric botch = "$="; 34458148Seric break; 34558148Seric 34658148Seric case MATCHNCLASS: 34758148Seric botch = "$~"; 34858148Seric break; 34957589Seric } 35058148Seric if (botch != NULL) 35158148Seric syserr("Inappropriate use of %s on RHS", 35258148Seric botch); 35357589Seric } 35457589Seric } 35556678Seric else 35656678Seric syserr("R line: null RHS"); 3573308Seric break; 3583308Seric 3594072Seric case 'S': /* select rewriting set */ 36057135Seric ruleset = atoi(&bp[1]); 3618056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3628056Seric { 3639381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3648056Seric ruleset = 0; 3658056Seric } 3664072Seric rwp = NULL; 3674072Seric break; 3684072Seric 3693308Seric case 'D': /* macro definition */ 37058333Seric define(bp[1], newstr(munchstring(&bp[2], NULL)), e); 3713308Seric break; 3723308Seric 3733387Seric case 'H': /* required header line */ 37457135Seric (void) chompheader(&bp[1], TRUE, e); 3753387Seric break; 3763387Seric 3774061Seric case 'C': /* word class */ 3784432Seric case 'F': /* word class from file */ 3794432Seric /* read list of words from argument or file */ 38057135Seric if (bp[0] == 'F') 3814432Seric { 3824432Seric /* read from file */ 38358050Seric for (p = &bp[2]; 38458050Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 38558050Seric p++) 3864432Seric continue; 3874432Seric if (*p == '\0') 3884432Seric p = "%s"; 3894432Seric else 3904432Seric { 3914432Seric *p = '\0'; 39258050Seric while (isascii(*++p) && isspace(*p)) 3934432Seric continue; 3944432Seric } 39557135Seric fileclass(bp[1], &bp[2], p, safe); 3964432Seric break; 3974432Seric } 3984061Seric 3994432Seric /* scan the list of words and set class for all */ 40057135Seric for (p = &bp[2]; *p != '\0'; ) 4014061Seric { 4024061Seric register char *wd; 4034061Seric char delim; 4044061Seric 40558050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 4064061Seric p++; 4074061Seric wd = p; 40858050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 4094061Seric p++; 4104061Seric delim = *p; 4114061Seric *p = '\0'; 4124061Seric if (wd[0] != '\0') 41358148Seric { 41458148Seric if (tTd(37, 2)) 41558148Seric printf("setclass(%c, %s)\n", 41658148Seric bp[1], wd); 41757135Seric setclass(bp[1], wd); 41858148Seric } 4194061Seric *p = delim; 4204061Seric } 4214061Seric break; 4224061Seric 4234096Seric case 'M': /* define mailer */ 42457135Seric makemailer(&bp[1]); 4254096Seric break; 4264096Seric 4278252Seric case 'O': /* set option */ 428*58734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4298252Seric break; 4308252Seric 4318252Seric case 'P': /* set precedence */ 4328252Seric if (NumPriorities >= MAXPRIORITIES) 4338252Seric { 4348547Seric toomany('P', MAXPRIORITIES); 4358252Seric break; 4368252Seric } 43757135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4388252Seric continue; 4398252Seric if (*p == '\0') 4408252Seric goto badline; 4418252Seric *p = '\0'; 44257135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4438252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4448252Seric NumPriorities++; 4458252Seric break; 4468252Seric 4478547Seric case 'T': /* trusted user(s) */ 44858161Seric /* this option is obsolete, but will be ignored */ 4498547Seric break; 4508547Seric 45152645Seric case 'V': /* configuration syntax version */ 45257135Seric ConfigLevel = atoi(&bp[1]); 45352645Seric break; 45452645Seric 45553654Seric case 'K': 45657135Seric makemapentry(&bp[1]); 45753654Seric break; 45853654Seric 4593308Seric default: 4604061Seric badline: 46157135Seric syserr("unknown control line \"%s\"", bp); 4623308Seric } 46357135Seric if (bp != buf) 46457135Seric free(bp); 4653308Seric } 46652637Seric if (ferror(cf)) 46752637Seric { 46852647Seric syserr("I/O read error", cfname); 46952637Seric exit(EX_OSFILE); 47052637Seric } 47152637Seric fclose(cf); 4729381Seric FileName = NULL; 47356836Seric 47457076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 47557076Seric { 47657076Seric /* user didn't initialize: set up host map */ 47757076Seric strcpy(buf, "host host"); 47857076Seric if (ConfigLevel >= 2) 47957076Seric strcat(buf, " -a."); 48057076Seric makemapentry(buf); 48157076Seric } 4824096Seric } 4834096Seric /* 4848547Seric ** TOOMANY -- signal too many of some option 4858547Seric ** 4868547Seric ** Parameters: 4878547Seric ** id -- the id of the error line 4888547Seric ** maxcnt -- the maximum possible values 4898547Seric ** 4908547Seric ** Returns: 4918547Seric ** none. 4928547Seric ** 4938547Seric ** Side Effects: 4948547Seric ** gives a syserr. 4958547Seric */ 4968547Seric 4978547Seric toomany(id, maxcnt) 4988547Seric char id; 4998547Seric int maxcnt; 5008547Seric { 5019381Seric syserr("too many %c lines, %d max", id, maxcnt); 5028547Seric } 5038547Seric /* 5044432Seric ** FILECLASS -- read members of a class from a file 5054432Seric ** 5064432Seric ** Parameters: 5074432Seric ** class -- class to define. 5084432Seric ** filename -- name of file to read. 5094432Seric ** fmt -- scanf string to use for match. 5104432Seric ** 5114432Seric ** Returns: 5124432Seric ** none 5134432Seric ** 5144432Seric ** Side Effects: 5154432Seric ** 5164432Seric ** puts all lines in filename that match a scanf into 5174432Seric ** the named class. 5184432Seric */ 5194432Seric 52054973Seric fileclass(class, filename, fmt, safe) 5214432Seric int class; 5224432Seric char *filename; 5234432Seric char *fmt; 52454973Seric bool safe; 5254432Seric { 52625808Seric FILE *f; 52754973Seric struct stat stbuf; 5284432Seric char buf[MAXLINE]; 5294432Seric 53054973Seric if (stat(filename, &stbuf) < 0) 53154973Seric { 53254973Seric syserr("fileclass: cannot stat %s", filename); 53354973Seric return; 53454973Seric } 53554973Seric if (!S_ISREG(stbuf.st_mode)) 53654973Seric { 53754973Seric syserr("fileclass: %s not a regular file", filename); 53854973Seric return; 53954973Seric } 54054973Seric if (!safe && access(filename, R_OK) < 0) 54154973Seric { 54254973Seric syserr("fileclass: access denied on %s", filename); 54354973Seric return; 54454973Seric } 54554973Seric f = fopen(filename, "r"); 5464432Seric if (f == NULL) 5474432Seric { 54854973Seric syserr("fileclass: cannot open %s", filename); 5494432Seric return; 5504432Seric } 5514432Seric 5524432Seric while (fgets(buf, sizeof buf, f) != NULL) 5534432Seric { 5544432Seric register STAB *s; 55525808Seric register char *p; 55625808Seric # ifdef SCANF 5574432Seric char wordbuf[MAXNAME+1]; 5584432Seric 5594432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5604432Seric continue; 56125808Seric p = wordbuf; 56256795Seric # else /* SCANF */ 56325808Seric p = buf; 56456795Seric # endif /* SCANF */ 56525808Seric 56625808Seric /* 56725808Seric ** Break up the match into words. 56825808Seric */ 56925808Seric 57025808Seric while (*p != '\0') 57125808Seric { 57225808Seric register char *q; 57325808Seric 57425808Seric /* strip leading spaces */ 57558050Seric while (isascii(*p) && isspace(*p)) 57625808Seric p++; 57725808Seric if (*p == '\0') 57825808Seric break; 57925808Seric 58025808Seric /* find the end of the word */ 58125808Seric q = p; 58258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 58325808Seric p++; 58425808Seric if (*p != '\0') 58525808Seric *p++ = '\0'; 58625808Seric 58725808Seric /* enter the word in the symbol table */ 58825808Seric s = stab(q, ST_CLASS, ST_ENTER); 58925808Seric setbitn(class, s->s_class); 59025808Seric } 5914432Seric } 5924432Seric 59354973Seric (void) fclose(f); 5944432Seric } 5954432Seric /* 5964096Seric ** MAKEMAILER -- define a new mailer. 5974096Seric ** 5984096Seric ** Parameters: 59910327Seric ** line -- description of mailer. This is in labeled 60010327Seric ** fields. The fields are: 60110327Seric ** P -- the path to the mailer 60210327Seric ** F -- the flags associated with the mailer 60310327Seric ** A -- the argv for this mailer 60410327Seric ** S -- the sender rewriting set 60510327Seric ** R -- the recipient rewriting set 60610327Seric ** E -- the eol string 60710327Seric ** The first word is the canonical name of the mailer. 6084096Seric ** 6094096Seric ** Returns: 6104096Seric ** none. 6114096Seric ** 6124096Seric ** Side Effects: 6134096Seric ** enters the mailer into the mailer table. 6144096Seric */ 6153308Seric 61621066Seric makemailer(line) 6174096Seric char *line; 6184096Seric { 6194096Seric register char *p; 6208067Seric register struct mailer *m; 6218067Seric register STAB *s; 6228067Seric int i; 62310327Seric char fcode; 62458020Seric auto char *endp; 6254096Seric extern int NextMailer; 62610327Seric extern char **makeargv(); 62710327Seric extern char *munchstring(); 62810701Seric extern long atol(); 6294096Seric 63010327Seric /* allocate a mailer and set up defaults */ 63110327Seric m = (struct mailer *) xalloc(sizeof *m); 63210327Seric bzero((char *) m, sizeof *m); 63310327Seric m->m_eol = "\n"; 63410327Seric 63510327Seric /* collect the mailer name */ 63658050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 63710327Seric continue; 63810327Seric if (*p != '\0') 63910327Seric *p++ = '\0'; 64010327Seric m->m_name = newstr(line); 64110327Seric 64210327Seric /* now scan through and assign info from the fields */ 64310327Seric while (*p != '\0') 64410327Seric { 64558333Seric auto char *delimptr; 64658333Seric 64758050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 64810327Seric p++; 64910327Seric 65010327Seric /* p now points to field code */ 65110327Seric fcode = *p; 65210327Seric while (*p != '\0' && *p != '=' && *p != ',') 65310327Seric p++; 65410327Seric if (*p++ != '=') 65510327Seric { 65652637Seric syserr("mailer %s: `=' expected", m->m_name); 65710327Seric return; 65810327Seric } 65958050Seric while (isascii(*p) && isspace(*p)) 66010327Seric p++; 66110327Seric 66210327Seric /* p now points to the field body */ 66358333Seric p = munchstring(p, &delimptr); 66410327Seric 66510327Seric /* install the field into the mailer struct */ 66610327Seric switch (fcode) 66710327Seric { 66810327Seric case 'P': /* pathname */ 66910327Seric m->m_mailer = newstr(p); 67010327Seric break; 67110327Seric 67210327Seric case 'F': /* flags */ 67310687Seric for (; *p != '\0'; p++) 67458050Seric if (!(isascii(*p) && isspace(*p))) 67552637Seric setbitn(*p, m->m_flags); 67610327Seric break; 67710327Seric 67810327Seric case 'S': /* sender rewriting ruleset */ 67910327Seric case 'R': /* recipient rewriting ruleset */ 68058020Seric i = strtol(p, &endp, 10); 68110327Seric if (i < 0 || i >= MAXRWSETS) 68210327Seric { 68310327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 68410327Seric return; 68510327Seric } 68610327Seric if (fcode == 'S') 68758020Seric m->m_sh_rwset = m->m_se_rwset = i; 68810327Seric else 68958020Seric m->m_rh_rwset = m->m_re_rwset = i; 69058020Seric 69158020Seric p = endp; 69258020Seric if (*p == '/') 69358020Seric { 69458020Seric i = strtol(p, NULL, 10); 69558020Seric if (i < 0 || i >= MAXRWSETS) 69658020Seric { 69758020Seric syserr("invalid rewrite set, %d max", 69858020Seric MAXRWSETS); 69958020Seric return; 70058020Seric } 70158020Seric if (fcode == 'S') 70258020Seric m->m_sh_rwset = i; 70358020Seric else 70458020Seric m->m_rh_rwset = i; 70558020Seric } 70610327Seric break; 70710327Seric 70810327Seric case 'E': /* end of line string */ 70910327Seric m->m_eol = newstr(p); 71010327Seric break; 71110327Seric 71210327Seric case 'A': /* argument vector */ 71310327Seric m->m_argv = makeargv(p); 71410327Seric break; 71510701Seric 71610701Seric case 'M': /* maximum message size */ 71710701Seric m->m_maxsize = atol(p); 71810701Seric break; 71952106Seric 72052106Seric case 'L': /* maximum line length */ 72152106Seric m->m_linelimit = atoi(p); 72252106Seric break; 72310327Seric } 72410327Seric 72558333Seric p = delimptr; 72610327Seric } 72710327Seric 72852106Seric /* do some heuristic cleanup for back compatibility */ 72952106Seric if (bitnset(M_LIMITS, m->m_flags)) 73052106Seric { 73152106Seric if (m->m_linelimit == 0) 73252106Seric m->m_linelimit = SMTPLINELIM; 73355418Seric if (ConfigLevel < 2) 73452106Seric setbitn(M_7BITS, m->m_flags); 73552106Seric } 73652106Seric 73758321Seric /* do some rationality checking */ 73858321Seric if (m->m_argv == NULL) 73958321Seric { 74058321Seric syserr("M%s: A= argument required", m->m_name); 74158321Seric return; 74258321Seric } 74358321Seric if (m->m_mailer == NULL) 74458321Seric { 74558321Seric syserr("M%s: P= argument required", m->m_name); 74658321Seric return; 74758321Seric } 74858321Seric 7494096Seric if (NextMailer >= MAXMAILERS) 7504096Seric { 7519381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7524096Seric return; 7534096Seric } 75457402Seric 75510327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 75657402Seric if (s->s_mailer != NULL) 75757402Seric { 75857402Seric i = s->s_mailer->m_mno; 75957402Seric free(s->s_mailer); 76057402Seric } 76157402Seric else 76257402Seric { 76357402Seric i = NextMailer++; 76457402Seric } 76557402Seric Mailer[i] = s->s_mailer = m; 76657454Seric m->m_mno = i; 76710327Seric } 76810327Seric /* 76910327Seric ** MUNCHSTRING -- translate a string into internal form. 77010327Seric ** 77110327Seric ** Parameters: 77210327Seric ** p -- the string to munch. 77358333Seric ** delimptr -- if non-NULL, set to the pointer of the 77458333Seric ** field delimiter character. 77510327Seric ** 77610327Seric ** Returns: 77710327Seric ** the munched string. 77810327Seric */ 7794096Seric 78010327Seric char * 78158333Seric munchstring(p, delimptr) 78210327Seric register char *p; 78358333Seric char **delimptr; 78410327Seric { 78510327Seric register char *q; 78610327Seric bool backslash = FALSE; 78710327Seric bool quotemode = FALSE; 78810327Seric static char buf[MAXLINE]; 7894096Seric 79010327Seric for (q = buf; *p != '\0'; p++) 7914096Seric { 79210327Seric if (backslash) 79310327Seric { 79410327Seric /* everything is roughly literal */ 79510357Seric backslash = FALSE; 79610327Seric switch (*p) 79710327Seric { 79810327Seric case 'r': /* carriage return */ 79910327Seric *q++ = '\r'; 80010327Seric continue; 80110327Seric 80210327Seric case 'n': /* newline */ 80310327Seric *q++ = '\n'; 80410327Seric continue; 80510327Seric 80610327Seric case 'f': /* form feed */ 80710327Seric *q++ = '\f'; 80810327Seric continue; 80910327Seric 81010327Seric case 'b': /* backspace */ 81110327Seric *q++ = '\b'; 81210327Seric continue; 81310327Seric } 81410327Seric *q++ = *p; 81510327Seric } 81610327Seric else 81710327Seric { 81810327Seric if (*p == '\\') 81910327Seric backslash = TRUE; 82010327Seric else if (*p == '"') 82110327Seric quotemode = !quotemode; 82210327Seric else if (quotemode || *p != ',') 82310327Seric *q++ = *p; 82410327Seric else 82510327Seric break; 82610327Seric } 8274096Seric } 8284096Seric 82958333Seric if (delimptr != NULL) 83058333Seric *delimptr = p; 83110327Seric *q++ = '\0'; 83210327Seric return (buf); 83310327Seric } 83410327Seric /* 83510327Seric ** MAKEARGV -- break up a string into words 83610327Seric ** 83710327Seric ** Parameters: 83810327Seric ** p -- the string to break up. 83910327Seric ** 84010327Seric ** Returns: 84110327Seric ** a char **argv (dynamically allocated) 84210327Seric ** 84310327Seric ** Side Effects: 84410327Seric ** munges p. 84510327Seric */ 8464096Seric 84710327Seric char ** 84810327Seric makeargv(p) 84910327Seric register char *p; 85010327Seric { 85110327Seric char *q; 85210327Seric int i; 85310327Seric char **avp; 85410327Seric char *argv[MAXPV + 1]; 85510327Seric 85610327Seric /* take apart the words */ 85710327Seric i = 0; 85810327Seric while (*p != '\0' && i < MAXPV) 8594096Seric { 86010327Seric q = p; 86158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 86210327Seric p++; 86358050Seric while (isascii(*p) && isspace(*p)) 86410327Seric *p++ = '\0'; 86510327Seric argv[i++] = newstr(q); 8664096Seric } 86710327Seric argv[i++] = NULL; 8684096Seric 86910327Seric /* now make a copy of the argv */ 87010327Seric avp = (char **) xalloc(sizeof *avp * i); 87116893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 87210327Seric 87310327Seric return (avp); 8743308Seric } 8753308Seric /* 8763308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8773308Seric ** 8783308Seric ** Parameters: 8793308Seric ** none. 8803308Seric ** 8813308Seric ** Returns: 8823308Seric ** none. 8833308Seric ** 8843308Seric ** Side Effects: 8853308Seric ** prints rewrite rules. 8863308Seric */ 8873308Seric 8883308Seric printrules() 8893308Seric { 8903308Seric register struct rewrite *rwp; 8914072Seric register int ruleset; 8923308Seric 8934072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8943308Seric { 8954072Seric if (RewriteRules[ruleset] == NULL) 8964072Seric continue; 8978067Seric printf("\n----Rule Set %d:", ruleset); 8983308Seric 8994072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9003308Seric { 9018067Seric printf("\nLHS:"); 9028067Seric printav(rwp->r_lhs); 9038067Seric printf("RHS:"); 9048067Seric printav(rwp->r_rhs); 9053308Seric } 9063308Seric } 9073308Seric } 9084319Seric 9094096Seric /* 9108256Seric ** SETOPTION -- set global processing option 9118256Seric ** 9128256Seric ** Parameters: 9138256Seric ** opt -- option name. 9148256Seric ** val -- option value (as a text string). 91521755Seric ** safe -- set if this came from a configuration file. 91621755Seric ** Some options (if set from the command line) will 91721755Seric ** reset the user id to avoid security problems. 9188269Seric ** sticky -- if set, don't let other setoptions override 9198269Seric ** this value. 920*58734Seric ** e -- the main envelope. 9218256Seric ** 9228256Seric ** Returns: 9238256Seric ** none. 9248256Seric ** 9258256Seric ** Side Effects: 9268256Seric ** Sets options as implied by the arguments. 9278256Seric */ 9288256Seric 92910687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9308269Seric 93157207Seric 93257207Seric #ifdef NAMED_BIND 93357207Seric 93457207Seric struct resolverflags 93557207Seric { 93657207Seric char *rf_name; /* name of the flag */ 93757207Seric long rf_bits; /* bits to set/clear */ 93857207Seric } ResolverFlags[] = 93957207Seric { 94057207Seric "debug", RES_DEBUG, 94157207Seric "aaonly", RES_AAONLY, 94257207Seric "usevc", RES_USEVC, 94357207Seric "primary", RES_PRIMARY, 94457207Seric "igntc", RES_IGNTC, 94557207Seric "recurse", RES_RECURSE, 94657207Seric "defnames", RES_DEFNAMES, 94757207Seric "stayopen", RES_STAYOPEN, 94857207Seric "dnsrch", RES_DNSRCH, 94957207Seric NULL, 0 95057207Seric }; 95157207Seric 95257207Seric #endif 95357207Seric 954*58734Seric setoption(opt, val, safe, sticky, e) 9558256Seric char opt; 9568256Seric char *val; 95721755Seric bool safe; 9588269Seric bool sticky; 959*58734Seric register ENVELOPE *e; 9608256Seric { 96157207Seric register char *p; 9628265Seric extern bool atobool(); 96312633Seric extern time_t convtime(); 96414879Seric extern int QueueLA; 96514879Seric extern int RefuseLA; 96617474Seric extern bool trusteduser(); 96717474Seric extern char *username(); 9688256Seric 9698256Seric if (tTd(37, 1)) 9709341Seric printf("setoption %c=%s", opt, val); 9718256Seric 9728256Seric /* 9738269Seric ** See if this option is preset for us. 9748256Seric */ 9758256Seric 97610687Seric if (bitnset(opt, StickyOpt)) 9778269Seric { 9789341Seric if (tTd(37, 1)) 9799341Seric printf(" (ignored)\n"); 9808269Seric return; 9818269Seric } 9828269Seric 98321755Seric /* 98421755Seric ** Check to see if this option can be specified by this user. 98521755Seric */ 98621755Seric 98736238Skarels if (!safe && getuid() == 0) 98821755Seric safe = TRUE; 98958082Seric if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL) 99021755Seric { 99139111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 99221755Seric { 99336582Sbostic if (tTd(37, 1)) 99436582Sbostic printf(" (unsafe)"); 99536582Sbostic if (getuid() != geteuid()) 99636582Sbostic { 99751210Seric if (tTd(37, 1)) 99851210Seric printf("(Resetting uid)"); 99936582Sbostic (void) setgid(getgid()); 100036582Sbostic (void) setuid(getuid()); 100136582Sbostic } 100221755Seric } 100321755Seric } 100451210Seric if (tTd(37, 1)) 100517985Seric printf("\n"); 10068269Seric 10078256Seric switch (opt) 10088256Seric { 100952106Seric case '8': /* allow eight-bit input */ 101052106Seric EightBit = atobool(val); 101152106Seric break; 101252106Seric 10138256Seric case 'A': /* set default alias file */ 10149381Seric if (val[0] == '\0') 10158269Seric AliasFile = "aliases"; 10169381Seric else 10179381Seric AliasFile = newstr(val); 10188256Seric break; 10198256Seric 102017474Seric case 'a': /* look N minutes for "@:@" in alias file */ 102117474Seric if (val[0] == '\0') 102217474Seric SafeAlias = 5; 102317474Seric else 102417474Seric SafeAlias = atoi(val); 102517474Seric break; 102617474Seric 102716843Seric case 'B': /* substitution for blank character */ 102816843Seric SpaceSub = val[0]; 102916843Seric if (SpaceSub == '\0') 103016843Seric SpaceSub = ' '; 103116843Seric break; 103216843Seric 103358082Seric case 'b': /* minimum number of blocks free on queue fs */ 103458082Seric MinBlocksFree = atol(val); 103558082Seric break; 103658082Seric 10379284Seric case 'c': /* don't connect to "expensive" mailers */ 10389381Seric NoConnect = atobool(val); 10399284Seric break; 10409284Seric 104151305Seric case 'C': /* checkpoint every N addresses */ 104251305Seric CheckpointInterval = atoi(val); 104324944Seric break; 104424944Seric 10459284Seric case 'd': /* delivery mode */ 10469284Seric switch (*val) 10478269Seric { 10489284Seric case '\0': 1049*58734Seric e->e_sendmode = SM_DELIVER; 10508269Seric break; 10518269Seric 105210755Seric case SM_QUEUE: /* queue only */ 105310755Seric #ifndef QUEUE 105410755Seric syserr("need QUEUE to set -odqueue"); 105556795Seric #endif /* QUEUE */ 105610755Seric /* fall through..... */ 105710755Seric 10589284Seric case SM_DELIVER: /* do everything */ 10599284Seric case SM_FORK: /* fork after verification */ 1060*58734Seric e->e_sendmode = *val; 10618269Seric break; 10628269Seric 10638269Seric default: 10649284Seric syserr("Unknown delivery mode %c", *val); 10658269Seric exit(EX_USAGE); 10668269Seric } 10678269Seric break; 10688269Seric 10699146Seric case 'D': /* rebuild alias database as needed */ 10709381Seric AutoRebuild = atobool(val); 10719146Seric break; 10729146Seric 107355372Seric case 'E': /* error message header/header file */ 107455379Seric if (*val != '\0') 107555379Seric ErrMsgFile = newstr(val); 107655372Seric break; 107755372Seric 10788269Seric case 'e': /* set error processing mode */ 10798269Seric switch (*val) 10808269Seric { 10819381Seric case EM_QUIET: /* be silent about it */ 10829381Seric case EM_MAIL: /* mail back */ 10839381Seric case EM_BERKNET: /* do berknet error processing */ 10849381Seric case EM_WRITE: /* write back (or mail) */ 10858269Seric HoldErrs = TRUE; 10869381Seric /* fall through... */ 10878269Seric 10889381Seric case EM_PRINT: /* print errors normally (default) */ 1089*58734Seric e->e_errormode = *val; 10908269Seric break; 10918269Seric } 10928269Seric break; 10938269Seric 10949049Seric case 'F': /* file mode */ 109517975Seric FileMode = atooct(val) & 0777; 10969049Seric break; 10979049Seric 10988269Seric case 'f': /* save Unix-style From lines on front */ 10999381Seric SaveFrom = atobool(val); 11008269Seric break; 11018269Seric 110253735Seric case 'G': /* match recipients against GECOS field */ 110353735Seric MatchGecos = atobool(val); 110453735Seric break; 110553735Seric 11068256Seric case 'g': /* default gid */ 110717474Seric DefGid = atoi(val); 11088256Seric break; 11098256Seric 11108256Seric case 'H': /* help file */ 11119381Seric if (val[0] == '\0') 11128269Seric HelpFile = "sendmail.hf"; 11139381Seric else 11149381Seric HelpFile = newstr(val); 11158256Seric break; 11168256Seric 111751305Seric case 'h': /* maximum hop count */ 111851305Seric MaxHopCount = atoi(val); 111951305Seric break; 112051305Seric 112135651Seric case 'I': /* use internet domain name server */ 112257207Seric #ifdef NAMED_BIND 112357207Seric UseNameServer = TRUE; 112457207Seric for (p = val; *p != 0; ) 112557207Seric { 112657207Seric bool clearmode; 112757207Seric char *q; 112857207Seric struct resolverflags *rfp; 112957207Seric 113057207Seric while (*p == ' ') 113157207Seric p++; 113257207Seric if (*p == '\0') 113357207Seric break; 113457207Seric clearmode = FALSE; 113557207Seric if (*p == '-') 113657207Seric clearmode = TRUE; 113757207Seric else if (*p != '+') 113857207Seric p--; 113957207Seric p++; 114057207Seric q = p; 114158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114257207Seric p++; 114357207Seric if (*p != '\0') 114457207Seric *p++ = '\0'; 114557207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114657207Seric { 114757207Seric if (strcasecmp(q, rfp->rf_name) == 0) 114857207Seric break; 114957207Seric } 115057207Seric if (clearmode) 115157207Seric _res.options &= ~rfp->rf_bits; 115257207Seric else 115357207Seric _res.options |= rfp->rf_bits; 115457207Seric } 115557207Seric if (tTd(8, 2)) 115657207Seric printf("_res.options = %x\n", _res.options); 115757207Seric #else 115857207Seric usrerr("name server (I option) specified but BIND not compiled in"); 115957207Seric #endif 116035651Seric break; 116135651Seric 11628269Seric case 'i': /* ignore dot lines in message */ 11639381Seric IgnrDot = atobool(val); 11648269Seric break; 11658269Seric 116657136Seric case 'J': /* .forward search path */ 116757136Seric ForwardPath = newstr(val); 116857136Seric break; 116957136Seric 117054967Seric case 'k': /* connection cache size */ 117154967Seric MaxMciCache = atoi(val); 117256215Seric if (MaxMciCache < 0) 117356215Seric MaxMciCache = 0; 117454967Seric break; 117554967Seric 117654967Seric case 'K': /* connection cache timeout */ 117754967Seric MciCacheTimeout = convtime(val); 117854967Seric break; 117954967Seric 11808256Seric case 'L': /* log level */ 11819381Seric LogLevel = atoi(val); 11828256Seric break; 11838256Seric 11848269Seric case 'M': /* define macro */ 11859381Seric define(val[0], newstr(&val[1]), CurEnv); 118616878Seric sticky = FALSE; 11878269Seric break; 11888269Seric 11898269Seric case 'm': /* send to me too */ 11909381Seric MeToo = atobool(val); 11918269Seric break; 11928269Seric 119325820Seric case 'n': /* validate RHS in newaliases */ 119425820Seric CheckAliases = atobool(val); 119525820Seric break; 119625820Seric 11978269Seric case 'o': /* assume old style headers */ 11989381Seric if (atobool(val)) 11999341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12009341Seric else 12019341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12028269Seric break; 12038269Seric 120458082Seric case 'p': /* select privacy level */ 120558082Seric p = val; 120658082Seric for (;;) 120758082Seric { 120858082Seric register struct prival *pv; 120958082Seric extern struct prival PrivacyValues[]; 121058082Seric 121158082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 121258082Seric p++; 121358082Seric if (*p == '\0') 121458082Seric break; 121558082Seric val = p; 121658082Seric while (isascii(*p) && isalnum(*p)) 121758082Seric p++; 121858082Seric if (*p != '\0') 121958082Seric *p++ = '\0'; 122058082Seric 122158082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 122258082Seric { 122358082Seric if (strcasecmp(val, pv->pv_name) == 0) 122458082Seric break; 122558082Seric } 122658082Seric PrivacyFlags |= pv->pv_flag; 122758082Seric } 122858082Seric break; 122958082Seric 123024944Seric case 'P': /* postmaster copy address for returned mail */ 123124944Seric PostMasterCopy = newstr(val); 123224944Seric break; 123324944Seric 123424944Seric case 'q': /* slope of queue only function */ 123524944Seric QueueFactor = atoi(val); 123624944Seric break; 123724944Seric 12388256Seric case 'Q': /* queue directory */ 12399381Seric if (val[0] == '\0') 12408269Seric QueueDir = "mqueue"; 12419381Seric else 12429381Seric QueueDir = newstr(val); 12438256Seric break; 12448256Seric 124558148Seric case 'R': /* don't prune routes */ 124658148Seric DontPruneRoutes = atobool(val); 124758148Seric break; 124858148Seric 12498256Seric case 'r': /* read timeout */ 125058112Seric settimeouts(val); 12518256Seric break; 12528256Seric 12538256Seric case 'S': /* status file */ 12549381Seric if (val[0] == '\0') 12558269Seric StatFile = "sendmail.st"; 12569381Seric else 12579381Seric StatFile = newstr(val); 12588256Seric break; 12598256Seric 12608265Seric case 's': /* be super safe, even if expensive */ 12619381Seric SuperSafe = atobool(val); 12628256Seric break; 12638256Seric 12648256Seric case 'T': /* queue timeout */ 12659381Seric TimeOut = convtime(val); 126654967Seric break; 12678256Seric 12688265Seric case 't': /* time zone name */ 126952106Seric TimeZoneSpec = newstr(val); 12708265Seric break; 12718265Seric 127250556Seric case 'U': /* location of user database */ 127351360Seric UdbSpec = newstr(val); 127450556Seric break; 127550556Seric 12768256Seric case 'u': /* set default uid */ 127717474Seric DefUid = atoi(val); 127840973Sbostic setdefuser(); 12798256Seric break; 12808256Seric 12818269Seric case 'v': /* run in verbose mode */ 12829381Seric Verbose = atobool(val); 12838256Seric break; 12848256Seric 128514879Seric case 'x': /* load avg at which to auto-queue msgs */ 128614879Seric QueueLA = atoi(val); 128714879Seric break; 128814879Seric 128914879Seric case 'X': /* load avg at which to auto-reject connections */ 129014879Seric RefuseLA = atoi(val); 129114879Seric break; 129214879Seric 129324981Seric case 'y': /* work recipient factor */ 129424981Seric WkRecipFact = atoi(val); 129524981Seric break; 129624981Seric 129724981Seric case 'Y': /* fork jobs during queue runs */ 129824952Seric ForkQueueRuns = atobool(val); 129924952Seric break; 130024952Seric 130124981Seric case 'z': /* work message class factor */ 130224981Seric WkClassFact = atoi(val); 130324981Seric break; 130424981Seric 130524981Seric case 'Z': /* work time factor */ 130624981Seric WkTimeFact = atoi(val); 130724981Seric break; 130824981Seric 13098256Seric default: 13108256Seric break; 13118256Seric } 131216878Seric if (sticky) 131316878Seric setbitn(opt, StickyOpt); 13149188Seric return; 13158256Seric } 131610687Seric /* 131710687Seric ** SETCLASS -- set a word into a class 131810687Seric ** 131910687Seric ** Parameters: 132010687Seric ** class -- the class to put the word in. 132110687Seric ** word -- the word to enter 132210687Seric ** 132310687Seric ** Returns: 132410687Seric ** none. 132510687Seric ** 132610687Seric ** Side Effects: 132710687Seric ** puts the word into the symbol table. 132810687Seric */ 132910687Seric 133010687Seric setclass(class, word) 133110687Seric int class; 133210687Seric char *word; 133310687Seric { 133410687Seric register STAB *s; 133510687Seric 133657943Seric if (tTd(37, 8)) 133757943Seric printf("%s added to class %c\n", word, class); 133810687Seric s = stab(word, ST_CLASS, ST_ENTER); 133910687Seric setbitn(class, s->s_class); 134010687Seric } 134153654Seric /* 134253654Seric ** MAKEMAPENTRY -- create a map entry 134353654Seric ** 134453654Seric ** Parameters: 134553654Seric ** line -- the config file line 134653654Seric ** 134753654Seric ** Returns: 134853654Seric ** TRUE if it successfully entered the map entry. 134953654Seric ** FALSE otherwise (usually syntax error). 135053654Seric ** 135153654Seric ** Side Effects: 135253654Seric ** Enters the map into the dictionary. 135353654Seric */ 135453654Seric 135553654Seric void 135653654Seric makemapentry(line) 135753654Seric char *line; 135853654Seric { 135953654Seric register char *p; 136053654Seric char *mapname; 136153654Seric char *classname; 136253654Seric register STAB *map; 136353654Seric STAB *class; 136453654Seric 136558050Seric for (p = line; isascii(*p) && isspace(*p); p++) 136653654Seric continue; 136758050Seric if (!(isascii(*p) && isalnum(*p))) 136853654Seric { 136953654Seric syserr("readcf: config K line: no map name"); 137053654Seric return; 137153654Seric } 137253654Seric 137353654Seric mapname = p; 137458050Seric while (isascii(*++p) && isalnum(*p)) 137553654Seric continue; 137653654Seric if (*p != '\0') 137753654Seric *p++ = '\0'; 137858050Seric while (isascii(*p) && isspace(*p)) 137953654Seric p++; 138058050Seric if (!(isascii(*p) && isalnum(*p))) 138153654Seric { 138253654Seric syserr("readcf: config K line, map %s: no map class", mapname); 138353654Seric return; 138453654Seric } 138553654Seric classname = p; 138658050Seric while (isascii(*++p) && isalnum(*p)) 138753654Seric continue; 138853654Seric if (*p != '\0') 138953654Seric *p++ = '\0'; 139058050Seric while (isascii(*p) && isspace(*p)) 139153654Seric p++; 139253654Seric 139353654Seric /* look up the class */ 139453654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 139553654Seric if (class == NULL) 139653654Seric { 139753654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 139853654Seric return; 139953654Seric } 140053654Seric 140153654Seric /* enter the map */ 140253654Seric map = stab(mapname, ST_MAP, ST_ENTER); 140353654Seric map->s_map.map_class = &class->s_mapclass; 140453654Seric 140556823Seric if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 140653654Seric map->s_map.map_flags |= MF_VALID; 140753654Seric } 140858112Seric /* 140958112Seric ** SETTIMEOUTS -- parse and set timeout values 141058112Seric ** 141158112Seric ** Parameters: 141258112Seric ** val -- a pointer to the values. If NULL, do initial 141358112Seric ** settings. 141458112Seric ** 141558112Seric ** Returns: 141658112Seric ** none. 141758112Seric ** 141858112Seric ** Side Effects: 141958112Seric ** Initializes the TimeOuts structure 142058112Seric */ 142158112Seric 142258112Seric #define MINUTES * 60 142358112Seric #define HOUR * 3600 142458112Seric 142558112Seric settimeouts(val) 142658112Seric register char *val; 142758112Seric { 142858112Seric register char *p; 142958671Seric extern time_t convtime(); 143058112Seric 143158112Seric if (val == NULL) 143258112Seric { 143358112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 143458112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 143558112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 143658112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 143758112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 143858112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 143958112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 144058112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 144158112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 144258112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 144358112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 144458112Seric return; 144558112Seric } 144658112Seric 144758112Seric for (;; val = p) 144858112Seric { 144958112Seric while (isascii(*val) && isspace(*val)) 145058112Seric val++; 145158112Seric if (*val == '\0') 145258112Seric break; 145358112Seric for (p = val; *p != '\0' && *p != ','; p++) 145458112Seric continue; 145558112Seric if (*p != '\0') 145658112Seric *p++ = '\0'; 145758112Seric 145858112Seric if (isascii(*val) && isdigit(*val)) 145958112Seric { 146058112Seric /* old syntax -- set everything */ 146158112Seric TimeOuts.to_mail = convtime(val); 146258112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 146358112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 146458112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 146558112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 146658112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 146758112Seric continue; 146858112Seric } 146958112Seric else 147058112Seric { 147158112Seric register char *q = strchr(val, '='); 147258112Seric time_t to; 147358112Seric 147458112Seric if (q == NULL) 147558112Seric { 147658112Seric /* syntax error */ 147758112Seric continue; 147858112Seric } 147958112Seric *q++ = '\0'; 148058112Seric to = convtime(q); 148158112Seric 148258112Seric if (strcasecmp(val, "initial") == 0) 148358112Seric TimeOuts.to_initial = to; 148458112Seric else if (strcasecmp(val, "mail") == 0) 148558112Seric TimeOuts.to_mail = to; 148658112Seric else if (strcasecmp(val, "rcpt") == 0) 148758112Seric TimeOuts.to_rcpt = to; 148858112Seric else if (strcasecmp(val, "datainit") == 0) 148958112Seric TimeOuts.to_datainit = to; 149058112Seric else if (strcasecmp(val, "datablock") == 0) 149158112Seric TimeOuts.to_datablock = to; 149258112Seric else if (strcasecmp(val, "datafinal") == 0) 149358112Seric TimeOuts.to_datafinal = to; 149458112Seric else if (strcasecmp(val, "command") == 0) 149558112Seric TimeOuts.to_nextcommand = to; 149658112Seric else if (strcasecmp(val, "rset") == 0) 149758112Seric TimeOuts.to_rset = to; 149858112Seric else if (strcasecmp(val, "helo") == 0) 149958112Seric TimeOuts.to_helo = to; 150058112Seric else if (strcasecmp(val, "quit") == 0) 150158112Seric TimeOuts.to_quit = to; 150258112Seric else if (strcasecmp(val, "misc") == 0) 150358112Seric TimeOuts.to_miscshort = to; 150458112Seric else 150558112Seric syserr("settimeouts: invalid timeout %s", val); 150658112Seric } 150758112Seric } 150858112Seric } 1509