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;
130 if(Conf->arg_type == ARG_IGNORED) {
131 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
132 c->log, Conf->name, 0);
135 arg_type = Conf->arg_type & ARGS_TYPES;
136 arg_user = Conf->arg_type & ARGS_USERLAND;
137 arg_syn = Conf->arg_type & ARGS_SYNTAX;
139 if((arg_type == ARG_DN) && c->argc == 1) {
143 if(Conf->min_args && (c->argc < Conf->min_args)) {
144 snprintf( c->msg, sizeof( c->msg ), "<%s> missing <%s> argument",
145 c->argv[0], Conf->what );
146 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n", c->log, c->msg, 0 );
147 return(ARG_BAD_CONF);
149 if(Conf->max_args && (c->argc > Conf->max_args)) {
150 char *ignored = " ignored";
152 snprintf( c->msg, sizeof( c->msg ), "<%s> extra cruft after <%s>",
153 c->argv[0], Conf->what );
156 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s%s.\n",
157 c->log, c->msg, ignored );
158 return(ARG_BAD_CONF);
160 if((arg_syn & ARG_DB) && !c->be) {
161 snprintf( c->msg, sizeof( c->msg ), "<%s> only allowed within database declaration",
163 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
165 return(ARG_BAD_CONF);
167 if((arg_syn & ARG_PRE_BI) && c->bi) {
168 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any backend %sdeclaration",
169 c->argv[0], (arg_syn & ARG_PRE_DB) ? "or database " : "" );
170 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
172 return(ARG_BAD_CONF);
174 if((arg_syn & ARG_PRE_DB) && c->be && c->be != frontendDB) {
175 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any database declaration",
177 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
179 return(ARG_BAD_CONF);
181 if((arg_syn & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
182 snprintf( c->msg, sizeof( c->msg ), "<%s> old format not supported", c->argv[0] );
183 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
185 return(ARG_BAD_CONF);
187 if(arg_type && !Conf->arg_item && !(arg_syn & ARG_OFFSET)) {
188 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid config_table, arg_item is NULL",
190 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
192 return(ARG_BAD_CONF);
195 memset(&c->values, 0, sizeof(c->values));
196 if(arg_type == ARG_STRING) {
198 c->value_string = ch_strdup(c->argv[1]);
199 } else if(arg_type == ARG_BERVAL) {
201 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
202 } else if(arg_type == ARG_DN) {
204 ber_str2bv( c->argv[1], 0, 0, &bv );
205 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
206 if ( rc != LDAP_SUCCESS ) {
207 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid DN %d (%s)",
208 c->argv[0], rc, ldap_err2string( rc ));
209 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n" , c->log, c->msg, 0);
210 return(ARG_BAD_CONF);
213 ch_free( c->value_ndn.bv_val );
214 ch_free( c->value_dn.bv_val );
216 } else { /* all numeric */
218 iarg = 0; larg = 0; barg = 0;
221 if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
222 snprintf( c->msg, sizeof( c->msg ),
223 "<%s> unable to parse \"%s\" as int",
224 c->argv[0], c->argv[1] );
225 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
227 return(ARG_BAD_CONF);
231 if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
232 snprintf( c->msg, sizeof( c->msg ),
233 "<%s> unable to parse \"%s\" as long",
234 c->argv[0], c->argv[1] );
235 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
237 return(ARG_BAD_CONF);
240 case ARG_BER_LEN_T: {
242 if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
243 snprintf( c->msg, sizeof( c->msg ),
244 "<%s> unable to parse \"%s\" as ber_len_t",
245 c->argv[0], c->argv[1] );
246 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
248 return(ARG_BAD_CONF);
255 } else if ( !strcasecmp(c->argv[1], "on") ||
256 !strcasecmp(c->argv[1], "true") ||
257 !strcasecmp(c->argv[1], "yes") )
260 } else if ( !strcasecmp(c->argv[1], "off") ||
261 !strcasecmp(c->argv[1], "false") ||
262 !strcasecmp(c->argv[1], "no") )
266 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
268 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
270 return(ARG_BAD_CONF);
274 j = (arg_type & ARG_NONZERO) ? 1 : 0;
275 if(iarg < j && larg < j && barg < j ) {
276 larg = larg ? larg : (barg ? barg : iarg);
277 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
279 Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
281 return(ARG_BAD_CONF);
285 case ARG_INT: c->value_int = iarg; break;
286 case ARG_LONG: c->value_long = larg; break;
287 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
293 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
297 arg_type = Conf->arg_type;
298 if(arg_type & ARG_MAGIC) {
299 if(!c->be) c->be = frontendDB;
301 rc = (*((ConfigDriver*)Conf->arg_item))(c);
303 if(c->be == frontendDB) c->be = NULL;
307 snprintf( c->msg, sizeof( c->msg ), "<%s> handler exited with %d",
309 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
312 return(ARG_BAD_CONF);
316 if(arg_type & ARG_OFFSET) {
317 if (c->be && c->table == Cft_Database)
318 ptr = c->be->be_private;
320 ptr = c->bi->bi_private;
322 snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
324 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
326 return(ARG_BAD_CONF);
328 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
329 } else if (arg_type & ARGS_TYPES) {
330 ptr = Conf->arg_item;
332 if(arg_type & ARGS_TYPES)
333 switch(arg_type & ARGS_TYPES) {
335 case ARG_INT: *(int*)ptr = c->value_int; break;
336 case ARG_LONG: *(long*)ptr = c->value_long; break;
337 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
339 char *cc = *(char**)ptr;
341 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
342 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
343 c->log, Conf->name, 0 );
344 return(ARG_BAD_CONF);
348 *(char **)ptr = c->value_string;
352 *(struct berval *)ptr = c->value_bv;
358 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
361 arg_type = Conf->arg_type;
362 if(arg_type == ARG_IGNORED) {
363 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
364 c->log, Conf->name, 0);
367 rc = config_check_vals( Conf, c, 0 );
369 return config_set_vals( Conf, c );
373 config_del_vals(ConfigTable *cf, ConfigArgs *c)
377 /* If there is no handler, just ignore it */
378 if ( cf->arg_type & ARG_MAGIC ) {
379 c->op = LDAP_MOD_DELETE;
380 c->type = cf->arg_type & ARGS_USERLAND;
381 rc = (*((ConfigDriver*)cf->arg_item))(c);
387 config_get_vals(ConfigTable *cf, ConfigArgs *c)
393 if ( cf->arg_type & ARG_IGNORED ) {
397 memset(&c->values, 0, sizeof(c->values));
398 c->rvalue_vals = NULL;
399 c->rvalue_nvals = NULL;
400 c->op = SLAP_CONFIG_EMIT;
401 c->type = cf->arg_type & ARGS_USERLAND;
403 if ( cf->arg_type & ARG_MAGIC ) {
404 rc = (*((ConfigDriver*)cf->arg_item))(c);
407 if ( cf->arg_type & ARG_OFFSET ) {
408 if (c->be && c->table == Cft_Database)
409 ptr = c->be->be_private;
411 ptr = c->bi->bi_private;
414 ptr = (void *)((char *)ptr + (long)cf->arg_item);
419 switch(cf->arg_type & ARGS_TYPES) {
421 case ARG_INT: c->value_int = *(int *)ptr; break;
422 case ARG_LONG: c->value_long = *(long *)ptr; break;
423 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
426 c->value_string = ch_strdup(*(char **)ptr);
429 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
432 if ( cf->arg_type & ARGS_TYPES) {
435 switch(cf->arg_type & ARGS_TYPES) {
436 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
437 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
438 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
439 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
440 c->value_int ? "TRUE" : "FALSE"); break;
442 if ( c->value_string && c->value_string[0]) {
443 ber_str2bv( c->value_string, 0, 0, &bv);
449 if ( !BER_BVISEMPTY( &c->value_bv )) {
459 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
462 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
463 ber_bvarray_add(&c->rvalue_vals, &bv);
464 } else if ( !BER_BVISNULL( &bv ) ) {
465 value_add_one(&c->rvalue_vals, &bv);
467 /* else: maybe c->rvalue_vals already set? */
473 init_config_attrs(ConfigTable *ct) {
476 for (i=0; ct[i].name; i++ ) {
477 if ( !ct[i].attribute ) continue;
478 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
480 fprintf( stderr, "init_config_attrs: register_at failed\n" );
484 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
492 init_config_ocs( ConfigOCs *ocs ) {
495 for (i=0;ocs[i].co_def;i++) {
496 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
498 fprintf( stderr, "init_config_ocs: register_oc failed\n" );
502 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
508 /* Split an LDIF line into space-separated tokens. Words may be grouped
509 * by quotes. A quoted string may begin in the middle of a word, but must
510 * end at the end of the word (be followed by whitespace or EOS). Any other
511 * quotes are passed through unchanged. All other characters are passed
515 strtok_quote_ldif( char **line )
517 char *beg, *ptr, *quote=NULL;
525 while( isspace( (unsigned char) *ptr )) ptr++;
536 if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
546 if ( isspace( (unsigned char) *ptr )) {
552 while ( quote < ptr ) {
560 while ( isspace( (unsigned char) *ptr )) ptr++;
567 config_parse_ldif( ConfigArgs *c )
570 c->tline = ch_strdup(c->line);
573 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
575 if ( c->argc >= c->argv_size ) {
576 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
579 c->argv_size += ARGS_STEP;
582 c->argv[c->argc] = NULL;
586 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
590 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
591 ct->ad->ad_cname.bv_val, valx );
593 c->argv[0] = ct->ad->ad_cname.bv_val;
595 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
596 c->argv[c->argc] = c->line;
598 c->argv[c->argc] = NULL;
601 config_parse_ldif( c );
603 rc = config_check_vals( ct, c, 1 );
608 rc = LDAP_CONSTRAINT_VIOLATION;
614 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
618 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
619 ct->ad->ad_cname.bv_val, valx );
621 c->argv[0] = ct->ad->ad_cname.bv_val;
623 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
624 c->argv[c->argc] = c->line;
626 c->argv[c->argc] = NULL;
629 config_parse_ldif( c );
631 c->op = LDAP_MOD_ADD;
632 rc = config_add_vals( ct, c );
639 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
647 c = ch_calloc( 1, sizeof( ConfigArgs ) );
653 memcpy( c, cf, sizeof( ConfigArgs ) );
655 c->depth = depth; /* XXX */
662 init_config_argv( c );
664 if ( stat( fname, &s ) != 0 ) {
666 Debug(LDAP_DEBUG_ANY,
667 "could not stat config file \"%s\": %s (%d)\n",
668 fname, strerror(errno), errno);
673 if ( !S_ISREG( s.st_mode ) ) {
675 Debug(LDAP_DEBUG_ANY,
676 "regular file expected, got \"%s\"\n",
682 fp = fopen( fname, "r" );
685 Debug(LDAP_DEBUG_ANY,
686 "could not open config file \"%s\": %s (%d)\n",
687 fname, strerror(errno), errno);
692 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
698 while ( fp_getline( fp, c ) ) {
699 /* skip comments and blank lines */
700 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
704 snprintf( c->log, sizeof( c->log ), "%s: line %d",
705 c->fname, c->lineno );
709 if ( fp_parse_line( c ) ) {
715 Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
721 c->op = SLAP_CONFIG_ADD;
723 ct = config_find_keyword( cft, c );
725 c->table = Cft_Global;
726 rc = config_add_vals( ct, c );
729 if ( rc & ARGS_USERLAND ) {
730 /* XXX a usertype would be opaque here */
731 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
732 c->log, c->argv[0], 0);
736 } else if ( rc == ARG_BAD_CONF ) {
741 } else if ( c->bi && !c->be ) {
742 rc = SLAP_CONF_UNKNOWN;
743 if ( c->bi->bi_cf_ocs ) {
744 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
746 c->table = c->bi->bi_cf_ocs->co_type;
747 rc = config_add_vals( ct, c );
750 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
751 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
756 case SLAP_CONF_UNKNOWN:
757 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
758 "<%s> inside backend info definition.\n",
759 c->log, *c->argv, 0);
766 } else if ( c->be && c->be != frontendDB ) {
767 rc = SLAP_CONF_UNKNOWN;
768 if ( c->be->be_cf_ocs ) {
769 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
771 c->table = c->be->be_cf_ocs->co_type;
772 rc = config_add_vals( ct, c );
775 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
776 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
779 if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
781 /* global overlays may need
782 * definitions inside other databases...
784 rc = (*frontendDB->be_config)( frontendDB,
785 c->fname, (int)c->lineno, c->argc, c->argv );
792 case SLAP_CONF_UNKNOWN:
793 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
794 "<%s> inside backend database definition.\n",
795 c->log, *c->argv, 0);
802 } else if ( frontendDB->be_config ) {
803 rc = (*frontendDB->be_config)( frontendDB,
804 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 global database definition.\n",
810 c->log, *c->argv, 0);
819 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
820 "<%s> outside backend info and database definitions.\n",
821 c->log, *c->argv, 0);
837 /* restrictops, allows, disallows, requires, loglevel */
840 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
842 for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
843 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
849 verb_to_mask(const char *word, slap_verbmasks *v) {
851 ber_str2bv( word, 0, 0, &bword );
852 return bverb_to_mask( &bword, v );
856 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
858 for(i = 1; i < argc; i++) {
859 j = verb_to_mask(argv[i], v);
860 if(BER_BVISNULL(&v[j].word)) return i;
861 while (!v[j].mask) j--;
867 /* Mask keywords that represent multiple bits should occur before single
868 * bit keywords in the verbmasks array.
871 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
875 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
876 if (!v[i].mask) continue;
877 if (( m & v[i].mask ) == v[i].mask ) {
878 value_add_one( bva, &v[i].word );
889 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
893 assert( *vp == NULL );
895 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
897 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
899 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
900 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
901 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
904 BER_BVZERO( &(*vp)[ i ].word );
910 slap_verbmasks_destroy( slap_verbmasks *v )
916 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
917 ch_free( v[ i ].word.bv_val );
926 slap_verbmasks_append(
930 slap_mask_t *ignore )
935 return LDAP_OPERATIONS_ERROR;
938 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
939 if ( !(*vp)[ i ].mask ) continue;
941 if ( ignore != NULL ) {
944 for ( j = 0; ignore[ j ] != 0; j++ ) {
945 if ( (*vp)[ i ].mask == ignore[ j ] ) {
951 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
952 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
953 /* already set; ignore */
957 return LDAP_TYPE_OR_VALUE_EXISTS;
960 if ( m & (*vp)[ i ].mask ) {
962 return LDAP_CONSTRAINT_VIOLATION;
967 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
968 ber_dupbv( &(*vp)[ i ].word, v );
969 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
970 BER_BVZERO( &(*vp)[ i + 1 ].word );
976 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
979 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
980 if ( m == v[i].mask ) {
991 static slap_verbmasks tlskey[] = {
992 { BER_BVC("no"), SB_TLS_OFF },
993 { BER_BVC("yes"), SB_TLS_ON },
994 { BER_BVC("critical"), SB_TLS_CRITICAL },
998 static slap_verbmasks crlkeys[] = {
999 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1000 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1001 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1005 static slap_verbmasks vfykeys[] = {
1006 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1007 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1008 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1009 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1014 static slap_verbmasks methkey[] = {
1015 { BER_BVC("none"), LDAP_AUTH_NONE },
1016 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
1017 #ifdef HAVE_CYRUS_SASL
1018 { BER_BVC("sasl"), LDAP_AUTH_SASL },
1023 static slap_verbmasks versionkey[] = {
1024 { BER_BVC("2"), LDAP_VERSION2 },
1025 { BER_BVC("3"), LDAP_VERSION3 },
1029 static slap_cf_aux_table bindkey[] = {
1030 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1031 { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1032 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1033 { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
1034 { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
1035 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1036 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1037 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1038 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1039 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1040 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 1, NULL },
1041 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1043 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1045 /* NOTE: replace "13" with the actual index
1046 * of the first TLS-related line */
1047 #define aux_TLS (bindkey+13) /* beginning of TLS keywords */
1049 { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1050 { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1051 { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1052 { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1053 { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1054 { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1055 #ifdef HAVE_OPENSSL_CRL
1056 { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1059 { BER_BVNULL, 0, 0, 0, NULL }
1064 * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1065 * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1068 * 'U': unsigned long
1072 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1074 int rc = SLAP_CONF_UNKNOWN;
1075 slap_cf_aux_table *tab;
1077 for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1078 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1083 unsigned long *ulptr;
1084 struct berval *bptr;
1085 const char *val = word + tab->key.bv_len;
1087 switch ( tab->type ) {
1089 cptr = (char **)((char *)dst + tab->off);
1090 *cptr = ch_strdup( val );
1095 bptr = (struct berval *)((char *)dst + tab->off);
1096 if ( tab->aux != NULL ) {
1098 slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1100 ber_str2bv( val, 0, 0, &dn );
1101 rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1104 ber_str2bv( val, 0, 1, bptr );
1110 iptr = (int *)((char *)dst + tab->off);
1112 if ( tab->aux != NULL ) {
1113 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1115 assert( aux != NULL );
1118 for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1119 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1120 *iptr = aux[j].mask;
1127 rc = lutil_atoix( iptr, val, 0 );
1132 uptr = (unsigned *)((char *)dst + tab->off);
1134 rc = lutil_atoux( uptr, val, 0 );
1138 lptr = (long *)((char *)dst + tab->off);
1140 rc = lutil_atolx( lptr, val, 0 );
1144 ulptr = (unsigned long *)((char *)dst + tab->off);
1146 rc = lutil_atoulx( ulptr, val, 0 );
1151 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1163 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1165 char buf[AC_LINE_MAX], *ptr;
1166 slap_cf_aux_table *tab;
1170 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1175 unsigned long *ulptr;
1176 struct berval *bptr;
1178 cptr = (char **)((char *)src + tab->off);
1180 switch ( tab->type ) {
1182 bptr = (struct berval *)((char *)src + tab->off);
1183 cptr = &bptr->bv_val;
1188 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1189 if ( tab->quote ) *ptr++ = '"';
1190 ptr = lutil_strcopy( ptr, *cptr );
1191 if ( tab->quote ) *ptr++ = '"';
1196 iptr = (int *)((char *)src + tab->off);
1198 if ( tab->aux != NULL ) {
1199 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1201 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1202 if ( *iptr == aux[i].mask ) {
1204 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1205 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1212 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1213 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1218 uptr = (unsigned *)((char *)src + tab->off);
1220 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1221 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1225 lptr = (long *)((char *)src + tab->off);
1227 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1228 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1232 ulptr = (unsigned long *)((char *)src + tab->off);
1234 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1235 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1243 tmp.bv_len = ptr - buf;
1244 ber_dupbv( bv, &tmp );
1249 slap_tls_get_config( LDAP *ld, int opt, char **val )
1251 slap_verbmasks *keys;
1257 case LDAP_OPT_X_TLS_CRLCHECK:
1260 case LDAP_OPT_X_TLS_REQUIRE_CERT:
1267 ldap_pvt_tls_get_option( ld, opt, &ival );
1268 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1269 if (keys[i].mask == ival) {
1270 *val = ch_strdup( keys[i].word.bv_val );
1278 bindconf_tls_parse( const char *word, slap_bindconf *bc )
1281 if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1282 bc->sb_tls_do_init = 1;
1290 bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
1293 return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
1299 bindconf_parse( const char *word, slap_bindconf *bc )
1302 /* Detect TLS config changes explicitly */
1303 if ( bindconf_tls_parse( word, bc ) == 0 ) {
1307 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1311 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1313 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1316 void bindconf_free( slap_bindconf *bc ) {
1317 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1318 ch_free( bc->sb_uri.bv_val );
1319 BER_BVZERO( &bc->sb_uri );
1321 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1322 ch_free( bc->sb_binddn.bv_val );
1323 BER_BVZERO( &bc->sb_binddn );
1325 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1326 ch_free( bc->sb_cred.bv_val );
1327 BER_BVZERO( &bc->sb_cred );
1329 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1330 ch_free( bc->sb_saslmech.bv_val );
1331 BER_BVZERO( &bc->sb_saslmech );
1333 if ( bc->sb_secprops ) {
1334 ch_free( bc->sb_secprops );
1335 bc->sb_secprops = NULL;
1337 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1338 ch_free( bc->sb_realm.bv_val );
1339 BER_BVZERO( &bc->sb_realm );
1341 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1342 ch_free( bc->sb_authcId.bv_val );
1343 BER_BVZERO( &bc->sb_authcId );
1345 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1346 ch_free( bc->sb_authzId.bv_val );
1347 BER_BVZERO( &bc->sb_authzId );
1350 if ( bc->sb_tls_cert ) {
1351 ch_free( bc->sb_tls_cert );
1352 bc->sb_tls_cert = NULL;
1354 if ( bc->sb_tls_key ) {
1355 ch_free( bc->sb_tls_key );
1356 bc->sb_tls_key = NULL;
1358 if ( bc->sb_tls_cacert ) {
1359 ch_free( bc->sb_tls_cacert );
1360 bc->sb_tls_cacert = NULL;
1362 if ( bc->sb_tls_cacertdir ) {
1363 ch_free( bc->sb_tls_cacertdir );
1364 bc->sb_tls_cacertdir = NULL;
1366 if ( bc->sb_tls_reqcert ) {
1367 ch_free( bc->sb_tls_reqcert );
1368 bc->sb_tls_reqcert = NULL;
1370 if ( bc->sb_tls_cipher_suite ) {
1371 ch_free( bc->sb_tls_cipher_suite );
1372 bc->sb_tls_cipher_suite = NULL;
1374 #ifdef HAVE_OPENSSL_CRL
1375 if ( bc->sb_tls_crlcheck ) {
1376 ch_free( bc->sb_tls_crlcheck );
1377 bc->sb_tls_crlcheck = NULL;
1384 bindconf_tls_defaults( slap_bindconf *bc )
1387 if ( bc->sb_tls_do_init ) {
1388 if ( !bc->sb_tls_cacert )
1389 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1390 &bc->sb_tls_cacert );
1391 if ( !bc->sb_tls_cacertdir )
1392 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1393 &bc->sb_tls_cacertdir );
1394 if ( !bc->sb_tls_cert )
1395 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1397 if ( !bc->sb_tls_key )
1398 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1400 if ( !bc->sb_tls_cipher_suite )
1401 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1402 &bc->sb_tls_cipher_suite );
1403 if ( !bc->sb_tls_reqcert )
1404 bc->sb_tls_reqcert = ch_strdup("demand");
1405 #ifdef HAVE_OPENSSL_CRL
1406 if ( !bc->sb_tls_crlcheck )
1407 slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1408 &bc->sb_tls_crlcheck );
1420 { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1421 { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1422 { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1423 { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1424 { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1428 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1430 int i, rc, newctx = 0, res = 0;
1431 char *ptr = (char *)bc, **word;
1433 bc->sb_tls_do_init = 0;
1435 for (i=0; bindtlsopts[i].opt; i++) {
1436 word = (char **)(ptr + bindtlsopts[i].offset);
1438 rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1440 Debug( LDAP_DEBUG_ANY,
1441 "bindconf_tls_set: failed to set %s to %s\n",
1442 bindtlsopts[i].key, *word, 0 );
1448 if ( bc->sb_tls_reqcert ) {
1449 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1450 bc->sb_tls_reqcert );
1452 Debug( LDAP_DEBUG_ANY,
1453 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1454 bc->sb_tls_reqcert, 0, 0 );
1459 #ifdef HAVE_OPENSSL_CRL
1460 if ( bc->sb_tls_crlcheck ) {
1461 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1462 bc->sb_tls_crlcheck );
1464 Debug( LDAP_DEBUG_ANY,
1465 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1466 bc->sb_tls_crlcheck, 0, 0 );
1475 if ( bc->sb_tls_ctx ) {
1476 ldap_pvt_tls_ctx_free( bc->sb_tls_ctx );
1477 bc->sb_tls_ctx = NULL;
1479 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1483 ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1491 * connect to a client using the bindconf data
1492 * note: should move "version" into bindconf...
1495 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1501 /* Init connection to master */
1502 rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1503 if ( rc != LDAP_SUCCESS ) {
1504 Debug( LDAP_DEBUG_ANY,
1505 "slap_client_connect: "
1506 "ldap_initialize(%s) failed (%d)\n",
1507 sb->sb_uri.bv_val, rc, 0 );
1511 if ( sb->sb_version != 0 ) {
1512 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1513 (const void *)&sb->sb_version );
1516 if ( sb->sb_timeout_api ) {
1517 tv.tv_sec = sb->sb_timeout_api;
1519 ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
1522 if ( sb->sb_timeout_net ) {
1523 tv.tv_sec = sb->sb_timeout_net;
1525 ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
1529 if ( sb->sb_tls_do_init ) {
1530 rc = bindconf_tls_set( sb, ld );
1532 } else if ( sb->sb_tls_ctx ) {
1533 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1538 Debug( LDAP_DEBUG_ANY,
1539 "slap_client_connect: "
1540 "URI=%s TLS context initialization failed (%d)\n",
1541 sb->sb_uri.bv_val, rc, 0 );
1548 rc = ldap_start_tls_s( ld, NULL, NULL );
1549 if ( rc != LDAP_SUCCESS ) {
1550 Debug( LDAP_DEBUG_ANY,
1551 "slap_client_connect: URI=%s "
1552 "%s, ldap_start_tls failed (%d)\n",
1554 sb->sb_tls == SB_TLS_CRITICAL ?
1555 "Error" : "Warning",
1557 if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1563 if ( sb->sb_method == LDAP_AUTH_SASL ) {
1564 #ifdef HAVE_CYRUS_SASL
1567 if ( sb->sb_secprops != NULL ) {
1568 rc = ldap_set_option( ld,
1569 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1571 if( rc != LDAP_OPT_SUCCESS ) {
1572 Debug( LDAP_DEBUG_ANY,
1573 "slap_client_connect: "
1574 "error, ldap_set_option "
1575 "(%s,SECPROPS,\"%s\") failed!\n",
1576 sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1581 defaults = lutil_sasl_defaults( ld,
1582 sb->sb_saslmech.bv_val,
1583 sb->sb_realm.bv_val,
1584 sb->sb_authcId.bv_val,
1586 sb->sb_authzId.bv_val );
1588 rc = ldap_sasl_interactive_bind_s( ld,
1589 sb->sb_binddn.bv_val,
1590 sb->sb_saslmech.bv_val,
1593 lutil_sasl_interact,
1596 lutil_sasl_freedefs( defaults );
1598 /* FIXME: different error behaviors according to
1600 * 2) on err policy : exit, retry, backoff ...
1602 if ( rc != LDAP_SUCCESS ) {
1603 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1605 Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1606 "ldap_sasl_interactive_bind_s failed (%d)\n",
1607 sb->sb_uri.bv_val, rc, 0 );
1609 /* FIXME (see above comment) */
1610 /* if Kerberos credentials cache is not active, retry */
1611 if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1612 rc == LDAP_LOCAL_ERROR )
1614 rc = LDAP_SERVER_DOWN;
1619 #else /* HAVE_CYRUS_SASL */
1620 /* Should never get here, we trapped this at config time */
1622 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1627 } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1628 rc = ldap_sasl_bind_s( ld,
1629 sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1630 &sb->sb_cred, NULL, NULL, NULL );
1631 if ( rc != LDAP_SUCCESS ) {
1632 Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1634 "ldap_sasl_bind_s failed (%d)\n",
1635 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1643 ldap_unbind_ext( ld, NULL, NULL );
1654 /* -------------------------------------- */
1658 strtok_quote( char *line, char *sep, char **quote_ptr )
1665 if ( line != NULL ) {
1668 while ( *next && strchr( sep, *next ) ) {
1672 if ( *next == '\0' ) {
1678 for ( inquote = 0; *next; ) {
1686 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1692 next + 1, strlen( next + 1 ) + 1 );
1693 next++; /* dont parse the escaped character */
1698 if ( strchr( sep, *next ) != NULL ) {
1712 static char buf[AC_LINE_MAX];
1714 static size_t lmax, lcur;
1716 #define CATLINE( buf ) \
1718 size_t len = strlen( buf ); \
1719 while ( lcur + len + 1 > lmax ) { \
1720 lmax += AC_LINE_MAX; \
1721 line = (char *) ch_realloc( line, lmax ); \
1723 strcpy( line + lcur, buf ); \
1728 fp_getline_init(ConfigArgs *c) {
1734 fp_getline( FILE *fp, ConfigArgs *c )
1742 /* avoid stack of bufs */
1743 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1749 while ( fgets( buf, sizeof( buf ), fp ) ) {
1750 p = strchr( buf, '\n' );
1752 if ( p > buf && p[-1] == '\r' ) {
1760 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1767 if ( !isspace( (unsigned char)buf[0] ) ) {
1778 return(line[0] ? 1 : 0);
1782 fp_parse_line(ConfigArgs *c)
1785 static char *const hide[] = {
1786 "rootpw", "replica", "syncrepl", /* in slapd */
1787 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1788 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1789 "pseudorootpw", /* in back-meta */
1790 "dbpasswd", /* in back-sql */
1794 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1796 c->tline = ch_strdup(c->line);
1797 token = strtok_quote(c->tline, " \t", "e_ptr);
1799 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1800 if(quote_ptr) *quote_ptr = ' ';
1801 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1802 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1803 if(quote_ptr) *quote_ptr = '\0';
1805 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1806 if(c->argc >= c->argv_size) {
1808 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1810 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1814 c->argv_size += ARGS_STEP;
1818 c->argv[c->argc++] = token;
1820 c->argv[c->argc] = NULL;
1827 ucdata_unload( UCDATA_ALL );
1829 /* NOTE: in case of early exit, frontendDB can be NULL */
1830 if ( frontendDB->be_schemandn.bv_val )
1831 free( frontendDB->be_schemandn.bv_val );
1832 if ( frontendDB->be_schemadn.bv_val )
1833 free( frontendDB->be_schemadn.bv_val );
1834 if ( frontendDB->be_acl )
1835 acl_destroy( frontendDB->be_acl, NULL );
1838 if ( slapd_args_file )
1839 free ( slapd_args_file );
1840 if ( slapd_pid_file )
1841 free ( slapd_pid_file );
1842 if ( default_passwd_hash )
1843 ldap_charray_free( default_passwd_hash );
1847 slap_str2clist( char ***out, char *in, const char *brkstr )
1855 /* find last element in list */
1856 for (i = 0; *out && (*out)[i]; i++);
1858 /* protect the input string from strtok */
1859 str = ch_strdup( in );
1861 if ( *str == '\0' ) {
1866 /* Count words in string */
1868 for ( s = str; *s; s++ ) {
1869 if ( strchr( brkstr, *s ) != NULL ) {
1874 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1876 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1878 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1880 *new = ch_strdup( s );
1889 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1890 int argc, char **argv )
1892 ConfigArgs c = { 0 };
1903 c.op = SLAP_CONFIG_ADD;
1904 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1906 rc = SLAP_CONF_UNKNOWN;
1907 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1909 c.table = be->be_cf_ocs->co_type;
1910 rc = config_add_vals( ct, &c );