122694Sdist /* 235073Sbostic * Copyright (c) 1983 Eric P. Allman 362522Sbostic * Copyright (c) 1988, 1993 462522Sbostic * The Regents of the University of California. All rights reserved. 533728Sbostic * 642824Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822694Sdist 958332Seric # include "sendmail.h" 1050577Seric # include <pwd.h> 1156766Seric 1233728Sbostic #ifndef lint 13*65091Seric static char sccsid[] = "@(#)alias.c 8.21 (Berkeley) 12/11/93"; 1433728Sbostic #endif /* not lint */ 1559673Seric 1659673Seric 1760537Seric MAP *AliasDB[MAXALIASDB + 1]; /* actual database list */ 1859673Seric int NAliasDBs; /* number of alias databases */ 1959673Seric /* 20292Seric ** ALIAS -- Compute aliases. 21292Seric ** 229368Seric ** Scans the alias file for an alias for the given address. 239368Seric ** If found, it arranges to deliver to the alias list instead. 249368Seric ** Uses libdbm database if -DDBM. 25292Seric ** 26292Seric ** Parameters: 274097Seric ** a -- address to alias. 284999Seric ** sendq -- a pointer to the head of the send queue 294999Seric ** to put the aliases in. 3058092Seric ** e -- the current envelope. 31292Seric ** 32292Seric ** Returns: 33292Seric ** none 34292Seric ** 35292Seric ** Side Effects: 363185Seric ** Aliases found are expanded. 37292Seric ** 38292Seric ** Deficiencies: 39292Seric ** It should complain about names that are aliased to 40292Seric ** nothing. 41292Seric */ 42292Seric 4355012Seric alias(a, sendq, e) 444097Seric register ADDRESS *a; 454999Seric ADDRESS **sendq; 4655012Seric register ENVELOPE *e; 47292Seric { 484081Seric register char *p; 4958082Seric int naliases; 5058170Seric char *owner; 5158170Seric char obuf[MAXNAME + 6]; 525701Seric extern char *aliaslookup(); 53292Seric 547671Seric if (tTd(27, 1)) 554098Seric printf("alias(%s)\n", a->q_paddr); 56292Seric 574098Seric /* don't realias already aliased names */ 5858680Seric if (bitset(QDONTSEND|QBADADDR|QVERIFIED, a->q_flags)) 594098Seric return; 604098Seric 6159673Seric if (NoAlias) 6259673Seric return; 6359673Seric 6455012Seric e->e_to = a->q_paddr; 654098Seric 664314Seric /* 674314Seric ** Look up this name 684314Seric */ 694314Seric 7059673Seric p = aliaslookup(a->q_user, e); 714098Seric if (p == NULL) 724098Seric return; 73292Seric 74292Seric /* 754098Seric ** Match on Alias. 764098Seric ** Deliver to the target list. 771515Seric */ 781515Seric 797671Seric if (tTd(27, 1)) 804098Seric printf("%s (%s, %s) aliased to %s\n", 814098Seric a->q_paddr, a->q_host, a->q_user, p); 8258092Seric if (bitset(EF_VRFYONLY, e->e_flags)) 8358154Seric { 8458154Seric a->q_flags |= QVERIFIED; 8558884Seric e->e_nrcpts++; 8658092Seric return; 8758154Seric } 8858154Seric message("aliased to %s", p); 8957977Seric #ifdef LOG 9058020Seric if (LogLevel > 9) 9157977Seric syslog(LOG_INFO, "%s: alias %s => %s", e->e_id, a->q_paddr, p); 9257977Seric #endif 9358082Seric a->q_flags &= ~QSELFREF; 944098Seric AliasLevel++; 9558082Seric naliases = sendtolist(p, a, sendq, e); 964098Seric AliasLevel--; 9764301Seric if (!bitset(QSELFREF, a->q_flags)) 9858065Seric { 9958065Seric if (tTd(27, 5)) 10058065Seric { 10158065Seric printf("alias: QDONTSEND "); 10258065Seric printaddr(a, FALSE); 10358065Seric } 10458065Seric a->q_flags |= QDONTSEND; 10558065Seric } 10658170Seric 10758170Seric /* 10858170Seric ** Look for owner of alias 10958170Seric */ 11058170Seric 11158170Seric (void) strcpy(obuf, "owner-"); 11258170Seric if (strncmp(a->q_user, "owner-", 6) == 0) 11358170Seric (void) strcat(obuf, "owner"); 11458170Seric else 11558170Seric (void) strcat(obuf, a->q_user); 11658170Seric if (!bitnset(M_USR_UPPER, a->q_mailer->m_flags)) 11758170Seric makelower(obuf); 11859673Seric owner = aliaslookup(obuf, e); 11958170Seric if (owner != NULL) 12058170Seric { 121*65091Seric if (strpbrk(owner, ",:/|\"") != NULL) 12258170Seric owner = obuf; 12358170Seric a->q_owner = newstr(owner); 12458170Seric } 1254098Seric } 1264098Seric /* 1275701Seric ** ALIASLOOKUP -- look up a name in the alias file. 1285701Seric ** 1295701Seric ** Parameters: 1305701Seric ** name -- the name to look up. 1315701Seric ** 1325701Seric ** Returns: 1335701Seric ** the value of name. 1345701Seric ** NULL if unknown. 1355701Seric ** 1365701Seric ** Side Effects: 1375701Seric ** none. 1385701Seric ** 1395701Seric ** Warnings: 1405701Seric ** The return value will be trashed across calls. 1415701Seric */ 1425701Seric 1435701Seric char * 14459673Seric aliaslookup(name, e) 1455701Seric char *name; 14659673Seric ENVELOPE *e; 1475701Seric { 14859673Seric register int dbno; 14960089Seric register MAP *map; 15059673Seric register char *p; 1515701Seric 15259673Seric for (dbno = 0; dbno < NAliasDBs; dbno++) 15359673Seric { 15460089Seric auto int stat; 15560089Seric 15660537Seric map = AliasDB[dbno]; 15760207Seric if (!bitset(MF_OPEN, map->map_mflags)) 15859673Seric continue; 15960207Seric p = (*map->map_class->map_lookup)(map, name, NULL, &stat); 16059673Seric if (p != NULL) 16159673Seric return p; 16259673Seric } 16359673Seric return NULL; 16459673Seric } 16559673Seric /* 16659673Seric ** SETALIAS -- set up an alias map 16759673Seric ** 16859673Seric ** Called when reading configuration file. 16959673Seric ** 17059673Seric ** Parameters: 17159673Seric ** spec -- the alias specification 17259673Seric ** 17359673Seric ** Returns: 17459673Seric ** none. 17559673Seric */ 17657381Seric 17759673Seric setalias(spec) 17859673Seric char *spec; 17959673Seric { 18059673Seric register char *p; 18160089Seric register MAP *map; 18259673Seric char *class; 18359673Seric STAB *s; 18459673Seric 18559697Seric if (tTd(27, 8)) 18659697Seric printf("setalias(%s)\n", spec); 18759697Seric 18859758Seric for (p = spec; p != NULL; ) 18951756Seric { 19060537Seric char aname[50]; 19160537Seric 19259758Seric while (isspace(*p)) 19359758Seric p++; 19460502Seric if (*p == '\0') 19559673Seric break; 19659673Seric spec = p; 19759673Seric 19859758Seric if (NAliasDBs >= MAXALIASDB) 19959758Seric { 20059758Seric syserr("Too many alias databases defined, %d max", MAXALIASDB); 20159758Seric return; 20259758Seric } 20360537Seric (void) sprintf(aname, "Alias%d", NAliasDBs); 20460537Seric s = stab(aname, ST_MAP, ST_ENTER); 20560537Seric map = &s->s_map; 20660537Seric AliasDB[NAliasDBs] = map; 20760089Seric bzero(map, sizeof *map); 20859758Seric 20959758Seric p = strpbrk(p, " ,/:"); 21059758Seric if (p != NULL && *p == ':') 21159758Seric { 21260089Seric /* map name */ 21359758Seric *p++ = '\0'; 21459758Seric class = spec; 21559758Seric spec = p; 21659758Seric } 21759758Seric else 21859758Seric { 21959758Seric class = "implicit"; 22060228Seric map->map_mflags = MF_OPTIONAL|MF_INCLNULL; 22159758Seric } 22259758Seric 22359758Seric /* find end of spec */ 22459758Seric if (p != NULL) 22559758Seric p = strchr(p, ','); 22659758Seric if (p != NULL) 22759758Seric *p++ = '\0'; 22859758Seric 22959758Seric /* look up class */ 23060089Seric s = stab(class, ST_MAPCLASS, ST_FIND); 23159758Seric if (s == NULL) 23259758Seric { 23359758Seric if (tTd(27, 1)) 23459758Seric printf("Unknown alias class %s\n", class); 23559758Seric } 23660207Seric else if (!bitset(MCF_ALIASOK, s->s_mapclass.map_cflags)) 23760207Seric { 23860207Seric syserr("setalias: map class %s can't handle aliases", 23960207Seric class); 24060207Seric } 24159758Seric else 24259758Seric { 24360207Seric map->map_class = &s->s_mapclass; 24460089Seric if (map->map_class->map_parse(map, spec)) 24560089Seric { 24660207Seric map->map_mflags |= MF_VALID|MF_ALIAS; 24760089Seric NAliasDBs++; 24860089Seric } 24959758Seric } 25059756Seric } 2515701Seric } 2525701Seric /* 25359673Seric ** ALIASWAIT -- wait for distinguished @:@ token to appear. 25459673Seric ** 25559673Seric ** This can decide to reopen or rebuild the alias file 25664718Seric ** 25764718Seric ** Parameters: 25864718Seric ** map -- a pointer to the map descriptor for this alias file. 25964718Seric ** ext -- the filename extension (e.g., ".db") for the 26064718Seric ** database file. 26164718Seric ** isopen -- if set, the database is already open, and we 26264718Seric ** should check for validity; otherwise, we are 26364718Seric ** just checking to see if it should be created. 26464718Seric ** 26564718Seric ** Returns: 26664718Seric ** TRUE -- if the database is open when we return. 26764718Seric ** FALSE -- if the database is closed when we return. 26859673Seric */ 26959673Seric 27064718Seric bool 27164718Seric aliaswait(map, ext, isopen) 27260089Seric MAP *map; 27360207Seric char *ext; 27464718Seric int isopen; 27559673Seric { 27664795Seric bool attimeout = FALSE; 27759673Seric time_t mtime; 27859673Seric struct stat stb; 27959673Seric char buf[MAXNAME]; 28059673Seric 28159697Seric if (tTd(27, 3)) 28260207Seric printf("aliaswait(%s:%s)\n", 28360207Seric map->map_class->map_cname, map->map_file); 28464648Seric if (bitset(MF_ALIASWAIT, map->map_mflags)) 28564795Seric return isopen; 28664648Seric map->map_mflags |= MF_ALIASWAIT; 28759697Seric 28864795Seric if (SafeAlias > 0) 28917471Seric { 29060089Seric auto int st; 29164795Seric time_t toolong = curtime() + SafeAlias; 29264795Seric unsigned int sleeptime = 2; 29360089Seric 29464795Seric while (isopen && 29560089Seric map->map_class->map_lookup(map, "@", NULL, &st) == NULL) 29625689Seric { 29764795Seric if (curtime() > toolong) 29864795Seric { 29964795Seric /* we timed out */ 30064795Seric attimeout = TRUE; 30164795Seric break; 30264795Seric } 30364795Seric 30425689Seric /* 30559673Seric ** Close and re-open the alias database in case 30659673Seric ** the one is mv'ed instead of cp'ed in. 30725689Seric */ 30825689Seric 30959697Seric if (tTd(27, 2)) 31064795Seric printf("aliaswait: sleeping for %d seconds\n", 31164795Seric sleeptime); 31259697Seric 31360089Seric map->map_class->map_close(map); 31464795Seric sleep(sleeptime); 31564795Seric sleeptime *= 2; 31664795Seric if (sleeptime > 60) 31764795Seric sleeptime = 60; 31864718Seric isopen = map->map_class->map_open(map, O_RDONLY); 31925689Seric } 32017471Seric } 3218437Seric 32259673Seric /* see if we need to go into auto-rebuild mode */ 32360207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 32460207Seric { 32560207Seric if (tTd(27, 3)) 32660207Seric printf("aliaswait: not rebuildable\n"); 32764648Seric map->map_mflags &= ~MF_ALIASWAIT; 32864718Seric return isopen; 32960207Seric } 33060207Seric if (stat(map->map_file, &stb) < 0) 33160207Seric { 33260207Seric if (tTd(27, 3)) 33360207Seric printf("aliaswait: no source file\n"); 33464648Seric map->map_mflags &= ~MF_ALIASWAIT; 33564718Seric return isopen; 33660207Seric } 33759673Seric mtime = stb.st_mtime; 33860089Seric (void) strcpy(buf, map->map_file); 33960207Seric if (ext != NULL) 34060207Seric (void) strcat(buf, ext); 34164795Seric if (stat(buf, &stb) < 0 || stb.st_mtime < mtime || attimeout) 3424322Seric { 34359673Seric /* database is out of date */ 34440559Sbostic if (AutoRebuild && stb.st_ino != 0 && stb.st_uid == geteuid()) 3454322Seric { 34660089Seric message("auto-rebuilding alias database %s", buf); 34764718Seric if (isopen) 34864718Seric map->map_class->map_close(map); 34960207Seric rebuildaliases(map, TRUE); 35064718Seric isopen = map->map_class->map_open(map, O_RDONLY); 3514322Seric } 3524322Seric else 3534322Seric { 35419039Seric #ifdef LOG 35558020Seric if (LogLevel > 3) 35659673Seric syslog(LOG_INFO, "alias database %s out of date", 35760089Seric buf); 35856795Seric #endif /* LOG */ 35960089Seric message("Warning: alias database %s out of date", buf); 3604322Seric } 3614322Seric } 36264648Seric map->map_mflags &= ~MF_ALIASWAIT; 36364718Seric return isopen; 36459673Seric } 36559673Seric /* 36659673Seric ** REBUILDALIASES -- rebuild the alias database. 36759673Seric ** 36859673Seric ** Parameters: 36960089Seric ** map -- the database to rebuild. 37059673Seric ** automatic -- set if this was automatically generated. 37159673Seric ** 37259673Seric ** Returns: 37359673Seric ** none. 37459673Seric ** 37559673Seric ** Side Effects: 37659673Seric ** Reads the text version of the database, builds the 37759673Seric ** DBM or DB version. 37859673Seric */ 3794322Seric 38060207Seric rebuildaliases(map, automatic) 38160089Seric register MAP *map; 38259673Seric bool automatic; 38359673Seric { 38459673Seric FILE *af; 38564388Seric bool nolock = FALSE; 38664564Seric sigfunc_t oldsigint; 3874322Seric 38860207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 38959673Seric return; 3904322Seric 39159673Seric /* try to lock the source file */ 39260089Seric if ((af = fopen(map->map_file, "r+")) == NULL) 39359673Seric { 39464388Seric if (errno != EACCES || automatic || 39564388Seric (af = fopen(map->map_file, "r")) == NULL) 39664388Seric { 39764388Seric int saveerr = errno; 39864382Seric 39964388Seric if (tTd(27, 1)) 40064388Seric printf("Can't open %s: %s\n", 40164388Seric map->map_file, errstring(saveerr)); 40264388Seric if (!automatic) 40364388Seric message("newaliases: cannot open %s: %s", 40464388Seric map->map_file, errstring(saveerr)); 40564388Seric errno = 0; 40664388Seric return; 40764388Seric } 40864388Seric nolock = TRUE; 40964388Seric message("warning: cannot lock %s: %s", 41064388Seric map->map_file, errstring(errno)); 4118437Seric } 41259673Seric 41359673Seric /* see if someone else is rebuilding the alias file */ 41464388Seric if (!nolock && 41564388Seric !lockfile(fileno(af), map->map_file, NULL, LOCK_EX|LOCK_NB)) 41659673Seric { 41759673Seric /* yes, they are -- wait until done */ 41859673Seric message("Alias file %s is already being rebuilt", 41960089Seric map->map_file); 42059673Seric if (OpMode != MD_INITALIAS) 42159673Seric { 42259673Seric /* wait for other rebuild to complete */ 42364335Seric (void) lockfile(fileno(af), map->map_file, NULL, 42459673Seric LOCK_EX); 42559673Seric } 42664772Seric (void) xfclose(af, "rebuildaliases1", map->map_file); 42759673Seric errno = 0; 42859673Seric return; 42959673Seric } 43059673Seric 43164035Seric oldsigint = setsignal(SIGINT, SIG_IGN); 43259673Seric 43360207Seric if (map->map_class->map_open(map, O_RDWR)) 43460089Seric { 43564382Seric #ifdef LOG 43664382Seric if (LogLevel > 7) 43764382Seric { 43864382Seric syslog(LOG_NOTICE, "alias database %s %srebuilt by %s", 43964382Seric map->map_file, automatic ? "auto" : "", 44064382Seric username()); 44164382Seric } 44264382Seric #endif /* LOG */ 44360207Seric map->map_mflags |= MF_OPEN|MF_WRITABLE; 44460207Seric readaliases(map, af, automatic); 44560089Seric } 44660207Seric else 44760207Seric { 44860207Seric if (tTd(27, 1)) 44960207Seric printf("Can't create database for %s: %s\n", 45060207Seric map->map_file, errstring(errno)); 45160207Seric if (!automatic) 45260207Seric syserr("Cannot create database for alias file %s", 45360207Seric map->map_file); 45460207Seric } 45559673Seric 45659673Seric /* close the file, thus releasing locks */ 45764772Seric xfclose(af, "rebuildaliases2", map->map_file); 45859673Seric 45959673Seric /* add distinguished entries and close the database */ 46060207Seric if (bitset(MF_OPEN, map->map_mflags)) 46160089Seric map->map_class->map_close(map); 46259673Seric 46359673Seric /* restore the old signal */ 46464035Seric (void) setsignal(SIGINT, oldsigint); 4654157Seric } 4664157Seric /* 4674157Seric ** READALIASES -- read and process the alias file. 4684157Seric ** 4694157Seric ** This routine implements the part of initaliases that occurs 4704157Seric ** when we are not going to use the DBM stuff. 4714157Seric ** 4724157Seric ** Parameters: 47360089Seric ** map -- the alias database descriptor. 47459673Seric ** af -- file to read the aliases from. 47559733Seric ** automatic -- set if this was an automatic rebuild. 4764157Seric ** 4774157Seric ** Returns: 4784157Seric ** none. 4794157Seric ** 4804157Seric ** Side Effects: 4814157Seric ** Reads aliasfile into the symbol table. 4824157Seric ** Optionally, builds the .dir & .pag files. 4834157Seric */ 4844157Seric 48560207Seric readaliases(map, af, automatic) 48660089Seric register MAP *map; 48759673Seric FILE *af; 48859733Seric int automatic; 4894157Seric { 4904098Seric register char *p; 4914098Seric char *rhs; 4924098Seric bool skipping; 49359673Seric long naliases, bytes, longest; 4944098Seric ADDRESS al, bl; 4959368Seric char line[BUFSIZ]; 4964098Seric 4974314Seric /* 4984314Seric ** Read and interpret lines 4994314Seric */ 5004314Seric 50160089Seric FileName = map->map_file; 5029368Seric LineNumber = 0; 5034322Seric naliases = bytes = longest = 0; 5044098Seric skipping = FALSE; 5054098Seric while (fgets(line, sizeof (line), af) != NULL) 5064098Seric { 5074322Seric int lhssize, rhssize; 5084322Seric 5099368Seric LineNumber++; 51056795Seric p = strchr(line, '\n'); 51125278Seric if (p != NULL) 51225278Seric *p = '\0'; 5134098Seric switch (line[0]) 5144098Seric { 5154098Seric case '#': 5164098Seric case '\0': 5174098Seric skipping = FALSE; 5184098Seric continue; 5194065Seric 5204098Seric case ' ': 5214098Seric case '\t': 5224098Seric if (!skipping) 52358151Seric syserr("554 Non-continuation line starts with space"); 5244098Seric skipping = TRUE; 5254097Seric continue; 5264098Seric } 5274098Seric skipping = FALSE; 5281874Seric 5294314Seric /* 5304314Seric ** Process the LHS 53157736Seric ** Find the colon separator, and parse the address. 53216898Seric ** It should resolve to a local name -- this will 53316898Seric ** be checked later (we want to optionally do 53416898Seric ** parsing of the RHS first to maximize error 53516898Seric ** detection). 5364314Seric */ 5374314Seric 5384098Seric for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++) 5394097Seric continue; 54016898Seric if (*p++ != ':') 5414098Seric { 54258151Seric syserr("554 missing colon"); 5434097Seric continue; 5444098Seric } 54564284Seric if (parseaddr(line, &al, RF_COPYALL, ':', NULL, CurEnv) == NULL) 5464098Seric { 54764838Seric syserr("554 %.40s... illegal alias name", line); 54816898Seric continue; 5494098Seric } 5504314Seric 5514314Seric /* 5524314Seric ** Process the RHS. 5534314Seric ** 'al' is the internal form of the LHS address. 5544314Seric ** 'p' points to the text of the RHS. 5554314Seric */ 5564314Seric 55758914Seric while (isascii(*p) && isspace(*p)) 55858914Seric p++; 5594098Seric rhs = p; 5604098Seric for (;;) 5614098Seric { 5624098Seric register char c; 56358662Seric register char *nlp; 5641515Seric 56558662Seric nlp = &p[strlen(p)]; 56658662Seric if (nlp[-1] == '\n') 56758662Seric *--nlp = '\0'; 56858662Seric 56959673Seric if (CheckAliases) 5704098Seric { 5714157Seric /* do parsing & compression of addresses */ 57225278Seric while (*p != '\0') 5734098Seric { 57458333Seric auto char *delimptr; 57525278Seric 57658050Seric while ((isascii(*p) && isspace(*p)) || 57758050Seric *p == ',') 5784157Seric p++; 57925278Seric if (*p == '\0') 58025278Seric break; 58164284Seric if (parseaddr(p, &bl, RF_COPYNONE, ',', 58264284Seric &delimptr, CurEnv) == NULL) 58358151Seric usrerr("553 %s... bad address", p); 58458333Seric p = delimptr; 5854098Seric } 5864098Seric } 5874157Seric else 58815769Seric { 58958662Seric p = nlp; 59015769Seric } 5911515Seric 5924098Seric /* see if there should be a continuation line */ 5934106Seric c = fgetc(af); 5944106Seric if (!feof(af)) 5954314Seric (void) ungetc(c, af); 5964106Seric if (c != ' ' && c != '\t') 5974098Seric break; 5984098Seric 5994098Seric /* read continuation line */ 6004098Seric if (fgets(p, sizeof line - (p - line), af) == NULL) 6014098Seric break; 6029368Seric LineNumber++; 60357135Seric 60457135Seric /* check for line overflow */ 60557135Seric if (strchr(p, '\n') == NULL) 60657135Seric { 60758151Seric usrerr("554 alias too long"); 60857135Seric break; 60957135Seric } 6104098Seric } 61116898Seric if (al.q_mailer != LocalMailer) 61216898Seric { 61364278Seric syserr("554 %s... cannot alias non-local names", 61464278Seric al.q_paddr); 61516898Seric continue; 61616898Seric } 6174314Seric 6184314Seric /* 6194314Seric ** Insert alias into symbol table or DBM file 6204314Seric */ 6214314Seric 62257381Seric if (!bitnset(M_USR_UPPER, al.q_mailer->m_flags)) 62357381Seric makelower(al.q_user); 6244322Seric 62559673Seric lhssize = strlen(al.q_user); 62659673Seric rhssize = strlen(rhs); 62760089Seric map->map_class->map_store(map, al.q_user, rhs); 6284157Seric 62959673Seric if (al.q_paddr != NULL) 63059673Seric free(al.q_paddr); 63159673Seric if (al.q_host != NULL) 63259673Seric free(al.q_host); 63359673Seric if (al.q_user != NULL) 63459673Seric free(al.q_user); 6354322Seric 6364322Seric /* statistics */ 6374322Seric naliases++; 6384322Seric bytes += lhssize + rhssize; 6394322Seric if (rhssize > longest) 6404322Seric longest = rhssize; 6411515Seric } 64219784Seric 64360207Seric CurEnv->e_to = NULL; 64459673Seric FileName = NULL; 64559733Seric if (Verbose || !automatic) 64659733Seric message("%s: %d aliases, longest %d bytes, %d bytes total", 64760089Seric map->map_file, naliases, longest, bytes); 64859673Seric # ifdef LOG 64959673Seric if (LogLevel > 7) 65059673Seric syslog(LOG_INFO, "%s: %d aliases, longest %d bytes, %d bytes total", 65160089Seric map->map_file, naliases, longest, bytes); 65259673Seric # endif /* LOG */ 65359673Seric } 65459673Seric /* 655292Seric ** FORWARD -- Try to forward mail 656292Seric ** 657292Seric ** This is similar but not identical to aliasing. 658292Seric ** 659292Seric ** Parameters: 6604314Seric ** user -- the name of the user who's mail we would like 6614314Seric ** to forward to. It must have been verified -- 6624314Seric ** i.e., the q_home field must have been filled 6634314Seric ** in. 6644999Seric ** sendq -- a pointer to the head of the send queue to 6654999Seric ** put this user's aliases in. 666292Seric ** 667292Seric ** Returns: 6684098Seric ** none. 669292Seric ** 670292Seric ** Side Effects: 6713185Seric ** New names are added to send queues. 672292Seric */ 673292Seric 67455012Seric forward(user, sendq, e) 6752966Seric ADDRESS *user; 6764999Seric ADDRESS **sendq; 67755012Seric register ENVELOPE *e; 678292Seric { 67957136Seric char *pp; 68057136Seric char *ep; 6814069Seric 6827671Seric if (tTd(27, 1)) 6834098Seric printf("forward(%s)\n", user->q_paddr); 6844098Seric 6854594Seric if (user->q_mailer != LocalMailer || bitset(QBADADDR, user->q_flags)) 6864098Seric return; 6874314Seric if (user->q_home == NULL) 68858059Seric { 68958151Seric syserr("554 forward: no home"); 69058059Seric user->q_home = "/nosuchdirectory"; 69158059Seric } 6924069Seric 6934069Seric /* good address -- look for .forward file in home */ 69455012Seric define('z', user->q_home, e); 69557136Seric define('u', user->q_user, e); 69657136Seric define('h', user->q_host, e); 69757136Seric if (ForwardPath == NULL) 69858050Seric ForwardPath = newstr("\201z/.forward"); 69957136Seric 70057136Seric for (pp = ForwardPath; pp != NULL; pp = ep) 70157136Seric { 70258247Seric int err; 70357232Seric char buf[MAXPATHLEN+1]; 70457136Seric 70557136Seric ep = strchr(pp, ':'); 70657136Seric if (ep != NULL) 70757136Seric *ep = '\0'; 70857136Seric expand(pp, buf, &buf[sizeof buf - 1], e); 70957136Seric if (ep != NULL) 71057136Seric *ep++ = ':'; 71157136Seric if (tTd(27, 3)) 71257136Seric printf("forward: trying %s\n", buf); 71363753Seric 71458247Seric err = include(buf, TRUE, user, sendq, e); 71558247Seric if (err == 0) 71657136Seric break; 71764325Seric else if (transienterror(err)) 71858247Seric { 71958247Seric /* we have to suspend this message */ 72059563Seric if (tTd(27, 2)) 72159563Seric printf("forward: transient error on %s\n", buf); 72259563Seric #ifdef LOG 72359563Seric if (LogLevel > 2) 72459624Seric syslog(LOG_ERR, "%s: forward %s: transient error: %s", 72559624Seric e->e_id, buf, errstring(err)); 72659563Seric #endif 72759611Seric message("%s: %s: message queued", buf, errstring(err)); 72863853Seric user->q_flags |= QQUEUEUP; 72958247Seric return; 73058247Seric } 73157136Seric } 732292Seric } 733