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