1setaliasent(3)             Library Functions Manual             setaliasent(3)
2
3
4

NAME

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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

69       The  functions  getaliasent_r() and getaliasbyname_r() return a nonzero
70       value on error.
71

FILES

73       The default alias database is  the  file  /etc/aliases.   This  can  be
74       changed in the /etc/nsswitch.conf file.
75

ATTRIBUTES

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

STANDARDS

90       GNU.
91

HISTORY

93       The NeXT system has similar routines:
94
95           #include <aliasdb.h>
96
97           void alias_setent(void);
98           void alias_endent(void);
99           alias_ent *alias_getent(void);
100           alias_ent *alias_getbyname(char *name);
101

EXAMPLES

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

SEE ALSO

132       getgrent(3), getpwent(3), getspent(3), aliases(5)
133
134
135
136Linux man-pages 6.04              2023-03-30                    setaliasent(3)
Impressum