1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Common code and structures used by name-service-switch "compat" backends.
27  */
28 
29 #ifndef _COMPAT_COMMON_H
30 #define	_COMPAT_COMMON_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <nss_common.h>
35 #include <nss_dbdefs.h>
36 #include <stdio.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct compat_backend *compat_backend_ptr_t;
43 typedef nss_status_t	(*compat_backend_op_t)(compat_backend_ptr_t, void *);
44 
45 /*
46  * ===> Fix da comments (and in files_common.h too...)
47  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
48  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
49  *   other values don't make much sense.  In other words we're abusing
50  *   (overloading) the meaning of nss_status_t, but hey...
51  * _nss_compat_XY_all() is a wrapper around _nss_files_do_all() that does the
52  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
53  */
54 typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
55 /* ===> ^^ nuke this line */
56 typedef int		(*compat_XY_check_func)(nss_XbyY_args_t *);
57 typedef const char 	*(*compat_get_name)(nss_XbyY_args_t *);
58 typedef int		(*compat_merge_func)(compat_backend_ptr_t,
59 					    nss_XbyY_args_t	*,
60 					    const char		**fields);
61 
62 typedef struct setofstrings	*strset_t;
63 
64 struct compat_backend {
65 	compat_backend_op_t	*ops;
66 	int			n_ops;
67 	const char		*filename;
68 	FILE			*f;
69 	int			minbuf;
70 	char			*buf;
71 	int			linelen;	/* <== Explain use, lifetime */
72 
73 	nss_db_initf_t		db_initf;
74 	nss_db_root_t		*db_rootp;	/* Shared between instances */
75 	nss_getent_t		db_context;	/* Per-instance enumeration */
76 
77 	compat_get_name		getnamef;
78 	compat_merge_func	mergef;
79 
80 	/* We wouldn't need all this hokey state stuff if we */
81 	/*   used another thread to implement a coroutine... */
82 	enum {
83 		GETENT_FILE,
84 		GETENT_NETGROUP,
85 		GETENT_ATTRDB,
86 		GETENT_ALL,
87 		GETENT_DONE
88 	}			state;
89 	strset_t		minuses;
90 
91 	int			permit_netgroups;
92 	const char		*yp_domain;
93 	nss_backend_t		*getnetgrent_backend;
94 	char			*netgr_buffer;
95 	int			return_string_data;
96 	int			(*str2ent_save)();
97 	int			(*str2ent_alt)();
98 	void			*workarea;
99 };
100 
101 #if defined(__STDC__)
102 extern nss_backend_t	*_nss_compat_constr(compat_backend_op_t	*ops,
103 					    int			n_ops,
104 					    const char		*filename,
105 					    int			min_bufsize,
106 					    nss_db_root_t	*rootp,
107 					    nss_db_initf_t	initf,
108 					    int			netgroups,
109 					    compat_get_name	getname_func,
110 					    compat_merge_func	merge_func);
111 extern nss_status_t	_nss_compat_destr(compat_backend_ptr_t, void *dummy);
112 extern nss_status_t	_nss_compat_setent(compat_backend_ptr_t, void *dummy);
113 extern nss_status_t	_nss_compat_endent(compat_backend_ptr_t, void *dummy);
114 extern nss_status_t	_nss_compat_getent(compat_backend_ptr_t, void *);
115 extern nss_status_t 	_nss_compat_XY_all(compat_backend_ptr_t,
116 					nss_XbyY_args_t	*args,
117 					compat_XY_check_func	check,
118 					nss_dbop_t		op_num);
119 extern nss_status_t 	_attrdb_compat_XY_all(compat_backend_ptr_t,
120 					nss_XbyY_args_t	*args,
121 					int netdb,
122 					compat_XY_check_func	check,
123 					nss_dbop_t		op_num);
124 #else
125 extern nss_backend_t	*_nss_compat_constr();
126 extern nss_status_t	_nss_compat_destr();
127 extern nss_status_t	_nss_compat_setent();
128 extern nss_status_t	_nss_compat_endent();
129 extern nss_status_t	_nss_compat_getent();
130 extern nss_status_t	_nss_compat_XY_all();
131 extern nss_status_t	_attrdb_compat_XY_all();
132 #endif
133 
134 #ifdef	__cplusplus
135 }
136 #endif
137 
138 #endif /* _COMPAT_COMMON_H */
139