xref: /onnv-gate/usr/src/head/nss_common.h (revision 2830:5228d1267a01)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2830Sdjl  * Common Development and Distribution License (the "License").
6*2830Sdjl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2830Sdjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2830Sdjl  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  * NOTE:  The interfaces documented in this file may change in a minor
290Sstevel@tonic-gate  *	  release.  It is intended that in the future a stronger committment
300Sstevel@tonic-gate  *	  will be made to these interface definitions which will guarantee
310Sstevel@tonic-gate  *	  them across minor releases.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifndef _NSS_COMMON_H
350Sstevel@tonic-gate #define	_NSS_COMMON_H
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <synch.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #ifdef	__cplusplus
420Sstevel@tonic-gate extern "C" {
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * The name-service switch
470Sstevel@tonic-gate  * -----------------------
480Sstevel@tonic-gate  *
490Sstevel@tonic-gate  * From nsswitch.conf(4):
500Sstevel@tonic-gate  *
51*2830Sdjl  *	    The operating system uses a number of "databases" of information
520Sstevel@tonic-gate  *	    about hosts, users (passwd/shadow), groups and so forth.  Data for
53*2830Sdjl  *	    these can come from a variety of "sources":  host-names and
540Sstevel@tonic-gate  *	    -addresses, for example, may be found in /etc/hosts, NIS, NIS+ or
550Sstevel@tonic-gate  *	    DNS.  One or more sources may be used for each database;  the
560Sstevel@tonic-gate  *	    sources and their lookup order are specified in the
570Sstevel@tonic-gate  *	    /etc/nsswitch.conf file.
580Sstevel@tonic-gate  *
590Sstevel@tonic-gate  * The implementation of this consists of:
600Sstevel@tonic-gate  *
61*2830Sdjl  *    -	a "frontend" for each database, which provides a programming
620Sstevel@tonic-gate  *	interface for that database [for example, the "passwd" frontend
630Sstevel@tonic-gate  *	consists of getpwnam_r(), getpwuid_r(), getpwent_r(), setpwent(),
640Sstevel@tonic-gate  *	endpwent(), and the old MT-unsafe routines getpwnam() and getpwuid()]
650Sstevel@tonic-gate  *	and is implemented by calls to...
660Sstevel@tonic-gate  *
67*2830Sdjl  *    -	the common core of the switch (called the "switch" or "policy" engine);
68*2830Sdjl  *	that determines what sources to use and when to invoke them.  This
69*2830Sdjl  *	component works in conjunction with the name service switch (nscd).
70*2830Sdjl  *	Usually nscd is the policy engine for an application lookup.
710Sstevel@tonic-gate  *
72*2830Sdjl  *    - Old style backend interfaces follow this pointer to function interface:
73*2830Sdjl  *
74*2830Sdjl  *     	A "backend" exists for useful <database, source> pairs.  Each backend
750Sstevel@tonic-gate  *	consists of whatever private data it needs and a set of functions
760Sstevel@tonic-gate  *	that the switch engine may invoke on behalf of the frontend
770Sstevel@tonic-gate  *	[e.g. the "nis" backend for "passwd" provides routines to lookup
780Sstevel@tonic-gate  *	by name and by uid, as well as set/get/end iterator routines].
790Sstevel@tonic-gate  *	The set of functions, and their expected arguments and results,
800Sstevel@tonic-gate  *	constitutes a (database-specific) interface between a frontend and
810Sstevel@tonic-gate  *	all its backends.  The switch engine knows as little as possible
820Sstevel@tonic-gate  *	about these interfaces.
830Sstevel@tonic-gate  *
84*2830Sdjl  *	(The term "backend" is used ambiguously;  it may also refer to a
850Sstevel@tonic-gate  *	particular instantiation of a backend, or to the set of all backends
860Sstevel@tonic-gate  *	for a particular source, e.g. "the nis backend").
870Sstevel@tonic-gate  *
880Sstevel@tonic-gate  * This header file defines the interface between the switch engine and the
890Sstevel@tonic-gate  * frontends and backends.  Interfaces between specific frontends and
900Sstevel@tonic-gate  * backends are defined elsewhere;  many are in <nss_dbdefs.h>.
91*2830Sdjl  * Most of these definitions are in the form of pointer to function
92*2830Sdjl  * indicies used to call specific backend APIs.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  *
950Sstevel@tonic-gate  * Switch-engine outline
960Sstevel@tonic-gate  * ---------------------
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * Frontends may call the following routines in the switch engine:
990Sstevel@tonic-gate  *
1000Sstevel@tonic-gate  *	nss_search() does getXXXbyYYY,	e.g. getpwnam_r(), getpwuid_r()
1010Sstevel@tonic-gate  *	nss_getent() does getXXXent,	e.g. getpwent_r()
1020Sstevel@tonic-gate  *	nss_setent() does setXXXent,	e.g. setpwent()
1030Sstevel@tonic-gate  *	nss_endent() does endXXXent,	e.g. endpwent()
1040Sstevel@tonic-gate  *	nss_delete() releases resources, in the style of endpwent().
1050Sstevel@tonic-gate  *
1060Sstevel@tonic-gate  * A getpwnam_r() call might proceed thus (with many details omitted):
1070Sstevel@tonic-gate  *
1080Sstevel@tonic-gate  *	(1)  getpwnam_r	fills in (getpwnam-specific) argument/result struct,
1090Sstevel@tonic-gate  *			calls nss_search(),
110*2830Sdjl  *	(2)  nss_search queries the name service cache for an existing
111*2830Sdjl  *			result via a call to _nsc_search().  if the cache
112*2830Sdjl  *			(nscd) has a definitive answer skip to step 7
113*2830Sdjl  *	(3)  nss_search	looks up configuration info, gets "passwd: files nis",
114*2830Sdjl  *	(4)  nss_search	decides to try first source ("files"),
1150Sstevel@tonic-gate  *	 (a) nss_search	locates code for <"passwd", "files"> backend,
1160Sstevel@tonic-gate  *	 (b) nss_search	creates instance of backend,
1170Sstevel@tonic-gate  *	 (c) nss_search	calls get-by-name routine in backend,
118*2830Sdjl  *			through a function pointer interface,
1190Sstevel@tonic-gate  *	 (d) backend	searches /etc/passwd, doesn't find the name,
1200Sstevel@tonic-gate  *			returns "not found" status to nss_search,
121*2830Sdjl  *	(5)  nss_search	examines status and config info, decides to try
1220Sstevel@tonic-gate  *			next source ("nis"),
1230Sstevel@tonic-gate  *	 (a) nss_search	locates code for <"passwd", "nis"> backend,
1240Sstevel@tonic-gate  *	 (b) nss_search	creates instance of backend,
1250Sstevel@tonic-gate  *	 (c) nss_search	calls get-by-name routine in backend,
126*2830Sdjl  *			through a function pointer interface,
1270Sstevel@tonic-gate  *	 (d) backend	searches passwd.byname, finds the desired entry,
1280Sstevel@tonic-gate  *			fills in the result part of the getpwnam-specific
1290Sstevel@tonic-gate  *			struct, returns "success" status to nss_search,
130*2830Sdjl  *	(6)  nss_search	examines status and config info, decides to return
1310Sstevel@tonic-gate  *			to caller,
132*2830Sdjl  *	(7)  getpwnam_r	extracts result from getpwnam-specific struct,
1330Sstevel@tonic-gate  *			returns to caller.
1340Sstevel@tonic-gate  *
1350Sstevel@tonic-gate  *
1360Sstevel@tonic-gate  * Data structures
1370Sstevel@tonic-gate  * ---------------
1380Sstevel@tonic-gate  *
1390Sstevel@tonic-gate  * Both databases and sources are represented by case-sensitive strings
1400Sstevel@tonic-gate  * (the same strings that appear in the configuration file).
1410Sstevel@tonic-gate  *
1420Sstevel@tonic-gate  * The switch engine maintains a per-frontend data structure so that the
1430Sstevel@tonic-gate  * results of steps (2), (a) and (b) can be cached.  The frontend holds a
1440Sstevel@tonic-gate  * handle (nss_db_root_t) to this structure and passes it in to the
1450Sstevel@tonic-gate  * nss_*() routines.
1460Sstevel@tonic-gate  *
1470Sstevel@tonic-gate  * The nss_setent(), nss_getent() and nss_endent() routines introduce another
1480Sstevel@tonic-gate  * variety of state (the current position in the enumeration process).
1490Sstevel@tonic-gate  * Within a single source, this information is maintained by private data
1500Sstevel@tonic-gate  * in the backend instance -- but, in the presence of multiple sources, the
1510Sstevel@tonic-gate  * switch engine must keep track of the current backend instance [e.g either
1520Sstevel@tonic-gate  * <"passwd", "files"> or <"passwd", "nis"> instances].  The switch engine
1530Sstevel@tonic-gate  * has a separate per-enumeration data structure for this;  again, the
1540Sstevel@tonic-gate  * frontend holds a handle (nss_getent_t) and passes it in, along with the
1550Sstevel@tonic-gate  * nss_db_root_t handle, to nss_setent(), nss_getent() and nss_endent().
1560Sstevel@tonic-gate  *
1570Sstevel@tonic-gate  *
1580Sstevel@tonic-gate  * Multithreading
1590Sstevel@tonic-gate  * --------------
1600Sstevel@tonic-gate  *
1610Sstevel@tonic-gate  * The switch engine takes care of locking;  frontends should be written to
1620Sstevel@tonic-gate  * be reentrant, and a backend instance may assume that all calls to it are
1630Sstevel@tonic-gate  * serialized.
1640Sstevel@tonic-gate  *
1650Sstevel@tonic-gate  * If multiple threads simultaneously want to use a particular backend, the
1660Sstevel@tonic-gate  * switch engine creates multiple backend instances (up to some limit
1670Sstevel@tonic-gate  * specified by the frontend).  Backends must of course lock any state that
1680Sstevel@tonic-gate  * is shared between instances, and must serialize calls to any MT-unsafe
1690Sstevel@tonic-gate  * code.
1700Sstevel@tonic-gate  *
1710Sstevel@tonic-gate  * The switch engine has no notion of per-thread state.
1720Sstevel@tonic-gate  *
1730Sstevel@tonic-gate  * Frontends can use the nss_getent_t handle to define the scope of the
1740Sstevel@tonic-gate  * enumeration (set/get/endXXXent) state:  a static handle gives global state
1750Sstevel@tonic-gate  * (which is what Posix has specified for the getXXXent_r routines), handles
1760Sstevel@tonic-gate  * in Thread-Specific Data give per-thread state, and handles on the stack
1770Sstevel@tonic-gate  * give per-invocation state.
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate /*
1810Sstevel@tonic-gate  * Backend instances
1820Sstevel@tonic-gate  * -----------------
1830Sstevel@tonic-gate  *
1840Sstevel@tonic-gate  * As far as the switch engine is concerned, an instance of a backend is a
1850Sstevel@tonic-gate  * struct whose first two members are:
1860Sstevel@tonic-gate  *    -	A pointer to a vector of function pointers, one for each
1870Sstevel@tonic-gate  *	database-specific function,
1880Sstevel@tonic-gate  *    -	The length of the vector (an int), used for bounds-checking.
1890Sstevel@tonic-gate  * There are four well-known function slots in the vector:
1900Sstevel@tonic-gate  *	[0] is a destructor for the backend instance,
1910Sstevel@tonic-gate  *	[1] is the endXXXent routine,
1920Sstevel@tonic-gate  *	[2] is the setXXXent routine,
1930Sstevel@tonic-gate  *	[3] is the getXXXent routine.
1940Sstevel@tonic-gate  * Any other slots are database-specific getXXXbyYYY routines;  the frontend
1950Sstevel@tonic-gate  * specifies a slot-number to nss_search().
1960Sstevel@tonic-gate  *
1970Sstevel@tonic-gate  * The functions take two arguments:
1980Sstevel@tonic-gate  *    -	a pointer to the backend instance (like a C++ "this" pointer)
1990Sstevel@tonic-gate  *    -	a single (void *) pointer to the database-specific argument/result
2000Sstevel@tonic-gate  *	structure (the contents are opaque to the switch engine).
2010Sstevel@tonic-gate  * The four well-known functions ignore the (void *) pointer.
2020Sstevel@tonic-gate  *
203*2830Sdjl  * Backend routines return the following status codes to the switch engine:
204*2830Sdjl  *
2050Sstevel@tonic-gate  * SUCCESS, UNAVAIL, NOTFOUND, TRYAGAIN (these are the same codes that may
206*2830Sdjl  * be specified in the config information;  see nsswitch.conf(4))
207*2830Sdjl  *
208*2830Sdjl  * The remaining conditions/errors are internally generated and if
209*2830Sdjl  * necessary are translated, as to one of the above external errors,
210*2830Sdjl  * usually NOTFOUND or UNAVAIL.
211*2830Sdjl  *
2120Sstevel@tonic-gate  * NSS_NISSERVDNS_TRYAGAIN (should only be used by the NIS backend for
2130Sstevel@tonic-gate  * NIS server in DNS forwarding mode to indicate DNS server non-response).
214*2830Sdjl  *
215*2830Sdjl  * The policy component may return NSS_TRYLOCAL which signifies that nscd
216*2830Sdjl  * is not going to process the request, and it should be performed locally.
217*2830Sdjl  *
218*2830Sdjl  * NSS_ERROR is a catchall for internal error conditions, errno will be set
219*2830Sdjl  * to a system <errno.h> error that can help track down the problem if
220*2830Sdjl  * it is persistent.  This error is the result of some internal error
221*2830Sdjl  * condition and should not be seen during or exposed to aan application.
222*2830Sdjl  * The error may be from the application side switch component or from the
223*2830Sdjl  * nscd side switch component.
224*2830Sdjl  *
225*2830Sdjl  * NSS_ALTRETRY and NSS_ALTRESET are internal codes used by the application
226*2830Sdjl  * side policy component and nscd to direct the policy component to
227*2830Sdjl  * communicate to a per-user nscd if/when per-user authentication is enabled.
228*2830Sdjl  *
229*2830Sdjl  * NSS_NSCD_PRIV is a catchall for internal nscd errors or status
230*2830Sdjl  * conditions.  This return code is not visible to applications.  nscd
231*2830Sdjl  * may use this as a status flag and maintain additional error or status
232*2830Sdjl  * information elsewhere in other private nscd data.  This status value
233*2830Sdjl  * is for nscd private/internal use only.
2340Sstevel@tonic-gate  */
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate typedef enum {
237*2830Sdjl 	NSS_SUCCESS = 0,
238*2830Sdjl 	NSS_NOTFOUND = 1,
239*2830Sdjl 	NSS_UNAVAIL = 2,
240*2830Sdjl 	NSS_TRYAGAIN = 3,
241*2830Sdjl 	NSS_NISSERVDNS_TRYAGAIN = 4,
242*2830Sdjl 	NSS_TRYLOCAL = 5,
243*2830Sdjl 	NSS_ERROR = 6,
244*2830Sdjl 	NSS_ALTRETRY = 7,
245*2830Sdjl 	NSS_ALTRESET = 8,
246*2830Sdjl 	NSS_NSCD_PRIV = 9
2470Sstevel@tonic-gate } nss_status_t;
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate struct nss_backend;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate #if defined(__STDC__)
2520Sstevel@tonic-gate typedef nss_status_t (*nss_backend_op_t)(struct nss_backend *, void *args);
2530Sstevel@tonic-gate #else
2540Sstevel@tonic-gate typedef nss_status_t (*nss_backend_op_t)();
2550Sstevel@tonic-gate #endif
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate struct nss_backend {
2580Sstevel@tonic-gate 	nss_backend_op_t	*ops;
2590Sstevel@tonic-gate 	int			n_ops;
2600Sstevel@tonic-gate };
2610Sstevel@tonic-gate typedef struct nss_backend	nss_backend_t;
2620Sstevel@tonic-gate typedef int			nss_dbop_t;
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate #define	NSS_DBOP_DESTRUCTOR	0
2650Sstevel@tonic-gate #define	NSS_DBOP_ENDENT		1
2660Sstevel@tonic-gate #define	NSS_DBOP_SETENT		2
2670Sstevel@tonic-gate #define	NSS_DBOP_GETENT		3
2680Sstevel@tonic-gate #define	NSS_DBOP_next_iter	(NSS_DBOP_GETENT + 1)
2690Sstevel@tonic-gate #define	NSS_DBOP_next_noiter	(NSS_DBOP_DESTRUCTOR + 1)
2700Sstevel@tonic-gate #define	NSS_DBOP_next_ipv6_iter	(NSS_DBOP_GETENT + 3)
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate #define	NSS_LOOKUP_DBOP(instp, n)					    \
2730Sstevel@tonic-gate 		(((n) >= 0 && (n) < (instp)->n_ops) ? (instp)->ops[n] : 0)
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate #define	NSS_INVOKE_DBOP(instp, n, argp)					    (\
2760Sstevel@tonic-gate 		((n) >= 0 && (n) < (instp)->n_ops && (instp)->ops[n] != 0) \
2770Sstevel@tonic-gate 		? (*(instp)->ops[n])(instp, argp)			    \
2780Sstevel@tonic-gate 		: NSS_UNAVAIL)
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate  * Locating and instantiating backends
2820Sstevel@tonic-gate  * -----------------------------------
2830Sstevel@tonic-gate  *
2840Sstevel@tonic-gate  * To perform step (a), the switch consults a list of backend-finder routines,
2850Sstevel@tonic-gate  * passing a <database, source> pair.
2860Sstevel@tonic-gate  *
2870Sstevel@tonic-gate  * There is a standard backend-finder;  frontends may augment or replace this
2880Sstevel@tonic-gate  * in order to, say, indicate that some backends are "compiled in" with the
2890Sstevel@tonic-gate  * frontend.
2900Sstevel@tonic-gate  *
2910Sstevel@tonic-gate  * Backend-finders return a pointer to a constructor function for the backend.
2920Sstevel@tonic-gate  * (or NULL if they can't find the backend).  The switch engine caches these
2930Sstevel@tonic-gate  * function pointers;  when it needs to perform step (b), it calls the
2940Sstevel@tonic-gate  * constructor function, which returns a pointer to a new instance of the
2950Sstevel@tonic-gate  * backend, properly initialized (or returns NULL).
2960Sstevel@tonic-gate  */
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate #if defined(__STDC__)
299*2830Sdjl typedef	nss_backend_t		*(*nss_backend_constr_t)(const char *db_name,
3000Sstevel@tonic-gate 							const char *src_name,
3010Sstevel@tonic-gate /* Hook for (unimplemented) args in nsswitch.conf */	const char *cfg_args);
3020Sstevel@tonic-gate #else
303*2830Sdjl typedef	nss_backend_t 		*(*nss_backend_constr_t)();
3040Sstevel@tonic-gate #endif
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate struct nss_backend_finder {
3070Sstevel@tonic-gate #if defined(__STDC__)
3080Sstevel@tonic-gate 	nss_backend_constr_t	(*lookup)
3090Sstevel@tonic-gate 		(void *lkp_priv, const char *, const char *, void **del_privp);
3100Sstevel@tonic-gate 	void			(*delete)
3110Sstevel@tonic-gate 		(void *del_priv, nss_backend_constr_t);
3120Sstevel@tonic-gate #else
3130Sstevel@tonic-gate 	nss_backend_constr_t	(*lookup)();
3140Sstevel@tonic-gate 	void			(*delete)();
3150Sstevel@tonic-gate #endif
3160Sstevel@tonic-gate 	struct nss_backend_finder *next;
3170Sstevel@tonic-gate 	void			*lookup_priv;
3180Sstevel@tonic-gate };
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate typedef struct nss_backend_finder nss_backend_finder_t;
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate extern nss_backend_finder_t	*nss_default_finders;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate /*
3250Sstevel@tonic-gate  * Frontend parameters
3260Sstevel@tonic-gate  * -------------------
3270Sstevel@tonic-gate  *
3280Sstevel@tonic-gate  * The frontend must tell the switch engine:
3290Sstevel@tonic-gate  *    -	the database name,
3300Sstevel@tonic-gate  *    -	the compiled-in default configuration entry.
3310Sstevel@tonic-gate  * It may also override default values for:
3320Sstevel@tonic-gate  *    -	the database name to use when looking up the configuration
3330Sstevel@tonic-gate  *	information (e.g. "shadow" uses the config entry for "passwd"),
3340Sstevel@tonic-gate  *    -	a limit on the number of instances of each backend that are
3350Sstevel@tonic-gate  *	simultaneously active,
3360Sstevel@tonic-gate  *    - a limit on the number of instances of each backend that are
3370Sstevel@tonic-gate  *	simultaneously dormant (waiting for new requests),
3380Sstevel@tonic-gate  *    -	a flag that tells the switch engine to use the default configuration
3390Sstevel@tonic-gate  *	entry and ignore any other config entry for this database,
3400Sstevel@tonic-gate  *    -	backend-finders (see above)
3410Sstevel@tonic-gate  *    - a cleanup routine that should be called when these parameters are
3420Sstevel@tonic-gate  *	about to be deleted.
3430Sstevel@tonic-gate  *
3440Sstevel@tonic-gate  * In order to do this, the frontend includes a pointer to an initialization
3450Sstevel@tonic-gate  * function (nss_db_initf_t) in every nss_*() call.  When necessary (normally
3460Sstevel@tonic-gate  * just on the first invocation), the switch engine allocates a parameter
3470Sstevel@tonic-gate  * structure (nss_db_params_t), fills in the default values, then calls
3480Sstevel@tonic-gate  * the initialization function, which should update the parameter structure
3490Sstevel@tonic-gate  * as necessary.
3500Sstevel@tonic-gate  *
3510Sstevel@tonic-gate  * (This might look more natural if we put nss_db_initf_t in nss_db_root_t,
3520Sstevel@tonic-gate  * or abolished nss_db_initf_t and put nss_db_params_t in nss_db_root_t.
3530Sstevel@tonic-gate  * It's done the way it is for shared-library efficiency, namely:
3540Sstevel@tonic-gate  *	- keep the unshared data (nss_db_root_t) to a minimum,
3550Sstevel@tonic-gate  *	- keep the symbol lookups and relocations to a minimum.
3560Sstevel@tonic-gate  * In particular this means that non-null pointers, e.g. strings and
3570Sstevel@tonic-gate  * function pointers, in global data are a bad thing).
3580Sstevel@tonic-gate  */
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate enum nss_dbp_flags {
3610Sstevel@tonic-gate 	NSS_USE_DEFAULT_CONFIG	= 0x1
3620Sstevel@tonic-gate };
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate struct nss_db_params {
3650Sstevel@tonic-gate 	const char 		*name;		/* Mandatory: database name */
3660Sstevel@tonic-gate 	const char		*config_name;	/* config-file database name */
3670Sstevel@tonic-gate 	const char		*default_config; /* Mandatory: default config */
3680Sstevel@tonic-gate 	unsigned		max_active_per_src;
3690Sstevel@tonic-gate 	unsigned		max_dormant_per_src;
3700Sstevel@tonic-gate 	enum nss_dbp_flags	flags;
3710Sstevel@tonic-gate 	nss_backend_finder_t	*finders;
3720Sstevel@tonic-gate 	void			*private;	/* Not used by switch */
3730Sstevel@tonic-gate 	void			(*cleanup)(struct nss_db_params *);
3740Sstevel@tonic-gate };
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate typedef struct nss_db_params nss_db_params_t;
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate #if defined(__STDC__)
3790Sstevel@tonic-gate typedef void (*nss_db_initf_t)(nss_db_params_t *);
3800Sstevel@tonic-gate #else
3810Sstevel@tonic-gate typedef void (*nss_db_initf_t)();
3820Sstevel@tonic-gate #endif
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate /*
385*2830Sdjl  * DBD param offsets in NSS2 nscd header.
386*2830Sdjl  * Offsets are relative to beginning of dbd section.
387*2830Sdjl  * 32 bit offsets should be sufficient, forever.
388*2830Sdjl  * 0 offset == NULL
389*2830Sdjl  * flags == nss_dbp_flags
390*2830Sdjl  */
391*2830Sdjl typedef struct nss_dbd {
392*2830Sdjl 	uint32_t	o_name;
393*2830Sdjl 	uint32_t	o_config_name;
394*2830Sdjl 	uint32_t	o_default_config;
395*2830Sdjl 	uint32_t	flags;
396*2830Sdjl } nss_dbd_t;
397*2830Sdjl 
398*2830Sdjl /*
3990Sstevel@tonic-gate  * These structures are defined inside the implementation of the switch
4000Sstevel@tonic-gate  * engine;  the interface just holds pointers to them.
4010Sstevel@tonic-gate  */
4020Sstevel@tonic-gate struct nss_db_state;
4030Sstevel@tonic-gate struct nss_getent_context;
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate /*
4060Sstevel@tonic-gate  * Finally, the two handles that frontends hold:
4070Sstevel@tonic-gate  */
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate struct nss_db_root {
4100Sstevel@tonic-gate 	struct nss_db_state	*s;
4110Sstevel@tonic-gate 	mutex_t			lock;
4120Sstevel@tonic-gate };
4130Sstevel@tonic-gate typedef struct nss_db_root nss_db_root_t;
4140Sstevel@tonic-gate #define	NSS_DB_ROOT_INIT		{ 0, DEFAULTMUTEX }
4150Sstevel@tonic-gate #define	DEFINE_NSS_DB_ROOT(name)	nss_db_root_t name = NSS_DB_ROOT_INIT
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate typedef struct {
4190Sstevel@tonic-gate 	struct nss_getent_context *ctx;
4200Sstevel@tonic-gate 	mutex_t			lock;
4210Sstevel@tonic-gate } nss_getent_t;
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate #define	NSS_GETENT_INIT			{ 0, DEFAULTMUTEX }
4240Sstevel@tonic-gate #define	DEFINE_NSS_GETENT(name)		nss_getent_t name = NSS_GETENT_INIT
4250Sstevel@tonic-gate 
426*2830Sdjl /*
427*2830Sdjl  * Policy Engine Configuration
428*2830Sdjl  * ---------------------------
429*2830Sdjl  *
430*2830Sdjl  * When nscd is running it can reconfigure it's internal policy engine
431*2830Sdjl  * as well as advise an application's front-end and policy engine on how
432*2830Sdjl  * respond optimally to results being returned from nscd.  This is done
433*2830Sdjl  * through the policy engine configuration interface.
434*2830Sdjl  */
435*2830Sdjl 
436*2830Sdjl typedef enum {
437*2830Sdjl 	NSS_CONFIG_GET,
438*2830Sdjl 	NSS_CONFIG_PUT,
439*2830Sdjl 	NSS_CONFIG_ADD,
440*2830Sdjl 	NSS_CONFIG_DELETE,
441*2830Sdjl 	NSS_CONFIG_LIST
442*2830Sdjl } nss_config_op_t;
443*2830Sdjl 
444*2830Sdjl struct nss_config {
445*2830Sdjl 	char		*name;
446*2830Sdjl 	nss_config_op_t	cop;
447*2830Sdjl 	mutex_t		*lock;
448*2830Sdjl 	void		*buffer;
449*2830Sdjl 	size_t		length;
450*2830Sdjl };
451*2830Sdjl typedef struct nss_config nss_config_t;
452*2830Sdjl 
453*2830Sdjl 
4540Sstevel@tonic-gate #if defined(__STDC__)
455*2830Sdjl extern nss_status_t nss_config(nss_config_t **, int);
456*2830Sdjl 
4570Sstevel@tonic-gate extern nss_status_t nss_search(nss_db_root_t *, nss_db_initf_t,
4580Sstevel@tonic-gate 			int search_fnum, void *search_args);
4590Sstevel@tonic-gate extern nss_status_t nss_getent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *,
4600Sstevel@tonic-gate 			void *getent_args);
4610Sstevel@tonic-gate extern void nss_setent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
462*2830Sdjl extern void nss_endent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
463*2830Sdjl extern void nss_delete(nss_db_root_t *);
4640Sstevel@tonic-gate 
465*2830Sdjl extern nss_status_t nss_pack(void *, size_t, nss_db_root_t *,
466*2830Sdjl 			nss_db_initf_t, int, void *);
467*2830Sdjl extern nss_status_t nss_pack_ent(void *, size_t, nss_db_root_t *,
468*2830Sdjl 			nss_db_initf_t, nss_getent_t *);
469*2830Sdjl extern nss_status_t nss_unpack(void *, size_t, nss_db_root_t *,
470*2830Sdjl 			nss_db_initf_t, int, void *);
471*2830Sdjl extern nss_status_t nss_unpack_ent(void *, size_t, nss_db_root_t *,
472*2830Sdjl 			nss_db_initf_t, nss_getent_t *, void *);
473*2830Sdjl 
474*2830Sdjl extern nss_status_t _nsc_search(nss_db_root_t *, nss_db_initf_t,
475*2830Sdjl 			int search_fnum, void *search_args);
476*2830Sdjl extern nss_status_t _nsc_getent_u(nss_db_root_t *, nss_db_initf_t,
477*2830Sdjl 			nss_getent_t *, void *getent_args);
478*2830Sdjl extern nss_status_t _nsc_setent_u(nss_db_root_t *, nss_db_initf_t,
479*2830Sdjl 			nss_getent_t *);
480*2830Sdjl extern nss_status_t _nsc_endent_u(nss_db_root_t *, nss_db_initf_t,
481*2830Sdjl 			nss_getent_t *);
482*2830Sdjl 
4830Sstevel@tonic-gate #else
484*2830Sdjl extern nss_status_t nss_config();
485*2830Sdjl 
4860Sstevel@tonic-gate extern nss_status_t nss_search();
4870Sstevel@tonic-gate extern nss_status_t nss_getent();
4880Sstevel@tonic-gate extern void nss_setent();
4890Sstevel@tonic-gate extern void nss_endent();
4900Sstevel@tonic-gate extern void nss_delete();
491*2830Sdjl 
492*2830Sdjl extern int nss_pack();
493*2830Sdjl extern int nss_pack_ent();
494*2830Sdjl extern int nss_unpack();
495*2830Sdjl extern int nss_unpack_ent();
496*2830Sdjl 
497*2830Sdjl extern nss_status_t _nsc_search();
498*2830Sdjl extern nss_status_t _nsc_getent_u();
499*2830Sdjl extern nss_status_t _nsc_setent_u();
500*2830Sdjl extern nss_status_t _nsc_endent_u();
5010Sstevel@tonic-gate #endif
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate #ifdef	__cplusplus
5040Sstevel@tonic-gate }
5050Sstevel@tonic-gate #endif
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate #endif /* _NSS_COMMON_H */
508