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]
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
33 #include <nss_dbdefs.h>
36 #define __NSS_PRIVATE_INTERFACE
37 #include "nsswitch_priv.h"
38 #undef __NSS_PRIVATE_INTERFACE
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
59 nss_db_params_t fe_params
;
60 struct __nsw_switchconfig_v1
*nsw_config
;
62 int *src_idx
; /* ptr to array of */
64 int nobase
; /* not shared */
68 * nscd_be_info_t is an abstraction of a NSS backend
72 nss_backend_constr_t be_constr
;
73 nss_backend_finder_t
*finder
;
78 * nscd_state_ctrl_t is used to control a nscd_nsw_state pool
85 struct nscd_nsw_state
*first
;
89 * nscd_nsw_state_base_t represents the nscd_nsw_state pool
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
;
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 */
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
;
123 * nscd_getent_ctx_base_t represents the nscd_getent_ctx_base_t pool
126 typedef struct nscd_getent_ctx_base
{
127 int dbi
; /* which database? */
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
{
140 mutex_t getent_mutex
;
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
;
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")
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")
169 int dbi
; /* database index */
171 * index of the database of which the switch policy
176 * index of the pseudo database that the NSS backend
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"
193 * set to 1 if require privilege to look up the database
199 * additional info returned by the switch engine
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) */
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
222 nscd_seq_num_t p0_seqnum
;
223 } nscd_getent_p0_cookie_t
;
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
279 nscd_nsw_state_t
*s
);
282 _nscd_put_nsw_state_thread(
283 nscd_nsw_state_t
*s
);
287 nss_db_root_t
*rootp
,
288 nscd_nsw_params_t
*params
);
291 _nscd_get_nsw_state_thread(
292 nss_db_root_t
*rootp
,
293 nscd_nsw_params_t
*params
);
296 _nscd_init_all_nsw_state_base();
299 _nscd_init_nsw_state_base(
305 _nscd_init_all_getent_ctx();
308 _nscd_init_getent_ctx_base(
313 *_nscd_create_getent_ctxaddrDB();
316 _nscd_get_getent_ctx(
317 nss_getent_t
*contextpp
,
318 nscd_nsw_params_t
*params
);
321 _nscd_put_getent_ctx(
322 nscd_getent_context_t
*ctx
);
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
);
332 _nscd_init_all_nsw_config();
335 _nscd_init_all_nsw_be_info_db();
337 #ifdef NSCD_NSSWITCH_CONF_FROM_SMF_PROP
339 _nscd_get_new_nsw_config(
342 scf_propertygroup_t
*pg
);
346 _nscd_get_new_service_state(
349 scf_property_t
*prop
);
351 nscd_getent_context_t
*
353 nscd_cookie_num_t cookie_num
);
356 _nscd_create_sw_struct(
362 nscd_nsw_params_t
*params
);
365 _nscd_create_new_config(
366 nscd_nsw_params_t
*params
);
369 _nscd_free_nsw_config(
370 nscd_nsw_config_t
*nswcfg
);
373 _nscd_init_smf_monitor();
376 _nscd_alloc_nsw_config();
379 _nscd_alloc_service_state_table();
382 _nscd_alloc_nsw_state_base();
385 _nscd_alloc_nsw_be_info_db();
388 _nscd_alloc_getent_ctx_base();
391 _nscd_free_all_nsw_state_base();
394 _nscd_free_all_getent_ctx_base();
397 _nscd_free_all_nsw_config();
400 _nscd_free_all_nsw_backend_info_db();
402 struct __nsw_switchconfig_v1
*
403 _nsw_getoneconfig_v1(
406 enum __nsw_parse_err
*errp
);
409 struct __nsw_switchconfig_v1
*conf
);
412 _nscd_get_smf_state(int srci
, int dbi
, int recheck
);
415 nss_psearch(void *buffer
, size_t length
);
417 nss_psetent(void *buffer
, size_t length
, pid_t pid
);
419 nss_pgetent(void *buffer
, size_t length
);
421 nss_pendent(void *buffer
, size_t length
);
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();
434 #endif /* _NSCD_SWITCH_H */