d9311a96046f7e45aafd9cce88b6f8973e1eacc6
static char SccsId
[] = "@(#)alias.c 3.19 %G% (with DBM)";
static char SccsId
[] = "@(#)alias.c 3.19 %G% (without DBM)";
** ALIAS -- Compute aliases.
** Scans the file /usr/lib/aliases for a set of aliases.
** If found, it arranges to deliver to them. Uses libdbm
** a -- address to alias.
** Aliases found are expanded.
** /usr/lib/aliases -- the mail aliases. The format is
** a series of lines of the form:
** alias:name1,name2,name3,...
** where 'alias' expands to all of
** 'name[i]'. Continuations begin with
** /usr/lib/aliases.pag, /usr/lib/aliases.dir: libdbm version
** of alias file. Keys are aliases, datums
** (data?) are name1,name2, ...
** If NoAlias (the "-n" flag) is set, no aliasing is
** It should complain about names that are aliased to
** It is unsophisticated about line overflows.
printf("alias(%s)\n", a
->q_paddr
);
/* don't realias already aliased names */
if (bitset(QDONTSEND
, a
->q_flags
))
/* create a key for fetch */
lhs
.dsize
= strlen(a
->q_user
) + 1;
s
= stab(a
->q_user
, ST_ALIAS
, ST_FIND
);
** Deliver to the target list.
printf("%s (%s, %s) aliased to %s\n",
a
->q_paddr
, a
->q_host
, a
->q_user
, p
);
message(Arpa_Info
, "aliased to %s", p
);
** INITALIASES -- initialize for aliasing
** Very different depending on whether we are running DBM or not.
** aliasfile -- location of aliases.
** init -- if set and if DBM, initialize the DBM files.
** if DBM: opens the database.
** if ~DBM: reads the aliases into the symbol table.
initaliases(aliasfile
, init
)
(void) strcpy(buf
, aliasfile
);
(void) strcat(buf
, ".dir");
if (close(creat(buf
, DBMMODE
)) < 0)
syserr("cannot make %s", buf
);
(void) strcpy(buf
, aliasfile
);
(void) strcat(buf
, ".pag");
if (close(creat(buf
, DBMMODE
)) < 0)
syserr("cannot make %s", buf
);
readaliases(aliasfile
, TRUE
);
readaliases(aliasfile
, init
);
** READALIASES -- read and process the alias file.
** This routine implements the part of initaliases that occurs
** when we are not going to use the DBM stuff.
** aliasfile -- the pathname of the alias file master.
** init -- if set, initialize the DBM stuff.
** Reads aliasfile into the symbol table.
** Optionally, builds the .dir & .pag files.
readaliases(aliasfile
, init
)
if ((af
= fopen(aliasfile
, "r")) == NULL
)
printf("Can't open %s\n", aliasfile
);
** Read and interpret lines
while (fgets(line
, sizeof (line
), af
) != NULL
)
syserr("aliases: %d: Non-continuation line starts with space", lineno
);
** Find the final colon, and parse the address.
** It should resolve to a local name -- this will
** be checked later (we want to optionally do
** parsing of the RHS first to maximize error
for (p
= line
; *p
!= '\0' && *p
!= ':' && *p
!= '\n'; p
++)
if (*p
== '\0' || *p
== '\n')
syserr("aliases: %d: missing colon", lineno
);
if (parse(line
, &al
, 1) == NULL
)
** 'al' is the internal form of the LHS address.
** 'p' points to the text of the RHS.
/* do parsing & compression of addresses */
while (*p
!= '\n' && *p
!= ',' && *p
!= '\0')
(void) parse(p2
, &bl
, -1);
/* see if there should be a continuation line */
if (c
!= ' ' && c
!= '\t')
/* read continuation line */
if (fgets(p
, sizeof line
- (p
- line
), af
) == NULL
)
if (al
.q_mailer
!= MN_LOCAL
)
syserr("aliases: %d: cannot alias non-local names", lineno
);
** Insert alias into symbol table or DBM file
key
.dsize
= strlen(al
.q_user
) + 1;
content
.dsize
= strlen(rhs
) + 1;
s
= stab(al
.q_user
, ST_ALIAS
, ST_ENTER
);
s
->s_alias
= newstr(rhs
);
** FORWARD -- Try to forward mail
** This is similar but not identical to aliasing.
** user -- the name of the user who's mail we would like
** to forward to. It must have been verified --
** i.e., the q_home field must have been filled
** New names are added to send queues.
** Sets the QDONTSEND bit in addresses that are forwarded.
printf("forward(%s)\n", user
->q_paddr
);
if (user
->q_mailer
!= MN_LOCAL
|| bitset(QBADADDR
, user
->q_flags
))
if (user
->q_home
== NULL
)
syserr("forward: no home");
/* good address -- look for .forward file in home */
define('z', user
->q_home
);
(void) expand("$z/.forward", buf
, &buf
[sizeof buf
- 1]);
if (stat(buf
, &stbuf
) < 0 || stbuf
.st_uid
!= user
->q_uid
||
!bitset(S_IREAD
, stbuf
.st_mode
))
/* we do have an address to forward to -- do it */
user
->q_flags
|= QDONTSEND
;
include(buf
, "forwarding");