]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/setaliasent.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / setaliasent.3
1 .\" Copyright 2003 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
2 .\" Distributed under GPL
3 .\"
4 .\" Polished a bit, added a little, aeb
5 .\"
6 .TH SETALIASENT 3 2003-09-09 "GNU" "access mail aliases database"
7 .SH NAME
8 setaliasent, endaliasent, getaliasent, getaliasent_r,
9 getaliasbyname, getaliasbyname_r \- read an alias entry
10 .SH SYNOPSIS
11 .B #include <aliases.h>
12 .sp
13 .BI "void setaliasent(void);"
14 .sp
15 .BI "void endaliasent(void);"
16 .sp
17 .BI "struct aliasent *getaliasent(void);"
18 .sp
19 .BI "int getaliasent_r(struct aliasent *" result ","
20 .br
21 .BI " char *" buffer ", size_t " buflen ", struct aliasent **" res );
22 .sp
23 .BI "struct aliasent *getaliasbyname(const char *" name );
24 .sp
25 .BI "int getaliasbyname_r(const char *" name ,
26 .br
27 .BI " struct aliasent *" result ,
28 .br
29 .BI " char *" buffer ", size_t " buflen ", struct aliasent **" res );
30 .sp
31 .SH DESCRIPTION
32 One of the databases available with the Name Service Switch (NSS)
33 is the aliases database, that contains mail aliases. (To find out
34 which databases are supported, try getent \-\-help .)
35 Six functions are provided to access the aliases database.
36 .PP
37 The
38 .BR getaliasent ()
39 function returns a pointer to a structure containing
40 the group information from the aliases database.
41 The first time it is called it returns the first entry;
42 thereafter, it returns successive entries.
43 .PP
44 The
45 .BR setaliasent ()
46 function rewinds the file pointer to the beginning of the
47 aliases database.
48 .PP
49 The
50 .BR endaliasent ()
51 function closes the aliases database.
52 .PP
53 .BR getaliasent_r ()
54 is the reentrant version of the previous function. The requested structure
55 is stored via the first argument but the programmer needs to fill the other
56 arguments also. Not providing enough space causes the function to fail.
57 .PP
58 The function
59 .BR getaliasbyname ()
60 takes the name argument and searches the aliases database. The entry is
61 returned as a pointer to a struct aliasent.
62 .PP
63 .BR getaliasbyname_r ()
64 is the reentrant version of the previous function. The requested structure
65 is stored via the second argument but the programmer need to fill the other
66 arguments also. Not providing enough space causes the function to fail.
67 .PP
68 The struct aliasent is defined in <aliases.h>.
69 .nf
70 struct aliasent {
71 char *alias_name; /* alias name */
72 size_t alias_members_len;
73 char **alias_members; /* alias name list */
74 int alias_local;
75 };
76 .fi
77 .SH FILES
78 The default alias database is the file
79 .IR /etc/aliases .
80 This can be changed in the
81 .I /etc/nsswitch.conf
82 file.
83 .SH "RETURN VALUE"
84 The functions
85 .BR getaliasent_r ()
86 and
87 .BR getaliasbyname_r ()
88 return a non-zero value on error.
89 .SH EXAMPLE
90 The following example compiles with
91 .IR "gcc example.c \-o example" .
92 It will dump all names in the alias database.
93 .sp
94 .nf
95 #include <aliases.h>
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <errno.h>
99
100 int main() {
101 struct aliasent *al;
102 setaliasent();
103 for (;;) {
104 al = getaliasent();
105 if (al == NULL) break;
106 printf("Name: %s\\n", al->alias_name);
107 }
108 if (errno) {
109 perror("reading alias");
110 exit(EXIT_FAILURE);
111 }
112 endaliasent();
113 exit(EXIT_SUCCESS);
114 }
115 .fi
116 .SH "CONFORMING TO"
117 These routines are glibc-specific.
118 The NeXT has similar routines
119 .RS
120 .nf
121 #include <aliasdb.h>
122 void alias_setent(void);
123 void alias_endent(void);
124 alias_ent *alias_getent(void);
125 alias_ent *alias_getbyname(char *name);
126 .fi
127 .RE
128 .SH "SEE ALSO"
129 .BR getgrent (3),
130 .BR getpwent (3),
131 .BR getspent (3),
132 .BR aliases (5)
133 .\"
134 .\" /etc/sendmail/aliases
135 .\" Yellow Pages
136 .\" newaliases, postalias