165532Snectar/*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
265532Snectar/*	$FreeBSD$ */
365532Snectar
465532Snectar/*-
565532Snectar * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
665532Snectar * All rights reserved.
765532Snectar *
865532Snectar * This code is derived from software contributed to The NetBSD Foundation
965532Snectar * by Luke Mewburn.
1065532Snectar *
1165532Snectar * Redistribution and use in source and binary forms, with or without
1265532Snectar * modification, are permitted provided that the following conditions
1365532Snectar * are met:
1465532Snectar * 1. Redistributions of source code must retain the above copyright
1565532Snectar *    notice, this list of conditions and the following disclaimer.
1665532Snectar * 2. Redistributions in binary form must reproduce the above copyright
1765532Snectar *    notice, this list of conditions and the following disclaimer in the
1865532Snectar *    documentation and/or other materials provided with the distribution.
1965532Snectar *
2065532Snectar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2165532Snectar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2265532Snectar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2365532Snectar * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2465532Snectar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2565532Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2665532Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2765532Snectar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2865532Snectar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2965532Snectar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3065532Snectar * POSSIBILITY OF SUCH DAMAGE.
3165532Snectar */
3265532Snectar
3365532Snectar#ifndef _NSSWITCH_H
3465532Snectar#define _NSSWITCH_H	1
3565532Snectar
3665532Snectar#include <sys/types.h>
3765532Snectar#include <stdarg.h>
3865532Snectar
39113595Snectar#define NSS_MODULE_INTERFACE_VERSION 1
40113595Snectar
4165532Snectar#ifndef _PATH_NS_CONF
4265532Snectar#define _PATH_NS_CONF	"/etc/nsswitch.conf"
4365532Snectar#endif
4465532Snectar
45113595Snectar/* NSS source actions */
46113595Snectar#define	NS_ACTION_CONTINUE	0	/* try the next source */
47113595Snectar#define	NS_ACTION_RETURN	1	/* look no further */
4865532Snectar
4965532Snectar#define	NS_SUCCESS	(1<<0)		/* entry was found */
5065532Snectar#define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
5165532Snectar#define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
52113595Snectar#define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retry */
53113595Snectar#define NS_RETURN	(1<<4)		/* stop search, e.g. for ERANGE */
54113595Snectar#define NS_TERMINATE	(NS_SUCCESS|NS_RETURN) /* flags that end search */
5565532Snectar#define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
5665532Snectar
5765532Snectar/*
5865532Snectar * currently implemented sources
5965532Snectar */
6065532Snectar#define NSSRC_FILES	"files"		/* local files */
61206155Sume#define	NSSRC_DB	"db"		/* database */
6265532Snectar#define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
6365532Snectar#define	NSSRC_NIS	"nis"		/* YP/NIS */
6465532Snectar#define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
65174547Sbushman#define	NSSRC_CACHE	"cache"		/* nscd daemon */
66174547Sbushman#define NSSRC_FALLBACK	"__fallback"	/* internal fallback source */
6765532Snectar
6865532Snectar/*
6965532Snectar * currently implemented databases
7065532Snectar */
7165532Snectar#define NSDB_HOSTS		"hosts"
7265532Snectar#define NSDB_GROUP		"group"
7365532Snectar#define NSDB_GROUP_COMPAT	"group_compat"
7465532Snectar#define NSDB_NETGROUP		"netgroup"
7565532Snectar#define NSDB_NETWORKS		"networks"
7665532Snectar#define NSDB_PASSWD		"passwd"
7765532Snectar#define NSDB_PASSWD_COMPAT	"passwd_compat"
7865532Snectar#define NSDB_SHELLS		"shells"
79158115Sume#define NSDB_SERVICES		"services"
80158115Sume#define NSDB_SERVICES_COMPAT	"services_compat"
81158115Sume#define NSDB_SSH_HOSTKEYS	"ssh_hostkeys"
82158115Sume#define NSDB_PROTOCOLS		"protocols"
83158115Sume#define NSDB_RPC		"rpc"
8465532Snectar
8565532Snectar/*
8665532Snectar * suggested databases to implement
8765532Snectar */
8865532Snectar#define NSDB_ALIASES		"aliases"
8965532Snectar#define NSDB_AUTH		"auth"
9065532Snectar#define NSDB_AUTOMOUNT		"automount"
9165532Snectar#define NSDB_BOOTPARAMS		"bootparams"
9265532Snectar#define NSDB_ETHERS		"ethers"
9365532Snectar#define NSDB_EXPORTS		"exports"
9465532Snectar#define NSDB_NETMASKS		"netmasks"
9565532Snectar#define NSDB_PHONES		"phones"
9665532Snectar#define NSDB_PRINTCAP		"printcap"
9765532Snectar#define NSDB_REMOTE		"remote"
9865532Snectar#define NSDB_SENDMAILVARS	"sendmailvars"
9965532Snectar#define NSDB_TERMCAP		"termcap"
10065532Snectar#define NSDB_TTYS		"ttys"
10165532Snectar
10265532Snectar/*
103113595Snectar * ns_dtab `method' function signature.
104113595Snectar */
105113595Snectartypedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
106113595Snectar
107113595Snectar/*
108113595Snectar * Macro for generating method prototypes.
109113595Snectar */
110113595Snectar#define NSS_METHOD_PROTOTYPE(method) \
111113595Snectar	int method(void *, void *, va_list)
112113595Snectar
113113595Snectar/*
11465532Snectar * ns_dtab - `nsswitch dispatch table'
115113595Snectar * Contains an entry for each source and the appropriate function to
116113595Snectar * call.  ns_dtabs are used in the nsdispatch() API in order to allow
117113595Snectar * the application to override built-in actions.
11865532Snectar */
119113595Snectartypedef struct _ns_dtab {
120113595Snectar	const char	 *src;		/* Source this entry implements */
121113595Snectar	nss_method	  method;	/* Method to be called */
122113595Snectar	void		 *mdata;	/* Data passed to method */
12365532Snectar} ns_dtab;
12465532Snectar
12565532Snectar/*
12665532Snectar * macros to help build an ns_dtab[]
12765532Snectar */
12865532Snectar#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
12965532Snectar#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
130174547Sbushman#define NS_FALLBACK_CB(F)	{ NSSRC_FALLBACK, F,	NULL },
13165532Snectar
13265532Snectar#ifdef HESIOD
13365532Snectar#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
13465532Snectar#else
13565532Snectar#   define NS_DNS_CB(F,C)
13665532Snectar#endif
13765532Snectar
13865532Snectar#ifdef YP
13965532Snectar#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
14065532Snectar#else
14165532Snectar#   define NS_NIS_CB(F,C)
14265532Snectar#endif
14365532Snectar
14465532Snectar/*
14565532Snectar * ns_src - `nsswitch source'
14665532Snectar * used by the nsparser routines to store a mapping between a source
14765532Snectar * and its dispatch control flags for a given database.
14865532Snectar */
149113595Snectartypedef struct _ns_src {
15065532Snectar	const char	*name;
15165532Snectar	u_int32_t	 flags;
15265532Snectar} ns_src;
15365532Snectar
15465532Snectar
15565532Snectar/*
15665532Snectar * default sourcelist (if nsswitch.conf is missing, corrupt,
15765532Snectar * or the requested database doesn't have an entry.
15865532Snectar */
15965532Snectarextern const ns_src __nsdefaultsrc[];
16065532Snectar
161113595Snectar/*
162113595Snectar * ns_mtab - NSS method table
163113595Snectar * An NSS module provides a mapping from (database name, method name)
164113595Snectar * tuples to the nss_method and associated data.
165113595Snectar */
166113595Snectartypedef struct _ns_mtab {
167113595Snectar	const char	*database;
168113595Snectar	const char	*name;
169113595Snectar	nss_method	 method;
170113595Snectar	void		*mdata;
171113595Snectar} ns_mtab;
17265532Snectar
173113595Snectar/*
174113595Snectar * NSS module de-registration, called at module unload.
175113595Snectar */
176113595Snectartypedef void	 (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
177113595Snectar
178113595Snectar/*
179113595Snectar * NSS module registration, called at module load.
180113595Snectar */
181113595Snectartypedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *,
182113595Snectar		       nss_module_unregister_fn *);
183113595Snectar
184113595Snectar/*
185113595Snectar * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern.
186113595Snectar * Developers are encouraged to use nss_lookup_type where approriate.
187113595Snectar */
188113595Snectarenum nss_lookup_type {
189113595Snectar	nss_lt_name = 1,
190113595Snectar	nss_lt_id   = 2,
191113595Snectar	nss_lt_all  = 3
192113595Snectar};
193113595Snectar
19465532Snectar#ifdef _NS_PRIVATE
19565532Snectar/*
19665532Snectar * private data structures for back-end nsswitch implementation
19765532Snectar */
19865532Snectar
19965532Snectar/*
20065532Snectar * ns_dbt - `nsswitch database thang'
20165532Snectar * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
20265532Snectar * name and a list of ns_src's containing the source information.
20365532Snectar */
204113595Snectartypedef struct _ns_dbt {
20565532Snectar	const char	*name;		/* name of database */
20665532Snectar	ns_src		*srclist;	/* list of sources */
20765532Snectar	int		 srclistsize;	/* size of srclist */
20865532Snectar} ns_dbt;
20965532Snectar
210113595Snectar/*
211113595Snectar * ns_mod - NSS module
212113595Snectar */
213113595Snectartypedef struct _ns_mod {
214113595Snectar	char		*name;		/* module name */
215113595Snectar	void		*handle;	/* handle from dlopen */
216113595Snectar	ns_mtab		*mtab;		/* method table */
217113595Snectar	unsigned int	 mtabsize;	/* count of entries in method table */
218113595Snectar	nss_module_unregister_fn unregister; /* called to unload module */
219113595Snectar} ns_mod;
220113595Snectar
22165532Snectar#endif /* _NS_PRIVATE */
22265532Snectar
22365532Snectar
22465532Snectar#include <sys/cdefs.h>
22565532Snectar
22665532Snectar__BEGIN_DECLS
22793032Simpextern	int	nsdispatch(void *, const ns_dtab [], const char *,
22893032Simp			   const char *, const ns_src [], ...);
22965532Snectar
23065532Snectar#ifdef _NS_PRIVATE
23193032Simpextern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
23293032Simpextern	void		 _nsdbtput(const ns_dbt *);
23393032Simpextern	void		 _nsyyerror(const char *);
23493032Simpextern	int		 _nsyylex(void);
235113595Snectarextern	int		 _nsyyparse(void);
23665532Snectarextern	int		 _nsyylineno;
237113595Snectar#ifdef _NSS_DEBUG
238113595Snectarextern	void		 _nsdbtdump(const ns_dbt *);
239113595Snectar#endif
24065532Snectar#endif /* _NS_PRIVATE */
24165532Snectar
24265532Snectar__END_DECLS
24365532Snectar
24465532Snectar#endif /* !_NSSWITCH_H */
245