8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / nscd / nscd_switch.h
blob0b3ded9e7008ac1dc9af3f88a1028dd2f7645b25
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _NSCD_SWITCH_H
27 #define _NSCD_SWITCH_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <nss_dbdefs.h>
34 #include <thread.h>
35 #include <libscf.h>
36 #define __NSS_PRIVATE_INTERFACE
37 #include "nsswitch_priv.h"
38 #undef __NSS_PRIVATE_INTERFACE
39 #include "nscd_db.h"
40 #include "nscd_config.h"
43 * max. length of e.g. "passwd: files ldap"
45 #define MAX_NSSWITCH_CONFIG_STRING_SZ 256
48 * max. length of the name of a NSS database
50 #define MAX_NSSWITCH_CONFIG_DB_NAME_SZ 256
53 * nscd_nsw_config_t is an abstraction of the configuration
54 * for a NSS database
56 typedef struct {
57 char *db_name;
58 char *nsw_cfg_str;
59 nss_db_params_t fe_params;
60 struct __nsw_switchconfig_v1 *nsw_config;
61 int max_src;
62 int *src_idx; /* ptr to array of */
63 /* src index */
64 int nobase; /* not shared */
65 } nscd_nsw_config_t;
68 * nscd_be_info_t is an abstraction of a NSS backend
70 typedef struct {
71 void *be_version;
72 nss_backend_constr_t be_constr;
73 nss_backend_finder_t *finder;
74 void *finder_priv;
75 } nscd_be_info_t;
78 * nscd_state_ctrl_t is used to control a nscd_nsw_state pool
80 typedef struct {
81 int max;
82 int allocated;
83 int free;
84 int waiter;
85 struct nscd_nsw_state *first;
86 } nscd_state_ctrl_t;
89 * nscd_nsw_state_base_t represents the nscd_nsw_state pool
90 * for a NSS database
92 typedef struct nscd_nsw_state_base {
93 int dbi; /* which database? */
94 nscd_state_ctrl_t nsw_state;
95 nscd_state_ctrl_t nsw_state_thr;
96 int used_by_thr;
97 thread_t tid;
98 cond_t thr_cond;
99 } nscd_nsw_state_base_t;
102 * nscd_nsw_state_t is an abstraction of all the data needed
103 * to do lookup of NSS database (e.g. "passwd" or "hosts")
105 extern void *_nscd_be_version; /* default version for supported be */
106 typedef struct nscd_nsw_state {
107 int dbi; /* which database? */
108 int max_src; /* is == config->num_lookups */
109 int getent; /* used by getent */
110 nscd_bool_t recheck_be; /* if set, check/init be */
111 nss_db_params_t p;
112 struct __nsw_switchconfig_v1 *config;
113 nscd_nsw_config_t **nsw_cfg_p;
114 nscd_nsw_state_base_t *base;
115 nss_backend_t **be; /* array of backends */
116 nss_backend_constr_t *be_constr; /* be constructor array */
117 nscd_db_t ***be_db_pp;
118 void **be_version_p; /* version ptr array */
119 struct nscd_nsw_state *next;
120 } nscd_nsw_state_t;
123 * nscd_getent_ctx_base_t represents the nscd_getent_ctx_base_t pool
124 * for a NSS database
126 typedef struct nscd_getent_ctx_base {
127 int dbi; /* which database? */
128 int max_getent_ctx;
129 int num_getent_ctx;
130 struct nscd_getent_context *first;
131 } nscd_getent_ctx_base_t;
134 * nscd_getent_context_t is an abstraction of all the data needed
135 * to enumerate a NSS database (e.g. "passwd" or "hosts")
137 typedef struct nscd_getent_context {
138 int dbi;
139 thread_t thr_id;
140 mutex_t getent_mutex;
141 int aborted;
142 int in_use;
143 int num_reclaim_check;
144 nscd_seq_num_t seq_num;
145 nscd_cookie_num_t cookie_num;
146 pid_t pid; /* door client's pid */
147 int n_src; /* >=max_src: end of sequence */
148 nscd_nsw_state_t *nsw_state;
149 nss_backend_t *be;
150 nscd_getent_ctx_base_t *base;
151 struct nscd_getent_context *next;
152 struct nscd_getent_context *next_to_reclaim;
153 } nscd_getent_context_t;
156 * nscd_smf_state_t is used to keep track of the state of the smf
157 * service associated with a NSS source (e.g. "passwd" or "hosts")
159 typedef struct {
160 char *src_name;
161 int src_state;
162 } nscd_smf_state_t;
165 * nscd_smf_state_t is used to keep track of the state of the smf
166 * service associated with a NSS source (e.g. "passwd" or "hosts")
168 typedef struct {
169 int dbi; /* database index */
171 * index of the database of which the switch policy
172 * should be used
174 int cfgdbi;
176 * index of the pseudo database that the NSS backend
177 * does search on
179 int compati;
181 * ptr to ptr to the siwtch config structure
183 nscd_nsw_config_t **nswcfg;
185 * frontend params passed to nss_search or nss_*ent
187 struct nss_db_params p;
189 * set to 1 if database is "hosts", else 2 if "ipnodes"
191 int8_t dnsi;
193 * set to 1 if require privilege to look up the database
195 uint8_t privdb;
196 } nscd_nsw_params_t;
199 * additional info returned by the switch engine
201 typedef struct {
202 void *pbuf; /* ptr to packed buffer */
203 size_t pbufsiz; /* length of the packed buffer */
204 int srci; /* last source searched */
205 int errnum; /* errno from the backend */
206 int noarg; /* if set, backend does not use the arg structure */
207 int fallback; /* if set, may need to fall back to main nscd */
208 int datalen; /* pbuf->data_len (backend may change it) */
209 } nscd_sw_return_t;
212 * nscd cookies used for setent/getent/endent
213 * - p0 cookie: returned by nscd to indicate
214 * the start of the enumeration position
215 * - p1 cookie: returned/updated by nscd to indicate
216 * the current enumeration position
218 #define NSCD_P0_COOKIE_SEQNUM -1
219 typedef struct {
220 pid_t p0_pid;
221 time_t p0_time;
222 nscd_seq_num_t p0_seqnum;
223 } nscd_getent_p0_cookie_t;
225 typedef struct {
226 nscd_cookie_num_t p1_cookie_num;
227 nscd_seq_num_t p1_seqnum;
228 } nscd_getent_p1_cookie_t;
231 * static tables or global data defined in other files
233 extern int _nscd_cfg_num_nsw_src;
234 extern int _nscd_cfg_num_nsw_src_all;
235 extern int _nscd_cfg_num_nsw_db;
236 extern int _nscd_cfg_num_nsw_db_all;
237 extern int _nscd_cfg_num_smf_services;
238 extern nscd_cfg_id_t _nscd_cfg_nsw_src[];
239 extern nscd_cfg_id_t *_nscd_cfg_nsw_src_all;
240 extern nscd_cfg_id_t _nscd_cfg_nsw_db[];
241 extern nss_db_initf_t nscd_nss_db_initf[];
242 extern nscd_cfg_id_t _nscd_cfg_smf_services[];
243 extern nscd_smf_state_t *nscd_smf_service_state;
244 extern nscd_db_t ***nscd_src_backend_db;
245 extern nscd_nsw_config_t ***nscd_nsw_config;
246 extern nscd_nsw_state_base_t **nscd_nsw_state_base;
247 extern nscd_getent_ctx_base_t **nscd_getent_ctx_base;
248 extern nscd_cfg_global_switch_t nscd_switch_cfg_g;
249 extern nscd_cfg_switch_t *nscd_switch_cfg;
250 extern nscd_cfg_stat_global_switch_t nscd_switch_stats_g;
251 extern nscd_cfg_stat_switch_t *nscd_switch_stats;
253 #define NSCD_NUM_SRC _nscd_cfg_num_nsw_src_all
254 #define NSCD_NUM_DB _nscd_cfg_num_nsw_db_all
255 #define NSCD_NUM_SMF_FMRI _nscd_cfg_num_smf_services
256 #define NSCD_NSW_SRC_NAME(i) (_nscd_cfg_nsw_src_all + i)->name
257 #define NSCD_NSW_DB_NAME(i) _nscd_cfg_nsw_db[i].name
258 #define NSCD_SMF_SVC_FMRI(i) _nscd_cfg_smf_services[i].name
259 #define NSCD_SMF_SVC_INDEX(i) _nscd_cfg_smf_services[i].index
260 #define NSCD_SMF_SVC_STATE(i) nscd_smf_service_state[i].src_state
261 #define NSCD_SW_CFG_G nscd_switch_cfg_g
262 #define NSCD_SW_CFG(i) nscd_switch_cfg[i]
263 #define NSCD_SW_STATS_G nscd_switch_stats_g
264 #define NSCD_SW_STATS(i) nscd_switch_stats[i]
267 * special service states used by the switch engine
269 #define NSCD_SVC_STATE_UNINITED -1
270 #define NSCD_SVC_STATE_FOREIGN_SRC -2
271 #define NSCD_SVC_STATE_UNSUPPORTED_SRC -3
274 * prototypes
277 void
278 _nscd_put_nsw_state(
279 nscd_nsw_state_t *s);
281 void
282 _nscd_put_nsw_state_thread(
283 nscd_nsw_state_t *s);
285 nscd_rc_t
286 _nscd_get_nsw_state(
287 nss_db_root_t *rootp,
288 nscd_nsw_params_t *params);
290 nscd_rc_t
291 _nscd_get_nsw_state_thread(
292 nss_db_root_t *rootp,
293 nscd_nsw_params_t *params);
295 nscd_rc_t
296 _nscd_init_all_nsw_state_base();
298 nscd_rc_t
299 _nscd_init_nsw_state_base(
300 int dbi,
301 int compat_basei,
302 int lock);
304 nscd_rc_t
305 _nscd_init_all_getent_ctx();
307 nscd_rc_t
308 _nscd_init_getent_ctx_base(
309 int dbi,
310 int lock);
312 nscd_db_t
313 *_nscd_create_getent_ctxaddrDB();
315 nscd_rc_t
316 _nscd_get_getent_ctx(
317 nss_getent_t *contextpp,
318 nscd_nsw_params_t *params);
320 void
321 _nscd_put_getent_ctx(
322 nscd_getent_context_t *ctx);
323 void
324 _nscd_free_ctx_if_aborted(
325 nscd_getent_context_t *ctx);
328 _nscd_is_getent_ctx_in_use(
329 nscd_getent_context_t *ctx);
331 nscd_rc_t
332 _nscd_init_all_nsw_config();
334 nscd_rc_t
335 _nscd_init_all_nsw_be_info_db();
337 #ifdef NSCD_NSSWITCH_CONF_FROM_SMF_PROP
338 nscd_rc_t
339 _nscd_get_new_nsw_config(
340 scf_handle_t *hndl,
341 const char *fmri,
342 scf_propertygroup_t *pg);
343 #endif
345 nscd_rc_t
346 _nscd_get_new_service_state(
347 int index,
348 scf_handle_t *hndl,
349 scf_property_t *prop);
351 nscd_getent_context_t *
352 _nscd_is_getent_ctx(
353 nscd_cookie_num_t cookie_num);
355 nscd_rc_t
356 _nscd_create_sw_struct(
357 int dbi,
358 int compat_basei,
359 const char *dbn,
360 const char *cfgstr,
361 void *swcfgv1,
362 nscd_nsw_params_t *params);
364 nscd_rc_t
365 _nscd_create_new_config(
366 nscd_nsw_params_t *params);
368 void
369 _nscd_free_nsw_config(
370 nscd_nsw_config_t *nswcfg);
372 nscd_rc_t
373 _nscd_init_smf_monitor();
375 nscd_rc_t
376 _nscd_alloc_nsw_config();
378 nscd_rc_t
379 _nscd_alloc_service_state_table();
381 nscd_rc_t
382 _nscd_alloc_nsw_state_base();
384 nscd_rc_t
385 _nscd_alloc_nsw_be_info_db();
387 nscd_rc_t
388 _nscd_alloc_getent_ctx_base();
390 void
391 _nscd_free_all_nsw_state_base();
393 void
394 _nscd_free_all_getent_ctx_base();
396 void
397 _nscd_free_all_nsw_config();
399 void
400 _nscd_free_all_nsw_backend_info_db();
402 struct __nsw_switchconfig_v1 *
403 _nsw_getoneconfig_v1(
404 const char *name,
405 char *linep,
406 enum __nsw_parse_err *errp);
408 __nsw_freeconfig_v1(
409 struct __nsw_switchconfig_v1 *conf);
412 _nscd_get_smf_state(int srci, int dbi, int recheck);
414 void
415 nss_psearch(void *buffer, size_t length);
416 void
417 nss_psetent(void *buffer, size_t length, pid_t pid);
418 void
419 nss_pgetent(void *buffer, size_t length);
420 void
421 nss_pendent(void *buffer, size_t length);
422 void
423 nss_pdelete(void *buffer, size_t length);
425 nscd_rc_t _nscd_alloc_switch_cfg();
426 nscd_rc_t _nscd_alloc_switch_stats();
427 nscd_db_t *_nscd_create_getent_ctx_addrDB();
428 nscd_db_t *_nscd_create_getent_ctxDB();
430 #ifdef __cplusplus
432 #endif
434 #endif /* _NSCD_SWITCH_H */