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>
37 #include <sys/types.h>
43 #include "slapi/slapi.h"
51 * defaults for various global variables
53 slap_mask_t global_allows = 0;
54 slap_mask_t global_disallows = 0;
55 int global_gentlehup = 0;
56 int global_idletimeout = 0;
57 char *global_host = NULL;
58 char *global_realm = NULL;
59 char *ldap_srvtab = "";
60 char **default_passwd_hash = NULL;
61 struct berval default_search_base = BER_BVNULL;
62 struct berval default_search_nbase = BER_BVNULL;
64 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
65 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
67 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
68 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
70 char *slapd_pid_file = NULL;
71 char *slapd_args_file = NULL;
73 int use_reverse_lookup = 0;
76 int slapi_plugins_used = 0;
79 static int fp_getline(FILE *fp, ConfigArgs *c);
80 static void fp_getline_init(ConfigArgs *c);
81 static int fp_parse_line(ConfigArgs *c);
83 static char *strtok_quote(char *line, char *sep, char **quote_ptr);
84 static char *strtok_quote_ldif(char **line);
87 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
90 c = ch_calloc( 1, sizeof( ConfigArgs ) );
91 if ( c == NULL ) return(NULL);
97 snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
102 init_config_argv( ConfigArgs *c )
104 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
105 c->argv_size = ARGS_STEP + 1;
108 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
111 for(i = 0; Conf[i].name; i++)
112 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
113 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
114 if ( !Conf[i].name ) return NULL;
118 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
119 int rc, arg_user, arg_type, iarg;
123 arg_type = Conf->arg_type;
124 if(arg_type == ARG_IGNORED) {
125 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
126 c->log, Conf->name, 0);
129 if((arg_type & ARG_DN) && c->argc == 1) {
133 if(Conf->min_args && (c->argc < Conf->min_args)) {
134 snprintf( c->msg, sizeof( c->msg ), "<%s> missing <%s> argument",
135 c->argv[0], Conf->what );
136 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
137 return(ARG_BAD_CONF);
139 if(Conf->max_args && (c->argc > Conf->max_args)) {
140 char *ignored = " ignored";
142 snprintf( c->msg, sizeof( c->msg ), "<%s> extra cruft after <%s>",
143 c->argv[0], Conf->what );
147 #endif /* LDAP_DEVEL */
148 Debug(LDAP_DEBUG_CONFIG, "%s: %s%s.\n",
149 c->log, c->msg, ignored );
151 return(ARG_BAD_CONF);
152 #endif /* LDAP_DEVEL */
154 if((arg_type & ARG_DB) && !c->be) {
155 snprintf( c->msg, sizeof( c->msg ), "<%s> only allowed within database declaration",
157 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
159 return(ARG_BAD_CONF);
161 if((arg_type & ARG_PRE_BI) && c->bi) {
162 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any backend %sdeclaration",
163 c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
164 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
166 return(ARG_BAD_CONF);
168 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
169 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any database declaration",
171 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
173 return(ARG_BAD_CONF);
175 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
176 snprintf( c->msg, sizeof( c->msg ), "<%s> old format not supported", c->argv[0] );
177 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
179 return(ARG_BAD_CONF);
181 if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
182 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid config_table, arg_item is NULL",
184 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
186 return(ARG_BAD_CONF);
188 c->type = arg_user = (arg_type & ARGS_USERLAND);
189 memset(&c->values, 0, sizeof(c->values));
190 if(arg_type & ARGS_NUMERIC) {
192 iarg = 0; larg = 0; barg = 0;
193 switch(arg_type & ARGS_NUMERIC) {
194 case ARG_INT: iarg = strtol(c->argv[1], NULL, 0); break;
195 case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
196 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
200 } else if(!strcasecmp(c->argv[1], "on") ||
201 !strcasecmp(c->argv[1], "true")) {
203 } else if(!strcasecmp(c->argv[1], "off") ||
204 !strcasecmp(c->argv[1], "false")) {
207 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value, ignored",
209 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
215 j = (arg_type & ARG_NONZERO) ? 1 : 0;
216 if(iarg < j && larg < j && barg < j ) {
217 larg = larg ? larg : (barg ? barg : iarg);
218 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value, ignored",
220 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
222 return(ARG_BAD_CONF);
224 switch(arg_type & ARGS_NUMERIC) {
226 case ARG_INT: c->value_int = iarg; break;
227 case ARG_LONG: c->value_long = larg; break;
228 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
230 } else if(arg_type & ARG_STRING) {
232 c->value_string = ch_strdup(c->argv[1]);
233 } else if(arg_type & ARG_BERVAL) {
235 ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
236 } else if(arg_type & ARG_DN) {
238 ber_str2bv( c->argv[1], 0, 0, &bv );
239 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
240 if ( rc != LDAP_SUCCESS ) {
241 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid DN %d (%s)",
242 c->argv[0], rc, ldap_err2string( rc ));
243 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
244 return(ARG_BAD_CONF);
247 ch_free( c->value_ndn.bv_val );
248 ch_free( c->value_dn.bv_val );
254 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
258 arg_type = Conf->arg_type;
259 if(arg_type & ARG_MAGIC) {
260 if(!c->be) c->be = frontendDB;
262 rc = (*((ConfigDriver*)Conf->arg_item))(c);
264 if(c->be == frontendDB) c->be = NULL;
268 snprintf( c->msg, sizeof( c->msg ), "<%s> handler exited with %d",
270 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
273 return(ARG_BAD_CONF);
277 if(arg_type & ARG_OFFSET) {
279 ptr = c->be->be_private;
281 ptr = c->bi->bi_private;
283 snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
285 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
287 return(ARG_BAD_CONF);
289 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
290 } else if (arg_type & ARGS_POINTER) {
291 ptr = Conf->arg_item;
293 if(arg_type & ARGS_POINTER)
294 switch(arg_type & ARGS_POINTER) {
296 case ARG_INT: *(int*)ptr = c->value_int; break;
297 case ARG_LONG: *(long*)ptr = c->value_long; break;
298 case ARG_BER_LEN_T: *(ber_len_t*)ptr = c->value_ber_t; break;
300 char *cc = *(char**)ptr;
302 if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
303 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
304 c->log, Conf->name, 0 );
305 return(ARG_BAD_CONF);
309 *(char **)ptr = c->value_string;
313 *(struct berval *)ptr = c->value_bv;
319 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
322 arg_type = Conf->arg_type;
323 if(arg_type == ARG_IGNORED) {
324 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
325 c->log, Conf->name, 0);
328 rc = config_check_vals( Conf, c, 0 );
330 return config_set_vals( Conf, c );
334 config_del_vals(ConfigTable *cf, ConfigArgs *c)
338 /* If there is no handler, just ignore it */
339 if ( cf->arg_type & ARG_MAGIC ) {
340 c->op = LDAP_MOD_DELETE;
341 c->type = cf->arg_type & ARGS_USERLAND;
342 rc = (*((ConfigDriver*)cf->arg_item))(c);
348 config_get_vals(ConfigTable *cf, ConfigArgs *c)
354 if ( cf->arg_type & ARG_IGNORED ) {
358 memset(&c->values, 0, sizeof(c->values));
359 c->rvalue_vals = NULL;
360 c->rvalue_nvals = NULL;
361 c->op = SLAP_CONFIG_EMIT;
362 c->type = cf->arg_type & ARGS_USERLAND;
364 if ( cf->arg_type & ARG_MAGIC ) {
365 rc = (*((ConfigDriver*)cf->arg_item))(c);
368 if ( cf->arg_type & ARG_OFFSET ) {
370 ptr = c->be->be_private;
372 ptr = c->bi->bi_private;
375 ptr = (void *)((char *)ptr + (long)cf->arg_item);
380 switch(cf->arg_type & ARGS_POINTER) {
382 case ARG_INT: c->value_int = *(int *)ptr; break;
383 case ARG_LONG: c->value_long = *(long *)ptr; break;
384 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)ptr; break;
387 c->value_string = ch_strdup(*(char **)ptr);
390 ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
393 if ( cf->arg_type & ARGS_POINTER) {
395 switch(cf->arg_type & ARGS_POINTER) {
396 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
397 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
398 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
399 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
400 c->value_int ? "TRUE" : "FALSE"); break;
402 if ( c->value_string && c->value_string[0]) {
403 ber_str2bv( c->value_string, 0, 0, &bv);
409 if ( !BER_BVISEMPTY( &c->value_bv )) {
416 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
419 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
420 ber_bvarray_add(&c->rvalue_vals, &bv);
422 value_add_one(&c->rvalue_vals, &bv);
428 init_config_attrs(ConfigTable *ct) {
429 LDAPAttributeType *at;
433 for (i=0; ct[i].name; i++ ) {
436 if ( !ct[i].attribute ) continue;
437 at = ldap_str2attributetype( ct[i].attribute,
438 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
440 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
441 ct[i].attribute, ldap_scherr2str(code), err );
445 code = at_add( at, 0, NULL, &err );
447 if ( code == SLAP_SCHERR_ATTR_DUP ) {
451 ldap_attributetype_free( at );
452 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
453 ct[i].attribute, scherr2str(code), err );
457 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
459 ldap_attributetype_free( at );
464 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
465 ct[i].attribute, err );
474 init_config_ocs( ConfigOCs *ocs ) {
477 for (i=0;ocs[i].co_def;i++) {
482 oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
483 LDAP_SCHEMA_ALLOW_ALL );
485 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
486 ocs[i].co_def, ldap_scherr2str(code), err );
489 code = oc_add(oc,0,NULL,&err);
490 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
491 fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
492 ocs[i].co_def, scherr2str(code), err );
495 ocs[i].co_oc = oc_find(oc->oc_names[0]);
501 /* Split an LDIF line into space-separated tokens. Words may be grouped
502 * by quotes. A quoted string may begin in the middle of a word, but must
503 * end at the end of the word (be followed by whitespace or EOS). Any other
504 * quotes are passed through unchanged. All other characters are passed
508 strtok_quote_ldif( char **line )
510 char *beg, *ptr, *quote=NULL;
518 while( isspace( *ptr )) ptr++;
529 if ( inquote && ( !ptr[1] || isspace(ptr[1]))) {
539 if ( isspace( *ptr )) {
545 while ( quote < ptr ) {
553 while ( isspace( *ptr )) ptr++;
560 config_parse_ldif( ConfigArgs *c )
563 c->tline = ch_strdup(c->line);
566 while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
568 if ( c->argc >= c->argv_size ) {
569 char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
572 c->argv_size += ARGS_STEP;
575 c->argv[c->argc] = NULL;
579 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
583 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
584 ct->ad->ad_cname.bv_val, valx );
586 c->argv[0] = ct->ad->ad_cname.bv_val;
588 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
589 c->argv[c->argc] = c->line;
591 c->argv[c->argc] = NULL;
594 config_parse_ldif( c );
596 rc = config_check_vals( ct, c, 1 );
600 rc = LDAP_CONSTRAINT_VIOLATION;
606 config_parse_add(ConfigTable *ct, ConfigArgs *c)
610 snprintf( c->log, sizeof( c->log ), "%s: value #%d",
611 ct->ad->ad_cname.bv_val, c->valx );
613 c->argv[0] = ct->ad->ad_cname.bv_val;
615 if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
616 c->argv[c->argc] = c->line;
618 c->argv[c->argc] = NULL;
621 config_parse_ldif( c );
623 c->op = LDAP_MOD_ADD;
624 rc = config_add_vals( ct, c );
631 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
639 c = ch_calloc( 1, sizeof( ConfigArgs ) );
645 memcpy( c, cf, sizeof( ConfigArgs ) );
647 c->depth = depth; /* XXX */
654 init_config_argv( c );
656 if ( stat( fname, &s ) != 0 ) {
658 Debug(LDAP_DEBUG_ANY,
659 "could not stat config file \"%s\": %s (%d)\n",
660 fname, strerror(errno), errno);
664 if ( !S_ISREG( s.st_mode ) ) {
666 Debug(LDAP_DEBUG_ANY,
667 "regular file expected, got \"%s\"\n",
672 fp = fopen( fname, "r" );
675 Debug(LDAP_DEBUG_ANY,
676 "could not open config file \"%s\": %s (%d)\n",
677 fname, strerror(errno), errno);
681 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
687 while ( fp_getline( fp, c ) ) {
688 /* skip comments and blank lines */
689 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
693 snprintf( c->log, sizeof( c->log ), "%s: line %d",
694 c->fname, c->lineno );
698 if ( fp_parse_line( c ) ) {
704 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line"
705 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
707 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
710 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
712 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
715 c->op = SLAP_CONFIG_ADD;
717 ct = config_find_keyword( cft, c );
719 rc = config_add_vals( ct, c );
722 if ( rc & ARGS_USERLAND ) {
723 /* XXX a usertype would be opaque here */
724 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
725 c->log, c->argv[0], 0);
729 } else if ( rc == ARG_BAD_CONF ) {
734 } else if ( c->bi && !c->be ) {
735 rc = SLAP_CONF_UNKNOWN;
736 if ( c->bi->bi_cf_ocs ) {
737 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
739 rc = config_add_vals( ct, c );
742 if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
743 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
748 case SLAP_CONF_UNKNOWN:
749 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
750 "unknown directive <%s> inside backend info definition"
751 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
752 c->log, *c->argv, 0);
753 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
755 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
762 } else if ( c->be ) {
763 rc = SLAP_CONF_UNKNOWN;
764 if ( c->be->be_cf_ocs ) {
765 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
767 rc = config_add_vals( ct, c );
770 if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
771 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
776 case SLAP_CONF_UNKNOWN:
777 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
778 "unknown directive <%s> inside backend database "
779 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
780 c->log, *c->argv, 0);
781 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
783 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
790 } else if ( frontendDB->be_config ) {
791 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
794 case SLAP_CONF_UNKNOWN:
795 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
796 "unknown directive <%s> inside global database definition"
797 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
798 c->log, *c->argv, 0);
799 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
801 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
809 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
810 "unknown directive <%s> outside backend info and database definitions"
811 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
812 c->log, *c->argv, 0);
813 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
816 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
818 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
832 /* restrictops, allows, disallows, requires, loglevel */
835 verb_to_mask(const char *word, slap_verbmasks *v) {
837 for(i = 0; !BER_BVISNULL(&v[i].word); i++)
838 if(!strcasecmp(word, v[i].word.bv_val))
844 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
846 for(i = 1; i < argc; i++) {
847 j = verb_to_mask(argv[i], v);
848 if(BER_BVISNULL(&v[j].word)) return i;
849 while (!v[j].mask) j--;
855 /* Mask keywords that represent multiple bits should occur before single
856 * bit keywords in the verbmasks array.
859 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
863 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
864 if (!v[i].mask) continue;
865 if (( m & v[i].mask ) == v[i].mask ) {
866 value_add_one( bva, &v[i].word );
877 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
881 assert( *vp == NULL );
883 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ )
886 *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
888 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
889 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
890 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
893 BER_BVZERO( &(*vp)[ i ].word );
899 slap_verbmasks_destroy( slap_verbmasks *v )
905 for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
906 ch_free( v[ i ].word.bv_val );
915 slap_verbmasks_append(
919 slap_mask_t *ignore )
924 return LDAP_OPERATIONS_ERROR;
927 for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
928 if ( !(*vp)[ i ].mask ) continue;
930 if ( ignore != NULL ) {
933 for ( j = 0; ignore[ j ] != 0; j++ ) {
934 if ( (*vp)[ i ].mask == ignore[ j ] ) {
940 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
941 if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
942 /* already set; ignore */
946 return LDAP_TYPE_OR_VALUE_EXISTS;
949 if ( m & (*vp)[ i ].mask ) {
951 return LDAP_CONSTRAINT_VIOLATION;
956 *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
957 ber_dupbv( &(*vp)[ i ].word, v );
958 *((slap_mask_t *)&(*vp)[ i ].mask) = m;
959 BER_BVZERO( &(*vp)[ i + 1 ].word );
965 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
968 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
969 if ( m == v[i].mask ) {
979 static slap_verbmasks tlskey[] = {
980 { BER_BVC("no"), SB_TLS_OFF },
981 { BER_BVC("yes"), SB_TLS_ON },
982 { BER_BVC("critical"), SB_TLS_CRITICAL },
986 static slap_verbmasks methkey[] = {
987 { BER_BVC("none"), LDAP_AUTH_NONE },
988 { BER_BVC("simple"), LDAP_AUTH_SIMPLE },
989 #ifdef HAVE_CYRUS_SASL
990 { BER_BVC("sasl"), LDAP_AUTH_SASL },
995 static slap_cf_aux_table bindkey[] = {
996 { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
997 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
998 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
999 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
1000 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1001 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1002 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1003 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1004 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
1005 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
1006 { BER_BVNULL, 0, 0, 0, NULL }
1010 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1013 slap_cf_aux_table *tab;
1015 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1016 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
1020 struct berval *bptr;
1021 const char *val = word + tab->key.bv_len;
1023 switch ( tab->type ) {
1025 cptr = (char **)((char *)dst + tab->off);
1026 *cptr = ch_strdup( val );
1030 bptr = (struct berval *)((char *)dst + tab->off);
1031 ber_str2bv( val, 0, 1, bptr );
1035 assert( tab->aux != NULL );
1036 iptr = (int *)((char *)dst + tab->off);
1039 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
1040 if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
1041 *iptr = tab->aux[j].mask;
1048 iptr = (int *)((char *)dst + tab->off);
1050 *iptr = strtol( val, &next, 0 );
1051 if ( next == val || next[ 0 ] != '\0' ) {
1057 uptr = (unsigned *)((char *)dst + tab->off);
1059 *uptr = strtoul( val, &next, 0 );
1060 if ( next == val || next[ 0 ] != '\0' ) {
1067 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1079 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1081 char buf[BUFSIZ], *ptr;
1082 slap_cf_aux_table *tab;
1086 for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1090 struct berval *bptr;
1092 cptr = (char **)((char *)src + tab->off);
1094 switch ( tab->type ) {
1096 bptr = (struct berval *)((char *)src + tab->off);
1097 cptr = &bptr->bv_val;
1101 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1102 if ( tab->quote ) *ptr++ = '"';
1103 ptr = lutil_strcopy( ptr, *cptr );
1104 if ( tab->quote ) *ptr++ = '"';
1109 assert( tab->aux != NULL );
1110 iptr = (int *)((char *)src + tab->off);
1112 for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
1113 if ( *iptr == tab->aux[i].mask ) {
1115 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1116 ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
1123 iptr = (int *)((char *)src + tab->off);
1125 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1126 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1130 uptr = (unsigned *)((char *)src + tab->off);
1132 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1133 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1138 tmp.bv_len = ptr - buf;
1139 ber_dupbv( bv, &tmp );
1144 bindconf_parse( const char *word, slap_bindconf *bc )
1146 return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1150 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1152 return slap_cf_aux_table_unparse( bc, bv, bindkey );
1155 void bindconf_free( slap_bindconf *bc ) {
1156 if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1157 ch_free( bc->sb_uri.bv_val );
1158 BER_BVZERO( &bc->sb_uri );
1160 if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1161 ch_free( bc->sb_binddn.bv_val );
1162 BER_BVZERO( &bc->sb_binddn );
1164 if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1165 ch_free( bc->sb_cred.bv_val );
1166 BER_BVZERO( &bc->sb_cred );
1168 if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1169 ch_free( bc->sb_saslmech.bv_val );
1170 BER_BVZERO( &bc->sb_saslmech );
1172 if ( bc->sb_secprops ) {
1173 ch_free( bc->sb_secprops );
1174 bc->sb_secprops = NULL;
1176 if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1177 ch_free( bc->sb_realm.bv_val );
1178 BER_BVZERO( &bc->sb_realm );
1180 if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1181 ch_free( bc->sb_authcId.bv_val );
1182 BER_BVZERO( &bc->sb_authcId );
1184 if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1185 ch_free( bc->sb_authzId.bv_val );
1186 BER_BVZERO( &bc->sb_authzId );
1191 /* -------------------------------------- */
1195 strtok_quote( char *line, char *sep, char **quote_ptr )
1202 if ( line != NULL ) {
1205 while ( *next && strchr( sep, *next ) ) {
1209 if ( *next == '\0' ) {
1215 for ( inquote = 0; *next; ) {
1223 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1229 next + 1, strlen( next + 1 ) + 1 );
1230 next++; /* dont parse the escaped character */
1235 if ( strchr( sep, *next ) != NULL ) {
1249 static char buf[BUFSIZ];
1251 static size_t lmax, lcur;
1253 #define CATLINE( buf ) \
1255 size_t len = strlen( buf ); \
1256 while ( lcur + len + 1 > lmax ) { \
1258 line = (char *) ch_realloc( line, lmax ); \
1260 strcpy( line + lcur, buf ); \
1265 fp_getline_init(ConfigArgs *c) {
1271 fp_getline( FILE *fp, ConfigArgs *c )
1279 /* avoid stack of bufs */
1280 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1286 while ( fgets( buf, sizeof( buf ), fp ) ) {
1287 p = strchr( buf, '\n' );
1289 if ( p > buf && p[-1] == '\r' ) {
1297 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1304 if ( !isspace( (unsigned char)buf[0] ) ) {
1315 return(line[0] ? 1 : 0);
1319 fp_parse_line(ConfigArgs *c)
1322 static char *const hide[] = {
1323 "rootpw", "replica", "syncrepl", /* in slapd */
1324 "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
1325 "acl-passwd", "bindpw", /* in back-<ldap/meta> */
1326 "pseudorootpw", /* in back-meta */
1327 "dbpasswd", /* in back-sql */
1331 int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1333 c->tline = ch_strdup(c->line);
1334 token = strtok_quote(c->tline, " \t", "e_ptr);
1336 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1337 if(quote_ptr) *quote_ptr = ' ';
1338 Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1339 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1340 if(quote_ptr) *quote_ptr = '\0';
1342 for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
1343 if(c->argc >= c->argv_size) {
1345 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1347 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1351 c->argv_size += ARGS_STEP;
1355 c->argv[c->argc++] = token;
1357 c->argv[c->argc] = NULL;
1364 ucdata_unload( UCDATA_ALL );
1366 /* NOTE: in case of early exit, frontendDB can be NULL */
1367 if ( frontendDB->be_schemandn.bv_val )
1368 free( frontendDB->be_schemandn.bv_val );
1369 if ( frontendDB->be_schemadn.bv_val )
1370 free( frontendDB->be_schemadn.bv_val );
1371 if ( frontendDB->be_acl )
1372 acl_destroy( frontendDB->be_acl, NULL );
1375 if ( slapd_args_file )
1376 free ( slapd_args_file );
1377 if ( slapd_pid_file )
1378 free ( slapd_pid_file );
1379 if ( default_passwd_hash )
1380 ldap_charray_free( default_passwd_hash );
1384 slap_str2clist( char ***out, char *in, const char *brkstr )
1392 /* find last element in list */
1393 for (i = 0; *out && (*out)[i]; i++);
1395 /* protect the input string from strtok */
1396 str = ch_strdup( in );
1398 if ( *str == '\0' ) {
1403 /* Count words in string */
1405 for ( s = str; *s; s++ ) {
1406 if ( strchr( brkstr, *s ) != NULL ) {
1411 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1413 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1415 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1417 *new = ch_strdup( s );
1426 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1427 int argc, char **argv )
1429 ConfigArgs c = { 0 };
1439 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1441 rc = SLAP_CONF_UNKNOWN;
1442 ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1444 rc = config_add_vals( ct, &c );