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 && c->table == Cft_Database)
322 ptr = c->be->be_private;
324 ptr = c->bi->bi_private;
326 snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
328 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
330 return(ARG_BAD_CONF);
332 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
333 } else if (arg_type & ARGS_TYPES) {
334 ptr = Conf->arg_item;
336 if(arg_type & ARGS_TYPES)
337 switch(arg_type & ARGS_TYPES) {
339 case ARG_INT: *(int*)ptr = c->value_int; break;
340 case ARG_LONG: *(long*)ptr = c->value_long; break;
341 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
343 char *cc = *(char**)ptr;
345 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
346 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
347 c->log, Conf->name, 0 );
348 return(ARG_BAD_CONF);
352 *(char **)ptr = c->value_string;
356 *(struct berval *)ptr = c->value_bv;
362 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
365 arg_type = Conf->arg_type;
366 if(arg_type == ARG_IGNORED) {
367 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
368 c->log, Conf->name, 0);
371 rc = config_check_vals( Conf, c, 0 );
373 return config_set_vals( Conf, c );
377 config_del_vals(ConfigTable *cf, ConfigArgs *c)
381 /* If there is no handler, just ignore it */
382 if ( cf->arg_type & ARG_MAGIC ) {
383 c->op = LDAP_MOD_DELETE;
384 c->type = cf->arg_type & ARGS_USERLAND;
385 rc = (*((ConfigDriver*)cf->arg_item))(c);
391 config_get_vals(ConfigTable *cf, ConfigArgs *c)
397 if ( cf->arg_type & ARG_IGNORED ) {
401 memset(&c->values, 0, sizeof(c->values));
402 c->rvalue_vals = NULL;
403 c->rvalue_nvals = NULL;
404 c->op = SLAP_CONFIG_EMIT;
405 c->type = cf->arg_type & ARGS_USERLAND;
407 if ( cf->arg_type & ARG_MAGIC ) {
408 rc = (*((ConfigDriver*)cf->arg_item))(c);
411 if ( cf->arg_type & ARG_OFFSET ) {
412 if (c->be && c->table == Cft_Database)
413 ptr = c->be->be_private;
415 ptr = c->bi->bi_private;
418 ptr = (void *)((char *)ptr + (long)cf->arg_item);
423 switch(cf->arg_type & ARGS_TYPES) {
425 case ARG_INT: c->value_int = *(int *)ptr; break;
426 case ARG_LONG: c->value_long = *(long *)ptr; break;
427 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
430 c->value_string = ch_strdup(*(char **)ptr);
433 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
436 if ( cf->arg_type & ARGS_TYPES) {
439 switch(cf->arg_type & ARGS_TYPES) {
440 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
441 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
442 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
443 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
444 c->value_int ? "TRUE" : "FALSE"); break;
446 if ( c->value_string && c->value_string[0]) {
447 ber_str2bv( c->value_string, 0, 0, &bv);
453 if ( !BER_BVISEMPTY( &c->value_bv )) {
463 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
466 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
467 ber_bvarray_add(&c->rvalue_vals, &bv);
468 } else if ( !BER_BVISNULL( &bv ) ) {
469 value_add_one(&c->rvalue_vals, &bv);
471 /* else: maybe c->rvalue_vals already set? */
477 init_config_attrs(ConfigTable *ct) {
480 for (i=0; ct[i].name; i++ ) {
481 if ( !ct[i].attribute ) continue;
482 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
484 fprintf( stderr, "init_config_attrs: register_at failed\n" );
488 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
496 init_config_ocs( ConfigOCs *ocs ) {
499 for (i=0;ocs[i].co_def;i++) {
500 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
502 fprintf( stderr, "init_config_ocs: register_oc failed\n" );
506 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
512 /* Split an LDIF line into space-separated tokens. Words may be grouped
513 * by quotes. A quoted string may begin in the middle of a word, but must
514 * end at the end of the word (be followed by whitespace or EOS). Any other
515 * quotes are passed through unchanged. All other characters are passed
519 strtok_quote_ldif( char **line )
521 char *beg, *ptr, *quote=NULL;
529 while( isspace( (unsigned char) *ptr )) ptr++;
540 if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
550 if ( isspace( (unsigned char) *ptr )) {
556 while ( quote < ptr ) {
564 while ( isspace( (unsigned char) *ptr )) ptr++;
571 config_parse_ldif( ConfigArgs *c )
574 c->tline = ch_strdup(c->line);
577 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
579 if ( c->argc >= c->argv_size ) {
580 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
583 c->argv_size += ARGS_STEP;
586 c->argv[c->argc] = NULL;
590 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
594 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
595 ct->ad->ad_cname.bv_val, valx );
597 c->argv[0] = ct->ad->ad_cname.bv_val;
599 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
600 c->argv[c->argc] = c->line;
602 c->argv[c->argc] = NULL;
605 config_parse_ldif( c );
607 rc = config_check_vals( ct, c, 1 );
612 rc = LDAP_CONSTRAINT_VIOLATION;
618 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
622 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
623 ct->ad->ad_cname.bv_val, valx );
625 c->argv[0] = ct->ad->ad_cname.bv_val;
627 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
628 c->argv[c->argc] = c->line;
630 c->argv[c->argc] = NULL;
633 config_parse_ldif( c );
635 c->op = LDAP_MOD_ADD;
636 rc = config_add_vals( ct, c );
643 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
651 c = ch_calloc( 1, sizeof( ConfigArgs ) );
657 memcpy( c, cf, sizeof( ConfigArgs ) );
659 c->depth = depth; /* XXX */
666 init_config_argv( c );
668 if ( stat( fname, &s ) != 0 ) {
670 Debug(LDAP_DEBUG_ANY,
671 "could not stat config file \"%s\": %s (%d)\n",
672 fname, strerror(errno), errno);
677 if ( !S_ISREG( s.st_mode ) ) {
679 Debug(LDAP_DEBUG_ANY,
680 "regular file expected, got \"%s\"\n",
686 fp = fopen( fname, "r" );
689 Debug(LDAP_DEBUG_ANY,
690 "could not open config file \"%s\": %s (%d)\n",
691 fname, strerror(errno), errno);
696 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
702 while ( fp_getline( fp, c ) ) {
703 /* skip comments and blank lines */
704 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
708 snprintf( c->log, sizeof( c->log ), "%s: line %d",
709 c->fname, c->lineno );
713 if ( fp_parse_line( c ) ) {
719 Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
725 c->op = SLAP_CONFIG_ADD;
727 ct = config_find_keyword( cft, c );
729 c->table = Cft_Global;
730 rc = config_add_vals( ct, c );
733 if ( rc & ARGS_USERLAND ) {
734 /* XXX a usertype would be opaque here */
735 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
736 c->log, c->argv[0], 0);
740 } else if ( rc == ARG_BAD_CONF ) {
745 } else if ( c->bi && !c->be ) {
746 rc = SLAP_CONF_UNKNOWN;
747 if ( c->bi->bi_cf_ocs ) {
748 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
750 c->table = c->bi->bi_cf_ocs->co_type;
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 c->table = c->be->be_cf_ocs->co_type;
776 rc = config_add_vals( ct, c );
779 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
780 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
783 if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
785 /* global overlays may need
786 * definitions inside other databases...
788 rc = (*frontendDB->be_config)( frontendDB,
789 c->fname, (int)c->lineno, c->argc, c->argv );
796 case SLAP_CONF_UNKNOWN:
797 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
798 "<%s> inside backend database definition.\n",
799 c->log, *c->argv, 0);
806 } else if ( frontendDB->be_config ) {
807 rc = (*frontendDB->be_config)( frontendDB,
808 c->fname, (int)c->lineno, c->argc, c->argv);
811 case SLAP_CONF_UNKNOWN:
812 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
813 "<%s> inside global database definition.\n",
814 c->log, *c->argv, 0);
823 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
824 "<%s> outside backend info and database definitions.\n",
825 c->log, *c->argv, 0);
841 /* restrictops, allows, disallows, requires, loglevel */
844 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
846 for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
847 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
853 verb_to_mask(const char *word, slap_verbmasks *v) {
855 ber_str2bv( word, 0, 0, &bword );
856 return bverb_to_mask( &bword, v );
860 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
862 for(i = 1; i < argc; i++) {
863 j = verb_to_mask(argv[i], v);
864 if(BER_BVISNULL(&v[j].word)) return i;
865 while (!v[j].mask) j--;
871 /* Mask keywords that represent multiple bits should occur before single
872 * bit keywords in the verbmasks array.
875 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
879 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
880 if (!v[i].mask) continue;
881 if (( m & v[i].mask ) == v[i].mask ) {
882 value_add_one( bva, &v[i].word );
893 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
897 assert( *vp == NULL );
899 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
901 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
903 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
904 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
905 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
908 BER_BVZERO( &(*vp)[ i ].word );
914 slap_verbmasks_destroy( slap_verbmasks *v )
920 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
921 ch_free( v[ i ].word.bv_val );
930 slap_verbmasks_append(
934 slap_mask_t *ignore )
939 return LDAP_OPERATIONS_ERROR;
942 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
943 if ( !(*vp)[ i ].mask ) continue;
945 if ( ignore != NULL ) {
948 for ( j = 0; ignore[ j ] != 0; j++ ) {
949 if ( (*vp)[ i ].mask == ignore[ j ] ) {
955 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
956 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
957 /* already set; ignore */
961 return LDAP_TYPE_OR_VALUE_EXISTS;
964 if ( m & (*vp)[ i ].mask ) {
966 return LDAP_CONSTRAINT_VIOLATION;
971 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
972 ber_dupbv( &(*vp)[ i ].word, v );
973 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
974 BER_BVZERO( &(*vp)[ i + 1 ].word );
980 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
983 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
984 if ( m == v[i].mask ) {
995 static slap_verbmasks tlskey[] = {
996 { BER_BVC("no"), SB_TLS_OFF },
997 { BER_BVC("yes"), SB_TLS_ON },
998 { BER_BVC("critical"), SB_TLS_CRITICAL },
1002 static slap_verbmasks crlkeys[] = {
1003 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1004 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1005 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1009 static slap_verbmasks vfykeys[] = {
1010 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1011 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1012 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1013 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1018 static slap_verbmasks methkey[] = {
1019 { BER_BVC("none"), LDAP_AUTH_NONE },
1020 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
1021 #ifdef HAVE_CYRUS_SASL
1022 { BER_BVC("sasl"), LDAP_AUTH_SASL },
1027 static slap_verbmasks versionkey[] = {
1028 { BER_BVC("2"), LDAP_VERSION2 },
1029 { BER_BVC("3"), LDAP_VERSION3 },
1033 static slap_cf_aux_table bindkey[] = {
1034 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1035 { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1036 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1037 { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
1038 { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
1039 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1040 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1041 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1042 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1043 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1044 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, (slap_verbmasks *)authzNormalize },
1045 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1047 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1049 /* NOTE: replace "13" with the actual index
1050 * of the first TLS-related line */
1051 #define aux_TLS (bindkey+13) /* beginning of TLS keywords */
1053 { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1054 { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1055 { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1056 { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1057 { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1058 { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1059 #ifdef HAVE_OPENSSL_CRL
1060 { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1063 { BER_BVNULL, 0, 0, 0, NULL }
1068 * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1069 * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1072 * 'U': unsigned long
1076 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1078 int rc = SLAP_CONF_UNKNOWN;
1079 slap_cf_aux_table *tab;
1081 for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1082 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1087 unsigned long *ulptr;
1088 struct berval *bptr;
1089 const char *val = word + tab->key.bv_len;
1091 switch ( tab->type ) {
1093 cptr = (char **)((char *)dst + tab->off);
1094 *cptr = ch_strdup( val );
1099 bptr = (struct berval *)((char *)dst + tab->off);
1100 if ( tab->aux != NULL ) {
1102 slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1104 ber_str2bv( val, 0, 0, &dn );
1105 rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1108 ber_str2bv( val, 0, 1, bptr );
1114 iptr = (int *)((char *)dst + tab->off);
1116 if ( tab->aux != NULL ) {
1117 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1119 assert( aux != NULL );
1122 for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1123 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1124 *iptr = aux[j].mask;
1131 rc = lutil_atoix( iptr, val, 0 );
1136 uptr = (unsigned *)((char *)dst + tab->off);
1138 rc = lutil_atoux( uptr, val, 0 );
1142 lptr = (long *)((char *)dst + tab->off);
1144 rc = lutil_atolx( lptr, val, 0 );
1148 ulptr = (unsigned long *)((char *)dst + tab->off);
1150 rc = lutil_atoulx( ulptr, val, 0 );
1155 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1167 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1169 char buf[AC_LINE_MAX], *ptr;
1170 slap_cf_aux_table *tab;
1174 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1179 unsigned long *ulptr;
1180 struct berval *bptr;
1182 cptr = (char **)((char *)src + tab->off);
1184 switch ( tab->type ) {
1186 bptr = (struct berval *)((char *)src + tab->off);
1187 cptr = &bptr->bv_val;
1192 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1193 if ( tab->quote ) *ptr++ = '"';
1194 ptr = lutil_strcopy( ptr, *cptr );
1195 if ( tab->quote ) *ptr++ = '"';
1200 iptr = (int *)((char *)src + tab->off);
1202 if ( tab->aux != NULL ) {
1203 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1205 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1206 if ( *iptr == aux[i].mask ) {
1208 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1209 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1216 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1217 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1222 uptr = (unsigned *)((char *)src + tab->off);
1224 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1225 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1229 lptr = (long *)((char *)src + tab->off);
1231 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1232 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1236 ulptr = (unsigned long *)((char *)src + tab->off);
1238 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1239 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1247 tmp.bv_len = ptr - buf;
1248 ber_dupbv( bv, &tmp );
1253 slap_tls_get_config( LDAP *ld, int opt, char **val )
1255 slap_verbmasks *keys;
1261 case LDAP_OPT_X_TLS_CRLCHECK:
1264 case LDAP_OPT_X_TLS_REQUIRE_CERT:
1271 ldap_pvt_tls_get_option( ld, opt, &ival );
1272 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1273 if (keys[i].mask == ival) {
1274 *val = ch_strdup( keys[i].word.bv_val );
1282 bindconf_tls_parse( const char *word, slap_bindconf *bc )
1285 if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1286 bc->sb_tls_do_init = 1;
1294 bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
1297 return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
1303 bindconf_parse( const char *word, slap_bindconf *bc )
1306 /* Detect TLS config changes explicitly */
1307 if ( bindconf_tls_parse( word, bc ) == 0 ) {
1311 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1315 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1317 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1320 void bindconf_free( slap_bindconf *bc ) {
1321 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1322 ch_free( bc->sb_uri.bv_val );
1323 BER_BVZERO( &bc->sb_uri );
1325 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1326 ch_free( bc->sb_binddn.bv_val );
1327 BER_BVZERO( &bc->sb_binddn );
1329 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1330 ch_free( bc->sb_cred.bv_val );
1331 BER_BVZERO( &bc->sb_cred );
1333 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1334 ch_free( bc->sb_saslmech.bv_val );
1335 BER_BVZERO( &bc->sb_saslmech );
1337 if ( bc->sb_secprops ) {
1338 ch_free( bc->sb_secprops );
1339 bc->sb_secprops = NULL;
1341 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1342 ch_free( bc->sb_realm.bv_val );
1343 BER_BVZERO( &bc->sb_realm );
1345 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1346 ch_free( bc->sb_authcId.bv_val );
1347 BER_BVZERO( &bc->sb_authcId );
1349 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1350 ch_free( bc->sb_authzId.bv_val );
1351 BER_BVZERO( &bc->sb_authzId );
1354 if ( bc->sb_tls_cert ) {
1355 ch_free( bc->sb_tls_cert );
1356 bc->sb_tls_cert = NULL;
1358 if ( bc->sb_tls_key ) {
1359 ch_free( bc->sb_tls_key );
1360 bc->sb_tls_key = NULL;
1362 if ( bc->sb_tls_cacert ) {
1363 ch_free( bc->sb_tls_cacert );
1364 bc->sb_tls_cacert = NULL;
1366 if ( bc->sb_tls_cacertdir ) {
1367 ch_free( bc->sb_tls_cacertdir );
1368 bc->sb_tls_cacertdir = NULL;
1370 if ( bc->sb_tls_reqcert ) {
1371 ch_free( bc->sb_tls_reqcert );
1372 bc->sb_tls_reqcert = NULL;
1374 if ( bc->sb_tls_cipher_suite ) {
1375 ch_free( bc->sb_tls_cipher_suite );
1376 bc->sb_tls_cipher_suite = NULL;
1378 #ifdef HAVE_OPENSSL_CRL
1379 if ( bc->sb_tls_crlcheck ) {
1380 ch_free( bc->sb_tls_crlcheck );
1381 bc->sb_tls_crlcheck = NULL;
1388 bindconf_tls_defaults( slap_bindconf *bc )
1391 if ( bc->sb_tls_do_init ) {
1392 if ( !bc->sb_tls_cacert )
1393 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1394 &bc->sb_tls_cacert );
1395 if ( !bc->sb_tls_cacertdir )
1396 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1397 &bc->sb_tls_cacertdir );
1398 if ( !bc->sb_tls_cert )
1399 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1401 if ( !bc->sb_tls_key )
1402 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1404 if ( !bc->sb_tls_cipher_suite )
1405 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1406 &bc->sb_tls_cipher_suite );
1407 if ( !bc->sb_tls_reqcert )
1408 bc->sb_tls_reqcert = ch_strdup("demand");
1409 #ifdef HAVE_OPENSSL_CRL
1410 if ( !bc->sb_tls_crlcheck )
1411 slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1412 &bc->sb_tls_crlcheck );
1424 { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1425 { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1426 { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1427 { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1428 { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1432 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1434 int i, rc, newctx = 0, res = 0;
1435 char *ptr = (char *)bc, **word;
1437 bc->sb_tls_do_init = 0;
1439 for (i=0; bindtlsopts[i].opt; i++) {
1440 word = (char **)(ptr + bindtlsopts[i].offset);
1442 rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1444 Debug( LDAP_DEBUG_ANY,
1445 "bindconf_tls_set: failed to set %s to %s\n",
1446 bindtlsopts[i].key, *word, 0 );
1452 if ( bc->sb_tls_reqcert ) {
1453 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1454 bc->sb_tls_reqcert );
1456 Debug( LDAP_DEBUG_ANY,
1457 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1458 bc->sb_tls_reqcert, 0, 0 );
1463 #ifdef HAVE_OPENSSL_CRL
1464 if ( bc->sb_tls_crlcheck ) {
1465 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1466 bc->sb_tls_crlcheck );
1468 Debug( LDAP_DEBUG_ANY,
1469 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1470 bc->sb_tls_crlcheck, 0, 0 );
1479 if ( bc->sb_tls_ctx ) {
1480 ldap_pvt_tls_ctx_free( bc->sb_tls_ctx );
1481 bc->sb_tls_ctx = NULL;
1483 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1487 ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1495 * connect to a client using the bindconf data
1496 * note: should move "version" into bindconf...
1499 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1505 /* Init connection to master */
1506 rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1507 if ( rc != LDAP_SUCCESS ) {
1508 Debug( LDAP_DEBUG_ANY,
1509 "slap_client_connect: "
1510 "ldap_initialize(%s) failed (%d)\n",
1511 sb->sb_uri.bv_val, rc, 0 );
1515 if ( sb->sb_version != 0 ) {
1516 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1517 (const void *)&sb->sb_version );
1520 if ( sb->sb_timeout_api ) {
1521 tv.tv_sec = sb->sb_timeout_api;
1523 ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
1526 if ( sb->sb_timeout_net ) {
1527 tv.tv_sec = sb->sb_timeout_net;
1529 ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
1533 if ( sb->sb_tls_do_init ) {
1534 rc = bindconf_tls_set( sb, ld );
1536 } else if ( sb->sb_tls_ctx ) {
1537 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1542 Debug( LDAP_DEBUG_ANY,
1543 "slap_client_connect: "
1544 "URI=%s TLS context initialization failed (%d)\n",
1545 sb->sb_uri.bv_val, rc, 0 );
1552 rc = ldap_start_tls_s( ld, NULL, NULL );
1553 if ( rc != LDAP_SUCCESS ) {
1554 Debug( LDAP_DEBUG_ANY,
1555 "slap_client_connect: URI=%s "
1556 "%s, ldap_start_tls failed (%d)\n",
1558 sb->sb_tls == SB_TLS_CRITICAL ?
1559 "Error" : "Warning",
1561 if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1567 if ( sb->sb_method == LDAP_AUTH_SASL ) {
1568 #ifdef HAVE_CYRUS_SASL
1571 if ( sb->sb_secprops != NULL ) {
1572 rc = ldap_set_option( ld,
1573 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1575 if( rc != LDAP_OPT_SUCCESS ) {
1576 Debug( LDAP_DEBUG_ANY,
1577 "slap_client_connect: "
1578 "error, ldap_set_option "
1579 "(%s,SECPROPS,\"%s\") failed!\n",
1580 sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1585 defaults = lutil_sasl_defaults( ld,
1586 sb->sb_saslmech.bv_val,
1587 sb->sb_realm.bv_val,
1588 sb->sb_authcId.bv_val,
1590 sb->sb_authzId.bv_val );
1592 rc = ldap_sasl_interactive_bind_s( ld,
1593 sb->sb_binddn.bv_val,
1594 sb->sb_saslmech.bv_val,
1597 lutil_sasl_interact,
1600 lutil_sasl_freedefs( defaults );
1602 /* FIXME: different error behaviors according to
1604 * 2) on err policy : exit, retry, backoff ...
1606 if ( rc != LDAP_SUCCESS ) {
1607 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1609 Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1610 "ldap_sasl_interactive_bind_s failed (%d)\n",
1611 sb->sb_uri.bv_val, rc, 0 );
1613 /* FIXME (see above comment) */
1614 /* if Kerberos credentials cache is not active, retry */
1615 if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1616 rc == LDAP_LOCAL_ERROR )
1618 rc = LDAP_SERVER_DOWN;
1623 #else /* HAVE_CYRUS_SASL */
1624 /* Should never get here, we trapped this at config time */
1626 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1631 } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1632 rc = ldap_sasl_bind_s( ld,
1633 sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1634 &sb->sb_cred, NULL, NULL, NULL );
1635 if ( rc != LDAP_SUCCESS ) {
1636 Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1638 "ldap_sasl_bind_s failed (%d)\n",
1639 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1647 ldap_unbind_ext( ld, NULL, NULL );
1658 /* -------------------------------------- */
1662 strtok_quote( char *line, char *sep, char **quote_ptr )
1669 if ( line != NULL ) {
1672 while ( *next && strchr( sep, *next ) ) {
1676 if ( *next == '\0' ) {
1682 for ( inquote = 0; *next; ) {
1690 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1696 next + 1, strlen( next + 1 ) + 1 );
1697 next++; /* dont parse the escaped character */
1702 if ( strchr( sep, *next ) != NULL ) {
1716 static char buf[AC_LINE_MAX];
1718 static size_t lmax, lcur;
1720 #define CATLINE( buf ) \
1722 size_t len = strlen( buf ); \
1723 while ( lcur + len + 1 > lmax ) { \
1724 lmax += AC_LINE_MAX; \
1725 line = (char *) ch_realloc( line, lmax ); \
1727 strcpy( line + lcur, buf ); \
1732 fp_getline_init(ConfigArgs *c) {
1738 fp_getline( FILE *fp, ConfigArgs *c )
1746 /* avoid stack of bufs */
1747 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1753 while ( fgets( buf, sizeof( buf ), fp ) ) {
1754 p = strchr( buf, '\n' );
1756 if ( p > buf && p[-1] == '\r' ) {
1764 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1771 if ( !isspace( (unsigned char)buf[0] ) ) {
1782 return(line[0] ? 1 : 0);
1786 fp_parse_line(ConfigArgs *c)
1789 static char *const hide[] = {
1790 "rootpw", "replica", "syncrepl", /* in slapd */
1791 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1792 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1793 "pseudorootpw", /* in back-meta */
1794 "dbpasswd", /* in back-sql */
1798 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1800 c->tline = ch_strdup(c->line);
1801 token = strtok_quote(c->tline, " \t", "e_ptr);
1803 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1804 if(quote_ptr) *quote_ptr = ' ';
1805 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1806 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1807 if(quote_ptr) *quote_ptr = '\0';
1809 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1810 if(c->argc >= c->argv_size) {
1812 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1814 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1818 c->argv_size += ARGS_STEP;
1822 c->argv[c->argc++] = token;
1824 c->argv[c->argc] = NULL;
1831 ucdata_unload( UCDATA_ALL );
1833 /* NOTE: in case of early exit, frontendDB can be NULL */
1834 if ( frontendDB->be_schemandn.bv_val )
1835 free( frontendDB->be_schemandn.bv_val );
1836 if ( frontendDB->be_schemadn.bv_val )
1837 free( frontendDB->be_schemadn.bv_val );
1838 if ( frontendDB->be_acl )
1839 acl_destroy( frontendDB->be_acl, NULL );
1842 if ( slapd_args_file )
1843 free ( slapd_args_file );
1844 if ( slapd_pid_file )
1845 free ( slapd_pid_file );
1846 if ( default_passwd_hash )
1847 ldap_charray_free( default_passwd_hash );
1851 slap_str2clist( char ***out, char *in, const char *brkstr )
1859 /* find last element in list */
1860 for (i = 0; *out && (*out)[i]; i++);
1862 /* protect the input string from strtok */
1863 str = ch_strdup( in );
1865 if ( *str == '\0' ) {
1870 /* Count words in string */
1872 for ( s = str; *s; s++ ) {
1873 if ( strchr( brkstr, *s ) != NULL ) {
1878 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1880 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1882 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1884 *new = ch_strdup( s );
1893 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1894 int argc, char **argv )
1896 ConfigArgs c = { 0 };
1907 c.op = SLAP_CONFIG_ADD;
1908 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1910 rc = SLAP_CONF_UNKNOWN;
1911 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1913 c.table = be->be_cf_ocs->co_type;
1914 rc = config_add_vals( ct, &c );