1 /* $NetBSD: nsswitch.h,v 1.19 2006/10/15 16:10:38 christos Exp $ */
4 * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
36 * Don't use va_list in prototypes. va_list is typedef'd in two places
37 * (<machine/varargs.h> and <machine/stdarg.h>), so if we include one of
38 * them here we may collide with the utility's includes. It's unreasonable
39 * for utilities to have to include one of them to include nsswitch.h, so
40 * we get _BSD_VA_LIST_ from <machine/ansi.h> and use it.
42 #include <machine/ansi.h>
43 #include <sys/types.h>
45 #define NSS_MODULE_INTERFACE_VERSION 0
48 #define _PATH_NS_CONF "/etc/nsswitch.conf"
56 * uint32_t ns_src.flags
58 /* nsswitch.conf status codes and nsdispatch(3) return values */
59 #define NS_SUCCESS (1<<0) /* entry was found */
60 #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */
61 #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */
62 #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retrys */
63 #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */
65 /* internal nsdispatch(3) flags; not settable in nsswitch.conf(5) */
66 #define NS_FORCEALL (1<<8) /* force all methods to be invoked; */
69 * Currently implemented sources.
71 #define NSSRC_FILES "files" /* local files */
72 #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */
73 #define NSSRC_NIS "nis" /* YP/NIS */
74 #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */
77 * Currently implemented databases.
79 #define NSDB_HOSTS "hosts"
80 #define NSDB_GROUP "group"
81 #define NSDB_GROUP_COMPAT "group_compat"
82 #define NSDB_NETGROUP "netgroup"
83 #define NSDB_NETWORKS "networks"
84 #define NSDB_PASSWD "passwd"
85 #define NSDB_PASSWD_COMPAT "passwd_compat"
86 #define NSDB_SHELLS "shells"
89 * Suggested databases to implement.
91 #define NSDB_ALIASES "aliases"
92 #define NSDB_AUTH "auth"
93 #define NSDB_AUTOMOUNT "automount"
94 #define NSDB_BOOTPARAMS "bootparams"
95 #define NSDB_ETHERS "ethers"
96 #define NSDB_EXPORTS "exports"
97 #define NSDB_NETMASKS "netmasks"
98 #define NSDB_PHONES "phones"
99 #define NSDB_PRINTCAP "printcap"
100 #define NSDB_PROTOCOLS "protocols"
101 #define NSDB_REMOTE "remote"
102 #define NSDB_RPC "rpc"
103 #define NSDB_SENDMAILVARS "sendmailvars"
104 #define NSDB_SERVICES "services"
105 #define NSDB_TERMCAP "termcap"
106 #define NSDB_TTYS "ttys"
109 * ns_dtab `callback' function signature.
111 typedef int (*nss_method
)(void *, void *, _BSD_VA_LIST_
);
114 * ns_dtab - `nsswitch dispatch table'
115 * Contains an entry for each source and the appropriate function to call.
124 * Macros to help build an ns_dtab[]
126 #define NS_FILES_CB(F,C) { NSSRC_FILES, F, __UNCONST(C) },
127 #define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, __UNCONST(C) },
130 # define NS_DNS_CB(F,C) { NSSRC_DNS, F, __UNCONST(C) },
132 # define NS_DNS_CB(F,C)
136 # define NS_NIS_CB(F,C) { NSSRC_NIS, F, __UNCONST(C) },
138 # define NS_NIS_CB(F,C)
140 #define NS_NULL_CB { .src = NULL },
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.
154 * Default sourcelists (if nsswitch.conf is missing, corrupt,
155 * or the requested database doesn't have an entry)
157 extern const ns_src __nsdefaultsrc
[];
158 extern const ns_src __nsdefaultcompat
[];
159 extern const ns_src __nsdefaultcompat_forceall
[];
160 extern const ns_src __nsdefaultfiles
[];
161 extern const ns_src __nsdefaultfiles_forceall
[];
162 extern const ns_src __nsdefaultnis
[];
163 extern const ns_src __nsdefaultnis_forceall
[];
167 * ns_mtab - `nsswitch method table'
168 * An nsswitch module provides a mapping from (database name, method name)
169 * tuples to the nss_method and associated callback data. Effectively,
170 * ns_dtab, but used for dynamically loaded modules.
173 const char *database
;
180 * nss_module_register_fn - module registration function
181 * called at module load
182 * nss_module_unregister_fn - module un-registration function
183 * called at module unload
185 typedef void (*nss_module_unregister_fn
)(ns_mtab
*, u_int
);
186 typedef ns_mtab
*(*nss_module_register_fn
)(const char *, u_int
*,
187 nss_module_unregister_fn
*);
192 * Private data structures for back-end nsswitch implementation.
196 * ns_dbt - `nsswitch database thang'
197 * For each database in /etc/nsswitch.conf there is a ns_dbt, with its
198 * name and a list of ns_src's containing the source information.
201 const char *name
; /* name of database */
202 ns_src
*srclist
; /* list of sources */
203 u_int srclistsize
; /* size of srclist */
207 * ns_mod - `nsswitch module'
210 const char *name
; /* module name */
211 void *handle
; /* handle from dlopen() */
212 ns_mtab
*mtab
; /* method table */
213 u_int mtabsize
; /* size of mtab */
214 /* called to unload module */
215 nss_module_unregister_fn unregister
;
218 #endif /* _NS_PRIVATE */
221 #include <sys/cdefs.h>
224 int nsdispatch(void *, const ns_dtab
[], const char *,
225 const char *, const ns_src
[], ...);
228 int _nsdbtaddsrc(ns_dbt
*, const ns_src
*);
229 void _nsdbtdump(const ns_dbt
*);
230 int _nsdbtput(const ns_dbt
*);
231 void _nsyyerror(const char *);
233 #endif /* _NS_PRIVATE */
237 #endif /* !_NSSWITCH_H */