17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6cb5caa98Sdjl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*2b4a7802SBaban Kenkre  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23cb5caa98Sdjl  * Use is subject to license terms.
24cb5caa98Sdjl  */
25cb5caa98Sdjl /*
267c478bd9Sstevel@tonic-gate  * Common code and structures used by name-service-switch "compat" backends.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _COMPAT_COMMON_H
307c478bd9Sstevel@tonic-gate #define	_COMPAT_COMMON_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <nss_common.h>
337c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate typedef struct compat_backend *compat_backend_ptr_t;
417c478bd9Sstevel@tonic-gate typedef nss_status_t	(*compat_backend_op_t)(compat_backend_ptr_t, void *);
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * ===> Fix da comments (and in files_common.h too...)
457c478bd9Sstevel@tonic-gate  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
467c478bd9Sstevel@tonic-gate  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
477c478bd9Sstevel@tonic-gate  *   other values don't make much sense.  In other words we're abusing
487c478bd9Sstevel@tonic-gate  *   (overloading) the meaning of nss_status_t, but hey...
497c478bd9Sstevel@tonic-gate  * _nss_compat_XY_all() is a wrapper around _nss_files_do_all() that does the
507c478bd9Sstevel@tonic-gate  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
537c478bd9Sstevel@tonic-gate /* ===> ^^ nuke this line */
547c478bd9Sstevel@tonic-gate typedef int		(*compat_XY_check_func)(nss_XbyY_args_t *);
557c478bd9Sstevel@tonic-gate typedef const char 	*(*compat_get_name)(nss_XbyY_args_t *);
567c478bd9Sstevel@tonic-gate typedef int		(*compat_merge_func)(compat_backend_ptr_t,
577c478bd9Sstevel@tonic-gate 					    nss_XbyY_args_t	*,
587c478bd9Sstevel@tonic-gate 					    const char		**fields);
597c478bd9Sstevel@tonic-gate 
60cb5caa98Sdjl typedef struct setofstrings	*strset_t;
61cb5caa98Sdjl 
62cb5caa98Sdjl struct compat_backend {
63cb5caa98Sdjl 	compat_backend_op_t	*ops;
64cb5caa98Sdjl 	int			n_ops;
65cb5caa98Sdjl 	const char		*filename;
66cb5caa98Sdjl 	FILE			*f;
67cb5caa98Sdjl 	int			minbuf;
68cb5caa98Sdjl 	char			*buf;
69cb5caa98Sdjl 	int			linelen;	/* <== Explain use, lifetime */
70cb5caa98Sdjl 
71cb5caa98Sdjl 	nss_db_initf_t		db_initf;
72cb5caa98Sdjl 	nss_db_root_t		*db_rootp;	/* Shared between instances */
73cb5caa98Sdjl 	nss_getent_t		db_context;	/* Per-instance enumeration */
74cb5caa98Sdjl 
75cb5caa98Sdjl 	compat_get_name		getnamef;
76cb5caa98Sdjl 	compat_merge_func	mergef;
77cb5caa98Sdjl 
78cb5caa98Sdjl 	/* We wouldn't need all this hokey state stuff if we */
79cb5caa98Sdjl 	/*   used another thread to implement a coroutine... */
80cb5caa98Sdjl 	enum {
81cb5caa98Sdjl 		GETENT_FILE,
82cb5caa98Sdjl 		GETENT_NETGROUP,
83cb5caa98Sdjl 		GETENT_ATTRDB,
84cb5caa98Sdjl 		GETENT_ALL,
85cb5caa98Sdjl 		GETENT_DONE
86cb5caa98Sdjl 	}			state;
87cb5caa98Sdjl 	strset_t		minuses;
88cb5caa98Sdjl 
89cb5caa98Sdjl 	int			permit_netgroups;
90cb5caa98Sdjl 	const char		*yp_domain;
91cb5caa98Sdjl 	nss_backend_t		*getnetgrent_backend;
92cb5caa98Sdjl 	char			*netgr_buffer;
93cb5caa98Sdjl 	int			return_string_data;
94ad0e80f7Smichen 	int			(*str2ent_save)();
95ad0e80f7Smichen 	int			(*str2ent_alt)();
96ad0e80f7Smichen 	void			*workarea;
97cb5caa98Sdjl };
98cb5caa98Sdjl 
997c478bd9Sstevel@tonic-gate #if defined(__STDC__)
1007c478bd9Sstevel@tonic-gate extern nss_backend_t	*_nss_compat_constr(compat_backend_op_t	*ops,
1017c478bd9Sstevel@tonic-gate 					    int			n_ops,
1027c478bd9Sstevel@tonic-gate 					    const char		*filename,
1037c478bd9Sstevel@tonic-gate 					    int			min_bufsize,
1047c478bd9Sstevel@tonic-gate 					    nss_db_root_t	*rootp,
1057c478bd9Sstevel@tonic-gate 					    nss_db_initf_t	initf,
1067c478bd9Sstevel@tonic-gate 					    int			netgroups,
1077c478bd9Sstevel@tonic-gate 					    compat_get_name	getname_func,
1087c478bd9Sstevel@tonic-gate 					    compat_merge_func	merge_func);
1097c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_destr(compat_backend_ptr_t, void *dummy);
1107c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_setent(compat_backend_ptr_t, void *dummy);
1117c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_endent(compat_backend_ptr_t, void *dummy);
1127c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_getent(compat_backend_ptr_t, void *);
1137c478bd9Sstevel@tonic-gate extern nss_status_t 	_nss_compat_XY_all(compat_backend_ptr_t,
1147c478bd9Sstevel@tonic-gate 					nss_XbyY_args_t	*args,
1157c478bd9Sstevel@tonic-gate 					compat_XY_check_func	check,
1167c478bd9Sstevel@tonic-gate 					nss_dbop_t		op_num);
1177c478bd9Sstevel@tonic-gate extern nss_status_t 	_attrdb_compat_XY_all(compat_backend_ptr_t,
1187c478bd9Sstevel@tonic-gate 					nss_XbyY_args_t	*args,
1197c478bd9Sstevel@tonic-gate 					int netdb,
1207c478bd9Sstevel@tonic-gate 					compat_XY_check_func	check,
1217c478bd9Sstevel@tonic-gate 					nss_dbop_t		op_num);
1227c478bd9Sstevel@tonic-gate #else
1237c478bd9Sstevel@tonic-gate extern nss_backend_t	*_nss_compat_constr();
1247c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_destr();
1257c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_setent();
1267c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_endent();
1277c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_getent();
1287c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_compat_XY_all();
1297c478bd9Sstevel@tonic-gate extern nss_status_t	_attrdb_compat_XY_all();
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
132*2b4a7802SBaban Kenkre /* functions to validate passwd and group ids */
133*2b4a7802SBaban Kenkre extern int validate_passwd_ids(char *line, int *linelenp, int buflen,
134*2b4a7802SBaban Kenkre 	int extra_chars);
135*2b4a7802SBaban Kenkre extern int validate_group_ids(char *line, int *linelenp, int buflen,
136*2b4a7802SBaban Kenkre 	int extra_chars);
137*2b4a7802SBaban Kenkre 
1387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate #endif
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #endif /* _COMPAT_COMMON_H */
143