genericopenlibs/openenvcore/include/nsswitch.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
       
     2 /*	$FreeBSD: src/include/nsswitch.h,v 1.3 2003/04/17 14:14:21 nectar Exp $ */
       
     3 
       
     4 /*-
       
     5  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
       
     6  * All rights reserved.
       
     7  *
       
     8  * This code is derived from software contributed to The NetBSD Foundation
       
     9  * by Luke Mewburn.
       
    10  *
       
    11  * Redistribution and use in source and binary forms, with or without
       
    12  * modification, are permitted provided that the following conditions
       
    13  * are met:
       
    14  * 1. Redistributions of source code must retain the above copyright
       
    15  *    notice, this list of conditions and the following disclaimer.
       
    16  * 2. Redistributions in binary form must reproduce the above copyright
       
    17  *    notice, this list of conditions and the following disclaimer in the
       
    18  *    documentation and/or other materials provided with the distribution.
       
    19  * 4. Neither the name of The NetBSD Foundation nor the names of its
       
    20  *    contributors may be used to endorse or promote products derived
       
    21  *    from this software without specific prior written permission.
       
    22  *
       
    23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
       
    24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
       
    25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
       
    27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       
    31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       
    32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    33  * POSSIBILITY OF SUCH DAMAGE.
       
    34  * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
    35  */
       
    36 
       
    37 #ifndef _NSSWITCH_H
       
    38 #define _NSSWITCH_H	1
       
    39 
       
    40 #include <sys/types.h>
       
    41 #include <stdarg.h>
       
    42 
       
    43 #define NSS_MODULE_INTERFACE_VERSION 1
       
    44 
       
    45 #ifndef _PATH_NS_CONF
       
    46 #define _PATH_NS_CONF	"/etc/nsswitch.conf"
       
    47 #endif
       
    48 
       
    49 /* NSS source actions */
       
    50 #define	NS_ACTION_CONTINUE	0	/* try the next source */
       
    51 #define	NS_ACTION_RETURN	1	/* look no further */
       
    52 
       
    53 #define	NS_SUCCESS	(1<<0)		/* entry was found */
       
    54 #define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
       
    55 #define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
       
    56 #define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retry */
       
    57 #define NS_RETURN	(1<<4)		/* stop search, e.g. for ERANGE */
       
    58 #define NS_TERMINATE	(NS_SUCCESS|NS_RETURN) /* flags that end search */
       
    59 #define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
       
    60 
       
    61 /*
       
    62  * currently implemented sources
       
    63  */
       
    64 #define NSSRC_FILES	"files"		/* local files */
       
    65 #define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
       
    66 #define	NSSRC_NIS	"nis"		/* YP/NIS */
       
    67 #define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
       
    68 
       
    69 /*
       
    70  * currently implemented databases
       
    71  */
       
    72 #define NSDB_HOSTS		"hosts"
       
    73 #define NSDB_GROUP		"group"
       
    74 #define NSDB_GROUP_COMPAT	"group_compat"
       
    75 #define NSDB_NETGROUP		"netgroup"
       
    76 #define NSDB_NETWORKS		"networks"
       
    77 #define NSDB_PASSWD		"passwd"
       
    78 #define NSDB_PASSWD_COMPAT	"passwd_compat"
       
    79 #define NSDB_SHELLS		"shells"
       
    80 
       
    81 /*
       
    82  * suggested databases to implement
       
    83  */
       
    84 #define NSDB_ALIASES		"aliases"
       
    85 #define NSDB_AUTH		"auth"
       
    86 #define NSDB_AUTOMOUNT		"automount"
       
    87 #define NSDB_BOOTPARAMS		"bootparams"
       
    88 #define NSDB_ETHERS		"ethers"
       
    89 #define NSDB_EXPORTS		"exports"
       
    90 #define NSDB_NETMASKS		"netmasks"
       
    91 #define NSDB_PHONES		"phones"
       
    92 #define NSDB_PRINTCAP		"printcap"
       
    93 #define NSDB_PROTOCOLS		"protocols"
       
    94 #define NSDB_REMOTE		"remote"
       
    95 #define NSDB_RPC		"rpc"
       
    96 #define NSDB_SENDMAILVARS	"sendmailvars"
       
    97 #define NSDB_SERVICES		"services"
       
    98 #define NSDB_TERMCAP		"termcap"
       
    99 #define NSDB_TTYS		"ttys"
       
   100 
       
   101 /*
       
   102  * ns_dtab `method' function signature.
       
   103  */ 
       
   104 typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
       
   105 
       
   106 /*
       
   107  * Macro for generating method prototypes.
       
   108  */
       
   109 #define NSS_METHOD_PROTOTYPE(method) \
       
   110 	int method(void *, void *, va_list)
       
   111 
       
   112 /*
       
   113  * ns_dtab - `nsswitch dispatch table'
       
   114  * Contains an entry for each source and the appropriate function to
       
   115  * call.  ns_dtabs are used in the nsdispatch() API in order to allow
       
   116  * the application to override built-in actions.
       
   117  */
       
   118 typedef struct _ns_dtab {
       
   119 	const char	 *src;		/* Source this entry implements */
       
   120 	nss_method	  method;	/* Method to be called */
       
   121 	void		 *mdata;	/* Data passed to method */
       
   122 } ns_dtab;
       
   123 
       
   124 /*
       
   125  * macros to help build an ns_dtab[]
       
   126  */
       
   127 #define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
       
   128 #define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
       
   129  
       
   130 #ifdef HESIOD
       
   131 #   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
       
   132 #else
       
   133 #   define NS_DNS_CB(F,C)
       
   134 #endif
       
   135 
       
   136 #ifdef YP
       
   137 #   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
       
   138 #else
       
   139 #   define NS_NIS_CB(F,C)
       
   140 #endif
       
   141 
       
   142 /*
       
   143  * ns_src - `nsswitch source'
       
   144  * used by the nsparser routines to store a mapping between a source
       
   145  * and its dispatch control flags for a given database.
       
   146  */
       
   147 typedef struct _ns_src {
       
   148 	const char	*name;
       
   149 	u_int32_t	 flags;
       
   150 } ns_src;
       
   151 
       
   152 
       
   153 /*
       
   154  * default sourcelist (if nsswitch.conf is missing, corrupt,
       
   155  * or the requested database doesn't have an entry.
       
   156  */
       
   157 extern const ns_src __nsdefaultsrc[];
       
   158 
       
   159 /*
       
   160  * ns_mtab - NSS method table
       
   161  * An NSS module provides a mapping from (database name, method name)
       
   162  * tuples to the nss_method and associated data.
       
   163  */
       
   164 typedef struct _ns_mtab {
       
   165 	const char	*database;
       
   166 	const char	*name;
       
   167 	nss_method	 method;
       
   168 	void		*mdata;
       
   169 } ns_mtab;
       
   170 
       
   171 /*
       
   172  * NSS module de-registration, called at module unload.
       
   173  */
       
   174 typedef void	 (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
       
   175 
       
   176 /*
       
   177  * NSS module registration, called at module load.
       
   178  */
       
   179 typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *,
       
   180 		       nss_module_unregister_fn *);
       
   181 
       
   182 /* 
       
   183  * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern.
       
   184  * Developers are encouraged to use nss_lookup_type where approriate.
       
   185  */
       
   186 enum nss_lookup_type {
       
   187 	nss_lt_name = 1,
       
   188 	nss_lt_id   = 2,
       
   189 	nss_lt_all  = 3
       
   190 };
       
   191 
       
   192 #ifdef _NS_PRIVATE
       
   193 
       
   194 /*
       
   195  * private data structures for back-end nsswitch implementation
       
   196  */
       
   197 
       
   198 /*
       
   199  * ns_dbt - `nsswitch database thang'
       
   200  * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
       
   201  * name and a list of ns_src's containing the source information.
       
   202  */
       
   203 typedef struct _ns_dbt {
       
   204 	const char	*name;		/* name of database */
       
   205 	ns_src		*srclist;	/* list of sources */
       
   206 	int		 srclistsize;	/* size of srclist */
       
   207 } ns_dbt;
       
   208 
       
   209 /*
       
   210  * ns_mod - NSS module
       
   211  */
       
   212 typedef struct _ns_mod {
       
   213 	char		*name;		/* module name */
       
   214 	void		*handle;	/* handle from dlopen */
       
   215 	ns_mtab		*mtab;		/* method table */
       
   216 	unsigned int	 mtabsize;	/* count of entries in method table */
       
   217 	nss_module_unregister_fn unregister; /* called to unload module */
       
   218 } ns_mod;
       
   219 
       
   220 #endif /* _NS_PRIVATE */
       
   221 
       
   222 #endif /* !_NSSWITCH_H */