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"
57 #include <openssl/ssl.h>
63 * defaults for various global variables
65 slap_mask_t global_allows = 0;
66 slap_mask_t global_disallows = 0;
67 int global_gentlehup = 0;
68 int global_idletimeout = 0;
69 char *global_host = NULL;
70 char *global_realm = NULL;
71 char **default_passwd_hash = NULL;
72 struct berval default_search_base = BER_BVNULL;
73 struct berval default_search_nbase = BER_BVNULL;
75 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
76 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
78 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
79 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
81 char *slapd_pid_file = NULL;
82 char *slapd_args_file = NULL;
84 int use_reverse_lookup = 0;
87 int slapi_plugins_used = 0;
90 static int fp_getline(FILE *fp, ConfigArgs *c);
91 static void fp_getline_init(ConfigArgs *c);
92 static int fp_parse_line(ConfigArgs *c);
94 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
95 static char *strtok_quote_ldif(char **line);
98 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
101 c = ch_calloc( 1, sizeof( ConfigArgs ) );
102 if ( c == NULL ) return(NULL);
108 snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
113 init_config_argv( ConfigArgs *c )
115 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
116 c->argv_size = ARGS_STEP + 1;
119 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
122 for(i = 0; Conf[i].name; i++)
123 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
124 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
125 if ( !Conf[i].name ) return NULL;
129 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
130 int rc, arg_user, arg_type, arg_syn, iarg;
134 if(Conf->arg_type == ARG_IGNORED) {
135 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
136 c->log, Conf->name, 0);
139 arg_type = Conf->arg_type & ARGS_TYPES;
140 arg_user = Conf->arg_type & ARGS_USERLAND;
141 arg_syn = Conf->arg_type & ARGS_SYNTAX;
143 if((arg_type == ARG_DN) && c->argc == 1) {
147 if(Conf->min_args && (c->argc < Conf->min_args)) {
148 snprintf( c->msg, sizeof( c->msg ), "<%s> missing <%s> argument",
149 c->argv[0], Conf->what );
150 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n", c->log, c->msg, 0 );
151 return(ARG_BAD_CONF);
153 if(Conf->max_args && (c->argc > Conf->max_args)) {
154 char *ignored = " ignored";
156 snprintf( c->msg, sizeof( c->msg ), "<%s> extra cruft after <%s>",
157 c->argv[0], Conf->what );
160 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s%s.\n",
161 c->log, c->msg, ignored );
162 return(ARG_BAD_CONF);
164 if((arg_syn & ARG_DB) && !c->be) {
165 snprintf( c->msg, sizeof( c->msg ), "<%s> only allowed within database declaration",
167 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
169 return(ARG_BAD_CONF);
171 if((arg_syn & ARG_PRE_BI) && c->bi) {
172 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any backend %sdeclaration",
173 c->argv[0], (arg_syn & ARG_PRE_DB) ? "or database " : "" );
174 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
176 return(ARG_BAD_CONF);
178 if((arg_syn & ARG_PRE_DB) && c->be && c->be != frontendDB) {
179 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any database declaration",
181 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
183 return(ARG_BAD_CONF);
185 if((arg_syn & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
186 snprintf( c->msg, sizeof( c->msg ), "<%s> old format not supported", c->argv[0] );
187 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
189 return(ARG_BAD_CONF);
191 if(arg_type && !Conf->arg_item && !(arg_syn & ARG_OFFSET)) {
192 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid config_table, arg_item is NULL",
194 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
196 return(ARG_BAD_CONF);
199 memset(&c->values, 0, sizeof(c->values));
200 if(arg_type == ARG_STRING) {
202 c->value_string = ch_strdup(c->argv[1]);
203 } else if(arg_type == ARG_BERVAL) {
205 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
206 } else if(arg_type == ARG_DN) {
208 ber_str2bv( c->argv[1], 0, 0, &bv );
209 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
210 if ( rc != LDAP_SUCCESS ) {
211 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid DN %d (%s)",
212 c->argv[0], rc, ldap_err2string( rc ));
213 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n" , c->log, c->msg, 0);
214 return(ARG_BAD_CONF);
217 ch_free( c->value_ndn.bv_val );
218 ch_free( c->value_dn.bv_val );
220 } else { /* all numeric */
222 iarg = 0; larg = 0; barg = 0;
225 if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
226 snprintf( c->msg, sizeof( c->msg ),
227 "<%s> unable to parse \"%s\" as int",
228 c->argv[0], c->argv[1] );
229 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
231 return(ARG_BAD_CONF);
235 if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
236 snprintf( c->msg, sizeof( c->msg ),
237 "<%s> unable to parse \"%s\" as long",
238 c->argv[0], c->argv[1] );
239 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
241 return(ARG_BAD_CONF);
244 case ARG_BER_LEN_T: {
246 if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
247 snprintf( c->msg, sizeof( c->msg ),
248 "<%s> unable to parse \"%s\" as ber_len_t",
249 c->argv[0], c->argv[1] );
250 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
252 return(ARG_BAD_CONF);
259 } else if ( !strcasecmp(c->argv[1], "on") ||
260 !strcasecmp(c->argv[1], "true") ||
261 !strcasecmp(c->argv[1], "yes") )
264 } else if ( !strcasecmp(c->argv[1], "off") ||
265 !strcasecmp(c->argv[1], "false") ||
266 !strcasecmp(c->argv[1], "no") )
270 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
272 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
274 return(ARG_BAD_CONF);
278 j = (arg_type & ARG_NONZERO) ? 1 : 0;
279 if(iarg < j && larg < j && barg < j ) {
280 larg = larg ? larg : (barg ? barg : iarg);
281 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
283 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
285 return(ARG_BAD_CONF);
289 case ARG_INT: c->value_int = iarg; break;
290 case ARG_LONG: c->value_long = larg; break;
291 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
297 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
301 arg_type = Conf->arg_type;
302 if(arg_type & ARG_MAGIC) {
303 if(!c->be) c->be = frontendDB;
305 rc = (*((ConfigDriver*)Conf->arg_item))(c);
307 if(c->be == frontendDB) c->be = NULL;
311 snprintf( c->msg, sizeof( c->msg ), "<%s> handler exited with %d",
313 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
316 return(ARG_BAD_CONF);
320 if(arg_type & ARG_OFFSET) {
321 if (c->be && (!overlay_is_over(c->be) ||
322 ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
323 ptr = c->be->be_private;
325 ptr = c->bi->bi_private;
327 snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
329 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
331 return(ARG_BAD_CONF);
333 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
334 } else if (arg_type & ARGS_TYPES) {
335 ptr = Conf->arg_item;
337 if(arg_type & ARGS_TYPES)
338 switch(arg_type & ARGS_TYPES) {
340 case ARG_INT: *(int*)ptr = c->value_int; break;
341 case ARG_LONG: *(long*)ptr = c->value_long; break;
342 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
344 char *cc = *(char**)ptr;
346 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
347 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
348 c->log, Conf->name, 0 );
349 return(ARG_BAD_CONF);
353 *(char **)ptr = c->value_string;
357 *(struct berval *)ptr = c->value_bv;
363 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
366 arg_type = Conf->arg_type;
367 if(arg_type == ARG_IGNORED) {
368 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
369 c->log, Conf->name, 0);
372 rc = config_check_vals( Conf, c, 0 );
374 return config_set_vals( Conf, c );
378 config_del_vals(ConfigTable *cf, ConfigArgs *c)
382 /* If there is no handler, just ignore it */
383 if ( cf->arg_type & ARG_MAGIC ) {
384 c->op = LDAP_MOD_DELETE;
385 c->type = cf->arg_type & ARGS_USERLAND;
386 rc = (*((ConfigDriver*)cf->arg_item))(c);
392 config_get_vals(ConfigTable *cf, ConfigArgs *c)
398 if ( cf->arg_type & ARG_IGNORED ) {
402 memset(&c->values, 0, sizeof(c->values));
403 c->rvalue_vals = NULL;
404 c->rvalue_nvals = NULL;
405 c->op = SLAP_CONFIG_EMIT;
406 c->type = cf->arg_type & ARGS_USERLAND;
408 if ( cf->arg_type & ARG_MAGIC ) {
409 rc = (*((ConfigDriver*)cf->arg_item))(c);
412 if ( cf->arg_type & ARG_OFFSET ) {
413 if (c->be && (!overlay_is_over(c->be) ||
414 ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
415 ptr = c->be->be_private;
417 ptr = c->bi->bi_private;
420 ptr = (void *)((char *)ptr + (long)cf->arg_item);
425 switch(cf->arg_type & ARGS_TYPES) {
427 case ARG_INT: c->value_int = *(int *)ptr; break;
428 case ARG_LONG: c->value_long = *(long *)ptr; break;
429 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
432 c->value_string = ch_strdup(*(char **)ptr);
435 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
438 if ( cf->arg_type & ARGS_TYPES) {
441 switch(cf->arg_type & ARGS_TYPES) {
442 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
443 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
444 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
445 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
446 c->value_int ? "TRUE" : "FALSE"); break;
448 if ( c->value_string && c->value_string[0]) {
449 ber_str2bv( c->value_string, 0, 0, &bv);
455 if ( !BER_BVISEMPTY( &c->value_bv )) {
465 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
468 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
469 ber_bvarray_add(&c->rvalue_vals, &bv);
470 } else if ( !BER_BVISNULL( &bv ) ) {
471 value_add_one(&c->rvalue_vals, &bv);
473 /* else: maybe c->rvalue_vals already set? */
479 init_config_attrs(ConfigTable *ct) {
482 for (i=0; ct[i].name; i++ ) {
483 if ( !ct[i].attribute ) continue;
484 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
486 fprintf( stderr, "init_config_attrs: register_at failed\n" );
490 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
498 init_config_ocs( ConfigOCs *ocs ) {
501 for (i=0;ocs[i].co_def;i++) {
502 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
504 fprintf( stderr, "init_config_ocs: register_oc failed\n" );
508 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
514 /* Split an LDIF line into space-separated tokens. Words may be grouped
515 * by quotes. A quoted string may begin in the middle of a word, but must
516 * end at the end of the word (be followed by whitespace or EOS). Any other
517 * quotes are passed through unchanged. All other characters are passed
521 strtok_quote_ldif( char **line )
523 char *beg, *ptr, *quote=NULL;
531 while( isspace( (unsigned char) *ptr )) ptr++;
542 if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
552 if ( isspace( (unsigned char) *ptr )) {
558 while ( quote < ptr ) {
566 while ( isspace( (unsigned char) *ptr )) ptr++;
573 config_parse_ldif( ConfigArgs *c )
576 c->tline = ch_strdup(c->line);
579 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
581 if ( c->argc >= c->argv_size ) {
582 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
585 c->argv_size += ARGS_STEP;
588 c->argv[c->argc] = NULL;
592 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
596 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
597 ct->ad->ad_cname.bv_val, valx );
599 c->argv[0] = ct->ad->ad_cname.bv_val;
601 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
602 c->argv[c->argc] = c->line;
604 c->argv[c->argc] = NULL;
607 config_parse_ldif( c );
609 rc = config_check_vals( ct, c, 1 );
614 rc = LDAP_CONSTRAINT_VIOLATION;
620 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
624 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
625 ct->ad->ad_cname.bv_val, valx );
627 c->argv[0] = ct->ad->ad_cname.bv_val;
629 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
630 c->argv[c->argc] = c->line;
632 c->argv[c->argc] = NULL;
635 config_parse_ldif( c );
637 c->op = LDAP_MOD_ADD;
638 rc = config_add_vals( ct, c );
645 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
653 c = ch_calloc( 1, sizeof( ConfigArgs ) );
659 memcpy( c, cf, sizeof( ConfigArgs ) );
661 c->depth = depth; /* XXX */
668 init_config_argv( c );
670 if ( stat( fname, &s ) != 0 ) {
672 Debug(LDAP_DEBUG_ANY,
673 "could not stat config file \"%s\": %s (%d)\n",
674 fname, strerror(errno), errno);
679 if ( !S_ISREG( s.st_mode ) ) {
681 Debug(LDAP_DEBUG_ANY,
682 "regular file expected, got \"%s\"\n",
688 fp = fopen( fname, "r" );
691 Debug(LDAP_DEBUG_ANY,
692 "could not open config file \"%s\": %s (%d)\n",
693 fname, strerror(errno), errno);
698 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
704 while ( fp_getline( fp, c ) ) {
705 /* skip comments and blank lines */
706 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
710 snprintf( c->log, sizeof( c->log ), "%s: line %d",
711 c->fname, c->lineno );
715 if ( fp_parse_line( c ) ) {
721 Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
727 c->op = SLAP_CONFIG_ADD;
729 ct = config_find_keyword( cft, c );
731 rc = config_add_vals( ct, c );
734 if ( rc & ARGS_USERLAND ) {
735 /* XXX a usertype would be opaque here */
736 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
737 c->log, c->argv[0], 0);
741 } else if ( rc == ARG_BAD_CONF ) {
746 } else if ( c->bi && !c->be ) {
747 rc = SLAP_CONF_UNKNOWN;
748 if ( c->bi->bi_cf_ocs ) {
749 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
751 rc = config_add_vals( ct, c );
754 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
755 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
760 case SLAP_CONF_UNKNOWN:
761 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
762 "<%s> inside backend info definition.\n",
763 c->log, *c->argv, 0);
770 } else if ( c->be && c->be != frontendDB ) {
771 rc = SLAP_CONF_UNKNOWN;
772 if ( c->be->be_cf_ocs ) {
773 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
775 rc = config_add_vals( ct, c );
778 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
779 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
782 if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
784 /* global overlays may need
785 * definitions inside other databases...
787 rc = (*frontendDB->be_config)( frontendDB,
788 c->fname, (int)c->lineno, c->argc, c->argv );
795 case SLAP_CONF_UNKNOWN:
796 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
797 "<%s> inside backend database definition.\n",
798 c->log, *c->argv, 0);
805 } else if ( frontendDB->be_config ) {
806 rc = (*frontendDB->be_config)( frontendDB,
807 c->fname, (int)c->lineno, c->argc, c->argv);
810 case SLAP_CONF_UNKNOWN:
811 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
812 "<%s> inside global database definition.\n",
813 c->log, *c->argv, 0);
822 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
823 "<%s> outside backend info and database definitions.\n",
824 c->log, *c->argv, 0);
840 /* restrictops, allows, disallows, requires, loglevel */
843 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
845 for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
846 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
852 verb_to_mask(const char *word, slap_verbmasks *v) {
854 ber_str2bv( word, 0, 0, &bword );
855 return bverb_to_mask( &bword, v );
859 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
861 for(i = 1; i < argc; i++) {
862 j = verb_to_mask(argv[i], v);
863 if(BER_BVISNULL(&v[j].word)) return i;
864 while (!v[j].mask) j--;
870 /* Mask keywords that represent multiple bits should occur before single
871 * bit keywords in the verbmasks array.
874 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
878 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
879 if (!v[i].mask) continue;
880 if (( m & v[i].mask ) == v[i].mask ) {
881 value_add_one( bva, &v[i].word );
892 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
896 assert( *vp == NULL );
898 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
900 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
902 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
903 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
904 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
907 BER_BVZERO( &(*vp)[ i ].word );
913 slap_verbmasks_destroy( slap_verbmasks *v )
919 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
920 ch_free( v[ i ].word.bv_val );
929 slap_verbmasks_append(
933 slap_mask_t *ignore )
938 return LDAP_OPERATIONS_ERROR;
941 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
942 if ( !(*vp)[ i ].mask ) continue;
944 if ( ignore != NULL ) {
947 for ( j = 0; ignore[ j ] != 0; j++ ) {
948 if ( (*vp)[ i ].mask == ignore[ j ] ) {
954 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
955 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
956 /* already set; ignore */
960 return LDAP_TYPE_OR_VALUE_EXISTS;
963 if ( m & (*vp)[ i ].mask ) {
965 return LDAP_CONSTRAINT_VIOLATION;
970 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
971 ber_dupbv( &(*vp)[ i ].word, v );
972 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
973 BER_BVZERO( &(*vp)[ i + 1 ].word );
979 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
982 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
983 if ( m == v[i].mask ) {
994 static slap_verbmasks tlskey[] = {
995 { BER_BVC("no"), SB_TLS_OFF },
996 { BER_BVC("yes"), SB_TLS_ON },
997 { BER_BVC("critical"), SB_TLS_CRITICAL },
1001 static slap_verbmasks crlkeys[] = {
1002 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1003 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1004 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1008 static slap_verbmasks vfykeys[] = {
1009 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1010 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1011 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1012 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1017 static slap_verbmasks methkey[] = {
1018 { BER_BVC("none"), LDAP_AUTH_NONE },
1019 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
1020 #ifdef HAVE_CYRUS_SASL
1021 { BER_BVC("sasl"), LDAP_AUTH_SASL },
1026 static slap_verbmasks versionkey[] = {
1027 { BER_BVC("2"), LDAP_VERSION2 },
1028 { BER_BVC("3"), LDAP_VERSION3 },
1032 static slap_cf_aux_table bindkey[] = {
1033 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1034 { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1035 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1036 { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
1037 { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
1038 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1039 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1040 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1041 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1042 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1043 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, (slap_verbmasks *)authzNormalize },
1044 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1046 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1048 /* NOTE: replace "13" with the actual index
1049 * of the first TLS-related line */
1050 #define aux_TLS (bindkey+13) /* beginning of TLS keywords */
1052 { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1053 { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1054 { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1055 { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1056 { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1057 { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1058 #ifdef HAVE_OPENSSL_CRL
1059 { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1062 { BER_BVNULL, 0, 0, 0, NULL }
1067 * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1068 * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1071 * 'U': unsigned long
1075 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1077 int rc = SLAP_CONF_UNKNOWN;
1078 slap_cf_aux_table *tab;
1080 for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1081 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1086 unsigned long *ulptr;
1087 struct berval *bptr;
1088 const char *val = word + tab->key.bv_len;
1090 switch ( tab->type ) {
1092 cptr = (char **)((char *)dst + tab->off);
1093 *cptr = ch_strdup( val );
1098 bptr = (struct berval *)((char *)dst + tab->off);
1099 if ( tab->aux != NULL ) {
1101 slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1103 ber_str2bv( val, 0, 0, &dn );
1104 rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1107 ber_str2bv( val, 0, 1, bptr );
1113 iptr = (int *)((char *)dst + tab->off);
1115 if ( tab->aux != NULL ) {
1116 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1118 assert( aux != NULL );
1121 for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1122 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1123 *iptr = aux[j].mask;
1130 rc = lutil_atoix( iptr, val, 0 );
1135 uptr = (unsigned *)((char *)dst + tab->off);
1137 rc = lutil_atoux( uptr, val, 0 );
1141 lptr = (long *)((char *)dst + tab->off);
1143 rc = lutil_atolx( lptr, val, 0 );
1147 ulptr = (unsigned long *)((char *)dst + tab->off);
1149 rc = lutil_atoulx( ulptr, val, 0 );
1154 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1166 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1168 char buf[AC_LINE_MAX], *ptr;
1169 slap_cf_aux_table *tab;
1173 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1178 unsigned long *ulptr;
1179 struct berval *bptr;
1181 cptr = (char **)((char *)src + tab->off);
1183 switch ( tab->type ) {
1185 bptr = (struct berval *)((char *)src + tab->off);
1186 cptr = &bptr->bv_val;
1191 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1192 if ( tab->quote ) *ptr++ = '"';
1193 ptr = lutil_strcopy( ptr, *cptr );
1194 if ( tab->quote ) *ptr++ = '"';
1199 iptr = (int *)((char *)src + tab->off);
1201 if ( tab->aux != NULL ) {
1202 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1204 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1205 if ( *iptr == aux[i].mask ) {
1207 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1208 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1215 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1216 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1221 uptr = (unsigned *)((char *)src + tab->off);
1223 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1224 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1228 lptr = (long *)((char *)src + tab->off);
1230 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1231 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1235 ulptr = (unsigned long *)((char *)src + tab->off);
1237 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1238 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1246 tmp.bv_len = ptr - buf;
1247 ber_dupbv( bv, &tmp );
1252 slap_tls_get_config( LDAP *ld, int opt, char **val )
1254 slap_verbmasks *keys;
1260 case LDAP_OPT_X_TLS_CRLCHECK:
1263 case LDAP_OPT_X_TLS_REQUIRE_CERT:
1270 ldap_pvt_tls_get_option( ld, opt, &ival );
1271 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1272 if (keys[i].mask == ival) {
1273 *val = ch_strdup( keys[i].word.bv_val );
1281 bindconf_tls_parse( const char *word, slap_bindconf *bc )
1284 if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1285 bc->sb_tls_do_init = 1;
1293 bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
1296 return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
1302 bindconf_parse( const char *word, slap_bindconf *bc )
1305 /* Detect TLS config changes explicitly */
1306 if ( bindconf_tls_parse( word, bc ) == 0 ) {
1310 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1314 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1316 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1319 void bindconf_free( slap_bindconf *bc ) {
1320 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1321 ch_free( bc->sb_uri.bv_val );
1322 BER_BVZERO( &bc->sb_uri );
1324 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1325 ch_free( bc->sb_binddn.bv_val );
1326 BER_BVZERO( &bc->sb_binddn );
1328 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1329 ch_free( bc->sb_cred.bv_val );
1330 BER_BVZERO( &bc->sb_cred );
1332 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1333 ch_free( bc->sb_saslmech.bv_val );
1334 BER_BVZERO( &bc->sb_saslmech );
1336 if ( bc->sb_secprops ) {
1337 ch_free( bc->sb_secprops );
1338 bc->sb_secprops = NULL;
1340 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1341 ch_free( bc->sb_realm.bv_val );
1342 BER_BVZERO( &bc->sb_realm );
1344 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1345 ch_free( bc->sb_authcId.bv_val );
1346 BER_BVZERO( &bc->sb_authcId );
1348 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1349 ch_free( bc->sb_authzId.bv_val );
1350 BER_BVZERO( &bc->sb_authzId );
1354 if ( bc->sb_tls_ctx ) {
1355 SSL_CTX_free( bc->sb_tls_ctx );
1356 bc->sb_tls_ctx = NULL;
1359 if ( bc->sb_tls_cert ) {
1360 ch_free( bc->sb_tls_cert );
1361 bc->sb_tls_cert = NULL;
1363 if ( bc->sb_tls_key ) {
1364 ch_free( bc->sb_tls_key );
1365 bc->sb_tls_key = NULL;
1367 if ( bc->sb_tls_cacert ) {
1368 ch_free( bc->sb_tls_cacert );
1369 bc->sb_tls_cacert = NULL;
1371 if ( bc->sb_tls_cacertdir ) {
1372 ch_free( bc->sb_tls_cacertdir );
1373 bc->sb_tls_cacertdir = NULL;
1375 if ( bc->sb_tls_reqcert ) {
1376 ch_free( bc->sb_tls_reqcert );
1377 bc->sb_tls_reqcert = NULL;
1379 if ( bc->sb_tls_cipher_suite ) {
1380 ch_free( bc->sb_tls_cipher_suite );
1381 bc->sb_tls_cipher_suite = NULL;
1383 #ifdef HAVE_OPENSSL_CRL
1384 if ( bc->sb_tls_crlcheck ) {
1385 ch_free( bc->sb_tls_crlcheck );
1386 bc->sb_tls_crlcheck = NULL;
1393 bindconf_tls_defaults( slap_bindconf *bc )
1396 if ( bc->sb_tls_do_init ) {
1397 if ( !bc->sb_tls_cacert )
1398 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1399 &bc->sb_tls_cacert );
1400 if ( !bc->sb_tls_cacertdir )
1401 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1402 &bc->sb_tls_cacertdir );
1403 if ( !bc->sb_tls_cert )
1404 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1406 if ( !bc->sb_tls_key )
1407 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1409 if ( !bc->sb_tls_cipher_suite )
1410 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1411 &bc->sb_tls_cipher_suite );
1412 if ( !bc->sb_tls_reqcert )
1413 bc->sb_tls_reqcert = ch_strdup("demand");
1414 #ifdef HAVE_OPENSSL_CRL
1415 if ( !bc->sb_tls_crlcheck )
1416 slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1417 &bc->sb_tls_crlcheck );
1429 { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1430 { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1431 { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1432 { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1433 { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1437 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1439 int i, rc, newctx = 0, res = 0;
1440 char *ptr = (char *)bc, **word;
1442 bc->sb_tls_do_init = 0;
1444 for (i=0; bindtlsopts[i].opt; i++) {
1445 word = (char **)(ptr + bindtlsopts[i].offset);
1447 rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1449 Debug( LDAP_DEBUG_ANY,
1450 "bindconf_tls_set: failed to set %s to %s\n",
1451 bindtlsopts[i].key, *word, 0 );
1457 if ( bc->sb_tls_reqcert ) {
1458 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1459 bc->sb_tls_reqcert );
1461 Debug( LDAP_DEBUG_ANY,
1462 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1463 bc->sb_tls_reqcert, 0, 0 );
1468 #ifdef HAVE_OPENSSL_CRL
1469 if ( bc->sb_tls_crlcheck ) {
1470 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1471 bc->sb_tls_crlcheck );
1473 Debug( LDAP_DEBUG_ANY,
1474 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1475 bc->sb_tls_crlcheck, 0, 0 );
1484 if ( bc->sb_tls_ctx ) {
1485 SSL_CTX_free( bc->sb_tls_ctx );
1486 bc->sb_tls_ctx = NULL;
1488 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1492 ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1500 * connect to a client using the bindconf data
1501 * note: should move "version" into bindconf...
1504 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1510 /* Init connection to master */
1511 rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1512 if ( rc != LDAP_SUCCESS ) {
1513 Debug( LDAP_DEBUG_ANY,
1514 "slap_client_connect: "
1515 "ldap_initialize(%s) failed (%d)\n",
1516 sb->sb_uri.bv_val, rc, 0 );
1520 if ( sb->sb_version != 0 ) {
1521 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1522 (const void *)&sb->sb_version );
1525 if ( sb->sb_timeout_api ) {
1526 tv.tv_sec = sb->sb_timeout_api;
1528 ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
1531 if ( sb->sb_timeout_net ) {
1532 tv.tv_sec = sb->sb_timeout_net;
1534 ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
1538 if ( sb->sb_tls_do_init ) {
1539 rc = bindconf_tls_set( sb, ld );
1541 } else if ( sb->sb_tls_ctx ) {
1542 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1547 Debug( LDAP_DEBUG_ANY,
1548 "slap_client_connect: "
1549 "URI=%s TLS context initialization failed (%d)\n",
1550 sb->sb_uri.bv_val, rc, 0 );
1557 rc = ldap_start_tls_s( ld, NULL, NULL );
1558 if ( rc != LDAP_SUCCESS ) {
1559 Debug( LDAP_DEBUG_ANY,
1560 "slap_client_connect: URI=%s "
1561 "%s, ldap_start_tls failed (%d)\n",
1563 sb->sb_tls == SB_TLS_CRITICAL ?
1564 "Error" : "Warning",
1566 if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1572 if ( sb->sb_method == LDAP_AUTH_SASL ) {
1573 #ifdef HAVE_CYRUS_SASL
1576 if ( sb->sb_secprops != NULL ) {
1577 rc = ldap_set_option( ld,
1578 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1580 if( rc != LDAP_OPT_SUCCESS ) {
1581 Debug( LDAP_DEBUG_ANY,
1582 "slap_client_connect: "
1583 "error, ldap_set_option "
1584 "(%s,SECPROPS,\"%s\") failed!\n",
1585 sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1590 defaults = lutil_sasl_defaults( ld,
1591 sb->sb_saslmech.bv_val,
1592 sb->sb_realm.bv_val,
1593 sb->sb_authcId.bv_val,
1595 sb->sb_authzId.bv_val );
1597 rc = ldap_sasl_interactive_bind_s( ld,
1598 sb->sb_binddn.bv_val,
1599 sb->sb_saslmech.bv_val,
1602 lutil_sasl_interact,
1605 lutil_sasl_freedefs( defaults );
1607 /* FIXME: different error behaviors according to
1609 * 2) on err policy : exit, retry, backoff ...
1611 if ( rc != LDAP_SUCCESS ) {
1612 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1614 Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1615 "ldap_sasl_interactive_bind_s failed (%d)\n",
1616 sb->sb_uri.bv_val, rc, 0 );
1618 /* FIXME (see above comment) */
1619 /* if Kerberos credentials cache is not active, retry */
1620 if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1621 rc == LDAP_LOCAL_ERROR )
1623 rc = LDAP_SERVER_DOWN;
1628 #else /* HAVE_CYRUS_SASL */
1629 /* Should never get here, we trapped this at config time */
1631 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1636 } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1637 rc = ldap_sasl_bind_s( ld,
1638 sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1639 &sb->sb_cred, NULL, NULL, NULL );
1640 if ( rc != LDAP_SUCCESS ) {
1641 Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1643 "ldap_sasl_bind_s failed (%d)\n",
1644 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1652 ldap_unbind_ext( ld, NULL, NULL );
1663 /* -------------------------------------- */
1667 strtok_quote( char *line, char *sep, char **quote_ptr )
1674 if ( line != NULL ) {
1677 while ( *next && strchr( sep, *next ) ) {
1681 if ( *next == '\0' ) {
1687 for ( inquote = 0; *next; ) {
1695 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1701 next + 1, strlen( next + 1 ) + 1 );
1702 next++; /* dont parse the escaped character */
1707 if ( strchr( sep, *next ) != NULL ) {
1721 static char buf[AC_LINE_MAX];
1723 static size_t lmax, lcur;
1725 #define CATLINE( buf ) \
1727 size_t len = strlen( buf ); \
1728 while ( lcur + len + 1 > lmax ) { \
1729 lmax += AC_LINE_MAX; \
1730 line = (char *) ch_realloc( line, lmax ); \
1732 strcpy( line + lcur, buf ); \
1737 fp_getline_init(ConfigArgs *c) {
1743 fp_getline( FILE *fp, ConfigArgs *c )
1751 /* avoid stack of bufs */
1752 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1758 while ( fgets( buf, sizeof( buf ), fp ) ) {
1759 p = strchr( buf, '\n' );
1761 if ( p > buf && p[-1] == '\r' ) {
1769 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1776 if ( !isspace( (unsigned char)buf[0] ) ) {
1787 return(line[0] ? 1 : 0);
1791 fp_parse_line(ConfigArgs *c)
1794 static char *const hide[] = {
1795 "rootpw", "replica", "syncrepl", /* in slapd */
1796 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1797 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1798 "pseudorootpw", /* in back-meta */
1799 "dbpasswd", /* in back-sql */
1803 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1805 c->tline = ch_strdup(c->line);
1806 token = strtok_quote(c->tline, " \t", "e_ptr);
1808 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1809 if(quote_ptr) *quote_ptr = ' ';
1810 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1811 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1812 if(quote_ptr) *quote_ptr = '\0';
1814 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1815 if(c->argc >= c->argv_size) {
1817 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1819 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1823 c->argv_size += ARGS_STEP;
1827 c->argv[c->argc++] = token;
1829 c->argv[c->argc] = NULL;
1836 ucdata_unload( UCDATA_ALL );
1838 /* NOTE: in case of early exit, frontendDB can be NULL */
1839 if ( frontendDB->be_schemandn.bv_val )
1840 free( frontendDB->be_schemandn.bv_val );
1841 if ( frontendDB->be_schemadn.bv_val )
1842 free( frontendDB->be_schemadn.bv_val );
1843 if ( frontendDB->be_acl )
1844 acl_destroy( frontendDB->be_acl, NULL );
1847 if ( slapd_args_file )
1848 free ( slapd_args_file );
1849 if ( slapd_pid_file )
1850 free ( slapd_pid_file );
1851 if ( default_passwd_hash )
1852 ldap_charray_free( default_passwd_hash );
1856 slap_str2clist( char ***out, char *in, const char *brkstr )
1864 /* find last element in list */
1865 for (i = 0; *out && (*out)[i]; i++);
1867 /* protect the input string from strtok */
1868 str = ch_strdup( in );
1870 if ( *str == '\0' ) {
1875 /* Count words in string */
1877 for ( s = str; *s; s++ ) {
1878 if ( strchr( brkstr, *s ) != NULL ) {
1883 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1885 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1887 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1889 *new = ch_strdup( s );
1898 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1899 int argc, char **argv )
1901 ConfigArgs c = { 0 };
1912 c.op = SLAP_CONFIG_ADD;
1913 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1915 rc = SLAP_CONF_UNKNOWN;
1916 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1918 rc = config_add_vals( ct, &c );