122694Sdist /* 235073Sbostic * Copyright (c) 1983 Eric P. Allman 333728Sbostic * Copyright (c) 1988 Regents of the University of California. 433728Sbostic * All rights reserved. 533728Sbostic * 642824Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822694Sdist 958332Seric # include "sendmail.h" 1050577Seric # include <signal.h> 1150577Seric # include <pwd.h> 1256766Seric 1333728Sbostic #ifndef lint 14*60502Seric static char sccsid[] = "@(#)alias.c 6.50 (Berkeley) 05/27/93"; 1533728Sbostic #endif /* not lint */ 1659673Seric 1759673Seric 1860089Seric MAP AliasDB[MAXALIASDB + 1]; /* actual database list */ 1959673Seric int NAliasDBs; /* number of alias databases */ 2059673Seric /* 21292Seric ** ALIAS -- Compute aliases. 22292Seric ** 239368Seric ** Scans the alias file for an alias for the given address. 249368Seric ** If found, it arranges to deliver to the alias list instead. 259368Seric ** Uses libdbm database if -DDBM. 26292Seric ** 27292Seric ** Parameters: 284097Seric ** a -- address to alias. 294999Seric ** sendq -- a pointer to the head of the send queue 304999Seric ** to put the aliases in. 3158092Seric ** e -- the current envelope. 32292Seric ** 33292Seric ** Returns: 34292Seric ** none 35292Seric ** 36292Seric ** Side Effects: 373185Seric ** Aliases found are expanded. 38292Seric ** 39292Seric ** Deficiencies: 40292Seric ** It should complain about names that are aliased to 41292Seric ** nothing. 42292Seric */ 43292Seric 4455012Seric alias(a, sendq, e) 454097Seric register ADDRESS *a; 464999Seric ADDRESS **sendq; 4755012Seric register ENVELOPE *e; 48292Seric { 494081Seric register char *p; 5058082Seric int naliases; 5158170Seric char *owner; 5258170Seric char obuf[MAXNAME + 6]; 535701Seric extern char *aliaslookup(); 54292Seric 557671Seric if (tTd(27, 1)) 564098Seric printf("alias(%s)\n", a->q_paddr); 57292Seric 584098Seric /* don't realias already aliased names */ 5958680Seric if (bitset(QDONTSEND|QBADADDR|QVERIFIED, a->q_flags)) 604098Seric return; 614098Seric 6259673Seric if (NoAlias) 6359673Seric return; 6459673Seric 6555012Seric e->e_to = a->q_paddr; 664098Seric 674314Seric /* 684314Seric ** Look up this name 694314Seric */ 704314Seric 7159673Seric p = aliaslookup(a->q_user, e); 724098Seric if (p == NULL) 734098Seric return; 74292Seric 75292Seric /* 764098Seric ** Match on Alias. 774098Seric ** Deliver to the target list. 781515Seric */ 791515Seric 807671Seric if (tTd(27, 1)) 814098Seric printf("%s (%s, %s) aliased to %s\n", 824098Seric a->q_paddr, a->q_host, a->q_user, p); 8358092Seric if (bitset(EF_VRFYONLY, e->e_flags)) 8458154Seric { 8558154Seric a->q_flags |= QVERIFIED; 8658884Seric e->e_nrcpts++; 8758092Seric return; 8858154Seric } 8958154Seric message("aliased to %s", p); 9057977Seric #ifdef LOG 9158020Seric if (LogLevel > 9) 9257977Seric syslog(LOG_INFO, "%s: alias %s => %s", e->e_id, a->q_paddr, p); 9357977Seric #endif 9458082Seric a->q_flags &= ~QSELFREF; 954098Seric AliasLevel++; 9658082Seric naliases = sendtolist(p, a, sendq, e); 974098Seric AliasLevel--; 9858082Seric if (naliases > 0 && !bitset(QSELFREF, a->q_flags)) 9958065Seric { 10058065Seric if (tTd(27, 5)) 10158065Seric { 10258065Seric printf("alias: QDONTSEND "); 10358065Seric printaddr(a, FALSE); 10458065Seric } 10558065Seric a->q_flags |= QDONTSEND; 10658065Seric } 10758170Seric 10858170Seric /* 10958170Seric ** Look for owner of alias 11058170Seric */ 11158170Seric 11258170Seric (void) strcpy(obuf, "owner-"); 11358170Seric if (strncmp(a->q_user, "owner-", 6) == 0) 11458170Seric (void) strcat(obuf, "owner"); 11558170Seric else 11658170Seric (void) strcat(obuf, a->q_user); 11758170Seric if (!bitnset(M_USR_UPPER, a->q_mailer->m_flags)) 11858170Seric makelower(obuf); 11959673Seric owner = aliaslookup(obuf, e); 12058170Seric if (owner != NULL) 12158170Seric { 12258170Seric if (strchr(owner, ',') != NULL) 12358170Seric owner = obuf; 12458170Seric a->q_owner = newstr(owner); 12558170Seric } 1264098Seric } 1274098Seric /* 1285701Seric ** ALIASLOOKUP -- look up a name in the alias file. 1295701Seric ** 1305701Seric ** Parameters: 1315701Seric ** name -- the name to look up. 1325701Seric ** 1335701Seric ** Returns: 1345701Seric ** the value of name. 1355701Seric ** NULL if unknown. 1365701Seric ** 1375701Seric ** Side Effects: 1385701Seric ** none. 1395701Seric ** 1405701Seric ** Warnings: 1415701Seric ** The return value will be trashed across calls. 1425701Seric */ 1435701Seric 1445701Seric char * 14559673Seric aliaslookup(name, e) 1465701Seric char *name; 14759673Seric ENVELOPE *e; 1485701Seric { 14959673Seric register int dbno; 15060089Seric register MAP *map; 15159673Seric register char *p; 1525701Seric 15359673Seric for (dbno = 0; dbno < NAliasDBs; dbno++) 15459673Seric { 15560089Seric auto int stat; 15660089Seric 15760089Seric map = &AliasDB[dbno]; 15860207Seric if (!bitset(MF_OPEN, map->map_mflags)) 15959673Seric continue; 16060207Seric p = (*map->map_class->map_lookup)(map, name, NULL, &stat); 16159673Seric if (p != NULL) 16259673Seric return p; 16359673Seric } 16459673Seric return NULL; 16559673Seric } 16659673Seric /* 16759673Seric ** SETALIAS -- set up an alias map 16859673Seric ** 16959673Seric ** Called when reading configuration file. 17059673Seric ** 17159673Seric ** Parameters: 17259673Seric ** spec -- the alias specification 17359673Seric ** 17459673Seric ** Returns: 17559673Seric ** none. 17659673Seric */ 17757381Seric 17859673Seric setalias(spec) 17959673Seric char *spec; 18059673Seric { 18159673Seric register char *p; 18260089Seric register MAP *map; 18359673Seric char *class; 18459673Seric STAB *s; 18559673Seric 18659697Seric if (tTd(27, 8)) 18759697Seric printf("setalias(%s)\n", spec); 18859697Seric 18959758Seric for (p = spec; p != NULL; ) 19051756Seric { 19159758Seric while (isspace(*p)) 19259758Seric p++; 193*60502Seric if (*p == '\0') 19459673Seric break; 19559673Seric spec = p; 19659673Seric 19759758Seric if (NAliasDBs >= MAXALIASDB) 19859758Seric { 19959758Seric syserr("Too many alias databases defined, %d max", MAXALIASDB); 20059758Seric return; 20159758Seric } 20260089Seric map = &AliasDB[NAliasDBs]; 20360089Seric bzero(map, sizeof *map); 20459758Seric 20559758Seric p = strpbrk(p, " ,/:"); 20659758Seric if (p != NULL && *p == ':') 20759758Seric { 20860089Seric /* map name */ 20959758Seric *p++ = '\0'; 21059758Seric class = spec; 21159758Seric spec = p; 21259758Seric } 21359758Seric else 21459758Seric { 21559758Seric class = "implicit"; 21660228Seric map->map_mflags = MF_OPTIONAL|MF_INCLNULL; 21759758Seric } 21859758Seric 21959758Seric /* find end of spec */ 22059758Seric if (p != NULL) 22159758Seric p = strchr(p, ','); 22259758Seric if (p != NULL) 22359758Seric *p++ = '\0'; 22459758Seric 22559758Seric /* look up class */ 22660089Seric s = stab(class, ST_MAPCLASS, ST_FIND); 22759758Seric if (s == NULL) 22859758Seric { 22959758Seric if (tTd(27, 1)) 23059758Seric printf("Unknown alias class %s\n", class); 23159758Seric } 23260207Seric else if (!bitset(MCF_ALIASOK, s->s_mapclass.map_cflags)) 23360207Seric { 23460207Seric syserr("setalias: map class %s can't handle aliases", 23560207Seric class); 23660207Seric } 23759758Seric else 23859758Seric { 23960207Seric map->map_class = &s->s_mapclass; 24060089Seric if (map->map_class->map_parse(map, spec)) 24160089Seric { 24260207Seric map->map_mflags |= MF_VALID|MF_ALIAS; 24360089Seric NAliasDBs++; 24460089Seric } 24559758Seric } 24659756Seric } 2475701Seric } 2485701Seric /* 2494098Seric ** INITALIASES -- initialize for aliasing 2504098Seric ** 25156845Seric ** Very different depending on whether we are running NDBM or not. 2524098Seric ** 2534098Seric ** Parameters: 25459673Seric ** rebuild -- if TRUE, this rebuilds the cached versions. 25559673Seric ** e -- current envelope. 2564098Seric ** 2574098Seric ** Returns: 2584098Seric ** none. 2594098Seric ** 2604098Seric ** Side Effects: 2614098Seric ** initializes aliases: 26256845Seric ** if NDBM: opens the database. 26356845Seric ** if ~NDBM: reads the aliases into the symbol table. 2644098Seric */ 2654098Seric 26659673Seric initaliases(rebuild, e) 26759673Seric bool rebuild; 26855012Seric register ENVELOPE *e; 2694098Seric { 27059673Seric int dbno; 27160089Seric register MAP *map; 2724322Seric 27360207Seric CurEnv = e; 27459673Seric for (dbno = 0; dbno < NAliasDBs; dbno++) 2758437Seric { 27660089Seric map = &AliasDB[dbno]; 27760207Seric if (!bitset(MF_VALID, map->map_mflags)) 27860207Seric continue; 27959697Seric 28059697Seric if (tTd(27, 2)) 28159697Seric printf("initaliases(%s:%s)\n", 28260089Seric map->map_class->map_cname, map->map_file); 28359697Seric 28460207Seric /* if already open, close it (for nested open) */ 28560207Seric if (bitset(MF_OPEN, map->map_mflags)) 28660207Seric { 28760207Seric map->map_class->map_close(map); 28860207Seric map->map_mflags &= ~(MF_OPEN|MF_WRITABLE); 28960207Seric } 29060207Seric 29159673Seric if (rebuild) 29250576Seric { 29360207Seric if (bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 29460207Seric rebuildaliases(map, FALSE); 29550576Seric } 29659673Seric else 29757249Seric { 29860089Seric if (map->map_class->map_open(map, O_RDONLY)) 29959756Seric { 30059756Seric if (tTd(27, 4)) 30159756Seric printf("%s:%s: valid\n", 30260089Seric map->map_class->map_cname, 30360089Seric map->map_file); 30460207Seric map->map_mflags |= MF_OPEN; 30559756Seric } 30659756Seric else if (tTd(27, 4)) 30759756Seric printf("%s:%s: invalid: %s\n", 30860207Seric map->map_class->map_cname, 30960207Seric map->map_file, 31059756Seric errstring(errno)); 31157249Seric } 31250575Seric } 31359673Seric } 31459673Seric /* 31559673Seric ** ALIASWAIT -- wait for distinguished @:@ token to appear. 31659673Seric ** 31759673Seric ** This can decide to reopen or rebuild the alias file 31859673Seric */ 31959673Seric 32060207Seric aliaswait(map, ext) 32160089Seric MAP *map; 32260207Seric char *ext; 32359673Seric { 32459673Seric int atcnt; 32559673Seric time_t mtime; 32659673Seric struct stat stb; 32759673Seric char buf[MAXNAME]; 32859673Seric 32959697Seric if (tTd(27, 3)) 33060207Seric printf("aliaswait(%s:%s)\n", 33160207Seric map->map_class->map_cname, map->map_file); 33259697Seric 33317471Seric atcnt = SafeAlias * 2; 33417471Seric if (atcnt > 0) 33517471Seric { 33660089Seric auto int st; 33760089Seric 33859673Seric while (atcnt-- >= 0 && 33960089Seric map->map_class->map_lookup(map, "@", NULL, &st) == NULL) 34025689Seric { 34125689Seric /* 34259673Seric ** Close and re-open the alias database in case 34359673Seric ** the one is mv'ed instead of cp'ed in. 34425689Seric */ 34525689Seric 34659697Seric if (tTd(27, 2)) 34759697Seric printf("aliaswait: sleeping\n"); 34859697Seric 34960089Seric map->map_class->map_close(map); 35017471Seric sleep(30); 35160089Seric map->map_class->map_open(map, O_RDONLY); 35225689Seric } 35317471Seric } 3548437Seric 35559673Seric /* see if we need to go into auto-rebuild mode */ 35660207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 35760207Seric { 35860207Seric if (tTd(27, 3)) 35960207Seric printf("aliaswait: not rebuildable\n"); 36059673Seric return; 36160207Seric } 36260207Seric if (stat(map->map_file, &stb) < 0) 36360207Seric { 36460207Seric if (tTd(27, 3)) 36560207Seric printf("aliaswait: no source file\n"); 36660207Seric return; 36760207Seric } 36859673Seric mtime = stb.st_mtime; 36960089Seric (void) strcpy(buf, map->map_file); 37060207Seric if (ext != NULL) 37160207Seric (void) strcat(buf, ext); 37259673Seric if (stat(buf, &stb) < 0 || stb.st_mtime < mtime || atcnt < 0) 3734322Seric { 37459673Seric /* database is out of date */ 37540559Sbostic if (AutoRebuild && stb.st_ino != 0 && stb.st_uid == geteuid()) 3764322Seric { 37760089Seric message("auto-rebuilding alias database %s", buf); 37860207Seric rebuildaliases(map, TRUE); 3794322Seric } 3804322Seric else 3814322Seric { 38219039Seric #ifdef LOG 38358020Seric if (LogLevel > 3) 38459673Seric syslog(LOG_INFO, "alias database %s out of date", 38560089Seric buf); 38656795Seric #endif /* LOG */ 38760089Seric message("Warning: alias database %s out of date", buf); 3884322Seric } 3894322Seric } 39059673Seric } 39159673Seric /* 39259673Seric ** REBUILDALIASES -- rebuild the alias database. 39359673Seric ** 39459673Seric ** Parameters: 39560089Seric ** map -- the database to rebuild. 39659673Seric ** automatic -- set if this was automatically generated. 39759673Seric ** 39859673Seric ** Returns: 39959673Seric ** none. 40059673Seric ** 40159673Seric ** Side Effects: 40259673Seric ** Reads the text version of the database, builds the 40359673Seric ** DBM or DB version. 40459673Seric */ 4054322Seric 40660207Seric rebuildaliases(map, automatic) 40760089Seric register MAP *map; 40859673Seric bool automatic; 40959673Seric { 41059673Seric FILE *af; 41159673Seric void (*oldsigint)(); 4124322Seric 41360207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 41459673Seric return; 4154322Seric 41659673Seric #ifdef LOG 41759673Seric if (LogLevel > 7) 4188437Seric { 41959673Seric syslog(LOG_NOTICE, "alias database %s %srebuilt by %s", 42060089Seric map->map_file, automatic ? "auto" : "", username()); 42159673Seric } 42256795Seric #endif /* LOG */ 42359673Seric 42459673Seric /* try to lock the source file */ 42560089Seric if ((af = fopen(map->map_file, "r+")) == NULL) 42659673Seric { 42759756Seric if (tTd(27, 1)) 42859756Seric printf("Can't open %s: %s\n", 42960089Seric map->map_file, errstring(errno)); 43059673Seric errno = 0; 43159673Seric return; 4328437Seric } 43359673Seric 43459673Seric /* see if someone else is rebuilding the alias file */ 43560089Seric if (!lockfile(fileno(af), map->map_file, LOCK_EX|LOCK_NB)) 43659673Seric { 43759673Seric /* yes, they are -- wait until done */ 43859673Seric message("Alias file %s is already being rebuilt", 43960089Seric map->map_file); 44059673Seric if (OpMode != MD_INITALIAS) 44159673Seric { 44259673Seric /* wait for other rebuild to complete */ 44360089Seric (void) lockfile(fileno(af), map->map_file, 44459673Seric LOCK_EX); 44559673Seric } 44659673Seric (void) fclose(af); 44759673Seric errno = 0; 44859673Seric return; 44959673Seric } 45059673Seric 45159673Seric oldsigint = signal(SIGINT, SIG_IGN); 45259673Seric 45360207Seric if (map->map_class->map_open(map, O_RDWR)) 45460089Seric { 45560207Seric map->map_mflags |= MF_OPEN|MF_WRITABLE; 45660207Seric readaliases(map, af, automatic); 45760089Seric } 45860207Seric else 45960207Seric { 46060207Seric if (tTd(27, 1)) 46160207Seric printf("Can't create database for %s: %s\n", 46260207Seric map->map_file, errstring(errno)); 46360207Seric if (!automatic) 46460207Seric syserr("Cannot create database for alias file %s", 46560207Seric map->map_file); 46660207Seric } 46759673Seric 46859673Seric /* close the file, thus releasing locks */ 46959673Seric fclose(af); 47059673Seric 47159673Seric /* add distinguished entries and close the database */ 47260207Seric if (bitset(MF_OPEN, map->map_mflags)) 47360089Seric map->map_class->map_close(map); 47459673Seric 47559673Seric /* restore the old signal */ 47659673Seric (void) signal(SIGINT, oldsigint); 4774157Seric } 4784157Seric /* 4794157Seric ** READALIASES -- read and process the alias file. 4804157Seric ** 4814157Seric ** This routine implements the part of initaliases that occurs 4824157Seric ** when we are not going to use the DBM stuff. 4834157Seric ** 4844157Seric ** Parameters: 48560089Seric ** map -- the alias database descriptor. 48659673Seric ** af -- file to read the aliases from. 48759733Seric ** automatic -- set if this was an automatic rebuild. 4884157Seric ** 4894157Seric ** Returns: 4904157Seric ** none. 4914157Seric ** 4924157Seric ** Side Effects: 4934157Seric ** Reads aliasfile into the symbol table. 4944157Seric ** Optionally, builds the .dir & .pag files. 4954157Seric */ 4964157Seric 49760207Seric readaliases(map, af, automatic) 49860089Seric register MAP *map; 49959673Seric FILE *af; 50059733Seric int automatic; 5014157Seric { 5024098Seric register char *p; 5034098Seric char *rhs; 5044098Seric bool skipping; 50559673Seric long naliases, bytes, longest; 5064098Seric ADDRESS al, bl; 5074106Seric register STAB *s; 5089368Seric char line[BUFSIZ]; 5094098Seric 5104314Seric /* 5114314Seric ** Read and interpret lines 5124314Seric */ 5134314Seric 51460089Seric FileName = map->map_file; 5159368Seric LineNumber = 0; 5164322Seric naliases = bytes = longest = 0; 5174098Seric skipping = FALSE; 5184098Seric while (fgets(line, sizeof (line), af) != NULL) 5194098Seric { 5204322Seric int lhssize, rhssize; 5214322Seric 5229368Seric LineNumber++; 52356795Seric p = strchr(line, '\n'); 52425278Seric if (p != NULL) 52525278Seric *p = '\0'; 5264098Seric switch (line[0]) 5274098Seric { 5284098Seric case '#': 5294098Seric case '\0': 5304098Seric skipping = FALSE; 5314098Seric continue; 5324065Seric 5334098Seric case ' ': 5344098Seric case '\t': 5354098Seric if (!skipping) 53658151Seric syserr("554 Non-continuation line starts with space"); 5374098Seric skipping = TRUE; 5384097Seric continue; 5394098Seric } 5404098Seric skipping = FALSE; 5411874Seric 5424314Seric /* 5434314Seric ** Process the LHS 54457736Seric ** Find the colon separator, and parse the address. 54516898Seric ** It should resolve to a local name -- this will 54616898Seric ** be checked later (we want to optionally do 54716898Seric ** parsing of the RHS first to maximize error 54816898Seric ** detection). 5494314Seric */ 5504314Seric 5514098Seric for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++) 5524097Seric continue; 55316898Seric if (*p++ != ':') 5544098Seric { 55558151Seric syserr("554 missing colon"); 5564097Seric continue; 5574098Seric } 55860207Seric if (parseaddr(line, &al, 1, ':', NULL, CurEnv) == NULL) 5594098Seric { 56058151Seric syserr("554 illegal alias name"); 56116898Seric continue; 5624098Seric } 5634314Seric 5644314Seric /* 5654314Seric ** Process the RHS. 5664314Seric ** 'al' is the internal form of the LHS address. 5674314Seric ** 'p' points to the text of the RHS. 5684314Seric */ 5694314Seric 57058914Seric while (isascii(*p) && isspace(*p)) 57158914Seric p++; 5724098Seric rhs = p; 5734098Seric for (;;) 5744098Seric { 5754098Seric register char c; 57658662Seric register char *nlp; 5771515Seric 57858662Seric nlp = &p[strlen(p)]; 57958662Seric if (nlp[-1] == '\n') 58058662Seric *--nlp = '\0'; 58158662Seric 58259673Seric if (CheckAliases) 5834098Seric { 5844157Seric /* do parsing & compression of addresses */ 58525278Seric while (*p != '\0') 5864098Seric { 58758333Seric auto char *delimptr; 58825278Seric 58958050Seric while ((isascii(*p) && isspace(*p)) || 59058050Seric *p == ',') 5914157Seric p++; 59225278Seric if (*p == '\0') 59325278Seric break; 59460207Seric if (parseaddr(p, &bl, -1, ',', &delimptr, CurEnv) == NULL) 59558151Seric usrerr("553 %s... bad address", p); 59658333Seric p = delimptr; 5974098Seric } 5984098Seric } 5994157Seric else 60015769Seric { 60158662Seric p = nlp; 60215769Seric } 6031515Seric 6044098Seric /* see if there should be a continuation line */ 6054106Seric c = fgetc(af); 6064106Seric if (!feof(af)) 6074314Seric (void) ungetc(c, af); 6084106Seric if (c != ' ' && c != '\t') 6094098Seric break; 6104098Seric 6114098Seric /* read continuation line */ 6124098Seric if (fgets(p, sizeof line - (p - line), af) == NULL) 6134098Seric break; 6149368Seric LineNumber++; 61557135Seric 61657135Seric /* check for line overflow */ 61757135Seric if (strchr(p, '\n') == NULL) 61857135Seric { 61958151Seric usrerr("554 alias too long"); 62057135Seric break; 62157135Seric } 6224098Seric } 62316898Seric if (al.q_mailer != LocalMailer) 62416898Seric { 62558151Seric syserr("554 cannot alias non-local names"); 62616898Seric continue; 62716898Seric } 6284314Seric 6294314Seric /* 6304314Seric ** Insert alias into symbol table or DBM file 6314314Seric */ 6324314Seric 63357381Seric if (!bitnset(M_USR_UPPER, al.q_mailer->m_flags)) 63457381Seric makelower(al.q_user); 6354322Seric 63659673Seric lhssize = strlen(al.q_user); 63759673Seric rhssize = strlen(rhs); 63860089Seric map->map_class->map_store(map, al.q_user, rhs); 6394157Seric 64059673Seric if (al.q_paddr != NULL) 64159673Seric free(al.q_paddr); 64259673Seric if (al.q_host != NULL) 64359673Seric free(al.q_host); 64459673Seric if (al.q_user != NULL) 64559673Seric free(al.q_user); 6464322Seric 6474322Seric /* statistics */ 6484322Seric naliases++; 6494322Seric bytes += lhssize + rhssize; 6504322Seric if (rhssize > longest) 6514322Seric longest = rhssize; 6521515Seric } 65319784Seric 65460207Seric CurEnv->e_to = NULL; 65559673Seric FileName = NULL; 65659733Seric if (Verbose || !automatic) 65759733Seric message("%s: %d aliases, longest %d bytes, %d bytes total", 65860089Seric map->map_file, naliases, longest, bytes); 65959673Seric # ifdef LOG 66059673Seric if (LogLevel > 7) 66159673Seric syslog(LOG_INFO, "%s: %d aliases, longest %d bytes, %d bytes total", 66260089Seric map->map_file, naliases, longest, bytes); 66359673Seric # endif /* LOG */ 66459673Seric } 66559673Seric /* 666292Seric ** FORWARD -- Try to forward mail 667292Seric ** 668292Seric ** This is similar but not identical to aliasing. 669292Seric ** 670292Seric ** Parameters: 6714314Seric ** user -- the name of the user who's mail we would like 6724314Seric ** to forward to. It must have been verified -- 6734314Seric ** i.e., the q_home field must have been filled 6744314Seric ** in. 6754999Seric ** sendq -- a pointer to the head of the send queue to 6764999Seric ** put this user's aliases in. 677292Seric ** 678292Seric ** Returns: 6794098Seric ** none. 680292Seric ** 681292Seric ** Side Effects: 6823185Seric ** New names are added to send queues. 683292Seric */ 684292Seric 68555012Seric forward(user, sendq, e) 6862966Seric ADDRESS *user; 6874999Seric ADDRESS **sendq; 68855012Seric register ENVELOPE *e; 689292Seric { 69057136Seric char *pp; 69157136Seric char *ep; 6924069Seric 6937671Seric if (tTd(27, 1)) 6944098Seric printf("forward(%s)\n", user->q_paddr); 6954098Seric 6964594Seric if (user->q_mailer != LocalMailer || bitset(QBADADDR, user->q_flags)) 6974098Seric return; 6984314Seric if (user->q_home == NULL) 69958059Seric { 70058151Seric syserr("554 forward: no home"); 70158059Seric user->q_home = "/nosuchdirectory"; 70258059Seric } 7034069Seric 7044069Seric /* good address -- look for .forward file in home */ 70555012Seric define('z', user->q_home, e); 70657136Seric define('u', user->q_user, e); 70757136Seric define('h', user->q_host, e); 70857136Seric if (ForwardPath == NULL) 70958050Seric ForwardPath = newstr("\201z/.forward"); 71057136Seric 71157136Seric for (pp = ForwardPath; pp != NULL; pp = ep) 71257136Seric { 71358247Seric int err; 71457232Seric char buf[MAXPATHLEN+1]; 71557136Seric 71657136Seric ep = strchr(pp, ':'); 71757136Seric if (ep != NULL) 71857136Seric *ep = '\0'; 71957136Seric expand(pp, buf, &buf[sizeof buf - 1], e); 72057136Seric if (ep != NULL) 72157136Seric *ep++ = ':'; 72257136Seric if (tTd(27, 3)) 72357136Seric printf("forward: trying %s\n", buf); 72458247Seric err = include(buf, TRUE, user, sendq, e); 72558247Seric if (err == 0) 72657136Seric break; 72758247Seric if (transienterror(err)) 72858247Seric { 72958247Seric /* we have to suspend this message */ 73059563Seric if (tTd(27, 2)) 73159563Seric printf("forward: transient error on %s\n", buf); 73259563Seric #ifdef LOG 73359563Seric if (LogLevel > 2) 73459624Seric syslog(LOG_ERR, "%s: forward %s: transient error: %s", 73559624Seric e->e_id, buf, errstring(err)); 73659563Seric #endif 73759611Seric message("%s: %s: message queued", buf, errstring(err)); 73858247Seric user->q_flags |= QQUEUEUP|QDONTSEND; 73958247Seric return; 74058247Seric } 74157136Seric } 742292Seric } 743