1 /* config.c - configuration file handling routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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>
40 #include "slapi/slapi.h"
47 * defaults for various global variables
49 struct slap_limits_set deflimit = {
50 SLAPD_DEFAULT_TIMELIMIT, /* backward compatible limits */
53 SLAPD_DEFAULT_SIZELIMIT, /* backward compatible limits */
55 -1, /* no limit on unchecked size */
57 0, /* hide number of entries left */
58 0 /* number of total entries returned by pagedResults equal to hard limit */
61 AccessControl *global_acl = NULL;
62 slap_access_t global_default_access = ACL_READ;
63 slap_mask_t global_restrictops = 0;
64 slap_mask_t global_allows = 0;
65 slap_mask_t global_disallows = 0;
66 slap_mask_t global_requires = 0;
67 slap_ssf_set_t global_ssf_set;
69 int global_gentlehup = 0;
70 int global_idletimeout = 0;
71 char *global_host = NULL;
72 char *global_realm = NULL;
73 char *ldap_srvtab = "";
74 char **default_passwd_hash = NULL;
75 int cargc = 0, cargv_size = 0;
77 struct berval default_search_base = BER_BVNULL;
78 struct berval default_search_nbase = BER_BVNULL;
79 unsigned num_subordinates = 0;
80 struct berval global_schemadn = BER_BVNULL;
81 struct berval global_schemandn = BER_BVNULL;
83 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
84 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
86 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
87 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
89 char *slapd_pid_file = NULL;
90 char *slapd_args_file = NULL;
92 char *strtok_quote_ptr;
94 int use_reverse_lookup = 0;
97 int slapi_plugins_used = 0;
100 static char *fp_getline(FILE *fp, int *lineno);
101 static void fp_getline_init(int *lineno);
102 static int fp_parse_line(int lineno, char *line);
104 static char *strtok_quote(char *line, char *sep);
105 static int load_ucdata(char *path);
107 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
108 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
111 read_config( const char *fname, int depth )
114 char *line, *savefname, *saveline;
118 struct berval vals[2];
121 static int lastmod = 1;
122 static BackendInfo *bi = NULL;
123 static BackendDB *be = NULL;
125 vals[1].bv_val = NULL;
128 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
129 cargv_size = ARGS_STEP + 1;
132 if ( (fp = fopen( fname, "r" )) == NULL ) {
135 LDAP_LOG( CONFIG, ENTRY,
136 "read_config: " "could not open config file \"%s\": %s (%d)\n",
137 fname, strerror(errno), errno );
139 Debug( LDAP_DEBUG_ANY,
140 "could not open config file \"%s\": %s (%d)\n",
141 fname, strerror(errno), errno );
147 LDAP_LOG( CONFIG, ENTRY,
148 "read_config: reading config file %s\n", fname, 0, 0 );
150 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
154 fp_getline_init( &lineno );
156 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
157 /* skip comments and blank lines */
158 if ( line[0] == '#' || line[0] == '\0' ) {
162 /* fp_parse_line is destructive, we save a copy */
163 saveline = ch_strdup( line );
165 if ( fp_parse_line( lineno, line ) != 0 ) {
171 LDAP_LOG( CONFIG, INFO,
172 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
174 Debug( LDAP_DEBUG_ANY,
175 "%s: line %d: bad config line (ignored)\n",
182 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
185 LDAP_LOG( CONFIG, CRIT,
186 "%s : line %d: missing type in \"backend\" line.\n",
189 Debug( LDAP_DEBUG_ANY,
190 "%s: line %d: missing type in \"backend <type>\" line\n",
199 LDAP_LOG( CONFIG, CRIT,
200 "%s: line %d: backend line must appear before any "
201 "database definition.\n", fname, lineno , 0 );
203 Debug( LDAP_DEBUG_ANY,
204 "%s: line %d: backend line must appear before any database definition\n",
211 bi = backend_info( cargv[1] );
215 LDAP_LOG( CONFIG, CRIT,
216 "read_config: backend %s initialization failed.\n",
219 Debug( LDAP_DEBUG_ANY,
220 "backend %s initialization failed.\n",
226 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
229 LDAP_LOG( CONFIG, CRIT,
230 "%s: line %d: missing type in \"database <type>\" line\n",
233 Debug( LDAP_DEBUG_ANY,
234 "%s: line %d: missing type in \"database <type>\" line\n",
242 be = backend_db_init( cargv[1] );
246 LDAP_LOG( CONFIG, CRIT,
247 "database %s initialization failed.\n", cargv[1], 0, 0 );
249 Debug( LDAP_DEBUG_ANY,
250 "database %s initialization failed.\n",
257 /* set thread concurrency */
258 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
262 LDAP_LOG( CONFIG, CRIT,
263 "%s: line %d: missing level in \"concurrency <level\" "
264 " line\n", fname, lineno, 0 );
266 Debug( LDAP_DEBUG_ANY,
267 "%s: line %d: missing level in \"concurrency <level>\" line\n",
274 c = atoi( cargv[1] );
278 LDAP_LOG( CONFIG, CRIT,
279 "%s: line %d: invalid level (%d) in "
280 "\"concurrency <level>\" line.\n", fname, lineno, c );
282 Debug( LDAP_DEBUG_ANY,
283 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
290 ldap_pvt_thread_set_concurrency( c );
292 /* set sockbuf max */
293 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
297 LDAP_LOG( CONFIG, CRIT,
298 "%s: line %d: missing max in \"sockbuf_max_incoming "
299 "<bytes>\" line\n", fname, lineno, 0 );
301 Debug( LDAP_DEBUG_ANY,
302 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
309 max = atol( cargv[1] );
313 LDAP_LOG( CONFIG, CRIT,
314 "%s: line %d: invalid max value (%ld) in "
315 "\"sockbuf_max_incoming <bytes>\" line.\n",
316 fname, lineno, max );
318 Debug( LDAP_DEBUG_ANY,
319 "%s: line %d: invalid max value (%ld) in "
320 "\"sockbuf_max_incoming <bytes>\" line.\n",
321 fname, lineno, max );
327 sockbuf_max_incoming = max;
329 /* set sockbuf max authenticated */
330 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
334 LDAP_LOG( CONFIG, CRIT,
335 "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
336 "<bytes>\" line\n", fname, lineno, 0 );
338 Debug( LDAP_DEBUG_ANY,
339 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
346 max = atol( cargv[1] );
350 LDAP_LOG( CONFIG, CRIT,
351 "%s: line %d: invalid max value (%ld) in "
352 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
353 fname, lineno, max );
355 Debug( LDAP_DEBUG_ANY,
356 "%s: line %d: invalid max value (%ld) in "
357 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
358 fname, lineno, max );
364 sockbuf_max_incoming_auth = max;
366 /* set conn pending max */
367 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
371 LDAP_LOG( CONFIG, CRIT,
372 "%s: line %d: missing max in \"conn_max_pending "
373 "<requests>\" line\n", fname, lineno, 0 );
375 Debug( LDAP_DEBUG_ANY,
376 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
383 max = atol( cargv[1] );
387 LDAP_LOG( CONFIG, CRIT,
388 "%s: line %d: invalid max value (%ld) in "
389 "\"conn_max_pending <requests>\" line.\n",
390 fname, lineno, max );
392 Debug( LDAP_DEBUG_ANY,
393 "%s: line %d: invalid max value (%ld) in "
394 "\"conn_max_pending <requests>\" line.\n",
395 fname, lineno, max );
401 slap_conn_max_pending = max;
403 /* set conn pending max authenticated */
404 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
408 LDAP_LOG( CONFIG, CRIT,
409 "%s: line %d: missing max in \"conn_max_pending_auth "
410 "<requests>\" line\n", fname, lineno, 0 );
412 Debug( LDAP_DEBUG_ANY,
413 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
420 max = atol( cargv[1] );
424 LDAP_LOG( CONFIG, CRIT,
425 "%s: line %d: invalid max value (%ld) in "
426 "\"conn_max_pending_auth <requests>\" line.\n",
427 fname, lineno, max );
429 Debug( LDAP_DEBUG_ANY,
430 "%s: line %d: invalid max value (%ld) in "
431 "\"conn_max_pending_auth <requests>\" line.\n",
432 fname, lineno, max );
438 slap_conn_max_pending_auth = max;
440 /* default search base */
441 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
444 LDAP_LOG( CONFIG, CRIT,
445 "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
446 "line\n", fname, lineno, 0 );
448 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
449 "missing dn in \"defaultSearchBase <dn>\" line\n",
455 } else if ( cargc > 2 ) {
457 LDAP_LOG( CONFIG, INFO,
458 "%s: line %d: extra cruft after <dn> in "
459 "\"defaultSearchBase %s\" line (ignored)\n",
460 fname, lineno, cargv[1] );
462 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
463 "extra cruft after <dn> in \"defaultSearchBase %s\", "
465 fname, lineno, cargv[1] );
469 if ( bi != NULL || be != NULL ) {
471 LDAP_LOG( CONFIG, CRIT,
472 "%s: line %d: defaultSearchBase line must appear "
473 "prior to any backend or database definitions\n",
476 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
477 "defaultSearchBaase line must appear prior to "
478 "any backend or database definition\n",
485 if ( default_search_nbase.bv_len ) {
487 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
488 "default search base \"%s\" already defined "
489 "(discarding old)\n", fname, lineno,
490 default_search_base.bv_val );
492 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
493 "default search base \"%s\" already defined "
494 "(discarding old)\n",
495 fname, lineno, default_search_base.bv_val );
498 free( default_search_base.bv_val );
499 free( default_search_nbase.bv_val );
502 if ( load_ucdata( NULL ) < 0 ) return 1;
507 dn.bv_val = cargv[1];
508 dn.bv_len = strlen( dn.bv_val );
510 rc = dnPrettyNormal( NULL, &dn,
511 &default_search_base,
512 &default_search_nbase, NULL );
514 if( rc != LDAP_SUCCESS ) {
516 LDAP_LOG( CONFIG, CRIT,
517 "%s: line %d: defaultSearchBase DN is invalid.\n",
520 Debug( LDAP_DEBUG_ANY,
521 "%s: line %d: defaultSearchBase DN is invalid\n",
528 /* set maximum threads in thread pool */
529 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
533 LDAP_LOG( CONFIG, CRIT,
534 "%s: line %d: missing count in \"threads <count>\" line\n",
537 Debug( LDAP_DEBUG_ANY,
538 "%s: line %d: missing count in \"threads <count>\" line\n",
545 c = atoi( cargv[1] );
549 LDAP_LOG( CONFIG, CRIT,
550 "%s: line %d: invalid level (%d) in \"threads <count>\""
551 "line\n", fname, lineno, c );
553 Debug( LDAP_DEBUG_ANY,
554 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
561 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
563 /* save for later use */
564 connection_pool_max = c;
566 /* get pid file name */
567 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
570 LDAP_LOG( CONFIG, CRIT,
571 "%s: line %d missing file name in \"pidfile <file>\" "
572 "line.\n", fname, lineno, 0 );
574 Debug( LDAP_DEBUG_ANY,
575 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
582 slapd_pid_file = ch_strdup( cargv[1] );
584 /* get args file name */
585 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
588 LDAP_LOG( CONFIG, CRIT,
589 "%s: %d: missing file name in "
590 "\"argsfile <file>\" line.\n",
593 Debug( LDAP_DEBUG_ANY,
594 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
601 slapd_args_file = ch_strdup( cargv[1] );
603 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
606 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
609 /* default password hash */
610 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
613 LDAP_LOG( CONFIG, CRIT,
614 "%s: line %d: missing hash in "
615 "\"password-hash <hash>\" line.\n",
618 Debug( LDAP_DEBUG_ANY,
619 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
625 if ( default_passwd_hash != NULL ) {
627 LDAP_LOG( CONFIG, CRIT,
628 "%s: line %d: already set default password_hash!\n",
631 Debug( LDAP_DEBUG_ANY,
632 "%s: line %d: already set default password_hash!\n",
639 for(i = 1; i < cargc; i++) {
640 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
642 LDAP_LOG( CONFIG, CRIT,
643 "%s: line %d: password scheme \"%s\" not available\n",
644 fname, lineno, cargv[i] );
646 Debug( LDAP_DEBUG_ANY,
647 "%s: line %d: password scheme \"%s\" not available\n",
648 fname, lineno, cargv[i] );
651 ldap_charray_add( &default_passwd_hash, cargv[i] );
654 if( !default_passwd_hash ) {
656 LDAP_LOG( CONFIG, CRIT,
657 "%s: line %d: no valid hashes found\n",
660 Debug( LDAP_DEBUG_ANY,
661 "%s: line %d: no valid hashes found\n",
667 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
671 LDAP_LOG( CONFIG, CRIT,
672 "%s: line %d: missing format in "
673 "\"password-crypt-salt-format <format>\" line\n",
676 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
677 "\"password-crypt-salt-format <format>\" line\n",
684 lutil_salt_format( cargv[1] );
686 /* SASL config options */
687 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
688 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
690 #ifdef SLAP_X_SASL_REWRITE
691 /* use authid rewrite instead of sasl regexp */
692 } else if ( strncasecmp( cargv[0], "authid-rewrite", sizeof("authid-rewrite") - 1 ) == 0 ) {
693 int rc = slap_sasl_rewrite_config( fname, lineno,
698 #endif /* SLAP_X_SASL_REWRITE */
700 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
704 LDAP_LOG( CONFIG, CRIT,
705 "%s: line %d: missing dn in "
706 "\"schemadn <dn>\" line.\n", fname, lineno, 0 );
708 Debug( LDAP_DEBUG_ANY,
709 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
714 ber_str2bv( cargv[1], 0, 0, &dn );
716 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
717 &be->be_schemandn, NULL );
719 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
720 &global_schemandn, NULL );
722 if ( rc != LDAP_SUCCESS ) {
724 LDAP_LOG( CONFIG, CRIT,
725 "%s: line %d: schemadn DN is invalid.\n",
728 Debug( LDAP_DEBUG_ANY,
729 "%s: line %d: schemadn DN is invalid\n",
735 /* set UCDATA path */
736 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
740 LDAP_LOG( CONFIG, CRIT,
741 "%s: line %d: missing path in "
742 "\"ucdata-path <path>\" line.\n", fname, lineno, 0 );
744 Debug( LDAP_DEBUG_ANY,
745 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
752 err = load_ucdata( cargv[1] );
756 LDAP_LOG( CONFIG, CRIT,
757 "%s: line %d: ucdata already loaded, ucdata-path "
758 "must be set earlier in the file and/or be "
759 "specified only once!\n", fname, lineno, 0 );
761 Debug( LDAP_DEBUG_ANY,
762 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
771 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
773 struct slap_limits_set *lim;
777 LDAP_LOG( CONFIG, CRIT,
778 "%s: line %d: missing limit in \"sizelimit <limit>\" "
779 "line.\n", fname, lineno, 0 );
781 Debug( LDAP_DEBUG_ANY,
782 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
792 lim = &be->be_def_limit;
795 for ( i = 1; i < cargc; i++ ) {
796 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
797 rc = limits_parse_one( cargv[i], lim );
800 LDAP_LOG( CONFIG, CRIT,
801 "%s: line %d: unable "
802 "to parse value \"%s\" in \"sizelimit "
803 "<limit>\" line.\n", fname, lineno, cargv[i] );
805 Debug( LDAP_DEBUG_ANY,
806 "%s: line %d: unable "
807 "to parse value \"%s\" "
810 fname, lineno, cargv[i] );
816 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
817 lim->lms_s_soft = -1;
821 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
822 if ( next == cargv[i] ) {
824 LDAP_LOG( CONFIG, CRIT,
825 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
826 "line.\n", fname, lineno, cargv[i] );
828 Debug( LDAP_DEBUG_ANY,
829 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
830 fname, lineno, cargv[i] );
834 } else if ( next[0] != '\0' ) {
836 LDAP_LOG( CONFIG, CRIT,
837 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
838 "line ignored.\n", fname, lineno, next );
840 Debug( LDAP_DEBUG_ANY,
841 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
842 fname, lineno, next );
850 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
852 struct slap_limits_set *lim;
856 LDAP_LOG( CONFIG, CRIT,
857 "%s: line %d missing limit in \"timelimit <limit>\" "
858 "line.\n", fname, lineno, 0 );
860 Debug( LDAP_DEBUG_ANY,
861 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
871 lim = &be->be_def_limit;
874 for ( i = 1; i < cargc; i++ ) {
875 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
876 rc = limits_parse_one( cargv[i], lim );
879 LDAP_LOG( CONFIG, CRIT,
880 "%s: line %d: unable to parse value \"%s\" "
881 "in \"timelimit <limit>\" line.\n",
882 fname, lineno, cargv[i] );
884 Debug( LDAP_DEBUG_ANY,
885 "%s: line %d: unable "
886 "to parse value \"%s\" "
889 fname, lineno, cargv[i] );
895 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
896 lim->lms_t_soft = -1;
900 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
901 if ( next == cargv[i] ) {
903 LDAP_LOG( CONFIG, CRIT,
904 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
905 "line.\n", fname, lineno, cargv[i] );
907 Debug( LDAP_DEBUG_ANY,
908 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
909 fname, lineno, cargv[i] );
913 } else if ( next[0] != '\0' ) {
915 LDAP_LOG( CONFIG, CRIT,
916 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
917 "line ignored.\n", fname, lineno, next );
919 Debug( LDAP_DEBUG_ANY,
920 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
921 fname, lineno, next );
928 /* set regex-based limits */
929 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
932 LDAP_LOG( CONFIG, WARNING,
933 "%s: line %d \"limits\" allowed only in database "
934 "environment.\n", fname, lineno, 0 );
936 Debug( LDAP_DEBUG_ANY,
937 "%s: line %d \"limits\" allowed only in database environment.\n%s",
943 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
947 /* mark this as a subordinate database */
948 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
951 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
952 "subordinate keyword must appear inside a database "
953 "definition.\n", fname, lineno, 0 );
955 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
956 "must appear inside a database definition.\n",
962 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
966 /* add an overlay to this backend */
967 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
970 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
971 "overlay keyword must appear inside a database "
972 "definition.\n", fname, lineno, 0 );
974 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
975 "must appear inside a database definition.\n",
980 } else if ( overlay_config( be, cargv[1] )) {
984 /* set database suffix */
985 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
987 struct berval dn, pdn, ndn;
991 LDAP_LOG( CONFIG, CRIT,
992 "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
995 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
996 "missing dn in \"suffix <dn>\" line\n",
1002 } else if ( cargc > 2 ) {
1004 LDAP_LOG( CONFIG, INFO,
1005 "%s: line %d: extra cruft after <dn> in \"suffix %s\""
1006 " line (ignored).\n", fname, lineno, cargv[1] );
1008 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
1009 "after <dn> in \"suffix %s\" line (ignored)\n",
1010 fname, lineno, cargv[1] );
1016 LDAP_LOG( CONFIG, INFO,
1017 "%s: line %d: suffix line must appear inside a database "
1018 "definition.\n", fname, lineno, 0 );
1020 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
1021 "must appear inside a database definition\n",
1026 #if defined(SLAPD_MONITOR_DN)
1027 /* "cn=Monitor" is reserved for monitoring slap */
1028 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
1030 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
1031 "%s\" is reserved for monitoring slapd\n",
1032 fname, lineno, SLAPD_MONITOR_DN );
1034 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
1035 "%s\" is reserved for monitoring slapd\n",
1036 fname, lineno, SLAPD_MONITOR_DN );
1039 #endif /* SLAPD_MONITOR_DN */
1042 if ( load_ucdata( NULL ) < 0 ) return 1;
1044 dn.bv_val = cargv[1];
1045 dn.bv_len = strlen( cargv[1] );
1047 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1048 if( rc != LDAP_SUCCESS ) {
1050 LDAP_LOG( CONFIG, CRIT,
1051 "%s: line %d: suffix DN is invalid.\n",
1054 Debug( LDAP_DEBUG_ANY,
1055 "%s: line %d: suffix DN is invalid\n",
1061 tmp_be = select_backend( &ndn, 0, 0 );
1062 if ( tmp_be == be ) {
1064 LDAP_LOG( CONFIG, INFO,
1065 "%s: line %d: suffix already served by this backend "
1066 "(ignored)\n", fname, lineno, 0 );
1068 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1069 "already served by this backend (ignored)\n",
1075 } else if ( tmp_be != NULL ) {
1077 LDAP_LOG( CONFIG, INFO,
1078 "%s: line %d: suffix already served by a preceding "
1079 "backend \"%s\"\n", fname, lineno,
1080 tmp_be->be_suffix[0].bv_val );
1082 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1083 "already served by a preceeding backend \"%s\"\n",
1084 fname, lineno, tmp_be->be_suffix[0].bv_val );
1090 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1092 LDAP_LOG( CONFIG, INFO,
1093 "%s: line %d: suffix DN empty and default search "
1094 "base provided \"%s\" (assuming okay).\n",
1095 fname, lineno, default_search_base.bv_val );
1097 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1098 "suffix DN empty and default "
1099 "search base provided \"%s\" (assuming okay)\n",
1100 fname, lineno, default_search_base.bv_val );
1104 ber_bvarray_add( &be->be_suffix, &pdn );
1105 ber_bvarray_add( &be->be_nsuffix, &ndn );
1107 /* set max deref depth */
1108 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1112 LDAP_LOG( CONFIG, CRIT,
1113 "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1114 " line\n", fname, lineno, 0 );
1116 Debug( LDAP_DEBUG_ANY,
1117 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1125 LDAP_LOG( CONFIG, INFO,
1126 "%s: line %d: depth line must appear inside a database "
1127 "definition.\n", fname, lineno ,0 );
1129 Debug( LDAP_DEBUG_ANY,
1130 "%s: line %d: depth line must appear inside a database definition.\n",
1135 } else if ((i = atoi(cargv[1])) < 0) {
1137 LDAP_LOG( CONFIG, INFO,
1138 "%s: line %d: depth must be positive.\n",
1141 Debug( LDAP_DEBUG_ANY,
1142 "%s: line %d: depth must be positive.\n",
1149 be->be_max_deref_depth = i;
1153 /* set magic "root" dn for this database */
1154 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1157 LDAP_LOG( CONFIG, INFO,
1158 "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1161 Debug( LDAP_DEBUG_ANY,
1162 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1171 LDAP_LOG( CONFIG, INFO,
1172 "%s: line %d: rootdn line must appear inside a database "
1173 "definition.\n", fname, lineno ,0 );
1175 Debug( LDAP_DEBUG_ANY,
1176 "%s: line %d: rootdn line must appear inside a database definition.\n",
1184 if ( load_ucdata( NULL ) < 0 ) return 1;
1186 dn.bv_val = cargv[1];
1187 dn.bv_len = strlen( cargv[1] );
1189 rc = dnPrettyNormal( NULL, &dn,
1191 &be->be_rootndn, NULL );
1193 if( rc != LDAP_SUCCESS ) {
1195 LDAP_LOG( CONFIG, CRIT,
1196 "%s: line %d: rootdn DN is invalid.\n",
1199 Debug( LDAP_DEBUG_ANY,
1200 "%s: line %d: rootdn DN is invalid\n",
1207 /* set super-secret magic database password */
1208 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1211 LDAP_LOG( CONFIG, CRIT,
1212 "%s: line %d: missing passwd in \"rootpw <passwd>\""
1213 " line\n", fname, lineno ,0 );
1215 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1216 "missing passwd in \"rootpw <passwd>\" line\n",
1225 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1226 "rootpw line must appear inside a database "
1227 "definition.\n", fname, lineno ,0 );
1229 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1230 "rootpw line must appear inside a database "
1237 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1239 if( tmp_be != be ) {
1241 LDAP_LOG( CONFIG, INFO,
1243 "rootpw can only be set when rootdn is under suffix\n",
1244 fname, lineno, "" );
1246 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1247 "rootpw can only be set when rootdn is under suffix\n",
1253 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1254 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1257 /* make this database read-only */
1258 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1261 LDAP_LOG( CONFIG, CRIT,
1262 "%s: line %d: missing on|off in \"readonly <on|off>\" "
1263 "line.\n", fname, lineno ,0 );
1265 Debug( LDAP_DEBUG_ANY,
1266 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1273 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1274 global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1276 global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1279 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1280 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1282 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1287 /* allow these features */
1288 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1289 strcasecmp( cargv[0], "allow" ) == 0 )
1295 LDAP_LOG( CONFIG, INFO,
1296 "%s: line %d: allow line must appear prior to "
1297 "database definitions.\n", fname, lineno ,0 );
1299 Debug( LDAP_DEBUG_ANY,
1300 "%s: line %d: allow line must appear prior to database definitions\n",
1308 LDAP_LOG( CONFIG, CRIT,
1309 "%s: line %d: missing feature(s) in \"allow <features>\""
1310 " line\n", fname, lineno ,0 );
1312 Debug( LDAP_DEBUG_ANY,
1313 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1322 for( i=1; i < cargc; i++ ) {
1323 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1324 allows |= SLAP_ALLOW_BIND_V2;
1326 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1327 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1329 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1330 allows |= SLAP_ALLOW_BIND_ANON_DN;
1332 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1333 allows |= SLAP_ALLOW_UPDATE_ANON;
1335 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1337 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1338 "unknown feature %s in \"allow <features>\" line.\n",
1339 fname, lineno, cargv[1] );
1341 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1342 "unknown feature %s in \"allow <features>\" line\n",
1343 fname, lineno, cargv[i] );
1350 global_allows = allows;
1352 /* disallow these features */
1353 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1354 strcasecmp( cargv[0], "disallow" ) == 0 )
1356 slap_mask_t disallows;
1360 LDAP_LOG( CONFIG, INFO,
1361 "%s: line %d: disallow line must appear prior to "
1362 "database definitions.\n", fname, lineno ,0 );
1364 Debug( LDAP_DEBUG_ANY,
1365 "%s: line %d: disallow line must appear prior to database definitions\n",
1373 LDAP_LOG( CONFIG, CRIT,
1374 "%s: line %d: missing feature(s) in \"disallow <features>\""
1375 " line.\n", fname, lineno ,0 );
1377 Debug( LDAP_DEBUG_ANY,
1378 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1387 for( i=1; i < cargc; i++ ) {
1388 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1389 disallows |= SLAP_DISALLOW_BIND_ANON;
1391 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1392 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1394 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1395 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1397 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1398 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1400 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1401 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1403 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1405 LDAP_LOG( CONFIG, CRIT,
1406 "%s: line %d: unknown feature %s in "
1407 "\"disallow <features>\" line.\n",
1408 fname, lineno, cargv[i] );
1410 Debug( LDAP_DEBUG_ANY,
1411 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1412 fname, lineno, cargv[i] );
1419 global_disallows = disallows;
1421 /* require these features */
1422 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1423 strcasecmp( cargv[0], "require" ) == 0 )
1425 slap_mask_t requires;
1429 LDAP_LOG( CONFIG, CRIT,
1430 "%s: line %d: missing feature(s) in "
1431 "\"require <features>\" line.\n", fname, lineno ,0 );
1433 Debug( LDAP_DEBUG_ANY,
1434 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1443 for( i=1; i < cargc; i++ ) {
1444 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1445 requires |= SLAP_REQUIRE_BIND;
1447 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1448 requires |= SLAP_REQUIRE_LDAP_V3;
1450 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1451 requires |= SLAP_REQUIRE_AUTHC;
1453 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1454 requires |= SLAP_REQUIRE_SASL;
1456 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1457 requires |= SLAP_REQUIRE_STRONG;
1459 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1461 LDAP_LOG( CONFIG, CRIT,
1462 "%s: line %d: unknown feature %s in "
1463 "\"require <features>\" line.\n",
1464 fname, lineno , cargv[i] );
1466 Debug( LDAP_DEBUG_ANY,
1467 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1468 fname, lineno, cargv[i] );
1476 global_requires = requires;
1478 be->be_requires = requires;
1481 /* required security factors */
1482 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1483 slap_ssf_set_t *set;
1487 LDAP_LOG( CONFIG, CRIT,
1488 "%s: line %d: missing factor(s) in \"security <factors>\""
1489 " line.\n", fname, lineno ,0 );
1491 Debug( LDAP_DEBUG_ANY,
1492 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1500 set = &global_ssf_set;
1502 set = &be->be_ssf_set;
1505 for( i=1; i < cargc; i++ ) {
1506 if( strncasecmp( cargv[i], "ssf=",
1507 sizeof("ssf") ) == 0 )
1510 atoi( &cargv[i][sizeof("ssf")] );
1512 } else if( strncasecmp( cargv[i], "transport=",
1513 sizeof("transport") ) == 0 )
1515 set->sss_transport =
1516 atoi( &cargv[i][sizeof("transport")] );
1518 } else if( strncasecmp( cargv[i], "tls=",
1519 sizeof("tls") ) == 0 )
1522 atoi( &cargv[i][sizeof("tls")] );
1524 } else if( strncasecmp( cargv[i], "sasl=",
1525 sizeof("sasl") ) == 0 )
1528 atoi( &cargv[i][sizeof("sasl")] );
1530 } else if( strncasecmp( cargv[i], "update_ssf=",
1531 sizeof("update_ssf") ) == 0 )
1533 set->sss_update_ssf =
1534 atoi( &cargv[i][sizeof("update_ssf")] );
1536 } else if( strncasecmp( cargv[i], "update_transport=",
1537 sizeof("update_transport") ) == 0 )
1539 set->sss_update_transport =
1540 atoi( &cargv[i][sizeof("update_transport")] );
1542 } else if( strncasecmp( cargv[i], "update_tls=",
1543 sizeof("update_tls") ) == 0 )
1545 set->sss_update_tls =
1546 atoi( &cargv[i][sizeof("update_tls")] );
1548 } else if( strncasecmp( cargv[i], "update_sasl=",
1549 sizeof("update_sasl") ) == 0 )
1551 set->sss_update_sasl =
1552 atoi( &cargv[i][sizeof("update_sasl")] );
1554 } else if( strncasecmp( cargv[i], "simple_bind=",
1555 sizeof("simple_bind") ) == 0 )
1557 set->sss_simple_bind =
1558 atoi( &cargv[i][sizeof("simple_bind")] );
1562 LDAP_LOG( CONFIG, CRIT,
1563 "%s: line %d: unknown factor %S in "
1564 "\"security <factors>\" line.\n",
1565 fname, lineno, cargv[1] );
1567 Debug( LDAP_DEBUG_ANY,
1568 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1569 fname, lineno, cargv[i] );
1575 /* where to send clients when we don't hold it */
1576 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1579 LDAP_LOG( CONFIG, CRIT,
1580 "%s: line %d: missing URL in \"referral <URL>\""
1581 " line.\n", fname, lineno , 0 );
1583 Debug( LDAP_DEBUG_ANY,
1584 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1591 if( validate_global_referral( cargv[1] ) ) {
1593 LDAP_LOG( CONFIG, CRIT,
1594 "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1595 fname, lineno, cargv[1] );
1597 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1598 "invalid URL (%s) in \"referral\" line.\n",
1599 fname, lineno, cargv[1] );
1604 vals[0].bv_val = cargv[1];
1605 vals[0].bv_len = strlen( vals[0].bv_val );
1606 if( value_add( &default_referral, vals ) )
1610 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1614 LDAP_LOG( CONFIG, CRIT,
1615 "%s: line %d: Error in logfile directive, "
1616 "\"logfile <filename>\"\n", fname, lineno , 0 );
1618 Debug( LDAP_DEBUG_ANY,
1619 "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1625 logfile = fopen( cargv[1], "w" );
1626 if ( logfile != NULL ) lutil_debug_file( logfile );
1629 /* start of a new database definition */
1630 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1634 LDAP_LOG( CONFIG, CRIT,
1635 "%s: line %d: Error in debug directive, "
1636 "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1638 Debug( LDAP_DEBUG_ANY,
1639 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1645 level = atoi( cargv[2] );
1646 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1647 lutil_set_debug_level( cargv[1], level );
1648 /* specify an Object Identifier macro */
1649 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1650 rc = parse_oidm( fname, lineno, cargc, cargv );
1653 /* specify an objectclass */
1654 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1657 LDAP_LOG( CONFIG, INFO,
1658 "%s: line %d: illegal objectclass format.\n",
1659 fname, lineno , 0 );
1661 Debug( LDAP_DEBUG_ANY,
1662 "%s: line %d: illegal objectclass format.\n",
1667 } else if ( *cargv[1] == '(' /*')'*/) {
1669 p = strchr(saveline,'(' /*')'*/);
1670 rc = parse_oc( fname, lineno, p, cargv );
1675 LDAP_LOG( CONFIG, INFO,
1676 "%s: line %d: old objectclass format not supported\n",
1677 fname, lineno , 0 );
1679 Debug( LDAP_DEBUG_ANY,
1680 "%s: line %d: old objectclass format not supported.\n",
1685 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1687 p = strchr(saveline,'(' /*')'*/);
1688 rc = parse_cr( fname, lineno, p, cargv );
1691 /* specify an attribute type */
1692 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1693 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1697 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1698 "illegal attribute type format.\n",
1699 fname, lineno , 0 );
1701 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1702 "illegal attribute type format.\n",
1707 } else if ( *cargv[1] == '(' /*')'*/) {
1709 p = strchr(saveline,'(' /*')'*/);
1710 rc = parse_at( fname, lineno, p, cargv );
1715 LDAP_LOG( CONFIG, INFO,
1716 "%s: line %d: old attribute type format not supported.\n",
1717 fname, lineno , 0 );
1719 Debug( LDAP_DEBUG_ANY,
1720 "%s: line %d: old attribute type format not supported.\n",
1726 /* define attribute option(s) */
1727 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1728 ad_define_option( NULL, NULL, 0 );
1729 for ( i = 1; i < cargc; i++ )
1730 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1733 /* turn on/off schema checking */
1734 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1737 LDAP_LOG( CONFIG, CRIT,
1738 "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1739 " line.\n", fname, lineno , 0 );
1741 Debug( LDAP_DEBUG_ANY,
1742 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1748 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1750 LDAP_LOG( CONFIG, CRIT,
1751 "%s: line %d: schema checking disabled! your mileage may "
1752 "vary!\n", fname, lineno , 0 );
1754 Debug( LDAP_DEBUG_ANY,
1755 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1758 global_schemacheck = 0;
1760 global_schemacheck = 1;
1763 /* specify access control info */
1764 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1765 parse_acl( be, fname, lineno, cargc, cargv );
1767 /* debug level to log things to syslog */
1768 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1771 LDAP_LOG( CONFIG, CRIT,
1772 "%s: line %d: missing level in \"loglevel <level>\""
1773 " line.\n", fname, lineno , 0 );
1775 Debug( LDAP_DEBUG_ANY,
1776 "%s: line %d: missing level in \"loglevel <level>\" line\n",
1785 for( i=1; i < cargc; i++ ) {
1786 ldap_syslog += atoi( cargv[1] );
1789 /* list of sync replication information in this backend (slave only) */
1790 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1794 LDAP_LOG( CONFIG, INFO,
1795 "%s: line %d: syncrepl line must appear inside "
1796 "a database definition.\n", fname, lineno, 0);
1798 Debug( LDAP_DEBUG_ANY,
1799 "%s: line %d: syncrepl line must appear inside "
1800 "a database definition.\n", fname, lineno, 0);
1804 } else if ( SLAP_SHADOW( be )) {
1806 LDAP_LOG( CONFIG, INFO,
1807 "%s: line %d: syncrepl: database already shadowed.\n",
1810 Debug( LDAP_DEBUG_ANY,
1811 "%s: line %d: syncrepl: database already shadowed.\n",
1816 } else if ( add_syncrepl( be, cargv, cargc )) {
1820 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1822 /* list of replicas of the data in this backend (master only) */
1823 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1826 LDAP_LOG( CONFIG, CRIT,
1827 "%s: line %d: missing host or uri in \"replica "
1828 " <host[:port]\" line\n", fname, lineno , 0 );
1830 Debug( LDAP_DEBUG_ANY,
1831 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1839 LDAP_LOG( CONFIG, INFO,
1840 "%s: line %d: replica line must appear inside "
1841 "a database definition.\n", fname, lineno, 0);
1843 Debug( LDAP_DEBUG_ANY,
1844 "%s: line %d: replica line must appear inside a database definition\n",
1852 for ( i = 1; i < cargc; i++ ) {
1853 if ( strncasecmp( cargv[i], "host=", 5 )
1855 nr = add_replica_info( be,
1858 } else if (strncasecmp( cargv[i], "uri=", 4 )
1860 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1863 LDAP_LOG( CONFIG, INFO,
1864 "%s: line %d: replica line contains invalid "
1865 "uri definition.\n", fname, lineno, 0);
1867 Debug( LDAP_DEBUG_ANY,
1868 "%s: line %d: replica line contains invalid "
1869 "uri definition.\n", fname, lineno, 0);
1873 if (ludp->lud_host == NULL ) {
1875 LDAP_LOG( CONFIG, INFO,
1876 "%s: line %d: replica line contains invalid "
1877 "uri definition - missing hostname.\n",
1880 Debug( LDAP_DEBUG_ANY,
1881 "%s: line %d: replica line contains invalid "
1882 "uri definition - missing hostname.\n", fname, lineno, 0);
1886 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1887 if ( replicahost == NULL ) {
1889 LDAP_LOG( CONFIG, ERR,
1890 "out of memory in read_config\n", 0, 0,0 );
1892 Debug( LDAP_DEBUG_ANY,
1893 "out of memory in read_config\n", 0, 0, 0 );
1895 ldap_free_urldesc( ludp );
1896 exit( EXIT_FAILURE );
1898 sprintf(replicahost, "%s:%d",
1899 ludp->lud_host, ludp->lud_port);
1900 nr = add_replica_info( be, replicahost );
1901 ldap_free_urldesc( ludp );
1902 ch_free(replicahost);
1908 LDAP_LOG( CONFIG, INFO,
1909 "%s: line %d: missing host or uri in \"replica\" line\n",
1910 fname, lineno , 0 );
1912 Debug( LDAP_DEBUG_ANY,
1913 "%s: line %d: missing host or uri in \"replica\" line\n",
1918 } else if ( nr == -1 ) {
1920 LDAP_LOG( CONFIG, INFO,
1921 "%s: line %d: unable to add"
1922 " replica \"%s\"\n",
1926 Debug( LDAP_DEBUG_ANY,
1927 "%s: line %d: unable to add replica \"%s\"\n",
1928 fname, lineno, cargv[i] + 5 );
1932 for ( i = 1; i < cargc; i++ ) {
1933 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1935 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1938 LDAP_LOG( CONFIG, INFO,
1939 "%s: line %d: suffix \"%s\" in \"replica\""
1940 " line is not valid for backend(ignored)\n",
1941 fname, lineno, cargv[i] + 7 );
1943 Debug( LDAP_DEBUG_ANY,
1944 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1945 fname, lineno, cargv[i] + 7 );
1951 LDAP_LOG( CONFIG, INFO,
1952 "%s: line %d: unable to normalize suffix"
1953 " in \"replica\" line (ignored)\n",
1954 fname, lineno , 0 );
1956 Debug( LDAP_DEBUG_ANY,
1957 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1963 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1965 char *arg = cargv[i] + 4;
1967 if ( arg[0] == '!' ) {
1972 if ( arg[0] != '=' ) {
1976 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1978 LDAP_LOG( CONFIG, INFO,
1979 "%s: line %d: attribute \"%s\" in "
1980 "\"replica\" line is unknown\n",
1981 fname, lineno, arg + 1 );
1983 Debug( LDAP_DEBUG_ANY,
1984 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1985 fname, lineno, arg + 1 );
1994 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1997 /* dn of slave entity allowed to write to replica */
1998 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2001 LDAP_LOG( CONFIG, CRIT,
2002 "%s: line %d: missing dn in \"updatedn <dn>\""
2003 " line.\n", fname, lineno , 0 );
2005 Debug( LDAP_DEBUG_ANY,
2006 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2014 LDAP_LOG( CONFIG, INFO,
2015 "%s: line %d: updatedn line must appear inside "
2016 "a database definition\n",
2017 fname, lineno , 0 );
2019 Debug( LDAP_DEBUG_ANY,
2020 "%s: line %d: updatedn line must appear inside a database definition\n",
2025 } else if ( SLAP_SHADOW(be) ) {
2027 LDAP_LOG( CONFIG, INFO,
2028 "%s: line %d: updatedn: database already shadowed.\n",
2031 Debug( LDAP_DEBUG_ANY,
2032 "%s: line %d: updatedn: database already shadowed.\n",
2040 if ( load_ucdata( NULL ) < 0 ) return 1;
2042 dn.bv_val = cargv[1];
2043 dn.bv_len = strlen( cargv[1] );
2045 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2046 if( rc != LDAP_SUCCESS ) {
2048 LDAP_LOG( CONFIG, CRIT,
2049 "%s: line %d: updatedn DN is invalid.\n",
2050 fname, lineno , 0 );
2052 Debug( LDAP_DEBUG_ANY,
2053 "%s: line %d: updatedn DN is invalid\n",
2060 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2062 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2065 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2066 "missing url in \"updateref <ldapurl>\" line.\n",
2067 fname, lineno , 0 );
2069 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2070 "missing url in \"updateref <ldapurl>\" line\n",
2078 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2079 " line must appear inside a database definition\n",
2080 fname, lineno , 0 );
2082 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2083 " line must appear inside a database definition\n",
2088 } else if ( !SLAP_SHADOW(be) ) {
2090 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2091 "updateref line must come after syncrepl or updatedn.\n",
2092 fname, lineno , 0 );
2094 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2095 "updateref line must after syncrepl or updatedn.\n",
2101 if( validate_global_referral( cargv[1] ) ) {
2103 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2104 "invalid URL (%s) in \"updateref\" line.\n",
2105 fname, lineno, cargv[1] );
2107 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2108 "invalid URL (%s) in \"updateref\" line.\n",
2109 fname, lineno, cargv[1] );
2114 vals[0].bv_val = cargv[1];
2115 vals[0].bv_len = strlen( vals[0].bv_val );
2116 if( value_add( &be->be_update_refs, vals ) ) {
2120 /* replication log file to which changes are appended */
2121 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2124 LDAP_LOG( CONFIG, CRIT,
2125 "%s: line %d: missing filename in \"replogfile <filename>\""
2126 " line.\n", fname, lineno , 0 );
2128 Debug( LDAP_DEBUG_ANY,
2129 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2136 be->be_replogfile = ch_strdup( cargv[1] );
2138 replogfile = ch_strdup( cargv[1] );
2141 /* file from which to read additional rootdse attrs */
2142 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2145 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2146 "missing filename in \"rootDSE <filename>\" line.\n",
2147 fname, lineno , 0 );
2149 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2150 "missing filename in \"rootDSE <filename>\" line.\n",
2156 if( read_root_dse_file( cargv[1] ) ) {
2158 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2159 "could not read \"rootDSE <filename>\" line.\n",
2160 fname, lineno , 0 );
2162 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2163 "could not read \"rootDSE <filename>\" line\n",
2169 /* maintain lastmodified{by,time} attributes */
2170 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2173 LDAP_LOG( CONFIG, CRIT,
2174 "%s: line %d: missing on|off in \"lastmod <on|off>\""
2175 " line.\n", fname, lineno , 0 );
2177 Debug( LDAP_DEBUG_ANY,
2178 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2184 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2186 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2192 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2199 /* turn on/off gentle SIGHUP handling */
2200 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2202 Debug( LDAP_DEBUG_ANY,
2203 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2207 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2208 global_gentlehup = 0;
2210 global_gentlehup = 1;
2214 /* set idle timeout value */
2215 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2219 LDAP_LOG( CONFIG, CRIT,
2220 "%s: line %d: missing timeout value in "
2221 "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2223 Debug( LDAP_DEBUG_ANY,
2224 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2231 i = atoi( cargv[1] );
2235 LDAP_LOG( CONFIG, CRIT,
2236 "%s: line %d: timeout value (%d) invalid "
2237 "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2239 Debug( LDAP_DEBUG_ANY,
2240 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2247 global_idletimeout = i;
2249 /* include another config file */
2250 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2253 LDAP_LOG( CONFIG, CRIT,
2254 "%s: line %d: missing filename in \"include "
2255 "<filename>\" line.\n", fname, lineno , 0 );
2257 Debug( LDAP_DEBUG_ANY,
2258 "%s: line %d: missing filename in \"include <filename>\" line\n",
2264 savefname = ch_strdup( cargv[1] );
2265 savelineno = lineno;
2267 if ( read_config( savefname, depth+1 ) != 0 ) {
2272 lineno = savelineno - 1;
2274 /* location of kerberos srvtab file */
2275 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2278 LDAP_LOG( CONFIG, CRIT,
2279 "%s: line %d: missing filename in \"srvtab "
2280 "<filename>\" line.\n", fname, lineno , 0 );
2282 Debug( LDAP_DEBUG_ANY,
2283 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2289 ldap_srvtab = ch_strdup( cargv[1] );
2291 #ifdef SLAPD_MODULES
2292 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2295 LDAP_LOG( CONFIG, INFO,
2296 "%s: line %d: missing filename in \"moduleload "
2297 "<filename>\" line.\n", fname, lineno , 0 );
2299 Debug( LDAP_DEBUG_ANY,
2300 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2304 exit( EXIT_FAILURE );
2306 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2308 LDAP_LOG( CONFIG, CRIT,
2309 "%s: line %d: failed to load or initialize module %s\n",
2310 fname, lineno, cargv[1] );
2312 Debug( LDAP_DEBUG_ANY,
2313 "%s: line %d: failed to load or initialize module %s\n",
2314 fname, lineno, cargv[1]);
2317 exit( EXIT_FAILURE );
2319 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2322 LDAP_LOG( CONFIG, INFO,
2323 "%s: line %d: missing path in \"modulepath <path>\""
2324 " line\n", fname, lineno , 0 );
2326 Debug( LDAP_DEBUG_ANY,
2327 "%s: line %d: missing path in \"modulepath <path>\" line\n",
2331 exit( EXIT_FAILURE );
2333 if (module_path( cargv[1] )) {
2335 LDAP_LOG( CONFIG, CRIT,
2336 "%s: line %d: failed to set module search path to %s.\n",
2337 fname, lineno, cargv[1] );
2339 Debug( LDAP_DEBUG_ANY,
2340 "%s: line %d: failed to set module search path to %s\n",
2341 fname, lineno, cargv[1]);
2344 exit( EXIT_FAILURE );
2347 #endif /*SLAPD_MODULES*/
2350 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2351 rc = ldap_pvt_tls_set_option( NULL,
2352 LDAP_OPT_X_TLS_RANDOM_FILE,
2357 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2358 rc = ldap_pvt_tls_set_option( NULL,
2359 LDAP_OPT_X_TLS_CIPHER_SUITE,
2364 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2365 rc = ldap_pvt_tls_set_option( NULL,
2366 LDAP_OPT_X_TLS_CERTFILE,
2371 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2372 rc = ldap_pvt_tls_set_option( NULL,
2373 LDAP_OPT_X_TLS_KEYFILE,
2378 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2379 rc = ldap_pvt_tls_set_option( NULL,
2380 LDAP_OPT_X_TLS_CACERTDIR,
2385 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2386 rc = ldap_pvt_tls_set_option( NULL,
2387 LDAP_OPT_X_TLS_CACERTFILE,
2391 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2392 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2394 rc = ldap_pvt_tls_set_option( NULL,
2395 LDAP_OPT_X_TLS_REQUIRE_CERT,
2398 rc = ldap_int_tls_config( NULL,
2399 LDAP_OPT_X_TLS_REQUIRE_CERT,
2408 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2409 #ifdef SLAPD_RLOOKUPS
2412 LDAP_LOG( CONFIG, INFO,
2413 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2414 fname, lineno , 0 );
2416 Debug( LDAP_DEBUG_ANY,
2417 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2423 if ( !strcasecmp( cargv[1], "on" ) ) {
2424 use_reverse_lookup = 1;
2425 } else if ( !strcasecmp( cargv[1], "off" ) ) {
2426 use_reverse_lookup = 0;
2429 LDAP_LOG( CONFIG, INFO,
2430 "%s: line %d: reverse-lookup: "
2431 "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2433 Debug( LDAP_DEBUG_ANY,
2434 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2440 #else /* !SLAPD_RLOOKUPS */
2442 LDAP_LOG( CONFIG, INFO,
2443 "%s: line %d: reverse lookups "
2444 "are not configured (ignored).\n", fname, lineno , 0 );
2446 Debug( LDAP_DEBUG_ANY,
2447 "%s: line %d: reverse lookups are not configured (ignored).\n",
2450 #endif /* !SLAPD_RLOOKUPS */
2452 /* Netscape plugins */
2453 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2454 #if defined( LDAP_SLAPI )
2456 #ifdef notdef /* allow global plugins, too */
2458 * a "plugin" line must be inside a database
2459 * definition, since we implement pre-,post-
2460 * and extended operation plugins
2464 LDAP_LOG( CONFIG, INFO,
2465 "%s: line %d: plugin line must appear "
2466 "insid a database definition.\n",
2469 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2470 "line must appear inside a database "
2471 "definition\n", fname, lineno, 0 );
2477 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
2481 slapi_plugins_used++;
2483 #else /* !defined( LDAP_SLAPI ) */
2485 LDAP_LOG( CONFIG, INFO,
2486 "%s: line %d: SLAPI not supported.\n",
2489 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2490 "not supported.\n", fname, lineno, 0 );
2494 #endif /* !defined( LDAP_SLAPI ) */
2496 /* Netscape plugins */
2497 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2498 #if defined( LDAP_SLAPI )
2501 LDAP_LOG( CONFIG, INFO,
2502 "%s: line %d: missing file name "
2503 "in pluginlog <filename> line.\n",
2506 Debug( LDAP_DEBUG_ANY,
2507 "%s: line %d: missing file name "
2508 "in pluginlog <filename> line.\n",
2514 if ( slapi_log_file != NULL ) {
2515 ch_free( slapi_log_file );
2518 slapi_log_file = ch_strdup( cargv[1] );
2519 #endif /* !defined( LDAP_SLAPI ) */
2521 /* pass anything else to the current backend info/db config routine */
2524 if ( bi->bi_config ) {
2525 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2531 case SLAP_CONF_UNKNOWN:
2533 LDAP_LOG( CONFIG, INFO,
2534 "%s: line %d: unknown directive \"%s\" inside "
2535 "backend info definition (ignored).\n",
2536 fname, lineno, cargv[0] );
2538 Debug( LDAP_DEBUG_ANY,
2539 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2540 fname, lineno, cargv[0] );
2549 } else if ( be != NULL ) {
2550 if ( be->be_config ) {
2551 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2557 case SLAP_CONF_UNKNOWN:
2559 LDAP_LOG( CONFIG, INFO,
2560 "%s: line %d: unknown directive \"%s\" inside "
2561 "backend database definition (ignored).\n",
2562 fname, lineno, cargv[0] );
2564 Debug( LDAP_DEBUG_ANY,
2565 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2566 fname, lineno, cargv[0] );
2577 LDAP_LOG( CONFIG, INFO,
2578 "%s: line %d: unknown directive \"%s\" outside backend "
2579 "info and database definitions (ignored).\n",
2580 fname, lineno, cargv[0] );
2582 Debug( LDAP_DEBUG_ANY,
2583 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2584 fname, lineno, cargv[0] );
2593 if ( depth == 0 ) ch_free( cargv );
2595 if ( !global_schemadn.bv_val ) {
2596 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2598 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2601 if ( load_ucdata( NULL ) < 0 ) return 1;
2613 char logbuf[sizeof("pseudorootpw ***")];
2616 token = strtok_quote( line, " \t" );
2620 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2621 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2622 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2623 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2624 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2626 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2629 if ( strtok_quote_ptr ) {
2630 *strtok_quote_ptr = ' ';
2634 LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2636 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2639 if ( strtok_quote_ptr ) {
2640 *strtok_quote_ptr = '\0';
2643 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2644 if ( cargc == cargv_size - 1 ) {
2646 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2648 if ( tmp == NULL ) {
2650 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2652 Debug( LDAP_DEBUG_ANY,
2653 "line %d: out of memory\n",
2659 cargv_size += ARGS_STEP;
2661 cargv[cargc++] = token;
2663 cargv[cargc] = NULL;
2668 strtok_quote( char *line, char *sep )
2674 strtok_quote_ptr = NULL;
2675 if ( line != NULL ) {
2678 while ( *next && strchr( sep, *next ) ) {
2682 if ( *next == '\0' ) {
2688 for ( inquote = 0; *next; ) {
2696 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2702 next + 1, strlen( next + 1 ) + 1 );
2703 next++; /* dont parse the escaped character */
2708 if ( strchr( sep, *next ) != NULL ) {
2709 strtok_quote_ptr = next;
2722 static char buf[BUFSIZ];
2724 static size_t lmax, lcur;
2726 #define CATLINE( buf ) \
2728 size_t len = strlen( buf ); \
2729 while ( lcur + len + 1 > lmax ) { \
2731 line = (char *) ch_realloc( line, lmax ); \
2733 strcpy( line + lcur, buf ); \
2738 fp_getline( FILE *fp, int *lineno )
2746 /* hack attack - keeps us from having to keep a stack of bufs... */
2747 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2752 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2753 /* trim off \r\n or \n */
2754 if ( (p = strchr( buf, '\n' )) != NULL ) {
2755 if( p > buf && p[-1] == '\r' ) --p;
2759 /* trim off trailing \ and append the next line */
2760 if ( line[ 0 ] != '\0'
2761 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2762 && p[ -1 ] != '\\' ) {
2767 if ( ! isspace( (unsigned char) buf[0] ) ) {
2771 /* change leading whitespace to a space */
2780 return( line[0] ? line : NULL );
2784 fp_getline_init( int *lineno )
2790 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2792 load_ucdata( char *path )
2794 static int loaded = 0;
2800 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2803 LDAP_LOG( CONFIG, CRIT,
2804 "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2806 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2819 ucdata_unload( UCDATA_ALL );
2820 free( global_schemandn.bv_val );
2821 free( global_schemadn.bv_val );
2823 if ( slapd_args_file )
2824 free ( slapd_args_file );
2825 if ( slapd_pid_file )
2826 free ( slapd_pid_file );
2827 if ( default_passwd_hash )
2828 ldap_charray_free( default_passwd_hash );
2829 acl_destroy( global_acl, NULL );
2840 syncinfo_t *si_entry;
2842 int duplicated_replica_id = 0;
2844 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2848 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2850 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2855 si->si_tls = SYNCINFO_TLS_OFF;
2856 if ( be->be_rootndn.bv_val ) {
2857 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2859 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2860 si->si_schemachecking = 0;
2861 ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
2862 &si->si_filterstr );
2863 si->si_base.bv_val = NULL;
2864 si->si_scope = LDAP_SCOPE_SUBTREE;
2865 si->si_attrsonly = 0;
2866 si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2867 si->si_attrs[0] = NULL;
2868 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2869 si->si_interval = 86400;
2870 si->si_syncCookie.ctxcsn = NULL;
2871 si->si_syncCookie.octet_str = NULL;
2872 si->si_syncCookie.sid = -1;
2873 si->si_manageDSAit = 0;
2876 si->si_syncUUID_ndn.bv_val = NULL;
2877 si->si_syncUUID_ndn.bv_len = 0;
2879 si->si_presentlist = NULL;
2880 LDAP_LIST_INIT( &si->si_nonpresentlist );
2882 rc = parse_syncrepl_line( cargv, cargc, si );
2884 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2885 if ( si->si_rid == si_entry->si_rid ) {
2887 LDAP_LOG( CONFIG, ERR,
2888 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
2890 Debug( LDAP_DEBUG_ANY,
2891 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2893 duplicated_replica_id = 1;
2898 if ( rc < 0 || duplicated_replica_id ) {
2899 syncinfo_t *si_entry;
2900 /* Something bad happened - back out */
2902 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2904 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2907 /* If error, remove all syncinfo */
2908 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2909 if ( si_entry->si_updatedn.bv_val ) {
2910 ch_free( si->si_updatedn.bv_val );
2912 if ( si_entry->si_filterstr.bv_val ) {
2913 ch_free( si->si_filterstr.bv_val );
2915 if ( si_entry->si_attrs ) {
2917 while ( si_entry->si_attrs[i] != NULL ) {
2918 ch_free( si_entry->si_attrs[i] );
2921 ch_free( si_entry->si_attrs );
2925 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2926 si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
2927 LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
2928 ch_free( si_entry );
2930 LDAP_STAILQ_INIT( &be->be_syncinfo );
2934 LDAP_LOG ( CONFIG, RESULTS,
2935 "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2936 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2938 Debug( LDAP_DEBUG_CONFIG,
2939 "Config: ** successfully added syncrepl \"%s\"\n",
2940 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2942 if ( !si->si_schemachecking ) {
2943 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2946 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2952 #define PROVIDERSTR "provider"
2953 #define SUFFIXSTR "suffix"
2954 #define UPDATEDNSTR "updatedn"
2955 #define BINDMETHSTR "bindmethod"
2956 #define SIMPLESTR "simple"
2957 #define SASLSTR "sasl"
2958 #define BINDDNSTR "binddn"
2959 #define CREDSTR "credentials"
2960 #define OLDAUTHCSTR "bindprincipal"
2961 #define AUTHCSTR "authcID"
2962 #define AUTHZSTR "authzID"
2963 #define SRVTABSTR "srvtab"
2964 #define SASLMECHSTR "saslmech"
2965 #define REALMSTR "realm"
2966 #define SECPROPSSTR "secprops"
2967 #define STARTTLSSTR "starttls"
2968 #define CRITICALSTR "critical"
2970 #define SCHEMASTR "schemachecking"
2971 #define FILTERSTR "filter"
2972 #define SEARCHBASESTR "searchbase"
2973 #define SCOPESTR "scope"
2974 #define ATTRSSTR "attrs"
2975 #define ATTRSONLYSTR "attrsonly"
2976 #define TYPESTR "type"
2977 #define INTERVALSTR "interval"
2978 #define LASTMODSTR "lastmod"
2979 #define LMREQSTR "req"
2980 #define LMGENSTR "gen"
2981 #define LMNOSTR "no"
2982 #define MANAGEDSAITSTR "manageDSAit"
2983 #define SLIMITSTR "sizelimit"
2984 #define TLIMITSTR "timelimit"
2986 #define GOT_ID 0x0001
2987 #define GOT_PROVIDER 0x0002
2988 #define GOT_METHOD 0x0004
2989 #define GOT_ALL 0x0007
2992 parse_syncrepl_line(
3003 for ( i = 1; i < cargc; i++ ) {
3004 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3006 /* '\0' string terminator accounts for '=' */
3007 val = cargv[ i ] + sizeof( IDSTR );
3009 if ( tmp >= 1000 || tmp < 0 ) {
3010 fprintf( stderr, "Error: parse_syncrepl_line: "
3011 "syncrepl id %d is out of range [0..999]\n", tmp );
3016 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3017 sizeof( PROVIDERSTR ) - 1 )) {
3018 val = cargv[ i ] + sizeof( PROVIDERSTR );
3019 si->si_provideruri = ch_strdup( val );
3020 si->si_provideruri_bv = (BerVarray)
3021 ch_calloc( 2, sizeof( struct berval ));
3022 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3023 0, &si->si_provideruri_bv[0] );
3024 si->si_provideruri_bv[1].bv_len = 0;
3025 si->si_provideruri_bv[1].bv_val = NULL;
3026 gots |= GOT_PROVIDER;
3027 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3028 sizeof(STARTTLSSTR) - 1 ) )
3030 val = cargv[ i ] + sizeof( STARTTLSSTR );
3031 if( !strcasecmp( val, CRITICALSTR ) ) {
3032 si->si_tls = SYNCINFO_TLS_CRITICAL;
3034 si->si_tls = SYNCINFO_TLS_ON;
3036 } else if ( !strncasecmp( cargv[ i ],
3037 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3039 struct berval updatedn = {0, NULL};
3040 val = cargv[ i ] + sizeof( UPDATEDNSTR );
3041 ber_str2bv( val, 0, 0, &updatedn );
3042 ch_free( si->si_updatedn.bv_val );
3043 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3044 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3045 sizeof( BINDMETHSTR ) - 1 ) )
3047 val = cargv[ i ] + sizeof( BINDMETHSTR );
3048 if ( !strcasecmp( val, SIMPLESTR )) {
3049 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3051 } else if ( !strcasecmp( val, SASLSTR )) {
3052 #ifdef HAVE_CYRUS_SASL
3053 si->si_bindmethod = LDAP_AUTH_SASL;
3055 #else /* HAVE_CYRUS_SASL */
3056 fprintf( stderr, "Error: parse_syncrepl_line: "
3057 "not compiled with SASL support\n" );
3059 #endif /* HAVE_CYRUS_SASL */
3061 si->si_bindmethod = -1;
3063 } else if ( !strncasecmp( cargv[ i ],
3064 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3065 val = cargv[ i ] + sizeof( BINDDNSTR );
3066 si->si_binddn = ch_strdup( val );
3067 } else if ( !strncasecmp( cargv[ i ],
3068 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3069 val = cargv[ i ] + sizeof( CREDSTR );
3070 si->si_passwd = ch_strdup( val );
3071 } else if ( !strncasecmp( cargv[ i ],
3072 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3073 val = cargv[ i ] + sizeof( SASLMECHSTR );
3074 si->si_saslmech = ch_strdup( val );
3075 } else if ( !strncasecmp( cargv[ i ],
3076 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3077 val = cargv[ i ] + sizeof( SECPROPSSTR );
3078 si->si_secprops = ch_strdup( val );
3079 } else if ( !strncasecmp( cargv[ i ],
3080 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3081 val = cargv[ i ] + sizeof( REALMSTR );
3082 si->si_realm = ch_strdup( val );
3083 } else if ( !strncasecmp( cargv[ i ],
3084 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3085 val = cargv[ i ] + sizeof( AUTHCSTR );
3086 si->si_authcId = ch_strdup( val );
3087 } else if ( !strncasecmp( cargv[ i ],
3088 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3089 /* Old authcID is provided for some backwards compatibility */
3090 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3091 si->si_authcId = ch_strdup( val );
3092 } else if ( !strncasecmp( cargv[ i ],
3093 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3094 val = cargv[ i ] + sizeof( AUTHZSTR );
3095 si->si_authzId = ch_strdup( val );
3096 } else if ( !strncasecmp( cargv[ i ],
3097 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3099 val = cargv[ i ] + sizeof( SCHEMASTR );
3100 if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
3101 si->si_schemachecking = 1;
3102 } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
3103 si->si_schemachecking = 0;
3105 si->si_schemachecking = 1;
3107 } else if ( !strncasecmp( cargv[ i ],
3108 FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3110 val = cargv[ i ] + sizeof( FILTERSTR );
3111 ber_str2bv( val, 0, 1, &si->si_filterstr );
3112 } else if ( !strncasecmp( cargv[ i ],
3113 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3116 val = cargv[ i ] + sizeof( SEARCHBASESTR );
3117 if ( si->si_base.bv_val ) {
3118 ch_free( si->si_base.bv_val );
3120 ber_str2bv( val, 0, 0, &bv );
3121 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3122 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3125 } else if ( !strncasecmp( cargv[ i ],
3126 SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3128 val = cargv[ i ] + sizeof( SCOPESTR );
3129 if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3130 si->si_scope = LDAP_SCOPE_BASE;
3131 } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3132 si->si_scope = LDAP_SCOPE_ONELEVEL;
3133 #ifdef LDAP_SCOPE_SUBORDINATE
3134 } else if ( !strcasecmp( val, "subordinate" ) ||
3135 !strcasecmp( val, "children" ))
3137 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3139 } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3140 si->si_scope = LDAP_SCOPE_SUBTREE;
3142 fprintf( stderr, "Error: parse_syncrepl_line: "
3143 "unknown scope \"%s\"\n", val);
3146 } else if ( !strncasecmp( cargv[ i ],
3147 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3149 si->si_attrsonly = 1;
3150 } else if ( !strncasecmp( cargv[ i ],
3151 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3153 val = cargv[ i ] + sizeof( ATTRSSTR );
3154 str2clist( &si->si_attrs, val, "," );
3155 } else if ( !strncasecmp( cargv[ i ],
3156 TYPESTR, sizeof( TYPESTR ) - 1 ) )
3158 val = cargv[ i ] + sizeof( TYPESTR );
3159 if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3160 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3161 } else if ( !strncasecmp( val, "refreshAndPersist",
3162 sizeof("refreshAndPersist")-1 ))
3164 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3165 si->si_interval = 60;
3167 fprintf( stderr, "Error: parse_syncrepl_line: "
3168 "unknown sync type \"%s\"\n", val);
3171 } else if ( !strncasecmp( cargv[ i ],
3172 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3174 val = cargv[ i ] + sizeof( INTERVALSTR );
3175 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3176 si->si_interval = 0;
3184 hstr = strchr( dstr, ':' );
3185 if ( hstr == NULL ) {
3186 fprintf( stderr, "Error: parse_syncrepl_line: "
3187 "invalid interval \"%s\"\n", val );
3191 mstr = strchr( hstr, ':' );
3192 if ( mstr == NULL ) {
3193 fprintf( stderr, "Error: parse_syncrepl_line: "
3194 "invalid interval \"%s\"\n", val );
3198 sstr = strchr( mstr, ':' );
3199 if ( sstr == NULL ) {
3200 fprintf( stderr, "Error: parse_syncrepl_line: "
3201 "invalid interval \"%s\"\n", val );
3210 if (( hh > 24 ) || ( hh < 0 ) ||
3211 ( mm > 60 ) || ( mm < 0 ) ||
3212 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3213 fprintf( stderr, "Error: parse_syncrepl_line: "
3214 "invalid interval \"%s\"\n", val );
3217 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3219 if ( si->si_interval < 0 ) {
3220 fprintf( stderr, "Error: parse_syncrepl_line: "
3221 "invalid interval \"%ld\"\n",
3222 (long) si->si_interval);
3225 } else if ( !strncasecmp( cargv[ i ],
3226 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3228 val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3229 si->si_manageDSAit = atoi( val );
3230 } else if ( !strncasecmp( cargv[ i ],
3231 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3233 val = cargv[ i ] + sizeof( SLIMITSTR );
3234 si->si_slimit = atoi( val );
3235 } else if ( !strncasecmp( cargv[ i ],
3236 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3238 val = cargv[ i ] + sizeof( TLIMITSTR );
3239 si->si_tlimit = atoi( val );
3241 fprintf( stderr, "Error: parse_syncrepl_line: "
3242 "unknown keyword \"%s\"\n", cargv[ i ] );
3246 if ( gots != GOT_ALL ) {
3248 "Error: Malformed \"syncrepl\" line in slapd config file" );
3256 str2clist( char ***out, char *in, const char *brkstr )
3265 /* find last element in list */
3266 for (i = 0; *out && *out[i]; i++);
3268 /* protect the input string from strtok */
3269 str = ch_strdup( in );
3271 if ( *str == '\0' ) {
3276 /* Count words in string */
3278 for ( s = str; *s; s++ ) {
3279 if ( strchr( brkstr, *s ) != NULL ) {
3284 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3286 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3288 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3290 *new = ch_strdup( s );