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 non-zero
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 has similar routines:
75
76           #include <aliasdb.h>
77
78           void alias_setent(void);
79           void alias_endent(void);
80           alias_ent *alias_getent(void);
81           alias_ent *alias_getbyname(char *name);
82

EXAMPLE

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

SEE ALSO

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

COLOPHON

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