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