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 char *ignored = " ignored";
141 sprintf( c->msg, "<%s> extra cruft after <%s>",
142 c->argv[0], Conf->what );
146 #endif /* LDAP_DEVEL */
147 Debug(LDAP_DEBUG_CONFIG, "%s: %s%s.\n",
148 c->log, c->msg, ignored );
150 return(ARG_BAD_CONF);
151 #endif /* LDAP_DEVEL */
153 if((arg_type & ARG_DB) && !c->be) {
154 sprintf( c->msg, "<%s> only allowed within database declaration",
156 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
158 return(ARG_BAD_CONF);
160 if((arg_type & ARG_PRE_BI) && c->bi) {
161 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
162 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
163 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
165 return(ARG_BAD_CONF);
167 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
168 sprintf( c->msg, "<%s> must occur before any database declaration",
170 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
172 return(ARG_BAD_CONF);
174 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
175 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
176 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
178 return(ARG_BAD_CONF);
180 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
181 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
183 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
185 return(ARG_BAD_CONF);
187 c->type = arg_user = (arg_type & ARGS_USERLAND);
188 memset(&c->values, 0, sizeof(c->values));
189 if(arg_type & ARGS_NUMERIC) {
191 iarg = 0; larg = 0; barg = 0;
192 switch(arg_type & ARGS_NUMERIC) {
193 case ARG_INT: iarg = atoi(c->argv[1]); break;
194 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
195 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
199 } else if(!strcasecmp(c->argv[1], "on") ||
200 !strcasecmp(c->argv[1], "true")) {
202 } else if(!strcasecmp(c->argv[1], "off") ||
203 !strcasecmp(c->argv[1], "false")) {
206 sprintf( c->msg, "<%s> invalid value, ignored",
208 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
214 j = (arg_type & ARG_NONZERO) ? 1 : 0;
215 if(iarg < j && larg < j && barg < j ) {
216 larg = larg ? larg : (barg ? barg : iarg);
217 sprintf( c->msg, "<%s> invalid value, ignored",
219 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
221 return(ARG_BAD_CONF);
223 switch(arg_type & ARGS_NUMERIC) {
225 case ARG_INT: c->value_int = iarg; break;
226 case ARG_LONG: c->value_long = larg; break;
227 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
229 } else if(arg_type & ARG_STRING) {
231 c->value_string = ch_strdup(c->argv[1]);
232 } else if(arg_type & ARG_BERVAL) {
234 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
235 } else if(arg_type & ARG_DN) {
237 ber_str2bv( c->argv[1], 0, 0, &bv );
238 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
239 if ( rc != LDAP_SUCCESS ) {
240 sprintf( c->msg, "<%s> invalid DN %d (%s)",
241 c->argv[0], rc, ldap_err2string( rc ));
242 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
243 return(ARG_BAD_CONF);
246 ch_free( c->value_ndn.bv_val );
247 ch_free( c->value_dn.bv_val );
253 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
257 arg_type = Conf->arg_type;
258 if(arg_type & ARG_MAGIC) {
259 if(!c->be) c->be = frontendDB;
261 rc = (*((ConfigDriver*)Conf->arg_item))(c);
263 if(c->be == frontendDB) c->be = NULL;
267 sprintf( c->msg, "<%s> handler exited with %d",
269 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
272 return(ARG_BAD_CONF);
276 if(arg_type & ARG_OFFSET) {
278 ptr = c->be->be_private;
280 ptr = c->bi->bi_private;
282 sprintf( c->msg, "<%s> offset is missing base pointer",
284 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
286 return(ARG_BAD_CONF);
288 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
289 } else if (arg_type & ARGS_POINTER) {
290 ptr = Conf->arg_item;
292 if(arg_type & ARGS_POINTER)
293 switch(arg_type & ARGS_POINTER) {
295 case ARG_INT: *(int*)ptr = c->value_int; break;
296 case ARG_LONG: *(long*)ptr = c->value_long; break;
297 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
299 char *cc = *(char**)ptr;
301 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
302 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
303 c->log, Conf->name, 0 );
304 return(ARG_BAD_CONF);
308 *(char **)ptr = c->value_string;
312 *(struct berval *)ptr = c->value_bv;
318 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
321 arg_type = Conf->arg_type;
322 if(arg_type == ARG_IGNORED) {
323 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
324 c->log, Conf->name, 0);
327 rc = config_check_vals( Conf, c, 0 );
329 return config_set_vals( Conf, c );
333 config_del_vals(ConfigTable *cf, ConfigArgs *c)
337 /* If there is no handler, just ignore it */
338 if ( cf->arg_type & ARG_MAGIC ) {
339 c->op = LDAP_MOD_DELETE;
340 c->type = cf->arg_type & ARGS_USERLAND;
341 rc = (*((ConfigDriver*)cf->arg_item))(c);
347 config_get_vals(ConfigTable *cf, ConfigArgs *c)
353 if ( cf->arg_type & ARG_IGNORED ) {
357 memset(&c->values, 0, sizeof(c->values));
358 c->rvalue_vals = NULL;
359 c->rvalue_nvals = NULL;
360 c->op = SLAP_CONFIG_EMIT;
361 c->type = cf->arg_type & ARGS_USERLAND;
363 if ( cf->arg_type & ARG_MAGIC ) {
364 rc = (*((ConfigDriver*)cf->arg_item))(c);
367 if ( cf->arg_type & ARG_OFFSET ) {
369 ptr = c->be->be_private;
371 ptr = c->bi->bi_private;
374 ptr = (void *)((char *)ptr + (int)cf->arg_item);
379 switch(cf->arg_type & ARGS_POINTER) {
381 case ARG_INT: c->value_int = *(int *)ptr; break;
382 case ARG_LONG: c->value_long = *(long *)ptr; break;
383 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
386 c->value_string = ch_strdup(*(char **)ptr);
389 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
392 if ( cf->arg_type & ARGS_POINTER) {
394 switch(cf->arg_type & ARGS_POINTER) {
395 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
396 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
397 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
398 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
399 c->value_int ? "TRUE" : "FALSE"); break;
401 if ( c->value_string && c->value_string[0]) {
402 ber_str2bv( c->value_string, 0, 0, &bv);
408 if ( !BER_BVISEMPTY( &c->value_bv )) {
415 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
416 ber_bvarray_add(&c->rvalue_vals, &bv);
418 value_add_one(&c->rvalue_vals, &bv);
424 init_config_attrs(ConfigTable *ct) {
425 LDAPAttributeType *at;
429 for (i=0; ct[i].name; i++ ) {
432 if ( !ct[i].attribute ) continue;
433 at = ldap_str2attributetype( ct[i].attribute,
434 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
436 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
437 ct[i].attribute, ldap_scherr2str(code), err );
441 code = at_add( at, 0, NULL, &err );
443 if ( code == SLAP_SCHERR_ATTR_DUP ) {
447 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
448 ct[i].attribute, scherr2str(code), err );
452 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
454 ldap_attributetype_free( at );
459 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
460 ct[i].attribute, err );
469 init_config_ocs( ConfigOCs *ocs ) {
472 for (i=0;ocs[i].co_def;i++) {
477 oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
478 LDAP_SCHEMA_ALLOW_ALL );
480 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
481 ocs[i].co_def, ldap_scherr2str(code), err );
484 code = oc_add(oc,0,NULL,&err);
485 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
486 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
487 ocs[i].co_def, scherr2str(code), err );
490 ocs[i].co_oc = oc_find(oc->oc_names[0]);
497 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
500 char *saveline = NULL;
502 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
503 ct->ad->ad_cname.bv_val, valx );
505 c->argv[0] = ct->ad->ad_cname.bv_val;
507 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
511 len = strlen( c->line );
512 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
513 sprintf( c->line, "\"%s\"", saveline );
516 if ( fp_parse_line( c ) ) {
519 rc = config_check_vals( ct, c, 1 );
528 rc = LDAP_CONSTRAINT_VIOLATION;
535 config_parse_add(ConfigTable *ct, ConfigArgs *c)
538 char *saveline = NULL;
540 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
541 ct->ad->ad_cname.bv_val, c->valx );
543 c->argv[0] = ct->ad->ad_cname.bv_val;
545 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
549 len = strlen( c->line );
551 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
552 sprintf( c->line, "\"%s\"", saveline );
555 if ( fp_parse_line( c ) ) {
558 c->op = LDAP_MOD_ADD;
559 rc = config_add_vals( ct, c );
572 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
580 c = ch_calloc( 1, sizeof( ConfigArgs ) );
586 memcpy( c, cf, sizeof( ConfigArgs ) );
588 c->depth = depth; /* XXX */
595 init_config_argv( c );
597 if ( stat( fname, &s ) != 0 ) {
599 Debug(LDAP_DEBUG_ANY,
600 "could not stat config file \"%s\": %s (%d)\n",
601 fname, strerror(errno), errno);
605 if ( !S_ISREG( s.st_mode ) ) {
607 Debug(LDAP_DEBUG_ANY,
608 "regular file expected, got \"%s\"\n",
613 fp = fopen( fname, "r" );
616 Debug(LDAP_DEBUG_ANY,
617 "could not open config file \"%s\": %s (%d)\n",
618 fname, strerror(errno), errno);
622 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
628 while ( fp_getline( fp, c ) ) {
629 /* skip comments and blank lines */
630 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
634 snprintf( c->log, sizeof( c->log ), "%s: line %d",
635 c->fname, c->lineno );
639 if ( fp_parse_line( c ) ) {
645 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line"
646 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
648 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
651 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
653 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
656 c->op = SLAP_CONFIG_ADD;
658 ct = config_find_keyword( cft, c );
660 rc = config_add_vals( ct, c );
663 if ( rc & ARGS_USERLAND ) {
664 /* XXX a usertype would be opaque here */
665 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
666 c->log, c->argv[0], 0);
670 } else if ( rc == ARG_BAD_CONF ) {
675 } else if ( c->bi && !c->be ) {
676 rc = SLAP_CONF_UNKNOWN;
677 if ( c->bi->bi_cf_ocs ) {
678 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
680 rc = config_add_vals( ct, c );
683 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
684 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
689 case SLAP_CONF_UNKNOWN:
690 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
691 "unknown directive <%s> inside backend info definition"
692 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
693 c->log, *c->argv, 0);
694 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
696 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
703 } else if ( c->be ) {
704 rc = SLAP_CONF_UNKNOWN;
705 if ( c->be->be_cf_ocs ) {
706 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
708 rc = config_add_vals( ct, c );
711 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
712 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
717 case SLAP_CONF_UNKNOWN:
718 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
719 "unknown directive <%s> inside backend database "
720 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
721 c->log, *c->argv, 0);
722 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
724 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
731 } else if ( frontendDB->be_config ) {
732 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
735 case SLAP_CONF_UNKNOWN:
736 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
737 "unknown directive <%s> inside global database definition"
738 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
739 c->log, *c->argv, 0);
740 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
742 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
750 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
751 "unknown directive <%s> outside backend info and database definitions"
752 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
753 c->log, *c->argv, 0);
754 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
757 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
759 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
773 /* restrictops, allows, disallows, requires, loglevel */
776 verb_to_mask(const char *word, slap_verbmasks *v) {
778 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
779 if(!strcasecmp(word, v[i].word.bv_val))
785 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
787 for(i = 1; i < argc; i++) {
788 j = verb_to_mask(argv[i], v);
789 if(BER_BVISNULL(&v[j].word)) return(1);
790 while (!v[j].mask) j--;
796 /* Mask keywords that represent multiple bits should occur before single
797 * bit keywords in the verbmasks array.
800 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
804 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
805 if (!v[i].mask) continue;
806 if (( m & v[i].mask ) == v[i].mask ) {
807 value_add_one( bva, &v[i].word );
816 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
820 assert( *vp == NULL );
822 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ )
825 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
827 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
828 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
829 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
832 BER_BVZERO( &(*vp)[ i ].word );
838 slap_verbmasks_destroy( slap_verbmasks *v )
844 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
845 ch_free( v[ i ].word.bv_val );
854 slap_verbmasks_append(
858 slap_mask_t *ignore )
863 return LDAP_OPERATIONS_ERROR;
866 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
867 if ( !(*vp)[ i ].mask ) continue;
869 if ( ignore != NULL ) {
872 for ( j = 0; ignore[ j ] != 0; j++ ) {
873 if ( (*vp)[ i ].mask == ignore[ j ] ) {
879 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
880 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
881 /* already set; ignore */
885 return LDAP_TYPE_OR_VALUE_EXISTS;
888 if ( m & (*vp)[ i ].mask ) {
890 return LDAP_CONSTRAINT_VIOLATION;
895 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
896 ber_dupbv( &(*vp)[ i ].word, v );
897 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
898 BER_BVZERO( &(*vp)[ i + 1 ].word );
904 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
907 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
908 if ( m == v[i].mask ) {
918 static slap_verbmasks tlskey[] = {
919 { BER_BVC("no"), SB_TLS_OFF },
920 { BER_BVC("yes"), SB_TLS_ON },
921 { BER_BVC("critical"), SB_TLS_CRITICAL },
925 static slap_verbmasks methkey[] = {
926 { BER_BVC("none"), LDAP_AUTH_NONE },
927 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
928 #ifdef HAVE_CYRUS_SASL
929 { BER_BVC("sasl"), LDAP_AUTH_SASL },
934 typedef struct cf_aux_table {
942 static cf_aux_table bindkey[] = {
943 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
944 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
945 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
946 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
947 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
948 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
949 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
950 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
951 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
952 { BER_BVNULL, 0, 0, 0, NULL }
955 int bindconf_parse( const char *word, slap_bindconf *bc ) {
959 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
960 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
964 const char *val = word + tab->key.bv_len;
966 switch ( tab->type ) {
968 cptr = (char **)((char *)bc + tab->off);
969 *cptr = ch_strdup( val );
973 bptr = (struct berval *)((char *)bc + tab->off);
974 ber_str2bv( val, 0, 1, bptr );
978 assert( tab->aux != NULL );
979 iptr = (int *)((char *)bc + tab->off);
982 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
983 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
984 *iptr = tab->aux[j].mask;
992 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
1003 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
1004 char buf[BUFSIZ], *ptr;
1009 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
1012 struct berval *bptr;
1014 cptr = (char **)((char *)bc + tab->off);
1016 switch ( tab->type ) {
1018 bptr = (struct berval *)((char *)bc + tab->off);
1019 cptr = &bptr->bv_val;
1023 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1024 if ( tab->quote ) *ptr++ = '"';
1025 ptr = lutil_strcopy( ptr, *cptr );
1026 if ( tab->quote ) *ptr++ = '"';
1031 assert( tab->aux != NULL );
1032 iptr = (int *)((char *)bc + tab->off);
1034 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
1035 if ( *iptr == tab->aux[i].mask ) {
1037 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1038 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
1046 tmp.bv_len = ptr - buf;
1047 ber_dupbv( bv, &tmp );
1051 void bindconf_free( slap_bindconf *bc ) {
1052 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1053 ch_free( bc->sb_binddn.bv_val );
1054 BER_BVZERO( &bc->sb_binddn );
1056 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1057 ch_free( bc->sb_cred.bv_val );
1058 BER_BVZERO( &bc->sb_cred );
1060 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1061 ch_free( bc->sb_saslmech.bv_val );
1062 BER_BVZERO( &bc->sb_saslmech );
1064 if ( bc->sb_secprops ) {
1065 ch_free( bc->sb_secprops );
1066 bc->sb_secprops = NULL;
1068 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1069 ch_free( bc->sb_realm.bv_val );
1070 BER_BVZERO( &bc->sb_realm );
1072 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1073 ch_free( bc->sb_authcId.bv_val );
1074 BER_BVZERO( &bc->sb_authcId );
1076 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1077 ch_free( bc->sb_authzId.bv_val );
1078 BER_BVZERO( &bc->sb_authzId );
1083 /* -------------------------------------- */
1087 strtok_quote( char *line, char *sep, char **quote_ptr )
1094 if ( line != NULL ) {
1097 while ( *next && strchr( sep, *next ) ) {
1101 if ( *next == '\0' ) {
1107 for ( inquote = 0; *next; ) {
1115 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1121 next + 1, strlen( next + 1 ) + 1 );
1122 next++; /* dont parse the escaped character */
1127 if ( strchr( sep, *next ) != NULL ) {
1141 static char buf[BUFSIZ];
1143 static size_t lmax, lcur;
1145 #define CATLINE( buf ) \
1147 size_t len = strlen( buf ); \
1148 while ( lcur + len + 1 > lmax ) { \
1150 line = (char *) ch_realloc( line, lmax ); \
1152 strcpy( line + lcur, buf ); \
1157 fp_getline_init(ConfigArgs *c) {
1163 fp_getline( FILE *fp, ConfigArgs *c )
1171 /* avoid stack of bufs */
1172 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1178 while ( fgets( buf, sizeof( buf ), fp ) ) {
1179 p = strchr( buf, '\n' );
1181 if ( p > buf && p[-1] == '\r' ) {
1189 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1196 if ( !isspace( (unsigned char)buf[0] ) ) {
1207 return(line[0] ? 1 : 0);
1211 fp_parse_line(ConfigArgs *c)
1214 static char *const hide[] = {
1215 "rootpw", "replica", "syncrepl", /* in slapd */
1216 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1217 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1218 "pseudorootpw", /* in back-meta */
1219 "dbpasswd", /* in back-sql */
1223 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1225 c->tline = ch_strdup(c->line);
1226 token = strtok_quote(c->tline, " \t", "e_ptr);
1228 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1229 if(quote_ptr) *quote_ptr = ' ';
1230 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1231 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1232 if(quote_ptr) *quote_ptr = '\0';
1234 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1235 if(c->argc >= c->argv_size) {
1237 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1239 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1243 c->argv_size += ARGS_STEP;
1247 c->argv[c->argc++] = token;
1249 c->argv[c->argc] = NULL;
1256 ucdata_unload( UCDATA_ALL );
1258 /* NOTE: in case of early exit, frontendDB can be NULL */
1259 if ( frontendDB->be_schemandn.bv_val )
1260 free( frontendDB->be_schemandn.bv_val );
1261 if ( frontendDB->be_schemadn.bv_val )
1262 free( frontendDB->be_schemadn.bv_val );
1263 if ( frontendDB->be_acl )
1264 acl_destroy( frontendDB->be_acl, NULL );
1267 if ( slapd_args_file )
1268 free ( slapd_args_file );
1269 if ( slapd_pid_file )
1270 free ( slapd_pid_file );
1271 if ( default_passwd_hash )
1272 ldap_charray_free( default_passwd_hash );
1276 slap_str2clist( char ***out, char *in, const char *brkstr )
1284 /* find last element in list */
1285 for (i = 0; *out && (*out)[i]; i++);
1287 /* protect the input string from strtok */
1288 str = ch_strdup( in );
1290 if ( *str == '\0' ) {
1295 /* Count words in string */
1297 for ( s = str; *s; s++ ) {
1298 if ( strchr( brkstr, *s ) != NULL ) {
1303 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1305 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1307 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1309 *new = ch_strdup( s );
1318 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1319 int argc, char **argv )
1321 ConfigArgs c = { 0 };
1331 sprintf( c.log, "%s: line %d", fname, lineno );
1333 rc = SLAP_CONF_UNKNOWN;
1334 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1336 rc = config_add_vals( ct, &c );