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*58148Seric static char sccsid[] = "@(#)readcf.c 6.11 (Berkeley) 02/22/93"; 1133731Sbostic #endif /* not lint */ 1222709Sdist 133313Seric # include "sendmail.h" 1452647Seric # include <sys/stat.h> 1554973Seric # include <unistd.h> 1657207Seric #ifdef NAMED_BIND 1757207Seric # include <arpa/nameser.h> 1857207Seric # include <resolv.h> 1957207Seric #endif 203308Seric 2157736Seric /* System 5 compatibility */ 2257736Seric #ifndef S_ISREG 2357736Seric #define S_ISREG(foo) ((foo & S_IFREG) == S_IFREG) 2457736Seric #endif 2557736Seric #ifndef S_IWGRP 2657736Seric #define S_IWGRP 020 2757736Seric #endif 2857736Seric #ifndef S_IWOTH 2957736Seric #define S_IWOTH 002 3057736Seric #endif 3157736Seric 323308Seric /* 333308Seric ** READCF -- read control file. 343308Seric ** 353308Seric ** This routine reads the control file and builds the internal 363308Seric ** form. 373308Seric ** 384432Seric ** The file is formatted as a sequence of lines, each taken 394432Seric ** atomically. The first character of each line describes how 404432Seric ** the line is to be interpreted. The lines are: 414432Seric ** Dxval Define macro x to have value val. 424432Seric ** Cxword Put word into class x. 434432Seric ** Fxfile [fmt] Read file for lines to put into 444432Seric ** class x. Use scanf string 'fmt' 454432Seric ** or "%s" if not present. Fmt should 464432Seric ** only produce one string-valued result. 474432Seric ** Hname: value Define header with field-name 'name' 484432Seric ** and value as specified; this will be 494432Seric ** macro expanded immediately before 504432Seric ** use. 514432Seric ** Sn Use rewriting set n. 524432Seric ** Rlhs rhs Rewrite addresses that match lhs to 534432Seric ** be rhs. 5424944Seric ** Mn arg=val... Define mailer. n is the internal name. 5524944Seric ** Args specify mailer parameters. 568252Seric ** Oxvalue Set option x to value. 578252Seric ** Pname=value Set precedence name to value. 5852645Seric ** Vversioncode Version level of configuration syntax. 5953654Seric ** Kmapname mapclass arguments.... 6053654Seric ** Define keyed lookup of a given class. 6153654Seric ** Arguments are class dependent. 624432Seric ** 633308Seric ** Parameters: 643308Seric ** cfname -- control file name. 6554973Seric ** safe -- TRUE if this is the system config file; 6654973Seric ** FALSE otherwise. 6755012Seric ** e -- the main envelope. 683308Seric ** 693308Seric ** Returns: 703308Seric ** none. 713308Seric ** 723308Seric ** Side Effects: 733308Seric ** Builds several internal tables. 743308Seric */ 753308Seric 7655012Seric readcf(cfname, safe, e) 773308Seric char *cfname; 7854973Seric bool safe; 7955012Seric register ENVELOPE *e; 803308Seric { 813308Seric FILE *cf; 828547Seric int ruleset = 0; 838547Seric char *q; 848547Seric char **pv; 859350Seric struct rewrite *rwp = NULL; 8657135Seric char *bp; 8757589Seric int nfuzzy; 883308Seric char buf[MAXLINE]; 893308Seric register char *p; 903308Seric extern char **prescan(); 913308Seric extern char **copyplist(); 9252647Seric struct stat statb; 935909Seric char exbuf[MAXLINE]; 9416915Seric char pvpbuf[PSBUFSIZE]; 959350Seric extern char *fgetfolded(); 9610709Seric extern char *munchstring(); 9753654Seric extern void makemapentry(); 983308Seric 9952647Seric FileName = cfname; 10052647Seric LineNumber = 0; 10152647Seric 1023308Seric cf = fopen(cfname, "r"); 1033308Seric if (cf == NULL) 1043308Seric { 10552647Seric syserr("cannot open"); 1063308Seric exit(EX_OSFILE); 1073308Seric } 1083308Seric 10952647Seric if (fstat(fileno(cf), &statb) < 0) 11052647Seric { 11152647Seric syserr("cannot fstat"); 11252647Seric exit(EX_OSFILE); 11352647Seric } 11452647Seric 11552647Seric if (!S_ISREG(statb.st_mode)) 11652647Seric { 11752647Seric syserr("not a plain file"); 11852647Seric exit(EX_OSFILE); 11952647Seric } 12052647Seric 12152647Seric if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode)) 12252647Seric { 12353037Seric if (OpMode == MD_DAEMON || OpMode == MD_FREEZE) 12453037Seric fprintf(stderr, "%s: WARNING: dangerous write permissions\n", 12553037Seric FileName); 12653037Seric #ifdef LOG 12753037Seric if (LogLevel > 0) 12853037Seric syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions", 12953037Seric FileName); 13053037Seric #endif 13152647Seric } 13252647Seric 13357135Seric while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL) 1343308Seric { 13557135Seric if (bp[0] == '#') 13657135Seric { 13757135Seric if (bp != buf) 13857135Seric free(bp); 13952637Seric continue; 14057135Seric } 14152637Seric 14258050Seric /* map $ into \201 for macro expansion */ 14357135Seric for (p = bp; *p != '\0'; p++) 14416157Seric { 14557135Seric if (*p == '#' && p > bp && ConfigLevel >= 3) 14652647Seric { 14752647Seric /* this is an on-line comment */ 14852647Seric register char *e; 14952647Seric 15058050Seric switch (*--p & 0377) 15152647Seric { 15258050Seric case MACROEXPAND: 15352647Seric /* it's from $# -- let it go through */ 15452647Seric p++; 15552647Seric break; 15652647Seric 15752647Seric case '\\': 15852647Seric /* it's backslash escaped */ 15952647Seric (void) strcpy(p, p + 1); 16052647Seric break; 16152647Seric 16252647Seric default: 16352647Seric /* delete preceeding white space */ 16458050Seric while (isascii(*p) && isspace(*p) && p > bp) 16552647Seric p--; 16656795Seric if ((e = strchr(++p, '\n')) != NULL) 16752647Seric (void) strcpy(p, e); 16852647Seric else 16952647Seric p[0] = p[1] = '\0'; 17052647Seric break; 17152647Seric } 17252647Seric continue; 17352647Seric } 17452647Seric 17516157Seric if (*p != '$') 17616157Seric continue; 17716157Seric 17816157Seric if (p[1] == '$') 17916157Seric { 18016157Seric /* actual dollar sign.... */ 18123111Seric (void) strcpy(p, p + 1); 18216157Seric continue; 18316157Seric } 18416157Seric 18516157Seric /* convert to macro expansion character */ 18658050Seric *p = MACROEXPAND; 18716157Seric } 18816157Seric 18916157Seric /* interpret this line */ 19057135Seric switch (bp[0]) 1913308Seric { 1923308Seric case '\0': 1933308Seric case '#': /* comment */ 1943308Seric break; 1953308Seric 1963308Seric case 'R': /* rewriting rule */ 19757135Seric for (p = &bp[1]; *p != '\0' && *p != '\t'; p++) 1983308Seric continue; 1993308Seric 2003308Seric if (*p == '\0') 2015909Seric { 20257135Seric syserr("invalid rewrite line \"%s\"", bp); 2035909Seric break; 2045909Seric } 2055909Seric 2065909Seric /* allocate space for the rule header */ 2075909Seric if (rwp == NULL) 2085909Seric { 2095909Seric RewriteRules[ruleset] = rwp = 2105909Seric (struct rewrite *) xalloc(sizeof *rwp); 2115909Seric } 2123308Seric else 2133308Seric { 2145909Seric rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp); 2155909Seric rwp = rwp->r_next; 2165909Seric } 2175909Seric rwp->r_next = NULL; 2183308Seric 2195909Seric /* expand and save the LHS */ 2205909Seric *p = '\0'; 22157135Seric expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e); 22216915Seric rwp->r_lhs = prescan(exbuf, '\t', pvpbuf); 22357589Seric nfuzzy = 0; 2245909Seric if (rwp->r_lhs != NULL) 22557589Seric { 22657589Seric register char **ap; 22757589Seric 2285909Seric rwp->r_lhs = copyplist(rwp->r_lhs, TRUE); 22957589Seric 23057589Seric /* count the number of fuzzy matches in LHS */ 23157589Seric for (ap = rwp->r_lhs; *ap != NULL; ap++) 23257589Seric { 233*58148Seric char *botch; 234*58148Seric 235*58148Seric botch = NULL; 23658050Seric switch (**ap & 0377) 23757589Seric { 23857589Seric case MATCHZANY: 23957589Seric case MATCHANY: 24057589Seric case MATCHONE: 24157589Seric case MATCHCLASS: 24257589Seric case MATCHNCLASS: 24357589Seric nfuzzy++; 244*58148Seric break; 245*58148Seric 246*58148Seric case MATCHREPL: 247*58148Seric botch = "$0-$9"; 248*58148Seric break; 249*58148Seric 250*58148Seric case CANONNET: 251*58148Seric botch = "$#"; 252*58148Seric break; 253*58148Seric 254*58148Seric case CANONHOST: 255*58148Seric botch = "$@"; 256*58148Seric break; 257*58148Seric 258*58148Seric case CANONUSER: 259*58148Seric botch = "$:"; 260*58148Seric break; 261*58148Seric 262*58148Seric case CALLSUBR: 263*58148Seric botch = "$>"; 264*58148Seric break; 265*58148Seric 266*58148Seric case CONDIF: 267*58148Seric botch = "$?"; 268*58148Seric break; 269*58148Seric 270*58148Seric case CONDELSE: 271*58148Seric botch = "$|"; 272*58148Seric break; 273*58148Seric 274*58148Seric case CONDFI: 275*58148Seric botch = "$."; 276*58148Seric break; 277*58148Seric 278*58148Seric case HOSTBEGIN: 279*58148Seric botch = "$["; 280*58148Seric break; 281*58148Seric 282*58148Seric case HOSTEND: 283*58148Seric botch = "$]"; 284*58148Seric break; 285*58148Seric 286*58148Seric case LOOKUPBEGIN: 287*58148Seric botch = "$("; 288*58148Seric break; 289*58148Seric 290*58148Seric case LOOKUPEND: 291*58148Seric botch = "$)"; 292*58148Seric break; 29357589Seric } 294*58148Seric if (botch != NULL) 295*58148Seric syserr("Inappropriate use of %s on LHS", 296*58148Seric botch); 29757589Seric } 29857589Seric } 29956678Seric else 30056678Seric syserr("R line: null LHS"); 3015909Seric 3025909Seric /* expand and save the RHS */ 3035909Seric while (*++p == '\t') 3045909Seric continue; 3057231Seric q = p; 3067231Seric while (*p != '\0' && *p != '\t') 3077231Seric p++; 3087231Seric *p = '\0'; 30955012Seric expand(q, exbuf, &exbuf[sizeof exbuf], e); 31016915Seric rwp->r_rhs = prescan(exbuf, '\t', pvpbuf); 3115909Seric if (rwp->r_rhs != NULL) 31257589Seric { 31357589Seric register char **ap; 31457589Seric 3155909Seric rwp->r_rhs = copyplist(rwp->r_rhs, TRUE); 31657589Seric 31757589Seric /* check no out-of-bounds replacements */ 31857589Seric nfuzzy += '0'; 31957589Seric for (ap = rwp->r_rhs; *ap != NULL; ap++) 32057589Seric { 321*58148Seric char *botch; 322*58148Seric 323*58148Seric botch = NULL; 324*58148Seric switch (**ap & 0377) 32557589Seric { 326*58148Seric case MATCHREPL: 327*58148Seric if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy) 328*58148Seric { 329*58148Seric syserr("replacement $%c out of bounds", 330*58148Seric (*ap)[1]); 331*58148Seric } 332*58148Seric break; 333*58148Seric 334*58148Seric case MATCHZANY: 335*58148Seric botch = "$*"; 336*58148Seric break; 337*58148Seric 338*58148Seric case MATCHANY: 339*58148Seric botch = "$+"; 340*58148Seric break; 341*58148Seric 342*58148Seric case MATCHONE: 343*58148Seric botch = "$-"; 344*58148Seric break; 345*58148Seric 346*58148Seric case MATCHCLASS: 347*58148Seric botch = "$="; 348*58148Seric break; 349*58148Seric 350*58148Seric case MATCHNCLASS: 351*58148Seric botch = "$~"; 352*58148Seric break; 35357589Seric } 354*58148Seric if (botch != NULL) 355*58148Seric syserr("Inappropriate use of %s on RHS", 356*58148Seric botch); 35757589Seric } 35857589Seric } 35956678Seric else 36056678Seric syserr("R line: null RHS"); 3613308Seric break; 3623308Seric 3634072Seric case 'S': /* select rewriting set */ 36457135Seric ruleset = atoi(&bp[1]); 3658056Seric if (ruleset >= MAXRWSETS || ruleset < 0) 3668056Seric { 3679381Seric syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS); 3688056Seric ruleset = 0; 3698056Seric } 3704072Seric rwp = NULL; 3714072Seric break; 3724072Seric 3733308Seric case 'D': /* macro definition */ 37457135Seric define(bp[1], newstr(munchstring(&bp[2])), e); 3753308Seric break; 3763308Seric 3773387Seric case 'H': /* required header line */ 37857135Seric (void) chompheader(&bp[1], TRUE, e); 3793387Seric break; 3803387Seric 3814061Seric case 'C': /* word class */ 3824432Seric case 'F': /* word class from file */ 3834432Seric /* read list of words from argument or file */ 38457135Seric if (bp[0] == 'F') 3854432Seric { 3864432Seric /* read from file */ 38758050Seric for (p = &bp[2]; 38858050Seric *p != '\0' && !(isascii(*p) && isspace(*p)); 38958050Seric p++) 3904432Seric continue; 3914432Seric if (*p == '\0') 3924432Seric p = "%s"; 3934432Seric else 3944432Seric { 3954432Seric *p = '\0'; 39658050Seric while (isascii(*++p) && isspace(*p)) 3974432Seric continue; 3984432Seric } 39957135Seric fileclass(bp[1], &bp[2], p, safe); 4004432Seric break; 4014432Seric } 4024061Seric 4034432Seric /* scan the list of words and set class for all */ 40457135Seric for (p = &bp[2]; *p != '\0'; ) 4054061Seric { 4064061Seric register char *wd; 4074061Seric char delim; 4084061Seric 40958050Seric while (*p != '\0' && isascii(*p) && isspace(*p)) 4104061Seric p++; 4114061Seric wd = p; 41258050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 4134061Seric p++; 4144061Seric delim = *p; 4154061Seric *p = '\0'; 4164061Seric if (wd[0] != '\0') 417*58148Seric { 418*58148Seric if (tTd(37, 2)) 419*58148Seric printf("setclass(%c, %s)\n", 420*58148Seric bp[1], wd); 42157135Seric setclass(bp[1], wd); 422*58148Seric } 4234061Seric *p = delim; 4244061Seric } 4254061Seric break; 4264061Seric 4274096Seric case 'M': /* define mailer */ 42857135Seric makemailer(&bp[1]); 4294096Seric break; 4304096Seric 4318252Seric case 'O': /* set option */ 43257135Seric setoption(bp[1], &bp[2], safe, FALSE); 4338252Seric break; 4348252Seric 4358252Seric case 'P': /* set precedence */ 4368252Seric if (NumPriorities >= MAXPRIORITIES) 4378252Seric { 4388547Seric toomany('P', MAXPRIORITIES); 4398252Seric break; 4408252Seric } 44157135Seric for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++) 4428252Seric continue; 4438252Seric if (*p == '\0') 4448252Seric goto badline; 4458252Seric *p = '\0'; 44657135Seric Priorities[NumPriorities].pri_name = newstr(&bp[1]); 4478252Seric Priorities[NumPriorities].pri_val = atoi(++p); 4488252Seric NumPriorities++; 4498252Seric break; 4508252Seric 4518547Seric case 'T': /* trusted user(s) */ 45257135Seric p = &bp[1]; 4538547Seric while (*p != '\0') 4548547Seric { 45558050Seric while (isascii(*p) && isspace(*p)) 4568547Seric p++; 4578547Seric q = p; 45858050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 4598547Seric p++; 4608547Seric if (*p != '\0') 4618547Seric *p++ = '\0'; 4628547Seric if (*q == '\0') 4638547Seric continue; 4648547Seric for (pv = TrustedUsers; *pv != NULL; pv++) 4658547Seric continue; 4668547Seric if (pv >= &TrustedUsers[MAXTRUST]) 4678547Seric { 4688547Seric toomany('T', MAXTRUST); 4698547Seric break; 4708547Seric } 4718547Seric *pv = newstr(q); 4728547Seric } 4738547Seric break; 4748547Seric 47552645Seric case 'V': /* configuration syntax version */ 47657135Seric ConfigLevel = atoi(&bp[1]); 47752645Seric break; 47852645Seric 47953654Seric case 'K': 48057135Seric makemapentry(&bp[1]); 48153654Seric break; 48253654Seric 4833308Seric default: 4844061Seric badline: 48557135Seric syserr("unknown control line \"%s\"", bp); 4863308Seric } 48757135Seric if (bp != buf) 48857135Seric free(bp); 4893308Seric } 49052637Seric if (ferror(cf)) 49152637Seric { 49252647Seric syserr("I/O read error", cfname); 49352637Seric exit(EX_OSFILE); 49452637Seric } 49552637Seric fclose(cf); 4969381Seric FileName = NULL; 49756836Seric 49857076Seric if (stab("host", ST_MAP, ST_FIND) == NULL) 49957076Seric { 50057076Seric /* user didn't initialize: set up host map */ 50157076Seric strcpy(buf, "host host"); 50257076Seric if (ConfigLevel >= 2) 50357076Seric strcat(buf, " -a."); 50457076Seric makemapentry(buf); 50557076Seric } 5064096Seric } 5074096Seric /* 5088547Seric ** TOOMANY -- signal too many of some option 5098547Seric ** 5108547Seric ** Parameters: 5118547Seric ** id -- the id of the error line 5128547Seric ** maxcnt -- the maximum possible values 5138547Seric ** 5148547Seric ** Returns: 5158547Seric ** none. 5168547Seric ** 5178547Seric ** Side Effects: 5188547Seric ** gives a syserr. 5198547Seric */ 5208547Seric 5218547Seric toomany(id, maxcnt) 5228547Seric char id; 5238547Seric int maxcnt; 5248547Seric { 5259381Seric syserr("too many %c lines, %d max", id, maxcnt); 5268547Seric } 5278547Seric /* 5284432Seric ** FILECLASS -- read members of a class from a file 5294432Seric ** 5304432Seric ** Parameters: 5314432Seric ** class -- class to define. 5324432Seric ** filename -- name of file to read. 5334432Seric ** fmt -- scanf string to use for match. 5344432Seric ** 5354432Seric ** Returns: 5364432Seric ** none 5374432Seric ** 5384432Seric ** Side Effects: 5394432Seric ** 5404432Seric ** puts all lines in filename that match a scanf into 5414432Seric ** the named class. 5424432Seric */ 5434432Seric 54454973Seric fileclass(class, filename, fmt, safe) 5454432Seric int class; 5464432Seric char *filename; 5474432Seric char *fmt; 54854973Seric bool safe; 5494432Seric { 55025808Seric FILE *f; 55154973Seric struct stat stbuf; 5524432Seric char buf[MAXLINE]; 5534432Seric 55454973Seric if (stat(filename, &stbuf) < 0) 55554973Seric { 55654973Seric syserr("fileclass: cannot stat %s", filename); 55754973Seric return; 55854973Seric } 55954973Seric if (!S_ISREG(stbuf.st_mode)) 56054973Seric { 56154973Seric syserr("fileclass: %s not a regular file", filename); 56254973Seric return; 56354973Seric } 56454973Seric if (!safe && access(filename, R_OK) < 0) 56554973Seric { 56654973Seric syserr("fileclass: access denied on %s", filename); 56754973Seric return; 56854973Seric } 56954973Seric f = fopen(filename, "r"); 5704432Seric if (f == NULL) 5714432Seric { 57254973Seric syserr("fileclass: cannot open %s", filename); 5734432Seric return; 5744432Seric } 5754432Seric 5764432Seric while (fgets(buf, sizeof buf, f) != NULL) 5774432Seric { 5784432Seric register STAB *s; 57925808Seric register char *p; 58025808Seric # ifdef SCANF 5814432Seric char wordbuf[MAXNAME+1]; 5824432Seric 5834432Seric if (sscanf(buf, fmt, wordbuf) != 1) 5844432Seric continue; 58525808Seric p = wordbuf; 58656795Seric # else /* SCANF */ 58725808Seric p = buf; 58856795Seric # endif /* SCANF */ 58925808Seric 59025808Seric /* 59125808Seric ** Break up the match into words. 59225808Seric */ 59325808Seric 59425808Seric while (*p != '\0') 59525808Seric { 59625808Seric register char *q; 59725808Seric 59825808Seric /* strip leading spaces */ 59958050Seric while (isascii(*p) && isspace(*p)) 60025808Seric p++; 60125808Seric if (*p == '\0') 60225808Seric break; 60325808Seric 60425808Seric /* find the end of the word */ 60525808Seric q = p; 60658050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 60725808Seric p++; 60825808Seric if (*p != '\0') 60925808Seric *p++ = '\0'; 61025808Seric 61125808Seric /* enter the word in the symbol table */ 61225808Seric s = stab(q, ST_CLASS, ST_ENTER); 61325808Seric setbitn(class, s->s_class); 61425808Seric } 6154432Seric } 6164432Seric 61754973Seric (void) fclose(f); 6184432Seric } 6194432Seric /* 6204096Seric ** MAKEMAILER -- define a new mailer. 6214096Seric ** 6224096Seric ** Parameters: 62310327Seric ** line -- description of mailer. This is in labeled 62410327Seric ** fields. The fields are: 62510327Seric ** P -- the path to the mailer 62610327Seric ** F -- the flags associated with the mailer 62710327Seric ** A -- the argv for this mailer 62810327Seric ** S -- the sender rewriting set 62910327Seric ** R -- the recipient rewriting set 63010327Seric ** E -- the eol string 63110327Seric ** The first word is the canonical name of the mailer. 6324096Seric ** 6334096Seric ** Returns: 6344096Seric ** none. 6354096Seric ** 6364096Seric ** Side Effects: 6374096Seric ** enters the mailer into the mailer table. 6384096Seric */ 6393308Seric 64021066Seric makemailer(line) 6414096Seric char *line; 6424096Seric { 6434096Seric register char *p; 6448067Seric register struct mailer *m; 6458067Seric register STAB *s; 6468067Seric int i; 64710327Seric char fcode; 64858020Seric auto char *endp; 6494096Seric extern int NextMailer; 65010327Seric extern char **makeargv(); 65110327Seric extern char *munchstring(); 65210327Seric extern char *DelimChar; 65310701Seric extern long atol(); 6544096Seric 65510327Seric /* allocate a mailer and set up defaults */ 65610327Seric m = (struct mailer *) xalloc(sizeof *m); 65710327Seric bzero((char *) m, sizeof *m); 65810327Seric m->m_eol = "\n"; 65910327Seric 66010327Seric /* collect the mailer name */ 66158050Seric for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++) 66210327Seric continue; 66310327Seric if (*p != '\0') 66410327Seric *p++ = '\0'; 66510327Seric m->m_name = newstr(line); 66610327Seric 66710327Seric /* now scan through and assign info from the fields */ 66810327Seric while (*p != '\0') 66910327Seric { 67058050Seric while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p)))) 67110327Seric p++; 67210327Seric 67310327Seric /* p now points to field code */ 67410327Seric fcode = *p; 67510327Seric while (*p != '\0' && *p != '=' && *p != ',') 67610327Seric p++; 67710327Seric if (*p++ != '=') 67810327Seric { 67952637Seric syserr("mailer %s: `=' expected", m->m_name); 68010327Seric return; 68110327Seric } 68258050Seric while (isascii(*p) && isspace(*p)) 68310327Seric p++; 68410327Seric 68510327Seric /* p now points to the field body */ 68610327Seric p = munchstring(p); 68710327Seric 68810327Seric /* install the field into the mailer struct */ 68910327Seric switch (fcode) 69010327Seric { 69110327Seric case 'P': /* pathname */ 69210327Seric m->m_mailer = newstr(p); 69310327Seric break; 69410327Seric 69510327Seric case 'F': /* flags */ 69610687Seric for (; *p != '\0'; p++) 69758050Seric if (!(isascii(*p) && isspace(*p))) 69852637Seric setbitn(*p, m->m_flags); 69910327Seric break; 70010327Seric 70110327Seric case 'S': /* sender rewriting ruleset */ 70210327Seric case 'R': /* recipient rewriting ruleset */ 70358020Seric i = strtol(p, &endp, 10); 70410327Seric if (i < 0 || i >= MAXRWSETS) 70510327Seric { 70610327Seric syserr("invalid rewrite set, %d max", MAXRWSETS); 70710327Seric return; 70810327Seric } 70910327Seric if (fcode == 'S') 71058020Seric m->m_sh_rwset = m->m_se_rwset = i; 71110327Seric else 71258020Seric m->m_rh_rwset = m->m_re_rwset = i; 71358020Seric 71458020Seric p = endp; 71558020Seric if (*p == '/') 71658020Seric { 71758020Seric i = strtol(p, NULL, 10); 71858020Seric if (i < 0 || i >= MAXRWSETS) 71958020Seric { 72058020Seric syserr("invalid rewrite set, %d max", 72158020Seric MAXRWSETS); 72258020Seric return; 72358020Seric } 72458020Seric if (fcode == 'S') 72558020Seric m->m_sh_rwset = i; 72658020Seric else 72758020Seric m->m_rh_rwset = i; 72858020Seric } 72910327Seric break; 73010327Seric 73110327Seric case 'E': /* end of line string */ 73210327Seric m->m_eol = newstr(p); 73310327Seric break; 73410327Seric 73510327Seric case 'A': /* argument vector */ 73610327Seric m->m_argv = makeargv(p); 73710327Seric break; 73810701Seric 73910701Seric case 'M': /* maximum message size */ 74010701Seric m->m_maxsize = atol(p); 74110701Seric break; 74252106Seric 74352106Seric case 'L': /* maximum line length */ 74452106Seric m->m_linelimit = atoi(p); 74552106Seric break; 74610327Seric } 74710327Seric 74810327Seric p = DelimChar; 74910327Seric } 75010327Seric 75152106Seric /* do some heuristic cleanup for back compatibility */ 75252106Seric if (bitnset(M_LIMITS, m->m_flags)) 75352106Seric { 75452106Seric if (m->m_linelimit == 0) 75552106Seric m->m_linelimit = SMTPLINELIM; 75655418Seric if (ConfigLevel < 2) 75752106Seric setbitn(M_7BITS, m->m_flags); 75852106Seric } 75952106Seric 7604096Seric if (NextMailer >= MAXMAILERS) 7614096Seric { 7629381Seric syserr("too many mailers defined (%d max)", MAXMAILERS); 7634096Seric return; 7644096Seric } 76557402Seric 76610327Seric s = stab(m->m_name, ST_MAILER, ST_ENTER); 76757402Seric if (s->s_mailer != NULL) 76857402Seric { 76957402Seric i = s->s_mailer->m_mno; 77057402Seric free(s->s_mailer); 77157402Seric } 77257402Seric else 77357402Seric { 77457402Seric i = NextMailer++; 77557402Seric } 77657402Seric Mailer[i] = s->s_mailer = m; 77757454Seric m->m_mno = i; 77810327Seric } 77910327Seric /* 78010327Seric ** MUNCHSTRING -- translate a string into internal form. 78110327Seric ** 78210327Seric ** Parameters: 78310327Seric ** p -- the string to munch. 78410327Seric ** 78510327Seric ** Returns: 78610327Seric ** the munched string. 78710327Seric ** 78810327Seric ** Side Effects: 78910327Seric ** Sets "DelimChar" to point to the string that caused us 79010327Seric ** to stop. 79110327Seric */ 7924096Seric 79310327Seric char * 79410327Seric munchstring(p) 79510327Seric register char *p; 79610327Seric { 79710327Seric register char *q; 79810327Seric bool backslash = FALSE; 79910327Seric bool quotemode = FALSE; 80010327Seric static char buf[MAXLINE]; 80110327Seric extern char *DelimChar; 8024096Seric 80310327Seric for (q = buf; *p != '\0'; p++) 8044096Seric { 80510327Seric if (backslash) 80610327Seric { 80710327Seric /* everything is roughly literal */ 80810357Seric backslash = FALSE; 80910327Seric switch (*p) 81010327Seric { 81110327Seric case 'r': /* carriage return */ 81210327Seric *q++ = '\r'; 81310327Seric continue; 81410327Seric 81510327Seric case 'n': /* newline */ 81610327Seric *q++ = '\n'; 81710327Seric continue; 81810327Seric 81910327Seric case 'f': /* form feed */ 82010327Seric *q++ = '\f'; 82110327Seric continue; 82210327Seric 82310327Seric case 'b': /* backspace */ 82410327Seric *q++ = '\b'; 82510327Seric continue; 82610327Seric } 82710327Seric *q++ = *p; 82810327Seric } 82910327Seric else 83010327Seric { 83110327Seric if (*p == '\\') 83210327Seric backslash = TRUE; 83310327Seric else if (*p == '"') 83410327Seric quotemode = !quotemode; 83510327Seric else if (quotemode || *p != ',') 83610327Seric *q++ = *p; 83710327Seric else 83810327Seric break; 83910327Seric } 8404096Seric } 8414096Seric 84210327Seric DelimChar = p; 84310327Seric *q++ = '\0'; 84410327Seric return (buf); 84510327Seric } 84610327Seric /* 84710327Seric ** MAKEARGV -- break up a string into words 84810327Seric ** 84910327Seric ** Parameters: 85010327Seric ** p -- the string to break up. 85110327Seric ** 85210327Seric ** Returns: 85310327Seric ** a char **argv (dynamically allocated) 85410327Seric ** 85510327Seric ** Side Effects: 85610327Seric ** munges p. 85710327Seric */ 8584096Seric 85910327Seric char ** 86010327Seric makeargv(p) 86110327Seric register char *p; 86210327Seric { 86310327Seric char *q; 86410327Seric int i; 86510327Seric char **avp; 86610327Seric char *argv[MAXPV + 1]; 86710327Seric 86810327Seric /* take apart the words */ 86910327Seric i = 0; 87010327Seric while (*p != '\0' && i < MAXPV) 8714096Seric { 87210327Seric q = p; 87358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 87410327Seric p++; 87558050Seric while (isascii(*p) && isspace(*p)) 87610327Seric *p++ = '\0'; 87710327Seric argv[i++] = newstr(q); 8784096Seric } 87910327Seric argv[i++] = NULL; 8804096Seric 88110327Seric /* now make a copy of the argv */ 88210327Seric avp = (char **) xalloc(sizeof *avp * i); 88316893Seric bcopy((char *) argv, (char *) avp, sizeof *avp * i); 88410327Seric 88510327Seric return (avp); 8863308Seric } 8873308Seric /* 8883308Seric ** PRINTRULES -- print rewrite rules (for debugging) 8893308Seric ** 8903308Seric ** Parameters: 8913308Seric ** none. 8923308Seric ** 8933308Seric ** Returns: 8943308Seric ** none. 8953308Seric ** 8963308Seric ** Side Effects: 8973308Seric ** prints rewrite rules. 8983308Seric */ 8993308Seric 9003308Seric printrules() 9013308Seric { 9023308Seric register struct rewrite *rwp; 9034072Seric register int ruleset; 9043308Seric 9054072Seric for (ruleset = 0; ruleset < 10; ruleset++) 9063308Seric { 9074072Seric if (RewriteRules[ruleset] == NULL) 9084072Seric continue; 9098067Seric printf("\n----Rule Set %d:", ruleset); 9103308Seric 9114072Seric for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next) 9123308Seric { 9138067Seric printf("\nLHS:"); 9148067Seric printav(rwp->r_lhs); 9158067Seric printf("RHS:"); 9168067Seric printav(rwp->r_rhs); 9173308Seric } 9183308Seric } 9193308Seric } 9204319Seric 9214096Seric /* 9228256Seric ** SETOPTION -- set global processing option 9238256Seric ** 9248256Seric ** Parameters: 9258256Seric ** opt -- option name. 9268256Seric ** val -- option value (as a text string). 92721755Seric ** safe -- set if this came from a configuration file. 92821755Seric ** Some options (if set from the command line) will 92921755Seric ** reset the user id to avoid security problems. 9308269Seric ** sticky -- if set, don't let other setoptions override 9318269Seric ** this value. 9328256Seric ** 9338256Seric ** Returns: 9348256Seric ** none. 9358256Seric ** 9368256Seric ** Side Effects: 9378256Seric ** Sets options as implied by the arguments. 9388256Seric */ 9398256Seric 94010687Seric static BITMAP StickyOpt; /* set if option is stuck */ 9418269Seric 94257207Seric 94357207Seric #ifdef NAMED_BIND 94457207Seric 94557207Seric struct resolverflags 94657207Seric { 94757207Seric char *rf_name; /* name of the flag */ 94857207Seric long rf_bits; /* bits to set/clear */ 94957207Seric } ResolverFlags[] = 95057207Seric { 95157207Seric "debug", RES_DEBUG, 95257207Seric "aaonly", RES_AAONLY, 95357207Seric "usevc", RES_USEVC, 95457207Seric "primary", RES_PRIMARY, 95557207Seric "igntc", RES_IGNTC, 95657207Seric "recurse", RES_RECURSE, 95757207Seric "defnames", RES_DEFNAMES, 95857207Seric "stayopen", RES_STAYOPEN, 95957207Seric "dnsrch", RES_DNSRCH, 96057207Seric NULL, 0 96157207Seric }; 96257207Seric 96357207Seric #endif 96457207Seric 96521755Seric setoption(opt, val, safe, sticky) 9668256Seric char opt; 9678256Seric char *val; 96821755Seric bool safe; 9698269Seric bool sticky; 9708256Seric { 97157207Seric register char *p; 9728265Seric extern bool atobool(); 97312633Seric extern time_t convtime(); 97414879Seric extern int QueueLA; 97514879Seric extern int RefuseLA; 97617474Seric extern bool trusteduser(); 97717474Seric extern char *username(); 9788256Seric 9798256Seric if (tTd(37, 1)) 9809341Seric printf("setoption %c=%s", opt, val); 9818256Seric 9828256Seric /* 9838269Seric ** See if this option is preset for us. 9848256Seric */ 9858256Seric 98610687Seric if (bitnset(opt, StickyOpt)) 9878269Seric { 9889341Seric if (tTd(37, 1)) 9899341Seric printf(" (ignored)\n"); 9908269Seric return; 9918269Seric } 9928269Seric 99321755Seric /* 99421755Seric ** Check to see if this option can be specified by this user. 99521755Seric */ 99621755Seric 99736238Skarels if (!safe && getuid() == 0) 99821755Seric safe = TRUE; 99958082Seric if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL) 100021755Seric { 100139111Srick if (opt != 'M' || (val[0] != 'r' && val[0] != 's')) 100221755Seric { 100336582Sbostic if (tTd(37, 1)) 100436582Sbostic printf(" (unsafe)"); 100536582Sbostic if (getuid() != geteuid()) 100636582Sbostic { 100751210Seric if (tTd(37, 1)) 100851210Seric printf("(Resetting uid)"); 100936582Sbostic (void) setgid(getgid()); 101036582Sbostic (void) setuid(getuid()); 101136582Sbostic } 101221755Seric } 101321755Seric } 101451210Seric if (tTd(37, 1)) 101517985Seric printf("\n"); 10168269Seric 10178256Seric switch (opt) 10188256Seric { 101952106Seric case '8': /* allow eight-bit input */ 102052106Seric EightBit = atobool(val); 102152106Seric break; 102252106Seric 10238256Seric case 'A': /* set default alias file */ 10249381Seric if (val[0] == '\0') 10258269Seric AliasFile = "aliases"; 10269381Seric else 10279381Seric AliasFile = newstr(val); 10288256Seric break; 10298256Seric 103017474Seric case 'a': /* look N minutes for "@:@" in alias file */ 103117474Seric if (val[0] == '\0') 103217474Seric SafeAlias = 5; 103317474Seric else 103417474Seric SafeAlias = atoi(val); 103517474Seric break; 103617474Seric 103716843Seric case 'B': /* substitution for blank character */ 103816843Seric SpaceSub = val[0]; 103916843Seric if (SpaceSub == '\0') 104016843Seric SpaceSub = ' '; 104116843Seric break; 104216843Seric 104358082Seric case 'b': /* minimum number of blocks free on queue fs */ 104458082Seric MinBlocksFree = atol(val); 104558082Seric break; 104658082Seric 10479284Seric case 'c': /* don't connect to "expensive" mailers */ 10489381Seric NoConnect = atobool(val); 10499284Seric break; 10509284Seric 105151305Seric case 'C': /* checkpoint every N addresses */ 105251305Seric CheckpointInterval = atoi(val); 105324944Seric break; 105424944Seric 10559284Seric case 'd': /* delivery mode */ 10569284Seric switch (*val) 10578269Seric { 10589284Seric case '\0': 10599284Seric SendMode = SM_DELIVER; 10608269Seric break; 10618269Seric 106210755Seric case SM_QUEUE: /* queue only */ 106310755Seric #ifndef QUEUE 106410755Seric syserr("need QUEUE to set -odqueue"); 106556795Seric #endif /* QUEUE */ 106610755Seric /* fall through..... */ 106710755Seric 10689284Seric case SM_DELIVER: /* do everything */ 10699284Seric case SM_FORK: /* fork after verification */ 10709284Seric SendMode = *val; 10718269Seric break; 10728269Seric 10738269Seric default: 10749284Seric syserr("Unknown delivery mode %c", *val); 10758269Seric exit(EX_USAGE); 10768269Seric } 10778269Seric break; 10788269Seric 10799146Seric case 'D': /* rebuild alias database as needed */ 10809381Seric AutoRebuild = atobool(val); 10819146Seric break; 10829146Seric 108355372Seric case 'E': /* error message header/header file */ 108455379Seric if (*val != '\0') 108555379Seric ErrMsgFile = newstr(val); 108655372Seric break; 108755372Seric 10888269Seric case 'e': /* set error processing mode */ 10898269Seric switch (*val) 10908269Seric { 10919381Seric case EM_QUIET: /* be silent about it */ 10929381Seric case EM_MAIL: /* mail back */ 10939381Seric case EM_BERKNET: /* do berknet error processing */ 10949381Seric case EM_WRITE: /* write back (or mail) */ 10958269Seric HoldErrs = TRUE; 10969381Seric /* fall through... */ 10978269Seric 10989381Seric case EM_PRINT: /* print errors normally (default) */ 10999381Seric ErrorMode = *val; 11008269Seric break; 11018269Seric } 11028269Seric break; 11038269Seric 11049049Seric case 'F': /* file mode */ 110517975Seric FileMode = atooct(val) & 0777; 11069049Seric break; 11079049Seric 11088269Seric case 'f': /* save Unix-style From lines on front */ 11099381Seric SaveFrom = atobool(val); 11108269Seric break; 11118269Seric 111253735Seric case 'G': /* match recipients against GECOS field */ 111353735Seric MatchGecos = atobool(val); 111453735Seric break; 111553735Seric 11168256Seric case 'g': /* default gid */ 111717474Seric DefGid = atoi(val); 11188256Seric break; 11198256Seric 11208256Seric case 'H': /* help file */ 11219381Seric if (val[0] == '\0') 11228269Seric HelpFile = "sendmail.hf"; 11239381Seric else 11249381Seric HelpFile = newstr(val); 11258256Seric break; 11268256Seric 112751305Seric case 'h': /* maximum hop count */ 112851305Seric MaxHopCount = atoi(val); 112951305Seric break; 113051305Seric 113135651Seric case 'I': /* use internet domain name server */ 113257207Seric #ifdef NAMED_BIND 113357207Seric UseNameServer = TRUE; 113457207Seric for (p = val; *p != 0; ) 113557207Seric { 113657207Seric bool clearmode; 113757207Seric char *q; 113857207Seric struct resolverflags *rfp; 113957207Seric 114057207Seric while (*p == ' ') 114157207Seric p++; 114257207Seric if (*p == '\0') 114357207Seric break; 114457207Seric clearmode = FALSE; 114557207Seric if (*p == '-') 114657207Seric clearmode = TRUE; 114757207Seric else if (*p != '+') 114857207Seric p--; 114957207Seric p++; 115057207Seric q = p; 115158050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 115257207Seric p++; 115357207Seric if (*p != '\0') 115457207Seric *p++ = '\0'; 115557207Seric for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++) 115657207Seric { 115757207Seric if (strcasecmp(q, rfp->rf_name) == 0) 115857207Seric break; 115957207Seric } 116057207Seric if (clearmode) 116157207Seric _res.options &= ~rfp->rf_bits; 116257207Seric else 116357207Seric _res.options |= rfp->rf_bits; 116457207Seric } 116557207Seric if (tTd(8, 2)) 116657207Seric printf("_res.options = %x\n", _res.options); 116757207Seric #else 116857207Seric usrerr("name server (I option) specified but BIND not compiled in"); 116957207Seric #endif 117035651Seric break; 117135651Seric 11728269Seric case 'i': /* ignore dot lines in message */ 11739381Seric IgnrDot = atobool(val); 11748269Seric break; 11758269Seric 117657136Seric case 'J': /* .forward search path */ 117757136Seric ForwardPath = newstr(val); 117857136Seric break; 117957136Seric 118054967Seric case 'k': /* connection cache size */ 118154967Seric MaxMciCache = atoi(val); 118256215Seric if (MaxMciCache < 0) 118356215Seric MaxMciCache = 0; 118454967Seric break; 118554967Seric 118654967Seric case 'K': /* connection cache timeout */ 118754967Seric MciCacheTimeout = convtime(val); 118854967Seric break; 118954967Seric 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 12078269Seric case 'o': /* assume old style headers */ 12089381Seric if (atobool(val)) 12099341Seric CurEnv->e_flags |= EF_OLDSTYLE; 12109341Seric else 12119341Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 12128269Seric break; 12138269Seric 121458082Seric case 'p': /* select privacy level */ 121558082Seric p = val; 121658082Seric for (;;) 121758082Seric { 121858082Seric register struct prival *pv; 121958082Seric extern struct prival PrivacyValues[]; 122058082Seric 122158082Seric while (isascii(*p) && (isspace(*p) || ispunct(*p))) 122258082Seric p++; 122358082Seric if (*p == '\0') 122458082Seric break; 122558082Seric val = p; 122658082Seric while (isascii(*p) && isalnum(*p)) 122758082Seric p++; 122858082Seric if (*p != '\0') 122958082Seric *p++ = '\0'; 123058082Seric 123158082Seric for (pv = PrivacyValues; pv->pv_name != NULL; pv++) 123258082Seric { 123358082Seric if (strcasecmp(val, pv->pv_name) == 0) 123458082Seric break; 123558082Seric } 123658082Seric PrivacyFlags |= pv->pv_flag; 123758082Seric } 123858082Seric break; 123958082Seric 124024944Seric case 'P': /* postmaster copy address for returned mail */ 124124944Seric PostMasterCopy = newstr(val); 124224944Seric break; 124324944Seric 124424944Seric case 'q': /* slope of queue only function */ 124524944Seric QueueFactor = atoi(val); 124624944Seric break; 124724944Seric 12488256Seric case 'Q': /* queue directory */ 12499381Seric if (val[0] == '\0') 12508269Seric QueueDir = "mqueue"; 12519381Seric else 12529381Seric QueueDir = newstr(val); 12538256Seric break; 12548256Seric 1255*58148Seric case 'R': /* don't prune routes */ 1256*58148Seric DontPruneRoutes = atobool(val); 1257*58148Seric break; 1258*58148Seric 12598256Seric case 'r': /* read timeout */ 126058112Seric settimeouts(val); 12618256Seric break; 12628256Seric 12638256Seric case 'S': /* status file */ 12649381Seric if (val[0] == '\0') 12658269Seric StatFile = "sendmail.st"; 12669381Seric else 12679381Seric StatFile = newstr(val); 12688256Seric break; 12698256Seric 12708265Seric case 's': /* be super safe, even if expensive */ 12719381Seric SuperSafe = atobool(val); 12728256Seric break; 12738256Seric 12748256Seric case 'T': /* queue timeout */ 12759381Seric TimeOut = convtime(val); 127654967Seric break; 12778256Seric 12788265Seric case 't': /* time zone name */ 127952106Seric TimeZoneSpec = newstr(val); 12808265Seric break; 12818265Seric 128250556Seric case 'U': /* location of user database */ 128351360Seric UdbSpec = newstr(val); 128450556Seric break; 128550556Seric 12868256Seric case 'u': /* set default uid */ 128717474Seric DefUid = atoi(val); 128840973Sbostic setdefuser(); 12898256Seric break; 12908256Seric 12918269Seric case 'v': /* run in verbose mode */ 12929381Seric Verbose = atobool(val); 12938256Seric break; 12948256Seric 129514879Seric case 'x': /* load avg at which to auto-queue msgs */ 129614879Seric QueueLA = atoi(val); 129714879Seric break; 129814879Seric 129914879Seric case 'X': /* load avg at which to auto-reject connections */ 130014879Seric RefuseLA = atoi(val); 130114879Seric break; 130214879Seric 130324981Seric case 'y': /* work recipient factor */ 130424981Seric WkRecipFact = atoi(val); 130524981Seric break; 130624981Seric 130724981Seric case 'Y': /* fork jobs during queue runs */ 130824952Seric ForkQueueRuns = atobool(val); 130924952Seric break; 131024952Seric 131124981Seric case 'z': /* work message class factor */ 131224981Seric WkClassFact = atoi(val); 131324981Seric break; 131424981Seric 131524981Seric case 'Z': /* work time factor */ 131624981Seric WkTimeFact = atoi(val); 131724981Seric break; 131824981Seric 13198256Seric default: 13208256Seric break; 13218256Seric } 132216878Seric if (sticky) 132316878Seric setbitn(opt, StickyOpt); 13249188Seric return; 13258256Seric } 132610687Seric /* 132710687Seric ** SETCLASS -- set a word into a class 132810687Seric ** 132910687Seric ** Parameters: 133010687Seric ** class -- the class to put the word in. 133110687Seric ** word -- the word to enter 133210687Seric ** 133310687Seric ** Returns: 133410687Seric ** none. 133510687Seric ** 133610687Seric ** Side Effects: 133710687Seric ** puts the word into the symbol table. 133810687Seric */ 133910687Seric 134010687Seric setclass(class, word) 134110687Seric int class; 134210687Seric char *word; 134310687Seric { 134410687Seric register STAB *s; 134510687Seric 134657943Seric if (tTd(37, 8)) 134757943Seric printf("%s added to class %c\n", word, class); 134810687Seric s = stab(word, ST_CLASS, ST_ENTER); 134910687Seric setbitn(class, s->s_class); 135010687Seric } 135153654Seric /* 135253654Seric ** MAKEMAPENTRY -- create a map entry 135353654Seric ** 135453654Seric ** Parameters: 135553654Seric ** line -- the config file line 135653654Seric ** 135753654Seric ** Returns: 135853654Seric ** TRUE if it successfully entered the map entry. 135953654Seric ** FALSE otherwise (usually syntax error). 136053654Seric ** 136153654Seric ** Side Effects: 136253654Seric ** Enters the map into the dictionary. 136353654Seric */ 136453654Seric 136553654Seric void 136653654Seric makemapentry(line) 136753654Seric char *line; 136853654Seric { 136953654Seric register char *p; 137053654Seric char *mapname; 137153654Seric char *classname; 137253654Seric register STAB *map; 137353654Seric STAB *class; 137453654Seric 137558050Seric for (p = line; isascii(*p) && isspace(*p); p++) 137653654Seric continue; 137758050Seric if (!(isascii(*p) && isalnum(*p))) 137853654Seric { 137953654Seric syserr("readcf: config K line: no map name"); 138053654Seric return; 138153654Seric } 138253654Seric 138353654Seric mapname = p; 138458050Seric while (isascii(*++p) && isalnum(*p)) 138553654Seric continue; 138653654Seric if (*p != '\0') 138753654Seric *p++ = '\0'; 138858050Seric while (isascii(*p) && isspace(*p)) 138953654Seric p++; 139058050Seric if (!(isascii(*p) && isalnum(*p))) 139153654Seric { 139253654Seric syserr("readcf: config K line, map %s: no map class", mapname); 139353654Seric return; 139453654Seric } 139553654Seric classname = p; 139658050Seric while (isascii(*++p) && isalnum(*p)) 139753654Seric continue; 139853654Seric if (*p != '\0') 139953654Seric *p++ = '\0'; 140058050Seric while (isascii(*p) && isspace(*p)) 140153654Seric p++; 140253654Seric 140353654Seric /* look up the class */ 140453654Seric class = stab(classname, ST_MAPCLASS, ST_FIND); 140553654Seric if (class == NULL) 140653654Seric { 140753654Seric syserr("readcf: map %s: class %s not available", mapname, classname); 140853654Seric return; 140953654Seric } 141053654Seric 141153654Seric /* enter the map */ 141253654Seric map = stab(mapname, ST_MAP, ST_ENTER); 141353654Seric map->s_map.map_class = &class->s_mapclass; 141453654Seric 141556823Seric if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p)) 141653654Seric map->s_map.map_flags |= MF_VALID; 141753654Seric } 141858112Seric /* 141958112Seric ** SETTIMEOUTS -- parse and set timeout values 142058112Seric ** 142158112Seric ** Parameters: 142258112Seric ** val -- a pointer to the values. If NULL, do initial 142358112Seric ** settings. 142458112Seric ** 142558112Seric ** Returns: 142658112Seric ** none. 142758112Seric ** 142858112Seric ** Side Effects: 142958112Seric ** Initializes the TimeOuts structure 143058112Seric */ 143158112Seric 143258112Seric #define MINUTES * 60 143358112Seric #define HOUR * 3600 143458112Seric 143558112Seric settimeouts(val) 143658112Seric register char *val; 143758112Seric { 143858112Seric register char *p; 143958112Seric 144058112Seric if (val == NULL) 144158112Seric { 144258112Seric TimeOuts.to_initial = (time_t) 5 MINUTES; 144358112Seric TimeOuts.to_helo = (time_t) 5 MINUTES; 144458112Seric TimeOuts.to_mail = (time_t) 10 MINUTES; 144558112Seric TimeOuts.to_rcpt = (time_t) 1 HOUR; 144658112Seric TimeOuts.to_datainit = (time_t) 5 MINUTES; 144758112Seric TimeOuts.to_datablock = (time_t) 1 HOUR; 144858112Seric TimeOuts.to_datafinal = (time_t) 1 HOUR; 144958112Seric TimeOuts.to_rset = (time_t) 5 MINUTES; 145058112Seric TimeOuts.to_quit = (time_t) 2 MINUTES; 145158112Seric TimeOuts.to_nextcommand = (time_t) 1 HOUR; 145258112Seric TimeOuts.to_miscshort = (time_t) 2 MINUTES; 145358112Seric return; 145458112Seric } 145558112Seric 145658112Seric for (;; val = p) 145758112Seric { 145858112Seric while (isascii(*val) && isspace(*val)) 145958112Seric val++; 146058112Seric if (*val == '\0') 146158112Seric break; 146258112Seric for (p = val; *p != '\0' && *p != ','; p++) 146358112Seric continue; 146458112Seric if (*p != '\0') 146558112Seric *p++ = '\0'; 146658112Seric 146758112Seric if (isascii(*val) && isdigit(*val)) 146858112Seric { 146958112Seric /* old syntax -- set everything */ 147058112Seric TimeOuts.to_mail = convtime(val); 147158112Seric TimeOuts.to_rcpt = TimeOuts.to_mail; 147258112Seric TimeOuts.to_datainit = TimeOuts.to_mail; 147358112Seric TimeOuts.to_datablock = TimeOuts.to_mail; 147458112Seric TimeOuts.to_datafinal = TimeOuts.to_mail; 147558112Seric TimeOuts.to_nextcommand = TimeOuts.to_mail; 147658112Seric continue; 147758112Seric } 147858112Seric else 147958112Seric { 148058112Seric register char *q = strchr(val, '='); 148158112Seric time_t to; 148258112Seric 148358112Seric if (q == NULL) 148458112Seric { 148558112Seric /* syntax error */ 148658112Seric continue; 148758112Seric } 148858112Seric *q++ = '\0'; 148958112Seric to = convtime(q); 149058112Seric 149158112Seric if (strcasecmp(val, "initial") == 0) 149258112Seric TimeOuts.to_initial = to; 149358112Seric else if (strcasecmp(val, "mail") == 0) 149458112Seric TimeOuts.to_mail = to; 149558112Seric else if (strcasecmp(val, "rcpt") == 0) 149658112Seric TimeOuts.to_rcpt = to; 149758112Seric else if (strcasecmp(val, "datainit") == 0) 149858112Seric TimeOuts.to_datainit = to; 149958112Seric else if (strcasecmp(val, "datablock") == 0) 150058112Seric TimeOuts.to_datablock = to; 150158112Seric else if (strcasecmp(val, "datafinal") == 0) 150258112Seric TimeOuts.to_datafinal = to; 150358112Seric else if (strcasecmp(val, "command") == 0) 150458112Seric TimeOuts.to_nextcommand = to; 150558112Seric else if (strcasecmp(val, "rset") == 0) 150658112Seric TimeOuts.to_rset = to; 150758112Seric else if (strcasecmp(val, "helo") == 0) 150858112Seric TimeOuts.to_helo = to; 150958112Seric else if (strcasecmp(val, "quit") == 0) 151058112Seric TimeOuts.to_quit = to; 151158112Seric else if (strcasecmp(val, "misc") == 0) 151258112Seric TimeOuts.to_miscshort = to; 151358112Seric else 151458112Seric syserr("settimeouts: invalid timeout %s", val); 151558112Seric } 151658112Seric } 151758112Seric } 1518