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