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