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