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);
84 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
87 c = ch_calloc( 1, sizeof( ConfigArgs ) );
88 if ( c == NULL ) return(NULL);
94 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
99 init_config_argv( ConfigArgs *c )
101 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
102 c->argv_size = ARGS_STEP + 1;
105 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
108 for(i = 0; Conf[i].name; i++)
109 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
110 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
111 if ( !Conf[i].name ) return NULL;
115 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
116 int rc, arg_user, arg_type, iarg;
120 arg_type = Conf->arg_type;
121 if(arg_type == ARG_IGNORED) {
122 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
123 c->log, Conf->name, 0);
126 if((arg_type & ARG_DN) && c->argc == 1) {
130 if(Conf->min_args && (c->argc < Conf->min_args)) {
131 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
132 c->log, Conf->name, Conf->what);
133 return(ARG_BAD_CONF);
135 if(Conf->max_args && (c->argc > Conf->max_args)) {
136 Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
137 c->log, Conf->what, Conf->name);
139 if((arg_type & ARG_DB) && !c->be) {
140 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
141 c->log, Conf->name, 0);
142 return(ARG_BAD_CONF);
144 if((arg_type & ARG_PRE_BI) && c->bi) {
145 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
146 c->log, Conf->name, ((arg_type & ARG_PRE_DB)
147 ? "or database " : "") );
148 return(ARG_BAD_CONF);
150 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
151 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
152 c->log, Conf->name, 0);
153 return(ARG_BAD_CONF);
155 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
156 Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
157 c->log, Conf->name, 0);
158 return(ARG_BAD_CONF);
160 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
161 Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
162 c->log, Conf->name, 0);
163 return(ARG_BAD_CONF);
165 c->type = arg_user = (arg_type & ARGS_USERLAND);
166 memset(&c->values, 0, sizeof(c->values));
167 if(arg_type & ARGS_NUMERIC) {
169 iarg = 0; larg = 0; barg = 0;
170 switch(arg_type & ARGS_NUMERIC) {
171 case ARG_INT: iarg = atoi(c->argv[1]); break;
172 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
173 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
177 } else if(!strcasecmp(c->argv[1], "on") ||
178 !strcasecmp(c->argv[1], "true")) {
180 } else if(!strcasecmp(c->argv[1], "off") ||
181 !strcasecmp(c->argv[1], "false")) {
184 Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
185 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
186 Conf->what, c->argv[1], Conf->name);
191 j = (arg_type & ARG_NONZERO) ? 1 : 0;
192 if(iarg < j && larg < j && barg < j ) {
193 larg = larg ? larg : (barg ? barg : iarg);
194 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
195 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf->what, larg, Conf->name);
196 return(ARG_BAD_CONF);
198 switch(arg_type & ARGS_NUMERIC) {
200 case ARG_INT: c->value_int = iarg; break;
201 case ARG_LONG: c->value_long = larg; break;
202 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
204 } else if(arg_type & ARG_STRING) {
206 c->value_string = ch_strdup(c->argv[1]);
207 } else if(arg_type & ARG_BERVAL) {
209 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
210 } else if(arg_type & ARG_DN) {
212 ber_str2bv( c->argv[1], 0, 0, &bv );
213 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
214 if ( rc != LDAP_SUCCESS ) {
215 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
216 Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
217 Conf->name, rc, ldap_err2string( rc ));
218 return(ARG_BAD_CONF);
221 ch_free( c->value_ndn.bv_val );
222 ch_free( c->value_dn.bv_val );
228 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
232 arg_type = Conf->arg_type;
233 if(arg_type & ARG_MAGIC) {
234 if(!c->be) c->be = frontendDB;
235 rc = (*((ConfigDriver*)Conf->arg_item))(c);
237 if(c->be == frontendDB) c->be = NULL;
240 Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!\n",
241 c->log, Conf->name, rc);
242 return(ARG_BAD_CONF);
246 if(arg_type & ARG_OFFSET) {
248 ptr = c->be->be_private;
250 ptr = c->bi->bi_private;
252 Debug(LDAP_DEBUG_CONFIG, "%s: offset for <%s> missing base pointer!\n",
253 c->log, Conf->name, 0);
254 return(ARG_BAD_CONF);
256 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
257 } else if (arg_type & ARGS_POINTER) {
258 ptr = Conf->arg_item;
260 if(arg_type & ARGS_POINTER)
261 switch(arg_type & ARGS_POINTER) {
263 case ARG_INT: *(int*)ptr = c->value_int; break;
264 case ARG_LONG: *(long*)ptr = c->value_long; break;
265 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
267 char *cc = *(char**)ptr;
269 if (arg_type & ARG_UNIQUE) {
270 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
271 c->log, Conf->name, 0 );
272 return(ARG_BAD_CONF);
276 *(char **)ptr = c->value_string;
280 *(struct berval *)ptr = c->value_bv;
286 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
289 arg_type = Conf->arg_type;
290 if(arg_type == ARG_IGNORED) {
291 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
292 c->log, Conf->name, 0);
295 rc = config_check_vals( Conf, c, 0 );
297 return config_set_vals( Conf, c );
301 config_del_vals(ConfigTable *cf, ConfigArgs *c)
309 config_get_vals(ConfigTable *cf, ConfigArgs *c)
315 if ( cf->arg_type & ARG_IGNORED ) {
319 memset(&c->values, 0, sizeof(c->values));
320 c->rvalue_vals = NULL;
321 c->rvalue_nvals = NULL;
322 c->op = SLAP_CONFIG_EMIT;
323 c->type = cf->arg_type & ARGS_USERLAND;
325 if ( cf->arg_type & ARG_MAGIC ) {
326 rc = (*((ConfigDriver*)cf->arg_item))(c);
329 if ( cf->arg_type & ARG_OFFSET ) {
331 ptr = c->be->be_private;
333 ptr = c->bi->bi_private;
336 ptr = (void *)((char *)ptr + (int)cf->arg_item);
341 switch(cf->arg_type & ARGS_POINTER) {
343 case ARG_INT: c->value_int = *(int *)ptr; break;
344 case ARG_LONG: c->value_long = *(long *)ptr; break;
345 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
348 c->value_string = ch_strdup(*(char **)ptr);
351 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
354 if ( cf->arg_type & ARGS_POINTER) {
356 switch(cf->arg_type & ARGS_POINTER) {
357 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
358 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
359 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
360 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
361 c->value_int ? "TRUE" : "FALSE"); break;
363 if ( c->value_string && c->value_string[0]) {
364 ber_str2bv( c->value_string, 0, 0, &bv);
370 if ( !BER_BVISEMPTY( &c->value_bv )) {
377 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
378 ber_bvarray_add(&c->rvalue_vals, &bv);
380 value_add_one(&c->rvalue_vals, &bv);
386 init_config_attrs(ConfigTable *ct) {
387 LDAPAttributeType *at;
391 for (i=0; ct[i].name; i++ ) {
392 if ( !ct[i].attribute ) continue;
393 at = ldap_str2attributetype( ct[i].attribute,
394 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
396 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
397 ct[i].attribute, ldap_scherr2str(code), err );
400 code = at_add( at, 0, NULL, &err );
401 if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
402 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
403 ct[i].attribute, scherr2str(code), err );
406 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
408 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
409 ct[i].attribute, err );
419 init_config_ocs( ConfigOCs *ocs ) {
422 for (i=0;ocs[i].def;i++) {
427 oc = ldap_str2objectclass( ocs[i].def, &code, &err,
428 LDAP_SCHEMA_ALLOW_ALL );
430 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
431 ocs[i].def, ldap_scherr2str(code), err );
434 code = oc_add(oc,0,NULL,&err);
435 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
436 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
437 ocs[i].def, scherr2str(code), err );
441 *ocs[i].oc = oc_find(oc->oc_names[0]);
449 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
453 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
454 ct->ad->ad_cname.bv_val, valx );
456 c->argv[0] = ct->ad->ad_cname.bv_val;
457 if ( fp_parse_line( c ) ) {
460 rc = config_check_vals( ct, c, 1 );
468 config_parse_add(ConfigTable *ct, ConfigArgs *c)
472 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
473 ct->ad->ad_cname.bv_val, c->valx );
475 c->argv[0] = ct->ad->ad_cname.bv_val;
476 if ( fp_parse_line( c ) ) {
479 c->op = LDAP_MOD_ADD;
480 rc = config_add_vals( ct, c );
488 read_config_file(const char *fname, int depth, ConfigArgs *cf)
495 c = ch_calloc( 1, sizeof( ConfigArgs ) );
501 memcpy( c, cf, sizeof( ConfigArgs ) );
503 c->depth = depth; /* XXX */
509 init_config_argv( c );
511 fp = fopen( fname, "r" );
514 Debug(LDAP_DEBUG_ANY,
515 "could not open config file \"%s\": %s (%d)\n",
516 fname, strerror(errno), errno);
520 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
526 while ( fp_getline( fp, c ) ) {
527 /* skip comments and blank lines */
528 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
532 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
533 c->fname, c->lineno );
537 if ( fp_parse_line( c ) ) {
543 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
547 c->op = SLAP_CONFIG_ADD;
549 ct = config_find_keyword( config_back_cf_table, c );
551 rc = config_add_vals( ct, c );
554 if ( rc & ARGS_USERLAND ) {
555 /* XXX a usertype would be opaque here */
556 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
557 c->log, c->argv[0], 0);
561 } else if ( rc == ARG_BAD_CONF ) {
566 } else if ( c->bi ) {
567 rc = SLAP_CONF_UNKNOWN;
568 if ( c->bi->bi_cf_table ) {
569 ct = config_find_keyword( c->bi->bi_cf_table, c );
571 rc = config_add_vals( ct, c );
574 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
575 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
580 case SLAP_CONF_UNKNOWN:
581 Debug(LDAP_DEBUG_CONFIG, "%s: "
582 "unknown directive <%s> inside backend info definition (ignored)\n",
583 c->log, *c->argv, 0);
591 } else if ( c->be ) {
592 rc = SLAP_CONF_UNKNOWN;
593 if ( c->be->be_cf_table ) {
594 ct = config_find_keyword( c->be->be_cf_table, c );
596 rc = config_add_vals( ct, c );
599 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
600 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
605 case SLAP_CONF_UNKNOWN:
606 Debug( LDAP_DEBUG_CONFIG, "%s: "
607 "unknown directive <%s> inside backend database "
608 "definition (ignored)\n",
609 c->log, *c->argv, 0);
617 } else if ( frontendDB->be_config ) {
618 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
621 case SLAP_CONF_UNKNOWN:
622 Debug( LDAP_DEBUG_CONFIG, "%s: "
623 "unknown directive <%s> inside global database definition (ignored)\n",
624 c->log, *c->argv, 0);
633 Debug(LDAP_DEBUG_CONFIG, "%s: "
634 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
635 c->log, *c->argv, 0);
641 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
642 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
643 &frontendDB->be_schemadn );
644 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
645 if ( rc != LDAP_SUCCESS ) {
646 Debug(LDAP_DEBUG_ANY, "%s: "
647 "unable to normalize default schema DN \"%s\"\n",
648 c->log, frontendDB->be_schemadn.bv_val, 0 );
649 /* must not happen */
663 /* restrictops, allows, disallows, requires, loglevel */
666 verb_to_mask(const char *word, slap_verbmasks *v) {
668 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
669 if(!strcasecmp(word, v[i].word.bv_val))
675 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
677 for(i = 1; i < argc; i++) {
678 j = verb_to_mask(argv[i], v);
679 if(BER_BVISNULL(&v[j].word)) return(1);
680 while (!v[j].mask) j--;
687 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
691 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
692 if (!v[i].mask) continue;
693 if (( m & v[i].mask ) == v[i].mask ) {
694 value_add_one( bva, &v[i].word );
700 static slap_verbmasks tlskey[] = {
701 { BER_BVC("no"), SB_TLS_OFF },
702 { BER_BVC("yes"), SB_TLS_ON },
703 { BER_BVC("critical"), SB_TLS_CRITICAL },
707 static slap_verbmasks methkey[] = {
709 { BER_BVC("none"), LDAP_AUTH_NONE },
711 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
712 #ifdef HAVE_CYRUS_SASL
713 { BER_BVC("sasl"), LDAP_AUTH_SASL },
718 typedef struct cf_aux_table {
726 static cf_aux_table bindkey[] = {
727 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
728 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
729 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
730 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
731 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
732 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
733 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
734 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
735 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
736 { BER_BVNULL, 0, 0, 0, NULL }
739 int bindconf_parse( const char *word, slap_bindconf *bc ) {
743 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
744 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
748 const char *val = word + tab->key.bv_len;
750 switch ( tab->type ) {
752 cptr = (char **)((char *)bc + tab->off);
753 *cptr = ch_strdup( val );
757 bptr = (struct berval *)((char *)bc + tab->off);
758 ber_str2bv( val, 0, 1, bptr );
763 iptr = (int *)((char *)bc + tab->off);
766 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
767 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
768 *iptr = tab->aux[j].mask;
776 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
787 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
788 char buf[BUFSIZ], *ptr;
793 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
798 cptr = (char **)((char *)bc + tab->off);
800 switch ( tab->type ) {
802 bptr = (struct berval *)((char *)bc + tab->off);
803 cptr = &bptr->bv_val;
807 ptr = lutil_strcopy( ptr, tab->key.bv_val );
808 if ( tab->quote ) *ptr++ = '"';
809 ptr = lutil_strcopy( ptr, *cptr );
810 if ( tab->quote ) *ptr++ = '"';
816 iptr = (int *)((char *)bc + tab->off);
818 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
819 if ( *iptr == tab->aux[i].mask ) {
821 ptr = lutil_strcopy( ptr, tab->key.bv_val );
822 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
830 tmp.bv_len = ptr - buf;
831 ber_dupbv( bv, &tmp );
835 void bindconf_free( slap_bindconf *bc ) {
836 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
837 ch_free( bc->sb_binddn.bv_val );
838 BER_BVZERO( &bc->sb_binddn );
840 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
841 ch_free( bc->sb_cred.bv_val );
842 BER_BVZERO( &bc->sb_cred );
844 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
845 ch_free( bc->sb_saslmech.bv_val );
846 BER_BVZERO( &bc->sb_saslmech );
848 if ( bc->sb_secprops ) {
849 ch_free( bc->sb_secprops );
850 bc->sb_secprops = NULL;
852 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
853 ch_free( bc->sb_realm.bv_val );
854 BER_BVZERO( &bc->sb_realm );
856 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
857 ch_free( bc->sb_authcId.bv_val );
858 BER_BVZERO( &bc->sb_authcId );
860 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
861 ch_free( bc->sb_authzId.bv_val );
862 BER_BVZERO( &bc->sb_authzId );
867 /* -------------------------------------- */
871 strtok_quote( char *line, char *sep, char **quote_ptr )
878 if ( line != NULL ) {
881 while ( *next && strchr( sep, *next ) ) {
885 if ( *next == '\0' ) {
891 for ( inquote = 0; *next; ) {
899 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
905 next + 1, strlen( next + 1 ) + 1 );
906 next++; /* dont parse the escaped character */
911 if ( strchr( sep, *next ) != NULL ) {
925 static char buf[BUFSIZ];
927 static size_t lmax, lcur;
929 #define CATLINE( buf ) \
931 size_t len = strlen( buf ); \
932 while ( lcur + len + 1 > lmax ) { \
934 line = (char *) ch_realloc( line, lmax ); \
936 strcpy( line + lcur, buf ); \
941 fp_getline_init(ConfigArgs *c) {
947 fp_getline( FILE *fp, ConfigArgs *c )
955 /* avoid stack of bufs */
956 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
962 while ( fgets( buf, sizeof( buf ), fp ) ) {
963 p = strchr( buf, '\n' );
965 if ( p > buf && p[-1] == '\r' ) {
973 && ( p = line + strlen( line ) - 1 )[0] == '\\'
980 if ( !isspace( (unsigned char)buf[0] ) ) {
991 return(line[0] ? 1 : 0);
995 fp_parse_line(ConfigArgs *c)
998 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
1002 c->tline = ch_strdup(c->line);
1003 token = strtok_quote(c->tline, " \t", "e_ptr);
1005 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1006 if(quote_ptr) *quote_ptr = ' ';
1007 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
1008 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1009 if(quote_ptr) *quote_ptr = '\0';
1011 for(; token; token = strtok_quote(NULL, " \t", "e_ptr)) {
1012 if(c->argc == c->argv_size - 1) {
1014 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1016 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1020 c->argv_size += ARGS_STEP;
1022 c->argv[c->argc++] = token;
1024 c->argv[c->argc] = NULL;
1031 ucdata_unload( UCDATA_ALL );
1033 /* NOTE: in case of early exit, frontendDB can be NULL */
1034 if ( frontendDB->be_schemandn.bv_val )
1035 free( frontendDB->be_schemandn.bv_val );
1036 if ( frontendDB->be_schemadn.bv_val )
1037 free( frontendDB->be_schemadn.bv_val );
1038 if ( frontendDB->be_acl )
1039 acl_destroy( frontendDB->be_acl, NULL );
1042 if ( slapd_args_file )
1043 free ( slapd_args_file );
1044 if ( slapd_pid_file )
1045 free ( slapd_pid_file );
1046 if ( default_passwd_hash )
1047 ldap_charray_free( default_passwd_hash );
1051 slap_str2clist( char ***out, char *in, const char *brkstr )
1059 /* find last element in list */
1060 for (i = 0; *out && (*out)[i]; i++);
1062 /* protect the input string from strtok */
1063 str = ch_strdup( in );
1065 if ( *str == '\0' ) {
1070 /* Count words in string */
1072 for ( s = str; *s; s++ ) {
1073 if ( strchr( brkstr, *s ) != NULL ) {
1078 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1080 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1082 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1084 *new = ch_strdup( s );
1093 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1094 int argc, char **argv )
1096 ConfigArgs c = { 0 };
1105 sprintf( c.log, "%s: line %lu", fname, lineno );
1107 rc = SLAP_CONF_UNKNOWN;
1108 ct = config_find_keyword( be->be_cf_table, &c );
1110 rc = config_add_vals( ct, &c );