]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/net/nsdispatch.3
Don't call dlopen(3) for built-in NSS types - "cache", "compat",
[FreeBSD/FreeBSD.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 .\" 3. 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 October 15, 2018
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 The
90 .Fa dtab
91 array should consist of one entry for each source type that is
92 implemented, with
93 .Va src
94 as the name of the source,
95 .Va method
96 as a function which handles that source, and
97 .Va mdata
98 as a handle on arbitrary data to be passed to the method.
99 The last entry in
100 .Va dtab
101 should contain
102 .Dv NULL
103 values for
104 .Va src ,
105 .Va method ,
106 and
107 .Va mdata .
108 .Pp
109 Additionally, methods may be implemented in NSS modules, in
110 which case they are selected using the
111 .Fa database
112 and
113 .Fa method_name
114 arguments along with the configured source.
115 Modules must use source names different from the built-in ones.
116 .Pp
117 .Va defaults
118 contains a list of default sources to try if
119 .Xr nsswitch.conf 5
120 is missing or corrupted, or if there is no relevant entry for
121 .Va database .
122 It is an array of
123 .Va ns_src
124 structures, which have the following format:
125 .Bd -literal -offset indent
126 typedef struct _ns_src {
127         const char      *src;
128         uint32_t         flags;
129 } ns_src;
130 .Ed
131 .Pp
132 The
133 .Fa defaults
134 array should consist of one entry for each source to be configured by
135 default indicated by
136 .Va src ,
137 and
138 .Va flags
139 set to the criterion desired
140 (usually
141 .Dv NS_SUCCESS ;
142 refer to
143 .Sx Method return values
144 for more information).
145 The last entry in
146 .Va defaults
147 should have
148 .Va src
149 set to
150 .Dv NULL
151 and
152 .Va flags
153 set to 0.
154 .Pp
155 For convenience, a global variable defined as:
156 .Pp
157 .Dl extern const ns_src __nsdefaultsrc[];
158 .Pp
159 exists which contains a single default entry for the source
160 .Sq files
161 that may be used by callers which do not require complicated default
162 rules.
163 .Pp
164 .Sq Va ...
165 are optional extra arguments, which are passed to the appropriate method
166 as a variable argument list of the type
167 .Vt va_list .
168 .Ss Valid source types
169 While there is support for arbitrary sources, the following
170 #defines for commonly implemented sources are available:
171 .Bl -column NSSRC_COMPAT compat -offset indent
172 .It Sy "#define value"
173 .It Dv NSSRC_FILES Ta  \&"files\&"
174 .It Dv NSSRC_DB Ta \&"db\&"
175 .It Dv NSSRC_DNS Ta \&"dns\&"
176 .It Dv NSSRC_NIS Ta \&"nis\&"
177 .It Dv NSSRC_COMPAT Ta \&"compat\&"
178 .El
179 .Pp
180 Refer to
181 .Xr nsswitch.conf 5
182 for a complete description of what each source type is.
183 .Ss Method return values
184 The
185 .Vt nss_method
186 functions must return one of the following values depending upon status
187 of the lookup:
188 .Bl -column "Return value" "Status code"
189 .It Sy "Return value    Status code"
190 .It Dv NS_SUCCESS Ta success
191 .It Dv NS_NOTFOUND Ta notfound
192 .It Dv NS_UNAVAIL Ta unavail
193 .It Dv NS_TRYAGAIN Ta tryagain
194 .It Dv NS_RETURN Ta -none-
195 .El
196 .Pp
197 Refer to
198 .Xr nsswitch.conf 5
199 for a complete description of each status code.
200 .Pp
201 The
202 .Fn nsdispatch
203 function returns the value of the method that caused the dispatcher to
204 terminate, or
205 .Dv NS_NOTFOUND
206 otherwise.
207 .Sh NOTES
208 .Fx Ns 's
209 .Lb libc
210 provides stubs for compatibility with NSS modules
211 written for the
212 .Tn GNU
213 C Library
214 .Nm nsswitch
215 interface.
216 However, these stubs only support the use of the
217 .Dq Li passwd
218 and
219 .Dq Li group
220 databases.
221 .Sh SEE ALSO
222 .Xr hesiod 3 ,
223 .Xr stdarg 3 ,
224 .Xr nsswitch.conf 5 ,
225 .Xr yp 8
226 .Sh HISTORY
227 The
228 .Fn nsdispatch
229 function first appeared in
230 .Fx 5.0 .
231 It was imported from the
232 .Nx
233 Project,
234 where it appeared first in
235 .Nx 1.4 .
236 Support for NSS modules first appeared in
237 .Fx 5.1 .
238 .Sh AUTHORS
239 .An Luke Mewburn Aq Mt lukem@netbsd.org
240 wrote this freely-distributable name-service switch implementation,
241 using ideas from the
242 .Tn ULTRIX
243 svc.conf(5)
244 and
245 .Tn Solaris
246 nsswitch.conf(4)
247 manual pages.
248 The
249 .Fx
250 Project
251 added the support for threads and NSS modules, and normalized the uses
252 of
253 .Fn nsdispatch
254 within the standard C library.