xref: /titanic_52/usr/src/cmd/nscd/nscd_config.h (revision 29836b1990ff03408750301a4ad20cfd233444b9)
1cb5caa98Sdjl /*
2cb5caa98Sdjl  * CDDL HEADER START
3cb5caa98Sdjl  *
4cb5caa98Sdjl  * The contents of this file are subject to the terms of the
5cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6cb5caa98Sdjl  * You may not use this file except in compliance with the License.
7cb5caa98Sdjl  *
8cb5caa98Sdjl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9cb5caa98Sdjl  * or http://www.opensolaris.org/os/licensing.
10cb5caa98Sdjl  * See the License for the specific language governing permissions
11cb5caa98Sdjl  * and limitations under the License.
12cb5caa98Sdjl  *
13cb5caa98Sdjl  * When distributing Covered Code, include this CDDL HEADER in each
14cb5caa98Sdjl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15cb5caa98Sdjl  * If applicable, add the following below this CDDL HEADER, with the
16cb5caa98Sdjl  * fields enclosed by brackets "[]" replaced with your own identifying
17cb5caa98Sdjl  * information: Portions Copyright [yyyy] [name of copyright owner]
18cb5caa98Sdjl  *
19cb5caa98Sdjl  * CDDL HEADER END
20cb5caa98Sdjl  */
21cb5caa98Sdjl /*
22*29836b19Smichen  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23cb5caa98Sdjl  * Use is subject to license terms.
24cb5caa98Sdjl  */
25cb5caa98Sdjl 
26cb5caa98Sdjl #ifndef	_NSCD_CONFIG_H
27cb5caa98Sdjl #define	_NSCD_CONFIG_H
28cb5caa98Sdjl 
29cb5caa98Sdjl #pragma ident	"%Z%%M%	%I%	%E% SMI"
30cb5caa98Sdjl 
31cb5caa98Sdjl #ifdef	__cplusplus
32cb5caa98Sdjl extern "C" {
33cb5caa98Sdjl #endif
34cb5caa98Sdjl 
35cb5caa98Sdjl #include <stdio.h>
36cb5caa98Sdjl #include "nscd_common.h"
37cb5caa98Sdjl 
38cb5caa98Sdjl /*
39cb5caa98Sdjl  * nscd_cfg_id_t is used to identify a config/stat
40cb5caa98Sdjl  * object. 'index' provides a way to quickly locate
41cb5caa98Sdjl  * the object in the associated configuration list.
42cb5caa98Sdjl  * 'name' can be looked up in the config info database
43cb5caa98Sdjl  * to obtain the index.
44cb5caa98Sdjl  */
45cb5caa98Sdjl typedef struct {
46cb5caa98Sdjl 	int		index;
47cb5caa98Sdjl 	char		*name;
48cb5caa98Sdjl } nscd_cfg_id_t;
49cb5caa98Sdjl 
50cb5caa98Sdjl /*
51cb5caa98Sdjl  * forward declaration of nscd_cfg_param_desc_t
52cb5caa98Sdjl  */
53cb5caa98Sdjl struct nscd_cfg_param_desc;
54cb5caa98Sdjl 
55cb5caa98Sdjl /*
56cb5caa98Sdjl  * for operations that apply to configuration data
57cb5caa98Sdjl  * in all the nsswitch databases
58cb5caa98Sdjl  */
59cb5caa98Sdjl #define	NSCD_CFG_NSW_ALLDB		"ALLDB"
60cb5caa98Sdjl #define	NSCD_CFG_NSW_ALLDB_INDEX	9999
61cb5caa98Sdjl 
62cb5caa98Sdjl /*
63cb5caa98Sdjl  * configuration lists includes switch databases (eg. hosts, passwd),
64cb5caa98Sdjl  * switch sources (eg. files, ldap), config parameter descriptions
65cb5caa98Sdjl  * (defined below), and status/statistic counter descriptions (defined
66cb5caa98Sdjl  * below)
67cb5caa98Sdjl  */
68cb5caa98Sdjl typedef struct {
69cb5caa98Sdjl 	int		num;
70cb5caa98Sdjl 	nscd_cfg_id_t	**list;
71cb5caa98Sdjl } nscd_cfg_list_t;
72cb5caa98Sdjl 
73cb5caa98Sdjl /*
74cb5caa98Sdjl  * type of configuration list
75cb5caa98Sdjl  */
76cb5caa98Sdjl typedef enum {
77cb5caa98Sdjl 	NSCD_CFG_LIST_NSW_DB	= 0,
78cb5caa98Sdjl 	NSCD_CFG_LIST_NSW_SRC	= 1,
79cb5caa98Sdjl 	NSCD_CFG_LIST_PARAM	= 2,
80cb5caa98Sdjl 	NSCD_CFG_LIST_STAT	= 3
81cb5caa98Sdjl } nscd_cfg_list_type_t;
82cb5caa98Sdjl 
83cb5caa98Sdjl /*
84cb5caa98Sdjl  * A config handle identifies config or stat data,
85cb5caa98Sdjl  * which if is nsswitch database specific, 'nswdb'
86cb5caa98Sdjl  * indicates the id of the database; if global,
87cb5caa98Sdjl  * 'nswdb' should be null. 'desc' is the config
88cb5caa98Sdjl  * param or stat description assocaited with the
89cb5caa98Sdjl  * data.
90cb5caa98Sdjl  */
91cb5caa98Sdjl typedef struct {
92cb5caa98Sdjl 	nscd_cfg_id_t			*nswdb;
93cb5caa98Sdjl 	void				*desc;
94cb5caa98Sdjl 	nscd_cfg_list_type_t		type;
95cb5caa98Sdjl } nscd_cfg_handle_t;
96cb5caa98Sdjl 
97cb5caa98Sdjl /*
98cb5caa98Sdjl  * type of configuration/statistics data
99cb5caa98Sdjl  */
100cb5caa98Sdjl typedef enum {
101cb5caa98Sdjl 	NSCD_CFG_DATA_NONE	= 0,
102cb5caa98Sdjl 	NSCD_CFG_DATA_INTEGER	= 1,
103cb5caa98Sdjl 	NSCD_CFG_DATA_BOOLEAN	= 2,
104cb5caa98Sdjl 	NSCD_CFG_DATA_STRING	= 3,
105cb5caa98Sdjl 	NSCD_CFG_DATA_BITMAP	= 4,
106cb5caa98Sdjl 	NSCD_CFG_DATA_PERCENT	= 5
107cb5caa98Sdjl } nscd_cfg_data_type_t;
108cb5caa98Sdjl #define	NSCD_CFG_NUM_DATA_TYPE	5
109cb5caa98Sdjl 
110cb5caa98Sdjl /*
111cb5caa98Sdjl  * data flag is attached to config/stat data passed between
112cb5caa98Sdjl  * function to specify the nature/type of action to perform
113cb5caa98Sdjl  */
114cb5caa98Sdjl 
115cb5caa98Sdjl #define	NSCD_CFG_DFLAG_NONE			   0x0000
116cb5caa98Sdjl 
117cb5caa98Sdjl /*
118cb5caa98Sdjl  * data should not be freed by receiver;
119cb5caa98Sdjl  * otherwise it should be freed
120cb5caa98Sdjl  */
121cb5caa98Sdjl #define	NSCD_CFG_DFLAG_STATIC_DATA		   0x0001
122cb5caa98Sdjl 
123cb5caa98Sdjl /*
124cb5caa98Sdjl  * data is sent/received due to nscd initialization;
125cb5caa98Sdjl  * otherwise due to modification of the config data
126cb5caa98Sdjl  * requested by users
127cb5caa98Sdjl  */
128cb5caa98Sdjl #define	NSCD_CFG_DFLAG_INIT			   0x0002
129cb5caa98Sdjl 
130cb5caa98Sdjl /*
131cb5caa98Sdjl  * the entire group of data is, or should be, sent;
132cb5caa98Sdjl  * otherwise only a single parameter/stat value
133cb5caa98Sdjl  */
134cb5caa98Sdjl #define	NSCD_CFG_DFLAG_GROUP			   0x0004
135cb5caa98Sdjl 
136cb5caa98Sdjl /*
137cb5caa98Sdjl  * the data sent/received is to be verified by the
138cb5caa98Sdjl  * 'verify' function defined in the parameter
139cb5caa98Sdjl  * description
140cb5caa98Sdjl  */
141cb5caa98Sdjl #define	NSCD_CFG_DFLAG_VERIFY			   0x0008
142cb5caa98Sdjl 
143cb5caa98Sdjl /*
144cb5caa98Sdjl  * the data sent/received is to be processed by the
145cb5caa98Sdjl  * 'notify' function defined in the parameter
146cb5caa98Sdjl  * description
147cb5caa98Sdjl  */
148cb5caa98Sdjl #define	NSCD_CFG_DFLAG_NOTIFY			   0x0010
149cb5caa98Sdjl 
150cb5caa98Sdjl /*
151cb5caa98Sdjl  * the data sent/received is to be applied to all
152cb5caa98Sdjl  * nsswitch databases
153cb5caa98Sdjl  */
154cb5caa98Sdjl #define	NSCD_CFG_DFLAG_SET_ALL_DB		   0x0020
155cb5caa98Sdjl 
156cb5caa98Sdjl /*
157cb5caa98Sdjl  * the entire group of data is sent/received;
158cb5caa98Sdjl  * however, only those parameters selected by
159cb5caa98Sdjl  * the bitmap in the group info should be
160cb5caa98Sdjl  * processed
161cb5caa98Sdjl  */
162cb5caa98Sdjl #define	NSCD_CFG_DFLAG_BIT_SELECTED		   0x0040
163cb5caa98Sdjl 
164cb5caa98Sdjl /*
165cb5caa98Sdjl  * param flag is defined in the parameter description.
166cb5caa98Sdjl  * It specifies what operation should be applied to, or
167cb5caa98Sdjl  * the nature of, the config parameters.
168cb5caa98Sdjl  */
169cb5caa98Sdjl 
170cb5caa98Sdjl #define	NSCD_CFG_PFLAG_NONE			   0x0000
171cb5caa98Sdjl 
172cb5caa98Sdjl /*
173cb5caa98Sdjl  * At init/refresh time, send the parameter value
174cb5caa98Sdjl  * with the data of the entire group; otherwise
175cb5caa98Sdjl  * send the parameter value only
176cb5caa98Sdjl  */
177cb5caa98Sdjl #define	NSCD_CFG_PFLAG_INIT_SEND_WHOLE_GROUP	   0x0001
178cb5caa98Sdjl 
179cb5caa98Sdjl /*
180cb5caa98Sdjl  * At user requested update time, send the parameter
181cb5caa98Sdjl  * value with the data of the entire group; otherwise
182cb5caa98Sdjl  * send the parameter value only
183cb5caa98Sdjl  */
184cb5caa98Sdjl #define	NSCD_CFG_PFLAG_UPDATE_SEND_WHOLE_GROUP	   0x0002
185cb5caa98Sdjl 
186cb5caa98Sdjl /*
187cb5caa98Sdjl  * At init/refresh time, send the config data
188cb5caa98Sdjl  * once for each nsswitch database
189cb5caa98Sdjl  */
190cb5caa98Sdjl #define	NSCD_CFG_PFLAG_INIT_SET_ALL_DB		   0x0004
191cb5caa98Sdjl 
192cb5caa98Sdjl /*
193cb5caa98Sdjl  * At user requested update time, send the per nsswitch
194cb5caa98Sdjl  * database (non-global) data just one time (not once
195cb5caa98Sdjl  * for each nsswitch database)
196cb5caa98Sdjl  */
197cb5caa98Sdjl #define	NSCD_CFG_PFLAG_UPDATE_SEND_NON_GLOBAL_ONCE 0x0008
198cb5caa98Sdjl 
199cb5caa98Sdjl /*
200cb5caa98Sdjl  * send entire group data, but use bitmap to indicate
201cb5caa98Sdjl  * the one config parameter being processed. This flag
202cb5caa98Sdjl  * can only be sepcified for a group description
203cb5caa98Sdjl  */
204cb5caa98Sdjl #define	NSCD_CFG_PFLAG_SEND_BIT_SELECTED	   0x0010
205cb5caa98Sdjl 
206cb5caa98Sdjl /*
207cb5caa98Sdjl  * data is global, not per nsswitch database
208cb5caa98Sdjl  */
209cb5caa98Sdjl #define	NSCD_CFG_PFLAG_GLOBAL			   0x0020
210cb5caa98Sdjl 
211cb5caa98Sdjl /*
212cb5caa98Sdjl  * data is group data, not individual parameter value
213cb5caa98Sdjl  */
214cb5caa98Sdjl #define	NSCD_CFG_PFLAG_GROUP			   0x0040
215cb5caa98Sdjl 
216cb5caa98Sdjl /*
217cb5caa98Sdjl  * data is of variable length
218cb5caa98Sdjl  */
219cb5caa98Sdjl #define	NSCD_CFG_PFLAG_VLEN_DATA		   0x0080
220cb5caa98Sdjl 
221cb5caa98Sdjl /*
222cb5caa98Sdjl  * data is hidden, for internal use only, get/set not allowed
223cb5caa98Sdjl  */
224cb5caa98Sdjl #define	NSCD_CFG_PFLAG_HIDDEN			   0x0100
225cb5caa98Sdjl 
226cb5caa98Sdjl /*
227cb5caa98Sdjl  * data is linked, using the value of a different database
228cb5caa98Sdjl  */
229cb5caa98Sdjl #define	NSCD_CFG_PFLAG_LINKED			   0x0200
230cb5caa98Sdjl 
231cb5caa98Sdjl /*
232cb5caa98Sdjl  * data is obsolete, ignored with warning, should not be displayed
233cb5caa98Sdjl  */
234cb5caa98Sdjl #define	NSCD_CFG_PFLAG_OBSOLETE			   0x0400
235cb5caa98Sdjl 
236cb5caa98Sdjl /*
237cb5caa98Sdjl  * structure for error reporting
238cb5caa98Sdjl  */
239cb5caa98Sdjl typedef struct {
240cb5caa98Sdjl 	nscd_rc_t	rc;
241cb5caa98Sdjl 	char		*msg;
242cb5caa98Sdjl } nscd_cfg_error_t;
243cb5caa98Sdjl 
244cb5caa98Sdjl /*
245cb5caa98Sdjl  * typedef for flag, bitmap, and boolean
246cb5caa98Sdjl  */
247cb5caa98Sdjl typedef int		nscd_cfg_flag_t;
248cb5caa98Sdjl typedef int		nscd_cfg_bitmap_t;
249cb5caa98Sdjl 
250cb5caa98Sdjl /*
251cb5caa98Sdjl  * struct nscd_cfg_param_desc is used to describe each and
252cb5caa98Sdjl  * every one of the nscd config parameters so that they can
253cb5caa98Sdjl  * be processed generically by the configuration management
254cb5caa98Sdjl  * component. During init or update time, config data needs
255cb5caa98Sdjl  * to be pushed to other nscd components (frontend, switch
256cb5caa98Sdjl  * engine, cache backend, and so on) for further processing.
257cb5caa98Sdjl  * The 'verify' and 'notify' functions are the hooks provided
258cb5caa98Sdjl  * by these other components to validate and store the new
259cb5caa98Sdjl  * config data. The 'p_check' field, if specified, points
260cb5caa98Sdjl  * to a set of data used for preliminary check of a parameter
261cb5caa98Sdjl  * value (range, length, null checking etc).
262cb5caa98Sdjl  */
2630dfdd7f3Smichen typedef	nscd_rc_t	(*nscd_cfg_func_notify_t)(void *,
2640dfdd7f3Smichen 			struct nscd_cfg_param_desc *,
2650dfdd7f3Smichen 			nscd_cfg_id_t *,
2660dfdd7f3Smichen 			nscd_cfg_flag_t,
2670dfdd7f3Smichen 			nscd_cfg_error_t **,
2680dfdd7f3Smichen 			void *);
2690dfdd7f3Smichen typedef	nscd_rc_t	(*nscd_cfg_func_verify_t)(void *,
2700dfdd7f3Smichen 			struct	nscd_cfg_param_desc *,
2710dfdd7f3Smichen 			nscd_cfg_id_t *,
2720dfdd7f3Smichen 			nscd_cfg_flag_t,
2730dfdd7f3Smichen 			nscd_cfg_error_t **,
2740dfdd7f3Smichen 			void **);
275cb5caa98Sdjl typedef struct nscd_cfg_param_desc {
276cb5caa98Sdjl 	nscd_cfg_id_t		id;
277cb5caa98Sdjl 	nscd_cfg_data_type_t	type;
278cb5caa98Sdjl 	nscd_cfg_flag_t		pflag;
279cb5caa98Sdjl 	int	p_size;
280cb5caa98Sdjl 	size_t	p_offset;
281cb5caa98Sdjl 	int	p_fn;
282cb5caa98Sdjl 	int	g_size;
283cb5caa98Sdjl 	size_t	g_offset;
284cb5caa98Sdjl 	int	g_index;
285cb5caa98Sdjl 	void	*p_check;
2860dfdd7f3Smichen 	nscd_cfg_func_notify_t	notify;
2870dfdd7f3Smichen 	nscd_cfg_func_verify_t	verify;
288cb5caa98Sdjl } nscd_cfg_param_desc_t;
289cb5caa98Sdjl 
290cb5caa98Sdjl /*
291cb5caa98Sdjl  * the _nscd_cfg_get_param_desc_list function returns
292cb5caa98Sdjl  * the list of nscd config param descriptions at
293cb5caa98Sdjl  * run time
294cb5caa98Sdjl  */
295cb5caa98Sdjl typedef struct {
296cb5caa98Sdjl 	int			num;
297cb5caa98Sdjl 	nscd_cfg_param_desc_t	**list;
298cb5caa98Sdjl } nscd_cfg_param_desc_list_t;
299cb5caa98Sdjl 
300cb5caa98Sdjl /* this describes data of variable length */
301cb5caa98Sdjl typedef struct {
302cb5caa98Sdjl 	void	*ptr;
303cb5caa98Sdjl 	int	len;
304cb5caa98Sdjl } nscd_cfg_vlen_data_t;
305cb5caa98Sdjl 
306cb5caa98Sdjl /*
307cb5caa98Sdjl  * The following defines the various global and nsswitch
308cb5caa98Sdjl  * database specific data structures for all the groups of
309cb5caa98Sdjl  * configuration parameters. Before each one, there lists
310cb5caa98Sdjl  * the associated group info which contains the number of
311cb5caa98Sdjl  * parameters and the corresponding bitmap.
312cb5caa98Sdjl  */
313cb5caa98Sdjl 
314cb5caa98Sdjl typedef struct {
315cb5caa98Sdjl 	int			num_param;
316cb5caa98Sdjl 	nscd_cfg_bitmap_t	bitmap;
317cb5caa98Sdjl } nscd_cfg_group_info_t;
318cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_NULL	{-1, 0x0000}
319cb5caa98Sdjl 
320cb5caa98Sdjl /*
321cb5caa98Sdjl  * frontend param group (Per nsswitch database)
322cb5caa98Sdjl  */
323cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_FRONTEND	{1, 0x0001}
324cb5caa98Sdjl typedef struct {
325cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
326cb5caa98Sdjl 	int			worker_thread_per_nsw_db;
327cb5caa98Sdjl } nscd_cfg_frontend_t;
328cb5caa98Sdjl 
329cb5caa98Sdjl /*
330cb5caa98Sdjl  * switch engine param group (Per nsswitch database)
331cb5caa98Sdjl  */
332cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_SWITCH	{7, 0x07f}
333cb5caa98Sdjl typedef struct {
334cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
335cb5caa98Sdjl 	char			*nsw_config_string;
336cb5caa98Sdjl 	char			*nsw_config_db;
337cb5caa98Sdjl 	nscd_bool_t		enable_lookup;
338cb5caa98Sdjl 	nscd_bool_t		enable_loopback_checking;
339cb5caa98Sdjl 	int			max_nsw_state_per_db;
340cb5caa98Sdjl 	int			max_nsw_state_per_thread;
341cb5caa98Sdjl 	int			max_getent_ctx_per_db;
342cb5caa98Sdjl } nscd_cfg_switch_t;
343cb5caa98Sdjl 
344cb5caa98Sdjl /*
345cb5caa98Sdjl  * log/debug param group (global)
346cb5caa98Sdjl  */
347cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_GLOBAL_LOG	{3, 0x0007}
348cb5caa98Sdjl typedef struct {
349cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
350cb5caa98Sdjl 	char			*logfile;
351cb5caa98Sdjl 	int			debug_level;
352cb5caa98Sdjl 	int			debug_comp;
353cb5caa98Sdjl } nscd_cfg_global_log_t;
354cb5caa98Sdjl 
355cb5caa98Sdjl /*
356cb5caa98Sdjl  * frontend param group (global)
357cb5caa98Sdjl  */
358cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_GLOBAL_FRONTEND	{2, 0x0003}
359cb5caa98Sdjl typedef struct {
360cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
361cb5caa98Sdjl 	int			common_worker_threads;
362cb5caa98Sdjl 	int			cache_hit_threads;
363cb5caa98Sdjl } nscd_cfg_global_frontend_t;
364cb5caa98Sdjl 
365cb5caa98Sdjl /*
366cb5caa98Sdjl  * self credential param group (global)
367cb5caa98Sdjl  */
368*29836b19Smichen #define	NSCD_CFG_GROUP_INFO_GLOBAL_SELFCRED	{2, 0x0003}
369cb5caa98Sdjl typedef struct {
370cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
371cb5caa98Sdjl 	nscd_bool_t		enable_selfcred;
372cb5caa98Sdjl 	int			per_user_nscd_ttl;
373cb5caa98Sdjl } nscd_cfg_global_selfcred_t;
374cb5caa98Sdjl 
375cb5caa98Sdjl /*
376cb5caa98Sdjl  * switch engine param group (global)
377cb5caa98Sdjl  */
378cb5caa98Sdjl #define	NSCD_CFG_GROUP_INFO_GLOBAL_SWITCH	{3, 0x0007}
379cb5caa98Sdjl typedef struct {
380cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
381cb5caa98Sdjl 	nscd_bool_t		enable_lookup_g;
382cb5caa98Sdjl 	nscd_bool_t		enable_loopback_checking_g;
383cb5caa98Sdjl 	int			check_smf_state_interval_g;
384cb5caa98Sdjl } nscd_cfg_global_switch_t;
385cb5caa98Sdjl 
386cb5caa98Sdjl /*
387cb5caa98Sdjl  * nscd_cfg_param_desc_t should always have nscd_cfg_id_t
388cb5caa98Sdjl  * as its first field. _nscd_cfg_get_desc below provides
389cb5caa98Sdjl  * an way to get to the nscd_cfg_param_desc_t from a
390cb5caa98Sdjl  * pointer to the static nscd_cfg_id_t returned by the
391cb5caa98Sdjl  * various_nscd_cfg_* functions
392cb5caa98Sdjl  */
393cb5caa98Sdjl #define	_nscd_cfg_get_desc_i(id)	((nscd_cfg_param_desc_t *)(id))
394cb5caa98Sdjl 
395cb5caa98Sdjl #define	_nscd_cfg_get_desc(h)		((h)->desc)
396cb5caa98Sdjl 
397cb5caa98Sdjl /*
398cb5caa98Sdjl  * The various param group structure should always have
399cb5caa98Sdjl  * nscd_cfg_group_info_t as its first field.
400cb5caa98Sdjl  * _nscd_cfg_get_gi below provides a generic way to
401cb5caa98Sdjl  * get to the nscd_cfg_group_info_t from a void pointer
402cb5caa98Sdjl  * to the various param group structure returned by the
403cb5caa98Sdjl  * _nscd_cfg_* functions
404cb5caa98Sdjl  */
405cb5caa98Sdjl #define	_nscd_cfg_get_gi(voidp)	((nscd_cfg_group_info_t *)(voidp))
406cb5caa98Sdjl 
407cb5caa98Sdjl /*
408cb5caa98Sdjl  * It is possible in the future, we will need more bits
409cb5caa98Sdjl  * than those in nscd_cfg_flag_t and nscd_cfg_bitmap_t. To
410cb5caa98Sdjl  * make it easier to extend, the following macro should be
411cb5caa98Sdjl  * used to deal with flags and bitmaps.
412cb5caa98Sdjl  * m, m1, m2, ma: mask, n: nth bit (0 based)
413cb5caa98Sdjl  * f: flag, v: value
414cb5caa98Sdjl  */
415cb5caa98Sdjl #define	NSCD_CFG_BITMAP_ZERO			0
416cb5caa98Sdjl #define	_nscd_cfg_bitmap_is_set(m, n)		(((m) >> n) & 1)
417cb5caa98Sdjl #define	_nscd_cfg_bitmap_is_not_set(m, n)	(!(((m) >> n) & 1))
418cb5caa98Sdjl #define	_nscd_cfg_bitmap_is_equal(m1, m2)	((m1) == (m2))
419cb5caa98Sdjl #define	_nscd_cfg_bitmap_value(m)		(m)
420cb5caa98Sdjl #define	_nscd_cfg_bitmap_set_nth(m, n)		((m) |= (1 << n))
421cb5caa98Sdjl #define	_nscd_cfg_bitmap_set(ma, m)		(*(nscd_cfg_bitmap_t *) \
422cb5caa98Sdjl 							(ma) = (m))
423cb5caa98Sdjl #define	_nscd_cfg_bitmap_valid(m1, m2)		(((m1) & ~(m2)) == 0)
424cb5caa98Sdjl 
425cb5caa98Sdjl #define	NSCD_CFG_FLAG_ZERO			0
426cb5caa98Sdjl #define	_nscd_cfg_flag_is_set(f, v)		((f) & (v))
427cb5caa98Sdjl #define	_nscd_cfg_flag_is_not_set(f, v)		(!((f) & (v)))
428cb5caa98Sdjl #define	_nscd_cfg_flag_value(f)			(f)
429cb5caa98Sdjl #define	_nscd_cfg_flag_set(f, v)		((f) | (v))
430cb5caa98Sdjl #define	_nscd_cfg_flag_unset(f, v)		((f) & ~(v))
431cb5caa98Sdjl 
432cb5caa98Sdjl /*
433cb5caa98Sdjl  * handy macros
434cb5caa98Sdjl  */
435cb5caa98Sdjl #define	NSCD_NULL			"NULL"
436cb5caa98Sdjl #define	NSCD_CFG_MAX_ERR_MSG_LEN	1024
437cb5caa98Sdjl #define	NSCD_STR_OR_NULL(s)		((s) == NULL ? "NULL" : (s))
438cb5caa98Sdjl #define	NSCD_STR_OR_GLOBAL(s)		((s) == NULL ? "GLOBAL" : (s))
439cb5caa98Sdjl #define	NSCD_Y_OR_N(s)			(*(nscd_bool_t *)s == nscd_true ? \
440cb5caa98Sdjl 				"yes" : "no")
441cb5caa98Sdjl 
442cb5caa98Sdjl #define	NSCD_ERR2MSG(e)		(((e) && (e)->msg) ? (e)->msg : "")
443cb5caa98Sdjl 
444cb5caa98Sdjl 
445cb5caa98Sdjl /*
446cb5caa98Sdjl  * This macro is based on offsetof defined in stddef_iso.h,
447cb5caa98Sdjl  * it gives the size of 'm' in structure 's' without needing
448cb5caa98Sdjl  * the declaration of a 's' variable (as macro sizeof does)
449cb5caa98Sdjl  */
450cb5caa98Sdjl #define	NSCD_SIZEOF(s, m)		(sizeof (((s *)0)->m))
451cb5caa98Sdjl 
452cb5caa98Sdjl 
453cb5caa98Sdjl /*
454cb5caa98Sdjl  * struct nscd_cfg_stat_desc is used to describe each and every
455cb5caa98Sdjl  * one of the nscd statistics counters so that they can be
456cb5caa98Sdjl  * processed generically by the configuration management
457cb5caa98Sdjl  * component. The component does not keep a separate copy of
458cb5caa98Sdjl  * all counters, which should be maintained by other nscd
459cb5caa98Sdjl  * components. The 'get_stat' functions defined in the
460cb5caa98Sdjl  * stat description are supplied by those components and used
461cb5caa98Sdjl  * by the config management component to request and print
462cb5caa98Sdjl  * counters on behave of the users. The free_stat function
463cb5caa98Sdjl  * returned by those components will also be used to free
464cb5caa98Sdjl  * the stat data if the NSCD_CFG_DFLAG_STATIC_DATA bit is
465cb5caa98Sdjl  * not set in dflag.
466cb5caa98Sdjl  */
4670dfdd7f3Smichen struct nscd_cfg_stat_desc;
4680dfdd7f3Smichen typedef	nscd_rc_t	(*nscd_cfg_func_get_stat_t)(void **,
4690dfdd7f3Smichen 			struct nscd_cfg_stat_desc *,
4700dfdd7f3Smichen 			nscd_cfg_id_t *,
4710dfdd7f3Smichen 			nscd_cfg_flag_t *,
4720dfdd7f3Smichen 			void (**) (void *),
4730dfdd7f3Smichen 			nscd_cfg_error_t **);
474cb5caa98Sdjl typedef struct nscd_cfg_stat_desc {
475cb5caa98Sdjl 	nscd_cfg_id_t		id;
476cb5caa98Sdjl 	nscd_cfg_data_type_t	type;
477cb5caa98Sdjl 	nscd_cfg_flag_t		sflag;
478cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
479cb5caa98Sdjl 	int	s_size;
480cb5caa98Sdjl 	size_t	s_offset;
481cb5caa98Sdjl 	int	s_fn;
482cb5caa98Sdjl 	int	g_size;
483cb5caa98Sdjl 	size_t	g_offset;
484cb5caa98Sdjl 	int	g_index;
4850dfdd7f3Smichen 	nscd_cfg_func_get_stat_t get_stat;
486cb5caa98Sdjl } nscd_cfg_stat_desc_t;
487cb5caa98Sdjl 
488cb5caa98Sdjl /*
489cb5caa98Sdjl  * stat flag is defined in the stat description. It
490cb5caa98Sdjl  * specifies the nature of the statistics counters.
491cb5caa98Sdjl  */
492cb5caa98Sdjl 
493cb5caa98Sdjl #define	NSCD_CFG_SFLAG_NONE			   0x0000
494cb5caa98Sdjl 
495cb5caa98Sdjl /*
496cb5caa98Sdjl  * statistics counter is global, not per nsswitch database
497cb5caa98Sdjl  */
498cb5caa98Sdjl #define	NSCD_CFG_SFLAG_GLOBAL			   0x0001
499cb5caa98Sdjl 
500cb5caa98Sdjl /*
501cb5caa98Sdjl  * description is for counter group, not individual counter
502cb5caa98Sdjl  */
503cb5caa98Sdjl #define	NSCD_CFG_SFLAG_GROUP			   0x0002
504cb5caa98Sdjl 
505cb5caa98Sdjl /*
506cb5caa98Sdjl  * The following defines the various global and nsswitch
507cb5caa98Sdjl  * database specific data structures for all the groups of
508cb5caa98Sdjl  * statistics counters. Before each one, there lists
509cb5caa98Sdjl  * the associated group info which contains the number of
510cb5caa98Sdjl  * counters and the corresponding bitmap.
511cb5caa98Sdjl  */
512cb5caa98Sdjl 
513cb5caa98Sdjl /*
514cb5caa98Sdjl  * switch engine stat group (Per nsswitch database)
515cb5caa98Sdjl  */
516cb5caa98Sdjl #define	NSCD_CFG_STAT_GROUP_INFO_SWITCH		{6, 0x003f}
517cb5caa98Sdjl typedef struct {
518cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
519cb5caa98Sdjl 	int			lookup_request_received;
520cb5caa98Sdjl 	int			lookup_request_queued;
521cb5caa98Sdjl 	int			lookup_request_in_progress;
522cb5caa98Sdjl 	int			lookup_request_succeeded;
523cb5caa98Sdjl 	int			lookup_request_failed;
524cb5caa98Sdjl 	int			loopback_nsw_db_skipped;
525cb5caa98Sdjl } nscd_cfg_stat_switch_t;
526cb5caa98Sdjl 
527cb5caa98Sdjl /*
528cb5caa98Sdjl  * log/debug stat group (global)
529cb5caa98Sdjl  */
530cb5caa98Sdjl #define	NSCD_CFG_STAT_GROUP_INFO_GLOBAL_LOG	{1, 0x0001}
531cb5caa98Sdjl typedef struct {
532cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
533cb5caa98Sdjl 	int			entries_logged;
534cb5caa98Sdjl } nscd_cfg_stat_global_log_t;
535cb5caa98Sdjl 
536cb5caa98Sdjl /*
537cb5caa98Sdjl  * switch engine stat group (global)
538cb5caa98Sdjl  */
539cb5caa98Sdjl #define	NSCD_CFG_STAT_GROUP_INFO_GLOBAL_SWITCH	{6, 0x003f}
540cb5caa98Sdjl typedef struct {
541cb5caa98Sdjl 	nscd_cfg_group_info_t	gi;
542cb5caa98Sdjl 	int			lookup_request_received_g;
543cb5caa98Sdjl 	int			lookup_request_queued_g;
544cb5caa98Sdjl 	int			lookup_request_in_progress_g;
545cb5caa98Sdjl 	int			lookup_request_succeeded_g;
546cb5caa98Sdjl 	int			lookup_request_failed_g;
547cb5caa98Sdjl 	int			loopback_nsw_db_skipped_g;
548cb5caa98Sdjl } nscd_cfg_stat_global_switch_t;
549cb5caa98Sdjl 
550cb5caa98Sdjl /*
551cb5caa98Sdjl  * control structure for appending string data to a buffer
552cb5caa98Sdjl  */
553cb5caa98Sdjl typedef struct {
554cb5caa98Sdjl 	char		*buf;
555cb5caa98Sdjl 	char		*next;
556cb5caa98Sdjl 	int		size;
557cb5caa98Sdjl 	int		used;
558cb5caa98Sdjl 	int		left;
559cb5caa98Sdjl 	int		real;
560cb5caa98Sdjl } nscd_cfg_buf_t;
561cb5caa98Sdjl 
562cb5caa98Sdjl /*
563cb5caa98Sdjl  * internal configuration management related functions
564cb5caa98Sdjl  */
565cb5caa98Sdjl nscd_rc_t _nscd_cfg_init();
566cb5caa98Sdjl 
567cb5caa98Sdjl nscd_rc_t
568cb5caa98Sdjl _nscd_cfg_get_param_desc_list(
569cb5caa98Sdjl 	nscd_cfg_param_desc_list_t **list);
570cb5caa98Sdjl 
571cb5caa98Sdjl nscd_rc_t
572cb5caa98Sdjl _nscd_cfg_get_handle(
573cb5caa98Sdjl 	char			*param_name,
574cb5caa98Sdjl 	char			*nswdb_name,
575cb5caa98Sdjl 	nscd_cfg_handle_t	**handle,
576cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
577cb5caa98Sdjl 
578cb5caa98Sdjl nscd_cfg_error_t *
579cb5caa98Sdjl _nscd_cfg_make_error(
580cb5caa98Sdjl 	nscd_rc_t		rc,
581cb5caa98Sdjl 	char			*msg);
582cb5caa98Sdjl 
583cb5caa98Sdjl void
584cb5caa98Sdjl _nscd_cfg_free_handle(
585cb5caa98Sdjl 	nscd_cfg_handle_t	*handle);
586cb5caa98Sdjl 
587cb5caa98Sdjl void
588cb5caa98Sdjl _nscd_cfg_free_group_data(
589cb5caa98Sdjl 	nscd_cfg_handle_t	*handle,
590cb5caa98Sdjl 	void			*data);
591cb5caa98Sdjl 
592cb5caa98Sdjl void
593cb5caa98Sdjl _nscd_cfg_free_param_data(
594cb5caa98Sdjl 	void			*data);
595cb5caa98Sdjl 
596cb5caa98Sdjl void
597cb5caa98Sdjl _nscd_cfg_free_error(
598cb5caa98Sdjl 	nscd_cfg_error_t	*error);
599cb5caa98Sdjl 
600cb5caa98Sdjl nscd_rc_t
601cb5caa98Sdjl _nscd_cfg_get(
602cb5caa98Sdjl 	nscd_cfg_handle_t	*handle,
603cb5caa98Sdjl 	void			**data,
604cb5caa98Sdjl 	int			*data_len,
605cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
606cb5caa98Sdjl 
607cb5caa98Sdjl nscd_rc_t
608cb5caa98Sdjl _nscd_cfg_set(
609cb5caa98Sdjl 	nscd_cfg_handle_t	*handle,
610cb5caa98Sdjl 	void			*data,
611cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
612cb5caa98Sdjl 
613cb5caa98Sdjl nscd_rc_t
614cb5caa98Sdjl _nscd_cfg_str_to_data(
615cb5caa98Sdjl 	nscd_cfg_param_desc_t	*desc,
616cb5caa98Sdjl 	char			*str,
617cb5caa98Sdjl 	void			*data,
618cb5caa98Sdjl 	void			**data_p,
619cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
620cb5caa98Sdjl 
621cb5caa98Sdjl nscd_rc_t
622cb5caa98Sdjl _nscd_cfg_prelim_check(
623cb5caa98Sdjl 	nscd_cfg_param_desc_t	*desc,
624cb5caa98Sdjl 	void			*data,
625cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
626cb5caa98Sdjl 
627cb5caa98Sdjl nscd_rc_t
628cb5caa98Sdjl _nscd_cfg_read_file(
629cb5caa98Sdjl 	char			*filename,
630cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
631cb5caa98Sdjl 
632cb5caa98Sdjl nscd_rc_t
633cb5caa98Sdjl _nscd_cfg_set_linked(
634cb5caa98Sdjl 	nscd_cfg_handle_t	*handle,
635cb5caa98Sdjl 	void			*data,
636cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
637cb5caa98Sdjl 
638cb5caa98Sdjl char *
639cb5caa98Sdjl _nscd_srcs_in_db_nsw_policy(
640cb5caa98Sdjl 	int			num_src,
641cb5caa98Sdjl 	char			**srcs);
642cb5caa98Sdjl 
643cb5caa98Sdjl nscd_rc_t
644cb5caa98Sdjl _nscd_cfg_read_nsswitch_file(
645cb5caa98Sdjl 	char			*filename,
646cb5caa98Sdjl 	nscd_cfg_error_t	**errorp);
647cb5caa98Sdjl 
648cb5caa98Sdjl #ifdef	__cplusplus
649cb5caa98Sdjl }
650cb5caa98Sdjl #endif
651cb5caa98Sdjl 
652cb5caa98Sdjl #endif	/* _NSCD_CONFIG_H */
653