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*58935Seric static char sccsid[] = "@(#)readcf.c 6.25 (Berkeley) 04/03/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1452647Seric # include <sys/stat.h> 1557207Seric #ifdef NAMED_BIND 1657207Seric # include <arpa/nameser.h> 1757207Seric # include <resolv.h> 1857207Seric #endif 193308Seric 2057736Seric /* System 5 compatibility */ 2157736Seric #ifndef S_ISREG 2257736Seric #define S_ISREG(foo) ((foo & S_IFREG) == S_IFREG) 2357736Seric #endif 2457736Seric #ifndef S_IWGRP 2557736Seric #define S_IWGRP 020 2657736Seric #endif 2757736Seric #ifndef S_IWOTH 2857736Seric #define S_IWOTH 002 2957736Seric #endif 3057736Seric 313308Seric /* 323308Seric ** READCF -- read control file. 333308Seric ** 343308Seric ** This routine reads the control file and builds the internal 353308Seric ** form. 363308Seric ** 374432Seric ** The file is formatted as a sequence of lines, each taken 384432Seric ** atomically. The first character of each line describes how 394432Seric ** the line is to be interpreted. The lines are: 404432Seric ** Dxval Define macro x to have value val. 414432Seric ** Cxword Put word into class x. 424432Seric ** Fxfile [fmt] Read file for lines to put into 434432Seric ** class x. Use scanf string 'fmt' 444432Seric ** or "%s" if not present. Fmt should 454432Seric ** only produce one string-valued result. 464432Seric ** Hname: value Define header with field-name 'name' 474432Seric ** and value as specified; this will be 484432Seric ** macro expanded immediately before 494432Seric ** use. 504432Seric ** Sn Use rewriting set n. 514432Seric ** Rlhs rhs Rewrite addresses that match lhs to 524432Seric ** be rhs. 5324944Seric ** Mn arg=val... Define mailer. n is the internal name. 5424944Seric ** Args specify mailer parameters. 558252Seric ** Oxvalue Set option x to value. 568252Seric ** Pname=value Set precedence name to value. 5752645Seric ** Vversioncode Version level of configuration syntax. 5853654Seric ** Kmapname mapclass arguments.... 5953654Seric ** Define keyed lookup of a given class. 6053654Seric ** Arguments are class dependent. 614432Seric ** 623308Seric ** Parameters: 633308Seric ** cfname -- control file name. 6454973Seric ** safe -- TRUE if this is the system config file; 6554973Seric ** FALSE otherwise. 6655012Seric ** e -- the main envelope. 673308Seric ** 683308Seric ** Returns: 693308Seric ** none. 703308Seric ** 713308Seric ** Side Effects: 723308Seric ** Builds several internal tables. 733308Seric */ 743308Seric 7555012Seric readcf(cfname, safe, e) 763308Seric char *cfname; 7754973Seric bool safe; 7855012Seric register ENVELOPE *e; 793308Seric { 803308Seric FILE *cf; 818547Seric int ruleset = 0; 828547Seric char *q; 838547Seric char **pv; 849350Seric struct rewrite *rwp = NULL; 8557135Seric char *bp; 8657589Seric int nfuzzy; 873308Seric char buf[MAXLINE]; 883308Seric register char *p; 893308Seric extern char **prescan(); 903308Seric extern char **copyplist(); 9152647Seric struct stat statb; 925909Seric char exbuf[MAXLINE]; 9316915Seric char pvpbuf[PSBUFSIZE]; 949350Seric extern char *fgetfolded(); 9510709Seric extern char *munchstring(); 9653654Seric extern void makemapentry(); 973308Seric 9852647Seric FileName = cfname; 9952647Seric LineNumber = 0; 10052647Seric 1013308Seric cf = fopen(cfname, "r"); 1023308Seric if (cf == NULL) 1033308Seric { 10452647Seric syserr("cannot open"); 1053308Seric exit(EX_OSFILE); 1063308Seric } 1073308Seric 10852647Seric if (fstat(fileno(cf), &statb) < 0) 10952647Seric { 11052647Seric syserr("cannot fstat"); 11152647Seric exit(EX_OSFILE); 11252647Seric } 11352647Seric 11452647Seric if (!S_ISREG(statb.st_mode)) 11552647Seric { 11652647Seric syserr("not a plain file"); 11752647Seric exit(EX_OSFILE); 11852647Seric } 11952647Seric 12052647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 12152647Seric { 12253037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 12353037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 12453037Seric FileName); 12553037Seric #ifdef LOG 12653037Seric if (LogLevel > 0) 12753037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 12853037Seric FileName); 12953037Seric #endif 13052647Seric } 13152647Seric 13257135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1333308Seric { 13457135Seric if (bp[0] == '#') 13557135Seric { 13657135Seric if (bp != buf) 13757135Seric free(bp); 13852637Seric continue; 13957135Seric } 14052637Seric 14158050Seric /* map $ into \201 for macro expansion */ 14257135Seric for (p = bp; *p != '\0'; p++) 14316157Seric { 14457135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14552647Seric { 14652647Seric /* this is an on-line comment */ 14752647Seric register char *e; 14852647Seric 14958050Seric switch (*--p & 0377) 15052647Seric { 15158050Seric case MACROEXPAND: 15252647Seric /* it's from $# -- let it go through */ 15352647Seric p++; 15452647Seric break; 15552647Seric 15652647Seric case '\\': 15752647Seric /* it's backslash escaped */ 15852647Seric (void) strcpy(p, p + 1); 15952647Seric break; 16052647Seric 16152647Seric default: 16252647Seric /* delete preceeding white space */ 16358050Seric while (isascii(*p) && isspace(*p) && p > bp) 16452647Seric p--; 16556795Seric if ((e = strchr(++p, '\n')) != NULL) 16652647Seric (void) strcpy(p, e); 16752647Seric else 16852647Seric p[0] = p[1] = '\0'; 16952647Seric break; 17052647Seric } 17152647Seric continue; 17252647Seric } 17352647Seric 17416157Seric if (*p != '$') 17516157Seric continue; 17616157Seric 17716157Seric if (p[1] == '$') 17816157Seric { 17916157Seric /* actual dollar sign.... */ 18023111Seric (void) strcpy(p, p + 1); 18116157Seric continue; 18216157Seric } 18316157Seric 18416157Seric /* convert to macro expansion character */ 18558050Seric *p = MACROEXPAND; 18616157Seric } 18716157Seric 18816157Seric /* interpret this line */ 18957135Seric switch (bp[0]) 1903308Seric { 1913308Seric case '\0': 1923308Seric case '#': /* comment */ 1933308Seric break; 1943308Seric 1953308Seric case 'R': /* rewriting rule */ 19657135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1973308Seric continue; 1983308Seric 1993308Seric if (*p == '\0') 2005909Seric { 20157135Seric syserr("invalid rewrite line \"%s\"", bp); 2025909Seric break; 2035909Seric } 2045909Seric 2055909Seric /* allocate space for the rule header */ 2065909Seric if (rwp == NULL) 2075909Seric { 2085909Seric RewriteRules[ruleset] = rwp = 2095909Seric (struct rewrite *) xalloc(sizeof *rwp); 2105909Seric } 2113308Seric else 2123308Seric { 2135909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2145909Seric rwp = rwp->r_next; 2155909Seric } 2165909Seric rwp->r_next = NULL; 2173308Seric 2185909Seric /* expand and save the LHS */ 2195909Seric *p = '\0'; 22057135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 22158333Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL); 22257589Seric nfuzzy = 0; 2235909Seric if (rwp->r_lhs != NULL) 22457589Seric { 22557589Seric register char **ap; 22657589Seric 2275909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22857589Seric 22957589Seric /* count the number of fuzzy matches in LHS */ 23057589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 23157589Seric { 23258148Seric char *botch; 23358148Seric 23458148Seric botch = NULL; 23558050Seric switch (**ap & 0377) 23657589Seric { 23757589Seric case MATCHZANY: 23857589Seric case MATCHANY: 23957589Seric case MATCHONE: 24057589Seric case MATCHCLASS: 24157589Seric case MATCHNCLASS: 24257589Seric nfuzzy++; 24358148Seric break; 24458148Seric 24558148Seric case MATCHREPL: 24658148Seric botch = "$0-$9"; 24758148Seric break; 24858148Seric 24958148Seric case CANONNET: 25058148Seric botch = "$#"; 25158148Seric break; 25258148Seric 25358148Seric case CANONUSER: 25458148Seric botch = "$:"; 25558148Seric break; 25658148Seric 25758148Seric case CALLSUBR: 25858148Seric botch = "$>"; 25958148Seric break; 26058148Seric 26158148Seric case CONDIF: 26258148Seric botch = "$?"; 26358148Seric break; 26458148Seric 26558148Seric case CONDELSE: 26658148Seric botch = "$|"; 26758148Seric break; 26858148Seric 26958148Seric case CONDFI: 27058148Seric botch = "$."; 27158148Seric break; 27258148Seric 27358148Seric case HOSTBEGIN: 27458148Seric botch = "$["; 27558148Seric break; 27658148Seric 27758148Seric case HOSTEND: 27858148Seric botch = "$]"; 27958148Seric break; 28058148Seric 28158148Seric case LOOKUPBEGIN: 28258148Seric botch = "$("; 28358148Seric break; 28458148Seric 28558148Seric case LOOKUPEND: 28658148Seric botch = "$)"; 28758148Seric break; 28857589Seric } 28958148Seric if (botch != NULL) 29058148Seric syserr("Inappropriate use of %s on LHS", 29158148Seric botch); 29257589Seric } 29357589Seric } 29456678Seric else 29556678Seric syserr("R line: null LHS"); 2965909Seric 2975909Seric /* expand and save the RHS */ 2985909Seric while (*++p == '\t') 2995909Seric continue; 3007231Seric q = p; 3017231Seric while (*p != '\0' && *p != '\t') 3027231Seric p++; 3037231Seric *p = '\0'; 30455012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 30558333Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL); 3065909Seric if (rwp->r_rhs != NULL) 30757589Seric { 30857589Seric register char **ap; 30957589Seric 3105909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 31157589Seric 31257589Seric /* check no out-of-bounds replacements */ 31357589Seric nfuzzy += '0'; 31457589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 31557589Seric { 31658148Seric char *botch; 31758148Seric 31858148Seric botch = NULL; 31958148Seric switch (**ap & 0377) 32057589Seric { 32158148Seric case MATCHREPL: 32258148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 32358148Seric { 32458148Seric syserr("replacement $%c out of bounds", 32558148Seric (*ap)[1]); 32658148Seric } 32758148Seric break; 32858148Seric 32958148Seric case MATCHZANY: 33058148Seric botch = "$*"; 33158148Seric break; 33258148Seric 33358148Seric case MATCHANY: 33458148Seric botch = "$+"; 33558148Seric break; 33658148Seric 33758148Seric case MATCHONE: 33858148Seric botch = "$-"; 33958148Seric break; 34058148Seric 34158148Seric case MATCHCLASS: 34258148Seric botch = "$="; 34358148Seric break; 34458148Seric 34558148Seric case MATCHNCLASS: 34658148Seric botch = "$~"; 34758148Seric break; 34857589Seric } 34958148Seric if (botch != NULL) 35058148Seric syserr("Inappropriate use of %s on RHS", 35158148Seric botch); 35257589Seric } 35357589Seric } 35456678Seric else 35556678Seric syserr("R line: null RHS"); 3563308Seric break; 3573308Seric 3584072Seric case 'S': /* select rewriting set */ 35957135Seric ruleset = atoi(&bp[1]); 3608056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3618056Seric { 3629381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3638056Seric ruleset = 0; 3648056Seric } 3654072Seric rwp = NULL; 3664072Seric break; 3674072Seric 3683308Seric case 'D': /* macro definition */ 36958333Seric define(bp[1], newstr(munchstring(&bp[2], NULL)), e); 3703308Seric break; 3713308Seric 3723387Seric case 'H': /* required header line */ 37357135Seric (void) chompheader(&bp[1], TRUE, e); 3743387Seric break; 3753387Seric 3764061Seric case 'C': /* word class */ 3774432Seric case 'F': /* word class from file */ 3784432Seric /* read list of words from argument or file */ 37957135Seric if (bp[0] == 'F') 3804432Seric { 3814432Seric /* read from file */ 38258050Seric for (p = &bp[2]; 38358050Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 38458050Seric p++) 3854432Seric continue; 3864432Seric if (*p == '\0') 3874432Seric p = "%s"; 3884432Seric else 3894432Seric { 3904432Seric *p = '\0'; 39158050Seric while (isascii(*++p) && isspace(*p)) 3924432Seric continue; 3934432Seric } 39457135Seric fileclass(bp[1], &bp[2], p, safe); 3954432Seric break; 3964432Seric } 3974061Seric 3984432Seric /* scan the list of words and set class for all */ 39957135Seric for (p = &bp[2]; *p != '\0'; ) 4004061Seric { 4014061Seric register char *wd; 4024061Seric char delim; 4034061Seric 40458050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 4054061Seric p++; 4064061Seric wd = p; 40758050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 4084061Seric p++; 4094061Seric delim = *p; 4104061Seric *p = '\0'; 4114061Seric if (wd[0] != '\0') 41258148Seric { 41358148Seric if (tTd(37, 2)) 41458148Seric printf("setclass(%c, %s)\n", 41558148Seric bp[1], wd); 41657135Seric setclass(bp[1], wd); 41758148Seric } 4184061Seric *p = delim; 4194061Seric } 4204061Seric break; 4214061Seric 4224096Seric case 'M': /* define mailer */ 42357135Seric makemailer(&bp[1]); 4244096Seric break; 4254096Seric 4268252Seric case 'O': /* set option */ 42758734Seric setoption(bp[1], &bp[2], safe, FALSE, e); 4288252Seric break; 4298252Seric 4308252Seric case 'P': /* set precedence */ 4318252Seric if (NumPriorities >= MAXPRIORITIES) 4328252Seric { 4338547Seric toomany('P', MAXPRIORITIES); 4348252Seric break; 4358252Seric } 43657135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4378252Seric continue; 4388252Seric if (*p == '\0') 4398252Seric goto badline; 4408252Seric *p = '\0'; 44157135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4428252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4438252Seric NumPriorities++; 4448252Seric break; 4458252Seric 4468547Seric case 'T': /* trusted user(s) */ 44758161Seric /* this option is obsolete, but will be ignored */ 4488547Seric break; 4498547Seric 45052645Seric case 'V': /* configuration syntax version */ 45157135Seric ConfigLevel = atoi(&bp[1]); 45252645Seric break; 45352645Seric 45453654Seric case 'K': 45557135Seric makemapentry(&bp[1]); 45653654Seric break; 45753654Seric 4583308Seric default: 4594061Seric badline: 46057135Seric syserr("unknown control line \"%s\"", bp); 4613308Seric } 46257135Seric if (bp != buf) 46357135Seric free(bp); 4643308Seric } 46552637Seric if (ferror(cf)) 46652637Seric { 46752647Seric syserr("I/O read error", cfname); 46852637Seric exit(EX_OSFILE); 46952637Seric } 47052637Seric fclose(cf); 4719381Seric FileName = NULL; 47256836Seric 47357076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 47457076Seric { 47557076Seric /* user didn't initialize: set up host map */ 47657076Seric strcpy(buf, "host host"); 47757076Seric if (ConfigLevel >= 2) 47857076Seric strcat(buf, " -a."); 47957076Seric makemapentry(buf); 48057076Seric } 4814096Seric } 4824096Seric /* 4838547Seric ** TOOMANY -- signal too many of some option 4848547Seric ** 4858547Seric ** Parameters: 4868547Seric ** id -- the id of the error line 4878547Seric ** maxcnt -- the maximum possible values 4888547Seric ** 4898547Seric ** Returns: 4908547Seric ** none. 4918547Seric ** 4928547Seric ** Side Effects: 4938547Seric ** gives a syserr. 4948547Seric */ 4958547Seric 4968547Seric toomany(id, maxcnt) 4978547Seric char id; 4988547Seric int maxcnt; 4998547Seric { 5009381Seric syserr("too many %c lines, %d max", id, maxcnt); 5018547Seric } 5028547Seric /* 5034432Seric ** FILECLASS -- read members of a class from a file 5044432Seric ** 5054432Seric ** Parameters: 5064432Seric ** class -- class to define. 5074432Seric ** filename -- name of file to read. 5084432Seric ** fmt -- scanf string to use for match. 5094432Seric ** 5104432Seric ** Returns: 5114432Seric ** none 5124432Seric ** 5134432Seric ** Side Effects: 5144432Seric ** 5154432Seric ** puts all lines in filename that match a scanf into 5164432Seric ** the named class. 5174432Seric */ 5184432Seric 51954973Seric fileclass(class, filename, fmt, safe) 5204432Seric int class; 5214432Seric char *filename; 5224432Seric char *fmt; 52354973Seric bool safe; 5244432Seric { 52525808Seric FILE *f; 52654973Seric struct stat stbuf; 5274432Seric char buf[MAXLINE]; 5284432Seric 52954973Seric if (stat(filename, &stbuf) < 0) 53054973Seric { 53154973Seric syserr("fileclass: cannot stat %s", filename); 53254973Seric return; 53354973Seric } 53454973Seric if (!S_ISREG(stbuf.st_mode)) 53554973Seric { 53654973Seric syserr("fileclass: %s not a regular file", filename); 53754973Seric return; 53854973Seric } 53954973Seric if (!safe && access(filename, R_OK) < 0) 54054973Seric { 54154973Seric syserr("fileclass: access denied on %s", filename); 54254973Seric return; 54354973Seric } 54454973Seric f = fopen(filename, "r"); 5454432Seric if (f == NULL) 5464432Seric { 54754973Seric syserr("fileclass: cannot open %s", filename); 5484432Seric return; 5494432Seric } 5504432Seric 5514432Seric while (fgets(buf, sizeof buf, f) != NULL) 5524432Seric { 5534432Seric register STAB *s; 55425808Seric register char *p; 55525808Seric # ifdef SCANF 5564432Seric char wordbuf[MAXNAME+1]; 5574432Seric 5584432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5594432Seric continue; 56025808Seric p = wordbuf; 56156795Seric # else /* SCANF */ 56225808Seric p = buf; 56356795Seric # endif /* SCANF */ 56425808Seric 56525808Seric /* 56625808Seric ** Break up the match into words. 56725808Seric */ 56825808Seric 56925808Seric while (*p != '\0') 57025808Seric { 57125808Seric register char *q; 57225808Seric 57325808Seric /* strip leading spaces */ 57458050Seric while (isascii(*p) && isspace(*p)) 57525808Seric p++; 57625808Seric if (*p == '\0') 57725808Seric break; 57825808Seric 57925808Seric /* find the end of the word */ 58025808Seric q = p; 58158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 58225808Seric p++; 58325808Seric if (*p != '\0') 58425808Seric *p++ = '\0'; 58525808Seric 58625808Seric /* enter the word in the symbol table */ 58725808Seric s = stab(q, ST_CLASS, ST_ENTER); 58825808Seric setbitn(class, s->s_class); 58925808Seric } 5904432Seric } 5914432Seric 59254973Seric (void) fclose(f); 5934432Seric } 5944432Seric /* 5954096Seric ** MAKEMAILER -- define a new mailer. 5964096Seric ** 5974096Seric ** Parameters: 59810327Seric ** line -- description of mailer. This is in labeled 59910327Seric ** fields. The fields are: 60010327Seric ** P -- the path to the mailer 60110327Seric ** F -- the flags associated with the mailer 60210327Seric ** A -- the argv for this mailer 60310327Seric ** S -- the sender rewriting set 60410327Seric ** R -- the recipient rewriting set 60510327Seric ** E -- the eol string 60610327Seric ** The first word is the canonical name of the mailer. 6074096Seric ** 6084096Seric ** Returns: 6094096Seric ** none. 6104096Seric ** 6114096Seric ** Side Effects: 6124096Seric ** enters the mailer into the mailer table. 6134096Seric */ 6143308Seric 61521066Seric makemailer(line) 6164096Seric char *line; 6174096Seric { 6184096Seric register char *p; 6198067Seric register struct mailer *m; 6208067Seric register STAB *s; 6218067Seric int i; 62210327Seric char fcode; 62358020Seric auto char *endp; 6244096Seric extern int NextMailer; 62510327Seric extern char **makeargv(); 62610327Seric extern char *munchstring(); 62710701Seric extern long atol(); 6284096Seric 62910327Seric /* allocate a mailer and set up defaults */ 63010327Seric m = (struct mailer *) xalloc(sizeof *m); 63110327Seric bzero((char *) m, sizeof *m); 63210327Seric m->m_eol = "\n"; 63310327Seric 63410327Seric /* collect the mailer name */ 63558050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 63610327Seric continue; 63710327Seric if (*p != '\0') 63810327Seric *p++ = '\0'; 63910327Seric m->m_name = newstr(line); 64010327Seric 64110327Seric /* now scan through and assign info from the fields */ 64210327Seric while (*p != '\0') 64310327Seric { 64458333Seric auto char *delimptr; 64558333Seric 64658050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 64710327Seric p++; 64810327Seric 64910327Seric /* p now points to field code */ 65010327Seric fcode = *p; 65110327Seric while (*p != '\0' && *p != '=' && *p != ',') 65210327Seric p++; 65310327Seric if (*p++ != '=') 65410327Seric { 65552637Seric syserr("mailer %s: `=' expected", m->m_name); 65610327Seric return; 65710327Seric } 65858050Seric while (isascii(*p) && isspace(*p)) 65910327Seric p++; 66010327Seric 66110327Seric /* p now points to the field body */ 66258333Seric p = munchstring(p, &delimptr); 66310327Seric 66410327Seric /* install the field into the mailer struct */ 66510327Seric switch (fcode) 66610327Seric { 66710327Seric case 'P': /* pathname */ 66810327Seric m->m_mailer = newstr(p); 66910327Seric break; 67010327Seric 67110327Seric case 'F': /* flags */ 67210687Seric for (; *p != '\0'; p++) 67358050Seric if (!(isascii(*p) && isspace(*p))) 67452637Seric setbitn(*p, m->m_flags); 67510327Seric break; 67610327Seric 67710327Seric case 'S': /* sender rewriting ruleset */ 67810327Seric case 'R': /* recipient rewriting ruleset */ 67958020Seric i = strtol(p, &endp, 10); 68010327Seric if (i < 0 || i >= MAXRWSETS) 68110327Seric { 68210327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 68310327Seric return; 68410327Seric } 68510327Seric if (fcode == 'S') 68658020Seric m->m_sh_rwset = m->m_se_rwset = i; 68710327Seric else 68858020Seric m->m_rh_rwset = m->m_re_rwset = i; 68958020Seric 69058020Seric p = endp; 69158020Seric if (*p == '/') 69258020Seric { 69358020Seric i = strtol(p, NULL, 10); 69458020Seric if (i < 0 || i >= MAXRWSETS) 69558020Seric { 69658020Seric syserr("invalid rewrite set, %d max", 69758020Seric MAXRWSETS); 69858020Seric return; 69958020Seric } 70058020Seric if (fcode == 'S') 70158020Seric m->m_sh_rwset = i; 70258020Seric else 70358020Seric m->m_rh_rwset = i; 70458020Seric } 70510327Seric break; 70610327Seric 70710327Seric case 'E': /* end of line string */ 70810327Seric m->m_eol = newstr(p); 70910327Seric break; 71010327Seric 71110327Seric case 'A': /* argument vector */ 71210327Seric m->m_argv = makeargv(p); 71310327Seric break; 71410701Seric 71510701Seric case 'M': /* maximum message size */ 71610701Seric m->m_maxsize = atol(p); 71710701Seric break; 71852106Seric 71952106Seric case 'L': /* maximum line length */ 72052106Seric m->m_linelimit = atoi(p); 72152106Seric break; 722*58935Seric 723*58935Seric case 'D': /* working directory */ 724*58935Seric m->m_execdir = newstr(p); 725*58935Seric break; 72610327Seric } 72710327Seric 72858333Seric p = delimptr; 72910327Seric } 73010327Seric 73152106Seric /* do some heuristic cleanup for back compatibility */ 73252106Seric if (bitnset(M_LIMITS, m->m_flags)) 73352106Seric { 73452106Seric if (m->m_linelimit == 0) 73552106Seric m->m_linelimit = SMTPLINELIM; 73655418Seric if (ConfigLevel < 2) 73752106Seric setbitn(M_7BITS, m->m_flags); 73852106Seric } 73952106Seric 74058321Seric /* do some rationality checking */ 74158321Seric if (m->m_argv == NULL) 74258321Seric { 74358321Seric syserr("M%s: A= argument required", m->m_name); 74458321Seric return; 74558321Seric } 74658321Seric if (m->m_mailer == NULL) 74758321Seric { 74858321Seric syserr("M%s: P= argument required", m->m_name); 74958321Seric return; 75058321Seric } 75158321Seric 7524096Seric if (NextMailer >= MAXMAILERS) 7534096Seric { 7549381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7554096Seric return; 7564096Seric } 75757402Seric 75810327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 75957402Seric if (s->s_mailer != NULL) 76057402Seric { 76157402Seric i = s->s_mailer->m_mno; 76257402Seric free(s->s_mailer); 76357402Seric } 76457402Seric else 76557402Seric { 76657402Seric i = NextMailer++; 76757402Seric } 76857402Seric Mailer[i] = s->s_mailer = m; 76957454Seric m->m_mno = i; 77010327Seric } 77110327Seric /* 77210327Seric ** MUNCHSTRING -- translate a string into internal form. 77310327Seric ** 77410327Seric ** Parameters: 77510327Seric ** p -- the string to munch. 77658333Seric ** delimptr -- if non-NULL, set to the pointer of the 77758333Seric ** field delimiter character. 77810327Seric ** 77910327Seric ** Returns: 78010327Seric ** the munched string. 78110327Seric */ 7824096Seric 78310327Seric char * 78458333Seric munchstring(p, delimptr) 78510327Seric register char *p; 78658333Seric char **delimptr; 78710327Seric { 78810327Seric register char *q; 78910327Seric bool backslash = FALSE; 79010327Seric bool quotemode = FALSE; 79110327Seric static char buf[MAXLINE]; 7924096Seric 79310327Seric for (q = buf; *p != '\0'; p++) 7944096Seric { 79510327Seric if (backslash) 79610327Seric { 79710327Seric /* everything is roughly literal */ 79810357Seric backslash = FALSE; 79910327Seric switch (*p) 80010327Seric { 80110327Seric case 'r': /* carriage return */ 80210327Seric *q++ = '\r'; 80310327Seric continue; 80410327Seric 80510327Seric case 'n': /* newline */ 80610327Seric *q++ = '\n'; 80710327Seric continue; 80810327Seric 80910327Seric case 'f': /* form feed */ 81010327Seric *q++ = '\f'; 81110327Seric continue; 81210327Seric 81310327Seric case 'b': /* backspace */ 81410327Seric *q++ = '\b'; 81510327Seric continue; 81610327Seric } 81710327Seric *q++ = *p; 81810327Seric } 81910327Seric else 82010327Seric { 82110327Seric if (*p == '\\') 82210327Seric backslash = TRUE; 82310327Seric else if (*p == '"') 82410327Seric quotemode = !quotemode; 82510327Seric else if (quotemode || *p != ',') 82610327Seric *q++ = *p; 82710327Seric else 82810327Seric break; 82910327Seric } 8304096Seric } 8314096Seric 83258333Seric if (delimptr != NULL) 83358333Seric *delimptr = p; 83410327Seric *q++ = '\0'; 83510327Seric return (buf); 83610327Seric } 83710327Seric /* 83810327Seric ** MAKEARGV -- break up a string into words 83910327Seric ** 84010327Seric ** Parameters: 84110327Seric ** p -- the string to break up. 84210327Seric ** 84310327Seric ** Returns: 84410327Seric ** a char **argv (dynamically allocated) 84510327Seric ** 84610327Seric ** Side Effects: 84710327Seric ** munges p. 84810327Seric */ 8494096Seric 85010327Seric char ** 85110327Seric makeargv(p) 85210327Seric register char *p; 85310327Seric { 85410327Seric char *q; 85510327Seric int i; 85610327Seric char **avp; 85710327Seric char *argv[MAXPV + 1]; 85810327Seric 85910327Seric /* take apart the words */ 86010327Seric i = 0; 86110327Seric while (*p != '\0' && i < MAXPV) 8624096Seric { 86310327Seric q = p; 86458050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 86510327Seric p++; 86658050Seric while (isascii(*p) && isspace(*p)) 86710327Seric *p++ = '\0'; 86810327Seric argv[i++] = newstr(q); 8694096Seric } 87010327Seric argv[i++] = NULL; 8714096Seric 87210327Seric /* now make a copy of the argv */ 87310327Seric avp = (char **) xalloc(sizeof *avp * i); 87416893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 87510327Seric 87610327Seric return (avp); 8773308Seric } 8783308Seric /* 8793308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8803308Seric ** 8813308Seric ** Parameters: 8823308Seric ** none. 8833308Seric ** 8843308Seric ** Returns: 8853308Seric ** none. 8863308Seric ** 8873308Seric ** Side Effects: 8883308Seric ** prints rewrite rules. 8893308Seric */ 8903308Seric 8913308Seric printrules() 8923308Seric { 8933308Seric register struct rewrite *rwp; 8944072Seric register int ruleset; 8953308Seric 8964072Seric for (ruleset = 0; ruleset < 10; ruleset++) 8973308Seric { 8984072Seric if (RewriteRules[ruleset] == NULL) 8994072Seric continue; 9008067Seric printf("\n----Rule Set %d:", ruleset); 9013308Seric 9024072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9033308Seric { 9048067Seric printf("\nLHS:"); 9058067Seric printav(rwp->r_lhs); 9068067Seric printf("RHS:"); 9078067Seric printav(rwp->r_rhs); 9083308Seric } 9093308Seric } 9103308Seric } 9114319Seric 9124096Seric /* 9138256Seric ** SETOPTION -- set global processing option 9148256Seric ** 9158256Seric ** Parameters: 9168256Seric ** opt -- option name. 9178256Seric ** val -- option value (as a text string). 91821755Seric ** safe -- set if this came from a configuration file. 91921755Seric ** Some options (if set from the command line) will 92021755Seric ** reset the user id to avoid security problems. 9218269Seric ** sticky -- if set, don't let other setoptions override 9228269Seric ** this value. 92358734Seric ** e -- the main envelope. 9248256Seric ** 9258256Seric ** Returns: 9268256Seric ** none. 9278256Seric ** 9288256Seric ** Side Effects: 9298256Seric ** Sets options as implied by the arguments. 9308256Seric */ 9318256Seric 93210687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9338269Seric 93457207Seric 93557207Seric #ifdef NAMED_BIND 93657207Seric 93757207Seric struct resolverflags 93857207Seric { 93957207Seric char *rf_name; /* name of the flag */ 94057207Seric long rf_bits; /* bits to set/clear */ 94157207Seric } ResolverFlags[] = 94257207Seric { 94357207Seric "debug", RES_DEBUG, 94457207Seric "aaonly", RES_AAONLY, 94557207Seric "usevc", RES_USEVC, 94657207Seric "primary", RES_PRIMARY, 94757207Seric "igntc", RES_IGNTC, 94857207Seric "recurse", RES_RECURSE, 94957207Seric "defnames", RES_DEFNAMES, 95057207Seric "stayopen", RES_STAYOPEN, 95157207Seric "dnsrch", RES_DNSRCH, 95257207Seric NULL, 0 95357207Seric }; 95457207Seric 95557207Seric #endif 95657207Seric 95758734Seric setoption(opt, val, safe, sticky, e) 9588256Seric char opt; 9598256Seric char *val; 96021755Seric bool safe; 9618269Seric bool sticky; 96258734Seric register ENVELOPE *e; 9638256Seric { 96457207Seric register char *p; 9658265Seric extern bool atobool(); 96612633Seric extern time_t convtime(); 96714879Seric extern int QueueLA; 96814879Seric extern int RefuseLA; 96917474Seric extern bool trusteduser(); 97017474Seric extern char *username(); 9718256Seric 9728256Seric if (tTd(37, 1)) 9739341Seric printf("setoption %c=%s", opt, val); 9748256Seric 9758256Seric /* 9768269Seric ** See if this option is preset for us. 9778256Seric */ 9788256Seric 97910687Seric if (bitnset(opt, StickyOpt)) 9808269Seric { 9819341Seric if (tTd(37, 1)) 9829341Seric printf(" (ignored)\n"); 9838269Seric return; 9848269Seric } 9858269Seric 98621755Seric /* 98721755Seric ** Check to see if this option can be specified by this user. 98821755Seric */ 98921755Seric 99036238Skarels if (!safe && getuid() == 0) 99121755Seric safe = TRUE; 99258082Seric if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL) 99321755Seric { 99439111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 99521755Seric { 99636582Sbostic if (tTd(37, 1)) 99736582Sbostic printf(" (unsafe)"); 99836582Sbostic if (getuid() != geteuid()) 99936582Sbostic { 100051210Seric if (tTd(37, 1)) 100151210Seric printf("(Resetting uid)"); 100236582Sbostic (void) setgid(getgid()); 100336582Sbostic (void) setuid(getuid()); 100436582Sbostic } 100521755Seric } 100621755Seric } 100751210Seric if (tTd(37, 1)) 100817985Seric printf("\n"); 10098269Seric 10108256Seric switch (opt) 10118256Seric { 101252106Seric case '8': /* allow eight-bit input */ 101352106Seric EightBit = atobool(val); 101452106Seric break; 101552106Seric 10168256Seric case 'A': /* set default alias file */ 10179381Seric if (val[0] == '\0') 10188269Seric AliasFile = "aliases"; 10199381Seric else 10209381Seric AliasFile = newstr(val); 10218256Seric break; 10228256Seric 102317474Seric case 'a': /* look N minutes for "@:@" in alias file */ 102417474Seric if (val[0] == '\0') 102517474Seric SafeAlias = 5; 102617474Seric else 102717474Seric SafeAlias = atoi(val); 102817474Seric break; 102917474Seric 103016843Seric case 'B': /* substitution for blank character */ 103116843Seric SpaceSub = val[0]; 103216843Seric if (SpaceSub == '\0') 103316843Seric SpaceSub = ' '; 103416843Seric break; 103516843Seric 103658082Seric case 'b': /* minimum number of blocks free on queue fs */ 103758082Seric MinBlocksFree = atol(val); 103858082Seric break; 103958082Seric 10409284Seric case 'c': /* don't connect to "expensive" mailers */ 10419381Seric NoConnect = atobool(val); 10429284Seric break; 10439284Seric 104451305Seric case 'C': /* checkpoint every N addresses */ 104551305Seric CheckpointInterval = atoi(val); 104624944Seric break; 104724944Seric 10489284Seric case 'd': /* delivery mode */ 10499284Seric switch (*val) 10508269Seric { 10519284Seric case '\0': 105258734Seric e->e_sendmode = SM_DELIVER; 10538269Seric break; 10548269Seric 105510755Seric case SM_QUEUE: /* queue only */ 105610755Seric #ifndef QUEUE 105710755Seric syserr("need QUEUE to set -odqueue"); 105856795Seric #endif /* QUEUE */ 105910755Seric /* fall through..... */ 106010755Seric 10619284Seric case SM_DELIVER: /* do everything */ 10629284Seric case SM_FORK: /* fork after verification */ 106358734Seric e->e_sendmode = *val; 10648269Seric break; 10658269Seric 10668269Seric default: 10679284Seric syserr("Unknown delivery mode %c", *val); 10688269Seric exit(EX_USAGE); 10698269Seric } 10708269Seric break; 10718269Seric 10729146Seric case 'D': /* rebuild alias database as needed */ 10739381Seric AutoRebuild = atobool(val); 10749146Seric break; 10759146Seric 107655372Seric case 'E': /* error message header/header file */ 107755379Seric if (*val != '\0') 107855379Seric ErrMsgFile = newstr(val); 107955372Seric break; 108055372Seric 10818269Seric case 'e': /* set error processing mode */ 10828269Seric switch (*val) 10838269Seric { 10849381Seric case EM_QUIET: /* be silent about it */ 10859381Seric case EM_MAIL: /* mail back */ 10869381Seric case EM_BERKNET: /* do berknet error processing */ 10879381Seric case EM_WRITE: /* write back (or mail) */ 10888269Seric HoldErrs = TRUE; 10899381Seric /* fall through... */ 10908269Seric 10919381Seric case EM_PRINT: /* print errors normally (default) */ 109258734Seric e->e_errormode = *val; 10938269Seric break; 10948269Seric } 10958269Seric break; 10968269Seric 10979049Seric case 'F': /* file mode */ 109817975Seric FileMode = atooct(val) & 0777; 10999049Seric break; 11009049Seric 11018269Seric case 'f': /* save Unix-style From lines on front */ 11029381Seric SaveFrom = atobool(val); 11038269Seric break; 11048269Seric 110553735Seric case 'G': /* match recipients against GECOS field */ 110653735Seric MatchGecos = atobool(val); 110753735Seric break; 110853735Seric 11098256Seric case 'g': /* default gid */ 111017474Seric DefGid = atoi(val); 11118256Seric break; 11128256Seric 11138256Seric case 'H': /* help file */ 11149381Seric if (val[0] == '\0') 11158269Seric HelpFile = "sendmail.hf"; 11169381Seric else 11179381Seric HelpFile = newstr(val); 11188256Seric break; 11198256Seric 112051305Seric case 'h': /* maximum hop count */ 112151305Seric MaxHopCount = atoi(val); 112251305Seric break; 112351305Seric 112435651Seric case 'I': /* use internet domain name server */ 112557207Seric #ifdef NAMED_BIND 112657207Seric UseNameServer = TRUE; 112757207Seric for (p = val; *p != 0; ) 112857207Seric { 112957207Seric bool clearmode; 113057207Seric char *q; 113157207Seric struct resolverflags *rfp; 113257207Seric 113357207Seric while (*p == ' ') 113457207Seric p++; 113557207Seric if (*p == '\0') 113657207Seric break; 113757207Seric clearmode = FALSE; 113857207Seric if (*p == '-') 113957207Seric clearmode = TRUE; 114057207Seric else if (*p != '+') 114157207Seric p--; 114257207Seric p++; 114357207Seric q = p; 114458050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 114557207Seric p++; 114657207Seric if (*p != '\0') 114757207Seric *p++ = '\0'; 114857207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 114957207Seric { 115057207Seric if (strcasecmp(q, rfp->rf_name) == 0) 115157207Seric break; 115257207Seric } 115357207Seric if (clearmode) 115457207Seric _res.options &= ~rfp->rf_bits; 115557207Seric else 115657207Seric _res.options |= rfp->rf_bits; 115757207Seric } 115857207Seric if (tTd(8, 2)) 115957207Seric printf("_res.options = %x\n", _res.options); 116057207Seric #else 116157207Seric usrerr("name server (I option) specified but BIND not compiled in"); 116257207Seric #endif 116335651Seric break; 116435651Seric 11658269Seric case 'i': /* ignore dot lines in message */ 11669381Seric IgnrDot = atobool(val); 11678269Seric break; 11688269Seric 116957136Seric case 'J': /* .forward search path */ 117057136Seric ForwardPath = newstr(val); 117157136Seric break; 117257136Seric 117354967Seric case 'k': /* connection cache size */ 117454967Seric MaxMciCache = atoi(val); 117556215Seric if (MaxMciCache < 0) 117656215Seric MaxMciCache = 0; 117754967Seric break; 117854967Seric 117954967Seric case 'K': /* connection cache timeout */ 118058796Seric MciCacheTimeout = convtime(val, 'm'); 118154967Seric break; 118254967Seric 11838256Seric case 'L': /* log level */ 11849381Seric LogLevel = atoi(val); 11858256Seric break; 11868256Seric 11878269Seric case 'M': /* define macro */ 11889381Seric define(val[0], newstr(&val[1]), CurEnv); 118916878Seric sticky = FALSE; 11908269Seric break; 11918269Seric 11928269Seric case 'm': /* send to me too */ 11939381Seric MeToo = atobool(val); 11948269Seric break; 11958269Seric 119625820Seric case 'n': /* validate RHS in newaliases */ 119725820Seric CheckAliases = atobool(val); 119825820Seric break; 119925820Seric 120058851Seric case 'O': /* daemon options */ 120158851Seric setdaemonoptions(val); 120258851Seric break; 120358851Seric 12048269Seric case 'o': /* assume old style headers */ 12059381Seric if (atobool(val)) 12069341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12079341Seric else 12089341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12098269Seric break; 12108269Seric 121158082Seric case 'p': /* select privacy level */ 121258082Seric p = val; 121358082Seric for (;;) 121458082Seric { 121558082Seric register struct prival *pv; 121658082Seric extern struct prival PrivacyValues[]; 121758082Seric 121858082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 121958082Seric p++; 122058082Seric if (*p == '\0') 122158082Seric break; 122258082Seric val = p; 122358082Seric while (isascii(*p) && isalnum(*p)) 122458082Seric p++; 122558082Seric if (*p != '\0') 122658082Seric *p++ = '\0'; 122758082Seric 122858082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 122958082Seric { 123058082Seric if (strcasecmp(val, pv->pv_name) == 0) 123158082Seric break; 123258082Seric } 123358886Seric if (pv->pv_name == NULL) 123458886Seric syserr("readcf: Op line: %s unrecognized", val); 123558082Seric PrivacyFlags |= pv->pv_flag; 123658082Seric } 123758082Seric break; 123858082Seric 123924944Seric case 'P': /* postmaster copy address for returned mail */ 124024944Seric PostMasterCopy = newstr(val); 124124944Seric break; 124224944Seric 124324944Seric case 'q': /* slope of queue only function */ 124424944Seric QueueFactor = atoi(val); 124524944Seric break; 124624944Seric 12478256Seric case 'Q': /* queue directory */ 12489381Seric if (val[0] == '\0') 12498269Seric QueueDir = "mqueue"; 12509381Seric else 12519381Seric QueueDir = newstr(val); 125258789Seric if (RealUid != 0 && !safe) 125358789Seric auth_warning(e, "Processed from queue %s", QueueDir); 12548256Seric break; 12558256Seric 125658148Seric case 'R': /* don't prune routes */ 125758148Seric DontPruneRoutes = atobool(val); 125858148Seric break; 125958148Seric 12608256Seric case 'r': /* read timeout */ 126158112Seric settimeouts(val); 12628256Seric break; 12638256Seric 12648256Seric case 'S': /* status file */ 12659381Seric if (val[0] == '\0') 12668269Seric StatFile = "sendmail.st"; 12679381Seric else 12689381Seric StatFile = newstr(val); 12698256Seric break; 12708256Seric 12718265Seric case 's': /* be super safe, even if expensive */ 12729381Seric SuperSafe = atobool(val); 12738256Seric break; 12748256Seric 12758256Seric case 'T': /* queue timeout */ 127658737Seric p = strchr(val, '/'); 127758737Seric if (p != NULL) 127858737Seric { 127958737Seric *p++ = '\0'; 128058796Seric TimeOuts.to_q_warning = convtime(p, 'd'); 128158737Seric } 128258796Seric TimeOuts.to_q_return = convtime(val, 'h'); 128354967Seric break; 12848256Seric 12858265Seric case 't': /* time zone name */ 128652106Seric TimeZoneSpec = newstr(val); 12878265Seric break; 12888265Seric 128950556Seric case 'U': /* location of user database */ 129051360Seric UdbSpec = newstr(val); 129150556Seric break; 129250556Seric 12938256Seric case 'u': /* set default uid */ 129417474Seric DefUid = atoi(val); 129540973Sbostic setdefuser(); 12968256Seric break; 12978256Seric 129858851Seric case 'V': /* fallback MX host */ 129958851Seric FallBackMX = newstr(val); 130058851Seric break; 130158851Seric 13028269Seric case 'v': /* run in verbose mode */ 13039381Seric Verbose = atobool(val); 13048256Seric break; 13058256Seric 130614879Seric case 'x': /* load avg at which to auto-queue msgs */ 130714879Seric QueueLA = atoi(val); 130814879Seric break; 130914879Seric 131014879Seric case 'X': /* load avg at which to auto-reject connections */ 131114879Seric RefuseLA = atoi(val); 131214879Seric break; 131314879Seric 131424981Seric case 'y': /* work recipient factor */ 131524981Seric WkRecipFact = atoi(val); 131624981Seric break; 131724981Seric 131824981Seric case 'Y': /* fork jobs during queue runs */ 131924952Seric ForkQueueRuns = atobool(val); 132024952Seric break; 132124952Seric 132224981Seric case 'z': /* work message class factor */ 132324981Seric WkClassFact = atoi(val); 132424981Seric break; 132524981Seric 132624981Seric case 'Z': /* work time factor */ 132724981Seric WkTimeFact = atoi(val); 132824981Seric break; 132924981Seric 13308256Seric default: 13318256Seric break; 13328256Seric } 133316878Seric if (sticky) 133416878Seric setbitn(opt, StickyOpt); 13359188Seric return; 13368256Seric } 133710687Seric /* 133810687Seric ** SETCLASS -- set a word into a class 133910687Seric ** 134010687Seric ** Parameters: 134110687Seric ** class -- the class to put the word in. 134210687Seric ** word -- the word to enter 134310687Seric ** 134410687Seric ** Returns: 134510687Seric ** none. 134610687Seric ** 134710687Seric ** Side Effects: 134810687Seric ** puts the word into the symbol table. 134910687Seric */ 135010687Seric 135110687Seric setclass(class, word) 135210687Seric int class; 135310687Seric char *word; 135410687Seric { 135510687Seric register STAB *s; 135610687Seric 135757943Seric if (tTd(37, 8)) 135857943Seric printf("%s added to class %c\n", word, class); 135910687Seric s = stab(word, ST_CLASS, ST_ENTER); 136010687Seric setbitn(class, s->s_class); 136110687Seric } 136253654Seric /* 136353654Seric ** MAKEMAPENTRY -- create a map entry 136453654Seric ** 136553654Seric ** Parameters: 136653654Seric ** line -- the config file line 136753654Seric ** 136853654Seric ** Returns: 136953654Seric ** TRUE if it successfully entered the map entry. 137053654Seric ** FALSE otherwise (usually syntax error). 137153654Seric ** 137253654Seric ** Side Effects: 137353654Seric ** Enters the map into the dictionary. 137453654Seric */ 137553654Seric 137653654Seric void 137753654Seric makemapentry(line) 137853654Seric char *line; 137953654Seric { 138053654Seric register char *p; 138153654Seric char *mapname; 138253654Seric char *classname; 138353654Seric register STAB *map; 138453654Seric STAB *class; 138553654Seric 138658050Seric for (p = line; isascii(*p) && isspace(*p); p++) 138753654Seric continue; 138858050Seric if (!(isascii(*p) && isalnum(*p))) 138953654Seric { 139053654Seric syserr("readcf: config K line: no map name"); 139153654Seric return; 139253654Seric } 139353654Seric 139453654Seric mapname = p; 139558050Seric while (isascii(*++p) && isalnum(*p)) 139653654Seric continue; 139753654Seric if (*p != '\0') 139853654Seric *p++ = '\0'; 139958050Seric while (isascii(*p) && isspace(*p)) 140053654Seric p++; 140158050Seric if (!(isascii(*p) && isalnum(*p))) 140253654Seric { 140353654Seric syserr("readcf: config K line, map %s: no map class", mapname); 140453654Seric return; 140553654Seric } 140653654Seric classname = p; 140758050Seric while (isascii(*++p) && isalnum(*p)) 140853654Seric continue; 140953654Seric if (*p != '\0') 141053654Seric *p++ = '\0'; 141158050Seric while (isascii(*p) && isspace(*p)) 141253654Seric p++; 141353654Seric 141453654Seric /* look up the class */ 141553654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 141653654Seric if (class == NULL) 141753654Seric { 141853654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 141953654Seric return; 142053654Seric } 142153654Seric 142253654Seric /* enter the map */ 142353654Seric map = stab(mapname, ST_MAP, ST_ENTER); 142453654Seric map->s_map.map_class = &class->s_mapclass; 142553654Seric 142656823Seric if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 142753654Seric map->s_map.map_flags |= MF_VALID; 142853654Seric } 142958112Seric /* 143058112Seric ** SETTIMEOUTS -- parse and set timeout values 143158112Seric ** 143258112Seric ** Parameters: 143358112Seric ** val -- a pointer to the values. If NULL, do initial 143458112Seric ** settings. 143558112Seric ** 143658112Seric ** Returns: 143758112Seric ** none. 143858112Seric ** 143958112Seric ** Side Effects: 144058112Seric ** Initializes the TimeOuts structure 144158112Seric */ 144258112Seric 144358112Seric #define MINUTES * 60 144458112Seric #define HOUR * 3600 144558112Seric 144658112Seric settimeouts(val) 144758112Seric register char *val; 144858112Seric { 144958112Seric register char *p; 145058671Seric extern time_t convtime(); 145158112Seric 145258112Seric if (val == NULL) 145358112Seric { 145458112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 145558112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 145658112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 145758112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 145858112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 145958112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 146058112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 146158112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 146258112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 146358112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 146458112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 146558112Seric return; 146658112Seric } 146758112Seric 146858112Seric for (;; val = p) 146958112Seric { 147058112Seric while (isascii(*val) && isspace(*val)) 147158112Seric val++; 147258112Seric if (*val == '\0') 147358112Seric break; 147458112Seric for (p = val; *p != '\0' && *p != ','; p++) 147558112Seric continue; 147658112Seric if (*p != '\0') 147758112Seric *p++ = '\0'; 147858112Seric 147958112Seric if (isascii(*val) && isdigit(*val)) 148058112Seric { 148158112Seric /* old syntax -- set everything */ 148258796Seric TimeOuts.to_mail = convtime(val, 'm'); 148358112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 148458112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 148558112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 148658112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 148758112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 148858112Seric continue; 148958112Seric } 149058112Seric else 149158112Seric { 149258112Seric register char *q = strchr(val, '='); 149358112Seric time_t to; 149458112Seric 149558112Seric if (q == NULL) 149658112Seric { 149758112Seric /* syntax error */ 149858112Seric continue; 149958112Seric } 150058112Seric *q++ = '\0'; 150158796Seric to = convtime(q, 'm'); 150258112Seric 150358112Seric if (strcasecmp(val, "initial") == 0) 150458112Seric TimeOuts.to_initial = to; 150558112Seric else if (strcasecmp(val, "mail") == 0) 150658112Seric TimeOuts.to_mail = to; 150758112Seric else if (strcasecmp(val, "rcpt") == 0) 150858112Seric TimeOuts.to_rcpt = to; 150958112Seric else if (strcasecmp(val, "datainit") == 0) 151058112Seric TimeOuts.to_datainit = to; 151158112Seric else if (strcasecmp(val, "datablock") == 0) 151258112Seric TimeOuts.to_datablock = to; 151358112Seric else if (strcasecmp(val, "datafinal") == 0) 151458112Seric TimeOuts.to_datafinal = to; 151558112Seric else if (strcasecmp(val, "command") == 0) 151658112Seric TimeOuts.to_nextcommand = to; 151758112Seric else if (strcasecmp(val, "rset") == 0) 151858112Seric TimeOuts.to_rset = to; 151958112Seric else if (strcasecmp(val, "helo") == 0) 152058112Seric TimeOuts.to_helo = to; 152158112Seric else if (strcasecmp(val, "quit") == 0) 152258112Seric TimeOuts.to_quit = to; 152358112Seric else if (strcasecmp(val, "misc") == 0) 152458112Seric TimeOuts.to_miscshort = to; 152558112Seric else 152658112Seric syserr("settimeouts: invalid timeout %s", val); 152758112Seric } 152858112Seric } 152958112Seric } 1530