nsswitch.h revision 158115
165532Snectar/*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
265532Snectar/*	$FreeBSD: head/include/nsswitch.h 158115 2006-04-28 12:03:38Z ume $ */
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 * 3. All advertising materials mentioning features or use of this software
2065532Snectar *    must display the following acknowledgement:
2165532Snectar *        This product includes software developed by the NetBSD
2265532Snectar *        Foundation, Inc. and its contributors.
2365532Snectar * 4. Neither the name of The NetBSD Foundation nor the names of its
2465532Snectar *    contributors may be used to endorse or promote products derived
2565532Snectar *    from this software without specific prior written permission.
2665532Snectar *
2765532Snectar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2865532Snectar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2965532Snectar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3065532Snectar * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3165532Snectar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3265532Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3365532Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3465532Snectar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3565532Snectar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3665532Snectar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3765532Snectar * POSSIBILITY OF SUCH DAMAGE.
3865532Snectar */
3965532Snectar
4065532Snectar#ifndef _NSSWITCH_H
4165532Snectar#define _NSSWITCH_H	1
4265532Snectar
4365532Snectar#include <sys/types.h>
4465532Snectar#include <stdarg.h>
4565532Snectar
46113595Snectar#define NSS_MODULE_INTERFACE_VERSION 1
47113595Snectar
4865532Snectar#ifndef _PATH_NS_CONF
4965532Snectar#define _PATH_NS_CONF	"/etc/nsswitch.conf"
5065532Snectar#endif
5165532Snectar
52113595Snectar/* NSS source actions */
53113595Snectar#define	NS_ACTION_CONTINUE	0	/* try the next source */
54113595Snectar#define	NS_ACTION_RETURN	1	/* look no further */
5565532Snectar
5665532Snectar#define	NS_SUCCESS	(1<<0)		/* entry was found */
5765532Snectar#define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
5865532Snectar#define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
59113595Snectar#define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retry */
60113595Snectar#define NS_RETURN	(1<<4)		/* stop search, e.g. for ERANGE */
61113595Snectar#define NS_TERMINATE	(NS_SUCCESS|NS_RETURN) /* flags that end search */
6265532Snectar#define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
6365532Snectar
6465532Snectar/*
6565532Snectar * currently implemented sources
6665532Snectar */
6765532Snectar#define NSSRC_FILES	"files"		/* local files */
6865532Snectar#define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
6965532Snectar#define	NSSRC_NIS	"nis"		/* YP/NIS */
7065532Snectar#define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
71158115Sume#define	NSSRC_CACHE	"cache"		/* cache daemon */
7265532Snectar
7365532Snectar/*
7465532Snectar * currently implemented databases
7565532Snectar */
7665532Snectar#define NSDB_HOSTS		"hosts"
7765532Snectar#define NSDB_GROUP		"group"
7865532Snectar#define NSDB_GROUP_COMPAT	"group_compat"
7965532Snectar#define NSDB_NETGROUP		"netgroup"
8065532Snectar#define NSDB_NETWORKS		"networks"
8165532Snectar#define NSDB_PASSWD		"passwd"
8265532Snectar#define NSDB_PASSWD_COMPAT	"passwd_compat"
8365532Snectar#define NSDB_SHELLS		"shells"
84158115Sume#define NSDB_SERVICES		"services"
85158115Sume#define NSDB_SERVICES_COMPAT	"services_compat"
86158115Sume#define NSDB_SSH_HOSTKEYS	"ssh_hostkeys"
87158115Sume#define NSDB_PROTOCOLS		"protocols"
88158115Sume#define NSDB_RPC		"rpc"
8965532Snectar
9065532Snectar/*
9165532Snectar * suggested databases to implement
9265532Snectar */
9365532Snectar#define NSDB_ALIASES		"aliases"
9465532Snectar#define NSDB_AUTH		"auth"
9565532Snectar#define NSDB_AUTOMOUNT		"automount"
9665532Snectar#define NSDB_BOOTPARAMS		"bootparams"
9765532Snectar#define NSDB_ETHERS		"ethers"
9865532Snectar#define NSDB_EXPORTS		"exports"
9965532Snectar#define NSDB_NETMASKS		"netmasks"
10065532Snectar#define NSDB_PHONES		"phones"
10165532Snectar#define NSDB_PRINTCAP		"printcap"
10265532Snectar#define NSDB_REMOTE		"remote"
10365532Snectar#define NSDB_SENDMAILVARS	"sendmailvars"
10465532Snectar#define NSDB_TERMCAP		"termcap"
10565532Snectar#define NSDB_TTYS		"ttys"
10665532Snectar
10765532Snectar/*
108113595Snectar * ns_dtab `method' function signature.
109113595Snectar */
110113595Snectartypedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
111113595Snectar
112113595Snectar/*
113113595Snectar * Macro for generating method prototypes.
114113595Snectar */
115113595Snectar#define NSS_METHOD_PROTOTYPE(method) \
116113595Snectar	int method(void *, void *, va_list)
117113595Snectar
118113595Snectar/*
11965532Snectar * ns_dtab - `nsswitch dispatch table'
120113595Snectar * Contains an entry for each source and the appropriate function to
121113595Snectar * call.  ns_dtabs are used in the nsdispatch() API in order to allow
122113595Snectar * the application to override built-in actions.
12365532Snectar */
124113595Snectartypedef struct _ns_dtab {
125113595Snectar	const char	 *src;		/* Source this entry implements */
126113595Snectar	nss_method	  method;	/* Method to be called */
127113595Snectar	void		 *mdata;	/* Data passed to method */
12865532Snectar} ns_dtab;
12965532Snectar
13065532Snectar/*
13165532Snectar * macros to help build an ns_dtab[]
13265532Snectar */
13365532Snectar#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
13465532Snectar#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
13565532Snectar
13665532Snectar#ifdef HESIOD
13765532Snectar#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
13865532Snectar#else
13965532Snectar#   define NS_DNS_CB(F,C)
14065532Snectar#endif
14165532Snectar
14265532Snectar#ifdef YP
14365532Snectar#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
14465532Snectar#else
14565532Snectar#   define NS_NIS_CB(F,C)
14665532Snectar#endif
14765532Snectar
14865532Snectar/*
14965532Snectar * ns_src - `nsswitch source'
15065532Snectar * used by the nsparser routines to store a mapping between a source
15165532Snectar * and its dispatch control flags for a given database.
15265532Snectar */
153113595Snectartypedef struct _ns_src {
15465532Snectar	const char	*name;
15565532Snectar	u_int32_t	 flags;
15665532Snectar} ns_src;
15765532Snectar
15865532Snectar
15965532Snectar/*
16065532Snectar * default sourcelist (if nsswitch.conf is missing, corrupt,
16165532Snectar * or the requested database doesn't have an entry.
16265532Snectar */
16365532Snectarextern const ns_src __nsdefaultsrc[];
16465532Snectar
165113595Snectar/*
166113595Snectar * ns_mtab - NSS method table
167113595Snectar * An NSS module provides a mapping from (database name, method name)
168113595Snectar * tuples to the nss_method and associated data.
169113595Snectar */
170113595Snectartypedef struct _ns_mtab {
171113595Snectar	const char	*database;
172113595Snectar	const char	*name;
173113595Snectar	nss_method	 method;
174113595Snectar	void		*mdata;
175113595Snectar} ns_mtab;
17665532Snectar
177113595Snectar/*
178113595Snectar * NSS module de-registration, called at module unload.
179113595Snectar */
180113595Snectartypedef void	 (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
181113595Snectar
182113595Snectar/*
183113595Snectar * NSS module registration, called at module load.
184113595Snectar */
185113595Snectartypedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *,
186113595Snectar		       nss_module_unregister_fn *);
187113595Snectar
188113595Snectar/*
189113595Snectar * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern.
190113595Snectar * Developers are encouraged to use nss_lookup_type where approriate.
191113595Snectar */
192113595Snectarenum nss_lookup_type {
193113595Snectar	nss_lt_name = 1,
194113595Snectar	nss_lt_id   = 2,
195113595Snectar	nss_lt_all  = 3
196113595Snectar};
197113595Snectar
19865532Snectar#ifdef _NS_PRIVATE
19965532Snectar/*
20065532Snectar * private data structures for back-end nsswitch implementation
20165532Snectar */
20265532Snectar
20365532Snectar/*
20465532Snectar * ns_dbt - `nsswitch database thang'
20565532Snectar * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
20665532Snectar * name and a list of ns_src's containing the source information.
20765532Snectar */
208113595Snectartypedef struct _ns_dbt {
20965532Snectar	const char	*name;		/* name of database */
21065532Snectar	ns_src		*srclist;	/* list of sources */
21165532Snectar	int		 srclistsize;	/* size of srclist */
21265532Snectar} ns_dbt;
21365532Snectar
214113595Snectar/*
215113595Snectar * ns_mod - NSS module
216113595Snectar */
217113595Snectartypedef struct _ns_mod {
218113595Snectar	char		*name;		/* module name */
219113595Snectar	void		*handle;	/* handle from dlopen */
220113595Snectar	ns_mtab		*mtab;		/* method table */
221113595Snectar	unsigned int	 mtabsize;	/* count of entries in method table */
222113595Snectar	nss_module_unregister_fn unregister; /* called to unload module */
223113595Snectar} ns_mod;
224113595Snectar
22565532Snectar#endif /* _NS_PRIVATE */
22665532Snectar
22765532Snectar
22865532Snectar#include <sys/cdefs.h>
22965532Snectar
23065532Snectar__BEGIN_DECLS
23193032Simpextern	int	nsdispatch(void *, const ns_dtab [], const char *,
23293032Simp			   const char *, const ns_src [], ...);
23365532Snectar
23465532Snectar#ifdef _NS_PRIVATE
23593032Simpextern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
23693032Simpextern	void		 _nsdbtput(const ns_dbt *);
23793032Simpextern	void		 _nsyyerror(const char *);
23893032Simpextern	int		 _nsyylex(void);
239113595Snectarextern	int		 _nsyyparse(void);
24065532Snectarextern	int		 _nsyylineno;
241113595Snectar#ifdef _NSS_DEBUG
242113595Snectarextern	void		 _nsdbtdump(const ns_dbt *);
243113595Snectar#endif
24465532Snectar#endif /* _NS_PRIVATE */
24565532Snectar
24665532Snectar__END_DECLS
24765532Snectar
24865532Snectar#endif /* !_NSSWITCH_H */
249