1SETALIASENT(3) Linux Programmer's Manual SETALIASENT(3)
2
3
4
6 setaliasent, endaliasent, getaliasent, getaliasent_r, getaliasbyname,
7 getaliasbyname_r - read an alias entry
8
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
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
66 The functions getaliasent_r() and getaliasbyname_r() return a nonzero
67 value on error.
68
70 The default alias database is the file /etc/aliases. This can be
71 changed in the /etc/nsswitch.conf file.
72
74 For an explanation of the terms used in this section, see
75 attributes(7).
76
77 ┌────────────────────┬───────────────┬────────────────┐
78 │Interface │ Attribute │ Value │
79 ├────────────────────┼───────────────┼────────────────┤
80 │setaliasent(), │ Thread safety │ MT-Safe locale │
81 │endaliasent(), │ │ │
82 │getaliasent_r(), │ │ │
83 │getaliasbyname_r() │ │ │
84 ├────────────────────┼───────────────┼────────────────┤
85 │getaliasent(), │ Thread safety │ MT-Unsafe │
86 │getaliasbyname() │ │ │
87 └────────────────────┴───────────────┴────────────────┘
89 These routines are glibc-specific. The NeXT system has similar rou‐
90 tines:
91
92 #include <aliasdb.h>
93
94 void alias_setent(void);
95 void alias_endent(void);
96 alias_ent *alias_getent(void);
97 alias_ent *alias_getbyname(char *name);
98
100 The following example compiles with gcc example.c -o example. It will
101 dump all names in the alias database.
102
103 #include <aliases.h>
104 #include <stdio.h>
105 #include <stdlib.h>
106 #include <errno.h>
107
108 int
109 main(void)
110 {
111 struct aliasent *al;
112 setaliasent();
113 for (;;) {
114 al = getaliasent();
115 if (al == NULL)
116 break;
117 printf("Name: %s\n", al->alias_name);
118 }
119 if (errno) {
120 perror("reading alias");
121 exit(EXIT_FAILURE);
122 }
123 endaliasent();
124 exit(EXIT_SUCCESS);
125 }
126
128 getgrent(3), getpwent(3), getspent(3), aliases(5)
129
131 This page is part of release 5.02 of the Linux man-pages project. A
132 description of the project, information about reporting bugs, and the
133 latest version of this page, can be found at
134 https://www.kernel.org/doc/man-pages/.
135
136
137
138GNU 2019-03-06 SETALIASENT(3)