1 /* config.c - configuration file handling routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 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>
41 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
50 #include "slapi/slapi.h"
53 #include "lutil_ldap.h"
59 * defaults for various global variables
61 slap_mask_t global_allows = 0;
62 slap_mask_t global_disallows = 0;
63 int global_gentlehup = 0;
64 int global_idletimeout = 0;
65 char *global_host = NULL;
66 char *global_realm = NULL;
67 char *sasl_host = NULL;
68 char **default_passwd_hash = NULL;
69 struct berval default_search_base = BER_BVNULL;
70 struct berval default_search_nbase = BER_BVNULL;
72 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
73 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
75 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
76 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
78 char *slapd_pid_file = NULL;
79 char *slapd_args_file = NULL;
81 int use_reverse_lookup = 0;
84 int slapi_plugins_used = 0;
87 static int fp_getline(FILE *fp, ConfigArgs *c);
88 static void fp_getline_init(ConfigArgs *c);
89 static int fp_parse_line(ConfigArgs *c);
91 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
92 static char *strtok_quote_ldif(char **line);
95 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
98 c = ch_calloc( 1, sizeof( ConfigArgs ) );
99 if ( c == NULL ) return(NULL);
105 snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
110 init_config_argv( ConfigArgs *c )
112 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
113 c->argv_size = ARGS_STEP + 1;
116 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
119 for(i = 0; Conf[i].name; i++)
120 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
121 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
122 if ( !Conf[i].name ) return NULL;
126 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
127 int rc, arg_user, arg_type, arg_syn, iarg;
132 if(Conf->arg_type == ARG_IGNORED) {
133 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
134 c->log, Conf->name, 0);
137 arg_type = Conf->arg_type & ARGS_TYPES;
138 arg_user = Conf->arg_type & ARGS_USERLAND;
139 arg_syn = Conf->arg_type & ARGS_SYNTAX;
141 if((arg_type == ARG_DN) && c->argc == 1) {
145 if(Conf->min_args && (c->argc < Conf->min_args)) {
146 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> missing <%s> argument",
147 c->argv[0], Conf->what );
148 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n", c->log, c->cr_msg, 0 );
149 return(ARG_BAD_CONF);
151 if(Conf->max_args && (c->argc > Conf->max_args)) {
152 char *ignored = " ignored";
154 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> extra cruft after <%s>",
155 c->argv[0], Conf->what );
158 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s%s.\n",
159 c->log, c->cr_msg, ignored );
160 return(ARG_BAD_CONF);
162 if((arg_syn & ARG_DB) && !c->be) {
163 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> only allowed within database declaration",
165 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
166 c->log, c->cr_msg, 0);
167 return(ARG_BAD_CONF);
169 if((arg_syn & ARG_PRE_BI) && c->bi) {
170 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must occur before any backend %sdeclaration",
171 c->argv[0], (arg_syn & ARG_PRE_DB) ? "or database " : "" );
172 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
173 c->log, c->cr_msg, 0 );
174 return(ARG_BAD_CONF);
176 if((arg_syn & ARG_PRE_DB) && c->be && c->be != frontendDB) {
177 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must occur before any database declaration",
179 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
180 c->log, c->cr_msg, 0);
181 return(ARG_BAD_CONF);
183 if((arg_syn & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
184 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> old format not supported", c->argv[0] );
185 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
186 c->log, c->cr_msg, 0);
187 return(ARG_BAD_CONF);
189 if(arg_type && !Conf->arg_item && !(arg_syn & ARG_OFFSET)) {
190 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid config_table, arg_item is NULL",
192 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
193 c->log, c->cr_msg, 0);
194 return(ARG_BAD_CONF);
197 memset(&c->values, 0, sizeof(c->values));
198 if(arg_type == ARG_STRING) {
200 c->value_string = ch_strdup(c->argv[1]);
201 } else if(arg_type == ARG_BERVAL) {
203 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
204 } else if(arg_type == ARG_DN) {
206 ber_str2bv( c->argv[1], 0, 0, &bv );
207 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
208 if ( rc != LDAP_SUCCESS ) {
209 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid DN %d (%s)",
210 c->argv[0], rc, ldap_err2string( rc ));
211 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n" , c->log, c->cr_msg, 0);
212 return(ARG_BAD_CONF);
215 ch_free( c->value_ndn.bv_val );
216 ch_free( c->value_dn.bv_val );
218 } else { /* all numeric */
220 iarg = 0; larg = 0; barg = 0;
223 if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
224 snprintf( c->cr_msg, sizeof( c->cr_msg ),
225 "<%s> unable to parse \"%s\" as int",
226 c->argv[0], c->argv[1] );
227 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
228 c->log, c->cr_msg, 0);
229 return(ARG_BAD_CONF);
233 if ( lutil_atoux( &uiarg, c->argv[1], 0 ) != 0 ) {
234 snprintf( c->cr_msg, sizeof( c->cr_msg ),
235 "<%s> unable to parse \"%s\" as unsigned int",
236 c->argv[0], c->argv[1] );
237 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
238 c->log, c->cr_msg, 0);
239 return(ARG_BAD_CONF);
243 if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
244 snprintf( c->cr_msg, sizeof( c->cr_msg ),
245 "<%s> unable to parse \"%s\" as long",
246 c->argv[0], c->argv[1] );
247 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
248 c->log, c->cr_msg, 0);
249 return(ARG_BAD_CONF);
252 case ARG_BER_LEN_T: {
254 if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
255 snprintf( c->cr_msg, sizeof( c->cr_msg ),
256 "<%s> unable to parse \"%s\" as ber_len_t",
257 c->argv[0], c->argv[1] );
258 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
259 c->log, c->cr_msg, 0);
260 return(ARG_BAD_CONF);
267 } else if ( !strcasecmp(c->argv[1], "on") ||
268 !strcasecmp(c->argv[1], "true") ||
269 !strcasecmp(c->argv[1], "yes") )
272 } else if ( !strcasecmp(c->argv[1], "off") ||
273 !strcasecmp(c->argv[1], "false") ||
274 !strcasecmp(c->argv[1], "no") )
278 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value",
280 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
281 c->log, c->cr_msg, 0 );
282 return(ARG_BAD_CONF);
286 j = (arg_type & ARG_NONZERO) ? 1 : 0;
287 if(iarg < j && larg < j && barg < j ) {
288 larg = larg ? larg : (barg ? barg : iarg);
289 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value",
291 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
292 c->log, c->cr_msg, 0 );
293 return(ARG_BAD_CONF);
297 case ARG_INT: c->value_int = iarg; break;
298 case ARG_UINT: c->value_uint = uiarg; break;
299 case ARG_LONG: c->value_long = larg; break;
300 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
306 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
310 arg_type = Conf->arg_type;
311 if(arg_type & ARG_MAGIC) {
312 if(!c->be) c->be = frontendDB;
314 rc = (*((ConfigDriver*)Conf->arg_item))(c);
316 if(c->be == frontendDB) c->be = NULL;
319 if ( !c->cr_msg[0] ) {
320 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> handler exited with %d",
322 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
323 c->log, c->cr_msg, 0 );
325 return(ARG_BAD_CONF);
329 if(arg_type & ARG_OFFSET) {
330 if (c->be && c->table == Cft_Database)
331 ptr = c->be->be_private;
333 ptr = c->bi->bi_private;
335 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> offset is missing base pointer",
337 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
338 c->log, c->cr_msg, 0);
339 return(ARG_BAD_CONF);
341 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
342 } else if (arg_type & ARGS_TYPES) {
343 ptr = Conf->arg_item;
345 if(arg_type & ARGS_TYPES)
346 switch(arg_type & ARGS_TYPES) {
348 case ARG_INT: *(int*)ptr = c->value_int; break;
349 case ARG_UINT: *(unsigned*)ptr = c->value_uint; break;
350 case ARG_LONG: *(long*)ptr = c->value_long; break;
351 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
353 char *cc = *(char**)ptr;
355 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
356 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
357 c->log, Conf->name, 0 );
358 return(ARG_BAD_CONF);
362 *(char **)ptr = c->value_string;
366 *(struct berval *)ptr = c->value_bv;
372 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
375 arg_type = Conf->arg_type;
376 if(arg_type == ARG_IGNORED) {
377 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
378 c->log, Conf->name, 0);
381 rc = config_check_vals( Conf, c, 0 );
383 return config_set_vals( Conf, c );
387 config_del_vals(ConfigTable *cf, ConfigArgs *c)
391 /* If there is no handler, just ignore it */
392 if ( cf->arg_type & ARG_MAGIC ) {
393 c->op = LDAP_MOD_DELETE;
394 c->type = cf->arg_type & ARGS_USERLAND;
395 rc = (*((ConfigDriver*)cf->arg_item))(c);
401 config_get_vals(ConfigTable *cf, ConfigArgs *c)
407 if ( cf->arg_type & ARG_IGNORED ) {
411 memset(&c->values, 0, sizeof(c->values));
412 c->rvalue_vals = NULL;
413 c->rvalue_nvals = NULL;
414 c->op = SLAP_CONFIG_EMIT;
415 c->type = cf->arg_type & ARGS_USERLAND;
417 if ( cf->arg_type & ARG_MAGIC ) {
418 rc = (*((ConfigDriver*)cf->arg_item))(c);
421 if ( cf->arg_type & ARG_OFFSET ) {
422 if (c->be && c->table == Cft_Database)
423 ptr = c->be->be_private;
425 ptr = c->bi->bi_private;
428 ptr = (void *)((char *)ptr + (long)cf->arg_item);
433 switch(cf->arg_type & ARGS_TYPES) {
435 case ARG_INT: c->value_int = *(int *)ptr; break;
436 case ARG_UINT: c->value_uint = *(unsigned *)ptr; break;
437 case ARG_LONG: c->value_long = *(long *)ptr; break;
438 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
441 c->value_string = ch_strdup(*(char **)ptr);
444 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
447 if ( cf->arg_type & ARGS_TYPES) {
450 switch(cf->arg_type & ARGS_TYPES) {
451 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
452 case ARG_UINT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%u", c->value_uint); break;
453 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
454 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
455 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
456 c->value_int ? "TRUE" : "FALSE"); break;
458 if ( c->value_string && c->value_string[0]) {
459 ber_str2bv( c->value_string, 0, 0, &bv);
465 if ( !BER_BVISEMPTY( &c->value_bv )) {
475 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
478 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
479 ber_bvarray_add(&c->rvalue_vals, &bv);
480 } else if ( !BER_BVISNULL( &bv ) ) {
481 value_add_one(&c->rvalue_vals, &bv);
483 /* else: maybe c->rvalue_vals already set? */
489 init_config_attrs(ConfigTable *ct) {
492 for (i=0; ct[i].name; i++ ) {
493 if ( !ct[i].attribute ) continue;
494 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
496 fprintf( stderr, "init_config_attrs: register_at failed\n" );
500 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
508 init_config_ocs( ConfigOCs *ocs ) {
511 for (i=0;ocs[i].co_def;i++) {
512 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
514 fprintf( stderr, "init_config_ocs: register_oc failed\n" );
518 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
524 /* Split an LDIF line into space-separated tokens. Words may be grouped
525 * by quotes. A quoted string may begin in the middle of a word, but must
526 * end at the end of the word (be followed by whitespace or EOS). Any other
527 * quotes are passed through unchanged. All other characters are passed
531 strtok_quote_ldif( char **line )
533 char *beg, *ptr, *quote=NULL;
541 while( isspace( (unsigned char) *ptr )) ptr++;
552 if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
562 if ( isspace( (unsigned char) *ptr )) {
568 while ( quote < ptr ) {
576 while ( isspace( (unsigned char) *ptr )) ptr++;
583 config_parse_ldif( ConfigArgs *c )
586 c->tline = ch_strdup(c->line);
589 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
591 if ( c->argc >= c->argv_size ) {
592 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
595 c->argv_size += ARGS_STEP;
598 c->argv[c->argc] = NULL;
602 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
606 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
607 ct->ad->ad_cname.bv_val, valx );
609 c->argv[0] = ct->ad->ad_cname.bv_val;
611 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
612 c->argv[c->argc] = c->line;
614 c->argv[c->argc] = NULL;
617 config_parse_ldif( c );
619 rc = config_check_vals( ct, c, 1 );
624 rc = LDAP_CONSTRAINT_VIOLATION;
630 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
634 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
635 ct->ad->ad_cname.bv_val, valx );
637 c->argv[0] = ct->ad->ad_cname.bv_val;
639 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
640 c->argv[c->argc] = c->line;
642 c->argv[c->argc] = NULL;
645 config_parse_ldif( c );
647 c->op = LDAP_MOD_ADD;
648 rc = config_add_vals( ct, c );
655 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
663 c = ch_calloc( 1, sizeof( ConfigArgs ) );
669 memcpy( c, cf, sizeof( ConfigArgs ) );
671 c->depth = depth; /* XXX */
678 init_config_argv( c );
680 if ( stat( fname, &s ) != 0 ) {
682 Debug(LDAP_DEBUG_ANY,
683 "could not stat config file \"%s\": %s (%d)\n",
684 fname, strerror(errno), errno);
689 if ( !S_ISREG( s.st_mode ) ) {
691 Debug(LDAP_DEBUG_ANY,
692 "regular file expected, got \"%s\"\n",
698 fp = fopen( fname, "r" );
701 Debug(LDAP_DEBUG_ANY,
702 "could not open config file \"%s\": %s (%d)\n",
703 fname, strerror(errno), errno);
708 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
714 while ( fp_getline( fp, c ) ) {
715 /* skip comments and blank lines */
716 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
720 snprintf( c->log, sizeof( c->log ), "%s: line %d",
721 c->fname, c->lineno );
725 if ( fp_parse_line( c ) ) {
731 Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
737 c->op = SLAP_CONFIG_ADD;
739 ct = config_find_keyword( cft, c );
741 c->table = Cft_Global;
742 rc = config_add_vals( ct, c );
745 if ( rc & ARGS_USERLAND ) {
746 /* XXX a usertype would be opaque here */
747 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
748 c->log, c->argv[0], 0);
752 } else if ( rc == ARG_BAD_CONF ) {
757 } else if ( c->bi && !c->be ) {
758 rc = SLAP_CONF_UNKNOWN;
759 if ( c->bi->bi_cf_ocs ) {
760 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
762 c->table = c->bi->bi_cf_ocs->co_type;
763 rc = config_add_vals( ct, c );
766 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
767 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
772 case SLAP_CONF_UNKNOWN:
773 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
774 "<%s> inside backend info definition.\n",
775 c->log, *c->argv, 0);
782 } else if ( c->be && c->be != frontendDB ) {
783 rc = SLAP_CONF_UNKNOWN;
784 if ( c->be->be_cf_ocs ) {
785 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
787 c->table = c->be->be_cf_ocs->co_type;
788 rc = config_add_vals( ct, c );
791 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
792 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
795 if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
797 /* global overlays may need
798 * definitions inside other databases...
800 rc = (*frontendDB->be_config)( frontendDB,
801 c->fname, (int)c->lineno, c->argc, c->argv );
808 case SLAP_CONF_UNKNOWN:
809 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
810 "<%s> inside backend database definition.\n",
811 c->log, *c->argv, 0);
818 } else if ( frontendDB->be_config ) {
819 rc = (*frontendDB->be_config)( frontendDB,
820 c->fname, (int)c->lineno, c->argc, c->argv);
823 case SLAP_CONF_UNKNOWN:
824 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
825 "<%s> inside global database definition.\n",
826 c->log, *c->argv, 0);
835 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
836 "<%s> outside backend info and database definitions.\n",
837 c->log, *c->argv, 0);
853 /* restrictops, allows, disallows, requires, loglevel */
856 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
858 for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
859 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
865 verb_to_mask(const char *word, slap_verbmasks *v) {
867 ber_str2bv( word, 0, 0, &bword );
868 return bverb_to_mask( &bword, v );
872 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
874 for(i = 1; i < argc; i++) {
875 j = verb_to_mask(argv[i], v);
876 if(BER_BVISNULL(&v[j].word)) return i;
877 while (!v[j].mask) j--;
883 /* Mask keywords that represent multiple bits should occur before single
884 * bit keywords in the verbmasks array.
887 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
891 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
892 if (!v[i].mask) continue;
893 if (( m & v[i].mask ) == v[i].mask ) {
894 value_add_one( bva, &v[i].word );
905 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
909 assert( *vp == NULL );
911 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
913 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
915 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
916 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
917 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
920 BER_BVZERO( &(*vp)[ i ].word );
926 slap_verbmasks_destroy( slap_verbmasks *v )
932 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
933 ch_free( v[ i ].word.bv_val );
942 slap_verbmasks_append(
946 slap_mask_t *ignore )
951 return LDAP_OPERATIONS_ERROR;
954 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
955 if ( !(*vp)[ i ].mask ) continue;
957 if ( ignore != NULL ) {
960 for ( j = 0; ignore[ j ] != 0; j++ ) {
961 if ( (*vp)[ i ].mask == ignore[ j ] ) {
967 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
968 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
969 /* already set; ignore */
973 return LDAP_TYPE_OR_VALUE_EXISTS;
976 if ( m & (*vp)[ i ].mask ) {
978 return LDAP_CONSTRAINT_VIOLATION;
983 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
984 ber_dupbv( &(*vp)[ i ].word, v );
985 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
986 BER_BVZERO( &(*vp)[ i + 1 ].word );
992 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
995 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
996 if ( m == v[i].mask ) {
1007 static slap_verbmasks tlskey[] = {
1008 { BER_BVC("no"), SB_TLS_OFF },
1009 { BER_BVC("yes"), SB_TLS_ON },
1010 { BER_BVC("critical"), SB_TLS_CRITICAL },
1014 static slap_verbmasks crlkeys[] = {
1015 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1016 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1017 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1021 static slap_verbmasks vfykeys[] = {
1022 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1023 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1024 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1025 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1030 static slap_verbmasks methkey[] = {
1031 { BER_BVC("none"), LDAP_AUTH_NONE },
1032 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
1033 #ifdef HAVE_CYRUS_SASL
1034 { BER_BVC("sasl"), LDAP_AUTH_SASL },
1039 static slap_verbmasks versionkey[] = {
1040 { BER_BVC("2"), LDAP_VERSION2 },
1041 { BER_BVC("3"), LDAP_VERSION3 },
1045 static slap_cf_aux_table bindkey[] = {
1046 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1047 { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1048 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1049 { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
1050 { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
1051 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1052 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1053 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1054 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1055 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1056 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 1, NULL },
1057 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1059 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1061 /* NOTE: replace "13" with the actual index
1062 * of the first TLS-related line */
1063 #define aux_TLS (bindkey+13) /* beginning of TLS keywords */
1065 { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1066 { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1067 { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1068 { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1069 { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1070 { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1071 #ifdef HAVE_OPENSSL_CRL
1072 { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1075 { BER_BVNULL, 0, 0, 0, NULL }
1080 * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1081 * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1084 * 'U': unsigned long
1088 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1090 int rc = SLAP_CONF_UNKNOWN;
1091 slap_cf_aux_table *tab;
1093 for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1094 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1099 unsigned long *ulptr;
1100 struct berval *bptr;
1101 const char *val = word + tab->key.bv_len;
1103 switch ( tab->type ) {
1105 cptr = (char **)((char *)dst + tab->off);
1106 *cptr = ch_strdup( val );
1111 bptr = (struct berval *)((char *)dst + tab->off);
1112 if ( tab->aux != NULL ) {
1114 slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1116 ber_str2bv( val, 0, 0, &dn );
1117 rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1120 ber_str2bv( val, 0, 1, bptr );
1126 iptr = (int *)((char *)dst + tab->off);
1128 if ( tab->aux != NULL ) {
1129 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1131 assert( aux != NULL );
1134 for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1135 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1136 *iptr = aux[j].mask;
1143 rc = lutil_atoix( iptr, val, 0 );
1148 uptr = (unsigned *)((char *)dst + tab->off);
1150 rc = lutil_atoux( uptr, val, 0 );
1154 lptr = (long *)((char *)dst + tab->off);
1156 rc = lutil_atolx( lptr, val, 0 );
1160 ulptr = (unsigned long *)((char *)dst + tab->off);
1162 rc = lutil_atoulx( ulptr, val, 0 );
1167 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1179 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1181 char buf[AC_LINE_MAX], *ptr;
1182 slap_cf_aux_table *tab;
1186 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1191 unsigned long *ulptr;
1192 struct berval *bptr;
1194 cptr = (char **)((char *)src + tab->off);
1196 switch ( tab->type ) {
1198 bptr = (struct berval *)((char *)src + tab->off);
1199 cptr = &bptr->bv_val;
1204 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1205 if ( tab->quote ) *ptr++ = '"';
1206 ptr = lutil_strcopy( ptr, *cptr );
1207 if ( tab->quote ) *ptr++ = '"';
1212 iptr = (int *)((char *)src + tab->off);
1214 if ( tab->aux != NULL ) {
1215 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1217 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1218 if ( *iptr == aux[i].mask ) {
1220 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1221 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1228 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1229 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1234 uptr = (unsigned *)((char *)src + tab->off);
1236 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1237 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1241 lptr = (long *)((char *)src + tab->off);
1243 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1244 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1248 ulptr = (unsigned long *)((char *)src + tab->off);
1250 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1251 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1259 tmp.bv_len = ptr - buf;
1260 ber_dupbv( bv, &tmp );
1265 slap_tls_get_config( LDAP *ld, int opt, char **val )
1267 slap_verbmasks *keys;
1273 case LDAP_OPT_X_TLS_CRLCHECK:
1276 case LDAP_OPT_X_TLS_REQUIRE_CERT:
1283 ldap_pvt_tls_get_option( ld, opt, &ival );
1284 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1285 if (keys[i].mask == ival) {
1286 *val = ch_strdup( keys[i].word.bv_val );
1294 bindconf_tls_parse( const char *word, slap_bindconf *bc )
1297 if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1298 bc->sb_tls_do_init = 1;
1306 bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
1309 return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
1315 bindconf_parse( const char *word, slap_bindconf *bc )
1318 /* Detect TLS config changes explicitly */
1319 if ( bindconf_tls_parse( word, bc ) == 0 ) {
1323 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1327 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1329 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1332 void bindconf_free( slap_bindconf *bc ) {
1333 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1334 ch_free( bc->sb_uri.bv_val );
1335 BER_BVZERO( &bc->sb_uri );
1337 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1338 ch_free( bc->sb_binddn.bv_val );
1339 BER_BVZERO( &bc->sb_binddn );
1341 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1342 ch_free( bc->sb_cred.bv_val );
1343 BER_BVZERO( &bc->sb_cred );
1345 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1346 ch_free( bc->sb_saslmech.bv_val );
1347 BER_BVZERO( &bc->sb_saslmech );
1349 if ( bc->sb_secprops ) {
1350 ch_free( bc->sb_secprops );
1351 bc->sb_secprops = NULL;
1353 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1354 ch_free( bc->sb_realm.bv_val );
1355 BER_BVZERO( &bc->sb_realm );
1357 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1358 ch_free( bc->sb_authcId.bv_val );
1359 BER_BVZERO( &bc->sb_authcId );
1361 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1362 ch_free( bc->sb_authzId.bv_val );
1363 BER_BVZERO( &bc->sb_authzId );
1366 if ( bc->sb_tls_cert ) {
1367 ch_free( bc->sb_tls_cert );
1368 bc->sb_tls_cert = NULL;
1370 if ( bc->sb_tls_key ) {
1371 ch_free( bc->sb_tls_key );
1372 bc->sb_tls_key = NULL;
1374 if ( bc->sb_tls_cacert ) {
1375 ch_free( bc->sb_tls_cacert );
1376 bc->sb_tls_cacert = NULL;
1378 if ( bc->sb_tls_cacertdir ) {
1379 ch_free( bc->sb_tls_cacertdir );
1380 bc->sb_tls_cacertdir = NULL;
1382 if ( bc->sb_tls_reqcert ) {
1383 ch_free( bc->sb_tls_reqcert );
1384 bc->sb_tls_reqcert = NULL;
1386 if ( bc->sb_tls_cipher_suite ) {
1387 ch_free( bc->sb_tls_cipher_suite );
1388 bc->sb_tls_cipher_suite = NULL;
1390 #ifdef HAVE_OPENSSL_CRL
1391 if ( bc->sb_tls_crlcheck ) {
1392 ch_free( bc->sb_tls_crlcheck );
1393 bc->sb_tls_crlcheck = NULL;
1400 bindconf_tls_defaults( slap_bindconf *bc )
1403 if ( bc->sb_tls_do_init ) {
1404 if ( !bc->sb_tls_cacert )
1405 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1406 &bc->sb_tls_cacert );
1407 if ( !bc->sb_tls_cacertdir )
1408 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1409 &bc->sb_tls_cacertdir );
1410 if ( !bc->sb_tls_cert )
1411 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1413 if ( !bc->sb_tls_key )
1414 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1416 if ( !bc->sb_tls_cipher_suite )
1417 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1418 &bc->sb_tls_cipher_suite );
1419 if ( !bc->sb_tls_reqcert )
1420 bc->sb_tls_reqcert = ch_strdup("demand");
1421 #ifdef HAVE_OPENSSL_CRL
1422 if ( !bc->sb_tls_crlcheck )
1423 slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1424 &bc->sb_tls_crlcheck );
1436 { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1437 { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1438 { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1439 { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1440 { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1444 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1446 int i, rc, newctx = 0, res = 0;
1447 char *ptr = (char *)bc, **word;
1449 bc->sb_tls_do_init = 0;
1451 for (i=0; bindtlsopts[i].opt; i++) {
1452 word = (char **)(ptr + bindtlsopts[i].offset);
1454 rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1456 Debug( LDAP_DEBUG_ANY,
1457 "bindconf_tls_set: failed to set %s to %s\n",
1458 bindtlsopts[i].key, *word, 0 );
1464 if ( bc->sb_tls_reqcert ) {
1465 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1466 bc->sb_tls_reqcert );
1468 Debug( LDAP_DEBUG_ANY,
1469 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1470 bc->sb_tls_reqcert, 0, 0 );
1475 #ifdef HAVE_OPENSSL_CRL
1476 if ( bc->sb_tls_crlcheck ) {
1477 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1478 bc->sb_tls_crlcheck );
1480 Debug( LDAP_DEBUG_ANY,
1481 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1482 bc->sb_tls_crlcheck, 0, 0 );
1491 if ( bc->sb_tls_ctx ) {
1492 ldap_pvt_tls_ctx_free( bc->sb_tls_ctx );
1493 bc->sb_tls_ctx = NULL;
1495 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1499 ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1507 * connect to a client using the bindconf data
1508 * note: should move "version" into bindconf...
1511 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1517 /* Init connection to master */
1518 rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1519 if ( rc != LDAP_SUCCESS ) {
1520 Debug( LDAP_DEBUG_ANY,
1521 "slap_client_connect: "
1522 "ldap_initialize(%s) failed (%d)\n",
1523 sb->sb_uri.bv_val, rc, 0 );
1527 if ( sb->sb_version != 0 ) {
1528 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1529 (const void *)&sb->sb_version );
1532 if ( sb->sb_timeout_api ) {
1533 tv.tv_sec = sb->sb_timeout_api;
1535 ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
1538 if ( sb->sb_timeout_net ) {
1539 tv.tv_sec = sb->sb_timeout_net;
1541 ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
1545 if ( sb->sb_tls_do_init ) {
1546 rc = bindconf_tls_set( sb, ld );
1548 } else if ( sb->sb_tls_ctx ) {
1549 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1554 Debug( LDAP_DEBUG_ANY,
1555 "slap_client_connect: "
1556 "URI=%s TLS context initialization failed (%d)\n",
1557 sb->sb_uri.bv_val, rc, 0 );
1564 rc = ldap_start_tls_s( ld, NULL, NULL );
1565 if ( rc != LDAP_SUCCESS ) {
1566 Debug( LDAP_DEBUG_ANY,
1567 "slap_client_connect: URI=%s "
1568 "%s, ldap_start_tls failed (%d)\n",
1570 sb->sb_tls == SB_TLS_CRITICAL ?
1571 "Error" : "Warning",
1573 if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1579 if ( sb->sb_method == LDAP_AUTH_SASL ) {
1580 #ifdef HAVE_CYRUS_SASL
1583 if ( sb->sb_secprops != NULL ) {
1584 rc = ldap_set_option( ld,
1585 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1587 if( rc != LDAP_OPT_SUCCESS ) {
1588 Debug( LDAP_DEBUG_ANY,
1589 "slap_client_connect: "
1590 "error, ldap_set_option "
1591 "(%s,SECPROPS,\"%s\") failed!\n",
1592 sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1597 defaults = lutil_sasl_defaults( ld,
1598 sb->sb_saslmech.bv_val,
1599 sb->sb_realm.bv_val,
1600 sb->sb_authcId.bv_val,
1602 sb->sb_authzId.bv_val );
1603 if ( defaults == NULL ) {
1608 rc = ldap_sasl_interactive_bind_s( ld,
1609 sb->sb_binddn.bv_val,
1610 sb->sb_saslmech.bv_val,
1613 lutil_sasl_interact,
1616 lutil_sasl_freedefs( defaults );
1618 /* FIXME: different error behaviors according to
1620 * 2) on err policy : exit, retry, backoff ...
1622 if ( rc != LDAP_SUCCESS ) {
1623 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1625 Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1626 "ldap_sasl_interactive_bind_s failed (%d)\n",
1627 sb->sb_uri.bv_val, rc, 0 );
1629 /* FIXME (see above comment) */
1630 /* if Kerberos credentials cache is not active, retry */
1631 if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1632 rc == LDAP_LOCAL_ERROR )
1634 rc = LDAP_SERVER_DOWN;
1639 #else /* HAVE_CYRUS_SASL */
1640 /* Should never get here, we trapped this at config time */
1642 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1647 } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1648 rc = ldap_sasl_bind_s( ld,
1649 sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1650 &sb->sb_cred, NULL, NULL, NULL );
1651 if ( rc != LDAP_SUCCESS ) {
1652 Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1654 "ldap_sasl_bind_s failed (%d)\n",
1655 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1663 ldap_unbind_ext( ld, NULL, NULL );
1674 /* -------------------------------------- */
1678 strtok_quote( char *line, char *sep, char **quote_ptr )
1685 if ( line != NULL ) {
1688 while ( *next && strchr( sep, *next ) ) {
1692 if ( *next == '\0' ) {
1698 for ( inquote = 0; *next; ) {
1706 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1712 next + 1, strlen( next + 1 ) + 1 );
1713 next++; /* dont parse the escaped character */
1718 if ( strchr( sep, *next ) != NULL ) {
1732 static char buf[AC_LINE_MAX];
1734 static size_t lmax, lcur;
1736 #define CATLINE( buf ) \
1738 size_t len = strlen( buf ); \
1739 while ( lcur + len + 1 > lmax ) { \
1740 lmax += AC_LINE_MAX; \
1741 line = (char *) ch_realloc( line, lmax ); \
1743 strcpy( line + lcur, buf ); \
1748 fp_getline_init(ConfigArgs *c) {
1754 fp_getline( FILE *fp, ConfigArgs *c )
1762 /* avoid stack of bufs */
1763 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1769 while ( fgets( buf, sizeof( buf ), fp ) ) {
1770 p = strchr( buf, '\n' );
1772 if ( p > buf && p[-1] == '\r' ) {
1780 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1787 if ( !isspace( (unsigned char)buf[0] ) ) {
1798 return(line[0] ? 1 : 0);
1802 fp_parse_line(ConfigArgs *c)
1805 static char *const hide[] = {
1806 "rootpw", "replica", "syncrepl", /* in slapd */
1807 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1808 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1809 "pseudorootpw", /* in back-meta */
1810 "dbpasswd", /* in back-sql */
1814 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1816 c->tline = ch_strdup(c->line);
1817 token = strtok_quote(c->tline, " \t", "e_ptr);
1819 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1820 if(quote_ptr) *quote_ptr = ' ';
1821 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1822 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1823 if(quote_ptr) *quote_ptr = '\0';
1825 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1826 if(c->argc >= c->argv_size) {
1828 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1830 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1834 c->argv_size += ARGS_STEP;
1838 c->argv[c->argc++] = token;
1840 c->argv[c->argc] = NULL;
1847 ucdata_unload( UCDATA_ALL );
1849 /* NOTE: in case of early exit, frontendDB can be NULL */
1850 if ( frontendDB->be_schemandn.bv_val )
1851 free( frontendDB->be_schemandn.bv_val );
1852 if ( frontendDB->be_schemadn.bv_val )
1853 free( frontendDB->be_schemadn.bv_val );
1854 if ( frontendDB->be_acl )
1855 acl_destroy( frontendDB->be_acl, NULL );
1858 if ( slapd_args_file )
1859 free ( slapd_args_file );
1860 if ( slapd_pid_file )
1861 free ( slapd_pid_file );
1862 if ( default_passwd_hash )
1863 ldap_charray_free( default_passwd_hash );
1867 slap_str2clist( char ***out, char *in, const char *brkstr )
1875 /* find last element in list */
1876 for (i = 0; *out && (*out)[i]; i++);
1878 /* protect the input string from strtok */
1879 str = ch_strdup( in );
1881 if ( *str == '\0' ) {
1886 /* Count words in string */
1888 for ( s = str; *s; s++ ) {
1889 if ( strchr( brkstr, *s ) != NULL ) {
1894 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1896 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1898 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1900 *new = ch_strdup( s );
1909 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1910 int argc, char **argv )
1912 ConfigArgs c = { 0 };
1923 c.op = SLAP_CONFIG_ADD;
1924 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1926 rc = SLAP_CONF_UNKNOWN;
1927 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1929 c.table = be->be_cf_ocs->co_type;
1930 rc = config_add_vals( ct, &c );