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       void endaliasent(void);
14
15       struct aliasent *getaliasent(void);
16       int getaliasent_r(struct aliasent *restrict result,
17                            char *restrict buffer, size_t buflen,
18                            struct aliasent **restrict res);
19
20       struct aliasent *getaliasbyname(const char *name);
21       int getaliasbyname_r(const char *restrict name,
22                            struct aliasent *restrict result,
23                            char *restrict buffer, size_t buflen,
24                            struct aliasent **restrict 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

ATTRIBUTES

74       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
75       tributes(7).
76
77       ┌─────────────────────────────────────┬───────────────┬────────────────┐
78Interface                            Attribute     Value          
79       ├─────────────────────────────────────┼───────────────┼────────────────┤
80setaliasent(), endaliasent(),        │ Thread safety │ MT-Safe locale │
81getaliasent_r(), getaliasbyname_r()  │               │                │
82       ├─────────────────────────────────────┼───────────────┼────────────────┤
83getaliasent(), getaliasbyname()      │ Thread safety │ MT-Unsafe      │
84       └─────────────────────────────────────┴───────────────┴────────────────┘
85

CONFORMING TO

87       These  routines  are  glibc-specific.  The NeXT system has similar rou‐
88       tines:
89
90           #include <aliasdb.h>
91
92           void alias_setent(void);
93           void alias_endent(void);
94           alias_ent *alias_getent(void);
95           alias_ent *alias_getbyname(char *name);
96

EXAMPLES

98       The following example compiles with gcc example.c -o example.  It  will
99       dump all names in the alias database.
100
101       #include <aliases.h>
102       #include <stdio.h>
103       #include <stdlib.h>
104       #include <errno.h>
105
106       int
107       main(void)
108       {
109           struct aliasent *al;
110           setaliasent();
111           for (;;) {
112               al = getaliasent();
113               if (al == NULL)
114                   break;
115               printf("Name: %s\n", al->alias_name);
116           }
117           if (errno) {
118               perror("reading alias");
119               exit(EXIT_FAILURE);
120           }
121           endaliasent();
122           exit(EXIT_SUCCESS);
123       }
124

SEE ALSO

126       getgrent(3), getpwent(3), getspent(3), aliases(5)
127

COLOPHON

129       This  page  is  part of release 5.13 of the Linux man-pages project.  A
130       description of the project, information about reporting bugs,  and  the
131       latest     version     of     this    page,    can    be    found    at
132       https://www.kernel.org/doc/man-pages/.
133
134
135
136GNU                               2021-03-22                    SETALIASENT(3)
Impressum