Debian Codegraph @

upstream/debian-trixie/man3/setaliasent.3

raw
1 '\" t
2 .\" Copyright 2003 Walter Harms ([email protected])
3 .\"
4 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\"
6 .\" Polished a bit, added a little, aeb
7 .\"
8 .TH setaliasent 3 2024-06-15 "Linux man-pages 6.9.1"
9 .SH NAME
10 setaliasent, endaliasent, getaliasent, getaliasent_r,
11 getaliasbyname, getaliasbyname_r \- read an alias entry
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <aliases.h>
18 .P
19 .B "void setaliasent(void);"
20 .B "void endaliasent(void);"
21 .P
22 .B "struct aliasent *getaliasent(void);"
23 .BI "int getaliasent_r(struct aliasent *restrict " result ,
24 .BI " char " buffer "[restrict ." buflen "], \
25 size_t " buflen ,
26 .BI " struct aliasent **restrict " res );
27 .P
28 .BI "struct aliasent *getaliasbyname(const char *" name );
29 .BI "int getaliasbyname_r(const char *restrict " name ,
30 .BI " struct aliasent *restrict " result ,
31 .BI " char " buffer "[restrict ." buflen "], \
32 size_t " buflen ,
33 .BI " struct aliasent **restrict " res );
34 .fi
35 .SH DESCRIPTION
36 One of the databases available with the Name Service Switch (NSS)
37 is the aliases database, that contains mail aliases.
38 (To find out which databases are supported, try
39 .IR "getent \-\-help" .)
40 Six functions are provided to access the aliases database.
41 .P
42 The
43 .BR getaliasent ()
44 function returns a pointer to a structure containing
45 the group information from the aliases database.
46 The first time it is called it returns the first entry;
47 thereafter, it returns successive entries.
48 .P
49 The
50 .BR setaliasent ()
51 function rewinds the file pointer to the beginning of the
52 aliases database.
53 .P
54 The
55 .BR endaliasent ()
56 function closes the aliases database.
57 .P
58 .BR getaliasent_r ()
59 is the reentrant version of the previous function.
60 The requested structure
61 is stored via the first argument but the programmer needs to fill the other
62 arguments also.
63 Not providing enough space causes the function to fail.
64 .P
65 The function
66 .BR getaliasbyname ()
67 takes the name argument and searches the aliases database.
68 The entry is returned as a pointer to a
69 .IR "struct aliasent" .
70 .P
71 .BR getaliasbyname_r ()
72 is the reentrant version of the previous function.
73 The requested structure
74 is stored via the second argument but the programmer needs to fill the other
75 arguments also.
76 Not providing enough space causes the function to fail.
77 .P
78 The
79 .I "struct aliasent"
80 is defined in
81 .IR <aliases.h> :
82 .P
83 .in +4n
84 .EX
85 struct aliasent {
86 char *alias_name; /* alias name */
87 size_t alias_members_len;
88 char **alias_members; /* alias name list */
89 int alias_local;
90 };
91 .EE
92 .in
93 .SH RETURN VALUE
94 The functions
95 .BR getaliasent_r ()
96 and
97 .BR getaliasbyname_r ()
98 return a nonzero value on error.
99 .SH FILES
100 The default alias database is the file
101 .IR /etc/aliases .
102 This can be changed in the
103 .I /etc/nsswitch.conf
104 file.
105 .SH ATTRIBUTES
106 For an explanation of the terms used in this section, see
107 .BR attributes (7).
108 .TS
109 allbox;
110 lbx lb lb
111 l l l.
112 Interface Attribute Value
113 T{
114 .na
115 .nh
116 .BR setaliasent (),
117 .BR endaliasent (),
118 .BR getaliasent_r (),
119 .BR getaliasbyname_r ()
120 T} Thread safety MT-Safe locale
121 T{
122 .na
123 .nh
124 .BR getaliasent (),
125 .BR getaliasbyname ()
126 T} Thread safety MT-Unsafe
127 .TE
128 .SH STANDARDS
129 GNU.
130 .SH HISTORY
131 The NeXT system has similar routines:
132 .P
133 .in +4n
134 .EX
135 #include <aliasdb.h>
136 \&
137 void alias_setent(void);
138 void alias_endent(void);
139 alias_ent *alias_getent(void);
140 alias_ent *alias_getbyname(char *name);
141 .EE
142 .in
143 .SH EXAMPLES
144 The following example compiles with
145 .IR "gcc example.c \-o example" .
146 It will dump all names in the alias database.
147 .P
148 .\" SRC BEGIN (setaliasent.c)
149 .EX
150 #include <aliases.h>
151 #include <errno.h>
152 #include <stdio.h>
153 #include <stdlib.h>
154 \&
155 int
156 main(void)
157 {
158 struct aliasent *al;
159 \&
160 setaliasent();
161 for (;;) {
162 al = getaliasent();
163 if (al == NULL)
164 break;
165 printf("Name: %s\[rs]n", al\->alias_name);
166 }
167 if (errno) {
168 perror("reading alias");
169 exit(EXIT_FAILURE);
170 }
171 endaliasent();
172 exit(EXIT_SUCCESS);
173 }
174 .EE
175 .\" SRC END
176 .SH SEE ALSO
177 .BR getgrent (3),
178 .BR getpwent (3),
179 .BR getspent (3),
180 .BR aliases (5)
181 .\"
182 .\" /etc/sendmail/aliases
183 .\" Yellow Pages
184 .\" newaliases, postalias