1 .\" $NetBSD: nsdispatch.3,v 1.29 2009/10/14 17:24:03 joerg 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
495 .Ft "struct group *grp" ,
497 .Ft "size_t buflen" ,
498 .Ft "struct group **result"
501 should be set to an appropriate
517 .Ft "struct group **retval" ,
521 should be set to a pointer to an internal static
538 .Ft "struct group *grp" ,
540 .Ft "size_t buflen" ,
541 .Ft "struct group **result"
544 should be set to an appropriate
560 .Ft "struct group **retval" ,
561 .Ft "const char *name"
564 should be set to a pointer to an internal static
580 .Ft "const char *name" ,
581 .Ft "struct group *grp" ,
583 .Ft "size_t buflen" ,
584 .Ft "struct group **result"
587 should be set to an appropriate
602 .It Sy getgroupmembership
604 .Ft "const char *name" ,
605 .Ft "gid_t basegid" ,
606 .Ft "gid_t *groups" ,
617 was returned to prevent multiple
619 compat entries from being expanded.
621 .Xr getgroupmembership 3
633 should be set to 0 on failure and 1 on success.
635 All methods for all sources are invoked for this method name.
640 All methods for all sources are invoked for this method name.
643 .Ss Methods for netgroup database
645 The method APIs for this database will be changing in the near future.
657 and return its value in
667 .Ft "const char **host" ,
668 .Ft "const char **user" ,
669 .Ft "const char **domain"
672 should be set to 0 for no more netgroup members and 1 otherwise.
684 .Ft "const char *grp" ,
685 .Ft "const char *host" ,
686 .Ft "const char *user" ,
687 .Ft "const char *domain"
690 should be set to 1 for a successful match and 0 otherwise.
692 .Ft "const char *netgroup"
695 .Ss Methods for networks database
698 .Ft "struct netent **retval" ,
703 should be set to a pointer to an internal static
718 .Ft "struct netent **retval" ,
719 .Ft "const char *name"
722 should be set to a pointer to an internal static
738 .Ss Methods for passwd and passwd_compat databases
744 All methods for all sources are invoked for this method name.
746 .Ft "struct passwd **retval"
749 should be set to a pointer to an internal static
765 .Ft "struct passwd *pw" ,
767 .Ft "size_t buflen" ,
768 .Ft "struct passwd **result"
771 should be set to an appropriate
787 .Ft "struct passwd **retval" ,
788 .Ft "const char *name"
791 should be set to a pointer to an internal static
807 .Ft "const char *name" ,
808 .Ft "struct passwd *pw" ,
810 .Ft "size_t buflen" ,
811 .Ft "struct passwd **result"
814 should be set to an appropriate
830 .Ft "struct passwd **retval" ,
834 should be set to a pointer to an internal static
851 .Ft "struct passwd *pw" ,
853 .Ft "size_t buflen" ,
854 .Ft "struct passwd **result"
857 should be set to an appropriate
877 should be set to 0 on failure and 1 on success.
879 All methods for all sources are invoked for this method name.
884 All methods for all sources are invoked for this method name.
887 .Ss Methods for shells database
893 All methods for all sources are invoked for this method name.
909 All methods for all sources are invoked for this method name.
921 routines first appeared in
923 Support for dynamically-loaded modules first appeared in
928 wrote this freely distributable name-service switch implementation,
936 Support for dynamically-loaded modules was added by Jason Thorpe
937 .Aq thorpej@NetBSD.org ,
938 based on code developed by the