1SETALIASENT(3)           access mail aliases database           SETALIASENT(3)
2
3
4

NAME

6       setaliasent,  endaliasent,  getaliasent, getaliasent_r, getaliasbyname,
7       getaliasbyname_r - read an alias entry
8

SYNOPSIS

10       #include <aliases.h>
11
12       void setaliasent(void);
13
14       void endaliasent(void);
15
16       struct aliasent *getaliasent(void);
17
18       int getaliasent_r(struct aliasent *result,
19           char *buffer, size_t buflen, struct aliasent **res);
20
21       struct aliasent *getaliasbyname(const char *name);
22
23       int getaliasbyname_r(const char *name,
24           struct aliasent *result,
25           char *buffer, size_t buflen, struct aliasent **res);
26
27

DESCRIPTION

29       One of the databases available with the Name Service  Switch  (NSS)  is
30       the  aliases  database,  that contains mail aliases. (To find out which
31       databases are supported, try  getent --help .)  Six functions are  pro‐
32       vided to access the aliases database.
33
34       The  getaliasent() function returns a pointer to a structure containing
35       the group information from the aliases database.  The first time it  is
36       called  it  returns  the first entry; thereafter, it returns successive
37       entries.
38
39       The setaliasent() function rewinds the file pointer to the beginning of
40       the aliases database.
41
42       The endaliasent() function closes the aliases database.
43
44       getaliasent_r()  is the reentrant version of the previous function. The
45       requested structure is stored via the first argument but the programmer
46       needs  to  fill  the  other  arguments also. Not providing enough space
47       causes the function to fail.
48
49       The function getaliasbyname() takes the name argument and searches  the
50       aliases  database.  The  entry  is  returned  as  a pointer to a struct
51       aliasent.
52
53       getaliasbyname_r() is the reentrant version of the  previous  function.
54       The  requested structure is stored via the second argument but the pro‐
55       grammer need to fill the other arguments  also.  Not  providing  enough
56       space causes the function to fail.
57
58       The struct aliasent is defined in <aliases.h>.
59       struct aliasent {
60           char *alias_name;              /* alias name */
61           size_t alias_members_len;
62           char **alias_members;          /* alias name list */
63           int alias_local;
64       };
65

FILES

67       The  default  alias  database  is  the  file /etc/aliases.  This can be
68       changed in the /etc/nsswitch.conf file.
69

RETURN VALUE

71       The functions getaliasent_r() and getaliasbyname_r() return a  non-zero
72       value on error.
73

EXAMPLE

75       The  following example compiles with gcc example.c -o example.  It will
76       dump all names in the alias database.
77
78       #include <aliases.h>
79       #include <stdio.h>
80       #include <stdlib.h>
81       #include <errno.h>
82
83       int main() {
84         struct aliasent *al;
85         setaliasent();
86         for (;;) {
87           al = getaliasent();
88           if (al == NULL) break;
89           printf("Name: %s\n", al->alias_name);
90         }
91         if (errno) {
92             perror("reading alias");
93             exit(EXIT_FAILURE);
94         }
95         endaliasent();
96         exit(EXIT_SUCCESS);
97       }
98

CONFORMING TO

100       These routines are glibc-specific.  The NeXT has similar routines
101              #include <aliasdb.h>
102              void alias_setent(void);
103              void alias_endent(void);
104              alias_ent *alias_getent(void);
105              alias_ent *alias_getbyname(char *name);
106

SEE ALSO

108       getgrent(3), getpwent(3), getspent(3), aliases(5)
109
110
111
112GNU                               2003-09-09                    SETALIASENT(3)
Impressum