Home | History | Annotate | Line # | Download | only in include
nsswitch.h revision 1.20.10.2
      1  1.20.10.2  martin /*	$NetBSD: nsswitch.h,v 1.20.10.2 2008/04/28 20:22:55 martin Exp $	*/
      2  1.20.10.2  martin 
      3  1.20.10.2  martin /*-
      4  1.20.10.2  martin  * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
      5  1.20.10.2  martin  * All rights reserved.
      6  1.20.10.2  martin  *
      7  1.20.10.2  martin  * This code is derived from software contributed to The NetBSD Foundation
      8  1.20.10.2  martin  * by Luke Mewburn.
      9  1.20.10.2  martin  *
     10  1.20.10.2  martin  * Redistribution and use in source and binary forms, with or without
     11  1.20.10.2  martin  * modification, are permitted provided that the following conditions
     12  1.20.10.2  martin  * are met:
     13  1.20.10.2  martin  * 1. Redistributions of source code must retain the above copyright
     14  1.20.10.2  martin  *    notice, this list of conditions and the following disclaimer.
     15  1.20.10.2  martin  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.20.10.2  martin  *    notice, this list of conditions and the following disclaimer in the
     17  1.20.10.2  martin  *    documentation and/or other materials provided with the distribution.
     18  1.20.10.2  martin  *
     19  1.20.10.2  martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.20.10.2  martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.20.10.2  martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.20.10.2  martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.20.10.2  martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.20.10.2  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.20.10.2  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.20.10.2  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.20.10.2  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.20.10.2  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.20.10.2  martin  * POSSIBILITY OF SUCH DAMAGE.
     30  1.20.10.2  martin  */
     31  1.20.10.2  martin 
     32  1.20.10.2  martin #ifndef _NSSWITCH_H
     33  1.20.10.2  martin #define _NSSWITCH_H	1
     34  1.20.10.2  martin 
     35  1.20.10.2  martin /*
     36  1.20.10.2  martin  * Don't use va_list in prototypes.   va_list is typedef'd in two places
     37  1.20.10.2  martin  * (<machine/varargs.h> and <machine/stdarg.h>), so if we include one of
     38  1.20.10.2  martin  * them here we may collide with the utility's includes.  It's unreasonable
     39  1.20.10.2  martin  * for utilities to have to include one of them to include nsswitch.h, so
     40  1.20.10.2  martin  * we get _BSD_VA_LIST_ from <machine/ansi.h> and use it.
     41  1.20.10.2  martin  */
     42  1.20.10.2  martin #include <machine/ansi.h>
     43  1.20.10.2  martin #include <sys/types.h>
     44  1.20.10.2  martin 
     45  1.20.10.2  martin #define	NSS_MODULE_INTERFACE_VERSION	0
     46  1.20.10.2  martin 
     47  1.20.10.2  martin #ifndef _PATH_NS_CONF
     48  1.20.10.2  martin #define _PATH_NS_CONF	"/etc/nsswitch.conf"
     49  1.20.10.2  martin #endif
     50  1.20.10.2  martin 
     51  1.20.10.2  martin #define	NS_CONTINUE	0
     52  1.20.10.2  martin #define	NS_RETURN	1
     53  1.20.10.2  martin 
     54  1.20.10.2  martin /*
     55  1.20.10.2  martin  * Layout of:
     56  1.20.10.2  martin  *	uint32_t ns_src.flags
     57  1.20.10.2  martin  */
     58  1.20.10.2  martin 	/* nsswitch.conf status codes and nsdispatch(3) return values */
     59  1.20.10.2  martin #define	NS_SUCCESS	(1<<0)		/* entry was found */
     60  1.20.10.2  martin #define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
     61  1.20.10.2  martin #define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
     62  1.20.10.2  martin #define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retrys */
     63  1.20.10.2  martin #define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
     64  1.20.10.2  martin 
     65  1.20.10.2  martin 	/* internal nsdispatch(3) flags; not settable in nsswitch.conf(5)  */
     66  1.20.10.2  martin #define	NS_FORCEALL	(1<<8)		/* force all methods to be invoked; */
     67  1.20.10.2  martin 
     68  1.20.10.2  martin /*
     69  1.20.10.2  martin  * Currently implemented sources.
     70  1.20.10.2  martin  */
     71  1.20.10.2  martin #define NSSRC_FILES	"files"		/* local files */
     72  1.20.10.2  martin #define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
     73  1.20.10.2  martin #define	NSSRC_NIS	"nis"		/* YP/NIS */
     74  1.20.10.2  martin #define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
     75  1.20.10.2  martin 
     76  1.20.10.2  martin /*
     77  1.20.10.2  martin  * Currently implemented databases.
     78  1.20.10.2  martin  */
     79  1.20.10.2  martin #define NSDB_HOSTS		"hosts"
     80  1.20.10.2  martin #define NSDB_GROUP		"group"
     81  1.20.10.2  martin #define NSDB_GROUP_COMPAT	"group_compat"
     82  1.20.10.2  martin #define NSDB_NETGROUP		"netgroup"
     83  1.20.10.2  martin #define NSDB_NETWORKS		"networks"
     84  1.20.10.2  martin #define NSDB_PASSWD		"passwd"
     85  1.20.10.2  martin #define NSDB_PASSWD_COMPAT	"passwd_compat"
     86  1.20.10.2  martin #define NSDB_SHELLS		"shells"
     87  1.20.10.2  martin 
     88  1.20.10.2  martin /*
     89  1.20.10.2  martin  * Suggested databases to implement.
     90  1.20.10.2  martin  */
     91  1.20.10.2  martin #define NSDB_ALIASES		"aliases"
     92  1.20.10.2  martin #define NSDB_AUTH		"auth"
     93  1.20.10.2  martin #define NSDB_AUTOMOUNT		"automount"
     94  1.20.10.2  martin #define NSDB_BOOTPARAMS		"bootparams"
     95  1.20.10.2  martin #define NSDB_ETHERS		"ethers"
     96  1.20.10.2  martin #define NSDB_EXPORTS		"exports"
     97  1.20.10.2  martin #define NSDB_NETMASKS		"netmasks"
     98  1.20.10.2  martin #define NSDB_PHONES		"phones"
     99  1.20.10.2  martin #define NSDB_PRINTCAP		"printcap"
    100  1.20.10.2  martin #define NSDB_PROTOCOLS		"protocols"
    101  1.20.10.2  martin #define NSDB_REMOTE		"remote"
    102  1.20.10.2  martin #define NSDB_RPC		"rpc"
    103  1.20.10.2  martin #define NSDB_SENDMAILVARS	"sendmailvars"
    104  1.20.10.2  martin #define NSDB_SERVICES		"services"
    105  1.20.10.2  martin #define NSDB_TERMCAP		"termcap"
    106  1.20.10.2  martin #define NSDB_TTYS		"ttys"
    107  1.20.10.2  martin 
    108  1.20.10.2  martin /*
    109  1.20.10.2  martin  * ns_dtab `callback' function signature.
    110  1.20.10.2  martin  */
    111  1.20.10.2  martin typedef	int (*nss_method)(void *, void *, _BSD_VA_LIST_);
    112  1.20.10.2  martin 
    113  1.20.10.2  martin /*
    114  1.20.10.2  martin  * ns_dtab - `nsswitch dispatch table'
    115  1.20.10.2  martin  * Contains an entry for each source and the appropriate function to call.
    116  1.20.10.2  martin  */
    117  1.20.10.2  martin typedef struct {
    118  1.20.10.2  martin 	const char	 *src;
    119  1.20.10.2  martin 	nss_method	 callback;
    120  1.20.10.2  martin 	void		 *cb_data;
    121  1.20.10.2  martin } ns_dtab;
    122  1.20.10.2  martin 
    123  1.20.10.2  martin /*
    124  1.20.10.2  martin  * Macros to help build an ns_dtab[]
    125  1.20.10.2  martin  */
    126  1.20.10.2  martin #define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	__UNCONST(C) },
    127  1.20.10.2  martin #define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	__UNCONST(C) },
    128  1.20.10.2  martin 
    129  1.20.10.2  martin #ifdef HESIOD
    130  1.20.10.2  martin #   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	__UNCONST(C) },
    131  1.20.10.2  martin #else
    132  1.20.10.2  martin #   define NS_DNS_CB(F,C)
    133  1.20.10.2  martin #endif
    134  1.20.10.2  martin 
    135  1.20.10.2  martin #ifdef YP
    136  1.20.10.2  martin #   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	__UNCONST(C) },
    137  1.20.10.2  martin #else
    138  1.20.10.2  martin #   define NS_NIS_CB(F,C)
    139  1.20.10.2  martin #endif
    140  1.20.10.2  martin #define	NS_NULL_CB		{ .src = NULL },
    141  1.20.10.2  martin 
    142  1.20.10.2  martin /*
    143  1.20.10.2  martin  * ns_src - `nsswitch source'
    144  1.20.10.2  martin  * Used by the nsparser routines to store a mapping between a source
    145  1.20.10.2  martin  * and its dispatch control flags for a given database.
    146  1.20.10.2  martin  */
    147  1.20.10.2  martin typedef struct {
    148  1.20.10.2  martin 	const char	*name;
    149  1.20.10.2  martin 	uint32_t	 flags;
    150  1.20.10.2  martin } ns_src;
    151  1.20.10.2  martin 
    152  1.20.10.2  martin 
    153  1.20.10.2  martin /*
    154  1.20.10.2  martin  * Default sourcelists (if nsswitch.conf is missing, corrupt,
    155  1.20.10.2  martin  * or the requested database doesn't have an entry)
    156  1.20.10.2  martin  */
    157  1.20.10.2  martin extern const ns_src __nsdefaultsrc[];
    158  1.20.10.2  martin extern const ns_src __nsdefaultcompat[];
    159  1.20.10.2  martin extern const ns_src __nsdefaultcompat_forceall[];
    160  1.20.10.2  martin extern const ns_src __nsdefaultfiles[];
    161  1.20.10.2  martin extern const ns_src __nsdefaultfiles_forceall[];
    162  1.20.10.2  martin extern const ns_src __nsdefaultnis[];
    163  1.20.10.2  martin extern const ns_src __nsdefaultnis_forceall[];
    164  1.20.10.2  martin 
    165  1.20.10.2  martin 
    166  1.20.10.2  martin /*
    167  1.20.10.2  martin  * ns_mtab - `nsswitch method table'
    168  1.20.10.2  martin  * An nsswitch module provides a mapping from (database name, method name)
    169  1.20.10.2  martin  * tuples to the nss_method and associated callback data.  Effectively,
    170  1.20.10.2  martin  * ns_dtab, but used for dynamically loaded modules.
    171  1.20.10.2  martin  */
    172  1.20.10.2  martin typedef struct {
    173  1.20.10.2  martin 	const char	*database;
    174  1.20.10.2  martin 	const char	*name;
    175  1.20.10.2  martin 	nss_method	 method;
    176  1.20.10.2  martin 	void		*mdata;
    177  1.20.10.2  martin } ns_mtab;
    178  1.20.10.2  martin 
    179  1.20.10.2  martin /*
    180  1.20.10.2  martin  * nss_module_register_fn - module registration function
    181  1.20.10.2  martin  *	called at module load
    182  1.20.10.2  martin  * nss_module_unregister_fn - module un-registration function
    183  1.20.10.2  martin  *	called at module unload
    184  1.20.10.2  martin  */
    185  1.20.10.2  martin typedef	void (*nss_module_unregister_fn)(ns_mtab *, u_int);
    186  1.20.10.2  martin typedef	ns_mtab *(*nss_module_register_fn)(const char *, u_int *,
    187  1.20.10.2  martin 					   nss_module_unregister_fn *);
    188  1.20.10.2  martin 
    189  1.20.10.2  martin #ifdef _NS_PRIVATE
    190  1.20.10.2  martin 
    191  1.20.10.2  martin /*
    192  1.20.10.2  martin  * Private data structures for back-end nsswitch implementation.
    193  1.20.10.2  martin  */
    194  1.20.10.2  martin 
    195  1.20.10.2  martin /*
    196  1.20.10.2  martin  * ns_dbt - `nsswitch database thang'
    197  1.20.10.2  martin  * For each database in /etc/nsswitch.conf there is a ns_dbt, with its
    198  1.20.10.2  martin  * name and a list of ns_src's containing the source information.
    199  1.20.10.2  martin  */
    200  1.20.10.2  martin typedef struct {
    201  1.20.10.2  martin 	const char	*name;		/* name of database */
    202  1.20.10.2  martin 	ns_src		*srclist;	/* list of sources */
    203  1.20.10.2  martin 	u_int		 srclistsize;	/* size of srclist */
    204  1.20.10.2  martin } ns_dbt;
    205  1.20.10.2  martin 
    206  1.20.10.2  martin /*
    207  1.20.10.2  martin  * ns_mod - `nsswitch module'
    208  1.20.10.2  martin  */
    209  1.20.10.2  martin typedef struct {
    210  1.20.10.2  martin 	const char	*name;		/* module name */
    211  1.20.10.2  martin 	void		*handle;	/* handle from dlopen() */
    212  1.20.10.2  martin 	ns_mtab		*mtab;		/* method table */
    213  1.20.10.2  martin 	u_int		 mtabsize;	/* size of mtab */
    214  1.20.10.2  martin 					/* called to unload module */
    215  1.20.10.2  martin 	nss_module_unregister_fn unregister;
    216  1.20.10.2  martin } ns_mod;
    217  1.20.10.2  martin 
    218  1.20.10.2  martin #endif /* _NS_PRIVATE */
    219  1.20.10.2  martin 
    220  1.20.10.2  martin 
    221  1.20.10.2  martin #include <sys/cdefs.h>
    222  1.20.10.2  martin 
    223  1.20.10.2  martin __BEGIN_DECLS
    224  1.20.10.2  martin int	nsdispatch(void *, const ns_dtab [], const char *,
    225  1.20.10.2  martin 			const char *, const ns_src [], ...);
    226  1.20.10.2  martin 
    227  1.20.10.2  martin #ifdef _NS_PRIVATE
    228  1.20.10.2  martin int		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
    229  1.20.10.2  martin void		 _nsdbtdump(const ns_dbt *);
    230  1.20.10.2  martin int		 _nsdbtput(const ns_dbt *);
    231  1.20.10.2  martin void		 _nsyyerror(const char *);
    232  1.20.10.2  martin int		 _nsyylex(void);
    233  1.20.10.2  martin #endif /* _NS_PRIVATE */
    234  1.20.10.2  martin 
    235  1.20.10.2  martin __END_DECLS
    236  1.20.10.2  martin 
    237  1.20.10.2  martin #endif /* !_NSSWITCH_H */
    238