Debian Codegraph @

upstream/debian-unstable/man3/setaliasent.3

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