1248aee62SJacques Vidrine.\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $ 2248aee62SJacques Vidrine.\" 3248aee62SJacques Vidrine.\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 4248aee62SJacques Vidrine.\" All rights reserved. 5248aee62SJacques Vidrine.\" 6248aee62SJacques Vidrine.\" This code is derived from software contributed to The NetBSD Foundation 7248aee62SJacques Vidrine.\" by Luke Mewburn. 8248aee62SJacques Vidrine.\" 9248aee62SJacques Vidrine.\" Redistribution and use in source and binary forms, with or without 10248aee62SJacques Vidrine.\" modification, are permitted provided that the following conditions 11248aee62SJacques Vidrine.\" are met: 12248aee62SJacques Vidrine.\" 1. Redistributions of source code must retain the above copyright 13248aee62SJacques Vidrine.\" notice, this list of conditions and the following disclaimer. 14248aee62SJacques Vidrine.\" 2. Redistributions in binary form must reproduce the above copyright 15248aee62SJacques Vidrine.\" notice, this list of conditions and the following disclaimer in the 16248aee62SJacques Vidrine.\" documentation and/or other materials provided with the distribution. 17*fbbd9655SWarner Losh.\" 3. Neither the name of The NetBSD Foundation nor the names of its 18248aee62SJacques Vidrine.\" contributors may be used to endorse or promote products derived 19248aee62SJacques Vidrine.\" from this software without specific prior written permission. 20248aee62SJacques Vidrine.\" 21248aee62SJacques Vidrine.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22248aee62SJacques Vidrine.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23248aee62SJacques Vidrine.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24248aee62SJacques Vidrine.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25248aee62SJacques Vidrine.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26248aee62SJacques Vidrine.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27248aee62SJacques Vidrine.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28248aee62SJacques Vidrine.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29248aee62SJacques Vidrine.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30248aee62SJacques Vidrine.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31248aee62SJacques Vidrine.\" POSSIBILITY OF SUCH DAMAGE. 32248aee62SJacques Vidrine.\" 336b806d21SRuslan Ermilov.\" $FreeBSD$ 346b806d21SRuslan Ermilov.\" 35e622b479SHajimu UMEMOTO.Dd April 4, 2010 36248aee62SJacques Vidrine.Dt NSDISPATCH 3 37248aee62SJacques Vidrine.Os 38248aee62SJacques Vidrine.Sh NAME 39248aee62SJacques Vidrine.Nm nsdispatch 40248aee62SJacques Vidrine.Nd name-service switch dispatcher routine 41248aee62SJacques Vidrine.Sh LIBRARY 42248aee62SJacques Vidrine.Lb libc 43248aee62SJacques Vidrine.Sh SYNOPSIS 4446d93063SJacques Vidrine.In sys/types.h 4546d93063SJacques Vidrine.In stdarg.h 4632eef9aeSRuslan Ermilov.In nsswitch.h 47248aee62SJacques Vidrine.Ft int 48248aee62SJacques Vidrine.Fo nsdispatch 49248aee62SJacques Vidrine.Fa "void *retval" 50248aee62SJacques Vidrine.Fa "const ns_dtab dtab[]" 51248aee62SJacques Vidrine.Fa "const char *database" 5246d93063SJacques Vidrine.Fa "const char *method_name" 53248aee62SJacques Vidrine.Fa "const ns_src defaults[]" 54248aee62SJacques Vidrine.Fa "..." 55248aee62SJacques Vidrine.Fc 56248aee62SJacques Vidrine.Sh DESCRIPTION 57248aee62SJacques VidrineThe 58248aee62SJacques Vidrine.Fn nsdispatch 5946d93063SJacques Vidrinefunction invokes the methods specified in 60248aee62SJacques Vidrine.Va dtab 6146d93063SJacques Vidrinein the order given by 6246d93063SJacques Vidrine.Xr nsswitch.conf 5 63248aee62SJacques Vidrinefor the database 64248aee62SJacques Vidrine.Va database 65248aee62SJacques Vidrineuntil a successful entry is found. 66248aee62SJacques Vidrine.Pp 67248aee62SJacques Vidrine.Va retval 6846d93063SJacques Vidrineis passed to each method to modify as necessary, to pass back results to 6946d93063SJacques Vidrinethe caller of 7046d93063SJacques Vidrine.Fn nsdispatch . 7146d93063SJacques Vidrine.Pp 7246d93063SJacques VidrineEach method has the function signature described by the typedef: 7346d93063SJacques Vidrine.Pp 743a5146d9SRuslan Ermilov.Ft typedef int 753a5146d9SRuslan Ermilov.Fn \*(lp*nss_method\*(rp "void *retval" "void *mdata" "va_list *ap" ; 76248aee62SJacques Vidrine.Pp 77248aee62SJacques Vidrine.Va dtab 78248aee62SJacques Vidrineis an array of 79248aee62SJacques Vidrine.Va ns_dtab 80248aee62SJacques Vidrinestructures, which have the following format: 81248aee62SJacques Vidrine.Bd -literal -offset indent 8246d93063SJacques Vidrinetypedef struct _ns_dtab { 83248aee62SJacques Vidrine const char *src; 8446d93063SJacques Vidrine nss_method method; 8546d93063SJacques Vidrine void *mdata; 86248aee62SJacques Vidrine} ns_dtab; 87248aee62SJacques Vidrine.Ed 88478c2636SJoel Dahl.Pp 8946d93063SJacques VidrineThe 9046d93063SJacques Vidrine.Fa dtab 9146d93063SJacques Vidrinearray should consist of one entry for each source type that is 9246d93063SJacques Vidrineimplemented, with 93248aee62SJacques Vidrine.Va src 9446d93063SJacques Vidrineas the name of the source, 9546d93063SJacques Vidrine.Va method 9646d93063SJacques Vidrineas a function which handles that source, and 9746d93063SJacques Vidrine.Va mdata 9846d93063SJacques Vidrineas a handle on arbitrary data to be passed to the method. 99248aee62SJacques VidrineThe last entry in 100248aee62SJacques Vidrine.Va dtab 101248aee62SJacques Vidrineshould contain 102248aee62SJacques Vidrine.Dv NULL 103248aee62SJacques Vidrinevalues for 104248aee62SJacques Vidrine.Va src , 10546d93063SJacques Vidrine.Va method , 106248aee62SJacques Vidrineand 10746d93063SJacques Vidrine.Va mdata . 108248aee62SJacques Vidrine.Pp 10946d93063SJacques VidrineAdditionally, methods may be implemented in NSS modules, in 11046d93063SJacques Vidrinewhich case they are selected using the 11146d93063SJacques Vidrine.Fa database 11246d93063SJacques Vidrineand 11346d93063SJacques Vidrine.Fa method_name 11446d93063SJacques Vidrinearguments along with the configured source. 11546d93063SJacques Vidrine(The methods supplied via 11646d93063SJacques Vidrine.Fa dtab 11746d93063SJacques Vidrinetake priority over those implemented in NSS modules in the event 11846d93063SJacques Vidrineof a conflict.) 119248aee62SJacques Vidrine.Pp 120248aee62SJacques Vidrine.Va defaults 12146d93063SJacques Vidrinecontains a list of default sources to try if 12246d93063SJacques Vidrine.Xr nsswitch.conf 5 12346d93063SJacques Vidrineis missing or corrupted, or if there is no relevant entry for 124248aee62SJacques Vidrine.Va database . 125248aee62SJacques VidrineIt is an array of 126248aee62SJacques Vidrine.Va ns_src 127248aee62SJacques Vidrinestructures, which have the following format: 128248aee62SJacques Vidrine.Bd -literal -offset indent 12946d93063SJacques Vidrinetypedef struct _ns_src { 130248aee62SJacques Vidrine const char *src; 1316b99842aSEd Schouten uint32_t flags; 132248aee62SJacques Vidrine} ns_src; 133248aee62SJacques Vidrine.Ed 134478c2636SJoel Dahl.Pp 13546d93063SJacques VidrineThe 13646d93063SJacques Vidrine.Fa defaults 13746d93063SJacques Vidrinearray should consist of one entry for each source to be configured by 13846d93063SJacques Vidrinedefault indicated by 13946d93063SJacques Vidrine.Va src , 14046d93063SJacques Vidrineand 141248aee62SJacques Vidrine.Va flags 14246d93063SJacques Vidrineset to the criterion desired 143248aee62SJacques Vidrine(usually 144248aee62SJacques Vidrine.Dv NS_SUCCESS ; 145248aee62SJacques Vidrinerefer to 14646d93063SJacques Vidrine.Sx Method return values 147248aee62SJacques Vidrinefor more information). 148248aee62SJacques VidrineThe last entry in 149248aee62SJacques Vidrine.Va defaults 150248aee62SJacques Vidrineshould have 151248aee62SJacques Vidrine.Va src 152248aee62SJacques Vidrineset to 153248aee62SJacques Vidrine.Dv NULL 154248aee62SJacques Vidrineand 155248aee62SJacques Vidrine.Va flags 156248aee62SJacques Vidrineset to 0. 157248aee62SJacques Vidrine.Pp 158248aee62SJacques VidrineFor convenience, a global variable defined as: 159478c2636SJoel Dahl.Pp 160248aee62SJacques Vidrine.Dl extern const ns_src __nsdefaultsrc[]; 161478c2636SJoel Dahl.Pp 16246d93063SJacques Vidrineexists which contains a single default entry for the source 163248aee62SJacques Vidrine.Sq files 16446d93063SJacques Vidrinethat may be used by callers which do not require complicated default 16546d93063SJacques Vidrinerules. 166248aee62SJacques Vidrine.Pp 167c2d03ea8SRuslan Ermilov.Sq Va ... 16846d93063SJacques Vidrineare optional extra arguments, which are passed to the appropriate method 16946d93063SJacques Vidrineas a variable argument list of the type 17046d93063SJacques Vidrine.Vt va_list . 171248aee62SJacques Vidrine.Ss Valid source types 17246d93063SJacques VidrineWhile there is support for arbitrary sources, the following 17357bd0fc6SJens Schweikhardt#defines for commonly implemented sources are available: 1743a5146d9SRuslan Ermilov.Bl -column NSSRC_COMPAT compat -offset indent 17542635956SRuslan Ermilov.It Sy "#define value" 17667783ce4SJoel Dahl.It Dv NSSRC_FILES Ta \&"files\&" 17767783ce4SJoel Dahl.It Dv NSSRC_DB Ta \&"db\&" 17867783ce4SJoel Dahl.It Dv NSSRC_DNS Ta \&"dns\&" 17967783ce4SJoel Dahl.It Dv NSSRC_NIS Ta \&"nis\&" 18067783ce4SJoel Dahl.It Dv NSSRC_COMPAT Ta \&"compat\&" 181248aee62SJacques Vidrine.El 182248aee62SJacques Vidrine.Pp 183248aee62SJacques VidrineRefer to 184248aee62SJacques Vidrine.Xr nsswitch.conf 5 185248aee62SJacques Vidrinefor a complete description of what each source type is. 18646d93063SJacques Vidrine.Ss Method return values 18746d93063SJacques VidrineThe 18846d93063SJacques Vidrine.Vt nss_method 18946d93063SJacques Vidrinefunctions must return one of the following values depending upon status 19046d93063SJacques Vidrineof the lookup: 1913a5146d9SRuslan Ermilov.Bl -column "Return value" "Status code" 19242635956SRuslan Ermilov.It Sy "Return value Status code" 1933a5146d9SRuslan Ermilov.It Dv NS_SUCCESS Ta success 1943a5146d9SRuslan Ermilov.It Dv NS_NOTFOUND Ta notfound 1953a5146d9SRuslan Ermilov.It Dv NS_UNAVAIL Ta unavail 1963a5146d9SRuslan Ermilov.It Dv NS_TRYAGAIN Ta tryagain 1973a5146d9SRuslan Ermilov.It Dv NS_RETURN Ta -none- 198248aee62SJacques Vidrine.El 199248aee62SJacques Vidrine.Pp 200248aee62SJacques VidrineRefer to 201248aee62SJacques Vidrine.Xr nsswitch.conf 5 20246d93063SJacques Vidrinefor a complete description of each status code. 203248aee62SJacques Vidrine.Pp 204d6498251SPhilippe CharnierThe 205d6498251SPhilippe Charnier.Fn nsdispatch 20646d93063SJacques Vidrinefunction returns the value of the method that caused the dispatcher to 2073a5146d9SRuslan Ermilovterminate, or 2083a5146d9SRuslan Ermilov.Dv NS_NOTFOUND 2093a5146d9SRuslan Ermilovotherwise. 21050c317acSBruce M Simpson.Sh NOTES 21150c317acSBruce M Simpson.Fx Ns 's 21250c317acSBruce M Simpson.Lb libc 21350c317acSBruce M Simpsonprovides stubs for compatibility with NSS modules 21450c317acSBruce M Simpsonwritten for the 21550c317acSBruce M Simpson.Tn GNU 21650c317acSBruce M SimpsonC Library 21750c317acSBruce M Simpson.Nm nsswitch 21850c317acSBruce M Simpsoninterface. 21950c317acSBruce M SimpsonHowever, these stubs only support the use of the 22050c317acSBruce M Simpson.Dq Li passwd 22150c317acSBruce M Simpsonand 22250c317acSBruce M Simpson.Dq Li group 22350c317acSBruce M Simpsondatabases. 224248aee62SJacques Vidrine.Sh SEE ALSO 225248aee62SJacques Vidrine.Xr hesiod 3 , 226248aee62SJacques Vidrine.Xr stdarg 3 , 2273a5146d9SRuslan Ermilov.Xr nsswitch.conf 5 , 2283a5146d9SRuslan Ermilov.Xr yp 8 229248aee62SJacques Vidrine.Sh HISTORY 230248aee62SJacques VidrineThe 231d6498251SPhilippe Charnier.Fn nsdispatch 232d6498251SPhilippe Charnierfunction first appeared in 2336883c2e5STom Rhodes.Fx 5.0 . 234d6498251SPhilippe CharnierIt was imported from the 235248aee62SJacques Vidrine.Nx 236248aee62SJacques VidrineProject, 237d6498251SPhilippe Charnierwhere it appeared first in 238248aee62SJacques Vidrine.Nx 1.4 . 23946d93063SJacques VidrineSupport for NSS modules first appeared in 24046d93063SJacques Vidrine.Fx 5.1 . 241248aee62SJacques Vidrine.Sh AUTHORS 2428fbf3d50SBaptiste Daroussin.An Luke Mewburn Aq Mt lukem@netbsd.org 24346d93063SJacques Vidrinewrote this freely-distributable name-service switch implementation, 244248aee62SJacques Vidrineusing ideas from the 245248aee62SJacques Vidrine.Tn ULTRIX 2463a5146d9SRuslan Ermilovsvc.conf(5) 247248aee62SJacques Vidrineand 248248aee62SJacques Vidrine.Tn Solaris 2493a5146d9SRuslan Ermilovnsswitch.conf(4) 250248aee62SJacques Vidrinemanual pages. 251248aee62SJacques VidrineThe 252aba60fa6SRuslan Ermilov.Fx 253aba60fa6SRuslan ErmilovProject 25446d93063SJacques Vidrineadded the support for threads and NSS modules, and normalized the uses 25546d93063SJacques Vidrineof 256d6498251SPhilippe Charnier.Fn nsdispatch 25746d93063SJacques Vidrinewithin the standard C library. 258