1/*	$NetBSD: nsswitch.h,v 1.18 2005/11/29 03:12:58 christos 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#include <sys/types.h>
43#include <stdarg.h>
44
45#define	NSS_MODULE_INTERFACE_VERSION	0
46
47#ifndef _PATH_NS_CONF
48#define _PATH_NS_CONF	"/etc/nsswitch.conf"
49#endif
50
51#define	NS_CONTINUE	0
52#define	NS_RETURN	1
53
54/*
55 * Layout of:
56 *	uint32_t ns_src.flags
57 */
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 */
64
65	/* internal nsdispatch(3) flags; not settable in nsswitch.conf(5)  */
66#define	NS_FORCEALL	(1<<8)		/* force all methods to be invoked; */
67
68/*
69 * Currently implemented sources.
70 */
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 */
75
76/*
77 * Currently implemented databases.
78 */
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"
87
88/*
89 * Suggested databases to implement.
90 */
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"
107
108/*
109 * ns_dtab `callback' function signature.
110 */
111typedef	int (*nss_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 call.
116 */
117typedef struct {
118	const char	 *src;
119	nss_method	 callback;
120	void		 *cb_data;
121} ns_dtab;
122
123/*
124 * Macros to help build an ns_dtab[]
125 */
126#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	__UNCONST(C) },
127#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	__UNCONST(C) },
128
129#ifdef HESIOD
130#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	__UNCONST(C) },
131#else
132#   define NS_DNS_CB(F,C)
133#endif
134
135#ifdef YP
136#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	__UNCONST(C) },
137#else
138#   define NS_NIS_CB(F,C)
139#endif
140
141/*
142 * ns_src - `nsswitch source'
143 * Used by the nsparser routines to store a mapping between a source
144 * and its dispatch control flags for a given database.
145 */
146typedef struct {
147	const char	*name;
148	uint32_t	 flags;
149} ns_src;
150
151
152/*
153 * Default sourcelists (if nsswitch.conf is missing, corrupt,
154 * or the requested database doesn't have an entry)
155 */
156extern const ns_src __nsdefaultsrc[];
157extern const ns_src __nsdefaultcompat[];
158extern const ns_src __nsdefaultcompat_forceall[];
159extern const ns_src __nsdefaultfiles[];
160extern const ns_src __nsdefaultfiles_forceall[];
161extern const ns_src __nsdefaultnis[];
162extern const ns_src __nsdefaultnis_forceall[];
163
164
165/*
166 * ns_mtab - `nsswitch method table'
167 * An nsswitch module provides a mapping from (database name, method name)
168 * tuples to the nss_method and associated callback data.  Effectively,
169 * ns_dtab, but used for dynamically loaded modules.
170 */
171typedef struct {
172	const char	*database;
173	const char	*name;
174	nss_method	 method;
175	void		*mdata;
176} ns_mtab;
177
178/*
179 * nss_module_register_fn - module registration function
180 *	called at module load
181 * nss_module_unregister_fn - module un-registration function
182 *	called at module unload
183 */
184typedef	void (*nss_module_unregister_fn)(ns_mtab *, u_int);
185typedef	ns_mtab *(*nss_module_register_fn)(const char *, u_int *,
186					   nss_module_unregister_fn *);
187
188#ifdef _NS_PRIVATE
189
190/*
191 * Private data structures for back-end nsswitch implementation.
192 */
193
194/*
195 * ns_dbt - `nsswitch database thang'
196 * For each database in /etc/nsswitch.conf there is a ns_dbt, with its
197 * name and a list of ns_src's containing the source information.
198 */
199typedef struct {
200	const char	*name;		/* name of database */
201	ns_src		*srclist;	/* list of sources */
202	u_int		 srclistsize;	/* size of srclist */
203} ns_dbt;
204
205/*
206 * ns_mod - `nsswitch module'
207 */
208typedef struct {
209	const char	*name;		/* module name */
210	void		*handle;	/* handle from dlopen() */
211	ns_mtab		*mtab;		/* method table */
212	u_int		 mtabsize;	/* size of mtab */
213					/* called to unload module */
214	nss_module_unregister_fn unregister;
215} ns_mod;
216
217#endif /* _NS_PRIVATE */
218
219
220#include <sys/cdefs.h>
221
222__BEGIN_DECLS
223int	nsdispatch(void *, const ns_dtab [], const char *,
224			const char *, const ns_src [], ...);
225
226#ifdef _NS_PRIVATE
227int		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
228void		 _nsdbtdump(const ns_dbt *);
229int		 _nsdbtput(const ns_dbt *);
230void		 _nsyyerror(const char *);
231int		 _nsyylex(void);
232#endif /* _NS_PRIVATE */
233
234__END_DECLS
235
236#endif /* !_NSSWITCH_H */
237