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 * ITS#3705: bail out if unknown config directives appear in slapd.conf
50 #define SLAPD_CONF_UNKNOWN_BAILOUT
51 #endif /* LDAP_DEVEL */
54 * defaults for various global variables
56 slap_mask_t global_allows = 0;
57 slap_mask_t global_disallows = 0;
58 int global_gentlehup = 0;
59 int global_idletimeout = 0;
60 char *global_host = NULL;
61 char *global_realm = NULL;
62 char *ldap_srvtab = "";
63 char **default_passwd_hash = NULL;
64 struct berval default_search_base = BER_BVNULL;
65 struct berval default_search_nbase = BER_BVNULL;
67 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
68 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
70 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
71 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
73 char *slapd_pid_file = NULL;
74 char *slapd_args_file = NULL;
76 int use_reverse_lookup = 0;
79 int slapi_plugins_used = 0;
82 static int fp_getline(FILE *fp, ConfigArgs *c);
83 static void fp_getline_init(ConfigArgs *c);
84 static int fp_parse_line(ConfigArgs *c);
86 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
88 int read_config_file(const char *fname, int depth, ConfigArgs *cf);
91 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
94 c = ch_calloc( 1, sizeof( ConfigArgs ) );
95 if ( c == NULL ) return(NULL);
101 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
106 init_config_argv( ConfigArgs *c )
108 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
109 c->argv_size = ARGS_STEP + 1;
112 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
115 for(i = 0; Conf[i].name; i++)
116 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
117 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
118 if ( !Conf[i].name ) return NULL;
122 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
123 int rc, arg_user, arg_type, iarg;
127 arg_type = Conf->arg_type;
128 if(arg_type == ARG_IGNORED) {
129 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
130 c->log, Conf->name, 0);
133 if((arg_type & ARG_DN) && c->argc == 1) {
137 if(Conf->min_args && (c->argc < Conf->min_args)) {
138 sprintf( c->msg, "<%s> missing <%s> argument",
139 c->argv[0], Conf->what );
140 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
141 return(ARG_BAD_CONF);
143 if(Conf->max_args && (c->argc > Conf->max_args)) {
144 sprintf( c->msg, "<%s> extra cruft after <%s> ignored",
145 c->argv[0], Conf->what );
146 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
148 if((arg_type & ARG_DB) && !c->be) {
149 sprintf( c->msg, "<%s> only allowed within database declaration",
151 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
153 return(ARG_BAD_CONF);
155 if((arg_type & ARG_PRE_BI) && c->bi) {
156 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
157 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
158 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
160 return(ARG_BAD_CONF);
162 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
163 sprintf( c->msg, "<%s> must occur before any database declaration",
165 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
167 return(ARG_BAD_CONF);
169 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
170 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
171 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
173 return(ARG_BAD_CONF);
175 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
176 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
178 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
180 return(ARG_BAD_CONF);
182 c->type = arg_user = (arg_type & ARGS_USERLAND);
183 memset(&c->values, 0, sizeof(c->values));
184 if(arg_type & ARGS_NUMERIC) {
186 iarg = 0; larg = 0; barg = 0;
187 switch(arg_type & ARGS_NUMERIC) {
188 case ARG_INT: iarg = atoi(c->argv[1]); break;
189 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
190 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
194 } else if(!strcasecmp(c->argv[1], "on") ||
195 !strcasecmp(c->argv[1], "true")) {
197 } else if(!strcasecmp(c->argv[1], "off") ||
198 !strcasecmp(c->argv[1], "false")) {
201 sprintf( c->msg, "<%s> invalid value, ignored",
203 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
209 j = (arg_type & ARG_NONZERO) ? 1 : 0;
210 if(iarg < j && larg < j && barg < j ) {
211 larg = larg ? larg : (barg ? barg : iarg);
212 sprintf( c->msg, "<%s> invalid value, ignored",
214 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
216 return(ARG_BAD_CONF);
218 switch(arg_type & ARGS_NUMERIC) {
220 case ARG_INT: c->value_int = iarg; break;
221 case ARG_LONG: c->value_long = larg; break;
222 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
224 } else if(arg_type & ARG_STRING) {
226 c->value_string = ch_strdup(c->argv[1]);
227 } else if(arg_type & ARG_BERVAL) {
229 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
230 } else if(arg_type & ARG_DN) {
232 ber_str2bv( c->argv[1], 0, 0, &bv );
233 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
234 if ( rc != LDAP_SUCCESS ) {
235 sprintf( c->msg, "<%s> invalid DN %d (%s)",
236 c->argv[0], rc, ldap_err2string( rc ));
237 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
238 return(ARG_BAD_CONF);
241 ch_free( c->value_ndn.bv_val );
242 ch_free( c->value_dn.bv_val );
248 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
252 arg_type = Conf->arg_type;
253 if(arg_type & ARG_MAGIC) {
254 if(!c->be) c->be = frontendDB;
256 rc = (*((ConfigDriver*)Conf->arg_item))(c);
258 if(c->be == frontendDB) c->be = NULL;
262 sprintf( c->msg, "<%s> handler exited with %d",
264 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
267 return(ARG_BAD_CONF);
271 if(arg_type & ARG_OFFSET) {
273 ptr = c->be->be_private;
275 ptr = c->bi->bi_private;
277 sprintf( c->msg, "<%s> offset is missing base pointer",
279 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
281 return(ARG_BAD_CONF);
283 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
284 } else if (arg_type & ARGS_POINTER) {
285 ptr = Conf->arg_item;
287 if(arg_type & ARGS_POINTER)
288 switch(arg_type & ARGS_POINTER) {
290 case ARG_INT: *(int*)ptr = c->value_int; break;
291 case ARG_LONG: *(long*)ptr = c->value_long; break;
292 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
294 char *cc = *(char**)ptr;
296 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
297 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
298 c->log, Conf->name, 0 );
299 return(ARG_BAD_CONF);
303 *(char **)ptr = c->value_string;
307 *(struct berval *)ptr = c->value_bv;
313 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
316 arg_type = Conf->arg_type;
317 if(arg_type == ARG_IGNORED) {
318 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
319 c->log, Conf->name, 0);
322 rc = config_check_vals( Conf, c, 0 );
324 return config_set_vals( Conf, c );
328 config_del_vals(ConfigTable *cf, ConfigArgs *c)
332 /* If there is no handler, just ignore it */
333 if ( cf->arg_type & ARG_MAGIC ) {
334 c->op = LDAP_MOD_DELETE;
335 c->type = cf->arg_type & ARGS_USERLAND;
336 rc = (*((ConfigDriver*)cf->arg_item))(c);
342 config_get_vals(ConfigTable *cf, ConfigArgs *c)
348 if ( cf->arg_type & ARG_IGNORED ) {
352 memset(&c->values, 0, sizeof(c->values));
353 c->rvalue_vals = NULL;
354 c->rvalue_nvals = NULL;
355 c->op = SLAP_CONFIG_EMIT;
356 c->type = cf->arg_type & ARGS_USERLAND;
358 if ( cf->arg_type & ARG_MAGIC ) {
359 rc = (*((ConfigDriver*)cf->arg_item))(c);
362 if ( cf->arg_type & ARG_OFFSET ) {
364 ptr = c->be->be_private;
366 ptr = c->bi->bi_private;
369 ptr = (void *)((char *)ptr + (int)cf->arg_item);
374 switch(cf->arg_type & ARGS_POINTER) {
376 case ARG_INT: c->value_int = *(int *)ptr; break;
377 case ARG_LONG: c->value_long = *(long *)ptr; break;
378 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
381 c->value_string = ch_strdup(*(char **)ptr);
384 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
387 if ( cf->arg_type & ARGS_POINTER) {
389 switch(cf->arg_type & ARGS_POINTER) {
390 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
391 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
392 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
393 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
394 c->value_int ? "TRUE" : "FALSE"); break;
396 if ( c->value_string && c->value_string[0]) {
397 ber_str2bv( c->value_string, 0, 0, &bv);
403 if ( !BER_BVISEMPTY( &c->value_bv )) {
410 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
411 ber_bvarray_add(&c->rvalue_vals, &bv);
413 value_add_one(&c->rvalue_vals, &bv);
419 init_config_attrs(ConfigTable *ct) {
420 LDAPAttributeType *at;
424 for (i=0; ct[i].name; i++ ) {
425 if ( !ct[i].attribute ) continue;
426 at = ldap_str2attributetype( ct[i].attribute,
427 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
429 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
430 ct[i].attribute, ldap_scherr2str(code), err );
433 code = at_add( at, 0, NULL, &err );
434 if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
435 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
436 ct[i].attribute, scherr2str(code), err );
439 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
441 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
442 ct[i].attribute, err );
452 init_config_ocs( ConfigOCs *ocs ) {
455 for (i=0;ocs[i].def;i++) {
460 oc = ldap_str2objectclass( ocs[i].def, &code, &err,
461 LDAP_SCHEMA_ALLOW_ALL );
463 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
464 ocs[i].def, ldap_scherr2str(code), err );
467 code = oc_add(oc,0,NULL,&err);
468 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
469 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
470 ocs[i].def, scherr2str(code), err );
474 *ocs[i].oc = oc_find(oc->oc_names[0]);
482 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
486 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
487 ct->ad->ad_cname.bv_val, valx );
489 c->argv[0] = ct->ad->ad_cname.bv_val;
490 if ( fp_parse_line( c ) ) {
493 rc = config_check_vals( ct, c, 1 );
496 rc = LDAP_CONSTRAINT_VIOLATION;
503 config_parse_add(ConfigTable *ct, ConfigArgs *c)
507 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
508 ct->ad->ad_cname.bv_val, c->valx );
510 c->argv[0] = ct->ad->ad_cname.bv_val;
511 if ( fp_parse_line( c ) ) {
514 c->op = LDAP_MOD_ADD;
515 rc = config_add_vals( ct, c );
523 read_config_file(const char *fname, int depth, ConfigArgs *cf)
530 c = ch_calloc( 1, sizeof( ConfigArgs ) );
536 memcpy( c, cf, sizeof( ConfigArgs ) );
538 c->depth = depth; /* XXX */
545 init_config_argv( c );
547 fp = fopen( fname, "r" );
550 Debug(LDAP_DEBUG_ANY,
551 "could not open config file \"%s\": %s (%d)\n",
552 fname, strerror(errno), errno);
556 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
562 while ( fp_getline( fp, c ) ) {
563 /* skip comments and blank lines */
564 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
568 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
569 c->fname, c->lineno );
573 if ( fp_parse_line( c ) ) {
579 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
583 c->op = SLAP_CONFIG_ADD;
585 ct = config_find_keyword( config_back_cf_table, c );
587 rc = config_add_vals( ct, c );
590 if ( rc & ARGS_USERLAND ) {
591 /* XXX a usertype would be opaque here */
592 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
593 c->log, c->argv[0], 0);
597 } else if ( rc == ARG_BAD_CONF ) {
602 } else if ( c->bi ) {
603 rc = SLAP_CONF_UNKNOWN;
604 if ( c->bi->bi_cf_table ) {
605 ct = config_find_keyword( c->bi->bi_cf_table, c );
607 rc = config_add_vals( ct, c );
610 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
611 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
616 case SLAP_CONF_UNKNOWN:
617 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
618 Debug(LDAP_DEBUG_CONFIG, "%s: "
619 "unknown directive <%s> inside backend info definition\n",
620 c->log, *c->argv, 0);
621 #else /* !SLAPD_CONF_UNKNOWN_BAILOUT */
622 Debug(LDAP_DEBUG_CONFIG, "%s: "
623 "unknown directive <%s> inside backend info definition (ignored)\n",
624 c->log, *c->argv, 0);
626 #endif /* !SLAPD_CONF_UNKNOWN_BAILOUT */
633 } else if ( c->be ) {
634 rc = SLAP_CONF_UNKNOWN;
635 if ( c->be->be_cf_table ) {
636 ct = config_find_keyword( c->be->be_cf_table, c );
638 rc = config_add_vals( ct, c );
641 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
642 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
647 case SLAP_CONF_UNKNOWN:
648 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
649 Debug( LDAP_DEBUG_CONFIG, "%s: "
650 "unknown directive <%s> inside backend database "
652 c->log, *c->argv, 0);
653 #else /* !SLAPD_CONF_UNKNOWN_BAILOUT */
654 Debug( LDAP_DEBUG_CONFIG, "%s: "
655 "unknown directive <%s> inside backend database "
656 "definition (ignored)\n",
657 c->log, *c->argv, 0);
659 #endif /* !SLAPD_CONF_UNKNOWN_BAILOUT */
666 } else if ( frontendDB->be_config ) {
667 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
670 case SLAP_CONF_UNKNOWN:
671 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
672 Debug( LDAP_DEBUG_CONFIG, "%s: "
673 "unknown directive <%s> inside global database definition\n",
674 c->log, *c->argv, 0);
675 #else /* !SLAPD_CONF_UNKNOWN_BAILOUT */
676 Debug( LDAP_DEBUG_CONFIG, "%s: "
677 "unknown directive <%s> inside global database definition (ignored)\n",
678 c->log, *c->argv, 0);
680 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
688 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
689 Debug(LDAP_DEBUG_CONFIG, "%s: "
690 "unknown directive <%s> outside backend info and database definitions\n",
691 c->log, *c->argv, 0);
694 #else /* !SLAPD_CONF_UNKNOWN_BAILOUT */
695 Debug(LDAP_DEBUG_CONFIG, "%s: "
696 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
697 c->log, *c->argv, 0);
699 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
703 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
704 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
705 &frontendDB->be_schemadn );
706 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
707 if ( rc != LDAP_SUCCESS ) {
708 Debug(LDAP_DEBUG_ANY, "%s: "
709 "unable to normalize default schema DN \"%s\"\n",
710 c->log, frontendDB->be_schemadn.bv_val, 0 );
711 /* must not happen */
725 /* restrictops, allows, disallows, requires, loglevel */
728 verb_to_mask(const char *word, slap_verbmasks *v) {
730 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
731 if(!strcasecmp(word, v[i].word.bv_val))
737 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
739 for(i = 1; i < argc; i++) {
740 j = verb_to_mask(argv[i], v);
741 if(BER_BVISNULL(&v[j].word)) return(1);
742 while (!v[j].mask) j--;
749 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
753 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
754 if (!v[i].mask) continue;
755 if (( m & v[i].mask ) == v[i].mask ) {
756 value_add_one( bva, &v[i].word );
762 static slap_verbmasks tlskey[] = {
763 { BER_BVC("no"), SB_TLS_OFF },
764 { BER_BVC("yes"), SB_TLS_ON },
765 { BER_BVC("critical"), SB_TLS_CRITICAL },
769 static slap_verbmasks methkey[] = {
771 { BER_BVC("none"), LDAP_AUTH_NONE },
773 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
774 #ifdef HAVE_CYRUS_SASL
775 { BER_BVC("sasl"), LDAP_AUTH_SASL },
780 typedef struct cf_aux_table {
788 static cf_aux_table bindkey[] = {
789 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
790 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
791 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
792 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
793 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
794 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
795 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
796 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
797 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
798 { BER_BVNULL, 0, 0, 0, NULL }
801 int bindconf_parse( const char *word, slap_bindconf *bc ) {
805 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
806 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
810 const char *val = word + tab->key.bv_len;
812 switch ( tab->type ) {
814 cptr = (char **)((char *)bc + tab->off);
815 *cptr = ch_strdup( val );
819 bptr = (struct berval *)((char *)bc + tab->off);
820 ber_str2bv( val, 0, 1, bptr );
825 iptr = (int *)((char *)bc + tab->off);
828 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
829 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
830 *iptr = tab->aux[j].mask;
838 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
849 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
850 char buf[BUFSIZ], *ptr;
855 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
860 cptr = (char **)((char *)bc + tab->off);
862 switch ( tab->type ) {
864 bptr = (struct berval *)((char *)bc + tab->off);
865 cptr = &bptr->bv_val;
869 ptr = lutil_strcopy( ptr, tab->key.bv_val );
870 if ( tab->quote ) *ptr++ = '"';
871 ptr = lutil_strcopy( ptr, *cptr );
872 if ( tab->quote ) *ptr++ = '"';
878 iptr = (int *)((char *)bc + tab->off);
880 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
881 if ( *iptr == tab->aux[i].mask ) {
883 ptr = lutil_strcopy( ptr, tab->key.bv_val );
884 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
892 tmp.bv_len = ptr - buf;
893 ber_dupbv( bv, &tmp );
897 void bindconf_free( slap_bindconf *bc ) {
898 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
899 ch_free( bc->sb_binddn.bv_val );
900 BER_BVZERO( &bc->sb_binddn );
902 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
903 ch_free( bc->sb_cred.bv_val );
904 BER_BVZERO( &bc->sb_cred );
906 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
907 ch_free( bc->sb_saslmech.bv_val );
908 BER_BVZERO( &bc->sb_saslmech );
910 if ( bc->sb_secprops ) {
911 ch_free( bc->sb_secprops );
912 bc->sb_secprops = NULL;
914 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
915 ch_free( bc->sb_realm.bv_val );
916 BER_BVZERO( &bc->sb_realm );
918 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
919 ch_free( bc->sb_authcId.bv_val );
920 BER_BVZERO( &bc->sb_authcId );
922 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
923 ch_free( bc->sb_authzId.bv_val );
924 BER_BVZERO( &bc->sb_authzId );
929 /* -------------------------------------- */
933 strtok_quote( char *line, char *sep, char **quote_ptr )
940 if ( line != NULL ) {
943 while ( *next && strchr( sep, *next ) ) {
947 if ( *next == '\0' ) {
953 for ( inquote = 0; *next; ) {
961 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
967 next + 1, strlen( next + 1 ) + 1 );
968 next++; /* dont parse the escaped character */
973 if ( strchr( sep, *next ) != NULL ) {
987 static char buf[BUFSIZ];
989 static size_t lmax, lcur;
991 #define CATLINE( buf ) \
993 size_t len = strlen( buf ); \
994 while ( lcur + len + 1 > lmax ) { \
996 line = (char *) ch_realloc( line, lmax ); \
998 strcpy( line + lcur, buf ); \
1003 fp_getline_init(ConfigArgs *c) {
1009 fp_getline( FILE *fp, ConfigArgs *c )
1017 /* avoid stack of bufs */
1018 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1024 while ( fgets( buf, sizeof( buf ), fp ) ) {
1025 p = strchr( buf, '\n' );
1027 if ( p > buf && p[-1] == '\r' ) {
1035 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1042 if ( !isspace( (unsigned char)buf[0] ) ) {
1053 return(line[0] ? 1 : 0);
1057 fp_parse_line(ConfigArgs *c)
1060 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
1064 c->tline = ch_strdup(c->line);
1065 token = strtok_quote(c->tline, " \t", "e_ptr);
1067 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1068 if(quote_ptr) *quote_ptr = ' ';
1069 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
1070 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1071 if(quote_ptr) *quote_ptr = '\0';
1073 for(; token; token = strtok_quote(NULL, " \t", "e_ptr)) {
1074 if(c->argc == c->argv_size - 1) {
1076 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1078 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1082 c->argv_size += ARGS_STEP;
1084 c->argv[c->argc++] = token;
1086 c->argv[c->argc] = NULL;
1093 ucdata_unload( UCDATA_ALL );
1095 /* NOTE: in case of early exit, frontendDB can be NULL */
1096 if ( frontendDB->be_schemandn.bv_val )
1097 free( frontendDB->be_schemandn.bv_val );
1098 if ( frontendDB->be_schemadn.bv_val )
1099 free( frontendDB->be_schemadn.bv_val );
1100 if ( frontendDB->be_acl )
1101 acl_destroy( frontendDB->be_acl, NULL );
1104 if ( slapd_args_file )
1105 free ( slapd_args_file );
1106 if ( slapd_pid_file )
1107 free ( slapd_pid_file );
1108 if ( default_passwd_hash )
1109 ldap_charray_free( default_passwd_hash );
1113 slap_str2clist( char ***out, char *in, const char *brkstr )
1121 /* find last element in list */
1122 for (i = 0; *out && (*out)[i]; i++);
1124 /* protect the input string from strtok */
1125 str = ch_strdup( in );
1127 if ( *str == '\0' ) {
1132 /* Count words in string */
1134 for ( s = str; *s; s++ ) {
1135 if ( strchr( brkstr, *s ) != NULL ) {
1140 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1142 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1144 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1146 *new = ch_strdup( s );
1155 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1156 int argc, char **argv )
1158 ConfigArgs c = { 0 };
1168 sprintf( c.log, "%s: line %lu", fname, lineno );
1170 rc = SLAP_CONF_UNKNOWN;
1171 ct = config_find_keyword( be->be_cf_table, &c );
1173 rc = config_add_vals( ct, &c );