1 /* config.c - configuration file handling routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 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>
39 #include "slapi/slapi.h"
47 * defaults for various global variables
49 slap_mask_t global_allows = 0;
50 slap_mask_t global_disallows = 0;
51 int global_gentlehup = 0;
52 int global_idletimeout = 0;
53 char *global_host = NULL;
54 char *global_realm = NULL;
55 char *ldap_srvtab = "";
56 char **default_passwd_hash = NULL;
57 struct berval default_search_base = BER_BVNULL;
58 struct berval default_search_nbase = BER_BVNULL;
60 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
61 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
63 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
64 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
66 char *slapd_pid_file = NULL;
67 char *slapd_args_file = NULL;
69 int use_reverse_lookup = 0;
72 int slapi_plugins_used = 0;
75 static int fp_getline(FILE *fp, ConfigArgs *c);
76 static void fp_getline_init(ConfigArgs *c);
77 static int fp_parse_line(ConfigArgs *c);
79 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
81 int read_config_file(const char *fname, int depth, ConfigArgs *cf);
84 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
87 c = ch_calloc( 1, sizeof( ConfigArgs ) );
88 if ( c == NULL ) return(NULL);
94 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
99 init_config_argv( ConfigArgs *c )
101 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
102 c->argv_size = ARGS_STEP + 1;
105 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
108 for(i = 0; Conf[i].name; i++)
109 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
110 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
111 if ( !Conf[i].name ) return NULL;
115 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
116 int rc, arg_user, arg_type, iarg;
120 arg_type = Conf->arg_type;
121 if(arg_type == ARG_IGNORED) {
122 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
123 c->log, Conf->name, 0);
126 if((arg_type & ARG_DN) && c->argc == 1) {
130 if(Conf->min_args && (c->argc < Conf->min_args)) {
131 sprintf( c->msg, "<%s> missing <%s> argument",
132 c->argv[0], Conf->what );
133 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
134 return(ARG_BAD_CONF);
136 if(Conf->max_args && (c->argc > Conf->max_args)) {
137 sprintf( c->msg, "<%s> extra cruft after <%s> ignored",
138 c->argv[0], Conf->what );
139 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
141 if((arg_type & ARG_DB) && !c->be) {
142 sprintf( c->msg, "<%s> only allowed within database declaration",
144 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
146 return(ARG_BAD_CONF);
148 if((arg_type & ARG_PRE_BI) && c->bi) {
149 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
150 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
151 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
153 return(ARG_BAD_CONF);
155 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
156 sprintf( c->msg, "<%s> must occur before any database declaration",
158 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
160 return(ARG_BAD_CONF);
162 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
163 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
164 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
166 return(ARG_BAD_CONF);
168 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
169 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
171 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
173 return(ARG_BAD_CONF);
175 c->type = arg_user = (arg_type & ARGS_USERLAND);
176 memset(&c->values, 0, sizeof(c->values));
177 if(arg_type & ARGS_NUMERIC) {
179 iarg = 0; larg = 0; barg = 0;
180 switch(arg_type & ARGS_NUMERIC) {
181 case ARG_INT: iarg = atoi(c->argv[1]); break;
182 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
183 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
187 } else if(!strcasecmp(c->argv[1], "on") ||
188 !strcasecmp(c->argv[1], "true")) {
190 } else if(!strcasecmp(c->argv[1], "off") ||
191 !strcasecmp(c->argv[1], "false")) {
194 sprintf( c->msg, "<%s> invalid value, ignored",
196 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
202 j = (arg_type & ARG_NONZERO) ? 1 : 0;
203 if(iarg < j && larg < j && barg < j ) {
204 larg = larg ? larg : (barg ? barg : iarg);
205 sprintf( c->msg, "<%s> invalid value, ignored",
207 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
209 return(ARG_BAD_CONF);
211 switch(arg_type & ARGS_NUMERIC) {
213 case ARG_INT: c->value_int = iarg; break;
214 case ARG_LONG: c->value_long = larg; break;
215 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
217 } else if(arg_type & ARG_STRING) {
219 c->value_string = ch_strdup(c->argv[1]);
220 } else if(arg_type & ARG_BERVAL) {
222 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
223 } else if(arg_type & ARG_DN) {
225 ber_str2bv( c->argv[1], 0, 0, &bv );
226 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
227 if ( rc != LDAP_SUCCESS ) {
228 sprintf( c->msg, "<%s> invalid DN %d (%s)",
229 c->argv[0], rc, ldap_err2string( rc ));
230 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
231 return(ARG_BAD_CONF);
234 ch_free( c->value_ndn.bv_val );
235 ch_free( c->value_dn.bv_val );
241 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
245 arg_type = Conf->arg_type;
246 if(arg_type & ARG_MAGIC) {
247 if(!c->be) c->be = frontendDB;
249 rc = (*((ConfigDriver*)Conf->arg_item))(c);
251 if(c->be == frontendDB) c->be = NULL;
255 sprintf( c->msg, "<%s> handler exited with %d",
257 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
260 return(ARG_BAD_CONF);
264 if(arg_type & ARG_OFFSET) {
266 ptr = c->be->be_private;
268 ptr = c->bi->bi_private;
270 sprintf( c->msg, "<%s> offset is missing base pointer",
272 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
274 return(ARG_BAD_CONF);
276 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
277 } else if (arg_type & ARGS_POINTER) {
278 ptr = Conf->arg_item;
280 if(arg_type & ARGS_POINTER)
281 switch(arg_type & ARGS_POINTER) {
283 case ARG_INT: *(int*)ptr = c->value_int; break;
284 case ARG_LONG: *(long*)ptr = c->value_long; break;
285 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
287 char *cc = *(char**)ptr;
289 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
290 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
291 c->log, Conf->name, 0 );
292 return(ARG_BAD_CONF);
296 *(char **)ptr = c->value_string;
300 *(struct berval *)ptr = c->value_bv;
306 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
309 arg_type = Conf->arg_type;
310 if(arg_type == ARG_IGNORED) {
311 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
312 c->log, Conf->name, 0);
315 rc = config_check_vals( Conf, c, 0 );
317 return config_set_vals( Conf, c );
321 config_del_vals(ConfigTable *cf, ConfigArgs *c)
325 /* If there is no handler, just ignore it */
326 if ( cf->arg_type & ARG_MAGIC ) {
327 c->op = LDAP_MOD_DELETE;
328 c->type = cf->arg_type & ARGS_USERLAND;
329 rc = (*((ConfigDriver*)cf->arg_item))(c);
335 config_get_vals(ConfigTable *cf, ConfigArgs *c)
341 if ( cf->arg_type & ARG_IGNORED ) {
345 memset(&c->values, 0, sizeof(c->values));
346 c->rvalue_vals = NULL;
347 c->rvalue_nvals = NULL;
348 c->op = SLAP_CONFIG_EMIT;
349 c->type = cf->arg_type & ARGS_USERLAND;
351 if ( cf->arg_type & ARG_MAGIC ) {
352 rc = (*((ConfigDriver*)cf->arg_item))(c);
355 if ( cf->arg_type & ARG_OFFSET ) {
357 ptr = c->be->be_private;
359 ptr = c->bi->bi_private;
362 ptr = (void *)((char *)ptr + (int)cf->arg_item);
367 switch(cf->arg_type & ARGS_POINTER) {
369 case ARG_INT: c->value_int = *(int *)ptr; break;
370 case ARG_LONG: c->value_long = *(long *)ptr; break;
371 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
374 c->value_string = ch_strdup(*(char **)ptr);
377 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
380 if ( cf->arg_type & ARGS_POINTER) {
382 switch(cf->arg_type & ARGS_POINTER) {
383 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
384 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
385 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
386 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
387 c->value_int ? "TRUE" : "FALSE"); break;
389 if ( c->value_string && c->value_string[0]) {
390 ber_str2bv( c->value_string, 0, 0, &bv);
396 if ( !BER_BVISEMPTY( &c->value_bv )) {
403 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
404 ber_bvarray_add(&c->rvalue_vals, &bv);
406 value_add_one(&c->rvalue_vals, &bv);
412 init_config_attrs(ConfigTable *ct) {
413 LDAPAttributeType *at;
417 for (i=0; ct[i].name; i++ ) {
418 if ( !ct[i].attribute ) continue;
419 at = ldap_str2attributetype( ct[i].attribute,
420 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
422 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
423 ct[i].attribute, ldap_scherr2str(code), err );
426 code = at_add( at, 0, NULL, &err );
427 if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
428 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
429 ct[i].attribute, scherr2str(code), err );
432 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
434 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
435 ct[i].attribute, err );
445 init_config_ocs( ConfigOCs *ocs ) {
448 for (i=0;ocs[i].def;i++) {
453 oc = ldap_str2objectclass( ocs[i].def, &code, &err,
454 LDAP_SCHEMA_ALLOW_ALL );
456 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
457 ocs[i].def, ldap_scherr2str(code), err );
460 code = oc_add(oc,0,NULL,&err);
461 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
462 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
463 ocs[i].def, scherr2str(code), err );
467 *ocs[i].oc = oc_find(oc->oc_names[0]);
475 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
479 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
480 ct->ad->ad_cname.bv_val, valx );
482 c->argv[0] = ct->ad->ad_cname.bv_val;
483 if ( fp_parse_line( c ) ) {
486 rc = config_check_vals( ct, c, 1 );
489 rc = LDAP_CONSTRAINT_VIOLATION;
496 config_parse_add(ConfigTable *ct, ConfigArgs *c)
500 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
501 ct->ad->ad_cname.bv_val, c->valx );
503 c->argv[0] = ct->ad->ad_cname.bv_val;
504 if ( fp_parse_line( c ) ) {
507 c->op = LDAP_MOD_ADD;
508 rc = config_add_vals( ct, c );
516 read_config_file(const char *fname, int depth, ConfigArgs *cf)
523 c = ch_calloc( 1, sizeof( ConfigArgs ) );
529 memcpy( c, cf, sizeof( ConfigArgs ) );
531 c->depth = depth; /* XXX */
538 init_config_argv( c );
540 fp = fopen( fname, "r" );
543 Debug(LDAP_DEBUG_ANY,
544 "could not open config file \"%s\": %s (%d)\n",
545 fname, strerror(errno), errno);
549 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
555 while ( fp_getline( fp, c ) ) {
556 /* skip comments and blank lines */
557 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
561 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
562 c->fname, c->lineno );
566 if ( fp_parse_line( c ) ) {
572 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line"
573 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
575 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
578 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
580 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
583 c->op = SLAP_CONFIG_ADD;
585 ct = config_find_keyword( config_back_cf_table, c );
587 rc = config_add_vals( ct, c );
590 if ( rc & ARGS_USERLAND ) {
591 /* XXX a usertype would be opaque here */
592 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
593 c->log, c->argv[0], 0);
597 } else if ( rc == ARG_BAD_CONF ) {
602 } else if ( c->bi ) {
603 rc = SLAP_CONF_UNKNOWN;
604 if ( c->bi->bi_cf_table ) {
605 ct = config_find_keyword( c->bi->bi_cf_table, c );
607 rc = config_add_vals( ct, c );
610 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
611 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
616 case SLAP_CONF_UNKNOWN:
617 Debug(LDAP_DEBUG_CONFIG, "%s: "
618 "unknown directive <%s> inside backend info definition"
619 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
620 c->log, *c->argv, 0);
621 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
623 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
630 } else if ( c->be ) {
631 rc = SLAP_CONF_UNKNOWN;
632 if ( c->be->be_cf_table ) {
633 ct = config_find_keyword( c->be->be_cf_table, c );
635 rc = config_add_vals( ct, c );
638 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
639 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
644 case SLAP_CONF_UNKNOWN:
645 Debug( LDAP_DEBUG_CONFIG, "%s: "
646 "unknown directive <%s> inside backend database "
647 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
648 c->log, *c->argv, 0);
649 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
651 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
658 } else if ( frontendDB->be_config ) {
659 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
662 case SLAP_CONF_UNKNOWN:
663 Debug( LDAP_DEBUG_CONFIG, "%s: "
664 "unknown directive <%s> inside global database definition"
665 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
666 c->log, *c->argv, 0);
667 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
669 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
677 Debug(LDAP_DEBUG_CONFIG, "%s: "
678 "unknown directive <%s> outside backend info and database definitions"
679 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
680 c->log, *c->argv, 0);
681 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
684 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
686 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
690 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
691 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
692 &frontendDB->be_schemadn );
693 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
694 if ( rc != LDAP_SUCCESS ) {
695 Debug(LDAP_DEBUG_ANY, "%s: "
696 "unable to normalize default schema DN \"%s\"\n",
697 c->log, frontendDB->be_schemadn.bv_val, 0 );
698 /* must not happen */
712 /* restrictops, allows, disallows, requires, loglevel */
715 verb_to_mask(const char *word, slap_verbmasks *v) {
717 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
718 if(!strcasecmp(word, v[i].word.bv_val))
724 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
726 for(i = 1; i < argc; i++) {
727 j = verb_to_mask(argv[i], v);
728 if(BER_BVISNULL(&v[j].word)) return(1);
729 while (!v[j].mask) j--;
736 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
740 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
741 if (!v[i].mask) continue;
742 if (( m & v[i].mask ) == v[i].mask ) {
743 value_add_one( bva, &v[i].word );
749 static slap_verbmasks tlskey[] = {
750 { BER_BVC("no"), SB_TLS_OFF },
751 { BER_BVC("yes"), SB_TLS_ON },
752 { BER_BVC("critical"), SB_TLS_CRITICAL },
756 static slap_verbmasks methkey[] = {
758 { BER_BVC("none"), LDAP_AUTH_NONE },
760 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
761 #ifdef HAVE_CYRUS_SASL
762 { BER_BVC("sasl"), LDAP_AUTH_SASL },
767 typedef struct cf_aux_table {
775 static cf_aux_table bindkey[] = {
776 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
777 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
778 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
779 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
780 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
781 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
782 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
783 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
784 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
785 { BER_BVNULL, 0, 0, 0, NULL }
788 int bindconf_parse( const char *word, slap_bindconf *bc ) {
792 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
793 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
797 const char *val = word + tab->key.bv_len;
799 switch ( tab->type ) {
801 cptr = (char **)((char *)bc + tab->off);
802 *cptr = ch_strdup( val );
806 bptr = (struct berval *)((char *)bc + tab->off);
807 ber_str2bv( val, 0, 1, bptr );
812 iptr = (int *)((char *)bc + tab->off);
815 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
816 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
817 *iptr = tab->aux[j].mask;
825 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
836 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
837 char buf[BUFSIZ], *ptr;
842 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
847 cptr = (char **)((char *)bc + tab->off);
849 switch ( tab->type ) {
851 bptr = (struct berval *)((char *)bc + tab->off);
852 cptr = &bptr->bv_val;
856 ptr = lutil_strcopy( ptr, tab->key.bv_val );
857 if ( tab->quote ) *ptr++ = '"';
858 ptr = lutil_strcopy( ptr, *cptr );
859 if ( tab->quote ) *ptr++ = '"';
865 iptr = (int *)((char *)bc + tab->off);
867 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
868 if ( *iptr == tab->aux[i].mask ) {
870 ptr = lutil_strcopy( ptr, tab->key.bv_val );
871 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
879 tmp.bv_len = ptr - buf;
880 ber_dupbv( bv, &tmp );
884 void bindconf_free( slap_bindconf *bc ) {
885 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
886 ch_free( bc->sb_binddn.bv_val );
887 BER_BVZERO( &bc->sb_binddn );
889 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
890 ch_free( bc->sb_cred.bv_val );
891 BER_BVZERO( &bc->sb_cred );
893 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
894 ch_free( bc->sb_saslmech.bv_val );
895 BER_BVZERO( &bc->sb_saslmech );
897 if ( bc->sb_secprops ) {
898 ch_free( bc->sb_secprops );
899 bc->sb_secprops = NULL;
901 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
902 ch_free( bc->sb_realm.bv_val );
903 BER_BVZERO( &bc->sb_realm );
905 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
906 ch_free( bc->sb_authcId.bv_val );
907 BER_BVZERO( &bc->sb_authcId );
909 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
910 ch_free( bc->sb_authzId.bv_val );
911 BER_BVZERO( &bc->sb_authzId );
916 /* -------------------------------------- */
920 strtok_quote( char *line, char *sep, char **quote_ptr )
927 if ( line != NULL ) {
930 while ( *next && strchr( sep, *next ) ) {
934 if ( *next == '\0' ) {
940 for ( inquote = 0; *next; ) {
948 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
954 next + 1, strlen( next + 1 ) + 1 );
955 next++; /* dont parse the escaped character */
960 if ( strchr( sep, *next ) != NULL ) {
974 static char buf[BUFSIZ];
976 static size_t lmax, lcur;
978 #define CATLINE( buf ) \
980 size_t len = strlen( buf ); \
981 while ( lcur + len + 1 > lmax ) { \
983 line = (char *) ch_realloc( line, lmax ); \
985 strcpy( line + lcur, buf ); \
990 fp_getline_init(ConfigArgs *c) {
996 fp_getline( FILE *fp, ConfigArgs *c )
1004 /* avoid stack of bufs */
1005 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1011 while ( fgets( buf, sizeof( buf ), fp ) ) {
1012 p = strchr( buf, '\n' );
1014 if ( p > buf && p[-1] == '\r' ) {
1022 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1029 if ( !isspace( (unsigned char)buf[0] ) ) {
1040 return(line[0] ? 1 : 0);
1044 fp_parse_line(ConfigArgs *c)
1047 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
1051 c->tline = ch_strdup(c->line);
1052 token = strtok_quote(c->tline, " \t", "e_ptr);
1054 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1055 if(quote_ptr) *quote_ptr = ' ';
1056 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
1057 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1058 if(quote_ptr) *quote_ptr = '\0';
1060 for(; token; token = strtok_quote(NULL, " \t", "e_ptr)) {
1061 if(c->argc == c->argv_size - 1) {
1063 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1065 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1069 c->argv_size += ARGS_STEP;
1071 c->argv[c->argc++] = token;
1073 c->argv[c->argc] = NULL;
1080 ucdata_unload( UCDATA_ALL );
1082 /* NOTE: in case of early exit, frontendDB can be NULL */
1083 if ( frontendDB->be_schemandn.bv_val )
1084 free( frontendDB->be_schemandn.bv_val );
1085 if ( frontendDB->be_schemadn.bv_val )
1086 free( frontendDB->be_schemadn.bv_val );
1087 if ( frontendDB->be_acl )
1088 acl_destroy( frontendDB->be_acl, NULL );
1091 if ( slapd_args_file )
1092 free ( slapd_args_file );
1093 if ( slapd_pid_file )
1094 free ( slapd_pid_file );
1095 if ( default_passwd_hash )
1096 ldap_charray_free( default_passwd_hash );
1100 slap_str2clist( char ***out, char *in, const char *brkstr )
1108 /* find last element in list */
1109 for (i = 0; *out && (*out)[i]; i++);
1111 /* protect the input string from strtok */
1112 str = ch_strdup( in );
1114 if ( *str == '\0' ) {
1119 /* Count words in string */
1121 for ( s = str; *s; s++ ) {
1122 if ( strchr( brkstr, *s ) != NULL ) {
1127 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1129 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1131 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1133 *new = ch_strdup( s );
1142 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1143 int argc, char **argv )
1145 ConfigArgs c = { 0 };
1155 sprintf( c.log, "%s: line %lu", fname, lineno );
1157 rc = SLAP_CONF_UNKNOWN;
1158 ct = config_find_keyword( be->be_cf_table, &c );
1160 rc = config_add_vals( ct, &c );