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>
39 #include "slapi/slapi.h"
47 * defaults for various global variables
49 slap_mask_t global_allows = 0;
50 slap_mask_t global_disallows = 0;
51 int global_gentlehup = 0;
52 int global_idletimeout = 0;
53 char *global_host = NULL;
54 char *global_realm = NULL;
55 char *ldap_srvtab = "";
56 char **default_passwd_hash = NULL;
57 struct berval default_search_base = BER_BVNULL;
58 struct berval default_search_nbase = BER_BVNULL;
60 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
61 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
63 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
64 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
66 char *slapd_pid_file = NULL;
67 char *slapd_args_file = NULL;
69 int use_reverse_lookup = 0;
72 int slapi_plugins_used = 0;
75 static int fp_getline(FILE *fp, ConfigArgs *c);
76 static void fp_getline_init(ConfigArgs *c);
77 static int fp_parse_line(ConfigArgs *c);
79 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
81 int read_config_file(const char *fname, int depth, ConfigArgs *cf,
85 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
88 c = ch_calloc( 1, sizeof( ConfigArgs ) );
89 if ( c == NULL ) return(NULL);
95 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
100 init_config_argv( ConfigArgs *c )
102 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
103 c->argv_size = ARGS_STEP + 1;
106 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
109 for(i = 0; Conf[i].name; i++)
110 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
111 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
112 if ( !Conf[i].name ) return NULL;
116 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
117 int rc, arg_user, arg_type, iarg;
121 arg_type = Conf->arg_type;
122 if(arg_type == ARG_IGNORED) {
123 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
124 c->log, Conf->name, 0);
127 if((arg_type & ARG_DN) && c->argc == 1) {
131 if(Conf->min_args && (c->argc < Conf->min_args)) {
132 sprintf( c->msg, "<%s> missing <%s> argument",
133 c->argv[0], Conf->what );
134 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
135 return(ARG_BAD_CONF);
137 if(Conf->max_args && (c->argc > Conf->max_args)) {
138 sprintf( c->msg, "<%s> extra cruft after <%s> ignored",
139 c->argv[0], Conf->what );
140 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
142 if((arg_type & ARG_DB) && !c->be) {
143 sprintf( c->msg, "<%s> only allowed within database declaration",
145 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
147 return(ARG_BAD_CONF);
149 if((arg_type & ARG_PRE_BI) && c->bi) {
150 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
151 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
152 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
154 return(ARG_BAD_CONF);
156 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
157 sprintf( c->msg, "<%s> must occur before any database declaration",
159 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
161 return(ARG_BAD_CONF);
163 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
164 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
165 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
167 return(ARG_BAD_CONF);
169 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
170 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
172 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
174 return(ARG_BAD_CONF);
176 c->type = arg_user = (arg_type & ARGS_USERLAND);
177 memset(&c->values, 0, sizeof(c->values));
178 if(arg_type & ARGS_NUMERIC) {
180 iarg = 0; larg = 0; barg = 0;
181 switch(arg_type & ARGS_NUMERIC) {
182 case ARG_INT: iarg = atoi(c->argv[1]); break;
183 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
184 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
188 } else if(!strcasecmp(c->argv[1], "on") ||
189 !strcasecmp(c->argv[1], "true")) {
191 } else if(!strcasecmp(c->argv[1], "off") ||
192 !strcasecmp(c->argv[1], "false")) {
195 sprintf( c->msg, "<%s> invalid value, ignored",
197 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
203 j = (arg_type & ARG_NONZERO) ? 1 : 0;
204 if(iarg < j && larg < j && barg < j ) {
205 larg = larg ? larg : (barg ? barg : iarg);
206 sprintf( c->msg, "<%s> invalid value, ignored",
208 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
210 return(ARG_BAD_CONF);
212 switch(arg_type & ARGS_NUMERIC) {
214 case ARG_INT: c->value_int = iarg; break;
215 case ARG_LONG: c->value_long = larg; break;
216 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
218 } else if(arg_type & ARG_STRING) {
220 c->value_string = ch_strdup(c->argv[1]);
221 } else if(arg_type & ARG_BERVAL) {
223 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
224 } else if(arg_type & ARG_DN) {
226 ber_str2bv( c->argv[1], 0, 0, &bv );
227 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
228 if ( rc != LDAP_SUCCESS ) {
229 sprintf( c->msg, "<%s> invalid DN %d (%s)",
230 c->argv[0], rc, ldap_err2string( rc ));
231 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
232 return(ARG_BAD_CONF);
235 ch_free( c->value_ndn.bv_val );
236 ch_free( c->value_dn.bv_val );
242 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
246 arg_type = Conf->arg_type;
247 if(arg_type & ARG_MAGIC) {
248 if(!c->be) c->be = frontendDB;
250 rc = (*((ConfigDriver*)Conf->arg_item))(c);
252 if(c->be == frontendDB) c->be = NULL;
256 sprintf( c->msg, "<%s> handler exited with %d",
258 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
261 return(ARG_BAD_CONF);
265 if(arg_type & ARG_OFFSET) {
267 ptr = c->be->be_private;
269 ptr = c->bi->bi_private;
271 sprintf( c->msg, "<%s> offset is missing base pointer",
273 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
275 return(ARG_BAD_CONF);
277 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
278 } else if (arg_type & ARGS_POINTER) {
279 ptr = Conf->arg_item;
281 if(arg_type & ARGS_POINTER)
282 switch(arg_type & ARGS_POINTER) {
284 case ARG_INT: *(int*)ptr = c->value_int; break;
285 case ARG_LONG: *(long*)ptr = c->value_long; break;
286 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
288 char *cc = *(char**)ptr;
290 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
291 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
292 c->log, Conf->name, 0 );
293 return(ARG_BAD_CONF);
297 *(char **)ptr = c->value_string;
301 *(struct berval *)ptr = c->value_bv;
307 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
310 arg_type = Conf->arg_type;
311 if(arg_type == ARG_IGNORED) {
312 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
313 c->log, Conf->name, 0);
316 rc = config_check_vals( Conf, c, 0 );
318 return config_set_vals( Conf, c );
322 config_del_vals(ConfigTable *cf, ConfigArgs *c)
326 /* If there is no handler, just ignore it */
327 if ( cf->arg_type & ARG_MAGIC ) {
328 c->op = LDAP_MOD_DELETE;
329 c->type = cf->arg_type & ARGS_USERLAND;
330 rc = (*((ConfigDriver*)cf->arg_item))(c);
336 config_get_vals(ConfigTable *cf, ConfigArgs *c)
342 if ( cf->arg_type & ARG_IGNORED ) {
346 memset(&c->values, 0, sizeof(c->values));
347 c->rvalue_vals = NULL;
348 c->rvalue_nvals = NULL;
349 c->op = SLAP_CONFIG_EMIT;
350 c->type = cf->arg_type & ARGS_USERLAND;
352 if ( cf->arg_type & ARG_MAGIC ) {
353 rc = (*((ConfigDriver*)cf->arg_item))(c);
356 if ( cf->arg_type & ARG_OFFSET ) {
358 ptr = c->be->be_private;
360 ptr = c->bi->bi_private;
363 ptr = (void *)((char *)ptr + (int)cf->arg_item);
368 switch(cf->arg_type & ARGS_POINTER) {
370 case ARG_INT: c->value_int = *(int *)ptr; break;
371 case ARG_LONG: c->value_long = *(long *)ptr; break;
372 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
375 c->value_string = ch_strdup(*(char **)ptr);
378 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
381 if ( cf->arg_type & ARGS_POINTER) {
383 switch(cf->arg_type & ARGS_POINTER) {
384 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
385 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
386 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
387 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
388 c->value_int ? "TRUE" : "FALSE"); break;
390 if ( c->value_string && c->value_string[0]) {
391 ber_str2bv( c->value_string, 0, 0, &bv);
397 if ( !BER_BVISEMPTY( &c->value_bv )) {
404 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
405 ber_bvarray_add(&c->rvalue_vals, &bv);
407 value_add_one(&c->rvalue_vals, &bv);
413 init_config_attrs(ConfigTable *ct) {
414 LDAPAttributeType *at;
418 for (i=0; ct[i].name; i++ ) {
419 if ( !ct[i].attribute ) continue;
420 at = ldap_str2attributetype( ct[i].attribute,
421 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
423 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
424 ct[i].attribute, ldap_scherr2str(code), err );
427 code = at_add( at, 0, NULL, &err );
428 if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
429 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
430 ct[i].attribute, scherr2str(code), err );
433 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
435 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
436 ct[i].attribute, err );
446 init_config_ocs( ConfigOCs *ocs ) {
449 for (i=0;ocs[i].co_def;i++) {
454 oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
455 LDAP_SCHEMA_ALLOW_ALL );
457 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
458 ocs[i].co_def, ldap_scherr2str(code), err );
461 code = oc_add(oc,0,NULL,&err);
462 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
463 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
464 ocs[i].co_def, scherr2str(code), err );
467 ocs[i].co_oc = oc_find(oc->oc_names[0]);
474 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
477 char *saveline = NULL;
479 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
480 ct->ad->ad_cname.bv_val, valx );
482 c->argv[0] = ct->ad->ad_cname.bv_val;
484 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
488 len = strlen( c->line );
489 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
490 sprintf( c->line, "\"%s\"", saveline );
493 if ( fp_parse_line( c ) ) {
496 rc = config_check_vals( ct, c, 1 );
505 rc = LDAP_CONSTRAINT_VIOLATION;
512 config_parse_add(ConfigTable *ct, ConfigArgs *c)
515 char *saveline = NULL;
517 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
518 ct->ad->ad_cname.bv_val, c->valx );
520 c->argv[0] = ct->ad->ad_cname.bv_val;
522 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
526 len = strlen( c->line );
528 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
529 sprintf( c->line, "\"%s\"", saveline );
532 if ( fp_parse_line( c ) ) {
535 c->op = LDAP_MOD_ADD;
536 rc = config_add_vals( ct, c );
549 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
556 c = ch_calloc( 1, sizeof( ConfigArgs ) );
562 memcpy( c, cf, sizeof( ConfigArgs ) );
564 c->depth = depth; /* XXX */
571 init_config_argv( c );
573 fp = fopen( fname, "r" );
576 Debug(LDAP_DEBUG_ANY,
577 "could not open config file \"%s\": %s (%d)\n",
578 fname, strerror(errno), errno);
582 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
588 while ( fp_getline( fp, c ) ) {
589 /* skip comments and blank lines */
590 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
594 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
595 c->fname, c->lineno );
599 if ( fp_parse_line( c ) ) {
605 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line"
606 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
608 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
611 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
613 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
616 c->op = SLAP_CONFIG_ADD;
618 ct = config_find_keyword( cft, c );
620 rc = config_add_vals( ct, c );
623 if ( rc & ARGS_USERLAND ) {
624 /* XXX a usertype would be opaque here */
625 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
626 c->log, c->argv[0], 0);
630 } else if ( rc == ARG_BAD_CONF ) {
635 } else if ( c->bi && !c->be ) {
636 rc = SLAP_CONF_UNKNOWN;
637 if ( c->bi->bi_cf_ocs ) {
638 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
640 rc = config_add_vals( ct, c );
643 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
644 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
649 case SLAP_CONF_UNKNOWN:
650 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
651 "unknown directive <%s> inside backend info definition"
652 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
653 c->log, *c->argv, 0);
654 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
656 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
663 } else if ( c->be ) {
664 rc = SLAP_CONF_UNKNOWN;
665 if ( c->be->be_cf_ocs ) {
666 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
668 rc = config_add_vals( ct, c );
671 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
672 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
677 case SLAP_CONF_UNKNOWN:
678 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
679 "unknown directive <%s> inside backend database "
680 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
681 c->log, *c->argv, 0);
682 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
684 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
691 } else if ( frontendDB->be_config ) {
692 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
695 case SLAP_CONF_UNKNOWN:
696 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
697 "unknown directive <%s> inside global database definition"
698 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
699 c->log, *c->argv, 0);
700 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
702 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
710 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
711 "unknown directive <%s> outside backend info and database definitions"
712 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
713 c->log, *c->argv, 0);
714 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
717 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
719 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
733 /* restrictops, allows, disallows, requires, loglevel */
736 verb_to_mask(const char *word, slap_verbmasks *v) {
738 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
739 if(!strcasecmp(word, v[i].word.bv_val))
745 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
747 for(i = 1; i < argc; i++) {
748 j = verb_to_mask(argv[i], v);
749 if(BER_BVISNULL(&v[j].word)) return(1);
750 while (!v[j].mask) j--;
756 /* Mask keywords that represent multiple bits should occur before single
757 * bit keywords in the verbmasks array.
760 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
764 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
765 if (!v[i].mask) continue;
766 if (( m & v[i].mask ) == v[i].mask ) {
767 value_add_one( bva, &v[i].word );
776 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
779 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
780 if ( m == v[i].mask ) {
790 static slap_verbmasks tlskey[] = {
791 { BER_BVC("no"), SB_TLS_OFF },
792 { BER_BVC("yes"), SB_TLS_ON },
793 { BER_BVC("critical"), SB_TLS_CRITICAL },
797 static slap_verbmasks methkey[] = {
798 { BER_BVC("none"), LDAP_AUTH_NONE },
799 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
800 #ifdef HAVE_CYRUS_SASL
801 { BER_BVC("sasl"), LDAP_AUTH_SASL },
806 typedef struct cf_aux_table {
814 static cf_aux_table bindkey[] = {
815 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
816 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
817 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
818 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
819 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
820 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
821 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
822 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
823 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
824 { BER_BVNULL, 0, 0, 0, NULL }
827 int bindconf_parse( const char *word, slap_bindconf *bc ) {
831 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
832 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
836 const char *val = word + tab->key.bv_len;
838 switch ( tab->type ) {
840 cptr = (char **)((char *)bc + tab->off);
841 *cptr = ch_strdup( val );
845 bptr = (struct berval *)((char *)bc + tab->off);
846 ber_str2bv( val, 0, 1, bptr );
851 iptr = (int *)((char *)bc + tab->off);
854 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
855 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
856 *iptr = tab->aux[j].mask;
864 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
875 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
876 char buf[BUFSIZ], *ptr;
881 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
886 cptr = (char **)((char *)bc + tab->off);
888 switch ( tab->type ) {
890 bptr = (struct berval *)((char *)bc + tab->off);
891 cptr = &bptr->bv_val;
895 ptr = lutil_strcopy( ptr, tab->key.bv_val );
896 if ( tab->quote ) *ptr++ = '"';
897 ptr = lutil_strcopy( ptr, *cptr );
898 if ( tab->quote ) *ptr++ = '"';
904 iptr = (int *)((char *)bc + tab->off);
906 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
907 if ( *iptr == tab->aux[i].mask ) {
909 ptr = lutil_strcopy( ptr, tab->key.bv_val );
910 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
918 tmp.bv_len = ptr - buf;
919 ber_dupbv( bv, &tmp );
923 void bindconf_free( slap_bindconf *bc ) {
924 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
925 ch_free( bc->sb_binddn.bv_val );
926 BER_BVZERO( &bc->sb_binddn );
928 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
929 ch_free( bc->sb_cred.bv_val );
930 BER_BVZERO( &bc->sb_cred );
932 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
933 ch_free( bc->sb_saslmech.bv_val );
934 BER_BVZERO( &bc->sb_saslmech );
936 if ( bc->sb_secprops ) {
937 ch_free( bc->sb_secprops );
938 bc->sb_secprops = NULL;
940 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
941 ch_free( bc->sb_realm.bv_val );
942 BER_BVZERO( &bc->sb_realm );
944 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
945 ch_free( bc->sb_authcId.bv_val );
946 BER_BVZERO( &bc->sb_authcId );
948 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
949 ch_free( bc->sb_authzId.bv_val );
950 BER_BVZERO( &bc->sb_authzId );
955 /* -------------------------------------- */
959 strtok_quote( char *line, char *sep, char **quote_ptr )
966 if ( line != NULL ) {
969 while ( *next && strchr( sep, *next ) ) {
973 if ( *next == '\0' ) {
979 for ( inquote = 0; *next; ) {
987 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
993 next + 1, strlen( next + 1 ) + 1 );
994 next++; /* dont parse the escaped character */
999 if ( strchr( sep, *next ) != NULL ) {
1013 static char buf[BUFSIZ];
1015 static size_t lmax, lcur;
1017 #define CATLINE( buf ) \
1019 size_t len = strlen( buf ); \
1020 while ( lcur + len + 1 > lmax ) { \
1022 line = (char *) ch_realloc( line, lmax ); \
1024 strcpy( line + lcur, buf ); \
1029 fp_getline_init(ConfigArgs *c) {
1035 fp_getline( FILE *fp, ConfigArgs *c )
1043 /* avoid stack of bufs */
1044 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1050 while ( fgets( buf, sizeof( buf ), fp ) ) {
1051 p = strchr( buf, '\n' );
1053 if ( p > buf && p[-1] == '\r' ) {
1061 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1068 if ( !isspace( (unsigned char)buf[0] ) ) {
1079 return(line[0] ? 1 : 0);
1083 fp_parse_line(ConfigArgs *c)
1086 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
1090 c->tline = ch_strdup(c->line);
1091 token = strtok_quote(c->tline, " \t", "e_ptr);
1093 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1094 if(quote_ptr) *quote_ptr = ' ';
1095 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
1096 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1097 if(quote_ptr) *quote_ptr = '\0';
1099 for(; token; token = strtok_quote(NULL, " \t", "e_ptr)) {
1100 if(c->argc == c->argv_size - 1) {
1102 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1104 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1108 c->argv_size += ARGS_STEP;
1110 c->argv[c->argc++] = token;
1112 c->argv[c->argc] = NULL;
1119 ucdata_unload( UCDATA_ALL );
1121 /* NOTE: in case of early exit, frontendDB can be NULL */
1122 if ( frontendDB->be_schemandn.bv_val )
1123 free( frontendDB->be_schemandn.bv_val );
1124 if ( frontendDB->be_schemadn.bv_val )
1125 free( frontendDB->be_schemadn.bv_val );
1126 if ( frontendDB->be_acl )
1127 acl_destroy( frontendDB->be_acl, NULL );
1130 if ( slapd_args_file )
1131 free ( slapd_args_file );
1132 if ( slapd_pid_file )
1133 free ( slapd_pid_file );
1134 if ( default_passwd_hash )
1135 ldap_charray_free( default_passwd_hash );
1139 slap_str2clist( char ***out, char *in, const char *brkstr )
1147 /* find last element in list */
1148 for (i = 0; *out && (*out)[i]; i++);
1150 /* protect the input string from strtok */
1151 str = ch_strdup( in );
1153 if ( *str == '\0' ) {
1158 /* Count words in string */
1160 for ( s = str; *s; s++ ) {
1161 if ( strchr( brkstr, *s ) != NULL ) {
1166 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1168 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1170 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1172 *new = ch_strdup( s );
1181 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1182 int argc, char **argv )
1184 ConfigArgs c = { 0 };
1194 sprintf( c.log, "%s: line %lu", fname, lineno );
1196 rc = SLAP_CONF_UNKNOWN;
1197 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1199 rc = config_add_vals( ct, &c );