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 **default_passwd_hash = NULL;
68 struct berval default_search_base = BER_BVNULL;
69 struct berval default_search_nbase = BER_BVNULL;
71 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
72 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
74 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
75 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
77 char *slapd_pid_file = NULL;
78 char *slapd_args_file = NULL;
80 int use_reverse_lookup = 0;
83 int slapi_plugins_used = 0;
86 static int fp_getline(FILE *fp, ConfigArgs *c);
87 static void fp_getline_init(ConfigArgs *c);
88 static int fp_parse_line(ConfigArgs *c);
90 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
91 static char *strtok_quote_ldif(char **line);
94 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
97 c = ch_calloc( 1, sizeof( ConfigArgs ) );
98 if ( c == NULL ) return(NULL);
104 snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
109 init_config_argv( ConfigArgs *c )
111 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
112 c->argv_size = ARGS_STEP + 1;
115 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
118 for(i = 0; Conf[i].name; i++)
119 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
120 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
121 if ( !Conf[i].name ) return NULL;
125 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
126 int rc, arg_user, arg_type, arg_syn, iarg;
131 if(Conf->arg_type == ARG_IGNORED) {
132 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
133 c->log, Conf->name, 0);
136 arg_type = Conf->arg_type & ARGS_TYPES;
137 arg_user = Conf->arg_type & ARGS_USERLAND;
138 arg_syn = Conf->arg_type & ARGS_SYNTAX;
140 if((arg_type == ARG_DN) && c->argc == 1) {
144 if(Conf->min_args && (c->argc < Conf->min_args)) {
145 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> missing <%s> argument",
146 c->argv[0], Conf->what );
147 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n", c->log, c->cr_msg, 0 );
148 return(ARG_BAD_CONF);
150 if(Conf->max_args && (c->argc > Conf->max_args)) {
151 char *ignored = " ignored";
153 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> extra cruft after <%s>",
154 c->argv[0], Conf->what );
157 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s%s.\n",
158 c->log, c->cr_msg, ignored );
159 return(ARG_BAD_CONF);
161 if((arg_syn & ARG_DB) && !c->be) {
162 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> only allowed within database declaration",
164 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
165 c->log, c->cr_msg, 0);
166 return(ARG_BAD_CONF);
168 if((arg_syn & ARG_PRE_BI) && c->bi) {
169 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must occur before any backend %sdeclaration",
170 c->argv[0], (arg_syn & ARG_PRE_DB) ? "or database " : "" );
171 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
172 c->log, c->cr_msg, 0 );
173 return(ARG_BAD_CONF);
175 if((arg_syn & ARG_PRE_DB) && c->be && c->be != frontendDB) {
176 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must occur before any database declaration",
178 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
179 c->log, c->cr_msg, 0);
180 return(ARG_BAD_CONF);
182 if((arg_syn & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
183 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> old format not supported", c->argv[0] );
184 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
185 c->log, c->cr_msg, 0);
186 return(ARG_BAD_CONF);
188 if(arg_type && !Conf->arg_item && !(arg_syn & ARG_OFFSET)) {
189 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid config_table, arg_item is NULL",
191 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
192 c->log, c->cr_msg, 0);
193 return(ARG_BAD_CONF);
196 memset(&c->values, 0, sizeof(c->values));
197 if(arg_type == ARG_STRING) {
199 c->value_string = ch_strdup(c->argv[1]);
200 } else if(arg_type == ARG_BERVAL) {
202 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
203 } else if(arg_type == ARG_DN) {
205 ber_str2bv( c->argv[1], 0, 0, &bv );
206 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
207 if ( rc != LDAP_SUCCESS ) {
208 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid DN %d (%s)",
209 c->argv[0], rc, ldap_err2string( rc ));
210 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n" , c->log, c->cr_msg, 0);
211 return(ARG_BAD_CONF);
214 ch_free( c->value_ndn.bv_val );
215 ch_free( c->value_dn.bv_val );
217 } else { /* all numeric */
219 iarg = 0; larg = 0; barg = 0;
222 if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
223 snprintf( c->cr_msg, sizeof( c->cr_msg ),
224 "<%s> unable to parse \"%s\" as int",
225 c->argv[0], c->argv[1] );
226 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
227 c->log, c->cr_msg, 0);
228 return(ARG_BAD_CONF);
232 if ( lutil_atoux( &uiarg, c->argv[1], 0 ) != 0 ) {
233 snprintf( c->cr_msg, sizeof( c->cr_msg ),
234 "<%s> unable to parse \"%s\" as unsigned int",
235 c->argv[0], c->argv[1] );
236 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
237 c->log, c->cr_msg, 0);
238 return(ARG_BAD_CONF);
242 if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
243 snprintf( c->cr_msg, sizeof( c->cr_msg ),
244 "<%s> unable to parse \"%s\" as long",
245 c->argv[0], c->argv[1] );
246 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
247 c->log, c->cr_msg, 0);
248 return(ARG_BAD_CONF);
251 case ARG_BER_LEN_T: {
253 if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
254 snprintf( c->cr_msg, sizeof( c->cr_msg ),
255 "<%s> unable to parse \"%s\" as ber_len_t",
256 c->argv[0], c->argv[1] );
257 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
258 c->log, c->cr_msg, 0);
259 return(ARG_BAD_CONF);
266 } else if ( !strcasecmp(c->argv[1], "on") ||
267 !strcasecmp(c->argv[1], "true") ||
268 !strcasecmp(c->argv[1], "yes") )
271 } else if ( !strcasecmp(c->argv[1], "off") ||
272 !strcasecmp(c->argv[1], "false") ||
273 !strcasecmp(c->argv[1], "no") )
277 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value",
279 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
280 c->log, c->cr_msg, 0 );
281 return(ARG_BAD_CONF);
285 j = (arg_type & ARG_NONZERO) ? 1 : 0;
286 if(iarg < j && larg < j && barg < j ) {
287 larg = larg ? larg : (barg ? barg : iarg);
288 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value",
290 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
291 c->log, c->cr_msg, 0 );
292 return(ARG_BAD_CONF);
296 case ARG_INT: c->value_int = iarg; break;
297 case ARG_UINT: c->value_uint = uiarg; break;
298 case ARG_LONG: c->value_long = larg; break;
299 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
305 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
309 arg_type = Conf->arg_type;
310 if(arg_type & ARG_MAGIC) {
311 if(!c->be) c->be = frontendDB;
313 rc = (*((ConfigDriver*)Conf->arg_item))(c);
315 if(c->be == frontendDB) c->be = NULL;
318 if ( !c->cr_msg[0] ) {
319 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> handler exited with %d",
321 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
322 c->log, c->cr_msg, 0 );
324 return(ARG_BAD_CONF);
328 if(arg_type & ARG_OFFSET) {
329 if (c->be && c->table == Cft_Database)
330 ptr = c->be->be_private;
332 ptr = c->bi->bi_private;
334 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> offset is missing base pointer",
336 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
337 c->log, c->cr_msg, 0);
338 return(ARG_BAD_CONF);
340 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
341 } else if (arg_type & ARGS_TYPES) {
342 ptr = Conf->arg_item;
344 if(arg_type & ARGS_TYPES)
345 switch(arg_type & ARGS_TYPES) {
347 case ARG_INT: *(int*)ptr = c->value_int; break;
348 case ARG_UINT: *(unsigned*)ptr = c->value_uint; break;
349 case ARG_LONG: *(long*)ptr = c->value_long; break;
350 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
352 char *cc = *(char**)ptr;
354 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
355 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
356 c->log, Conf->name, 0 );
357 return(ARG_BAD_CONF);
361 *(char **)ptr = c->value_string;
365 *(struct berval *)ptr = c->value_bv;
371 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
374 arg_type = Conf->arg_type;
375 if(arg_type == ARG_IGNORED) {
376 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
377 c->log, Conf->name, 0);
380 rc = config_check_vals( Conf, c, 0 );
382 return config_set_vals( Conf, c );
386 config_del_vals(ConfigTable *cf, ConfigArgs *c)
390 /* If there is no handler, just ignore it */
391 if ( cf->arg_type & ARG_MAGIC ) {
392 c->op = LDAP_MOD_DELETE;
393 c->type = cf->arg_type & ARGS_USERLAND;
394 rc = (*((ConfigDriver*)cf->arg_item))(c);
400 config_get_vals(ConfigTable *cf, ConfigArgs *c)
406 if ( cf->arg_type & ARG_IGNORED ) {
410 memset(&c->values, 0, sizeof(c->values));
411 c->rvalue_vals = NULL;
412 c->rvalue_nvals = NULL;
413 c->op = SLAP_CONFIG_EMIT;
414 c->type = cf->arg_type & ARGS_USERLAND;
416 if ( cf->arg_type & ARG_MAGIC ) {
417 rc = (*((ConfigDriver*)cf->arg_item))(c);
420 if ( cf->arg_type & ARG_OFFSET ) {
421 if (c->be && c->table == Cft_Database)
422 ptr = c->be->be_private;
424 ptr = c->bi->bi_private;
427 ptr = (void *)((char *)ptr + (long)cf->arg_item);
432 switch(cf->arg_type & ARGS_TYPES) {
434 case ARG_INT: c->value_int = *(int *)ptr; break;
435 case ARG_UINT: c->value_uint = *(unsigned *)ptr; break;
436 case ARG_LONG: c->value_long = *(long *)ptr; break;
437 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
440 c->value_string = ch_strdup(*(char **)ptr);
443 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
446 if ( cf->arg_type & ARGS_TYPES) {
449 switch(cf->arg_type & ARGS_TYPES) {
450 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
451 case ARG_UINT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%u", c->value_uint); break;
452 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
453 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
454 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
455 c->value_int ? "TRUE" : "FALSE"); break;
457 if ( c->value_string && c->value_string[0]) {
458 ber_str2bv( c->value_string, 0, 0, &bv);
464 if ( !BER_BVISEMPTY( &c->value_bv )) {
474 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
477 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
478 ber_bvarray_add(&c->rvalue_vals, &bv);
479 } else if ( !BER_BVISNULL( &bv ) ) {
480 value_add_one(&c->rvalue_vals, &bv);
482 /* else: maybe c->rvalue_vals already set? */
488 init_config_attrs(ConfigTable *ct) {
491 for (i=0; ct[i].name; i++ ) {
492 if ( !ct[i].attribute ) continue;
493 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
495 fprintf( stderr, "init_config_attrs: register_at failed\n" );
499 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
507 init_config_ocs( ConfigOCs *ocs ) {
510 for (i=0;ocs[i].co_def;i++) {
511 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
513 fprintf( stderr, "init_config_ocs: register_oc failed\n" );
517 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
523 /* Split an LDIF line into space-separated tokens. Words may be grouped
524 * by quotes. A quoted string may begin in the middle of a word, but must
525 * end at the end of the word (be followed by whitespace or EOS). Any other
526 * quotes are passed through unchanged. All other characters are passed
530 strtok_quote_ldif( char **line )
532 char *beg, *ptr, *quote=NULL;
540 while( isspace( (unsigned char) *ptr )) ptr++;
551 if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
561 if ( isspace( (unsigned char) *ptr )) {
567 while ( quote < ptr ) {
575 while ( isspace( (unsigned char) *ptr )) ptr++;
582 config_parse_ldif( ConfigArgs *c )
585 c->tline = ch_strdup(c->line);
588 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
590 if ( c->argc >= c->argv_size ) {
591 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
594 c->argv_size += ARGS_STEP;
597 c->argv[c->argc] = NULL;
601 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
605 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
606 ct->ad->ad_cname.bv_val, valx );
608 c->argv[0] = ct->ad->ad_cname.bv_val;
610 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
611 c->argv[c->argc] = c->line;
613 c->argv[c->argc] = NULL;
616 config_parse_ldif( c );
618 rc = config_check_vals( ct, c, 1 );
623 rc = LDAP_CONSTRAINT_VIOLATION;
629 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
633 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
634 ct->ad->ad_cname.bv_val, valx );
636 c->argv[0] = ct->ad->ad_cname.bv_val;
638 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
639 c->argv[c->argc] = c->line;
641 c->argv[c->argc] = NULL;
644 config_parse_ldif( c );
646 c->op = LDAP_MOD_ADD;
647 rc = config_add_vals( ct, c );
654 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
662 c = ch_calloc( 1, sizeof( ConfigArgs ) );
668 memcpy( c, cf, sizeof( ConfigArgs ) );
670 c->depth = depth; /* XXX */
677 init_config_argv( c );
679 if ( stat( fname, &s ) != 0 ) {
681 Debug(LDAP_DEBUG_ANY,
682 "could not stat config file \"%s\": %s (%d)\n",
683 fname, strerror(errno), errno);
688 if ( !S_ISREG( s.st_mode ) ) {
690 Debug(LDAP_DEBUG_ANY,
691 "regular file expected, got \"%s\"\n",
697 fp = fopen( fname, "r" );
700 Debug(LDAP_DEBUG_ANY,
701 "could not open config file \"%s\": %s (%d)\n",
702 fname, strerror(errno), errno);
707 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
713 while ( fp_getline( fp, c ) ) {
714 /* skip comments and blank lines */
715 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
719 snprintf( c->log, sizeof( c->log ), "%s: line %d",
720 c->fname, c->lineno );
724 if ( fp_parse_line( c ) ) {
730 Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
736 c->op = SLAP_CONFIG_ADD;
738 ct = config_find_keyword( cft, c );
740 c->table = Cft_Global;
741 rc = config_add_vals( ct, c );
744 if ( rc & ARGS_USERLAND ) {
745 /* XXX a usertype would be opaque here */
746 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
747 c->log, c->argv[0], 0);
751 } else if ( rc == ARG_BAD_CONF ) {
756 } else if ( c->bi && !c->be ) {
757 rc = SLAP_CONF_UNKNOWN;
758 if ( c->bi->bi_cf_ocs ) {
759 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
761 c->table = c->bi->bi_cf_ocs->co_type;
762 rc = config_add_vals( ct, c );
765 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
766 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
771 case SLAP_CONF_UNKNOWN:
772 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
773 "<%s> inside backend info definition.\n",
774 c->log, *c->argv, 0);
781 } else if ( c->be && c->be != frontendDB ) {
782 rc = SLAP_CONF_UNKNOWN;
783 if ( c->be->be_cf_ocs ) {
784 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
786 c->table = c->be->be_cf_ocs->co_type;
787 rc = config_add_vals( ct, c );
790 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
791 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
794 if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
796 /* global overlays may need
797 * definitions inside other databases...
799 rc = (*frontendDB->be_config)( frontendDB,
800 c->fname, (int)c->lineno, c->argc, c->argv );
807 case SLAP_CONF_UNKNOWN:
808 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
809 "<%s> inside backend database definition.\n",
810 c->log, *c->argv, 0);
817 } else if ( frontendDB->be_config ) {
818 rc = (*frontendDB->be_config)( frontendDB,
819 c->fname, (int)c->lineno, c->argc, c->argv);
822 case SLAP_CONF_UNKNOWN:
823 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
824 "<%s> inside global database definition.\n",
825 c->log, *c->argv, 0);
834 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
835 "<%s> outside backend info and database definitions.\n",
836 c->log, *c->argv, 0);
852 /* restrictops, allows, disallows, requires, loglevel */
855 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
857 for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
858 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
864 verb_to_mask(const char *word, slap_verbmasks *v) {
866 ber_str2bv( word, 0, 0, &bword );
867 return bverb_to_mask( &bword, v );
871 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
873 for(i = 1; i < argc; i++) {
874 j = verb_to_mask(argv[i], v);
875 if(BER_BVISNULL(&v[j].word)) return i;
876 while (!v[j].mask) j--;
882 /* Mask keywords that represent multiple bits should occur before single
883 * bit keywords in the verbmasks array.
886 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
890 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
891 if (!v[i].mask) continue;
892 if (( m & v[i].mask ) == v[i].mask ) {
893 value_add_one( bva, &v[i].word );
904 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
908 assert( *vp == NULL );
910 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
912 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
914 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
915 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
916 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
919 BER_BVZERO( &(*vp)[ i ].word );
925 slap_verbmasks_destroy( slap_verbmasks *v )
931 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
932 ch_free( v[ i ].word.bv_val );
941 slap_verbmasks_append(
945 slap_mask_t *ignore )
950 return LDAP_OPERATIONS_ERROR;
953 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
954 if ( !(*vp)[ i ].mask ) continue;
956 if ( ignore != NULL ) {
959 for ( j = 0; ignore[ j ] != 0; j++ ) {
960 if ( (*vp)[ i ].mask == ignore[ j ] ) {
966 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
967 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
968 /* already set; ignore */
972 return LDAP_TYPE_OR_VALUE_EXISTS;
975 if ( m & (*vp)[ i ].mask ) {
977 return LDAP_CONSTRAINT_VIOLATION;
982 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
983 ber_dupbv( &(*vp)[ i ].word, v );
984 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
985 BER_BVZERO( &(*vp)[ i + 1 ].word );
991 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
994 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
995 if ( m == v[i].mask ) {
1006 static slap_verbmasks tlskey[] = {
1007 { BER_BVC("no"), SB_TLS_OFF },
1008 { BER_BVC("yes"), SB_TLS_ON },
1009 { BER_BVC("critical"), SB_TLS_CRITICAL },
1013 static slap_verbmasks crlkeys[] = {
1014 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1015 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1016 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1020 static slap_verbmasks vfykeys[] = {
1021 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1022 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1023 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1024 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1029 static slap_verbmasks methkey[] = {
1030 { BER_BVC("none"), LDAP_AUTH_NONE },
1031 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
1032 #ifdef HAVE_CYRUS_SASL
1033 { BER_BVC("sasl"), LDAP_AUTH_SASL },
1038 static slap_verbmasks versionkey[] = {
1039 { BER_BVC("2"), LDAP_VERSION2 },
1040 { BER_BVC("3"), LDAP_VERSION3 },
1044 static slap_cf_aux_table bindkey[] = {
1045 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1046 { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1047 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1048 { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
1049 { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
1050 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1051 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1052 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1053 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1054 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1055 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 1, NULL },
1056 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1058 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1060 /* NOTE: replace "13" with the actual index
1061 * of the first TLS-related line */
1062 #define aux_TLS (bindkey+13) /* beginning of TLS keywords */
1064 { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1065 { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1066 { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1067 { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1068 { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1069 { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1070 #ifdef HAVE_OPENSSL_CRL
1071 { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1074 { BER_BVNULL, 0, 0, 0, NULL }
1079 * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1080 * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1083 * 'U': unsigned long
1087 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1089 int rc = SLAP_CONF_UNKNOWN;
1090 slap_cf_aux_table *tab;
1092 for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1093 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1098 unsigned long *ulptr;
1099 struct berval *bptr;
1100 const char *val = word + tab->key.bv_len;
1102 switch ( tab->type ) {
1104 cptr = (char **)((char *)dst + tab->off);
1105 *cptr = ch_strdup( val );
1110 bptr = (struct berval *)((char *)dst + tab->off);
1111 if ( tab->aux != NULL ) {
1113 slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1115 ber_str2bv( val, 0, 0, &dn );
1116 rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1119 ber_str2bv( val, 0, 1, bptr );
1125 iptr = (int *)((char *)dst + tab->off);
1127 if ( tab->aux != NULL ) {
1128 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1130 assert( aux != NULL );
1133 for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1134 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1135 *iptr = aux[j].mask;
1142 rc = lutil_atoix( iptr, val, 0 );
1147 uptr = (unsigned *)((char *)dst + tab->off);
1149 rc = lutil_atoux( uptr, val, 0 );
1153 lptr = (long *)((char *)dst + tab->off);
1155 rc = lutil_atolx( lptr, val, 0 );
1159 ulptr = (unsigned long *)((char *)dst + tab->off);
1161 rc = lutil_atoulx( ulptr, val, 0 );
1166 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1178 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1180 char buf[AC_LINE_MAX], *ptr;
1181 slap_cf_aux_table *tab;
1185 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1190 unsigned long *ulptr;
1191 struct berval *bptr;
1193 cptr = (char **)((char *)src + tab->off);
1195 switch ( tab->type ) {
1197 bptr = (struct berval *)((char *)src + tab->off);
1198 cptr = &bptr->bv_val;
1203 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1204 if ( tab->quote ) *ptr++ = '"';
1205 ptr = lutil_strcopy( ptr, *cptr );
1206 if ( tab->quote ) *ptr++ = '"';
1211 iptr = (int *)((char *)src + tab->off);
1213 if ( tab->aux != NULL ) {
1214 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1216 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1217 if ( *iptr == aux[i].mask ) {
1219 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1220 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1227 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1228 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1233 uptr = (unsigned *)((char *)src + tab->off);
1235 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1236 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1240 lptr = (long *)((char *)src + tab->off);
1242 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1243 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1247 ulptr = (unsigned long *)((char *)src + tab->off);
1249 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1250 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1258 tmp.bv_len = ptr - buf;
1259 ber_dupbv( bv, &tmp );
1264 slap_tls_get_config( LDAP *ld, int opt, char **val )
1266 slap_verbmasks *keys;
1272 case LDAP_OPT_X_TLS_CRLCHECK:
1275 case LDAP_OPT_X_TLS_REQUIRE_CERT:
1282 ldap_pvt_tls_get_option( ld, opt, &ival );
1283 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1284 if (keys[i].mask == ival) {
1285 *val = ch_strdup( keys[i].word.bv_val );
1293 bindconf_tls_parse( const char *word, slap_bindconf *bc )
1296 if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1297 bc->sb_tls_do_init = 1;
1305 bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
1308 return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
1314 bindconf_parse( const char *word, slap_bindconf *bc )
1317 /* Detect TLS config changes explicitly */
1318 if ( bindconf_tls_parse( word, bc ) == 0 ) {
1322 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1326 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1328 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1331 void bindconf_free( slap_bindconf *bc ) {
1332 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1333 ch_free( bc->sb_uri.bv_val );
1334 BER_BVZERO( &bc->sb_uri );
1336 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1337 ch_free( bc->sb_binddn.bv_val );
1338 BER_BVZERO( &bc->sb_binddn );
1340 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1341 ch_free( bc->sb_cred.bv_val );
1342 BER_BVZERO( &bc->sb_cred );
1344 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1345 ch_free( bc->sb_saslmech.bv_val );
1346 BER_BVZERO( &bc->sb_saslmech );
1348 if ( bc->sb_secprops ) {
1349 ch_free( bc->sb_secprops );
1350 bc->sb_secprops = NULL;
1352 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1353 ch_free( bc->sb_realm.bv_val );
1354 BER_BVZERO( &bc->sb_realm );
1356 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1357 ch_free( bc->sb_authcId.bv_val );
1358 BER_BVZERO( &bc->sb_authcId );
1360 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1361 ch_free( bc->sb_authzId.bv_val );
1362 BER_BVZERO( &bc->sb_authzId );
1365 if ( bc->sb_tls_cert ) {
1366 ch_free( bc->sb_tls_cert );
1367 bc->sb_tls_cert = NULL;
1369 if ( bc->sb_tls_key ) {
1370 ch_free( bc->sb_tls_key );
1371 bc->sb_tls_key = NULL;
1373 if ( bc->sb_tls_cacert ) {
1374 ch_free( bc->sb_tls_cacert );
1375 bc->sb_tls_cacert = NULL;
1377 if ( bc->sb_tls_cacertdir ) {
1378 ch_free( bc->sb_tls_cacertdir );
1379 bc->sb_tls_cacertdir = NULL;
1381 if ( bc->sb_tls_reqcert ) {
1382 ch_free( bc->sb_tls_reqcert );
1383 bc->sb_tls_reqcert = NULL;
1385 if ( bc->sb_tls_cipher_suite ) {
1386 ch_free( bc->sb_tls_cipher_suite );
1387 bc->sb_tls_cipher_suite = NULL;
1389 #ifdef HAVE_OPENSSL_CRL
1390 if ( bc->sb_tls_crlcheck ) {
1391 ch_free( bc->sb_tls_crlcheck );
1392 bc->sb_tls_crlcheck = NULL;
1399 bindconf_tls_defaults( slap_bindconf *bc )
1402 if ( bc->sb_tls_do_init ) {
1403 if ( !bc->sb_tls_cacert )
1404 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1405 &bc->sb_tls_cacert );
1406 if ( !bc->sb_tls_cacertdir )
1407 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1408 &bc->sb_tls_cacertdir );
1409 if ( !bc->sb_tls_cert )
1410 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1412 if ( !bc->sb_tls_key )
1413 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1415 if ( !bc->sb_tls_cipher_suite )
1416 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1417 &bc->sb_tls_cipher_suite );
1418 if ( !bc->sb_tls_reqcert )
1419 bc->sb_tls_reqcert = ch_strdup("demand");
1420 #ifdef HAVE_OPENSSL_CRL
1421 if ( !bc->sb_tls_crlcheck )
1422 slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1423 &bc->sb_tls_crlcheck );
1435 { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1436 { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1437 { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1438 { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1439 { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1443 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1445 int i, rc, newctx = 0, res = 0;
1446 char *ptr = (char *)bc, **word;
1448 bc->sb_tls_do_init = 0;
1450 for (i=0; bindtlsopts[i].opt; i++) {
1451 word = (char **)(ptr + bindtlsopts[i].offset);
1453 rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1455 Debug( LDAP_DEBUG_ANY,
1456 "bindconf_tls_set: failed to set %s to %s\n",
1457 bindtlsopts[i].key, *word, 0 );
1463 if ( bc->sb_tls_reqcert ) {
1464 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1465 bc->sb_tls_reqcert );
1467 Debug( LDAP_DEBUG_ANY,
1468 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1469 bc->sb_tls_reqcert, 0, 0 );
1474 #ifdef HAVE_OPENSSL_CRL
1475 if ( bc->sb_tls_crlcheck ) {
1476 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1477 bc->sb_tls_crlcheck );
1479 Debug( LDAP_DEBUG_ANY,
1480 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1481 bc->sb_tls_crlcheck, 0, 0 );
1490 if ( bc->sb_tls_ctx ) {
1491 ldap_pvt_tls_ctx_free( bc->sb_tls_ctx );
1492 bc->sb_tls_ctx = NULL;
1494 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1498 ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1506 * connect to a client using the bindconf data
1507 * note: should move "version" into bindconf...
1510 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1516 /* Init connection to master */
1517 rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1518 if ( rc != LDAP_SUCCESS ) {
1519 Debug( LDAP_DEBUG_ANY,
1520 "slap_client_connect: "
1521 "ldap_initialize(%s) failed (%d)\n",
1522 sb->sb_uri.bv_val, rc, 0 );
1526 if ( sb->sb_version != 0 ) {
1527 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1528 (const void *)&sb->sb_version );
1531 if ( sb->sb_timeout_api ) {
1532 tv.tv_sec = sb->sb_timeout_api;
1534 ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
1537 if ( sb->sb_timeout_net ) {
1538 tv.tv_sec = sb->sb_timeout_net;
1540 ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
1544 if ( sb->sb_tls_do_init ) {
1545 rc = bindconf_tls_set( sb, ld );
1547 } else if ( sb->sb_tls_ctx ) {
1548 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1553 Debug( LDAP_DEBUG_ANY,
1554 "slap_client_connect: "
1555 "URI=%s TLS context initialization failed (%d)\n",
1556 sb->sb_uri.bv_val, rc, 0 );
1563 rc = ldap_start_tls_s( ld, NULL, NULL );
1564 if ( rc != LDAP_SUCCESS ) {
1565 Debug( LDAP_DEBUG_ANY,
1566 "slap_client_connect: URI=%s "
1567 "%s, ldap_start_tls failed (%d)\n",
1569 sb->sb_tls == SB_TLS_CRITICAL ?
1570 "Error" : "Warning",
1572 if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1578 if ( sb->sb_method == LDAP_AUTH_SASL ) {
1579 #ifdef HAVE_CYRUS_SASL
1582 if ( sb->sb_secprops != NULL ) {
1583 rc = ldap_set_option( ld,
1584 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1586 if( rc != LDAP_OPT_SUCCESS ) {
1587 Debug( LDAP_DEBUG_ANY,
1588 "slap_client_connect: "
1589 "error, ldap_set_option "
1590 "(%s,SECPROPS,\"%s\") failed!\n",
1591 sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1596 defaults = lutil_sasl_defaults( ld,
1597 sb->sb_saslmech.bv_val,
1598 sb->sb_realm.bv_val,
1599 sb->sb_authcId.bv_val,
1601 sb->sb_authzId.bv_val );
1602 if ( defaults == NULL ) {
1607 rc = ldap_sasl_interactive_bind_s( ld,
1608 sb->sb_binddn.bv_val,
1609 sb->sb_saslmech.bv_val,
1612 lutil_sasl_interact,
1615 lutil_sasl_freedefs( defaults );
1617 /* FIXME: different error behaviors according to
1619 * 2) on err policy : exit, retry, backoff ...
1621 if ( rc != LDAP_SUCCESS ) {
1622 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1624 Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1625 "ldap_sasl_interactive_bind_s failed (%d)\n",
1626 sb->sb_uri.bv_val, rc, 0 );
1628 /* FIXME (see above comment) */
1629 /* if Kerberos credentials cache is not active, retry */
1630 if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1631 rc == LDAP_LOCAL_ERROR )
1633 rc = LDAP_SERVER_DOWN;
1638 #else /* HAVE_CYRUS_SASL */
1639 /* Should never get here, we trapped this at config time */
1641 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1646 } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1647 rc = ldap_sasl_bind_s( ld,
1648 sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1649 &sb->sb_cred, NULL, NULL, NULL );
1650 if ( rc != LDAP_SUCCESS ) {
1651 Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1653 "ldap_sasl_bind_s failed (%d)\n",
1654 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1662 ldap_unbind_ext( ld, NULL, NULL );
1673 /* -------------------------------------- */
1677 strtok_quote( char *line, char *sep, char **quote_ptr )
1684 if ( line != NULL ) {
1687 while ( *next && strchr( sep, *next ) ) {
1691 if ( *next == '\0' ) {
1697 for ( inquote = 0; *next; ) {
1705 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1711 next + 1, strlen( next + 1 ) + 1 );
1712 next++; /* dont parse the escaped character */
1717 if ( strchr( sep, *next ) != NULL ) {
1731 static char buf[AC_LINE_MAX];
1733 static size_t lmax, lcur;
1735 #define CATLINE( buf ) \
1737 size_t len = strlen( buf ); \
1738 while ( lcur + len + 1 > lmax ) { \
1739 lmax += AC_LINE_MAX; \
1740 line = (char *) ch_realloc( line, lmax ); \
1742 strcpy( line + lcur, buf ); \
1747 fp_getline_init(ConfigArgs *c) {
1753 fp_getline( FILE *fp, ConfigArgs *c )
1761 /* avoid stack of bufs */
1762 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1768 while ( fgets( buf, sizeof( buf ), fp ) ) {
1769 p = strchr( buf, '\n' );
1771 if ( p > buf && p[-1] == '\r' ) {
1779 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1786 if ( !isspace( (unsigned char)buf[0] ) ) {
1797 return(line[0] ? 1 : 0);
1801 fp_parse_line(ConfigArgs *c)
1804 static char *const hide[] = {
1805 "rootpw", "replica", "syncrepl", /* in slapd */
1806 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1807 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1808 "pseudorootpw", /* in back-meta */
1809 "dbpasswd", /* in back-sql */
1813 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1815 c->tline = ch_strdup(c->line);
1816 token = strtok_quote(c->tline, " \t", "e_ptr);
1818 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1819 if(quote_ptr) *quote_ptr = ' ';
1820 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1821 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1822 if(quote_ptr) *quote_ptr = '\0';
1824 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1825 if(c->argc >= c->argv_size) {
1827 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1829 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1833 c->argv_size += ARGS_STEP;
1837 c->argv[c->argc++] = token;
1839 c->argv[c->argc] = NULL;
1846 ucdata_unload( UCDATA_ALL );
1848 /* NOTE: in case of early exit, frontendDB can be NULL */
1849 if ( frontendDB->be_schemandn.bv_val )
1850 free( frontendDB->be_schemandn.bv_val );
1851 if ( frontendDB->be_schemadn.bv_val )
1852 free( frontendDB->be_schemadn.bv_val );
1853 if ( frontendDB->be_acl )
1854 acl_destroy( frontendDB->be_acl, NULL );
1857 if ( slapd_args_file )
1858 free ( slapd_args_file );
1859 if ( slapd_pid_file )
1860 free ( slapd_pid_file );
1861 if ( default_passwd_hash )
1862 ldap_charray_free( default_passwd_hash );
1866 slap_str2clist( char ***out, char *in, const char *brkstr )
1874 /* find last element in list */
1875 for (i = 0; *out && (*out)[i]; i++);
1877 /* protect the input string from strtok */
1878 str = ch_strdup( in );
1880 if ( *str == '\0' ) {
1885 /* Count words in string */
1887 for ( s = str; *s; s++ ) {
1888 if ( strchr( brkstr, *s ) != NULL ) {
1893 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1895 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1897 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1899 *new = ch_strdup( s );
1908 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1909 int argc, char **argv )
1911 ConfigArgs c = { 0 };
1922 c.op = SLAP_CONFIG_ADD;
1923 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1925 rc = SLAP_CONF_UNKNOWN;
1926 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1928 c.table = be->be_cf_ocs->co_type;
1929 rc = config_add_vals( ct, &c );