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