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*58321Seric static char sccsid[] = "@(#)readcf.c 6.14 (Berkeley) 02/28/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1452647Seric # include <sys/stat.h> 1554973Seric # include <unistd.h> 1657207Seric #ifdef NAMED_BIND 1757207Seric # include <arpa/nameser.h> 1857207Seric # include <resolv.h> 1957207Seric #endif 203308Seric 2157736Seric /* System 5 compatibility */ 2257736Seric #ifndef S_ISREG 2357736Seric #define S_ISREG(foo) ((foo & S_IFREG) == S_IFREG) 2457736Seric #endif 2557736Seric #ifndef S_IWGRP 2657736Seric #define S_IWGRP 020 2757736Seric #endif 2857736Seric #ifndef S_IWOTH 2957736Seric #define S_IWOTH 002 3057736Seric #endif 3157736Seric 323308Seric /* 333308Seric ** READCF -- read control file. 343308Seric ** 353308Seric ** This routine reads the control file and builds the internal 363308Seric ** form. 373308Seric ** 384432Seric ** The file is formatted as a sequence of lines, each taken 394432Seric ** atomically. The first character of each line describes how 404432Seric ** the line is to be interpreted. The lines are: 414432Seric ** Dxval Define macro x to have value val. 424432Seric ** Cxword Put word into class x. 434432Seric ** Fxfile [fmt] Read file for lines to put into 444432Seric ** class x. Use scanf string 'fmt' 454432Seric ** or "%s" if not present. Fmt should 464432Seric ** only produce one string-valued result. 474432Seric ** Hname: value Define header with field-name 'name' 484432Seric ** and value as specified; this will be 494432Seric ** macro expanded immediately before 504432Seric ** use. 514432Seric ** Sn Use rewriting set n. 524432Seric ** Rlhs rhs Rewrite addresses that match lhs to 534432Seric ** be rhs. 5424944Seric ** Mn arg=val... Define mailer. n is the internal name. 5524944Seric ** Args specify mailer parameters. 568252Seric ** Oxvalue Set option x to value. 578252Seric ** Pname=value Set precedence name to value. 5852645Seric ** Vversioncode Version level of configuration syntax. 5953654Seric ** Kmapname mapclass arguments.... 6053654Seric ** Define keyed lookup of a given class. 6153654Seric ** Arguments are class dependent. 624432Seric ** 633308Seric ** Parameters: 643308Seric ** cfname -- control file name. 6554973Seric ** safe -- TRUE if this is the system config file; 6654973Seric ** FALSE otherwise. 6755012Seric ** e -- the main envelope. 683308Seric ** 693308Seric ** Returns: 703308Seric ** none. 713308Seric ** 723308Seric ** Side Effects: 733308Seric ** Builds several internal tables. 743308Seric */ 753308Seric 7655012Seric readcf(cfname, safe, e) 773308Seric char *cfname; 7854973Seric bool safe; 7955012Seric register ENVELOPE *e; 803308Seric { 813308Seric FILE *cf; 828547Seric int ruleset = 0; 838547Seric char *q; 848547Seric char **pv; 859350Seric struct rewrite *rwp = NULL; 8657135Seric char *bp; 8757589Seric int nfuzzy; 883308Seric char buf[MAXLINE]; 893308Seric register char *p; 903308Seric extern char **prescan(); 913308Seric extern char **copyplist(); 9252647Seric struct stat statb; 935909Seric char exbuf[MAXLINE]; 9416915Seric char pvpbuf[PSBUFSIZE]; 959350Seric extern char *fgetfolded(); 9610709Seric extern char *munchstring(); 9753654Seric extern void makemapentry(); 983308Seric 9952647Seric FileName = cfname; 10052647Seric LineNumber = 0; 10152647Seric 1023308Seric cf = fopen(cfname, "r"); 1033308Seric if (cf == NULL) 1043308Seric { 10552647Seric syserr("cannot open"); 1063308Seric exit(EX_OSFILE); 1073308Seric } 1083308Seric 10952647Seric if (fstat(fileno(cf), &statb) < 0) 11052647Seric { 11152647Seric syserr("cannot fstat"); 11252647Seric exit(EX_OSFILE); 11352647Seric } 11452647Seric 11552647Seric if (!S_ISREG(statb.st_mode)) 11652647Seric { 11752647Seric syserr("not a plain file"); 11852647Seric exit(EX_OSFILE); 11952647Seric } 12052647Seric 12152647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 12252647Seric { 12353037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 12453037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 12553037Seric FileName); 12653037Seric #ifdef LOG 12753037Seric if (LogLevel > 0) 12853037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 12953037Seric FileName); 13053037Seric #endif 13152647Seric } 13252647Seric 13357135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1343308Seric { 13557135Seric if (bp[0] == '#') 13657135Seric { 13757135Seric if (bp != buf) 13857135Seric free(bp); 13952637Seric continue; 14057135Seric } 14152637Seric 14258050Seric /* map $ into \201 for macro expansion */ 14357135Seric for (p = bp; *p != '\0'; p++) 14416157Seric { 14557135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14652647Seric { 14752647Seric /* this is an on-line comment */ 14852647Seric register char *e; 14952647Seric 15058050Seric switch (*--p & 0377) 15152647Seric { 15258050Seric case MACROEXPAND: 15352647Seric /* it's from $# -- let it go through */ 15452647Seric p++; 15552647Seric break; 15652647Seric 15752647Seric case '\\': 15852647Seric /* it's backslash escaped */ 15952647Seric (void) strcpy(p, p + 1); 16052647Seric break; 16152647Seric 16252647Seric default: 16352647Seric /* delete preceeding white space */ 16458050Seric while (isascii(*p) && isspace(*p) && p > bp) 16552647Seric p--; 16656795Seric if ((e = strchr(++p, '\n')) != NULL) 16752647Seric (void) strcpy(p, e); 16852647Seric else 16952647Seric p[0] = p[1] = '\0'; 17052647Seric break; 17152647Seric } 17252647Seric continue; 17352647Seric } 17452647Seric 17516157Seric if (*p != '$') 17616157Seric continue; 17716157Seric 17816157Seric if (p[1] == '$') 17916157Seric { 18016157Seric /* actual dollar sign.... */ 18123111Seric (void) strcpy(p, p + 1); 18216157Seric continue; 18316157Seric } 18416157Seric 18516157Seric /* convert to macro expansion character */ 18658050Seric *p = MACROEXPAND; 18716157Seric } 18816157Seric 18916157Seric /* interpret this line */ 19057135Seric switch (bp[0]) 1913308Seric { 1923308Seric case '\0': 1933308Seric case '#': /* comment */ 1943308Seric break; 1953308Seric 1963308Seric case 'R': /* rewriting rule */ 19757135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1983308Seric continue; 1993308Seric 2003308Seric if (*p == '\0') 2015909Seric { 20257135Seric syserr("invalid rewrite line \"%s\"", bp); 2035909Seric break; 2045909Seric } 2055909Seric 2065909Seric /* allocate space for the rule header */ 2075909Seric if (rwp == NULL) 2085909Seric { 2095909Seric RewriteRules[ruleset] = rwp = 2105909Seric (struct rewrite *) xalloc(sizeof *rwp); 2115909Seric } 2123308Seric else 2133308Seric { 2145909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2155909Seric rwp = rwp->r_next; 2165909Seric } 2175909Seric rwp->r_next = NULL; 2183308Seric 2195909Seric /* expand and save the LHS */ 2205909Seric *p = '\0'; 22157135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 22216915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 22357589Seric nfuzzy = 0; 2245909Seric if (rwp->r_lhs != NULL) 22557589Seric { 22657589Seric register char **ap; 22757589Seric 2285909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22957589Seric 23057589Seric /* count the number of fuzzy matches in LHS */ 23157589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 23257589Seric { 23358148Seric char *botch; 23458148Seric 23558148Seric botch = NULL; 23658050Seric switch (**ap & 0377) 23757589Seric { 23857589Seric case MATCHZANY: 23957589Seric case MATCHANY: 24057589Seric case MATCHONE: 24157589Seric case MATCHCLASS: 24257589Seric case MATCHNCLASS: 24358173Seric case CANONHOST: 24457589Seric nfuzzy++; 24558148Seric break; 24658148Seric 24758148Seric case MATCHREPL: 24858148Seric botch = "$0-$9"; 24958148Seric break; 25058148Seric 25158148Seric case CANONNET: 25258148Seric botch = "$#"; 25358148Seric break; 25458148Seric 25558148Seric case CANONUSER: 25658148Seric botch = "$:"; 25758148Seric break; 25858148Seric 25958148Seric case CALLSUBR: 26058148Seric botch = "$>"; 26158148Seric break; 26258148Seric 26358148Seric case CONDIF: 26458148Seric botch = "$?"; 26558148Seric break; 26658148Seric 26758148Seric case CONDELSE: 26858148Seric botch = "$|"; 26958148Seric break; 27058148Seric 27158148Seric case CONDFI: 27258148Seric botch = "$."; 27358148Seric break; 27458148Seric 27558148Seric case HOSTBEGIN: 27658148Seric botch = "$["; 27758148Seric break; 27858148Seric 27958148Seric case HOSTEND: 28058148Seric botch = "$]"; 28158148Seric break; 28258148Seric 28358148Seric case LOOKUPBEGIN: 28458148Seric botch = "$("; 28558148Seric break; 28658148Seric 28758148Seric case LOOKUPEND: 28858148Seric botch = "$)"; 28958148Seric break; 29057589Seric } 29158148Seric if (botch != NULL) 29258148Seric syserr("Inappropriate use of %s on LHS", 29358148Seric botch); 29457589Seric } 29557589Seric } 29656678Seric else 29756678Seric syserr("R line: null LHS"); 2985909Seric 2995909Seric /* expand and save the RHS */ 3005909Seric while (*++p == '\t') 3015909Seric continue; 3027231Seric q = p; 3037231Seric while (*p != '\0' && *p != '\t') 3047231Seric p++; 3057231Seric *p = '\0'; 30655012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 30716915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 3085909Seric if (rwp->r_rhs != NULL) 30957589Seric { 31057589Seric register char **ap; 31157589Seric 3125909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 31357589Seric 31457589Seric /* check no out-of-bounds replacements */ 31557589Seric nfuzzy += '0'; 31657589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31757589Seric { 31858148Seric char *botch; 31958148Seric 32058148Seric botch = NULL; 32158148Seric switch (**ap & 0377) 32257589Seric { 32358148Seric case MATCHREPL: 32458148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32558148Seric { 32658148Seric syserr("replacement $%c out of bounds", 32758148Seric (*ap)[1]); 32858148Seric } 32958148Seric break; 33058148Seric 33158148Seric case MATCHZANY: 33258148Seric botch = "$*"; 33358148Seric break; 33458148Seric 33558148Seric case MATCHANY: 33658148Seric botch = "$+"; 33758148Seric break; 33858148Seric 33958148Seric case MATCHONE: 34058148Seric botch = "$-"; 34158148Seric break; 34258148Seric 34358148Seric case MATCHCLASS: 34458148Seric botch = "$="; 34558148Seric break; 34658148Seric 34758148Seric case MATCHNCLASS: 34858148Seric botch = "$~"; 34958148Seric break; 35057589Seric } 35158148Seric if (botch != NULL) 35258148Seric syserr("Inappropriate use of %s on RHS", 35358148Seric botch); 35457589Seric } 35557589Seric } 35656678Seric else 35756678Seric syserr("R line: null RHS"); 3583308Seric break; 3593308Seric 3604072Seric case 'S': /* select rewriting set */ 36157135Seric ruleset = atoi(&bp[1]); 3628056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3638056Seric { 3649381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3658056Seric ruleset = 0; 3668056Seric } 3674072Seric rwp = NULL; 3684072Seric break; 3694072Seric 3703308Seric case 'D': /* macro definition */ 37157135Seric define(bp[1], newstr(munchstring(&bp[2])), e); 3723308Seric break; 3733308Seric 3743387Seric case 'H': /* required header line */ 37557135Seric (void) chompheader(&bp[1], TRUE, e); 3763387Seric break; 3773387Seric 3784061Seric case 'C': /* word class */ 3794432Seric case 'F': /* word class from file */ 3804432Seric /* read list of words from argument or file */ 38157135Seric if (bp[0] == 'F') 3824432Seric { 3834432Seric /* read from file */ 38458050Seric for (p = &bp[2]; 38558050Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 38658050Seric p++) 3874432Seric continue; 3884432Seric if (*p == '\0') 3894432Seric p = "%s"; 3904432Seric else 3914432Seric { 3924432Seric *p = '\0'; 39358050Seric while (isascii(*++p) && isspace(*p)) 3944432Seric continue; 3954432Seric } 39657135Seric fileclass(bp[1], &bp[2], p, safe); 3974432Seric break; 3984432Seric } 3994061Seric 4004432Seric /* scan the list of words and set class for all */ 40157135Seric for (p = &bp[2]; *p != '\0'; ) 4024061Seric { 4034061Seric register char *wd; 4044061Seric char delim; 4054061Seric 40658050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 4074061Seric p++; 4084061Seric wd = p; 40958050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 4104061Seric p++; 4114061Seric delim = *p; 4124061Seric *p = '\0'; 4134061Seric if (wd[0] != '\0') 41458148Seric { 41558148Seric if (tTd(37, 2)) 41658148Seric printf("setclass(%c, %s)\n", 41758148Seric bp[1], wd); 41857135Seric setclass(bp[1], wd); 41958148Seric } 4204061Seric *p = delim; 4214061Seric } 4224061Seric break; 4234061Seric 4244096Seric case 'M': /* define mailer */ 42557135Seric makemailer(&bp[1]); 4264096Seric break; 4274096Seric 4288252Seric case 'O': /* set option */ 42957135Seric setoption(bp[1], &bp[2], safe, FALSE); 4308252Seric break; 4318252Seric 4328252Seric case 'P': /* set precedence */ 4338252Seric if (NumPriorities >= MAXPRIORITIES) 4348252Seric { 4358547Seric toomany('P', MAXPRIORITIES); 4368252Seric break; 4378252Seric } 43857135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4398252Seric continue; 4408252Seric if (*p == '\0') 4418252Seric goto badline; 4428252Seric *p = '\0'; 44357135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4448252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4458252Seric NumPriorities++; 4468252Seric break; 4478252Seric 4488547Seric case 'T': /* trusted user(s) */ 44958161Seric /* this option is obsolete, but will be ignored */ 4508547Seric break; 4518547Seric 45252645Seric case 'V': /* configuration syntax version */ 45357135Seric ConfigLevel = atoi(&bp[1]); 45452645Seric break; 45552645Seric 45653654Seric case 'K': 45757135Seric makemapentry(&bp[1]); 45853654Seric break; 45953654Seric 4603308Seric default: 4614061Seric badline: 46257135Seric syserr("unknown control line \"%s\"", bp); 4633308Seric } 46457135Seric if (bp != buf) 46557135Seric free(bp); 4663308Seric } 46752637Seric if (ferror(cf)) 46852637Seric { 46952647Seric syserr("I/O read error", cfname); 47052637Seric exit(EX_OSFILE); 47152637Seric } 47252637Seric fclose(cf); 4739381Seric FileName = NULL; 47456836Seric 47557076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 47657076Seric { 47757076Seric /* user didn't initialize: set up host map */ 47857076Seric strcpy(buf, "host host"); 47957076Seric if (ConfigLevel >= 2) 48057076Seric strcat(buf, " -a."); 48157076Seric makemapentry(buf); 48257076Seric } 4834096Seric } 4844096Seric /* 4858547Seric ** TOOMANY -- signal too many of some option 4868547Seric ** 4878547Seric ** Parameters: 4888547Seric ** id -- the id of the error line 4898547Seric ** maxcnt -- the maximum possible values 4908547Seric ** 4918547Seric ** Returns: 4928547Seric ** none. 4938547Seric ** 4948547Seric ** Side Effects: 4958547Seric ** gives a syserr. 4968547Seric */ 4978547Seric 4988547Seric toomany(id, maxcnt) 4998547Seric char id; 5008547Seric int maxcnt; 5018547Seric { 5029381Seric syserr("too many %c lines, %d max", id, maxcnt); 5038547Seric } 5048547Seric /* 5054432Seric ** FILECLASS -- read members of a class from a file 5064432Seric ** 5074432Seric ** Parameters: 5084432Seric ** class -- class to define. 5094432Seric ** filename -- name of file to read. 5104432Seric ** fmt -- scanf string to use for match. 5114432Seric ** 5124432Seric ** Returns: 5134432Seric ** none 5144432Seric ** 5154432Seric ** Side Effects: 5164432Seric ** 5174432Seric ** puts all lines in filename that match a scanf into 5184432Seric ** the named class. 5194432Seric */ 5204432Seric 52154973Seric fileclass(class, filename, fmt, safe) 5224432Seric int class; 5234432Seric char *filename; 5244432Seric char *fmt; 52554973Seric bool safe; 5264432Seric { 52725808Seric FILE *f; 52854973Seric struct stat stbuf; 5294432Seric char buf[MAXLINE]; 5304432Seric 53154973Seric if (stat(filename, &stbuf) < 0) 53254973Seric { 53354973Seric syserr("fileclass: cannot stat %s", filename); 53454973Seric return; 53554973Seric } 53654973Seric if (!S_ISREG(stbuf.st_mode)) 53754973Seric { 53854973Seric syserr("fileclass: %s not a regular file", filename); 53954973Seric return; 54054973Seric } 54154973Seric if (!safe && access(filename, R_OK) < 0) 54254973Seric { 54354973Seric syserr("fileclass: access denied on %s", filename); 54454973Seric return; 54554973Seric } 54654973Seric f = fopen(filename, "r"); 5474432Seric if (f == NULL) 5484432Seric { 54954973Seric syserr("fileclass: cannot open %s", filename); 5504432Seric return; 5514432Seric } 5524432Seric 5534432Seric while (fgets(buf, sizeof buf, f) != NULL) 5544432Seric { 5554432Seric register STAB *s; 55625808Seric register char *p; 55725808Seric # ifdef SCANF 5584432Seric char wordbuf[MAXNAME+1]; 5594432Seric 5604432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5614432Seric continue; 56225808Seric p = wordbuf; 56356795Seric # else /* SCANF */ 56425808Seric p = buf; 56556795Seric # endif /* SCANF */ 56625808Seric 56725808Seric /* 56825808Seric ** Break up the match into words. 56925808Seric */ 57025808Seric 57125808Seric while (*p != '\0') 57225808Seric { 57325808Seric register char *q; 57425808Seric 57525808Seric /* strip leading spaces */ 57658050Seric while (isascii(*p) && isspace(*p)) 57725808Seric p++; 57825808Seric if (*p == '\0') 57925808Seric break; 58025808Seric 58125808Seric /* find the end of the word */ 58225808Seric q = p; 58358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 58425808Seric p++; 58525808Seric if (*p != '\0') 58625808Seric *p++ = '\0'; 58725808Seric 58825808Seric /* enter the word in the symbol table */ 58925808Seric s = stab(q, ST_CLASS, ST_ENTER); 59025808Seric setbitn(class, s->s_class); 59125808Seric } 5924432Seric } 5934432Seric 59454973Seric (void) fclose(f); 5954432Seric } 5964432Seric /* 5974096Seric ** MAKEMAILER -- define a new mailer. 5984096Seric ** 5994096Seric ** Parameters: 60010327Seric ** line -- description of mailer. This is in labeled 60110327Seric ** fields. The fields are: 60210327Seric ** P -- the path to the mailer 60310327Seric ** F -- the flags associated with the mailer 60410327Seric ** A -- the argv for this mailer 60510327Seric ** S -- the sender rewriting set 60610327Seric ** R -- the recipient rewriting set 60710327Seric ** E -- the eol string 60810327Seric ** The first word is the canonical name of the mailer. 6094096Seric ** 6104096Seric ** Returns: 6114096Seric ** none. 6124096Seric ** 6134096Seric ** Side Effects: 6144096Seric ** enters the mailer into the mailer table. 6154096Seric */ 6163308Seric 61721066Seric makemailer(line) 6184096Seric char *line; 6194096Seric { 6204096Seric register char *p; 6218067Seric register struct mailer *m; 6228067Seric register STAB *s; 6238067Seric int i; 62410327Seric char fcode; 62558020Seric auto char *endp; 6264096Seric extern int NextMailer; 62710327Seric extern char **makeargv(); 62810327Seric extern char *munchstring(); 62910327Seric extern char *DelimChar; 63010701Seric extern long atol(); 6314096Seric 63210327Seric /* allocate a mailer and set up defaults */ 63310327Seric m = (struct mailer *) xalloc(sizeof *m); 63410327Seric bzero((char *) m, sizeof *m); 63510327Seric m->m_eol = "\n"; 63610327Seric 63710327Seric /* collect the mailer name */ 63858050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 63910327Seric continue; 64010327Seric if (*p != '\0') 64110327Seric *p++ = '\0'; 64210327Seric m->m_name = newstr(line); 64310327Seric 64410327Seric /* now scan through and assign info from the fields */ 64510327Seric while (*p != '\0') 64610327Seric { 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 */ 66310327Seric p = munchstring(p); 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 72510327Seric p = DelimChar; 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 737*58321Seric /* do some rationality checking */ 738*58321Seric if (m->m_argv == NULL) 739*58321Seric { 740*58321Seric syserr("M%s: A= argument required", m->m_name); 741*58321Seric return; 742*58321Seric } 743*58321Seric if (m->m_mailer == NULL) 744*58321Seric { 745*58321Seric syserr("M%s: P= argument required", m->m_name); 746*58321Seric return; 747*58321Seric } 748*58321Seric 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. 77310327Seric ** 77410327Seric ** Returns: 77510327Seric ** the munched string. 77610327Seric ** 77710327Seric ** Side Effects: 77810327Seric ** Sets "DelimChar" to point to the string that caused us 77910327Seric ** to stop. 78010327Seric */ 7814096Seric 78210327Seric char * 78310327Seric munchstring(p) 78410327Seric register char *p; 78510327Seric { 78610327Seric register char *q; 78710327Seric bool backslash = FALSE; 78810327Seric bool quotemode = FALSE; 78910327Seric static char buf[MAXLINE]; 79010327Seric extern char *DelimChar; 7914096Seric 79210327Seric for (q = buf; *p != '\0'; p++) 7934096Seric { 79410327Seric if (backslash) 79510327Seric { 79610327Seric /* everything is roughly literal */ 79710357Seric backslash = FALSE; 79810327Seric switch (*p) 79910327Seric { 80010327Seric case 'r': /* carriage return */ 80110327Seric *q++ = '\r'; 80210327Seric continue; 80310327Seric 80410327Seric case 'n': /* newline */ 80510327Seric *q++ = '\n'; 80610327Seric continue; 80710327Seric 80810327Seric case 'f': /* form feed */ 80910327Seric *q++ = '\f'; 81010327Seric continue; 81110327Seric 81210327Seric case 'b': /* backspace */ 81310327Seric *q++ = '\b'; 81410327Seric continue; 81510327Seric } 81610327Seric *q++ = *p; 81710327Seric } 81810327Seric else 81910327Seric { 82010327Seric if (*p == '\\') 82110327Seric backslash = TRUE; 82210327Seric else if (*p == '"') 82310327Seric quotemode = !quotemode; 82410327Seric else if (quotemode || *p != ',') 82510327Seric *q++ = *p; 82610327Seric else 82710327Seric break; 82810327Seric } 8294096Seric } 8304096Seric 83110327Seric DelimChar = p; 83210327Seric *q++ = '\0'; 83310327Seric return (buf); 83410327Seric } 83510327Seric /* 83610327Seric ** MAKEARGV -- break up a string into words 83710327Seric ** 83810327Seric ** Parameters: 83910327Seric ** p -- the string to break up. 84010327Seric ** 84110327Seric ** Returns: 84210327Seric ** a char **argv (dynamically allocated) 84310327Seric ** 84410327Seric ** Side Effects: 84510327Seric ** munges p. 84610327Seric */ 8474096Seric 84810327Seric char ** 84910327Seric makeargv(p) 85010327Seric register char *p; 85110327Seric { 85210327Seric char *q; 85310327Seric int i; 85410327Seric char **avp; 85510327Seric char *argv[MAXPV + 1]; 85610327Seric 85710327Seric /* take apart the words */ 85810327Seric i = 0; 85910327Seric while (*p != '\0' && i < MAXPV) 8604096Seric { 86110327Seric q = p; 86258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 86310327Seric p++; 86458050Seric while (isascii(*p) && isspace(*p)) 86510327Seric *p++ = '\0'; 86610327Seric argv[i++] = newstr(q); 8674096Seric } 86810327Seric argv[i++] = NULL; 8694096Seric 87010327Seric /* now make a copy of the argv */ 87110327Seric avp = (char **) xalloc(sizeof *avp * i); 87216893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 87310327Seric 87410327Seric return (avp); 8753308Seric } 8763308Seric /* 8773308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8783308Seric ** 8793308Seric ** Parameters: 8803308Seric ** none. 8813308Seric ** 8823308Seric ** Returns: 8833308Seric ** none. 8843308Seric ** 8853308Seric ** Side Effects: 8863308Seric ** prints rewrite rules. 8873308Seric */ 8883308Seric 8893308Seric printrules() 8903308Seric { 8913308Seric register struct rewrite *rwp; 8924072Seric register int ruleset; 8933308Seric 8944072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8953308Seric { 8964072Seric if (RewriteRules[ruleset] == NULL) 8974072Seric continue; 8988067Seric printf("\n----Rule Set %d:", ruleset); 8993308Seric 9004072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9013308Seric { 9028067Seric printf("\nLHS:"); 9038067Seric printav(rwp->r_lhs); 9048067Seric printf("RHS:"); 9058067Seric printav(rwp->r_rhs); 9063308Seric } 9073308Seric } 9083308Seric } 9094319Seric 9104096Seric /* 9118256Seric ** SETOPTION -- set global processing option 9128256Seric ** 9138256Seric ** Parameters: 9148256Seric ** opt -- option name. 9158256Seric ** val -- option value (as a text string). 91621755Seric ** safe -- set if this came from a configuration file. 91721755Seric ** Some options (if set from the command line) will 91821755Seric ** reset the user id to avoid security problems. 9198269Seric ** sticky -- if set, don't let other setoptions override 9208269Seric ** this value. 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 95421755Seric setoption(opt, val, safe, sticky) 9558256Seric char opt; 9568256Seric char *val; 95721755Seric bool safe; 9588269Seric bool sticky; 9598256Seric { 96057207Seric register char *p; 9618265Seric extern bool atobool(); 96212633Seric extern time_t convtime(); 96314879Seric extern int QueueLA; 96414879Seric extern int RefuseLA; 96517474Seric extern bool trusteduser(); 96617474Seric extern char *username(); 9678256Seric 9688256Seric if (tTd(37, 1)) 9699341Seric printf("setoption %c=%s", opt, val); 9708256Seric 9718256Seric /* 9728269Seric ** See if this option is preset for us. 9738256Seric */ 9748256Seric 97510687Seric if (bitnset(opt, StickyOpt)) 9768269Seric { 9779341Seric if (tTd(37, 1)) 9789341Seric printf(" (ignored)\n"); 9798269Seric return; 9808269Seric } 9818269Seric 98221755Seric /* 98321755Seric ** Check to see if this option can be specified by this user. 98421755Seric */ 98521755Seric 98636238Skarels if (!safe && getuid() == 0) 98721755Seric safe = TRUE; 98858082Seric if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL) 98921755Seric { 99039111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 99121755Seric { 99236582Sbostic if (tTd(37, 1)) 99336582Sbostic printf(" (unsafe)"); 99436582Sbostic if (getuid() != geteuid()) 99536582Sbostic { 99651210Seric if (tTd(37, 1)) 99751210Seric printf("(Resetting uid)"); 99836582Sbostic (void) setgid(getgid()); 99936582Sbostic (void) setuid(getuid()); 100036582Sbostic } 100121755Seric } 100221755Seric } 100351210Seric if (tTd(37, 1)) 100417985Seric printf("\n"); 10058269Seric 10068256Seric switch (opt) 10078256Seric { 100852106Seric case '8': /* allow eight-bit input */ 100952106Seric EightBit = atobool(val); 101052106Seric break; 101152106Seric 10128256Seric case 'A': /* set default alias file */ 10139381Seric if (val[0] == '\0') 10148269Seric AliasFile = "aliases"; 10159381Seric else 10169381Seric AliasFile = newstr(val); 10178256Seric break; 10188256Seric 101917474Seric case 'a': /* look N minutes for "@:@" in alias file */ 102017474Seric if (val[0] == '\0') 102117474Seric SafeAlias = 5; 102217474Seric else 102317474Seric SafeAlias = atoi(val); 102417474Seric break; 102517474Seric 102616843Seric case 'B': /* substitution for blank character */ 102716843Seric SpaceSub = val[0]; 102816843Seric if (SpaceSub == '\0') 102916843Seric SpaceSub = ' '; 103016843Seric break; 103116843Seric 103258082Seric case 'b': /* minimum number of blocks free on queue fs */ 103358082Seric MinBlocksFree = atol(val); 103458082Seric break; 103558082Seric 10369284Seric case 'c': /* don't connect to "expensive" mailers */ 10379381Seric NoConnect = atobool(val); 10389284Seric break; 10399284Seric 104051305Seric case 'C': /* checkpoint every N addresses */ 104151305Seric CheckpointInterval = atoi(val); 104224944Seric break; 104324944Seric 10449284Seric case 'd': /* delivery mode */ 10459284Seric switch (*val) 10468269Seric { 10479284Seric case '\0': 10489284Seric SendMode = SM_DELIVER; 10498269Seric break; 10508269Seric 105110755Seric case SM_QUEUE: /* queue only */ 105210755Seric #ifndef QUEUE 105310755Seric syserr("need QUEUE to set -odqueue"); 105456795Seric #endif /* QUEUE */ 105510755Seric /* fall through..... */ 105610755Seric 10579284Seric case SM_DELIVER: /* do everything */ 10589284Seric case SM_FORK: /* fork after verification */ 10599284Seric SendMode = *val; 10608269Seric break; 10618269Seric 10628269Seric default: 10639284Seric syserr("Unknown delivery mode %c", *val); 10648269Seric exit(EX_USAGE); 10658269Seric } 10668269Seric break; 10678269Seric 10689146Seric case 'D': /* rebuild alias database as needed */ 10699381Seric AutoRebuild = atobool(val); 10709146Seric break; 10719146Seric 107255372Seric case 'E': /* error message header/header file */ 107355379Seric if (*val != '\0') 107455379Seric ErrMsgFile = newstr(val); 107555372Seric break; 107655372Seric 10778269Seric case 'e': /* set error processing mode */ 10788269Seric switch (*val) 10798269Seric { 10809381Seric case EM_QUIET: /* be silent about it */ 10819381Seric case EM_MAIL: /* mail back */ 10829381Seric case EM_BERKNET: /* do berknet error processing */ 10839381Seric case EM_WRITE: /* write back (or mail) */ 10848269Seric HoldErrs = TRUE; 10859381Seric /* fall through... */ 10868269Seric 10879381Seric case EM_PRINT: /* print errors normally (default) */ 10889381Seric ErrorMode = *val; 10898269Seric break; 10908269Seric } 10918269Seric break; 10928269Seric 10939049Seric case 'F': /* file mode */ 109417975Seric FileMode = atooct(val) & 0777; 10959049Seric break; 10969049Seric 10978269Seric case 'f': /* save Unix-style From lines on front */ 10989381Seric SaveFrom = atobool(val); 10998269Seric break; 11008269Seric 110153735Seric case 'G': /* match recipients against GECOS field */ 110253735Seric MatchGecos = atobool(val); 110353735Seric break; 110453735Seric 11058256Seric case 'g': /* default gid */ 110617474Seric DefGid = atoi(val); 11078256Seric break; 11088256Seric 11098256Seric case 'H': /* help file */ 11109381Seric if (val[0] == '\0') 11118269Seric HelpFile = "sendmail.hf"; 11129381Seric else 11139381Seric HelpFile = newstr(val); 11148256Seric break; 11158256Seric 111651305Seric case 'h': /* maximum hop count */ 111751305Seric MaxHopCount = atoi(val); 111851305Seric break; 111951305Seric 112035651Seric case 'I': /* use internet domain name server */ 112157207Seric #ifdef NAMED_BIND 112257207Seric UseNameServer = TRUE; 112357207Seric for (p = val; *p != 0; ) 112457207Seric { 112557207Seric bool clearmode; 112657207Seric char *q; 112757207Seric struct resolverflags *rfp; 112857207Seric 112957207Seric while (*p == ' ') 113057207Seric p++; 113157207Seric if (*p == '\0') 113257207Seric break; 113357207Seric clearmode = FALSE; 113457207Seric if (*p == '-') 113557207Seric clearmode = TRUE; 113657207Seric else if (*p != '+') 113757207Seric p--; 113857207Seric p++; 113957207Seric q = p; 114058050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114157207Seric p++; 114257207Seric if (*p != '\0') 114357207Seric *p++ = '\0'; 114457207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114557207Seric { 114657207Seric if (strcasecmp(q, rfp->rf_name) == 0) 114757207Seric break; 114857207Seric } 114957207Seric if (clearmode) 115057207Seric _res.options &= ~rfp->rf_bits; 115157207Seric else 115257207Seric _res.options |= rfp->rf_bits; 115357207Seric } 115457207Seric if (tTd(8, 2)) 115557207Seric printf("_res.options = %x\n", _res.options); 115657207Seric #else 115757207Seric usrerr("name server (I option) specified but BIND not compiled in"); 115857207Seric #endif 115935651Seric break; 116035651Seric 11618269Seric case 'i': /* ignore dot lines in message */ 11629381Seric IgnrDot = atobool(val); 11638269Seric break; 11648269Seric 116557136Seric case 'J': /* .forward search path */ 116657136Seric ForwardPath = newstr(val); 116757136Seric break; 116857136Seric 116954967Seric case 'k': /* connection cache size */ 117054967Seric MaxMciCache = atoi(val); 117156215Seric if (MaxMciCache < 0) 117256215Seric MaxMciCache = 0; 117354967Seric break; 117454967Seric 117554967Seric case 'K': /* connection cache timeout */ 117654967Seric MciCacheTimeout = convtime(val); 117754967Seric break; 117854967Seric 11798256Seric case 'L': /* log level */ 11809381Seric LogLevel = atoi(val); 11818256Seric break; 11828256Seric 11838269Seric case 'M': /* define macro */ 11849381Seric define(val[0], newstr(&val[1]), CurEnv); 118516878Seric sticky = FALSE; 11868269Seric break; 11878269Seric 11888269Seric case 'm': /* send to me too */ 11899381Seric MeToo = atobool(val); 11908269Seric break; 11918269Seric 119225820Seric case 'n': /* validate RHS in newaliases */ 119325820Seric CheckAliases = atobool(val); 119425820Seric break; 119525820Seric 11968269Seric case 'o': /* assume old style headers */ 11979381Seric if (atobool(val)) 11989341Seric CurEnv->e_flags |= EF_OLDSTYLE; 11999341Seric else 12009341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12018269Seric break; 12028269Seric 120358082Seric case 'p': /* select privacy level */ 120458082Seric p = val; 120558082Seric for (;;) 120658082Seric { 120758082Seric register struct prival *pv; 120858082Seric extern struct prival PrivacyValues[]; 120958082Seric 121058082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 121158082Seric p++; 121258082Seric if (*p == '\0') 121358082Seric break; 121458082Seric val = p; 121558082Seric while (isascii(*p) && isalnum(*p)) 121658082Seric p++; 121758082Seric if (*p != '\0') 121858082Seric *p++ = '\0'; 121958082Seric 122058082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 122158082Seric { 122258082Seric if (strcasecmp(val, pv->pv_name) == 0) 122358082Seric break; 122458082Seric } 122558082Seric PrivacyFlags |= pv->pv_flag; 122658082Seric } 122758082Seric break; 122858082Seric 122924944Seric case 'P': /* postmaster copy address for returned mail */ 123024944Seric PostMasterCopy = newstr(val); 123124944Seric break; 123224944Seric 123324944Seric case 'q': /* slope of queue only function */ 123424944Seric QueueFactor = atoi(val); 123524944Seric break; 123624944Seric 12378256Seric case 'Q': /* queue directory */ 12389381Seric if (val[0] == '\0') 12398269Seric QueueDir = "mqueue"; 12409381Seric else 12419381Seric QueueDir = newstr(val); 12428256Seric break; 12438256Seric 124458148Seric case 'R': /* don't prune routes */ 124558148Seric DontPruneRoutes = atobool(val); 124658148Seric break; 124758148Seric 12488256Seric case 'r': /* read timeout */ 124958112Seric settimeouts(val); 12508256Seric break; 12518256Seric 12528256Seric case 'S': /* status file */ 12539381Seric if (val[0] == '\0') 12548269Seric StatFile = "sendmail.st"; 12559381Seric else 12569381Seric StatFile = newstr(val); 12578256Seric break; 12588256Seric 12598265Seric case 's': /* be super safe, even if expensive */ 12609381Seric SuperSafe = atobool(val); 12618256Seric break; 12628256Seric 12638256Seric case 'T': /* queue timeout */ 12649381Seric TimeOut = convtime(val); 126554967Seric break; 12668256Seric 12678265Seric case 't': /* time zone name */ 126852106Seric TimeZoneSpec = newstr(val); 12698265Seric break; 12708265Seric 127150556Seric case 'U': /* location of user database */ 127251360Seric UdbSpec = newstr(val); 127350556Seric break; 127450556Seric 12758256Seric case 'u': /* set default uid */ 127617474Seric DefUid = atoi(val); 127740973Sbostic setdefuser(); 12788256Seric break; 12798256Seric 12808269Seric case 'v': /* run in verbose mode */ 12819381Seric Verbose = atobool(val); 12828256Seric break; 12838256Seric 128414879Seric case 'x': /* load avg at which to auto-queue msgs */ 128514879Seric QueueLA = atoi(val); 128614879Seric break; 128714879Seric 128814879Seric case 'X': /* load avg at which to auto-reject connections */ 128914879Seric RefuseLA = atoi(val); 129014879Seric break; 129114879Seric 129224981Seric case 'y': /* work recipient factor */ 129324981Seric WkRecipFact = atoi(val); 129424981Seric break; 129524981Seric 129624981Seric case 'Y': /* fork jobs during queue runs */ 129724952Seric ForkQueueRuns = atobool(val); 129824952Seric break; 129924952Seric 130024981Seric case 'z': /* work message class factor */ 130124981Seric WkClassFact = atoi(val); 130224981Seric break; 130324981Seric 130424981Seric case 'Z': /* work time factor */ 130524981Seric WkTimeFact = atoi(val); 130624981Seric break; 130724981Seric 13088256Seric default: 13098256Seric break; 13108256Seric } 131116878Seric if (sticky) 131216878Seric setbitn(opt, StickyOpt); 13139188Seric return; 13148256Seric } 131510687Seric /* 131610687Seric ** SETCLASS -- set a word into a class 131710687Seric ** 131810687Seric ** Parameters: 131910687Seric ** class -- the class to put the word in. 132010687Seric ** word -- the word to enter 132110687Seric ** 132210687Seric ** Returns: 132310687Seric ** none. 132410687Seric ** 132510687Seric ** Side Effects: 132610687Seric ** puts the word into the symbol table. 132710687Seric */ 132810687Seric 132910687Seric setclass(class, word) 133010687Seric int class; 133110687Seric char *word; 133210687Seric { 133310687Seric register STAB *s; 133410687Seric 133557943Seric if (tTd(37, 8)) 133657943Seric printf("%s added to class %c\n", word, class); 133710687Seric s = stab(word, ST_CLASS, ST_ENTER); 133810687Seric setbitn(class, s->s_class); 133910687Seric } 134053654Seric /* 134153654Seric ** MAKEMAPENTRY -- create a map entry 134253654Seric ** 134353654Seric ** Parameters: 134453654Seric ** line -- the config file line 134553654Seric ** 134653654Seric ** Returns: 134753654Seric ** TRUE if it successfully entered the map entry. 134853654Seric ** FALSE otherwise (usually syntax error). 134953654Seric ** 135053654Seric ** Side Effects: 135153654Seric ** Enters the map into the dictionary. 135253654Seric */ 135353654Seric 135453654Seric void 135553654Seric makemapentry(line) 135653654Seric char *line; 135753654Seric { 135853654Seric register char *p; 135953654Seric char *mapname; 136053654Seric char *classname; 136153654Seric register STAB *map; 136253654Seric STAB *class; 136353654Seric 136458050Seric for (p = line; isascii(*p) && isspace(*p); p++) 136553654Seric continue; 136658050Seric if (!(isascii(*p) && isalnum(*p))) 136753654Seric { 136853654Seric syserr("readcf: config K line: no map name"); 136953654Seric return; 137053654Seric } 137153654Seric 137253654Seric mapname = p; 137358050Seric while (isascii(*++p) && isalnum(*p)) 137453654Seric continue; 137553654Seric if (*p != '\0') 137653654Seric *p++ = '\0'; 137758050Seric while (isascii(*p) && isspace(*p)) 137853654Seric p++; 137958050Seric if (!(isascii(*p) && isalnum(*p))) 138053654Seric { 138153654Seric syserr("readcf: config K line, map %s: no map class", mapname); 138253654Seric return; 138353654Seric } 138453654Seric classname = p; 138558050Seric while (isascii(*++p) && isalnum(*p)) 138653654Seric continue; 138753654Seric if (*p != '\0') 138853654Seric *p++ = '\0'; 138958050Seric while (isascii(*p) && isspace(*p)) 139053654Seric p++; 139153654Seric 139253654Seric /* look up the class */ 139353654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 139453654Seric if (class == NULL) 139553654Seric { 139653654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 139753654Seric return; 139853654Seric } 139953654Seric 140053654Seric /* enter the map */ 140153654Seric map = stab(mapname, ST_MAP, ST_ENTER); 140253654Seric map->s_map.map_class = &class->s_mapclass; 140353654Seric 140456823Seric if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 140553654Seric map->s_map.map_flags |= MF_VALID; 140653654Seric } 140758112Seric /* 140858112Seric ** SETTIMEOUTS -- parse and set timeout values 140958112Seric ** 141058112Seric ** Parameters: 141158112Seric ** val -- a pointer to the values. If NULL, do initial 141258112Seric ** settings. 141358112Seric ** 141458112Seric ** Returns: 141558112Seric ** none. 141658112Seric ** 141758112Seric ** Side Effects: 141858112Seric ** Initializes the TimeOuts structure 141958112Seric */ 142058112Seric 142158112Seric #define MINUTES * 60 142258112Seric #define HOUR * 3600 142358112Seric 142458112Seric settimeouts(val) 142558112Seric register char *val; 142658112Seric { 142758112Seric register char *p; 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