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