1SETALIASENT(3)             Linux Programmer's Manual            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, struct aliasent *result,
24               char *buffer, size_t buflen, struct aliasent **res);
25

DESCRIPTION

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

RETURN VALUE

66       The  functions  getaliasent_r() and getaliasbyname_r() return a nonzero
67       value on error.
68

FILES

70       The default alias database is  the  file  /etc/aliases.   This  can  be
71       changed in the /etc/nsswitch.conf file.
72

CONFORMING TO

74       These  routines  are  glibc-specific.  The NeXT system has similar rou‐
75       tines:
76
77           #include <aliasdb.h>
78
79           void alias_setent(void);
80           void alias_endent(void);
81           alias_ent *alias_getent(void);
82           alias_ent *alias_getbyname(char *name);
83

EXAMPLE

85       The following example compiles with gcc example.c -o example.  It  will
86       dump all names in the alias database.
87
88       #include <aliases.h>
89       #include <stdio.h>
90       #include <stdlib.h>
91       #include <errno.h>
92
93       int
94       main(void)
95       {
96           struct aliasent *al;
97           setaliasent();
98           for (;;) {
99               al = getaliasent();
100               if (al == NULL)
101                   break;
102               printf("Name: %s\n", al->alias_name);
103           }
104           if (errno) {
105               perror("reading alias");
106               exit(EXIT_FAILURE);
107           }
108           endaliasent();
109           exit(EXIT_SUCCESS);
110       }
111

SEE ALSO

113       getgrent(3), getpwent(3), getspent(3), aliases(5)
114

COLOPHON

116       This  page  is  part of release 3.53 of the Linux man-pages project.  A
117       description of the project, and information about reporting  bugs,  can
118       be found at http://www.kernel.org/doc/man-pages/.
119
120
121
122GNU                               2003-09-09                    SETALIASENT(3)
Impressum