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