OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / 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 2003-09-09 "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 .sp
16 .B "void setaliasent(void);"
17 .sp
18 .B "void endaliasent(void);"
19 .sp
20 .B "struct aliasent *getaliasent(void);"
21 .sp
22 .BI "int getaliasent_r(struct aliasent *" result ","
23 .br
24 .BI "        char *" buffer ", size_t " buflen ", struct aliasent **" res );
25 .sp
26 .BI "struct aliasent *getaliasbyname(const char *" name );
27 .sp
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  \fIgetent \-\-help\fP.)
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.
55 The requested structure
56 is stored via the first argument but the programmer needs to fill the other
57 arguments also.
58 Not providing enough space causes the function to fail.
59 .PP
60 The function
61 .BR getaliasbyname ()
62 takes the name argument and searches the aliases database.
63 The entry is returned as a pointer to a
64 .IR "struct aliasent" .
65 .PP
66 .BR getaliasbyname_r ()
67 is the reentrant version of the previous function.
68 The requested structure
69 is stored via the second argument but the programmer needs to fill the other
70 arguments also.
71 Not providing enough space causes the function to fail.
72 .PP
73 The
74 .I "struct aliasent"
75 is defined in
76 .IR <aliases.h> :
77 .in +4n
78 .nf
79
80 struct aliasent {
81     char    *alias_name;             /* alias name */
82     size_t   alias_members_len;
83     char   **alias_members;          /* alias name list */
84     int      alias_local;
85 };
86 .fi
87 .in
88 .SH RETURN VALUE
89 The functions
90 .BR getaliasent_r ()
91 and
92 .BR getaliasbyname_r ()
93 return a nonzero value on error.
94 .SH FILES
95 The default alias database is the file
96 .IR /etc/aliases .
97 This can be changed in the
98 .I /etc/nsswitch.conf
99 file.
100 .SH CONFORMING TO
101 These routines are glibc-specific.
102 The NeXT system has similar routines:
103 .in +4n
104 .nf
105
106 #include <aliasdb.h>
107
108 void alias_setent(void);
109 void alias_endent(void);
110 alias_ent *alias_getent(void);
111 alias_ent *alias_getbyname(char *name);
112 .fi
113 .in
114 .SH EXAMPLE
115 The following example compiles with
116 .IR "gcc example.c \-o example" .
117 It will dump all names in the alias database.
118 .sp
119 .nf
120 #include <aliases.h>
121 #include <stdio.h>
122 #include <stdlib.h>
123 #include <errno.h>
124
125 int
126 main(void)
127 {
128     struct aliasent *al;
129     setaliasent();
130     for (;;) {
131         al = getaliasent();
132         if (al == NULL)
133             break;
134         printf("Name: %s\\n", al\->alias_name);
135     }
136     if (errno) {
137         perror("reading alias");
138         exit(EXIT_FAILURE);
139     }
140     endaliasent();
141     exit(EXIT_SUCCESS);
142 }
143 .fi
144 .SH SEE ALSO
145 .BR getgrent (3),
146 .BR getpwent (3),
147 .BR getspent (3),
148 .BR aliases (5)
149 .\"
150 .\" /etc/sendmail/aliases
151 .\" Yellow Pages
152 .\" newaliases, postalias