1 /* config.c - configuration file handling routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
31 #include <ac/string.h>
33 #include <ac/signal.h>
34 #include <ac/socket.h>
37 #include <sys/types.h>
43 #include "slapi/slapi.h"
51 * defaults for various global variables
53 slap_mask_t global_allows = 0;
54 slap_mask_t global_disallows = 0;
55 int global_gentlehup = 0;
56 int global_idletimeout = 0;
57 char *global_host = NULL;
58 char *global_realm = NULL;
59 char *ldap_srvtab = "";
60 char **default_passwd_hash = NULL;
61 struct berval default_search_base = BER_BVNULL;
62 struct berval default_search_nbase = BER_BVNULL;
64 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
65 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
67 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
68 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
70 char *slapd_pid_file = NULL;
71 char *slapd_args_file = NULL;
73 int use_reverse_lookup = 0;
76 int slapi_plugins_used = 0;
79 static int fp_getline(FILE *fp, ConfigArgs *c);
80 static void fp_getline_init(ConfigArgs *c);
81 static int fp_parse_line(ConfigArgs *c);
83 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
86 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
89 c = ch_calloc( 1, sizeof( ConfigArgs ) );
90 if ( c == NULL ) return(NULL);
96 snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
101 init_config_argv( ConfigArgs *c )
103 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
104 c->argv_size = ARGS_STEP + 1;
107 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
110 for(i = 0; Conf[i].name; i++)
111 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
112 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
113 if ( !Conf[i].name ) return NULL;
117 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
118 int rc, arg_user, arg_type, iarg;
122 arg_type = Conf->arg_type;
123 if(arg_type == ARG_IGNORED) {
124 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
125 c->log, Conf->name, 0);
128 if((arg_type & ARG_DN) && c->argc == 1) {
132 if(Conf->min_args && (c->argc < Conf->min_args)) {
133 sprintf( c->msg, "<%s> missing <%s> argument",
134 c->argv[0], Conf->what );
135 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
136 return(ARG_BAD_CONF);
138 if(Conf->max_args && (c->argc > Conf->max_args)) {
139 sprintf( c->msg, "<%s> extra cruft after <%s> ignored",
140 c->argv[0], Conf->what );
141 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
143 if((arg_type & ARG_DB) && !c->be) {
144 sprintf( c->msg, "<%s> only allowed within database declaration",
146 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
148 return(ARG_BAD_CONF);
150 if((arg_type & ARG_PRE_BI) && c->bi) {
151 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
152 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
153 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
155 return(ARG_BAD_CONF);
157 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
158 sprintf( c->msg, "<%s> must occur before any database declaration",
160 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
162 return(ARG_BAD_CONF);
164 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
165 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
166 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
168 return(ARG_BAD_CONF);
170 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
171 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
173 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
175 return(ARG_BAD_CONF);
177 c->type = arg_user = (arg_type & ARGS_USERLAND);
178 memset(&c->values, 0, sizeof(c->values));
179 if(arg_type & ARGS_NUMERIC) {
181 iarg = 0; larg = 0; barg = 0;
182 switch(arg_type & ARGS_NUMERIC) {
183 case ARG_INT: iarg = atoi(c->argv[1]); break;
184 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
185 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
189 } else if(!strcasecmp(c->argv[1], "on") ||
190 !strcasecmp(c->argv[1], "true")) {
192 } else if(!strcasecmp(c->argv[1], "off") ||
193 !strcasecmp(c->argv[1], "false")) {
196 sprintf( c->msg, "<%s> invalid value, ignored",
198 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
204 j = (arg_type & ARG_NONZERO) ? 1 : 0;
205 if(iarg < j && larg < j && barg < j ) {
206 larg = larg ? larg : (barg ? barg : iarg);
207 sprintf( c->msg, "<%s> invalid value, ignored",
209 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
211 return(ARG_BAD_CONF);
213 switch(arg_type & ARGS_NUMERIC) {
215 case ARG_INT: c->value_int = iarg; break;
216 case ARG_LONG: c->value_long = larg; break;
217 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
219 } else if(arg_type & ARG_STRING) {
221 c->value_string = ch_strdup(c->argv[1]);
222 } else if(arg_type & ARG_BERVAL) {
224 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
225 } else if(arg_type & ARG_DN) {
227 ber_str2bv( c->argv[1], 0, 0, &bv );
228 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
229 if ( rc != LDAP_SUCCESS ) {
230 sprintf( c->msg, "<%s> invalid DN %d (%s)",
231 c->argv[0], rc, ldap_err2string( rc ));
232 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
233 return(ARG_BAD_CONF);
236 ch_free( c->value_ndn.bv_val );
237 ch_free( c->value_dn.bv_val );
243 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
247 arg_type = Conf->arg_type;
248 if(arg_type & ARG_MAGIC) {
249 if(!c->be) c->be = frontendDB;
251 rc = (*((ConfigDriver*)Conf->arg_item))(c);
253 if(c->be == frontendDB) c->be = NULL;
257 sprintf( c->msg, "<%s> handler exited with %d",
259 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
262 return(ARG_BAD_CONF);
266 if(arg_type & ARG_OFFSET) {
268 ptr = c->be->be_private;
270 ptr = c->bi->bi_private;
272 sprintf( c->msg, "<%s> offset is missing base pointer",
274 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
276 return(ARG_BAD_CONF);
278 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
279 } else if (arg_type & ARGS_POINTER) {
280 ptr = Conf->arg_item;
282 if(arg_type & ARGS_POINTER)
283 switch(arg_type & ARGS_POINTER) {
285 case ARG_INT: *(int*)ptr = c->value_int; break;
286 case ARG_LONG: *(long*)ptr = c->value_long; break;
287 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
289 char *cc = *(char**)ptr;
291 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
292 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
293 c->log, Conf->name, 0 );
294 return(ARG_BAD_CONF);
298 *(char **)ptr = c->value_string;
302 *(struct berval *)ptr = c->value_bv;
308 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
311 arg_type = Conf->arg_type;
312 if(arg_type == ARG_IGNORED) {
313 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
314 c->log, Conf->name, 0);
317 rc = config_check_vals( Conf, c, 0 );
319 return config_set_vals( Conf, c );
323 config_del_vals(ConfigTable *cf, ConfigArgs *c)
327 /* If there is no handler, just ignore it */
328 if ( cf->arg_type & ARG_MAGIC ) {
329 c->op = LDAP_MOD_DELETE;
330 c->type = cf->arg_type & ARGS_USERLAND;
331 rc = (*((ConfigDriver*)cf->arg_item))(c);
337 config_get_vals(ConfigTable *cf, ConfigArgs *c)
343 if ( cf->arg_type & ARG_IGNORED ) {
347 memset(&c->values, 0, sizeof(c->values));
348 c->rvalue_vals = NULL;
349 c->rvalue_nvals = NULL;
350 c->op = SLAP_CONFIG_EMIT;
351 c->type = cf->arg_type & ARGS_USERLAND;
353 if ( cf->arg_type & ARG_MAGIC ) {
354 rc = (*((ConfigDriver*)cf->arg_item))(c);
357 if ( cf->arg_type & ARG_OFFSET ) {
359 ptr = c->be->be_private;
361 ptr = c->bi->bi_private;
364 ptr = (void *)((char *)ptr + (int)cf->arg_item);
369 switch(cf->arg_type & ARGS_POINTER) {
371 case ARG_INT: c->value_int = *(int *)ptr; break;
372 case ARG_LONG: c->value_long = *(long *)ptr; break;
373 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
376 c->value_string = ch_strdup(*(char **)ptr);
379 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
382 if ( cf->arg_type & ARGS_POINTER) {
384 switch(cf->arg_type & ARGS_POINTER) {
385 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
386 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
387 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
388 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
389 c->value_int ? "TRUE" : "FALSE"); break;
391 if ( c->value_string && c->value_string[0]) {
392 ber_str2bv( c->value_string, 0, 0, &bv);
398 if ( !BER_BVISEMPTY( &c->value_bv )) {
405 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
406 ber_bvarray_add(&c->rvalue_vals, &bv);
408 value_add_one(&c->rvalue_vals, &bv);
414 init_config_attrs(ConfigTable *ct) {
415 LDAPAttributeType *at;
419 for (i=0; ct[i].name; i++ ) {
420 if ( !ct[i].attribute ) continue;
421 at = ldap_str2attributetype( ct[i].attribute,
422 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
424 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
425 ct[i].attribute, ldap_scherr2str(code), err );
428 code = at_add( at, 0, NULL, &err );
429 if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
430 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
431 ct[i].attribute, scherr2str(code), err );
434 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
436 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
437 ct[i].attribute, err );
447 init_config_ocs( ConfigOCs *ocs ) {
450 for (i=0;ocs[i].co_def;i++) {
455 oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
456 LDAP_SCHEMA_ALLOW_ALL );
458 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
459 ocs[i].co_def, ldap_scherr2str(code), err );
462 code = oc_add(oc,0,NULL,&err);
463 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
464 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
465 ocs[i].co_def, scherr2str(code), err );
468 ocs[i].co_oc = oc_find(oc->oc_names[0]);
475 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
478 char *saveline = NULL;
480 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
481 ct->ad->ad_cname.bv_val, valx );
483 c->argv[0] = ct->ad->ad_cname.bv_val;
485 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
489 len = strlen( c->line );
490 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
491 sprintf( c->line, "\"%s\"", saveline );
494 if ( fp_parse_line( c ) ) {
497 rc = config_check_vals( ct, c, 1 );
506 rc = LDAP_CONSTRAINT_VIOLATION;
513 config_parse_add(ConfigTable *ct, ConfigArgs *c)
516 char *saveline = NULL;
518 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
519 ct->ad->ad_cname.bv_val, c->valx );
521 c->argv[0] = ct->ad->ad_cname.bv_val;
523 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
527 len = strlen( c->line );
529 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
530 sprintf( c->line, "\"%s\"", saveline );
533 if ( fp_parse_line( c ) ) {
536 c->op = LDAP_MOD_ADD;
537 rc = config_add_vals( ct, c );
550 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
558 c = ch_calloc( 1, sizeof( ConfigArgs ) );
564 memcpy( c, cf, sizeof( ConfigArgs ) );
566 c->depth = depth; /* XXX */
573 init_config_argv( c );
575 if ( stat( fname, &s ) != 0 ) {
577 Debug(LDAP_DEBUG_ANY,
578 "could not stat config file \"%s\": %s (%d)\n",
579 fname, strerror(errno), errno);
583 if ( !S_ISREG( s.st_mode ) ) {
585 Debug(LDAP_DEBUG_ANY,
586 "regular file expected, got \"%s\"\n",
591 fp = fopen( fname, "r" );
594 Debug(LDAP_DEBUG_ANY,
595 "could not open config file \"%s\": %s (%d)\n",
596 fname, strerror(errno), errno);
600 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
606 while ( fp_getline( fp, c ) ) {
607 /* skip comments and blank lines */
608 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
612 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
613 c->fname, c->lineno );
617 if ( fp_parse_line( c ) ) {
623 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line"
624 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
626 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
629 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
631 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
634 c->op = SLAP_CONFIG_ADD;
636 ct = config_find_keyword( cft, c );
638 rc = config_add_vals( ct, c );
641 if ( rc & ARGS_USERLAND ) {
642 /* XXX a usertype would be opaque here */
643 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
644 c->log, c->argv[0], 0);
648 } else if ( rc == ARG_BAD_CONF ) {
653 } else if ( c->bi && !c->be ) {
654 rc = SLAP_CONF_UNKNOWN;
655 if ( c->bi->bi_cf_ocs ) {
656 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
658 rc = config_add_vals( ct, c );
661 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
662 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
667 case SLAP_CONF_UNKNOWN:
668 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
669 "unknown directive <%s> inside backend info definition"
670 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
671 c->log, *c->argv, 0);
672 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
674 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
681 } else if ( c->be ) {
682 rc = SLAP_CONF_UNKNOWN;
683 if ( c->be->be_cf_ocs ) {
684 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
686 rc = config_add_vals( ct, c );
689 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
690 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
695 case SLAP_CONF_UNKNOWN:
696 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
697 "unknown directive <%s> inside backend database "
698 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
699 c->log, *c->argv, 0);
700 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
702 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
709 } else if ( frontendDB->be_config ) {
710 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
713 case SLAP_CONF_UNKNOWN:
714 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
715 "unknown directive <%s> inside global database definition"
716 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
717 c->log, *c->argv, 0);
718 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
720 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
728 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
729 "unknown directive <%s> outside backend info and database definitions"
730 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
731 c->log, *c->argv, 0);
732 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
735 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
737 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
751 /* restrictops, allows, disallows, requires, loglevel */
754 verb_to_mask(const char *word, slap_verbmasks *v) {
756 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
757 if(!strcasecmp(word, v[i].word.bv_val))
763 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
765 for(i = 1; i < argc; i++) {
766 j = verb_to_mask(argv[i], v);
767 if(BER_BVISNULL(&v[j].word)) return(1);
768 while (!v[j].mask) j--;
774 /* Mask keywords that represent multiple bits should occur before single
775 * bit keywords in the verbmasks array.
778 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
782 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
783 if (!v[i].mask) continue;
784 if (( m & v[i].mask ) == v[i].mask ) {
785 value_add_one( bva, &v[i].word );
794 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
797 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
798 if ( m == v[i].mask ) {
808 static slap_verbmasks tlskey[] = {
809 { BER_BVC("no"), SB_TLS_OFF },
810 { BER_BVC("yes"), SB_TLS_ON },
811 { BER_BVC("critical"), SB_TLS_CRITICAL },
815 static slap_verbmasks methkey[] = {
816 { BER_BVC("none"), LDAP_AUTH_NONE },
817 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
818 #ifdef HAVE_CYRUS_SASL
819 { BER_BVC("sasl"), LDAP_AUTH_SASL },
824 typedef struct cf_aux_table {
832 static cf_aux_table bindkey[] = {
833 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
834 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
835 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
836 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
837 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
838 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
839 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
840 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
841 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
842 { BER_BVNULL, 0, 0, 0, NULL }
845 int bindconf_parse( const char *word, slap_bindconf *bc ) {
849 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
850 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
854 const char *val = word + tab->key.bv_len;
856 switch ( tab->type ) {
858 cptr = (char **)((char *)bc + tab->off);
859 *cptr = ch_strdup( val );
863 bptr = (struct berval *)((char *)bc + tab->off);
864 ber_str2bv( val, 0, 1, bptr );
869 iptr = (int *)((char *)bc + tab->off);
872 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
873 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
874 *iptr = tab->aux[j].mask;
882 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
893 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
894 char buf[BUFSIZ], *ptr;
899 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
904 cptr = (char **)((char *)bc + tab->off);
906 switch ( tab->type ) {
908 bptr = (struct berval *)((char *)bc + tab->off);
909 cptr = &bptr->bv_val;
913 ptr = lutil_strcopy( ptr, tab->key.bv_val );
914 if ( tab->quote ) *ptr++ = '"';
915 ptr = lutil_strcopy( ptr, *cptr );
916 if ( tab->quote ) *ptr++ = '"';
922 iptr = (int *)((char *)bc + tab->off);
924 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
925 if ( *iptr == tab->aux[i].mask ) {
927 ptr = lutil_strcopy( ptr, tab->key.bv_val );
928 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
936 tmp.bv_len = ptr - buf;
937 ber_dupbv( bv, &tmp );
941 void bindconf_free( slap_bindconf *bc ) {
942 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
943 ch_free( bc->sb_binddn.bv_val );
944 BER_BVZERO( &bc->sb_binddn );
946 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
947 ch_free( bc->sb_cred.bv_val );
948 BER_BVZERO( &bc->sb_cred );
950 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
951 ch_free( bc->sb_saslmech.bv_val );
952 BER_BVZERO( &bc->sb_saslmech );
954 if ( bc->sb_secprops ) {
955 ch_free( bc->sb_secprops );
956 bc->sb_secprops = NULL;
958 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
959 ch_free( bc->sb_realm.bv_val );
960 BER_BVZERO( &bc->sb_realm );
962 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
963 ch_free( bc->sb_authcId.bv_val );
964 BER_BVZERO( &bc->sb_authcId );
966 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
967 ch_free( bc->sb_authzId.bv_val );
968 BER_BVZERO( &bc->sb_authzId );
973 /* -------------------------------------- */
977 strtok_quote( char *line, char *sep, char **quote_ptr )
984 if ( line != NULL ) {
987 while ( *next && strchr( sep, *next ) ) {
991 if ( *next == '\0' ) {
997 for ( inquote = 0; *next; ) {
1005 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1011 next + 1, strlen( next + 1 ) + 1 );
1012 next++; /* dont parse the escaped character */
1017 if ( strchr( sep, *next ) != NULL ) {
1031 static char buf[BUFSIZ];
1033 static size_t lmax, lcur;
1035 #define CATLINE( buf ) \
1037 size_t len = strlen( buf ); \
1038 while ( lcur + len + 1 > lmax ) { \
1040 line = (char *) ch_realloc( line, lmax ); \
1042 strcpy( line + lcur, buf ); \
1047 fp_getline_init(ConfigArgs *c) {
1053 fp_getline( FILE *fp, ConfigArgs *c )
1061 /* avoid stack of bufs */
1062 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1068 while ( fgets( buf, sizeof( buf ), fp ) ) {
1069 p = strchr( buf, '\n' );
1071 if ( p > buf && p[-1] == '\r' ) {
1079 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1086 if ( !isspace( (unsigned char)buf[0] ) ) {
1097 return(line[0] ? 1 : 0);
1101 fp_parse_line(ConfigArgs *c)
1104 static char *const hide[] = {
1105 "rootpw", "replica", "syncrepl", /* in slapd */
1106 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1107 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1108 "pseudorootpw", /* in back-meta */
1109 "dbpasswd", /* in back-sql */
1113 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1115 c->tline = ch_strdup(c->line);
1116 token = strtok_quote(c->tline, " \t", "e_ptr);
1118 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1119 if(quote_ptr) *quote_ptr = ' ';
1120 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
1121 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1122 if(quote_ptr) *quote_ptr = '\0';
1124 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1125 if(c->argc >= c->argv_size) {
1127 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1129 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1133 c->argv_size += ARGS_STEP;
1137 c->argv[c->argc++] = token;
1139 c->argv[c->argc] = NULL;
1146 ucdata_unload( UCDATA_ALL );
1148 /* NOTE: in case of early exit, frontendDB can be NULL */
1149 if ( frontendDB->be_schemandn.bv_val )
1150 free( frontendDB->be_schemandn.bv_val );
1151 if ( frontendDB->be_schemadn.bv_val )
1152 free( frontendDB->be_schemadn.bv_val );
1153 if ( frontendDB->be_acl )
1154 acl_destroy( frontendDB->be_acl, NULL );
1157 if ( slapd_args_file )
1158 free ( slapd_args_file );
1159 if ( slapd_pid_file )
1160 free ( slapd_pid_file );
1161 if ( default_passwd_hash )
1162 ldap_charray_free( default_passwd_hash );
1166 slap_str2clist( char ***out, char *in, const char *brkstr )
1174 /* find last element in list */
1175 for (i = 0; *out && (*out)[i]; i++);
1177 /* protect the input string from strtok */
1178 str = ch_strdup( in );
1180 if ( *str == '\0' ) {
1185 /* Count words in string */
1187 for ( s = str; *s; s++ ) {
1188 if ( strchr( brkstr, *s ) != NULL ) {
1193 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1195 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1197 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1199 *new = ch_strdup( s );
1208 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1209 int argc, char **argv )
1211 ConfigArgs c = { 0 };
1221 sprintf( c.log, "%s: line %d", fname, lineno );
1223 rc = SLAP_CONF_UNKNOWN;
1224 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1226 rc = config_add_vals( ct, &c );