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