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*66784Seric static char sccsid[] = "@(#)alias.c 8.25 (Berkeley) 04/14/94"; 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) 9166280Seric syslog(LOG_INFO, "%s: alias %s => %s", 9266280Seric e->e_id == NULL ? "NOQUEUE" : e->e_id, 9366280Seric a->q_paddr, p); 9457977Seric #endif 9558082Seric a->q_flags &= ~QSELFREF; 964098Seric AliasLevel++; 9758082Seric naliases = sendtolist(p, a, sendq, e); 984098Seric AliasLevel--; 9964301Seric if (!bitset(QSELFREF, a->q_flags)) 10058065Seric { 10158065Seric if (tTd(27, 5)) 10258065Seric { 10358065Seric printf("alias: QDONTSEND "); 10458065Seric printaddr(a, FALSE); 10558065Seric } 10658065Seric a->q_flags |= QDONTSEND; 10758065Seric } 10858170Seric 10958170Seric /* 11058170Seric ** Look for owner of alias 11158170Seric */ 11258170Seric 11358170Seric (void) strcpy(obuf, "owner-"); 11458170Seric if (strncmp(a->q_user, "owner-", 6) == 0) 11558170Seric (void) strcat(obuf, "owner"); 11658170Seric else 11758170Seric (void) strcat(obuf, a->q_user); 11858170Seric if (!bitnset(M_USR_UPPER, a->q_mailer->m_flags)) 11958170Seric makelower(obuf); 12059673Seric owner = aliaslookup(obuf, e); 121*66784Seric if (owner == NULL) 122*66784Seric return; 123*66784Seric 124*66784Seric /* reflect owner into envelope sender */ 125*66784Seric if (strpbrk(owner, ",:/|\"") != NULL) 126*66784Seric owner = obuf; 127*66784Seric a->q_owner = newstr(owner); 128*66784Seric 129*66784Seric /* announce delivery to this alias; NORECEIPT bit set later */ 130*66784Seric if (e->e_xfp != NULL) 13158170Seric { 132*66784Seric fprintf(e->e_xfp, "Message delivered to mailing list %s\n", 133*66784Seric a->q_paddr); 134*66784Seric e->e_flags |= EF_SENDRECEIPT; 13558170Seric } 1364098Seric } 1374098Seric /* 1385701Seric ** ALIASLOOKUP -- look up a name in the alias file. 1395701Seric ** 1405701Seric ** Parameters: 1415701Seric ** name -- the name to look up. 1425701Seric ** 1435701Seric ** Returns: 1445701Seric ** the value of name. 1455701Seric ** NULL if unknown. 1465701Seric ** 1475701Seric ** Side Effects: 1485701Seric ** none. 1495701Seric ** 1505701Seric ** Warnings: 1515701Seric ** The return value will be trashed across calls. 1525701Seric */ 1535701Seric 1545701Seric char * 15559673Seric aliaslookup(name, e) 1565701Seric char *name; 15759673Seric ENVELOPE *e; 1585701Seric { 15959673Seric register int dbno; 16060089Seric register MAP *map; 16159673Seric register char *p; 1625701Seric 16359673Seric for (dbno = 0; dbno < NAliasDBs; dbno++) 16459673Seric { 16560089Seric auto int stat; 16660089Seric 16760537Seric map = AliasDB[dbno]; 16860207Seric if (!bitset(MF_OPEN, map->map_mflags)) 16959673Seric continue; 17060207Seric p = (*map->map_class->map_lookup)(map, name, NULL, &stat); 17159673Seric if (p != NULL) 17259673Seric return p; 17359673Seric } 17459673Seric return NULL; 17559673Seric } 17659673Seric /* 17759673Seric ** SETALIAS -- set up an alias map 17859673Seric ** 17959673Seric ** Called when reading configuration file. 18059673Seric ** 18159673Seric ** Parameters: 18259673Seric ** spec -- the alias specification 18359673Seric ** 18459673Seric ** Returns: 18559673Seric ** none. 18659673Seric */ 18757381Seric 18859673Seric setalias(spec) 18959673Seric char *spec; 19059673Seric { 19159673Seric register char *p; 19260089Seric register MAP *map; 19359673Seric char *class; 19459673Seric STAB *s; 19559673Seric 19659697Seric if (tTd(27, 8)) 19759697Seric printf("setalias(%s)\n", spec); 19859697Seric 19959758Seric for (p = spec; p != NULL; ) 20051756Seric { 20160537Seric char aname[50]; 20260537Seric 20359758Seric while (isspace(*p)) 20459758Seric p++; 20560502Seric if (*p == '\0') 20659673Seric break; 20759673Seric spec = p; 20859673Seric 20959758Seric if (NAliasDBs >= MAXALIASDB) 21059758Seric { 21159758Seric syserr("Too many alias databases defined, %d max", MAXALIASDB); 21259758Seric return; 21359758Seric } 21460537Seric (void) sprintf(aname, "Alias%d", NAliasDBs); 21560537Seric s = stab(aname, ST_MAP, ST_ENTER); 21660537Seric map = &s->s_map; 21760537Seric AliasDB[NAliasDBs] = map; 21860089Seric bzero(map, sizeof *map); 21959758Seric 22059758Seric p = strpbrk(p, " ,/:"); 22159758Seric if (p != NULL && *p == ':') 22259758Seric { 22360089Seric /* map name */ 22459758Seric *p++ = '\0'; 22559758Seric class = spec; 22659758Seric spec = p; 22759758Seric } 22859758Seric else 22959758Seric { 23059758Seric class = "implicit"; 23160228Seric map->map_mflags = MF_OPTIONAL|MF_INCLNULL; 23259758Seric } 23359758Seric 23459758Seric /* find end of spec */ 23559758Seric if (p != NULL) 23659758Seric p = strchr(p, ','); 23759758Seric if (p != NULL) 23859758Seric *p++ = '\0'; 23959758Seric 24059758Seric /* look up class */ 24160089Seric s = stab(class, ST_MAPCLASS, ST_FIND); 24259758Seric if (s == NULL) 24359758Seric { 24459758Seric if (tTd(27, 1)) 24559758Seric printf("Unknown alias class %s\n", class); 24659758Seric } 24760207Seric else if (!bitset(MCF_ALIASOK, s->s_mapclass.map_cflags)) 24860207Seric { 24960207Seric syserr("setalias: map class %s can't handle aliases", 25060207Seric class); 25160207Seric } 25259758Seric else 25359758Seric { 25460207Seric map->map_class = &s->s_mapclass; 25560089Seric if (map->map_class->map_parse(map, spec)) 25660089Seric { 25760207Seric map->map_mflags |= MF_VALID|MF_ALIAS; 25860089Seric NAliasDBs++; 25960089Seric } 26059758Seric } 26159756Seric } 2625701Seric } 2635701Seric /* 26459673Seric ** ALIASWAIT -- wait for distinguished @:@ token to appear. 26559673Seric ** 26659673Seric ** This can decide to reopen or rebuild the alias file 26764718Seric ** 26864718Seric ** Parameters: 26964718Seric ** map -- a pointer to the map descriptor for this alias file. 27064718Seric ** ext -- the filename extension (e.g., ".db") for the 27164718Seric ** database file. 27264718Seric ** isopen -- if set, the database is already open, and we 27364718Seric ** should check for validity; otherwise, we are 27464718Seric ** just checking to see if it should be created. 27564718Seric ** 27664718Seric ** Returns: 27764718Seric ** TRUE -- if the database is open when we return. 27864718Seric ** FALSE -- if the database is closed when we return. 27959673Seric */ 28059673Seric 28164718Seric bool 28264718Seric aliaswait(map, ext, isopen) 28360089Seric MAP *map; 28460207Seric char *ext; 28564718Seric int isopen; 28659673Seric { 28764795Seric bool attimeout = FALSE; 28859673Seric time_t mtime; 28959673Seric struct stat stb; 29059673Seric char buf[MAXNAME]; 29159673Seric 29259697Seric if (tTd(27, 3)) 29360207Seric printf("aliaswait(%s:%s)\n", 29460207Seric map->map_class->map_cname, map->map_file); 29564648Seric if (bitset(MF_ALIASWAIT, map->map_mflags)) 29664795Seric return isopen; 29764648Seric map->map_mflags |= MF_ALIASWAIT; 29859697Seric 29964795Seric if (SafeAlias > 0) 30017471Seric { 30160089Seric auto int st; 30264795Seric time_t toolong = curtime() + SafeAlias; 30364795Seric unsigned int sleeptime = 2; 30460089Seric 30564795Seric while (isopen && 30660089Seric map->map_class->map_lookup(map, "@", NULL, &st) == NULL) 30725689Seric { 30864795Seric if (curtime() > toolong) 30964795Seric { 31064795Seric /* we timed out */ 31164795Seric attimeout = TRUE; 31264795Seric break; 31364795Seric } 31464795Seric 31525689Seric /* 31659673Seric ** Close and re-open the alias database in case 31759673Seric ** the one is mv'ed instead of cp'ed in. 31825689Seric */ 31925689Seric 32059697Seric if (tTd(27, 2)) 32164795Seric printf("aliaswait: sleeping for %d seconds\n", 32264795Seric sleeptime); 32359697Seric 32460089Seric map->map_class->map_close(map); 32564795Seric sleep(sleeptime); 32664795Seric sleeptime *= 2; 32764795Seric if (sleeptime > 60) 32864795Seric sleeptime = 60; 32964718Seric isopen = map->map_class->map_open(map, O_RDONLY); 33025689Seric } 33117471Seric } 3328437Seric 33359673Seric /* see if we need to go into auto-rebuild mode */ 33460207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 33560207Seric { 33660207Seric if (tTd(27, 3)) 33760207Seric printf("aliaswait: not rebuildable\n"); 33864648Seric map->map_mflags &= ~MF_ALIASWAIT; 33964718Seric return isopen; 34060207Seric } 34160207Seric if (stat(map->map_file, &stb) < 0) 34260207Seric { 34360207Seric if (tTd(27, 3)) 34460207Seric printf("aliaswait: no source file\n"); 34564648Seric map->map_mflags &= ~MF_ALIASWAIT; 34664718Seric return isopen; 34760207Seric } 34859673Seric mtime = stb.st_mtime; 34960089Seric (void) strcpy(buf, map->map_file); 35060207Seric if (ext != NULL) 35160207Seric (void) strcat(buf, ext); 35264795Seric if (stat(buf, &stb) < 0 || stb.st_mtime < mtime || attimeout) 3534322Seric { 35459673Seric /* database is out of date */ 35540559Sbostic if (AutoRebuild && stb.st_ino != 0 && stb.st_uid == geteuid()) 3564322Seric { 35760089Seric message("auto-rebuilding alias database %s", buf); 35864718Seric if (isopen) 35964718Seric map->map_class->map_close(map); 36060207Seric rebuildaliases(map, TRUE); 36164718Seric isopen = map->map_class->map_open(map, O_RDONLY); 3624322Seric } 3634322Seric else 3644322Seric { 36519039Seric #ifdef LOG 36658020Seric if (LogLevel > 3) 36759673Seric syslog(LOG_INFO, "alias database %s out of date", 36860089Seric buf); 36956795Seric #endif /* LOG */ 37060089Seric message("Warning: alias database %s out of date", buf); 3714322Seric } 3724322Seric } 37364648Seric map->map_mflags &= ~MF_ALIASWAIT; 37464718Seric return isopen; 37559673Seric } 37659673Seric /* 37759673Seric ** REBUILDALIASES -- rebuild the alias database. 37859673Seric ** 37959673Seric ** Parameters: 38060089Seric ** map -- the database to rebuild. 38159673Seric ** automatic -- set if this was automatically generated. 38259673Seric ** 38359673Seric ** Returns: 38459673Seric ** none. 38559673Seric ** 38659673Seric ** Side Effects: 38759673Seric ** Reads the text version of the database, builds the 38859673Seric ** DBM or DB version. 38959673Seric */ 3904322Seric 39160207Seric rebuildaliases(map, automatic) 39260089Seric register MAP *map; 39359673Seric bool automatic; 39459673Seric { 39559673Seric FILE *af; 39664388Seric bool nolock = FALSE; 39764564Seric sigfunc_t oldsigint; 3984322Seric 39960207Seric if (!bitset(MCF_REBUILDABLE, map->map_class->map_cflags)) 40059673Seric return; 4014322Seric 40259673Seric /* try to lock the source file */ 40360089Seric if ((af = fopen(map->map_file, "r+")) == NULL) 40459673Seric { 40565953Seric if ((errno != EACCES && errno != EROFS) || automatic || 40664388Seric (af = fopen(map->map_file, "r")) == NULL) 40764388Seric { 40864388Seric int saveerr = errno; 40964382Seric 41064388Seric if (tTd(27, 1)) 41164388Seric printf("Can't open %s: %s\n", 41264388Seric map->map_file, errstring(saveerr)); 41364388Seric if (!automatic) 41464388Seric message("newaliases: cannot open %s: %s", 41564388Seric map->map_file, errstring(saveerr)); 41664388Seric errno = 0; 41764388Seric return; 41864388Seric } 41964388Seric nolock = TRUE; 42064388Seric message("warning: cannot lock %s: %s", 42164388Seric map->map_file, errstring(errno)); 4228437Seric } 42359673Seric 42459673Seric /* see if someone else is rebuilding the alias file */ 42564388Seric if (!nolock && 42664388Seric !lockfile(fileno(af), map->map_file, NULL, LOCK_EX|LOCK_NB)) 42759673Seric { 42859673Seric /* yes, they are -- wait until done */ 42959673Seric message("Alias file %s is already being rebuilt", 43060089Seric map->map_file); 43159673Seric if (OpMode != MD_INITALIAS) 43259673Seric { 43359673Seric /* wait for other rebuild to complete */ 43464335Seric (void) lockfile(fileno(af), map->map_file, NULL, 43559673Seric LOCK_EX); 43659673Seric } 43764772Seric (void) xfclose(af, "rebuildaliases1", map->map_file); 43859673Seric errno = 0; 43959673Seric return; 44059673Seric } 44159673Seric 44264035Seric oldsigint = setsignal(SIGINT, SIG_IGN); 44359673Seric 44460207Seric if (map->map_class->map_open(map, O_RDWR)) 44560089Seric { 44664382Seric #ifdef LOG 44764382Seric if (LogLevel > 7) 44864382Seric { 44964382Seric syslog(LOG_NOTICE, "alias database %s %srebuilt by %s", 45064382Seric map->map_file, automatic ? "auto" : "", 45164382Seric username()); 45264382Seric } 45364382Seric #endif /* LOG */ 45460207Seric map->map_mflags |= MF_OPEN|MF_WRITABLE; 45560207Seric readaliases(map, af, automatic); 45660089Seric } 45760207Seric else 45860207Seric { 45960207Seric if (tTd(27, 1)) 46060207Seric printf("Can't create database for %s: %s\n", 46160207Seric map->map_file, errstring(errno)); 46260207Seric if (!automatic) 46360207Seric syserr("Cannot create database for alias file %s", 46460207Seric map->map_file); 46560207Seric } 46659673Seric 46759673Seric /* close the file, thus releasing locks */ 46864772Seric xfclose(af, "rebuildaliases2", map->map_file); 46959673Seric 47059673Seric /* add distinguished entries and close the database */ 47160207Seric if (bitset(MF_OPEN, map->map_mflags)) 47260089Seric map->map_class->map_close(map); 47359673Seric 47459673Seric /* restore the old signal */ 47564035Seric (void) setsignal(SIGINT, oldsigint); 4764157Seric } 4774157Seric /* 4784157Seric ** READALIASES -- read and process the alias file. 4794157Seric ** 4804157Seric ** This routine implements the part of initaliases that occurs 4814157Seric ** when we are not going to use the DBM stuff. 4824157Seric ** 4834157Seric ** Parameters: 48460089Seric ** map -- the alias database descriptor. 48559673Seric ** af -- file to read the aliases from. 48659733Seric ** automatic -- set if this was an automatic rebuild. 4874157Seric ** 4884157Seric ** Returns: 4894157Seric ** none. 4904157Seric ** 4914157Seric ** Side Effects: 4924157Seric ** Reads aliasfile into the symbol table. 4934157Seric ** Optionally, builds the .dir & .pag files. 4944157Seric */ 4954157Seric 49660207Seric readaliases(map, af, automatic) 49760089Seric register MAP *map; 49859673Seric FILE *af; 49959733Seric int automatic; 5004157Seric { 5014098Seric register char *p; 5024098Seric char *rhs; 5034098Seric bool skipping; 50459673Seric long naliases, bytes, longest; 5054098Seric ADDRESS al, bl; 5069368Seric char line[BUFSIZ]; 5074098Seric 5084314Seric /* 5094314Seric ** Read and interpret lines 5104314Seric */ 5114314Seric 51260089Seric FileName = map->map_file; 5139368Seric LineNumber = 0; 5144322Seric naliases = bytes = longest = 0; 5154098Seric skipping = FALSE; 5164098Seric while (fgets(line, sizeof (line), af) != NULL) 5174098Seric { 5184322Seric int lhssize, rhssize; 5194322Seric 5209368Seric LineNumber++; 52156795Seric p = strchr(line, '\n'); 52225278Seric if (p != NULL) 52325278Seric *p = '\0'; 5244098Seric switch (line[0]) 5254098Seric { 5264098Seric case '#': 5274098Seric case '\0': 5284098Seric skipping = FALSE; 5294098Seric continue; 5304065Seric 5314098Seric case ' ': 5324098Seric case '\t': 5334098Seric if (!skipping) 53458151Seric syserr("554 Non-continuation line starts with space"); 5354098Seric skipping = TRUE; 5364097Seric continue; 5374098Seric } 5384098Seric skipping = FALSE; 5391874Seric 5404314Seric /* 5414314Seric ** Process the LHS 54257736Seric ** Find the colon separator, and parse the address. 54316898Seric ** It should resolve to a local name -- this will 54416898Seric ** be checked later (we want to optionally do 54516898Seric ** parsing of the RHS first to maximize error 54616898Seric ** detection). 5474314Seric */ 5484314Seric 5494098Seric for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++) 5504097Seric continue; 55116898Seric if (*p++ != ':') 5524098Seric { 55358151Seric syserr("554 missing colon"); 5544097Seric continue; 5554098Seric } 55664284Seric if (parseaddr(line, &al, RF_COPYALL, ':', NULL, CurEnv) == NULL) 5574098Seric { 55864838Seric syserr("554 %.40s... illegal alias name", line); 55916898Seric continue; 5604098Seric } 5614314Seric 5624314Seric /* 5634314Seric ** Process the RHS. 5644314Seric ** 'al' is the internal form of the LHS address. 5654314Seric ** 'p' points to the text of the RHS. 5664314Seric */ 5674314Seric 56858914Seric while (isascii(*p) && isspace(*p)) 56958914Seric p++; 5704098Seric rhs = p; 5714098Seric for (;;) 5724098Seric { 5734098Seric register char c; 57458662Seric register char *nlp; 5751515Seric 57658662Seric nlp = &p[strlen(p)]; 57758662Seric if (nlp[-1] == '\n') 57858662Seric *--nlp = '\0'; 57958662Seric 58059673Seric if (CheckAliases) 5814098Seric { 5824157Seric /* do parsing & compression of addresses */ 58325278Seric while (*p != '\0') 5844098Seric { 58558333Seric auto char *delimptr; 58625278Seric 58758050Seric while ((isascii(*p) && isspace(*p)) || 58858050Seric *p == ',') 5894157Seric p++; 59025278Seric if (*p == '\0') 59125278Seric break; 59264284Seric if (parseaddr(p, &bl, RF_COPYNONE, ',', 59364284Seric &delimptr, CurEnv) == NULL) 59458151Seric usrerr("553 %s... bad address", p); 59558333Seric p = delimptr; 5964098Seric } 5974098Seric } 5984157Seric else 59915769Seric { 60058662Seric p = nlp; 60115769Seric } 6021515Seric 6034098Seric /* see if there should be a continuation line */ 6044106Seric c = fgetc(af); 6054106Seric if (!feof(af)) 6064314Seric (void) ungetc(c, af); 6074106Seric if (c != ' ' && c != '\t') 6084098Seric break; 6094098Seric 6104098Seric /* read continuation line */ 6114098Seric if (fgets(p, sizeof line - (p - line), af) == NULL) 6124098Seric break; 6139368Seric LineNumber++; 61457135Seric 61557135Seric /* check for line overflow */ 61657135Seric if (strchr(p, '\n') == NULL) 61757135Seric { 61858151Seric usrerr("554 alias too long"); 61957135Seric break; 62057135Seric } 6214098Seric } 62216898Seric if (al.q_mailer != LocalMailer) 62316898Seric { 62464278Seric syserr("554 %s... cannot alias non-local names", 62564278Seric al.q_paddr); 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); 72463753Seric 72558247Seric err = include(buf, TRUE, user, sendq, e); 72658247Seric if (err == 0) 72757136Seric break; 72864325Seric else if (transienterror(err)) 72958247Seric { 73058247Seric /* we have to suspend this message */ 73159563Seric if (tTd(27, 2)) 73259563Seric printf("forward: transient error on %s\n", buf); 73359563Seric #ifdef LOG 73459563Seric if (LogLevel > 2) 73559624Seric syslog(LOG_ERR, "%s: forward %s: transient error: %s", 73666284Seric e->e_id == NULL ? "NOQUEUE" : e->e_id, 73766284Seric buf, errstring(err)); 73859563Seric #endif 73959611Seric message("%s: %s: message queued", buf, errstring(err)); 74063853Seric user->q_flags |= QQUEUEUP; 74158247Seric return; 74258247Seric } 74357136Seric } 744292Seric } 745