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*67426Seric static char sccsid[] = "@(#)alias.c 8.27 (Berkeley) 06/19/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)) 55*67426Seric printf("alias(%s)\n", a->q_user); 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); 12166784Seric if (owner == NULL) 12266784Seric return; 12366784Seric 12466784Seric /* reflect owner into envelope sender */ 12566784Seric if (strpbrk(owner, ",:/|\"") != NULL) 12666784Seric owner = obuf; 12766784Seric a->q_owner = newstr(owner); 12866784Seric 12966784Seric /* announce delivery to this alias; NORECEIPT bit set later */ 13066784Seric if (e->e_xfp != NULL) 13158170Seric { 13266784Seric fprintf(e->e_xfp, "Message delivered to mailing list %s\n", 13366784Seric a->q_paddr); 13466784Seric 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; 45567263Seric readaliases(map, af, !automatic, TRUE); 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. 48667263Seric ** announcestats -- anounce statistics regarding number of 48767263Seric ** aliases, longest alias, etc. 48867263Seric ** logstats -- lot the same info. 4894157Seric ** 4904157Seric ** Returns: 4914157Seric ** none. 4924157Seric ** 4934157Seric ** Side Effects: 4944157Seric ** Reads aliasfile into the symbol table. 4954157Seric ** Optionally, builds the .dir & .pag files. 4964157Seric */ 4974157Seric 49867263Seric readaliases(map, af, announcestats, logstats) 49960089Seric register MAP *map; 50059673Seric FILE *af; 50167263Seric bool announcestats; 50267263Seric bool logstats; 5034157Seric { 5044098Seric register char *p; 5054098Seric char *rhs; 5064098Seric bool skipping; 50759673Seric long naliases, bytes, longest; 5084098Seric ADDRESS al, bl; 5099368Seric char line[BUFSIZ]; 5104098Seric 5114314Seric /* 5124314Seric ** Read and interpret lines 5134314Seric */ 5144314Seric 51560089Seric FileName = map->map_file; 5169368Seric LineNumber = 0; 5174322Seric naliases = bytes = longest = 0; 5184098Seric skipping = FALSE; 5194098Seric while (fgets(line, sizeof (line), af) != NULL) 5204098Seric { 5214322Seric int lhssize, rhssize; 5224322Seric 5239368Seric LineNumber++; 52456795Seric p = strchr(line, '\n'); 52525278Seric if (p != NULL) 52625278Seric *p = '\0'; 5274098Seric switch (line[0]) 5284098Seric { 5294098Seric case '#': 5304098Seric case '\0': 5314098Seric skipping = FALSE; 5324098Seric continue; 5334065Seric 5344098Seric case ' ': 5354098Seric case '\t': 5364098Seric if (!skipping) 53758151Seric syserr("554 Non-continuation line starts with space"); 5384098Seric skipping = TRUE; 5394097Seric continue; 5404098Seric } 5414098Seric skipping = FALSE; 5421874Seric 5434314Seric /* 5444314Seric ** Process the LHS 54557736Seric ** Find the colon separator, and parse the address. 54616898Seric ** It should resolve to a local name -- this will 54716898Seric ** be checked later (we want to optionally do 54816898Seric ** parsing of the RHS first to maximize error 54916898Seric ** detection). 5504314Seric */ 5514314Seric 5524098Seric for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++) 5534097Seric continue; 55416898Seric if (*p++ != ':') 5554098Seric { 55658151Seric syserr("554 missing colon"); 5574097Seric continue; 5584098Seric } 55964284Seric if (parseaddr(line, &al, RF_COPYALL, ':', NULL, CurEnv) == NULL) 5604098Seric { 56164838Seric syserr("554 %.40s... illegal alias name", line); 56216898Seric continue; 5634098Seric } 5644314Seric 5654314Seric /* 5664314Seric ** Process the RHS. 5674314Seric ** 'al' is the internal form of the LHS address. 5684314Seric ** 'p' points to the text of the RHS. 5694314Seric */ 5704314Seric 57158914Seric while (isascii(*p) && isspace(*p)) 57258914Seric p++; 5734098Seric rhs = p; 5744098Seric for (;;) 5754098Seric { 5764098Seric register char c; 57758662Seric register char *nlp; 5781515Seric 57958662Seric nlp = &p[strlen(p)]; 58058662Seric if (nlp[-1] == '\n') 58158662Seric *--nlp = '\0'; 58258662Seric 58359673Seric if (CheckAliases) 5844098Seric { 5854157Seric /* do parsing & compression of addresses */ 58625278Seric while (*p != '\0') 5874098Seric { 58858333Seric auto char *delimptr; 58925278Seric 59058050Seric while ((isascii(*p) && isspace(*p)) || 59158050Seric *p == ',') 5924157Seric p++; 59325278Seric if (*p == '\0') 59425278Seric break; 59564284Seric if (parseaddr(p, &bl, RF_COPYNONE, ',', 59664284Seric &delimptr, CurEnv) == NULL) 59758151Seric usrerr("553 %s... bad address", p); 59858333Seric p = delimptr; 5994098Seric } 6004098Seric } 6014157Seric else 60215769Seric { 60358662Seric p = nlp; 60415769Seric } 6051515Seric 6064098Seric /* see if there should be a continuation line */ 6074106Seric c = fgetc(af); 6084106Seric if (!feof(af)) 6094314Seric (void) ungetc(c, af); 6104106Seric if (c != ' ' && c != '\t') 6114098Seric break; 6124098Seric 6134098Seric /* read continuation line */ 6144098Seric if (fgets(p, sizeof line - (p - line), af) == NULL) 6154098Seric break; 6169368Seric LineNumber++; 61757135Seric 61857135Seric /* check for line overflow */ 61957135Seric if (strchr(p, '\n') == NULL) 62057135Seric { 62158151Seric usrerr("554 alias too long"); 62257135Seric break; 62357135Seric } 6244098Seric } 62516898Seric if (al.q_mailer != LocalMailer) 62616898Seric { 62764278Seric syserr("554 %s... cannot alias non-local names", 62864278Seric al.q_paddr); 62916898Seric continue; 63016898Seric } 6314314Seric 6324314Seric /* 6334314Seric ** Insert alias into symbol table or DBM file 6344314Seric */ 6354314Seric 63657381Seric if (!bitnset(M_USR_UPPER, al.q_mailer->m_flags)) 63757381Seric makelower(al.q_user); 6384322Seric 63959673Seric lhssize = strlen(al.q_user); 64059673Seric rhssize = strlen(rhs); 64160089Seric map->map_class->map_store(map, al.q_user, rhs); 6424157Seric 64359673Seric if (al.q_paddr != NULL) 64459673Seric free(al.q_paddr); 64559673Seric if (al.q_host != NULL) 64659673Seric free(al.q_host); 64759673Seric if (al.q_user != NULL) 64859673Seric free(al.q_user); 6494322Seric 6504322Seric /* statistics */ 6514322Seric naliases++; 6524322Seric bytes += lhssize + rhssize; 6534322Seric if (rhssize > longest) 6544322Seric longest = rhssize; 6551515Seric } 65619784Seric 65760207Seric CurEnv->e_to = NULL; 65859673Seric FileName = NULL; 65967263Seric if (Verbose || announcestats) 66059733Seric message("%s: %d aliases, longest %d bytes, %d bytes total", 66160089Seric map->map_file, naliases, longest, bytes); 66259673Seric # ifdef LOG 66367263Seric if (LogLevel > 7 && logstats) 66459673Seric syslog(LOG_INFO, "%s: %d aliases, longest %d bytes, %d bytes total", 66560089Seric map->map_file, naliases, longest, bytes); 66659673Seric # endif /* LOG */ 66759673Seric } 66859673Seric /* 669292Seric ** FORWARD -- Try to forward mail 670292Seric ** 671292Seric ** This is similar but not identical to aliasing. 672292Seric ** 673292Seric ** Parameters: 6744314Seric ** user -- the name of the user who's mail we would like 6754314Seric ** to forward to. It must have been verified -- 6764314Seric ** i.e., the q_home field must have been filled 6774314Seric ** in. 6784999Seric ** sendq -- a pointer to the head of the send queue to 6794999Seric ** put this user's aliases in. 680292Seric ** 681292Seric ** Returns: 6824098Seric ** none. 683292Seric ** 684292Seric ** Side Effects: 6853185Seric ** New names are added to send queues. 686292Seric */ 687292Seric 68855012Seric forward(user, sendq, e) 6892966Seric ADDRESS *user; 6904999Seric ADDRESS **sendq; 69155012Seric register ENVELOPE *e; 692292Seric { 69357136Seric char *pp; 69457136Seric char *ep; 6954069Seric 6967671Seric if (tTd(27, 1)) 6974098Seric printf("forward(%s)\n", user->q_paddr); 6984098Seric 6994594Seric if (user->q_mailer != LocalMailer || bitset(QBADADDR, user->q_flags)) 7004098Seric return; 7014314Seric if (user->q_home == NULL) 70258059Seric { 70358151Seric syserr("554 forward: no home"); 70458059Seric user->q_home = "/nosuchdirectory"; 70558059Seric } 7064069Seric 7074069Seric /* good address -- look for .forward file in home */ 70855012Seric define('z', user->q_home, e); 70957136Seric define('u', user->q_user, e); 71057136Seric define('h', user->q_host, e); 71157136Seric if (ForwardPath == NULL) 71258050Seric ForwardPath = newstr("\201z/.forward"); 71357136Seric 71457136Seric for (pp = ForwardPath; pp != NULL; pp = ep) 71557136Seric { 71658247Seric int err; 71757232Seric char buf[MAXPATHLEN+1]; 71857136Seric 71957136Seric ep = strchr(pp, ':'); 72057136Seric if (ep != NULL) 72157136Seric *ep = '\0'; 72257136Seric expand(pp, buf, &buf[sizeof buf - 1], e); 72357136Seric if (ep != NULL) 72457136Seric *ep++ = ':'; 72557136Seric if (tTd(27, 3)) 72657136Seric printf("forward: trying %s\n", buf); 72763753Seric 72858247Seric err = include(buf, TRUE, user, sendq, e); 72958247Seric if (err == 0) 73057136Seric break; 73164325Seric else if (transienterror(err)) 73258247Seric { 73358247Seric /* we have to suspend this message */ 73459563Seric if (tTd(27, 2)) 73559563Seric printf("forward: transient error on %s\n", buf); 73659563Seric #ifdef LOG 73759563Seric if (LogLevel > 2) 73859624Seric syslog(LOG_ERR, "%s: forward %s: transient error: %s", 73966284Seric e->e_id == NULL ? "NOQUEUE" : e->e_id, 74066284Seric buf, errstring(err)); 74159563Seric #endif 74259611Seric message("%s: %s: message queued", buf, errstring(err)); 74363853Seric user->q_flags |= QQUEUEUP; 74458247Seric return; 74558247Seric } 74657136Seric } 747292Seric } 748