1.\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $ 2.\" $FreeBSD$ 3.\" 4.\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Luke Mewburn. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 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. 18.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the NetBSD 21.\" Foundation, Inc. and its contributors. 22.\" 4. Neither the name of The NetBSD Foundation nor the names of its 23.\" contributors may be used to endorse or promote products derived 24.\" from this software without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36.\" POSSIBILITY OF SUCH DAMAGE. 37.\" 38.Dd April 16, 2003 39.Dt NSDISPATCH 3 40.Os 41.Sh NAME 42.Nm nsdispatch 43.Nd name-service switch dispatcher routine 44.Sh LIBRARY 45.Lb libc 46.Sh SYNOPSIS 47.In sys/types.h 48.In stdarg.h 49.In nsswitch.h 50.Ft int 51.Fo nsdispatch 52.Fa "void *retval" 53.Fa "const ns_dtab dtab[]" 54.Fa "const char *database" 55.Fa "const char *method_name" 56.Fa "const ns_src defaults[]" 57.Fa "..." 58.Fc 59.Sh DESCRIPTION 60The 61.Fn nsdispatch 62function invokes the methods specified in 63.Va dtab 64in the order given by 65.Xr nsswitch.conf 5 66for the database 67.Va database 68until a successful entry is found. 69.Pp 70.Va retval 71is passed to each method to modify as necessary, to pass back results to 72the caller of 73.Fn nsdispatch . 74.Pp 75Each method has the function signature described by the typedef: 76.Pp 77.Ft typedef int 78.Fn \*(lp*nss_method\*(rp "void *retval" "void *mdata" "va_list *ap" ; 79.Pp 80.Va dtab 81is an array of 82.Va ns_dtab 83structures, which have the following format: 84.Bd -literal -offset indent 85typedef struct _ns_dtab { 86 const char *src; 87 nss_method method; 88 void *mdata; 89} ns_dtab; 90.Ed 91.Pp 92.Bd -ragged -offset indent 93The 94.Fa dtab 95array should consist of one entry for each source type that is 96implemented, with 97.Va src 98as the name of the source, 99.Va method 100as a function which handles that source, and 101.Va mdata 102as a handle on arbitrary data to be passed to the method. 103The last entry in 104.Va dtab 105should contain 106.Dv NULL 107values for 108.Va src , 109.Va method , 110and 111.Va mdata . 112.Ed 113.Pp 114Additionally, methods may be implemented in NSS modules, in 115which case they are selected using the 116.Fa database 117and 118.Fa method_name 119arguments along with the configured source. 120(The methods supplied via 121.Fa dtab 122take priority over those implemented in NSS modules in the event 123of a conflict.) 124.Pp 125.Va defaults 126contains a list of default sources to try if 127.Xr nsswitch.conf 5 128is missing or corrupted, or if there is no relevant entry for 129.Va database . 130It is an array of 131.Va ns_src 132structures, which have the following format: 133.Bd -literal -offset indent 134typedef struct _ns_src { 135 const char *src; 136 u_int32_t flags; 137} ns_src; 138.Ed 139.Pp 140.Bd -ragged -offset indent 141The 142.Fa defaults 143array should consist of one entry for each source to be configured by 144default indicated by 145.Va src , 146and 147.Va flags 148set to the criterion desired 149(usually 150.Dv NS_SUCCESS ; 151refer to 152.Sx Method return values 153for more information). 154The last entry in 155.Va defaults 156should have 157.Va src 158set to 159.Dv NULL 160and 161.Va flags 162set to 0. 163.Pp 164For convenience, a global variable defined as: 165.Dl extern const ns_src __nsdefaultsrc[]; 166exists which contains a single default entry for the source 167.Sq files 168that may be used by callers which do not require complicated default 169rules. 170.Ed 171.Pp 172.Sq Va ... 173are optional extra arguments, which are passed to the appropriate method 174as a variable argument list of the type 175.Vt va_list . 176.Ss Valid source types 177While there is support for arbitrary sources, the following 178#defines for commonly implemented sources are available: 179.Bl -column NSSRC_COMPAT compat -offset indent 180.It Sy "#define value" 181.It Dv NSSRC_FILES Ta """files"" 182.It Dv NSSRC_DNS Ta """dns"" 183.It Dv NSSRC_NIS Ta """nis"" 184.It Dv NSSRC_COMPAT Ta """compat"" 185.El 186.Pp 187Refer to 188.Xr nsswitch.conf 5 189for a complete description of what each source type is. 190.Pp 191.Ss Method return values 192The 193.Vt nss_method 194functions must return one of the following values depending upon status 195of the lookup: 196.Bl -column "Return value" "Status code" 197.It Sy "Return value Status code" 198.It Dv NS_SUCCESS Ta success 199.It Dv NS_NOTFOUND Ta notfound 200.It Dv NS_UNAVAIL Ta unavail 201.It Dv NS_TRYAGAIN Ta tryagain 202.It Dv NS_RETURN Ta -none- 203.El 204.Pp 205Refer to 206.Xr nsswitch.conf 5 207for a complete description of each status code. 208.Pp 209The 210.Fn nsdispatch 211function returns the value of the method that caused the dispatcher to 212terminate, or 213.Dv NS_NOTFOUND 214otherwise. 215.Sh SEE ALSO 216.Xr hesiod 3 , 217.Xr stdarg 3 , 218.Xr nsswitch.conf 5 , 219.Xr yp 8 220.Sh HISTORY 221The 222.Fn nsdispatch 223function first appeared in 224.Fx 5.0 . 225It was imported from the 226.Nx 227Project, 228where it appeared first in 229.Nx 1.4 . 230Support for NSS modules first appeared in 231.Fx 5.1 . 232.Sh AUTHORS 233Luke Mewburn 234.Aq lukem@netbsd.org 235wrote this freely-distributable name-service switch implementation, 236using ideas from the 237.Tn ULTRIX 238svc.conf(5) 239and 240.Tn Solaris 241nsswitch.conf(4) 242manual pages. 243The 244.Fx 245Project 246added the support for threads and NSS modules, and normalized the uses 247of 248.Fn nsdispatch 249within the standard C library. 250