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. 17fbbd9655SWarner 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.\" 33*1d7da823SEdward Tomasz Napierala.Dd October 15, 2018 34248aee62SJacques Vidrine.Dt NSDISPATCH 3 35248aee62SJacques Vidrine.Os 36248aee62SJacques Vidrine.Sh NAME 37248aee62SJacques Vidrine.Nm nsdispatch 38248aee62SJacques Vidrine.Nd name-service switch dispatcher routine 39248aee62SJacques Vidrine.Sh LIBRARY 40248aee62SJacques Vidrine.Lb libc 41248aee62SJacques Vidrine.Sh SYNOPSIS 4246d93063SJacques Vidrine.In sys/types.h 4346d93063SJacques Vidrine.In stdarg.h 4432eef9aeSRuslan Ermilov.In nsswitch.h 45248aee62SJacques Vidrine.Ft int 46248aee62SJacques Vidrine.Fo nsdispatch 47248aee62SJacques Vidrine.Fa "void *retval" 48248aee62SJacques Vidrine.Fa "const ns_dtab dtab[]" 49248aee62SJacques Vidrine.Fa "const char *database" 5046d93063SJacques Vidrine.Fa "const char *method_name" 51248aee62SJacques Vidrine.Fa "const ns_src defaults[]" 52248aee62SJacques Vidrine.Fa "..." 53248aee62SJacques Vidrine.Fc 54248aee62SJacques Vidrine.Sh DESCRIPTION 55248aee62SJacques VidrineThe 56248aee62SJacques Vidrine.Fn nsdispatch 5746d93063SJacques Vidrinefunction invokes the methods specified in 58248aee62SJacques Vidrine.Va dtab 5946d93063SJacques Vidrinein the order given by 6046d93063SJacques Vidrine.Xr nsswitch.conf 5 61248aee62SJacques Vidrinefor the database 62248aee62SJacques Vidrine.Va database 63248aee62SJacques Vidrineuntil a successful entry is found. 64248aee62SJacques Vidrine.Pp 65248aee62SJacques Vidrine.Va retval 6646d93063SJacques Vidrineis passed to each method to modify as necessary, to pass back results to 6746d93063SJacques Vidrinethe caller of 6846d93063SJacques Vidrine.Fn nsdispatch . 6946d93063SJacques Vidrine.Pp 7046d93063SJacques VidrineEach method has the function signature described by the typedef: 7146d93063SJacques Vidrine.Pp 723a5146d9SRuslan Ermilov.Ft typedef int 733a5146d9SRuslan Ermilov.Fn \*(lp*nss_method\*(rp "void *retval" "void *mdata" "va_list *ap" ; 74248aee62SJacques Vidrine.Pp 75248aee62SJacques Vidrine.Va dtab 76248aee62SJacques Vidrineis an array of 77248aee62SJacques Vidrine.Va ns_dtab 78248aee62SJacques Vidrinestructures, which have the following format: 79248aee62SJacques Vidrine.Bd -literal -offset indent 8046d93063SJacques Vidrinetypedef struct _ns_dtab { 81248aee62SJacques Vidrine const char *src; 8246d93063SJacques Vidrine nss_method method; 8346d93063SJacques Vidrine void *mdata; 84248aee62SJacques Vidrine} ns_dtab; 85248aee62SJacques Vidrine.Ed 86478c2636SJoel Dahl.Pp 8746d93063SJacques VidrineThe 8846d93063SJacques Vidrine.Fa dtab 8946d93063SJacques Vidrinearray should consist of one entry for each source type that is 9046d93063SJacques Vidrineimplemented, with 91248aee62SJacques Vidrine.Va src 9246d93063SJacques Vidrineas the name of the source, 9346d93063SJacques Vidrine.Va method 9446d93063SJacques Vidrineas a function which handles that source, and 9546d93063SJacques Vidrine.Va mdata 9646d93063SJacques Vidrineas a handle on arbitrary data to be passed to the method. 97248aee62SJacques VidrineThe last entry in 98248aee62SJacques Vidrine.Va dtab 99248aee62SJacques Vidrineshould contain 100248aee62SJacques Vidrine.Dv NULL 101248aee62SJacques Vidrinevalues for 102248aee62SJacques Vidrine.Va src , 10346d93063SJacques Vidrine.Va method , 104248aee62SJacques Vidrineand 10546d93063SJacques Vidrine.Va mdata . 106248aee62SJacques Vidrine.Pp 10746d93063SJacques VidrineAdditionally, methods may be implemented in NSS modules, in 10846d93063SJacques Vidrinewhich case they are selected using the 10946d93063SJacques Vidrine.Fa database 11046d93063SJacques Vidrineand 11146d93063SJacques Vidrine.Fa method_name 11246d93063SJacques Vidrinearguments along with the configured source. 113*1d7da823SEdward Tomasz NapieralaModules must use source names different from the built-in ones. 114248aee62SJacques Vidrine.Pp 115248aee62SJacques Vidrine.Va defaults 11646d93063SJacques Vidrinecontains a list of default sources to try if 11746d93063SJacques Vidrine.Xr nsswitch.conf 5 11846d93063SJacques Vidrineis missing or corrupted, or if there is no relevant entry for 119248aee62SJacques Vidrine.Va database . 120248aee62SJacques VidrineIt is an array of 121248aee62SJacques Vidrine.Va ns_src 122248aee62SJacques Vidrinestructures, which have the following format: 123248aee62SJacques Vidrine.Bd -literal -offset indent 12446d93063SJacques Vidrinetypedef struct _ns_src { 125248aee62SJacques Vidrine const char *src; 1266b99842aSEd Schouten uint32_t flags; 127248aee62SJacques Vidrine} ns_src; 128248aee62SJacques Vidrine.Ed 129478c2636SJoel Dahl.Pp 13046d93063SJacques VidrineThe 13146d93063SJacques Vidrine.Fa defaults 13246d93063SJacques Vidrinearray should consist of one entry for each source to be configured by 13346d93063SJacques Vidrinedefault indicated by 13446d93063SJacques Vidrine.Va src , 13546d93063SJacques Vidrineand 136248aee62SJacques Vidrine.Va flags 13746d93063SJacques Vidrineset to the criterion desired 138248aee62SJacques Vidrine(usually 139248aee62SJacques Vidrine.Dv NS_SUCCESS ; 140248aee62SJacques Vidrinerefer to 14146d93063SJacques Vidrine.Sx Method return values 142248aee62SJacques Vidrinefor more information). 143248aee62SJacques VidrineThe last entry in 144248aee62SJacques Vidrine.Va defaults 145248aee62SJacques Vidrineshould have 146248aee62SJacques Vidrine.Va src 147248aee62SJacques Vidrineset to 148248aee62SJacques Vidrine.Dv NULL 149248aee62SJacques Vidrineand 150248aee62SJacques Vidrine.Va flags 151248aee62SJacques Vidrineset to 0. 152248aee62SJacques Vidrine.Pp 153248aee62SJacques VidrineFor convenience, a global variable defined as: 154478c2636SJoel Dahl.Pp 155248aee62SJacques Vidrine.Dl extern const ns_src __nsdefaultsrc[]; 156478c2636SJoel Dahl.Pp 15746d93063SJacques Vidrineexists which contains a single default entry for the source 158248aee62SJacques Vidrine.Sq files 15946d93063SJacques Vidrinethat may be used by callers which do not require complicated default 16046d93063SJacques Vidrinerules. 161248aee62SJacques Vidrine.Pp 162c2d03ea8SRuslan Ermilov.Sq Va ... 16346d93063SJacques Vidrineare optional extra arguments, which are passed to the appropriate method 16446d93063SJacques Vidrineas a variable argument list of the type 16546d93063SJacques Vidrine.Vt va_list . 166248aee62SJacques Vidrine.Ss Valid source types 16746d93063SJacques VidrineWhile there is support for arbitrary sources, the following 16857bd0fc6SJens Schweikhardt#defines for commonly implemented sources are available: 1693a5146d9SRuslan Ermilov.Bl -column NSSRC_COMPAT compat -offset indent 17042635956SRuslan Ermilov.It Sy "#define value" 17167783ce4SJoel Dahl.It Dv NSSRC_FILES Ta \&"files\&" 17267783ce4SJoel Dahl.It Dv NSSRC_DB Ta \&"db\&" 17367783ce4SJoel Dahl.It Dv NSSRC_DNS Ta \&"dns\&" 17467783ce4SJoel Dahl.It Dv NSSRC_NIS Ta \&"nis\&" 17567783ce4SJoel Dahl.It Dv NSSRC_COMPAT Ta \&"compat\&" 176248aee62SJacques Vidrine.El 177248aee62SJacques Vidrine.Pp 178248aee62SJacques VidrineRefer to 179248aee62SJacques Vidrine.Xr nsswitch.conf 5 180248aee62SJacques Vidrinefor a complete description of what each source type is. 18146d93063SJacques Vidrine.Ss Method return values 18246d93063SJacques VidrineThe 18346d93063SJacques Vidrine.Vt nss_method 18446d93063SJacques Vidrinefunctions must return one of the following values depending upon status 18546d93063SJacques Vidrineof the lookup: 1863a5146d9SRuslan Ermilov.Bl -column "Return value" "Status code" 18742635956SRuslan Ermilov.It Sy "Return value Status code" 1883a5146d9SRuslan Ermilov.It Dv NS_SUCCESS Ta success 1893a5146d9SRuslan Ermilov.It Dv NS_NOTFOUND Ta notfound 1903a5146d9SRuslan Ermilov.It Dv NS_UNAVAIL Ta unavail 1913a5146d9SRuslan Ermilov.It Dv NS_TRYAGAIN Ta tryagain 1923a5146d9SRuslan Ermilov.It Dv NS_RETURN Ta -none- 193248aee62SJacques Vidrine.El 194248aee62SJacques Vidrine.Pp 195248aee62SJacques VidrineRefer to 196248aee62SJacques Vidrine.Xr nsswitch.conf 5 19746d93063SJacques Vidrinefor a complete description of each status code. 198248aee62SJacques Vidrine.Pp 199d6498251SPhilippe CharnierThe 200d6498251SPhilippe Charnier.Fn nsdispatch 20146d93063SJacques Vidrinefunction returns the value of the method that caused the dispatcher to 2023a5146d9SRuslan Ermilovterminate, or 2033a5146d9SRuslan Ermilov.Dv NS_NOTFOUND 2043a5146d9SRuslan Ermilovotherwise. 20550c317acSBruce M Simpson.Sh NOTES 20650c317acSBruce M Simpson.Fx Ns 's 20750c317acSBruce M Simpson.Lb libc 20850c317acSBruce M Simpsonprovides stubs for compatibility with NSS modules 20950c317acSBruce M Simpsonwritten for the 21050c317acSBruce M Simpson.Tn GNU 21150c317acSBruce M SimpsonC Library 21250c317acSBruce M Simpson.Nm nsswitch 21350c317acSBruce M Simpsoninterface. 21450c317acSBruce M SimpsonHowever, these stubs only support the use of the 21550c317acSBruce M Simpson.Dq Li passwd 21650c317acSBruce M Simpsonand 21750c317acSBruce M Simpson.Dq Li group 21850c317acSBruce M Simpsondatabases. 219248aee62SJacques Vidrine.Sh SEE ALSO 220248aee62SJacques Vidrine.Xr hesiod 3 , 221248aee62SJacques Vidrine.Xr stdarg 3 , 2223a5146d9SRuslan Ermilov.Xr nsswitch.conf 5 , 2233a5146d9SRuslan Ermilov.Xr yp 8 224248aee62SJacques Vidrine.Sh HISTORY 225248aee62SJacques VidrineThe 226d6498251SPhilippe Charnier.Fn nsdispatch 227d6498251SPhilippe Charnierfunction first appeared in 2286883c2e5STom Rhodes.Fx 5.0 . 229d6498251SPhilippe CharnierIt was imported from the 230248aee62SJacques Vidrine.Nx 231248aee62SJacques VidrineProject, 232d6498251SPhilippe Charnierwhere it appeared first in 233248aee62SJacques Vidrine.Nx 1.4 . 23446d93063SJacques VidrineSupport for NSS modules first appeared in 23546d93063SJacques Vidrine.Fx 5.1 . 236248aee62SJacques Vidrine.Sh AUTHORS 2378fbf3d50SBaptiste Daroussin.An Luke Mewburn Aq Mt lukem@netbsd.org 23846d93063SJacques Vidrinewrote this freely-distributable name-service switch implementation, 239248aee62SJacques Vidrineusing ideas from the 240248aee62SJacques Vidrine.Tn ULTRIX 2413a5146d9SRuslan Ermilovsvc.conf(5) 242248aee62SJacques Vidrineand 243248aee62SJacques Vidrine.Tn Solaris 2443a5146d9SRuslan Ermilovnsswitch.conf(4) 245248aee62SJacques Vidrinemanual pages. 246248aee62SJacques VidrineThe 247aba60fa6SRuslan Ermilov.Fx 248aba60fa6SRuslan ErmilovProject 24946d93063SJacques Vidrineadded the support for threads and NSS modules, and normalized the uses 25046d93063SJacques Vidrineof 251d6498251SPhilippe Charnier.Fn nsdispatch 25246d93063SJacques Vidrinewithin the standard C library. 253