xref: /titanic_44/usr/src/cmd/nscd/nscd_db.h (revision b60f2a0b921611326383e4789e0874e9e8a2e708)
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 #ifndef	_NSCD_DB_H
27 #define	_NSCD_DB_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <nss_dbdefs.h>		/* nssuint_t */
36 #include "nscd_common.h"
37 
38 /* make a pointer 8-byte aligned, or an integer a multiple of 8 */
39 #define	roundup(x)	(((unsigned long)(x)+7) & ~7)
40 
41 /*
42  * type of nscd data
43  */
44 #define	NSCD_DATA_UNKNOWN		0
45 #define	NSCD_DATA_NSW_CONFIG		1
46 #define	NSCD_DATA_NSW_STATE_BASE	2
47 #define	NSCD_DATA_GETENT_CTX_BASE	3
48 #define	NSCD_DATA_BACKEND_INFO		4
49 #define	NSCD_DATA_BACKEND_INFO_DB	5
50 #define	NSCD_DATA_CFG_NSW_DB_INDEX	6
51 #define	NSCD_DATA_CFG_NSW_SRC_INDEX	7
52 #define	NSCD_DATA_CFG_PARAM_INDEX	8
53 #define	NSCD_DATA_CFG_STAT_INDEX	9
54 #define	NSCD_DATA_ADDR			127
55 #define	NSCD_DATA_CTX_ADDR		128
56 
57 /*
58  * database operation options
59  */
60 typedef enum {
61 	NSCD_GET_FIRST_DB_ENTRY		= 1,
62 	NSCD_GET_NEXT_DB_ENTRY		= 2,
63 	NSCD_GET_EXACT_DB_ENTRY		= 3,
64 	NSCD_ADD_DB_ENTRY_FIRST		= 4,
65 	NSCD_ADD_DB_ENTRY_LAST		= 5,
66 	NSCD_ADD_DB_ENTRY_REPLACE	= 6,
67 	NSCD_ADD_DB_ENTRY_IF_NONE	= 7,
68 	NSCD_DEL_FIRST_DB_ENTRY		= 8,
69 	NSCD_DEL_ALL_DB_ENTRY		= 9,
70 	NSCD_DEL_EXACT_DB_ENTRY		= 10
71 } nscd_db_option_t;
72 
73 /*
74  * This structure defines an instance of the
75  * nscd database entry.
76  */
77 typedef struct nscd_db_entry {
78 	int			type;
79 	int			id_num;
80 	int			num_data;
81 	int			num_array;
82 	char			*name;
83 	void			**data_array;
84 } nscd_db_entry_t;
85 
86 /*
87  * sequence number attached to nscd data
88  */
89 typedef	nssuint_t nscd_seq_num_t;
90 typedef nssuint_t nscd_cookie_num_t;
91 
92 /*
93  * The nscd_access_s datatype represents a nscd
94  * access data structure. It is an opaque structure.
95  */
96 struct nscd_access_s;
97 typedef struct nscd_access_s	nscd_access_t;
98 struct nscd_acc_data_s;
99 typedef struct nscd_acc_data_s	nscd_acc_data_t;
100 
101 /*
102  * The nscd_db_t datatype represents a nscd
103  * database. It is also an opaque structure.
104  */
105 struct nscd_db_s;
106 typedef struct nscd_db_s	nscd_db_t;
107 
108 /*
109  * four sizes for a nscd database:
110  * large, medium, small, tiny
111  */
112 #define	NSCD_DB_SIZE_LARGE	1
113 #define	NSCD_DB_SIZE_MEDIUM	2
114 #define	NSCD_DB_SIZE_SMALL	3
115 #define	NSCD_DB_SIZE_TINY	4
116 
117 /*
118  * options for _nscd_alloc()
119  */
120 #define	NSCD_ALLOC_MUTEX	0x0001
121 #define	NSCD_ALLOC_RWLOCK	0x0002
122 #define	NSCD_ALLOC_COND		0x0004
123 
124 /*
125  * prototypes
126  */
127 nscd_seq_num_t
128 _nscd_get_seq_num();
129 
130 nscd_cookie_num_t
131 _nscd_get_cookie_num();
132 
133 nscd_acc_data_t *
134 _nscd_get(
135 	nscd_acc_data_t		*data);
136 
137 nscd_acc_data_t
138 *_nscd_set(
139 	nscd_acc_data_t		*old,
140 	nscd_acc_data_t		*new);
141 
142 void
143 _nscd_release(
144 	nscd_acc_data_t		*data);
145 
146 nscd_acc_data_t
147 *_nscd_rdlock(
148 	nscd_acc_data_t		*data);
149 
150 nscd_acc_data_t
151 *_nscd_wrlock(
152 	nscd_acc_data_t		*data);
153 
154 void
155 _nscd_rw_unlock(
156 	nscd_acc_data_t		*data);
157 
158 void
159 _nscd_rw_unlock_no_release(
160 	nscd_acc_data_t		*data);
161 
162 nscd_acc_data_t
163 *_nscd_mutex_lock(
164 	nscd_acc_data_t		*data);
165 
166 void
167 _nscd_mutex_unlock(
168 	nscd_acc_data_t		*data);
169 
170 void
171 _nscd_cond_signal(
172 	nscd_acc_data_t		*data);
173 
174 void
175 _nscd_cond_wait(
176 	nscd_acc_data_t		*data,
177 	cond_t			*cond);
178 
179 nscd_acc_data_t *
180 _nscd_alloc(
181 	int			type,
182 	size_t			size,
183 	void			(*data_free)(
184 				nscd_acc_data_t *data),
185 	int			option);
186 
187 nscd_rc_t
188 _nscd_add_int_addr(
189 	void 			*ptr,
190 	int 			type,
191 	nscd_seq_num_t		seq_num);
192 
193 rwlock_t *
194 _nscd_is_int_addr(
195 	void 			*ptr,
196 	nscd_seq_num_t		seq_num);
197 
198 void
199 _nscd_del_int_addr(
200 	void 			*ptr,
201 	nscd_seq_num_t		seq_num);
202 
203 nscd_db_t *
204 _nscd_alloc_db(
205 	int			size);
206 
207 void
208 _nscd_free_db(
209 	nscd_db_t		*db);
210 
211 nscd_db_entry_t *
212 _nscd_alloc_db_entry(
213 	int			type,
214 	const char 		*name,
215 	int			dataSize,
216 	int			num_data,
217 	int			num_array);
218 
219 const nscd_db_entry_t *
220 _nscd_get_db_entry(
221 	const nscd_db_t		*db,
222 	int			type,
223 	const char		*str,
224 	nscd_db_option_t	option,
225 	int			id_num);
226 
227 nscd_rc_t
228 _nscd_add_db_entry(
229 	nscd_db_t		*db,
230 	const char 		*str,
231 	nscd_db_entry_t		*entry,
232 	nscd_db_option_t	option);
233 
234 nscd_rc_t
235 _nscd_delete_db_entry(
236 	nscd_db_t		*db,
237 	int			type,
238 	const char		*str,
239 	nscd_db_option_t	option,
240 	int			id_num);
241 
242 
243 void *
244 _nscd_create_int_addrDB();
245 
246 void
247 _nscd_destroy_int_addrDB();
248 
249 #ifdef	__cplusplus
250 }
251 #endif
252 
253 #endif	/* _NSCD_DB_H */
254