nsswitch.h revision 174547
165532Snectar/*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
265532Snectar/*	$FreeBSD: head/include/nsswitch.h 174547 2007-12-12 10:08:03Z bushman $ */
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 */
71174547Sbushman#define	NSSRC_CACHE	"cache"		/* nscd daemon */
72174547Sbushman#define NSSRC_FALLBACK	"__fallback"	/* internal fallback source */
7365532Snectar
7465532Snectar/*
7565532Snectar * currently implemented databases
7665532Snectar */
7765532Snectar#define NSDB_HOSTS		"hosts"
7865532Snectar#define NSDB_GROUP		"group"
7965532Snectar#define NSDB_GROUP_COMPAT	"group_compat"
8065532Snectar#define NSDB_NETGROUP		"netgroup"
8165532Snectar#define NSDB_NETWORKS		"networks"
8265532Snectar#define NSDB_PASSWD		"passwd"
8365532Snectar#define NSDB_PASSWD_COMPAT	"passwd_compat"
8465532Snectar#define NSDB_SHELLS		"shells"
85158115Sume#define NSDB_SERVICES		"services"
86158115Sume#define NSDB_SERVICES_COMPAT	"services_compat"
87158115Sume#define NSDB_SSH_HOSTKEYS	"ssh_hostkeys"
88158115Sume#define NSDB_PROTOCOLS		"protocols"
89158115Sume#define NSDB_RPC		"rpc"
9065532Snectar
9165532Snectar/*
9265532Snectar * suggested databases to implement
9365532Snectar */
9465532Snectar#define NSDB_ALIASES		"aliases"
9565532Snectar#define NSDB_AUTH		"auth"
9665532Snectar#define NSDB_AUTOMOUNT		"automount"
9765532Snectar#define NSDB_BOOTPARAMS		"bootparams"
9865532Snectar#define NSDB_ETHERS		"ethers"
9965532Snectar#define NSDB_EXPORTS		"exports"
10065532Snectar#define NSDB_NETMASKS		"netmasks"
10165532Snectar#define NSDB_PHONES		"phones"
10265532Snectar#define NSDB_PRINTCAP		"printcap"
10365532Snectar#define NSDB_REMOTE		"remote"
10465532Snectar#define NSDB_SENDMAILVARS	"sendmailvars"
10565532Snectar#define NSDB_TERMCAP		"termcap"
10665532Snectar#define NSDB_TTYS		"ttys"
10765532Snectar
10865532Snectar/*
109113595Snectar * ns_dtab `method' function signature.
110113595Snectar */
111113595Snectartypedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
112113595Snectar
113113595Snectar/*
114113595Snectar * Macro for generating method prototypes.
115113595Snectar */
116113595Snectar#define NSS_METHOD_PROTOTYPE(method) \
117113595Snectar	int method(void *, void *, va_list)
118113595Snectar
119113595Snectar/*
12065532Snectar * ns_dtab - `nsswitch dispatch table'
121113595Snectar * Contains an entry for each source and the appropriate function to
122113595Snectar * call.  ns_dtabs are used in the nsdispatch() API in order to allow
123113595Snectar * the application to override built-in actions.
12465532Snectar */
125113595Snectartypedef struct _ns_dtab {
126113595Snectar	const char	 *src;		/* Source this entry implements */
127113595Snectar	nss_method	  method;	/* Method to be called */
128113595Snectar	void		 *mdata;	/* Data passed to method */
12965532Snectar} ns_dtab;
13065532Snectar
13165532Snectar/*
13265532Snectar * macros to help build an ns_dtab[]
13365532Snectar */
13465532Snectar#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
13565532Snectar#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
136174547Sbushman#define NS_FALLBACK_CB(F)	{ NSSRC_FALLBACK, F,	NULL },
13765532Snectar
13865532Snectar#ifdef HESIOD
13965532Snectar#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
14065532Snectar#else
14165532Snectar#   define NS_DNS_CB(F,C)
14265532Snectar#endif
14365532Snectar
14465532Snectar#ifdef YP
14565532Snectar#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
14665532Snectar#else
14765532Snectar#   define NS_NIS_CB(F,C)
14865532Snectar#endif
14965532Snectar
15065532Snectar/*
15165532Snectar * ns_src - `nsswitch source'
15265532Snectar * used by the nsparser routines to store a mapping between a source
15365532Snectar * and its dispatch control flags for a given database.
15465532Snectar */
155113595Snectartypedef struct _ns_src {
15665532Snectar	const char	*name;
15765532Snectar	u_int32_t	 flags;
15865532Snectar} ns_src;
15965532Snectar
16065532Snectar
16165532Snectar/*
16265532Snectar * default sourcelist (if nsswitch.conf is missing, corrupt,
16365532Snectar * or the requested database doesn't have an entry.
16465532Snectar */
16565532Snectarextern const ns_src __nsdefaultsrc[];
16665532Snectar
167113595Snectar/*
168113595Snectar * ns_mtab - NSS method table
169113595Snectar * An NSS module provides a mapping from (database name, method name)
170113595Snectar * tuples to the nss_method and associated data.
171113595Snectar */
172113595Snectartypedef struct _ns_mtab {
173113595Snectar	const char	*database;
174113595Snectar	const char	*name;
175113595Snectar	nss_method	 method;
176113595Snectar	void		*mdata;
177113595Snectar} ns_mtab;
17865532Snectar
179113595Snectar/*
180113595Snectar * NSS module de-registration, called at module unload.
181113595Snectar */
182113595Snectartypedef void	 (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
183113595Snectar
184113595Snectar/*
185113595Snectar * NSS module registration, called at module load.
186113595Snectar */
187113595Snectartypedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *,
188113595Snectar		       nss_module_unregister_fn *);
189113595Snectar
190113595Snectar/*
191113595Snectar * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern.
192113595Snectar * Developers are encouraged to use nss_lookup_type where approriate.
193113595Snectar */
194113595Snectarenum nss_lookup_type {
195113595Snectar	nss_lt_name = 1,
196113595Snectar	nss_lt_id   = 2,
197113595Snectar	nss_lt_all  = 3
198113595Snectar};
199113595Snectar
20065532Snectar#ifdef _NS_PRIVATE
20165532Snectar/*
20265532Snectar * private data structures for back-end nsswitch implementation
20365532Snectar */
20465532Snectar
20565532Snectar/*
20665532Snectar * ns_dbt - `nsswitch database thang'
20765532Snectar * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
20865532Snectar * name and a list of ns_src's containing the source information.
20965532Snectar */
210113595Snectartypedef struct _ns_dbt {
21165532Snectar	const char	*name;		/* name of database */
21265532Snectar	ns_src		*srclist;	/* list of sources */
21365532Snectar	int		 srclistsize;	/* size of srclist */
21465532Snectar} ns_dbt;
21565532Snectar
216113595Snectar/*
217113595Snectar * ns_mod - NSS module
218113595Snectar */
219113595Snectartypedef struct _ns_mod {
220113595Snectar	char		*name;		/* module name */
221113595Snectar	void		*handle;	/* handle from dlopen */
222113595Snectar	ns_mtab		*mtab;		/* method table */
223113595Snectar	unsigned int	 mtabsize;	/* count of entries in method table */
224113595Snectar	nss_module_unregister_fn unregister; /* called to unload module */
225113595Snectar} ns_mod;
226113595Snectar
22765532Snectar#endif /* _NS_PRIVATE */
22865532Snectar
22965532Snectar
23065532Snectar#include <sys/cdefs.h>
23165532Snectar
23265532Snectar__BEGIN_DECLS
23393032Simpextern	int	nsdispatch(void *, const ns_dtab [], const char *,
23493032Simp			   const char *, const ns_src [], ...);
23565532Snectar
23665532Snectar#ifdef _NS_PRIVATE
23793032Simpextern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
23893032Simpextern	void		 _nsdbtput(const ns_dbt *);
23993032Simpextern	void		 _nsyyerror(const char *);
24093032Simpextern	int		 _nsyylex(void);
241113595Snectarextern	int		 _nsyyparse(void);
24265532Snectarextern	int		 _nsyylineno;
243113595Snectar#ifdef _NSS_DEBUG
244113595Snectarextern	void		 _nsdbtdump(const ns_dbt *);
245113595Snectar#endif
24665532Snectar#endif /* _NS_PRIVATE */
24765532Snectar
24865532Snectar__END_DECLS
24965532Snectar
25065532Snectar#endif /* !_NSSWITCH_H */
251