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*58671Seric static char sccsid[] = "@(#)readcf.c 6.17 (Berkeley) 03/14/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 */ 42857135Seric setoption(bp[1], &bp[2], safe, FALSE); 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. 9208256Seric ** 9218256Seric ** Returns: 9228256Seric ** none. 9238256Seric ** 9248256Seric ** Side Effects: 9258256Seric ** Sets options as implied by the arguments. 9268256Seric */ 9278256Seric 92810687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9298269Seric 93057207Seric 93157207Seric #ifdef NAMED_BIND 93257207Seric 93357207Seric struct resolverflags 93457207Seric { 93557207Seric char *rf_name; /* name of the flag */ 93657207Seric long rf_bits; /* bits to set/clear */ 93757207Seric } ResolverFlags[] = 93857207Seric { 93957207Seric "debug", RES_DEBUG, 94057207Seric "aaonly", RES_AAONLY, 94157207Seric "usevc", RES_USEVC, 94257207Seric "primary", RES_PRIMARY, 94357207Seric "igntc", RES_IGNTC, 94457207Seric "recurse", RES_RECURSE, 94557207Seric "defnames", RES_DEFNAMES, 94657207Seric "stayopen", RES_STAYOPEN, 94757207Seric "dnsrch", RES_DNSRCH, 94857207Seric NULL, 0 94957207Seric }; 95057207Seric 95157207Seric #endif 95257207Seric 95321755Seric setoption(opt, val, safe, sticky) 9548256Seric char opt; 9558256Seric char *val; 95621755Seric bool safe; 9578269Seric bool sticky; 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 97410687Seric if (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; 98758082Seric if (!safe && strchr("bdeEiLmoprsvC8", 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 { 100752106Seric case '8': /* allow eight-bit input */ 100852106Seric EightBit = atobool(val); 100952106Seric break; 101052106Seric 10118256Seric case 'A': /* set default alias file */ 10129381Seric if (val[0] == '\0') 10138269Seric AliasFile = "aliases"; 10149381Seric else 10159381Seric AliasFile = newstr(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 103158082Seric case 'b': /* minimum number of blocks free on queue fs */ 103258082Seric MinBlocksFree = atol(val); 103358082Seric break; 103458082Seric 10359284Seric case 'c': /* don't connect to "expensive" mailers */ 10369381Seric NoConnect = atobool(val); 10379284Seric break; 10389284Seric 103951305Seric case 'C': /* checkpoint every N addresses */ 104051305Seric CheckpointInterval = atoi(val); 104124944Seric break; 104224944Seric 10439284Seric case 'd': /* delivery mode */ 10449284Seric switch (*val) 10458269Seric { 10469284Seric case '\0': 10479284Seric SendMode = SM_DELIVER; 10488269Seric break; 10498269Seric 105010755Seric case SM_QUEUE: /* queue only */ 105110755Seric #ifndef QUEUE 105210755Seric syserr("need QUEUE to set -odqueue"); 105356795Seric #endif /* QUEUE */ 105410755Seric /* fall through..... */ 105510755Seric 10569284Seric case SM_DELIVER: /* do everything */ 10579284Seric case SM_FORK: /* fork after verification */ 10589284Seric SendMode = *val; 10598269Seric break; 10608269Seric 10618269Seric default: 10629284Seric syserr("Unknown delivery mode %c", *val); 10638269Seric exit(EX_USAGE); 10648269Seric } 10658269Seric break; 10668269Seric 10679146Seric case 'D': /* rebuild alias database as needed */ 10689381Seric AutoRebuild = atobool(val); 10699146Seric break; 10709146Seric 107155372Seric case 'E': /* error message header/header file */ 107255379Seric if (*val != '\0') 107355379Seric ErrMsgFile = newstr(val); 107455372Seric break; 107555372Seric 10768269Seric case 'e': /* set error processing mode */ 10778269Seric switch (*val) 10788269Seric { 10799381Seric case EM_QUIET: /* be silent about it */ 10809381Seric case EM_MAIL: /* mail back */ 10819381Seric case EM_BERKNET: /* do berknet error processing */ 10829381Seric case EM_WRITE: /* write back (or mail) */ 10838269Seric HoldErrs = TRUE; 10849381Seric /* fall through... */ 10858269Seric 10869381Seric case EM_PRINT: /* print errors normally (default) */ 10879381Seric ErrorMode = *val; 10888269Seric break; 10898269Seric } 10908269Seric break; 10918269Seric 10929049Seric case 'F': /* file mode */ 109317975Seric FileMode = atooct(val) & 0777; 10949049Seric break; 10959049Seric 10968269Seric case 'f': /* save Unix-style From lines on front */ 10979381Seric SaveFrom = atobool(val); 10988269Seric break; 10998269Seric 110053735Seric case 'G': /* match recipients against GECOS field */ 110153735Seric MatchGecos = atobool(val); 110253735Seric break; 110353735Seric 11048256Seric case 'g': /* default gid */ 110517474Seric DefGid = atoi(val); 11068256Seric break; 11078256Seric 11088256Seric case 'H': /* help file */ 11099381Seric if (val[0] == '\0') 11108269Seric HelpFile = "sendmail.hf"; 11119381Seric else 11129381Seric HelpFile = newstr(val); 11138256Seric break; 11148256Seric 111551305Seric case 'h': /* maximum hop count */ 111651305Seric MaxHopCount = atoi(val); 111751305Seric break; 111851305Seric 111935651Seric case 'I': /* use internet domain name server */ 112057207Seric #ifdef NAMED_BIND 112157207Seric UseNameServer = TRUE; 112257207Seric for (p = val; *p != 0; ) 112357207Seric { 112457207Seric bool clearmode; 112557207Seric char *q; 112657207Seric struct resolverflags *rfp; 112757207Seric 112857207Seric while (*p == ' ') 112957207Seric p++; 113057207Seric if (*p == '\0') 113157207Seric break; 113257207Seric clearmode = FALSE; 113357207Seric if (*p == '-') 113457207Seric clearmode = TRUE; 113557207Seric else if (*p != '+') 113657207Seric p--; 113757207Seric p++; 113857207Seric q = p; 113958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114057207Seric p++; 114157207Seric if (*p != '\0') 114257207Seric *p++ = '\0'; 114357207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114457207Seric { 114557207Seric if (strcasecmp(q, rfp->rf_name) == 0) 114657207Seric break; 114757207Seric } 114857207Seric if (clearmode) 114957207Seric _res.options &= ~rfp->rf_bits; 115057207Seric else 115157207Seric _res.options |= rfp->rf_bits; 115257207Seric } 115357207Seric if (tTd(8, 2)) 115457207Seric printf("_res.options = %x\n", _res.options); 115557207Seric #else 115657207Seric usrerr("name server (I option) specified but BIND not compiled in"); 115757207Seric #endif 115835651Seric break; 115935651Seric 11608269Seric case 'i': /* ignore dot lines in message */ 11619381Seric IgnrDot = atobool(val); 11628269Seric break; 11638269Seric 116457136Seric case 'J': /* .forward search path */ 116557136Seric ForwardPath = newstr(val); 116657136Seric break; 116757136Seric 116854967Seric case 'k': /* connection cache size */ 116954967Seric MaxMciCache = atoi(val); 117056215Seric if (MaxMciCache < 0) 117156215Seric MaxMciCache = 0; 117254967Seric break; 117354967Seric 117454967Seric case 'K': /* connection cache timeout */ 117554967Seric MciCacheTimeout = convtime(val); 117654967Seric break; 117754967Seric 11788256Seric case 'L': /* log level */ 11799381Seric LogLevel = atoi(val); 11808256Seric break; 11818256Seric 11828269Seric case 'M': /* define macro */ 11839381Seric define(val[0], newstr(&val[1]), CurEnv); 118416878Seric sticky = FALSE; 11858269Seric break; 11868269Seric 11878269Seric case 'm': /* send to me too */ 11889381Seric MeToo = atobool(val); 11898269Seric break; 11908269Seric 119125820Seric case 'n': /* validate RHS in newaliases */ 119225820Seric CheckAliases = atobool(val); 119325820Seric break; 119425820Seric 11958269Seric case 'o': /* assume old style headers */ 11969381Seric if (atobool(val)) 11979341Seric CurEnv->e_flags |= EF_OLDSTYLE; 11989341Seric else 11999341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12008269Seric break; 12018269Seric 120258082Seric case 'p': /* select privacy level */ 120358082Seric p = val; 120458082Seric for (;;) 120558082Seric { 120658082Seric register struct prival *pv; 120758082Seric extern struct prival PrivacyValues[]; 120858082Seric 120958082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 121058082Seric p++; 121158082Seric if (*p == '\0') 121258082Seric break; 121358082Seric val = p; 121458082Seric while (isascii(*p) && isalnum(*p)) 121558082Seric p++; 121658082Seric if (*p != '\0') 121758082Seric *p++ = '\0'; 121858082Seric 121958082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 122058082Seric { 122158082Seric if (strcasecmp(val, pv->pv_name) == 0) 122258082Seric break; 122358082Seric } 122458082Seric PrivacyFlags |= pv->pv_flag; 122558082Seric } 122658082Seric break; 122758082Seric 122824944Seric case 'P': /* postmaster copy address for returned mail */ 122924944Seric PostMasterCopy = newstr(val); 123024944Seric break; 123124944Seric 123224944Seric case 'q': /* slope of queue only function */ 123324944Seric QueueFactor = atoi(val); 123424944Seric break; 123524944Seric 12368256Seric case 'Q': /* queue directory */ 12379381Seric if (val[0] == '\0') 12388269Seric QueueDir = "mqueue"; 12399381Seric else 12409381Seric QueueDir = newstr(val); 12418256Seric break; 12428256Seric 124358148Seric case 'R': /* don't prune routes */ 124458148Seric DontPruneRoutes = atobool(val); 124558148Seric break; 124658148Seric 12478256Seric case 'r': /* read timeout */ 124858112Seric settimeouts(val); 12498256Seric break; 12508256Seric 12518256Seric case 'S': /* status file */ 12529381Seric if (val[0] == '\0') 12538269Seric StatFile = "sendmail.st"; 12549381Seric else 12559381Seric StatFile = newstr(val); 12568256Seric break; 12578256Seric 12588265Seric case 's': /* be super safe, even if expensive */ 12599381Seric SuperSafe = atobool(val); 12608256Seric break; 12618256Seric 12628256Seric case 'T': /* queue timeout */ 12639381Seric TimeOut = convtime(val); 126454967Seric break; 12658256Seric 12668265Seric case 't': /* time zone name */ 126752106Seric TimeZoneSpec = newstr(val); 12688265Seric break; 12698265Seric 127050556Seric case 'U': /* location of user database */ 127151360Seric UdbSpec = newstr(val); 127250556Seric break; 127350556Seric 12748256Seric case 'u': /* set default uid */ 127517474Seric DefUid = atoi(val); 127640973Sbostic setdefuser(); 12778256Seric break; 12788256Seric 12798269Seric case 'v': /* run in verbose mode */ 12809381Seric Verbose = atobool(val); 12818256Seric break; 12828256Seric 128314879Seric case 'x': /* load avg at which to auto-queue msgs */ 128414879Seric QueueLA = atoi(val); 128514879Seric break; 128614879Seric 128714879Seric case 'X': /* load avg at which to auto-reject connections */ 128814879Seric RefuseLA = atoi(val); 128914879Seric break; 129014879Seric 129124981Seric case 'y': /* work recipient factor */ 129224981Seric WkRecipFact = atoi(val); 129324981Seric break; 129424981Seric 129524981Seric case 'Y': /* fork jobs during queue runs */ 129624952Seric ForkQueueRuns = atobool(val); 129724952Seric break; 129824952Seric 129924981Seric case 'z': /* work message class factor */ 130024981Seric WkClassFact = atoi(val); 130124981Seric break; 130224981Seric 130324981Seric case 'Z': /* work time factor */ 130424981Seric WkTimeFact = atoi(val); 130524981Seric break; 130624981Seric 13078256Seric default: 13088256Seric break; 13098256Seric } 131016878Seric if (sticky) 131116878Seric setbitn(opt, StickyOpt); 13129188Seric return; 13138256Seric } 131410687Seric /* 131510687Seric ** SETCLASS -- set a word into a class 131610687Seric ** 131710687Seric ** Parameters: 131810687Seric ** class -- the class to put the word in. 131910687Seric ** word -- the word to enter 132010687Seric ** 132110687Seric ** Returns: 132210687Seric ** none. 132310687Seric ** 132410687Seric ** Side Effects: 132510687Seric ** puts the word into the symbol table. 132610687Seric */ 132710687Seric 132810687Seric setclass(class, word) 132910687Seric int class; 133010687Seric char *word; 133110687Seric { 133210687Seric register STAB *s; 133310687Seric 133457943Seric if (tTd(37, 8)) 133557943Seric printf("%s added to class %c\n", word, class); 133610687Seric s = stab(word, ST_CLASS, ST_ENTER); 133710687Seric setbitn(class, s->s_class); 133810687Seric } 133953654Seric /* 134053654Seric ** MAKEMAPENTRY -- create a map entry 134153654Seric ** 134253654Seric ** Parameters: 134353654Seric ** line -- the config file line 134453654Seric ** 134553654Seric ** Returns: 134653654Seric ** TRUE if it successfully entered the map entry. 134753654Seric ** FALSE otherwise (usually syntax error). 134853654Seric ** 134953654Seric ** Side Effects: 135053654Seric ** Enters the map into the dictionary. 135153654Seric */ 135253654Seric 135353654Seric void 135453654Seric makemapentry(line) 135553654Seric char *line; 135653654Seric { 135753654Seric register char *p; 135853654Seric char *mapname; 135953654Seric char *classname; 136053654Seric register STAB *map; 136153654Seric STAB *class; 136253654Seric 136358050Seric for (p = line; isascii(*p) && isspace(*p); p++) 136453654Seric continue; 136558050Seric if (!(isascii(*p) && isalnum(*p))) 136653654Seric { 136753654Seric syserr("readcf: config K line: no map name"); 136853654Seric return; 136953654Seric } 137053654Seric 137153654Seric mapname = p; 137258050Seric while (isascii(*++p) && isalnum(*p)) 137353654Seric continue; 137453654Seric if (*p != '\0') 137553654Seric *p++ = '\0'; 137658050Seric while (isascii(*p) && isspace(*p)) 137753654Seric p++; 137858050Seric if (!(isascii(*p) && isalnum(*p))) 137953654Seric { 138053654Seric syserr("readcf: config K line, map %s: no map class", mapname); 138153654Seric return; 138253654Seric } 138353654Seric classname = p; 138458050Seric while (isascii(*++p) && isalnum(*p)) 138553654Seric continue; 138653654Seric if (*p != '\0') 138753654Seric *p++ = '\0'; 138858050Seric while (isascii(*p) && isspace(*p)) 138953654Seric p++; 139053654Seric 139153654Seric /* look up the class */ 139253654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 139353654Seric if (class == NULL) 139453654Seric { 139553654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 139653654Seric return; 139753654Seric } 139853654Seric 139953654Seric /* enter the map */ 140053654Seric map = stab(mapname, ST_MAP, ST_ENTER); 140153654Seric map->s_map.map_class = &class->s_mapclass; 140253654Seric 140356823Seric if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 140453654Seric map->s_map.map_flags |= MF_VALID; 140553654Seric } 140658112Seric /* 140758112Seric ** SETTIMEOUTS -- parse and set timeout values 140858112Seric ** 140958112Seric ** Parameters: 141058112Seric ** val -- a pointer to the values. If NULL, do initial 141158112Seric ** settings. 141258112Seric ** 141358112Seric ** Returns: 141458112Seric ** none. 141558112Seric ** 141658112Seric ** Side Effects: 141758112Seric ** Initializes the TimeOuts structure 141858112Seric */ 141958112Seric 142058112Seric #define MINUTES * 60 142158112Seric #define HOUR * 3600 142258112Seric 142358112Seric settimeouts(val) 142458112Seric register char *val; 142558112Seric { 142658112Seric register char *p; 1427*58671Seric extern time_t convtime(); 142858112Seric 142958112Seric if (val == NULL) 143058112Seric { 143158112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 143258112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 143358112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 143458112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 143558112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 143658112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 143758112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 143858112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 143958112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 144058112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 144158112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 144258112Seric return; 144358112Seric } 144458112Seric 144558112Seric for (;; val = p) 144658112Seric { 144758112Seric while (isascii(*val) && isspace(*val)) 144858112Seric val++; 144958112Seric if (*val == '\0') 145058112Seric break; 145158112Seric for (p = val; *p != '\0' && *p != ','; p++) 145258112Seric continue; 145358112Seric if (*p != '\0') 145458112Seric *p++ = '\0'; 145558112Seric 145658112Seric if (isascii(*val) && isdigit(*val)) 145758112Seric { 145858112Seric /* old syntax -- set everything */ 145958112Seric TimeOuts.to_mail = convtime(val); 146058112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 146158112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 146258112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 146358112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 146458112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 146558112Seric continue; 146658112Seric } 146758112Seric else 146858112Seric { 146958112Seric register char *q = strchr(val, '='); 147058112Seric time_t to; 147158112Seric 147258112Seric if (q == NULL) 147358112Seric { 147458112Seric /* syntax error */ 147558112Seric continue; 147658112Seric } 147758112Seric *q++ = '\0'; 147858112Seric to = convtime(q); 147958112Seric 148058112Seric if (strcasecmp(val, "initial") == 0) 148158112Seric TimeOuts.to_initial = to; 148258112Seric else if (strcasecmp(val, "mail") == 0) 148358112Seric TimeOuts.to_mail = to; 148458112Seric else if (strcasecmp(val, "rcpt") == 0) 148558112Seric TimeOuts.to_rcpt = to; 148658112Seric else if (strcasecmp(val, "datainit") == 0) 148758112Seric TimeOuts.to_datainit = to; 148858112Seric else if (strcasecmp(val, "datablock") == 0) 148958112Seric TimeOuts.to_datablock = to; 149058112Seric else if (strcasecmp(val, "datafinal") == 0) 149158112Seric TimeOuts.to_datafinal = to; 149258112Seric else if (strcasecmp(val, "command") == 0) 149358112Seric TimeOuts.to_nextcommand = to; 149458112Seric else if (strcasecmp(val, "rset") == 0) 149558112Seric TimeOuts.to_rset = to; 149658112Seric else if (strcasecmp(val, "helo") == 0) 149758112Seric TimeOuts.to_helo = to; 149858112Seric else if (strcasecmp(val, "quit") == 0) 149958112Seric TimeOuts.to_quit = to; 150058112Seric else if (strcasecmp(val, "misc") == 0) 150158112Seric TimeOuts.to_miscshort = to; 150258112Seric else 150358112Seric syserr("settimeouts: invalid timeout %s", val); 150458112Seric } 150558112Seric } 150658112Seric } 1507