122709Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 362530Sbostic * Copyright (c) 1988, 1993 462530Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822709Sdist 922709Sdist #ifndef lint 10*64121Seric static char sccsid[] = "@(#)readcf.c 8.6 (Berkeley) 08/06/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1457207Seric #ifdef NAMED_BIND 1557207Seric # include <arpa/nameser.h> 1657207Seric # include <resolv.h> 1757207Seric #endif 183308Seric 193308Seric /* 203308Seric ** READCF -- read control file. 213308Seric ** 223308Seric ** This routine reads the control file and builds the internal 233308Seric ** form. 243308Seric ** 254432Seric ** The file is formatted as a sequence of lines, each taken 264432Seric ** atomically. The first character of each line describes how 274432Seric ** the line is to be interpreted. The lines are: 284432Seric ** Dxval Define macro x to have value val. 294432Seric ** Cxword Put word into class x. 304432Seric ** Fxfile [fmt] Read file for lines to put into 314432Seric ** class x. Use scanf string 'fmt' 324432Seric ** or "%s" if not present. Fmt should 334432Seric ** only produce one string-valued result. 344432Seric ** Hname: value Define header with field-name 'name' 354432Seric ** and value as specified; this will be 364432Seric ** macro expanded immediately before 374432Seric ** use. 384432Seric ** Sn Use rewriting set n. 394432Seric ** Rlhs rhs Rewrite addresses that match lhs to 404432Seric ** be rhs. 4124944Seric ** Mn arg=val... Define mailer. n is the internal name. 4224944Seric ** Args specify mailer parameters. 438252Seric ** Oxvalue Set option x to value. 448252Seric ** Pname=value Set precedence name to value. 4552645Seric ** Vversioncode Version level of configuration syntax. 4653654Seric ** Kmapname mapclass arguments.... 4753654Seric ** Define keyed lookup of a given class. 4853654Seric ** Arguments are class dependent. 494432Seric ** 503308Seric ** Parameters: 513308Seric ** cfname -- control file name. 5254973Seric ** safe -- TRUE if this is the system config file; 5354973Seric ** FALSE otherwise. 5455012Seric ** e -- the main envelope. 553308Seric ** 563308Seric ** Returns: 573308Seric ** none. 583308Seric ** 593308Seric ** Side Effects: 603308Seric ** Builds several internal tables. 613308Seric */ 623308Seric 6355012Seric readcf(cfname, safe, e) 643308Seric char *cfname; 6554973Seric bool safe; 6655012Seric register ENVELOPE *e; 673308Seric { 683308Seric FILE *cf; 698547Seric int ruleset = 0; 708547Seric char *q; 719350Seric struct rewrite *rwp = NULL; 7257135Seric char *bp; 7357589Seric int nfuzzy; 743308Seric char buf[MAXLINE]; 753308Seric register char *p; 763308Seric extern char **copyplist(); 7752647Seric struct stat statb; 785909Seric char exbuf[MAXLINE]; 7916915Seric char pvpbuf[PSBUFSIZE]; 8010709Seric extern char *munchstring(); 8153654Seric extern void makemapentry(); 823308Seric 8352647Seric FileName = cfname; 8452647Seric LineNumber = 0; 8552647Seric 863308Seric cf = fopen(cfname, "r"); 873308Seric if (cf == NULL) 883308Seric { 8952647Seric syserr("cannot open"); 903308Seric exit(EX_OSFILE); 913308Seric } 923308Seric 9352647Seric if (fstat(fileno(cf), &statb) < 0) 9452647Seric { 9552647Seric syserr("cannot fstat"); 9652647Seric exit(EX_OSFILE); 9752647Seric } 9852647Seric 9952647Seric if (!S_ISREG(statb.st_mode)) 10052647Seric { 10152647Seric syserr("not a plain file"); 10252647Seric exit(EX_OSFILE); 10352647Seric } 10452647Seric 10552647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 10652647Seric { 10753037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 10853037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 10953037Seric FileName); 11053037Seric #ifdef LOG 11153037Seric if (LogLevel > 0) 11253037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 11353037Seric FileName); 11453037Seric #endif 11552647Seric } 11652647Seric 11759254Seric #ifdef XLA 11859254Seric xla_zero(); 11959254Seric #endif 12059254Seric 12157135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1223308Seric { 12357135Seric if (bp[0] == '#') 12457135Seric { 12557135Seric if (bp != buf) 12657135Seric free(bp); 12752637Seric continue; 12857135Seric } 12952637Seric 13058050Seric /* map $ into \201 for macro expansion */ 13157135Seric for (p = bp; *p != '\0'; p++) 13216157Seric { 13357135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 13452647Seric { 13552647Seric /* this is an on-line comment */ 13652647Seric register char *e; 13752647Seric 13858050Seric switch (*--p & 0377) 13952647Seric { 14058050Seric case MACROEXPAND: 14152647Seric /* it's from $# -- let it go through */ 14252647Seric p++; 14352647Seric break; 14452647Seric 14552647Seric case '\\': 14652647Seric /* it's backslash escaped */ 14752647Seric (void) strcpy(p, p + 1); 14852647Seric break; 14952647Seric 15052647Seric default: 15152647Seric /* delete preceeding white space */ 15258050Seric while (isascii(*p) && isspace(*p) && p > bp) 15352647Seric p--; 15456795Seric if ((e = strchr(++p, '\n')) != NULL) 15552647Seric (void) strcpy(p, e); 15652647Seric else 15752647Seric p[0] = p[1] = '\0'; 15852647Seric break; 15952647Seric } 16052647Seric continue; 16152647Seric } 16252647Seric 16316157Seric if (*p != '$') 16416157Seric continue; 16516157Seric 16616157Seric if (p[1] == '$') 16716157Seric { 16816157Seric /* actual dollar sign.... */ 16923111Seric (void) strcpy(p, p + 1); 17016157Seric continue; 17116157Seric } 17216157Seric 17316157Seric /* convert to macro expansion character */ 17458050Seric *p = MACROEXPAND; 17516157Seric } 17616157Seric 17716157Seric /* interpret this line */ 17857135Seric switch (bp[0]) 1793308Seric { 1803308Seric case '\0': 1813308Seric case '#': /* comment */ 1823308Seric break; 1833308Seric 1843308Seric case 'R': /* rewriting rule */ 18557135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1863308Seric continue; 1873308Seric 1883308Seric if (*p == '\0') 1895909Seric { 19057135Seric syserr("invalid rewrite line \"%s\"", bp); 1915909Seric break; 1925909Seric } 1935909Seric 1945909Seric /* allocate space for the rule header */ 1955909Seric if (rwp == NULL) 1965909Seric { 1975909Seric RewriteRules[ruleset] = rwp = 1985909Seric (struct rewrite *) xalloc(sizeof *rwp); 1995909Seric } 2003308Seric else 2013308Seric { 2025909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2035909Seric rwp = rwp->r_next; 2045909Seric } 2055909Seric rwp->r_next = NULL; 2063308Seric 2075909Seric /* expand and save the LHS */ 2085909Seric *p = '\0'; 20957135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 21058333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 21157589Seric nfuzzy = 0; 2125909Seric if (rwp->r_lhs != NULL) 21357589Seric { 21457589Seric register char **ap; 21557589Seric 2165909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 21757589Seric 21857589Seric /* count the number of fuzzy matches in LHS */ 21957589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 22057589Seric { 22158148Seric char *botch; 22258148Seric 22358148Seric botch = NULL; 22458050Seric switch (**ap & 0377) 22557589Seric { 22657589Seric case MATCHZANY: 22757589Seric case MATCHANY: 22857589Seric case MATCHONE: 22957589Seric case MATCHCLASS: 23057589Seric case MATCHNCLASS: 23157589Seric nfuzzy++; 23258148Seric break; 23358148Seric 23458148Seric case MATCHREPL: 23558148Seric botch = "$0-$9"; 23658148Seric break; 23758148Seric 23858148Seric case CANONNET: 23958148Seric botch = "$#"; 24058148Seric break; 24158148Seric 24258148Seric case CANONUSER: 24358148Seric botch = "$:"; 24458148Seric break; 24558148Seric 24658148Seric case CALLSUBR: 24758148Seric botch = "$>"; 24858148Seric break; 24958148Seric 25058148Seric case CONDIF: 25158148Seric botch = "$?"; 25258148Seric break; 25358148Seric 25458148Seric case CONDELSE: 25558148Seric botch = "$|"; 25658148Seric break; 25758148Seric 25858148Seric case CONDFI: 25958148Seric botch = "$."; 26058148Seric break; 26158148Seric 26258148Seric case HOSTBEGIN: 26358148Seric botch = "$["; 26458148Seric break; 26558148Seric 26658148Seric case HOSTEND: 26758148Seric botch = "$]"; 26858148Seric break; 26958148Seric 27058148Seric case LOOKUPBEGIN: 27158148Seric botch = "$("; 27258148Seric break; 27358148Seric 27458148Seric case LOOKUPEND: 27558148Seric botch = "$)"; 27658148Seric break; 27757589Seric } 27858148Seric if (botch != NULL) 27958148Seric syserr("Inappropriate use of %s on LHS", 28058148Seric botch); 28157589Seric } 28257589Seric } 28356678Seric else 28456678Seric syserr("R line: null LHS"); 2855909Seric 2865909Seric /* expand and save the RHS */ 2875909Seric while (*++p == '\t') 2885909Seric continue; 2897231Seric q = p; 2907231Seric while (*p != '\0' && *p != '\t') 2917231Seric p++; 2927231Seric *p = '\0'; 29355012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 29458333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 2955909Seric if (rwp->r_rhs != NULL) 29657589Seric { 29757589Seric register char **ap; 29857589Seric 2995909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 30057589Seric 30157589Seric /* check no out-of-bounds replacements */ 30257589Seric nfuzzy += '0'; 30357589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 30457589Seric { 30558148Seric char *botch; 30658148Seric 30758148Seric botch = NULL; 30858148Seric switch (**ap & 0377) 30957589Seric { 31058148Seric case MATCHREPL: 31158148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 31258148Seric { 31358148Seric syserr("replacement $%c out of bounds", 31458148Seric (*ap)[1]); 31558148Seric } 31658148Seric break; 31758148Seric 31858148Seric case MATCHZANY: 31958148Seric botch = "$*"; 32058148Seric break; 32158148Seric 32258148Seric case MATCHANY: 32358148Seric botch = "$+"; 32458148Seric break; 32558148Seric 32658148Seric case MATCHONE: 32758148Seric botch = "$-"; 32858148Seric break; 32958148Seric 33058148Seric case MATCHCLASS: 33158148Seric botch = "$="; 33258148Seric break; 33358148Seric 33458148Seric case MATCHNCLASS: 33558148Seric botch = "$~"; 33658148Seric break; 33757589Seric } 33858148Seric if (botch != NULL) 33958148Seric syserr("Inappropriate use of %s on RHS", 34058148Seric botch); 34157589Seric } 34257589Seric } 34356678Seric else 34456678Seric syserr("R line: null RHS"); 3453308Seric break; 3463308Seric 3474072Seric case 'S': /* select rewriting set */ 34857135Seric ruleset = atoi(&bp[1]); 3498056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3508056Seric { 3519381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3528056Seric ruleset = 0; 3538056Seric } 3544072Seric rwp = NULL; 3554072Seric break; 3564072Seric 3573308Seric case 'D': /* macro definition */ 35864086Seric p = munchstring(&bp[2], NULL); 35964086Seric define(bp[1], newstr(p), e); 3603308Seric break; 3613308Seric 3623387Seric case 'H': /* required header line */ 36357135Seric (void) chompheader(&bp[1], TRUE, e); 3643387Seric break; 3653387Seric 3664061Seric case 'C': /* word class */ 3674432Seric /* scan the list of words and set class for all */ 368*64121Seric expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e); 369*64121Seric for (p = exbuf; *p != '\0'; ) 3704061Seric { 3714061Seric register char *wd; 3724061Seric char delim; 3734061Seric 37458050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 3754061Seric p++; 3764061Seric wd = p; 37758050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 3784061Seric p++; 3794061Seric delim = *p; 3804061Seric *p = '\0'; 3814061Seric if (wd[0] != '\0') 38258148Seric { 38358148Seric if (tTd(37, 2)) 38458148Seric printf("setclass(%c, %s)\n", 38558148Seric bp[1], wd); 38657135Seric setclass(bp[1], wd); 38758148Seric } 3884061Seric *p = delim; 3894061Seric } 3904061Seric break; 3914061Seric 39259272Seric case 'F': /* word class from file */ 39359272Seric /* read list of words from argument or file */ 39459272Seric /* read from file */ 39559272Seric for (p = &bp[2]; 39659272Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 39759272Seric p++) 39859272Seric continue; 39959272Seric if (*p == '\0') 40059272Seric p = "%s"; 40159272Seric else 40259272Seric { 40359272Seric *p = '\0'; 40459272Seric while (isascii(*++p) && isspace(*p)) 40559272Seric continue; 40659272Seric } 40759272Seric fileclass(bp[1], &bp[2], p, safe); 40859272Seric break; 40959272Seric 41059156Seric #ifdef XLA 41159156Seric case 'L': /* extended load average description */ 41259156Seric xla_init(&bp[1]); 41359156Seric break; 41459156Seric #endif 41559156Seric 4164096Seric case 'M': /* define mailer */ 41757135Seric makemailer(&bp[1]); 4184096Seric break; 4194096Seric 4208252Seric case 'O': /* set option */ 42158734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4228252Seric break; 4238252Seric 4248252Seric case 'P': /* set precedence */ 4258252Seric if (NumPriorities >= MAXPRIORITIES) 4268252Seric { 4278547Seric toomany('P', MAXPRIORITIES); 4288252Seric break; 4298252Seric } 43057135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4318252Seric continue; 4328252Seric if (*p == '\0') 4338252Seric goto badline; 4348252Seric *p = '\0'; 43557135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4368252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4378252Seric NumPriorities++; 4388252Seric break; 4398252Seric 4408547Seric case 'T': /* trusted user(s) */ 44158161Seric /* this option is obsolete, but will be ignored */ 4428547Seric break; 4438547Seric 44452645Seric case 'V': /* configuration syntax version */ 44557135Seric ConfigLevel = atoi(&bp[1]); 44652645Seric break; 44752645Seric 44853654Seric case 'K': 44957135Seric makemapentry(&bp[1]); 45053654Seric break; 45153654Seric 4523308Seric default: 4534061Seric badline: 45457135Seric syserr("unknown control line \"%s\"", bp); 4553308Seric } 45657135Seric if (bp != buf) 45757135Seric free(bp); 4583308Seric } 45952637Seric if (ferror(cf)) 46052637Seric { 46152647Seric syserr("I/O read error", cfname); 46252637Seric exit(EX_OSFILE); 46352637Seric } 46452637Seric fclose(cf); 4659381Seric FileName = NULL; 46656836Seric 46757076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 46857076Seric { 46957076Seric /* user didn't initialize: set up host map */ 47057076Seric strcpy(buf, "host host"); 47157076Seric if (ConfigLevel >= 2) 47257076Seric strcat(buf, " -a."); 47357076Seric makemapentry(buf); 47457076Seric } 4754096Seric } 4764096Seric /* 4778547Seric ** TOOMANY -- signal too many of some option 4788547Seric ** 4798547Seric ** Parameters: 4808547Seric ** id -- the id of the error line 4818547Seric ** maxcnt -- the maximum possible values 4828547Seric ** 4838547Seric ** Returns: 4848547Seric ** none. 4858547Seric ** 4868547Seric ** Side Effects: 4878547Seric ** gives a syserr. 4888547Seric */ 4898547Seric 4908547Seric toomany(id, maxcnt) 4918547Seric char id; 4928547Seric int maxcnt; 4938547Seric { 4949381Seric syserr("too many %c lines, %d max", id, maxcnt); 4958547Seric } 4968547Seric /* 4974432Seric ** FILECLASS -- read members of a class from a file 4984432Seric ** 4994432Seric ** Parameters: 5004432Seric ** class -- class to define. 5014432Seric ** filename -- name of file to read. 5024432Seric ** fmt -- scanf string to use for match. 5034432Seric ** 5044432Seric ** Returns: 5054432Seric ** none 5064432Seric ** 5074432Seric ** Side Effects: 5084432Seric ** 5094432Seric ** puts all lines in filename that match a scanf into 5104432Seric ** the named class. 5114432Seric */ 5124432Seric 51354973Seric fileclass(class, filename, fmt, safe) 5144432Seric int class; 5154432Seric char *filename; 5164432Seric char *fmt; 51754973Seric bool safe; 5184432Seric { 51925808Seric FILE *f; 52054973Seric struct stat stbuf; 5214432Seric char buf[MAXLINE]; 5224432Seric 52354973Seric if (stat(filename, &stbuf) < 0) 52454973Seric { 52554973Seric syserr("fileclass: cannot stat %s", filename); 52654973Seric return; 52754973Seric } 52854973Seric if (!S_ISREG(stbuf.st_mode)) 52954973Seric { 53054973Seric syserr("fileclass: %s not a regular file", filename); 53154973Seric return; 53254973Seric } 53354973Seric if (!safe && access(filename, R_OK) < 0) 53454973Seric { 53554973Seric syserr("fileclass: access denied on %s", filename); 53654973Seric return; 53754973Seric } 53854973Seric f = fopen(filename, "r"); 5394432Seric if (f == NULL) 5404432Seric { 54154973Seric syserr("fileclass: cannot open %s", filename); 5424432Seric return; 5434432Seric } 5444432Seric 5454432Seric while (fgets(buf, sizeof buf, f) != NULL) 5464432Seric { 5474432Seric register STAB *s; 54825808Seric register char *p; 54925808Seric # ifdef SCANF 5504432Seric char wordbuf[MAXNAME+1]; 5514432Seric 5524432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5534432Seric continue; 55425808Seric p = wordbuf; 55556795Seric # else /* SCANF */ 55625808Seric p = buf; 55756795Seric # endif /* SCANF */ 55825808Seric 55925808Seric /* 56025808Seric ** Break up the match into words. 56125808Seric */ 56225808Seric 56325808Seric while (*p != '\0') 56425808Seric { 56525808Seric register char *q; 56625808Seric 56725808Seric /* strip leading spaces */ 56858050Seric while (isascii(*p) && isspace(*p)) 56925808Seric p++; 57025808Seric if (*p == '\0') 57125808Seric break; 57225808Seric 57325808Seric /* find the end of the word */ 57425808Seric q = p; 57558050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 57625808Seric p++; 57725808Seric if (*p != '\0') 57825808Seric *p++ = '\0'; 57925808Seric 58025808Seric /* enter the word in the symbol table */ 58125808Seric s = stab(q, ST_CLASS, ST_ENTER); 58225808Seric setbitn(class, s->s_class); 58325808Seric } 5844432Seric } 5854432Seric 58654973Seric (void) fclose(f); 5874432Seric } 5884432Seric /* 5894096Seric ** MAKEMAILER -- define a new mailer. 5904096Seric ** 5914096Seric ** Parameters: 59210327Seric ** line -- description of mailer. This is in labeled 59310327Seric ** fields. The fields are: 59410327Seric ** P -- the path to the mailer 59510327Seric ** F -- the flags associated with the mailer 59610327Seric ** A -- the argv for this mailer 59710327Seric ** S -- the sender rewriting set 59810327Seric ** R -- the recipient rewriting set 59910327Seric ** E -- the eol string 60010327Seric ** The first word is the canonical name of the mailer. 6014096Seric ** 6024096Seric ** Returns: 6034096Seric ** none. 6044096Seric ** 6054096Seric ** Side Effects: 6064096Seric ** enters the mailer into the mailer table. 6074096Seric */ 6083308Seric 60921066Seric makemailer(line) 6104096Seric char *line; 6114096Seric { 6124096Seric register char *p; 6138067Seric register struct mailer *m; 6148067Seric register STAB *s; 6158067Seric int i; 61610327Seric char fcode; 61758020Seric auto char *endp; 6184096Seric extern int NextMailer; 61910327Seric extern char **makeargv(); 62010327Seric extern char *munchstring(); 62110701Seric extern long atol(); 6224096Seric 62310327Seric /* allocate a mailer and set up defaults */ 62410327Seric m = (struct mailer *) xalloc(sizeof *m); 62510327Seric bzero((char *) m, sizeof *m); 62610327Seric m->m_eol = "\n"; 62710327Seric 62810327Seric /* collect the mailer name */ 62958050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 63010327Seric continue; 63110327Seric if (*p != '\0') 63210327Seric *p++ = '\0'; 63310327Seric m->m_name = newstr(line); 63410327Seric 63510327Seric /* now scan through and assign info from the fields */ 63610327Seric while (*p != '\0') 63710327Seric { 63858333Seric auto char *delimptr; 63958333Seric 64058050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 64110327Seric p++; 64210327Seric 64310327Seric /* p now points to field code */ 64410327Seric fcode = *p; 64510327Seric while (*p != '\0' && *p != '=' && *p != ',') 64610327Seric p++; 64710327Seric if (*p++ != '=') 64810327Seric { 64952637Seric syserr("mailer %s: `=' expected", m->m_name); 65010327Seric return; 65110327Seric } 65258050Seric while (isascii(*p) && isspace(*p)) 65310327Seric p++; 65410327Seric 65510327Seric /* p now points to the field body */ 65658333Seric p = munchstring(p, &delimptr); 65710327Seric 65810327Seric /* install the field into the mailer struct */ 65910327Seric switch (fcode) 66010327Seric { 66110327Seric case 'P': /* pathname */ 66210327Seric m->m_mailer = newstr(p); 66310327Seric break; 66410327Seric 66510327Seric case 'F': /* flags */ 66610687Seric for (; *p != '\0'; p++) 66758050Seric if (!(isascii(*p) && isspace(*p))) 66852637Seric setbitn(*p, m->m_flags); 66910327Seric break; 67010327Seric 67110327Seric case 'S': /* sender rewriting ruleset */ 67210327Seric case 'R': /* recipient rewriting ruleset */ 67358020Seric i = strtol(p, &endp, 10); 67410327Seric if (i < 0 || i >= MAXRWSETS) 67510327Seric { 67610327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 67710327Seric return; 67810327Seric } 67910327Seric if (fcode == 'S') 68058020Seric m->m_sh_rwset = m->m_se_rwset = i; 68110327Seric else 68258020Seric m->m_rh_rwset = m->m_re_rwset = i; 68358020Seric 68458020Seric p = endp; 68559985Seric if (*p++ == '/') 68658020Seric { 68758020Seric i = strtol(p, NULL, 10); 68858020Seric if (i < 0 || i >= MAXRWSETS) 68958020Seric { 69058020Seric syserr("invalid rewrite set, %d max", 69158020Seric MAXRWSETS); 69258020Seric return; 69358020Seric } 69458020Seric if (fcode == 'S') 69558020Seric m->m_sh_rwset = i; 69658020Seric else 69758020Seric m->m_rh_rwset = i; 69858020Seric } 69910327Seric break; 70010327Seric 70110327Seric case 'E': /* end of line string */ 70210327Seric m->m_eol = newstr(p); 70310327Seric break; 70410327Seric 70510327Seric case 'A': /* argument vector */ 70610327Seric m->m_argv = makeargv(p); 70710327Seric break; 70810701Seric 70910701Seric case 'M': /* maximum message size */ 71010701Seric m->m_maxsize = atol(p); 71110701Seric break; 71252106Seric 71352106Seric case 'L': /* maximum line length */ 71452106Seric m->m_linelimit = atoi(p); 71552106Seric break; 71658935Seric 71758935Seric case 'D': /* working directory */ 71858935Seric m->m_execdir = newstr(p); 71958935Seric break; 72010327Seric } 72110327Seric 72258333Seric p = delimptr; 72310327Seric } 72410327Seric 72552106Seric /* do some heuristic cleanup for back compatibility */ 72652106Seric if (bitnset(M_LIMITS, m->m_flags)) 72752106Seric { 72852106Seric if (m->m_linelimit == 0) 72952106Seric m->m_linelimit = SMTPLINELIM; 73055418Seric if (ConfigLevel < 2) 73152106Seric setbitn(M_7BITS, m->m_flags); 73252106Seric } 73352106Seric 73458321Seric /* do some rationality checking */ 73558321Seric if (m->m_argv == NULL) 73658321Seric { 73758321Seric syserr("M%s: A= argument required", m->m_name); 73858321Seric return; 73958321Seric } 74058321Seric if (m->m_mailer == NULL) 74158321Seric { 74258321Seric syserr("M%s: P= argument required", m->m_name); 74358321Seric return; 74458321Seric } 74558321Seric 7464096Seric if (NextMailer >= MAXMAILERS) 7474096Seric { 7489381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7494096Seric return; 7504096Seric } 75157402Seric 75210327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 75357402Seric if (s->s_mailer != NULL) 75457402Seric { 75557402Seric i = s->s_mailer->m_mno; 75657402Seric free(s->s_mailer); 75757402Seric } 75857402Seric else 75957402Seric { 76057402Seric i = NextMailer++; 76157402Seric } 76257402Seric Mailer[i] = s->s_mailer = m; 76357454Seric m->m_mno = i; 76410327Seric } 76510327Seric /* 76610327Seric ** MUNCHSTRING -- translate a string into internal form. 76710327Seric ** 76810327Seric ** Parameters: 76910327Seric ** p -- the string to munch. 77058333Seric ** delimptr -- if non-NULL, set to the pointer of the 77158333Seric ** field delimiter character. 77210327Seric ** 77310327Seric ** Returns: 77410327Seric ** the munched string. 77510327Seric */ 7764096Seric 77710327Seric char * 77858333Seric munchstring(p, delimptr) 77910327Seric register char *p; 78058333Seric char **delimptr; 78110327Seric { 78210327Seric register char *q; 78310327Seric bool backslash = FALSE; 78410327Seric bool quotemode = FALSE; 78510327Seric static char buf[MAXLINE]; 7864096Seric 78710327Seric for (q = buf; *p != '\0'; p++) 7884096Seric { 78910327Seric if (backslash) 79010327Seric { 79110327Seric /* everything is roughly literal */ 79210357Seric backslash = FALSE; 79310327Seric switch (*p) 79410327Seric { 79510327Seric case 'r': /* carriage return */ 79610327Seric *q++ = '\r'; 79710327Seric continue; 79810327Seric 79910327Seric case 'n': /* newline */ 80010327Seric *q++ = '\n'; 80110327Seric continue; 80210327Seric 80310327Seric case 'f': /* form feed */ 80410327Seric *q++ = '\f'; 80510327Seric continue; 80610327Seric 80710327Seric case 'b': /* backspace */ 80810327Seric *q++ = '\b'; 80910327Seric continue; 81010327Seric } 81110327Seric *q++ = *p; 81210327Seric } 81310327Seric else 81410327Seric { 81510327Seric if (*p == '\\') 81610327Seric backslash = TRUE; 81710327Seric else if (*p == '"') 81810327Seric quotemode = !quotemode; 81910327Seric else if (quotemode || *p != ',') 82010327Seric *q++ = *p; 82110327Seric else 82210327Seric break; 82310327Seric } 8244096Seric } 8254096Seric 82658333Seric if (delimptr != NULL) 82758333Seric *delimptr = p; 82810327Seric *q++ = '\0'; 82910327Seric return (buf); 83010327Seric } 83110327Seric /* 83210327Seric ** MAKEARGV -- break up a string into words 83310327Seric ** 83410327Seric ** Parameters: 83510327Seric ** p -- the string to break up. 83610327Seric ** 83710327Seric ** Returns: 83810327Seric ** a char **argv (dynamically allocated) 83910327Seric ** 84010327Seric ** Side Effects: 84110327Seric ** munges p. 84210327Seric */ 8434096Seric 84410327Seric char ** 84510327Seric makeargv(p) 84610327Seric register char *p; 84710327Seric { 84810327Seric char *q; 84910327Seric int i; 85010327Seric char **avp; 85110327Seric char *argv[MAXPV + 1]; 85210327Seric 85310327Seric /* take apart the words */ 85410327Seric i = 0; 85510327Seric while (*p != '\0' && i < MAXPV) 8564096Seric { 85710327Seric q = p; 85858050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 85910327Seric p++; 86058050Seric while (isascii(*p) && isspace(*p)) 86110327Seric *p++ = '\0'; 86210327Seric argv[i++] = newstr(q); 8634096Seric } 86410327Seric argv[i++] = NULL; 8654096Seric 86610327Seric /* now make a copy of the argv */ 86710327Seric avp = (char **) xalloc(sizeof *avp * i); 86816893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 86910327Seric 87010327Seric return (avp); 8713308Seric } 8723308Seric /* 8733308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8743308Seric ** 8753308Seric ** Parameters: 8763308Seric ** none. 8773308Seric ** 8783308Seric ** Returns: 8793308Seric ** none. 8803308Seric ** 8813308Seric ** Side Effects: 8823308Seric ** prints rewrite rules. 8833308Seric */ 8843308Seric 8853308Seric printrules() 8863308Seric { 8873308Seric register struct rewrite *rwp; 8884072Seric register int ruleset; 8893308Seric 8904072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8913308Seric { 8924072Seric if (RewriteRules[ruleset] == NULL) 8934072Seric continue; 8948067Seric printf("\n----Rule Set %d:", ruleset); 8953308Seric 8964072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 8973308Seric { 8988067Seric printf("\nLHS:"); 8998067Seric printav(rwp->r_lhs); 9008067Seric printf("RHS:"); 9018067Seric printav(rwp->r_rhs); 9023308Seric } 9033308Seric } 9043308Seric } 9054319Seric 9064096Seric /* 9078256Seric ** SETOPTION -- set global processing option 9088256Seric ** 9098256Seric ** Parameters: 9108256Seric ** opt -- option name. 9118256Seric ** val -- option value (as a text string). 91221755Seric ** safe -- set if this came from a configuration file. 91321755Seric ** Some options (if set from the command line) will 91421755Seric ** reset the user id to avoid security problems. 9158269Seric ** sticky -- if set, don't let other setoptions override 9168269Seric ** this value. 91758734Seric ** e -- the main envelope. 9188256Seric ** 9198256Seric ** Returns: 9208256Seric ** none. 9218256Seric ** 9228256Seric ** Side Effects: 9238256Seric ** Sets options as implied by the arguments. 9248256Seric */ 9258256Seric 92610687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9278269Seric 92857207Seric 92957207Seric #ifdef NAMED_BIND 93057207Seric 93157207Seric struct resolverflags 93257207Seric { 93357207Seric char *rf_name; /* name of the flag */ 93457207Seric long rf_bits; /* bits to set/clear */ 93557207Seric } ResolverFlags[] = 93657207Seric { 93757207Seric "debug", RES_DEBUG, 93857207Seric "aaonly", RES_AAONLY, 93957207Seric "usevc", RES_USEVC, 94057207Seric "primary", RES_PRIMARY, 94157207Seric "igntc", RES_IGNTC, 94257207Seric "recurse", RES_RECURSE, 94357207Seric "defnames", RES_DEFNAMES, 94457207Seric "stayopen", RES_STAYOPEN, 94557207Seric "dnsrch", RES_DNSRCH, 94657207Seric NULL, 0 94757207Seric }; 94857207Seric 94957207Seric #endif 95057207Seric 95158734Seric setoption(opt, val, safe, sticky, e) 9528256Seric char opt; 9538256Seric char *val; 95421755Seric bool safe; 9558269Seric bool sticky; 95658734Seric register ENVELOPE *e; 9578256Seric { 95857207Seric register char *p; 9598265Seric extern bool atobool(); 96012633Seric extern time_t convtime(); 96114879Seric extern int QueueLA; 96214879Seric extern int RefuseLA; 96317474Seric extern bool trusteduser(); 9648256Seric 9658256Seric if (tTd(37, 1)) 9669341Seric printf("setoption %c=%s", opt, val); 9678256Seric 9688256Seric /* 9698269Seric ** See if this option is preset for us. 9708256Seric */ 9718256Seric 97259731Seric if (!sticky && bitnset(opt, StickyOpt)) 9738269Seric { 9749341Seric if (tTd(37, 1)) 9759341Seric printf(" (ignored)\n"); 9768269Seric return; 9778269Seric } 9788269Seric 97921755Seric /* 98021755Seric ** Check to see if this option can be specified by this user. 98121755Seric */ 98221755Seric 98363787Seric if (!safe && RealUid == 0) 98421755Seric safe = TRUE; 98563837Seric if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL) 98621755Seric { 98739111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 98821755Seric { 98936582Sbostic if (tTd(37, 1)) 99036582Sbostic printf(" (unsafe)"); 99163787Seric if (RealUid != geteuid()) 99236582Sbostic { 99351210Seric if (tTd(37, 1)) 99451210Seric printf("(Resetting uid)"); 99563787Seric (void) setgid(RealGid); 99663787Seric (void) setuid(RealUid); 99736582Sbostic } 99821755Seric } 99921755Seric } 100051210Seric if (tTd(37, 1)) 100117985Seric printf("\n"); 10028269Seric 10038256Seric switch (opt) 10048256Seric { 100559709Seric case '7': /* force seven-bit input */ 100659709Seric SevenBit = atobool(val); 100752106Seric break; 100852106Seric 10098256Seric case 'A': /* set default alias file */ 10109381Seric if (val[0] == '\0') 101159672Seric setalias("aliases"); 10129381Seric else 101359672Seric setalias(val); 10148256Seric break; 10158256Seric 101617474Seric case 'a': /* look N minutes for "@:@" in alias file */ 101717474Seric if (val[0] == '\0') 101817474Seric SafeAlias = 5; 101917474Seric else 102017474Seric SafeAlias = atoi(val); 102117474Seric break; 102217474Seric 102316843Seric case 'B': /* substitution for blank character */ 102416843Seric SpaceSub = val[0]; 102516843Seric if (SpaceSub == '\0') 102616843Seric SpaceSub = ' '; 102716843Seric break; 102816843Seric 102959283Seric case 'b': /* min blocks free on queue fs/max msg size */ 103059283Seric p = strchr(val, '/'); 103159283Seric if (p != NULL) 103259283Seric { 103359283Seric *p++ = '\0'; 103459283Seric MaxMessageSize = atol(p); 103559283Seric } 103658082Seric MinBlocksFree = atol(val); 103758082Seric break; 103858082Seric 10399284Seric case 'c': /* don't connect to "expensive" mailers */ 10409381Seric NoConnect = atobool(val); 10419284Seric break; 10429284Seric 104351305Seric case 'C': /* checkpoint every N addresses */ 104451305Seric CheckpointInterval = atoi(val); 104524944Seric break; 104624944Seric 10479284Seric case 'd': /* delivery mode */ 10489284Seric switch (*val) 10498269Seric { 10509284Seric case '\0': 105158734Seric e->e_sendmode = SM_DELIVER; 10528269Seric break; 10538269Seric 105410755Seric case SM_QUEUE: /* queue only */ 105510755Seric #ifndef QUEUE 105610755Seric syserr("need QUEUE to set -odqueue"); 105756795Seric #endif /* QUEUE */ 105810755Seric /* fall through..... */ 105910755Seric 10609284Seric case SM_DELIVER: /* do everything */ 10619284Seric case SM_FORK: /* fork after verification */ 106258734Seric e->e_sendmode = *val; 10638269Seric break; 10648269Seric 10658269Seric default: 10669284Seric syserr("Unknown delivery mode %c", *val); 10678269Seric exit(EX_USAGE); 10688269Seric } 10698269Seric break; 10708269Seric 10719146Seric case 'D': /* rebuild alias database as needed */ 10729381Seric AutoRebuild = atobool(val); 10739146Seric break; 10749146Seric 107555372Seric case 'E': /* error message header/header file */ 107655379Seric if (*val != '\0') 107755379Seric ErrMsgFile = newstr(val); 107855372Seric break; 107955372Seric 10808269Seric case 'e': /* set error processing mode */ 10818269Seric switch (*val) 10828269Seric { 10839381Seric case EM_QUIET: /* be silent about it */ 10849381Seric case EM_MAIL: /* mail back */ 10859381Seric case EM_BERKNET: /* do berknet error processing */ 10869381Seric case EM_WRITE: /* write back (or mail) */ 10878269Seric HoldErrs = TRUE; 10889381Seric /* fall through... */ 10898269Seric 10909381Seric case EM_PRINT: /* print errors normally (default) */ 109158734Seric e->e_errormode = *val; 10928269Seric break; 10938269Seric } 10948269Seric break; 10958269Seric 10969049Seric case 'F': /* file mode */ 109717975Seric FileMode = atooct(val) & 0777; 10989049Seric break; 10999049Seric 11008269Seric case 'f': /* save Unix-style From lines on front */ 11019381Seric SaveFrom = atobool(val); 11028269Seric break; 11038269Seric 110453735Seric case 'G': /* match recipients against GECOS field */ 110553735Seric MatchGecos = atobool(val); 110653735Seric break; 110753735Seric 11088256Seric case 'g': /* default gid */ 110917474Seric DefGid = atoi(val); 11108256Seric break; 11118256Seric 11128256Seric case 'H': /* help file */ 11139381Seric if (val[0] == '\0') 11148269Seric HelpFile = "sendmail.hf"; 11159381Seric else 11169381Seric HelpFile = newstr(val); 11178256Seric break; 11188256Seric 111951305Seric case 'h': /* maximum hop count */ 112051305Seric MaxHopCount = atoi(val); 112151305Seric break; 112251305Seric 112335651Seric case 'I': /* use internet domain name server */ 112457207Seric #ifdef NAMED_BIND 112557207Seric UseNameServer = TRUE; 112657207Seric for (p = val; *p != 0; ) 112757207Seric { 112857207Seric bool clearmode; 112957207Seric char *q; 113057207Seric struct resolverflags *rfp; 113157207Seric 113257207Seric while (*p == ' ') 113357207Seric p++; 113457207Seric if (*p == '\0') 113557207Seric break; 113657207Seric clearmode = FALSE; 113757207Seric if (*p == '-') 113857207Seric clearmode = TRUE; 113957207Seric else if (*p != '+') 114057207Seric p--; 114157207Seric p++; 114257207Seric q = p; 114358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114457207Seric p++; 114557207Seric if (*p != '\0') 114657207Seric *p++ = '\0'; 114757207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114857207Seric { 114957207Seric if (strcasecmp(q, rfp->rf_name) == 0) 115057207Seric break; 115157207Seric } 115257207Seric if (clearmode) 115357207Seric _res.options &= ~rfp->rf_bits; 115457207Seric else 115557207Seric _res.options |= rfp->rf_bits; 115657207Seric } 115757207Seric if (tTd(8, 2)) 115857207Seric printf("_res.options = %x\n", _res.options); 115957207Seric #else 116057207Seric usrerr("name server (I option) specified but BIND not compiled in"); 116157207Seric #endif 116235651Seric break; 116335651Seric 11648269Seric case 'i': /* ignore dot lines in message */ 11659381Seric IgnrDot = atobool(val); 11668269Seric break; 11678269Seric 116859730Seric case 'j': /* send errors in MIME (RFC 1341) format */ 116959730Seric SendMIMEErrors = atobool(val); 117059730Seric break; 117159730Seric 117257136Seric case 'J': /* .forward search path */ 117357136Seric ForwardPath = newstr(val); 117457136Seric break; 117557136Seric 117654967Seric case 'k': /* connection cache size */ 117754967Seric MaxMciCache = atoi(val); 117856215Seric if (MaxMciCache < 0) 117956215Seric MaxMciCache = 0; 118054967Seric break; 118154967Seric 118254967Seric case 'K': /* connection cache timeout */ 118358796Seric MciCacheTimeout = convtime(val, 'm'); 118454967Seric break; 118554967Seric 118661104Seric case 'l': /* use Errors-To: header */ 118761104Seric UseErrorsTo = atobool(val); 118861104Seric break; 118961104Seric 11908256Seric case 'L': /* log level */ 11919381Seric LogLevel = atoi(val); 11928256Seric break; 11938256Seric 11948269Seric case 'M': /* define macro */ 11959381Seric define(val[0], newstr(&val[1]), CurEnv); 119616878Seric sticky = FALSE; 11978269Seric break; 11988269Seric 11998269Seric case 'm': /* send to me too */ 12009381Seric MeToo = atobool(val); 12018269Seric break; 12028269Seric 120325820Seric case 'n': /* validate RHS in newaliases */ 120425820Seric CheckAliases = atobool(val); 120525820Seric break; 120625820Seric 120761104Seric /* 'N' available -- was "net name" */ 120861104Seric 120958851Seric case 'O': /* daemon options */ 121058851Seric setdaemonoptions(val); 121158851Seric break; 121258851Seric 12138269Seric case 'o': /* assume old style headers */ 12149381Seric if (atobool(val)) 12159341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12169341Seric else 12179341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12188269Seric break; 12198269Seric 122058082Seric case 'p': /* select privacy level */ 122158082Seric p = val; 122258082Seric for (;;) 122358082Seric { 122458082Seric register struct prival *pv; 122558082Seric extern struct prival PrivacyValues[]; 122658082Seric 122758082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 122858082Seric p++; 122958082Seric if (*p == '\0') 123058082Seric break; 123158082Seric val = p; 123258082Seric while (isascii(*p) && isalnum(*p)) 123358082Seric p++; 123458082Seric if (*p != '\0') 123558082Seric *p++ = '\0'; 123658082Seric 123758082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 123858082Seric { 123958082Seric if (strcasecmp(val, pv->pv_name) == 0) 124058082Seric break; 124158082Seric } 124258886Seric if (pv->pv_name == NULL) 124358886Seric syserr("readcf: Op line: %s unrecognized", val); 124458082Seric PrivacyFlags |= pv->pv_flag; 124558082Seric } 124658082Seric break; 124758082Seric 124824944Seric case 'P': /* postmaster copy address for returned mail */ 124924944Seric PostMasterCopy = newstr(val); 125024944Seric break; 125124944Seric 125224944Seric case 'q': /* slope of queue only function */ 125324944Seric QueueFactor = atoi(val); 125424944Seric break; 125524944Seric 12568256Seric case 'Q': /* queue directory */ 12579381Seric if (val[0] == '\0') 12588269Seric QueueDir = "mqueue"; 12599381Seric else 12609381Seric QueueDir = newstr(val); 126158789Seric if (RealUid != 0 && !safe) 126258789Seric auth_warning(e, "Processed from queue %s", QueueDir); 12638256Seric break; 12648256Seric 126558148Seric case 'R': /* don't prune routes */ 126658148Seric DontPruneRoutes = atobool(val); 126758148Seric break; 126858148Seric 12698256Seric case 'r': /* read timeout */ 127058112Seric settimeouts(val); 12718256Seric break; 12728256Seric 12738256Seric case 'S': /* status file */ 12749381Seric if (val[0] == '\0') 12758269Seric StatFile = "sendmail.st"; 12769381Seric else 12779381Seric StatFile = newstr(val); 12788256Seric break; 12798256Seric 12808265Seric case 's': /* be super safe, even if expensive */ 12819381Seric SuperSafe = atobool(val); 12828256Seric break; 12838256Seric 12848256Seric case 'T': /* queue timeout */ 128558737Seric p = strchr(val, '/'); 128658737Seric if (p != NULL) 128758737Seric { 128858737Seric *p++ = '\0'; 128958796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 129058737Seric } 129158796Seric TimeOuts.to_q_return = convtime(val, 'h'); 129254967Seric break; 12938256Seric 12948265Seric case 't': /* time zone name */ 129552106Seric TimeZoneSpec = newstr(val); 12968265Seric break; 12978265Seric 129850556Seric case 'U': /* location of user database */ 129951360Seric UdbSpec = newstr(val); 130050556Seric break; 130150556Seric 13028256Seric case 'u': /* set default uid */ 130317474Seric DefUid = atoi(val); 130440973Sbostic setdefuser(); 13058256Seric break; 13068256Seric 130758851Seric case 'V': /* fallback MX host */ 130858851Seric FallBackMX = newstr(val); 130958851Seric break; 131058851Seric 13118269Seric case 'v': /* run in verbose mode */ 13129381Seric Verbose = atobool(val); 13138256Seric break; 13148256Seric 131563837Seric case 'w': /* if we are best MX, try host directly */ 131663837Seric TryNullMXList = atobool(val); 131763837Seric break; 131861104Seric 131961104Seric /* 'W' available -- was wizard password */ 132061104Seric 132114879Seric case 'x': /* load avg at which to auto-queue msgs */ 132214879Seric QueueLA = atoi(val); 132314879Seric break; 132414879Seric 132514879Seric case 'X': /* load avg at which to auto-reject connections */ 132614879Seric RefuseLA = atoi(val); 132714879Seric break; 132814879Seric 132924981Seric case 'y': /* work recipient factor */ 133024981Seric WkRecipFact = atoi(val); 133124981Seric break; 133224981Seric 133324981Seric case 'Y': /* fork jobs during queue runs */ 133424952Seric ForkQueueRuns = atobool(val); 133524952Seric break; 133624952Seric 133724981Seric case 'z': /* work message class factor */ 133824981Seric WkClassFact = atoi(val); 133924981Seric break; 134024981Seric 134124981Seric case 'Z': /* work time factor */ 134224981Seric WkTimeFact = atoi(val); 134324981Seric break; 134424981Seric 13458256Seric default: 13468256Seric break; 13478256Seric } 134816878Seric if (sticky) 134916878Seric setbitn(opt, StickyOpt); 13509188Seric return; 13518256Seric } 135210687Seric /* 135310687Seric ** SETCLASS -- set a word into a class 135410687Seric ** 135510687Seric ** Parameters: 135610687Seric ** class -- the class to put the word in. 135710687Seric ** word -- the word to enter 135810687Seric ** 135910687Seric ** Returns: 136010687Seric ** none. 136110687Seric ** 136210687Seric ** Side Effects: 136310687Seric ** puts the word into the symbol table. 136410687Seric */ 136510687Seric 136610687Seric setclass(class, word) 136710687Seric int class; 136810687Seric char *word; 136910687Seric { 137010687Seric register STAB *s; 137110687Seric 137257943Seric if (tTd(37, 8)) 137357943Seric printf("%s added to class %c\n", word, class); 137410687Seric s = stab(word, ST_CLASS, ST_ENTER); 137510687Seric setbitn(class, s->s_class); 137610687Seric } 137753654Seric /* 137853654Seric ** MAKEMAPENTRY -- create a map entry 137953654Seric ** 138053654Seric ** Parameters: 138153654Seric ** line -- the config file line 138253654Seric ** 138353654Seric ** Returns: 138453654Seric ** TRUE if it successfully entered the map entry. 138553654Seric ** FALSE otherwise (usually syntax error). 138653654Seric ** 138753654Seric ** Side Effects: 138853654Seric ** Enters the map into the dictionary. 138953654Seric */ 139053654Seric 139153654Seric void 139253654Seric makemapentry(line) 139353654Seric char *line; 139453654Seric { 139553654Seric register char *p; 139653654Seric char *mapname; 139753654Seric char *classname; 139864078Seric register STAB *s; 139953654Seric STAB *class; 140053654Seric 140158050Seric for (p = line; isascii(*p) && isspace(*p); p++) 140253654Seric continue; 140358050Seric if (!(isascii(*p) && isalnum(*p))) 140453654Seric { 140553654Seric syserr("readcf: config K line: no map name"); 140653654Seric return; 140753654Seric } 140853654Seric 140953654Seric mapname = p; 141058050Seric while (isascii(*++p) && isalnum(*p)) 141153654Seric continue; 141253654Seric if (*p != '\0') 141353654Seric *p++ = '\0'; 141458050Seric while (isascii(*p) && isspace(*p)) 141553654Seric p++; 141658050Seric if (!(isascii(*p) && isalnum(*p))) 141753654Seric { 141853654Seric syserr("readcf: config K line, map %s: no map class", mapname); 141953654Seric return; 142053654Seric } 142153654Seric classname = p; 142258050Seric while (isascii(*++p) && isalnum(*p)) 142353654Seric continue; 142453654Seric if (*p != '\0') 142553654Seric *p++ = '\0'; 142658050Seric while (isascii(*p) && isspace(*p)) 142753654Seric p++; 142853654Seric 142953654Seric /* look up the class */ 143053654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 143153654Seric if (class == NULL) 143253654Seric { 143353654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 143453654Seric return; 143553654Seric } 143653654Seric 143753654Seric /* enter the map */ 143864078Seric s = stab(mapname, ST_MAP, ST_ENTER); 143964078Seric s->s_map.map_class = &class->s_mapclass; 144064078Seric s->s_map.map_mname = newstr(mapname); 144153654Seric 144264078Seric if (class->s_mapclass.map_parse(&s->s_map, p)) 144364078Seric s->s_map.map_mflags |= MF_VALID; 144464078Seric 144564078Seric if (tTd(37, 5)) 144664078Seric { 144764078Seric printf("map %s, class %s, flags %x, file %s,\n", 144864078Seric s->s_map.map_mname, s->s_map.map_class->map_cname, 144964078Seric s->s_map.map_mflags, 145064078Seric s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file); 145164078Seric printf("\tapp %s, domain %s, rebuild %s\n", 145264078Seric s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app, 145364078Seric s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain, 145464078Seric s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild); 145564078Seric } 145653654Seric } 145758112Seric /* 145858112Seric ** SETTIMEOUTS -- parse and set timeout values 145958112Seric ** 146058112Seric ** Parameters: 146158112Seric ** val -- a pointer to the values. If NULL, do initial 146258112Seric ** settings. 146358112Seric ** 146458112Seric ** Returns: 146558112Seric ** none. 146658112Seric ** 146758112Seric ** Side Effects: 146858112Seric ** Initializes the TimeOuts structure 146958112Seric */ 147058112Seric 147158112Seric #define MINUTES * 60 147258112Seric #define HOUR * 3600 147358112Seric 147458112Seric settimeouts(val) 147558112Seric register char *val; 147658112Seric { 147758112Seric register char *p; 147858671Seric extern time_t convtime(); 147958112Seric 148058112Seric if (val == NULL) 148158112Seric { 148258112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 148358112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 148458112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 148558112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 148658112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 148758112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 148858112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 148958112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 149058112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 149158112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 149258112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 149358112Seric return; 149458112Seric } 149558112Seric 149658112Seric for (;; val = p) 149758112Seric { 149858112Seric while (isascii(*val) && isspace(*val)) 149958112Seric val++; 150058112Seric if (*val == '\0') 150158112Seric break; 150258112Seric for (p = val; *p != '\0' && *p != ','; p++) 150358112Seric continue; 150458112Seric if (*p != '\0') 150558112Seric *p++ = '\0'; 150658112Seric 150758112Seric if (isascii(*val) && isdigit(*val)) 150858112Seric { 150958112Seric /* old syntax -- set everything */ 151058796Seric TimeOuts.to_mail = convtime(val, 'm'); 151158112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 151258112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 151358112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 151458112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 151558112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 151658112Seric continue; 151758112Seric } 151858112Seric else 151958112Seric { 152058112Seric register char *q = strchr(val, '='); 152158112Seric time_t to; 152258112Seric 152358112Seric if (q == NULL) 152458112Seric { 152558112Seric /* syntax error */ 152658112Seric continue; 152758112Seric } 152858112Seric *q++ = '\0'; 152958796Seric to = convtime(q, 'm'); 153058112Seric 153158112Seric if (strcasecmp(val, "initial") == 0) 153258112Seric TimeOuts.to_initial = to; 153358112Seric else if (strcasecmp(val, "mail") == 0) 153458112Seric TimeOuts.to_mail = to; 153558112Seric else if (strcasecmp(val, "rcpt") == 0) 153658112Seric TimeOuts.to_rcpt = to; 153758112Seric else if (strcasecmp(val, "datainit") == 0) 153858112Seric TimeOuts.to_datainit = to; 153958112Seric else if (strcasecmp(val, "datablock") == 0) 154058112Seric TimeOuts.to_datablock = to; 154158112Seric else if (strcasecmp(val, "datafinal") == 0) 154258112Seric TimeOuts.to_datafinal = to; 154358112Seric else if (strcasecmp(val, "command") == 0) 154458112Seric TimeOuts.to_nextcommand = to; 154558112Seric else if (strcasecmp(val, "rset") == 0) 154658112Seric TimeOuts.to_rset = to; 154758112Seric else if (strcasecmp(val, "helo") == 0) 154858112Seric TimeOuts.to_helo = to; 154958112Seric else if (strcasecmp(val, "quit") == 0) 155058112Seric TimeOuts.to_quit = to; 155158112Seric else if (strcasecmp(val, "misc") == 0) 155258112Seric TimeOuts.to_miscshort = to; 155358112Seric else 155458112Seric syserr("settimeouts: invalid timeout %s", val); 155558112Seric } 155658112Seric } 155758112Seric } 1558