xref: /onnv-gate/usr/src/lib/nsswitch/compat/common/compat_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.
24*2830Sdjl  */
25*2830Sdjl /*
260Sstevel@tonic-gate  * Common code and structures used by name-service-switch "compat" backends.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _COMPAT_COMMON_H
300Sstevel@tonic-gate #define	_COMPAT_COMMON_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <nss_common.h>
350Sstevel@tonic-gate #include <nss_dbdefs.h>
360Sstevel@tonic-gate #include <stdio.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate typedef struct compat_backend *compat_backend_ptr_t;
430Sstevel@tonic-gate typedef nss_status_t	(*compat_backend_op_t)(compat_backend_ptr_t, void *);
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * ===> Fix da comments (and in files_common.h too...)
470Sstevel@tonic-gate  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
480Sstevel@tonic-gate  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
490Sstevel@tonic-gate  *   other values don't make much sense.  In other words we're abusing
500Sstevel@tonic-gate  *   (overloading) the meaning of nss_status_t, but hey...
510Sstevel@tonic-gate  * _nss_compat_XY_all() is a wrapper around _nss_files_do_all() that does the
520Sstevel@tonic-gate  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
550Sstevel@tonic-gate /* ===> ^^ nuke this line */
560Sstevel@tonic-gate typedef int		(*compat_XY_check_func)(nss_XbyY_args_t *);
570Sstevel@tonic-gate typedef const char 	*(*compat_get_name)(nss_XbyY_args_t *);
580Sstevel@tonic-gate typedef int		(*compat_merge_func)(compat_backend_ptr_t,
590Sstevel@tonic-gate 					    nss_XbyY_args_t	*,
600Sstevel@tonic-gate 					    const char		**fields);
610Sstevel@tonic-gate 
62*2830Sdjl typedef struct setofstrings	*strset_t;
63*2830Sdjl 
64*2830Sdjl struct compat_backend {
65*2830Sdjl 	compat_backend_op_t	*ops;
66*2830Sdjl 	int			n_ops;
67*2830Sdjl 	const char		*filename;
68*2830Sdjl 	FILE			*f;
69*2830Sdjl 	int			minbuf;
70*2830Sdjl 	char			*buf;
71*2830Sdjl 	int			linelen;	/* <== Explain use, lifetime */
72*2830Sdjl 
73*2830Sdjl 	nss_db_initf_t		db_initf;
74*2830Sdjl 	nss_db_root_t		*db_rootp;	/* Shared between instances */
75*2830Sdjl 	nss_getent_t		db_context;	/* Per-instance enumeration */
76*2830Sdjl 
77*2830Sdjl 	compat_get_name		getnamef;
78*2830Sdjl 	compat_merge_func	mergef;
79*2830Sdjl 
80*2830Sdjl 	/* We wouldn't need all this hokey state stuff if we */
81*2830Sdjl 	/*   used another thread to implement a coroutine... */
82*2830Sdjl 	enum {
83*2830Sdjl 		GETENT_FILE,
84*2830Sdjl 		GETENT_NETGROUP,
85*2830Sdjl 		GETENT_ATTRDB,
86*2830Sdjl 		GETENT_ALL,
87*2830Sdjl 		GETENT_DONE
88*2830Sdjl 	}			state;
89*2830Sdjl 	strset_t		minuses;
90*2830Sdjl 
91*2830Sdjl 	int			permit_netgroups;
92*2830Sdjl 	const char		*yp_domain;
93*2830Sdjl 	nss_backend_t		*getnetgrent_backend;
94*2830Sdjl 	char			*netgr_buffer;
95*2830Sdjl 	int			return_string_data;
96*2830Sdjl };
97*2830Sdjl 
980Sstevel@tonic-gate #if defined(__STDC__)
990Sstevel@tonic-gate extern nss_backend_t	*_nss_compat_constr(compat_backend_op_t	*ops,
1000Sstevel@tonic-gate 					    int			n_ops,
1010Sstevel@tonic-gate 					    const char		*filename,
1020Sstevel@tonic-gate 					    int			min_bufsize,
1030Sstevel@tonic-gate 					    nss_db_root_t	*rootp,
1040Sstevel@tonic-gate 					    nss_db_initf_t	initf,
1050Sstevel@tonic-gate 					    int			netgroups,
1060Sstevel@tonic-gate 					    compat_get_name	getname_func,
1070Sstevel@tonic-gate 					    compat_merge_func	merge_func);
1080Sstevel@tonic-gate extern nss_status_t	_nss_compat_destr(compat_backend_ptr_t, void *dummy);
1090Sstevel@tonic-gate extern nss_status_t	_nss_compat_setent(compat_backend_ptr_t, void *dummy);
1100Sstevel@tonic-gate extern nss_status_t	_nss_compat_endent(compat_backend_ptr_t, void *dummy);
1110Sstevel@tonic-gate extern nss_status_t	_nss_compat_getent(compat_backend_ptr_t, void *);
1120Sstevel@tonic-gate extern nss_status_t 	_nss_compat_XY_all(compat_backend_ptr_t,
1130Sstevel@tonic-gate 					nss_XbyY_args_t	*args,
1140Sstevel@tonic-gate 					compat_XY_check_func	check,
1150Sstevel@tonic-gate 					nss_dbop_t		op_num);
1160Sstevel@tonic-gate extern nss_status_t 	_attrdb_compat_XY_all(compat_backend_ptr_t,
1170Sstevel@tonic-gate 					nss_XbyY_args_t	*args,
1180Sstevel@tonic-gate 					int netdb,
1190Sstevel@tonic-gate 					compat_XY_check_func	check,
1200Sstevel@tonic-gate 					nss_dbop_t		op_num);
1210Sstevel@tonic-gate #else
1220Sstevel@tonic-gate extern nss_backend_t	*_nss_compat_constr();
1230Sstevel@tonic-gate extern nss_status_t	_nss_compat_destr();
1240Sstevel@tonic-gate extern nss_status_t	_nss_compat_setent();
1250Sstevel@tonic-gate extern nss_status_t	_nss_compat_endent();
1260Sstevel@tonic-gate extern nss_status_t	_nss_compat_getent();
1270Sstevel@tonic-gate extern nss_status_t	_nss_compat_XY_all();
1280Sstevel@tonic-gate extern nss_status_t	_attrdb_compat_XY_all();
1290Sstevel@tonic-gate #endif
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #ifdef	__cplusplus
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate #endif
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #endif /* _COMPAT_COMMON_H */
136