]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libc/net/nsdispatch.3
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libc / net / nsdispatch.3
1 .\"     $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $
2 .\"
3 .\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Luke Mewburn.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
18 .\"    contributors may be used to endorse or promote products derived
19 .\"    from this software without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 .\" POSSIBILITY OF SUCH DAMAGE.
32 .\"
33 .\" $FreeBSD$
34 .\"
35 .Dd April 4, 2010
36 .Dt NSDISPATCH 3
37 .Os
38 .Sh NAME
39 .Nm nsdispatch
40 .Nd name-service switch dispatcher routine
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/types.h
45 .In stdarg.h
46 .In nsswitch.h
47 .Ft int
48 .Fo nsdispatch
49 .Fa "void *retval"
50 .Fa "const ns_dtab dtab[]"
51 .Fa "const char *database"
52 .Fa "const char *method_name"
53 .Fa "const ns_src defaults[]"
54 .Fa "..."
55 .Fc
56 .Sh DESCRIPTION
57 The
58 .Fn nsdispatch
59 function invokes the methods specified in
60 .Va dtab
61 in the order given by
62 .Xr nsswitch.conf 5
63 for the database
64 .Va database
65 until a successful entry is found.
66 .Pp
67 .Va retval
68 is passed to each method to modify as necessary, to pass back results to
69 the caller of
70 .Fn nsdispatch .
71 .Pp
72 Each method has the function signature described by the typedef:
73 .Pp
74 .Ft typedef int
75 .Fn \*(lp*nss_method\*(rp "void *retval" "void *mdata" "va_list *ap" ;
76 .Pp
77 .Va dtab
78 is an array of
79 .Va ns_dtab
80 structures, which have the following format:
81 .Bd -literal -offset indent
82 typedef struct _ns_dtab {
83         const char      *src;
84         nss_method       method;
85         void            *mdata;
86 } ns_dtab;
87 .Ed
88 .Pp
89 .Bd -ragged -offset indent
90 The
91 .Fa dtab
92 array should consist of one entry for each source type that is
93 implemented, with
94 .Va src
95 as the name of the source,
96 .Va method
97 as a function which handles that source, and
98 .Va mdata
99 as a handle on arbitrary data to be passed to the method.
100 The last entry in
101 .Va dtab
102 should contain
103 .Dv NULL
104 values for
105 .Va src ,
106 .Va method ,
107 and
108 .Va mdata .
109 .Ed
110 .Pp
111 Additionally, methods may be implemented in NSS modules, in
112 which case they are selected using the
113 .Fa database
114 and
115 .Fa method_name
116 arguments along with the configured source.
117 (The methods supplied via
118 .Fa dtab
119 take priority over those implemented in NSS modules in the event
120 of a conflict.)
121 .Pp
122 .Va defaults
123 contains a list of default sources to try if
124 .Xr nsswitch.conf 5
125 is missing or corrupted, or if there is no relevant entry for
126 .Va database .
127 It is an array of
128 .Va ns_src
129 structures, which have the following format:
130 .Bd -literal -offset indent
131 typedef struct _ns_src {
132         const char      *src;
133         u_int32_t        flags;
134 } ns_src;
135 .Ed
136 .Pp
137 .Bd -ragged -offset indent
138 The
139 .Fa defaults
140 array should consist of one entry for each source to be configured by
141 default indicated by
142 .Va src ,
143 and
144 .Va flags
145 set to the criterion desired
146 (usually
147 .Dv NS_SUCCESS ;
148 refer to
149 .Sx Method return values
150 for more information).
151 The last entry in
152 .Va defaults
153 should have
154 .Va src
155 set to
156 .Dv NULL
157 and
158 .Va flags
159 set to 0.
160 .Pp
161 For convenience, a global variable defined as:
162 .Dl extern const ns_src __nsdefaultsrc[];
163 exists which contains a single default entry for the source
164 .Sq files
165 that may be used by callers which do not require complicated default
166 rules.
167 .Ed
168 .Pp
169 .Sq Va ...
170 are optional extra arguments, which are passed to the appropriate method
171 as a variable argument list of the type
172 .Vt va_list .
173 .Ss Valid source types
174 While there is support for arbitrary sources, the following
175 #defines for commonly implemented sources are available:
176 .Bl -column NSSRC_COMPAT compat -offset indent
177 .It Sy "#define value"
178 .It Dv NSSRC_FILES Ta """files""
179 .It Dv NSSRC_DB Ta """db""
180 .It Dv NSSRC_DNS Ta """dns""
181 .It Dv NSSRC_NIS Ta """nis""
182 .It Dv NSSRC_COMPAT Ta """compat""
183 .El
184 .Pp
185 Refer to
186 .Xr nsswitch.conf 5
187 for a complete description of what each source type is.
188 .Pp
189 .Ss Method return values
190 The
191 .Vt nss_method
192 functions must return one of the following values depending upon status
193 of the lookup:
194 .Bl -column "Return value" "Status code"
195 .It Sy "Return value    Status code"
196 .It Dv NS_SUCCESS Ta success
197 .It Dv NS_NOTFOUND Ta notfound
198 .It Dv NS_UNAVAIL Ta unavail
199 .It Dv NS_TRYAGAIN Ta tryagain
200 .It Dv NS_RETURN Ta -none-
201 .El
202 .Pp
203 Refer to
204 .Xr nsswitch.conf 5
205 for a complete description of each status code.
206 .Pp
207 The
208 .Fn nsdispatch
209 function returns the value of the method that caused the dispatcher to
210 terminate, or
211 .Dv NS_NOTFOUND
212 otherwise.
213 .Sh NOTES
214 .Fx Ns 's
215 .Lb libc
216 provides stubs for compatibility with NSS modules
217 written for the
218 .Tn GNU
219 C Library
220 .Nm nsswitch
221 interface.
222 However, these stubs only support the use of the
223 .Dq Li passwd
224 and
225 .Dq Li group
226 databases.
227 .Sh SEE ALSO
228 .Xr hesiod 3 ,
229 .Xr stdarg 3 ,
230 .Xr nsswitch.conf 5 ,
231 .Xr yp 8
232 .Sh HISTORY
233 The
234 .Fn nsdispatch
235 function first appeared in
236 .Fx 5.0 .
237 It was imported from the
238 .Nx
239 Project,
240 where it appeared first in
241 .Nx 1.4 .
242 Support for NSS modules first appeared in
243 .Fx 5.1 .
244 .Sh AUTHORS
245 Luke Mewburn
246 .Aq lukem@netbsd.org
247 wrote this freely-distributable name-service switch implementation,
248 using ideas from the
249 .Tn ULTRIX
250 svc.conf(5)
251 and
252 .Tn Solaris
253 nsswitch.conf(4)
254 manual pages.
255 The
256 .Fx
257 Project
258 added the support for threads and NSS modules, and normalized the uses
259 of
260 .Fn nsdispatch
261 within the standard C library.