master
  1/*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
  2
  3/*-
  4 * SPDX-License-Identifier: BSD-2-Clause
  5 *
  6 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
  7 * All rights reserved.
  8 *
  9 * This code is derived from software contributed to The NetBSD Foundation
 10 * by Luke Mewburn.
 11 *
 12 * Redistribution and use in source and binary forms, with or without
 13 * modification, are permitted provided that the following conditions
 14 * are met:
 15 * 1. Redistributions of source code must retain the above copyright
 16 *    notice, this list of conditions and the following disclaimer.
 17 * 2. Redistributions in binary form must reproduce the above copyright
 18 *    notice, this list of conditions and the following disclaimer in the
 19 *    documentation and/or other materials provided with the distribution.
 20 *
 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31 * POSSIBILITY OF SUCH DAMAGE.
 32 */
 33
 34#ifndef _NSSWITCH_H
 35#define _NSSWITCH_H	1
 36
 37#include <sys/types.h>
 38#include <stdarg.h>
 39
 40#define NSS_MODULE_INTERFACE_VERSION 1
 41
 42#ifndef _PATH_NS_CONF
 43#define _PATH_NS_CONF	"/etc/nsswitch.conf"
 44#endif
 45
 46/* NSS source actions */
 47#define	NS_ACTION_CONTINUE	0	/* try the next source */
 48#define	NS_ACTION_RETURN	1	/* look no further */
 49
 50#define	NS_SUCCESS	(1<<0)		/* entry was found */
 51#define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
 52#define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
 53#define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retry */
 54#define NS_RETURN	(1<<4)		/* stop search, e.g. for ERANGE */
 55#define NS_ADDRFAMILY	(1<<5)		/* no addr for fam, getaddrinfo only */
 56#define NS_TERMINATE	(NS_SUCCESS|NS_RETURN) /* flags that end search */
 57#define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
 58
 59/*
 60 * currently implemented sources
 61 */
 62#define NSSRC_FILES	"files"		/* local files */
 63#define	NSSRC_DB	"db"		/* database */
 64#define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
 65#define	NSSRC_NIS	"nis"		/* YP/NIS */
 66#define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
 67#define	NSSRC_CACHE	"cache"		/* nscd daemon */
 68#define NSSRC_FALLBACK	"__fallback"	/* internal fallback source */
 69
 70/*
 71 * currently implemented databases
 72 */
 73#define NSDB_HOSTS		"hosts"
 74#define NSDB_GROUP		"group"
 75#define NSDB_GROUP_COMPAT	"group_compat"
 76#define NSDB_NETGROUP		"netgroup"
 77#define NSDB_NETWORKS		"networks"
 78#define NSDB_PASSWD		"passwd"
 79#define NSDB_PASSWD_COMPAT	"passwd_compat"
 80#define NSDB_SHELLS		"shells"
 81#define NSDB_SERVICES		"services"
 82#define NSDB_SERVICES_COMPAT	"services_compat"
 83#define NSDB_SSH_HOSTKEYS	"ssh_hostkeys"
 84#define NSDB_PROTOCOLS		"protocols"
 85#define NSDB_RPC		"rpc"
 86
 87/*
 88 * suggested databases to implement
 89 */
 90#define NSDB_ALIASES		"aliases"
 91#define NSDB_AUTH		"auth"
 92#define NSDB_AUTOMOUNT		"automount"
 93#define NSDB_BOOTPARAMS		"bootparams"
 94#define NSDB_ETHERS		"ethers"
 95#define NSDB_EXPORTS		"exports"
 96#define NSDB_NETMASKS		"netmasks"
 97#define NSDB_PHONES		"phones"
 98#define NSDB_PRINTCAP		"printcap"
 99#define NSDB_REMOTE		"remote"
