xref: /illumos-gate/usr/src/cmd/nscd/nscd_config.h (revision c65ebfc7045424bd04a6c7719a27b0ad3399ad54)
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 2008 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	{2, 0x0003}
369 typedef struct {
370 	nscd_cfg_group_info_t	gi;
371 	nscd_bool_t		enable_selfcred;
372 	int			per_user_nscd_ttl;
373 } nscd_cfg_global_selfcred_t;
374 
375 /*
376  * switch engine param group (global)
377  */
378 #define	NSCD_CFG_GROUP_INFO_GLOBAL_SWITCH	{3, 0x0007}
379 typedef struct {
380 	nscd_cfg_group_info_t	gi;
381 	nscd_bool_t		enable_lookup_g;
382 	nscd_bool_t		enable_loopback_checking_g;
383 	int			check_smf_state_interval_g;
384 } nscd_cfg_global_switch_t;
385 
386 /*
387  * nscd_cfg_param_desc_t should always have nscd_cfg_id_t
388  * as its first field. _nscd_cfg_get_desc below provides
389  * an way to get to the nscd_cfg_param_desc_t from a
390  * pointer to the static nscd_cfg_id_t returned by the
391  * various_nscd_cfg_* functions
392  */
393 #define	_nscd_cfg_get_desc_i(id)	((nscd_cfg_param_desc_t *)(id))
394 
395 #define	_nscd_cfg_get_desc(h)		((h)->desc)
396 
397 /*
398  * The various param group structure should always have
399  * nscd_cfg_group_info_t as its first field.
400  * _nscd_cfg_get_gi below provides a generic way to
401  * get to the nscd_cfg_group_info_t from a void pointer
402  * to the various param group structure returned by the
403  * _nscd_cfg_* functions
404  */
405 #define	_nscd_cfg_get_gi(voidp)	((nscd_cfg_group_info_t *)(voidp))
406 
407 /*
408  * It is possible in the future, we will need more bits
409  * than those in nscd_cfg_flag_t and nscd_cfg_bitmap_t. To
410  * make it easier to extend, the following macro should be
411  * used to deal with flags and bitmaps.
412  * m, m1, m2, ma: mask, n: nth bit (0 based)
413  * f: flag, v: value
414  */
415 #define	NSCD_CFG_BITMAP_ZERO			0
416 #define	_nscd_cfg_bitmap_is_set(m, n)		(((m) >> n) & 1)
417 #define	_nscd_cfg_bitmap_is_not_set(m, n)	(!(((m) >> n) & 1))
418 #define	_nscd_cfg_bitmap_is_equal(m1, m2)	((m1) == (m2))
419 #define	_nscd_cfg_bitmap_value(m)		(m)
420 #define	_nscd_cfg_bitmap_set_nth(m, n)		((m) |= (1 << n))
421 #define	_nscd_cfg_bitmap_set(ma, m)		(*(nscd_cfg_bitmap_t *) \
422 							(ma) = (m))
423 #define	_nscd_cfg_bitmap_valid(m1, m2)		(((m1) & ~(m2)) == 0)
424 
425 #define	NSCD_CFG_FLAG_ZERO			0
426 #define	_nscd_cfg_flag_is_set(f, v)		((f) & (v))
427 #define	_nscd_cfg_flag_is_not_set(f, v)		(!((f) & (v)))
428 #define	_nscd_cfg_flag_value(f)			(f)
429 #define	_nscd_cfg_flag_set(f, v)		((f) | (v))
430 #define	_nscd_cfg_flag_unset(f, v)		((f) & ~(v))
431 
432 /*
433  * handy macros
434  */
435 #define	NSCD_NULL			"NULL"
436 #define	NSCD_CFG_MAX_ERR_MSG_LEN	1024
437 #define	NSCD_STR_OR_NULL(s)		((s) == NULL ? "NULL" : (s))
438 #define	NSCD_STR_OR_GLOBAL(s)		((s) == NULL ? "GLOBAL" : (s))
439 #define	NSCD_Y_OR_N(s)			(*(nscd_bool_t *)s == nscd_true ? \
440 				"yes" : "no")
441 
442 #define	NSCD_ERR2MSG(e)		(((e) && (e)->msg) ? (e)->msg : "")
443 
444 
445 /*
446  * This macro is based on offsetof defined in stddef_iso.h,
447  * it gives the size of 'm' in structure 's' without needing
448  * the declaration of a 's' variable (as macro sizeof does)
449  */
450 #define	NSCD_SIZEOF(s, m)		(sizeof (((s *)0)->m))
451 
452 
453 /*
454  * struct nscd_cfg_stat_desc is used to describe each and every
455  * one of the nscd statistics counters so that they can be
456  * processed generically by the configuration management
457  * component. The component does not keep a separate copy of
458  * all counters, which should be maintained by other nscd
459  * components. The 'get_stat' functions defined in the
460  * stat description are supplied by those components and used
461  * by the config management component to request and print
462  * counters on behave of the users. The free_stat function
463  * returned by those components will also be used to free
464  * the stat data if the NSCD_CFG_DFLAG_STATIC_DATA bit is
465  * not set in dflag.
466  */
467 struct nscd_cfg_stat_desc;
468 typedef	nscd_rc_t	(*nscd_cfg_func_get_stat_t)(void **,
469 			struct nscd_cfg_stat_desc *,
470 			nscd_cfg_id_t *,
471 			nscd_cfg_flag_t *,
472 			void (**) (void *),
473 			nscd_cfg_error_t **);
474 typedef struct nscd_cfg_stat_desc {
475 	nscd_cfg_id_t		id;
476 	nscd_cfg_data_type_t	type;
477 	nscd_cfg_flag_t		sflag;
478 	nscd_cfg_group_info_t	gi;
479 	int	s_size;
480 	size_t	s_offset;
481 	int	s_fn;
482 	int	g_size;
483 	size_t	g_offset;
484 	int	g_index;
485 	nscd_cfg_func_get_stat_t get_stat;
486 } nscd_cfg_stat_desc_t;
487 
488 /*
489  * stat flag is defined in the stat description. It
490  * specifies the nature of the statistics counters.
491  */
492 
493 #define	NSCD_CFG_SFLAG_NONE			   0x0000
494 
495 /*
496  * statistics counter is global, not per nsswitch database
497  */
498 #define	NSCD_CFG_SFLAG_GLOBAL			   0x0001
499 
500 /*
501  * description is for counter group, not individual counter
502  */
503 #define	NSCD_CFG_SFLAG_GROUP			   0x0002
504 
505 /*
506  * The following defines the various global and nsswitch
507  * database specific data structures for all the groups of
508  * statistics counters. Before each one, there lists
509  * the associated group info which contains the number of
510  * counters and the corresponding bitmap.
511  */
512 
513 /*
514  * switch engine stat group (Per nsswitch database)
515  */
516 #define	NSCD_CFG_STAT_GROUP_INFO_SWITCH		{6, 0x003f}
517 typedef struct {
518 	nscd_cfg_group_info_t	gi;
519 	int			lookup_request_received;
520 	int			lookup_request_queued;
521 	int			lookup_request_in_progress;
522 	int			lookup_request_succeeded;
523 	int			lookup_request_failed;
524 	int			loopback_nsw_db_skipped;
525 } nscd_cfg_stat_switch_t;
526 
527 /*
528  * log/debug stat group (global)
529  */
530 #define	NSCD_CFG_STAT_GROUP_INFO_GLOBAL_LOG	{1, 0x0001}
531 typedef struct {
532 	nscd_cfg_group_info_t	gi;
533 	int			entries_logged;
534 } nscd_cfg_stat_global_log_t;
535 
536 /*
537  * switch engine stat group (global)
538  */
539 #define	NSCD_CFG_STAT_GROUP_INFO_GLOBAL_SWITCH	{6, 0x003f}
540 typedef struct {
541 	nscd_cfg_group_info_t	gi;
542 	int			lookup_request_received_g;
543 	int			lookup_request_queued_g;
544 	int			lookup_request_in_progress_g;
545 	int			lookup_request_succeeded_g;
546 	int			lookup_request_failed_g;
547 	int			loopback_nsw_db_skipped_g;
548 } nscd_cfg_stat_global_switch_t;
549 
550 /*
551  * control structure for appending string data to a buffer
552  */
553 typedef struct {
554 	char		*buf;
555 	char		*next;
556 	int		size;
557 	int		used;
558 	int		left;
559 	int		real;
560 } nscd_cfg_buf_t;
561 
562 /*
563  * internal configuration management related functions
564  */
565 nscd_rc_t _nscd_cfg_init();
566 
567 nscd_rc_t
568 _nscd_cfg_get_param_desc_list(
569 	nscd_cfg_param_desc_list_t **list);
570 
571 nscd_rc_t
572 _nscd_cfg_get_handle(
573 	char			*param_name,
574 	char			*nswdb_name,
575 	nscd_cfg_handle_t	**handle,
576 	nscd_cfg_error_t	**errorp);
577 
578 nscd_cfg_error_t *
579 _nscd_cfg_make_error(
580 	nscd_rc_t		rc,
581 	char			*msg);
582 
583 void
584 _nscd_cfg_free_handle(
585 	nscd_cfg_handle_t	*handle);
586 
587 void
588 _nscd_cfg_free_group_data(
589 	nscd_cfg_handle_t	*handle,
590 	void			*data);
591 
592 void
593 _nscd_cfg_free_param_data(
594 	void			*data);
595 
596 void
597 _nscd_cfg_free_error(
598 	nscd_cfg_error_t	*error);
599 
600 nscd_rc_t
601 _nscd_cfg_get(
602 	nscd_cfg_handle_t	*handle,
603 	void			**data,
604 	int			*data_len,
605 	nscd_cfg_error_t	**errorp);
606 
607 nscd_rc_t
608 _nscd_cfg_set(
609 	nscd_cfg_handle_t	*handle,
610 	void			*data,
611 	nscd_cfg_error_t	**errorp);
612 
613 nscd_rc_t
614 _nscd_cfg_str_to_data(
615 	nscd_cfg_param_desc_t	*desc,
616 	char			*str,
617 	void			*data,
618 	void			**data_p,
619 	nscd_cfg_error_t	**errorp);
620 
621 nscd_rc_t
622 _nscd_cfg_prelim_check(
623 	nscd_cfg_param_desc_t	*desc,
624 	void			*data,
625 	nscd_cfg_error_t	**errorp);
626 
627 nscd_rc_t
628 _nscd_cfg_read_file(
629 	char			*filename,
630 	nscd_cfg_error_t	**errorp);
631 
632 nscd_rc_t
633 _nscd_cfg_set_linked(
634 	nscd_cfg_handle_t	*handle,
635 	void			*data,
636 	nscd_cfg_error_t	**errorp);
637 
638 char *
639 _nscd_srcs_in_db_nsw_policy(
640 	int			num_src,
641 	char			**srcs);
642 
643 nscd_rc_t
644 _nscd_cfg_read_nsswitch_file(
645 	char			*filename,
646 	nscd_cfg_error_t	**errorp);
647 
648 #ifdef	__cplusplus
649 }
650 #endif
651 
652 #endif	/* _NSCD_CONFIG_H */
653