xref: /titanic_52/usr/src/lib/nsswitch/compat/common/compat_common.h (revision d0e72dff6c5b858c797dfc1172d9c3aed2103940)
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 };
97 
98 #if defined(__STDC__)
99 extern nss_backend_t	*_nss_compat_constr(compat_backend_op_t	*ops,
100 					    int			n_ops,
101 					    const char		*filename,
102 					    int			min_bufsize,
103 					    nss_db_root_t	*rootp,
104 					    nss_db_initf_t	initf,
105 					    int			netgroups,
106 					    compat_get_name	getname_func,
107 					    compat_merge_func	merge_func);
108 extern nss_status_t	_nss_compat_destr(compat_backend_ptr_t, void *dummy);
109 extern nss_status_t	_nss_compat_setent(compat_backend_ptr_t, void *dummy);
110 extern nss_status_t	_nss_compat_endent(compat_backend_ptr_t, void *dummy);
111 extern nss_status_t	_nss_compat_getent(compat_backend_ptr_t, void *);
112 extern nss_status_t 	_nss_compat_XY_all(compat_backend_ptr_t,
113 					nss_XbyY_args_t	*args,
114 					compat_XY_check_func	check,
115 					nss_dbop_t		op_num);
116 extern nss_status_t 	_attrdb_compat_XY_all(compat_backend_ptr_t,
117 					nss_XbyY_args_t	*args,
118 					int netdb,
119 					compat_XY_check_func	check,
120 					nss_dbop_t		op_num);
121 #else
122 extern nss_backend_t	*_nss_compat_constr();
123 extern nss_status_t	_nss_compat_destr();
124 extern nss_status_t	_nss_compat_setent();
125 extern nss_status_t	_nss_compat_endent();
126 extern nss_status_t	_nss_compat_getent();
127 extern nss_status_t	_nss_compat_XY_all();
128 extern nss_status_t	_attrdb_compat_XY_all();
129 #endif
130 
131 #ifdef	__cplusplus
132 }
133 #endif
134 
135 #endif /* _COMPAT_COMMON_H */
136