1 .\" $NetBSD: nsdispatch.3,v 1.31 2011/04/28 16:16:23 wiz Exp $
3 .\" Copyright (c) 1997, 1998, 1999, 2004, 2005, 2008
4 .\" The NetBSD Foundation, Inc.
5 .\" All rights reserved.
7 .\" This code is derived from software contributed to The NetBSD Foundation
8 .\" by Luke Mewburn; and by Jason R. Thorpe.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
19 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd name-service switch dispatcher routine
44 .Fa "const ns_dtab dtab[]"
45 .Fa "const char *database"
46 .Fa "const char *name"
47 .Fa "const ns_src defaults[]"
53 function invokes the callback functions specified in
56 .Pa /etc/nsswitch.conf
59 until the action criteria for a source of that database is fulfilled.
62 is passed to each callback function to use as necessary
63 (to pass back to the caller of
69 structures, which have the following format:
70 .Bl -item -offset indent
82 array should consist of one entry for each source type that has a
83 static implementation,
86 as the name of the source,
88 as a callback function which handles that source, and
90 as a pointer to arbitrary data to be passed to the callback function.
101 The callback function signature is described by the typedef:
102 .Bd -ragged -offset indent
104 .Fo \*(lp*nss_method\*(rp
109 .Bl -tag -width cbdata
119 member of the array entry for the source that this
120 callback function implements in the
138 are used to select methods from optional per-source
139 dynamically-loaded modules.
141 is usually the name of the function calling
143 Note that the callback functions provided by
145 take priority over those implemented in dynamically-loaded modules in the
149 contains a list of default sources to try in the case of
151 .Xr nsswitch.conf 5 ,
152 or if there isn't a relevant entry for
156 structures, which have the following format:
157 .Bl -item -offset indent
168 array should consist of one entry for each source to consult by default
173 set to the desired behavior
177 .Sx Callback function return values
178 for more information).
193 need to force all callback functions to be invoked,
194 irrespective of the action criteria listed in
195 .Xr nsswitch.conf 5 .
196 This can be achieved by adding
199 .Fa defaults[0].flags
204 will be the result of the final callback function invoked.
206 For convenience, a global variable defined as:
207 .Dl extern const ns_src __nsdefaultsrc[];
208 exists which contains a single default entry for
210 for use by callers which don't require complicated default rules.
214 are optional extra arguments, which
215 are passed to the appropriate callback function as a
222 returns the value of the callback function that caused the dispatcher
227 .Ss Dynamically-loaded module interface
230 function loads callback functions from the run-time link-editor's search
231 path using the following naming convention:
232 .Bl -item -offset indent
235 nss_\*[Lt]source\*[Gt].so.\*[Lt]version\*[Gt]
237 .Bl -tag -width XversionX
239 The source that the module implements.
243 module interface version, which is defined by the integer
244 .Dv NSS_MODULE_INTERFACE_VERSION ,
245 which has the value 0.
249 When a module is loaded,
251 looks for and calls the following function in the module:
253 .Bd -ragged -offset indent
255 .Fo nss_module_register
256 .Fa "const char *source"
258 .Fa "nss_module_unregister_fn *unreg"
261 .Bl -tag -width source
263 The name of the source that the module implements, as used by
265 to construct the module's name.
267 A pointer to an unsigned integer that
268 .Fn nss_module_register
269 should set to the number of elements in the
272 .Fn nss_module_register ,
275 if there was a failure.
277 A pointer to a function pointer that
278 .Fn nss_module_register
279 can optionally set to an unregister function to be invoked when the module is
286 The unregister function signature is described by the typedef:
288 .Bd -ragged -offset indent
290 .Fo \*(lp*nss_module_unregister_fn\*(rp
295 .Bl -tag -width nelems
299 structures returned by
300 .Fn nss_module_register .
305 .Fn nss_module_register .
309 .Fn nss_module_register
317 if there was a failure.
320 structures have the following format:
321 .Bl -item -offset indent
325 const char *database;
334 array should consist of one entry for each callback function (method)
338 as the name of the database,
340 as the name of the callback function,
344 callback function that implements the method, and
346 as a pointer to arbitrary data to be passed to the callback function as its
351 .Ss Valid source types
352 While there is support for arbitrary sources, the following
353 #defines for commonly implemented sources are provided:
354 .Bl -column NSSRC_COMPAT COMPAT -offset indent
356 .It NSSRC_FILES "files"
359 .It NSSRC_COMPAT "compat"
364 for a complete description of what each source type is.
366 .Ss Valid database types
367 While there is support for arbitrary databases, the following
368 #defines for currently implemented system databases are provided:
369 .Bl -column NSDB_PASSWD_COMPAT PASSWD_COMPAT -offset indent
371 .It NSDB_HOSTS "hosts"
372 .It NSDB_GROUP "group"
373 .It NSDB_GROUP_COMPAT "group_compat"
374 .It NSDB_NETGROUP "netgroup"
375 .It NSDB_NETWORKS "networks"
376 .It NSDB_PASSWD "passwd"
377 .It NSDB_PASSWD_COMPAT "passwd_compat"
378 .It NSDB_SHELLS "shells"
383 for a complete description of what each database is.
385 .Ss Callback function return values
386 The callback functions should return one of the following values
387 depending upon status of the lookup:
388 .Bl -column NS_NOTFOUND -offset indent
389 .It Sy "Return value" Status code
390 .It NS_SUCCESS The requested entry was found.
391 .It NS_NOTFOUND The entry is not present at this source.
392 .It NS_TRYAGAIN The source is busy, and may respond to retries.
393 .It NS_UNAVAIL The source is not responding, or entry is corrupt.
396 .Sh CALLBACK FUNCTION API FOR STANDARD DATABASES
397 The organization of the
401 callback function for a standard method in a standard database is:
402 .Bl -enum -offset indent -compact
404 Pointer to return value of the standard function.
406 First argument of the standard function.
411 For example, given the standard function
413 .Bd -ragged -offset indent -compact
415 .Fn getgrnam "const char *name"
419 organization used by the callback functions is:
420 .Bl -enum -offset indent -compact
422 .Ft "struct group **"
428 Not all standard databases are using this calling convention yet;
429 those that aren't are noted below.
430 These will be changed in the future.
432 The callback function names and
434 organization for various standard database callback functions are:
436 .Ss Methods for hosts database
438 The method APIs for this database will be changing in the near future.
442 .Ft "const struct addrinfo *pai"
445 .Ft "struct addrinfo *"
449 .Ft "unsigned char *addr" ,
454 .Ft "struct hostent *"
463 .Ft "struct hostent *"
468 .Ss Methods for group and group_compat databases
474 All methods for all sources are invoked for this method name.
476 .Ft "struct group **retval"
479 should be set to a pointer to an internal static
496 .Ft "struct group *grp" ,
498 .Ft "size_t buflen" ,
499 .Ft "struct group **result"
502 should be set to an appropriate
518 .Ft "struct group **retval" ,
522 should be set to a pointer to an internal static
540 .Ft "struct group *grp" ,
542 .Ft "size_t buflen" ,
543 .Ft "struct group **result"
546 should be set to an appropriate
562 .Ft "struct group **retval" ,
563 .Ft "const char *name"
566 should be set to a pointer to an internal static
583 .Ft "const char *name" ,
584 .Ft "struct group *grp" ,
586 .Ft "size_t buflen" ,
587 .Ft "struct group **result"
590 should be set to an appropriate
605 .It Sy getgroupmembership
607 .Ft "const char *name" ,
608 .Ft "gid_t basegid" ,
609 .Ft "gid_t *groups" ,
620 was returned to prevent multiple
622 compat entries from being expanded.
624 .Xr getgroupmembership 3
636 should be set to 0 on failure and 1 on success.
638 All methods for all sources are invoked for this method name.
643 All methods for all sources are invoked for this method name.
646 .Ss Methods for netgroup database
648 The method APIs for this database will be changing in the near future.
660 and return its value in
670 .Ft "const char **host" ,
671 .Ft "const char **user" ,
672 .Ft "const char **domain"
675 should be set to 0 for no more netgroup members and 1 otherwise.
687 .Ft "const char *grp" ,
688 .Ft "const char *host" ,
689 .Ft "const char *user" ,
690 .Ft "const char *domain"
693 should be set to 1 for a successful match and 0 otherwise.
695 .Ft "const char *netgroup"
698 .Ss Methods for networks database
701 .Ft "struct netent **retval" ,
706 should be set to a pointer to an internal static
722 .Ft "struct netent **retval" ,
723 .Ft "const char *name"
726 should be set to a pointer to an internal static
743 .Ss Methods for passwd and passwd_compat databases
749 All methods for all sources are invoked for this method name.
751 .Ft "struct passwd **retval"
754 should be set to a pointer to an internal static
771 .Ft "struct passwd *pw" ,
773 .Ft "size_t buflen" ,
774 .Ft "struct passwd **result"
777 should be set to an appropriate
793 .Ft "struct passwd **retval" ,
794 .Ft "const char *name"
797 should be set to a pointer to an internal static
814 .Ft "const char *name" ,
815 .Ft "struct passwd *pw" ,
817 .Ft "size_t buflen" ,
818 .Ft "struct passwd **result"
821 should be set to an appropriate
837 .Ft "struct passwd **retval" ,
841 should be set to a pointer to an internal static
859 .Ft "struct passwd *pw" ,
861 .Ft "size_t buflen" ,
862 .Ft "struct passwd **result"
865 should be set to an appropriate
885 should be set to 0 on failure and 1 on success.
887 All methods for all sources are invoked for this method name.
892 All methods for all sources are invoked for this method name.
895 .Ss Methods for shells database
901 All methods for all sources are invoked for this method name.
917 All methods for all sources are invoked for this method name.
929 routines first appeared in
931 Support for dynamically-loaded modules first appeared in
936 wrote this freely distributable name-service switch implementation,
944 Support for dynamically-loaded modules was added by Jason Thorpe
945 .Aq thorpej@NetBSD.org ,
946 based on code developed by the