100#define NSDB_SENDMAILVARS	"sendmailvars"
101#define NSDB_TERMCAP		"termcap"
102#define NSDB_TTYS		"ttys"
103
104/*
105 * ns_dtab `method' function signature.
106 */ 
107typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
108
109/*
110 * Macro for generating method prototypes.
111 */
112#define NSS_METHOD_PROTOTYPE(method) \
113	int method(void *, void *, va_list)
114
115/*
116 * ns_dtab - `nsswitch dispatch table'
117 * Contains an entry for each source and the appropriate function to
118 * call.  ns_dtabs are used in the nsdispatch() API in order to allow
119 * the application to override built-in actions.
120 */
121typedef struct _ns_dtab {
122	const char	 *src;		/* Source this entry implements */
123	nss_method	  method;	/* Method to be called */
124	void		 *mdata;	/* Data passed to method */
125} ns_dtab;
126
127/*
128 * macros to help build an ns_dtab[]
129 */
130#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
131#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
132#define NS_FALLBACK_CB(F)	{ NSSRC_FALLBACK, F,	NULL },
133 
134#ifdef HESIOD
135#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
136#else
137#   define NS_DNS_CB(F,C)
138#endif
139
140#ifdef YP
141#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
142#else
143#   define NS_NIS_CB(F,C)
144#endif
145
146/*
147 * ns_src - `nsswitch source'
148 * used by the nsparser routines to store a mapping between a source
149 * and its dispatch control flags for a given database.
150 */
151typedef struct _ns_src {
152	const char	*name;
153	u_int32_t	 flags;
154} ns_src;
155
156
157/*
158 * default sourcelist (if nsswitch.conf is missing, corrupt,
159 * or the requested database doesn't have an entry.
160 */
161extern const ns_src __nsdefaultsrc[];
162
163/*
164 * ns_mtab - NSS method table
165 * An NSS module provides a mapping from (database name, method name)
166 * tuples to the nss_method and associated data.
167 */
168typedef struct _ns_mtab {
169	const char	*database;
170	const char	*name;
171	nss_method	 method;
172	void		*mdata;
173} ns_mtab;
174
175/*
176 * NSS module de-registration, called at module unload.
177 */
178typedef void	 (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
179
180/*
181 * NSS module registration, called at module load.
182 */
183typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *,
184		       nss_module_unregister_fn *);
185
186/* 
187 * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern.
188 * Developers are encouraged to use nss_lookup_type where appropriate.
189 */
190enum nss_lookup_type {
191	nss_lt_name = 1,
192	nss_lt_id   = 2,
193	nss_lt_all  = 3
194};
195
196#ifdef _NS_PRIVATE
197/*
198 * private data structures for back-end nsswitch implementation
199 */
200
201/*
202 * ns_dbt - `nsswitch database thang'
203 * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
204 * name and a list of ns_src's containing the source information.
205 */
206typedef struct _ns_dbt {
207	const char	*name;		/* name of database */
208	ns_src		*srclist;	/* list of sources */
209	int		 srclistsize;	/* size of srclist */
210} ns_dbt;
211
212/*
213 * ns_mod - NSS module
214 */
215typedef struct _ns_mod {
216	char		*name;		/* module name */
217	void		*handle;	/* handle from dlopen */
218	ns_mtab		*mtab;		/* method table */
219	unsigned int	 mtabsize;	/* count of entries in method table */
220	nss_module_unregister_fn unregister; /* called to unload module */
221} ns_mod;
222
223#endif /* _NS_PRIVATE */
224
225
226#include <sys/cdefs.h>
227
228__BEGIN_DECLS
229extern	int	nsdispatch(void *, const ns_dtab [], const char *,
230			   const char *, const ns_src [], ...);
231
232#ifdef _NS_PRIVATE
233extern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
234extern	void		 _nsdbtput(const ns_dbt *);
235extern	void		 _nsyyerror(const char *);
236extern	int		 _nsyylex(void);
237extern	int		 _nsyyparse(void);
238extern	int		 _nsyylineno;
239#ifdef _NSS_DEBUG
240extern	void		 _nsdbtdump(const ns_dbt *);
241#endif
242#endif /* _NS_PRIVATE */
243
244__END_DECLS
245
246#endif /* !_NSSWITCH_H */