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 );
851 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
853 struct slap_limits_set *lim;
857 LDAP_LOG( CONFIG, CRIT,
858 "%s: line %d missing limit in \"timelimit <limit>\" "
859 "line.\n", fname, lineno, 0 );
861 Debug( LDAP_DEBUG_ANY,
862 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
872 lim = &be->be_def_limit;
875 for ( i = 1; i < cargc; i++ ) {
876 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
877 rc = limits_parse_one( cargv[i], lim );
880 LDAP_LOG( CONFIG, CRIT,
881 "%s: line %d: unable to parse value \"%s\" "
882 "in \"timelimit <limit>\" line.\n",
883 fname, lineno, cargv[i] );
885 Debug( LDAP_DEBUG_ANY,
886 "%s: line %d: unable "
887 "to parse value \"%s\" "
890 fname, lineno, cargv[i] );
896 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
897 lim->lms_t_soft = -1;
901 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
902 if ( next == cargv[i] ) {
904 LDAP_LOG( CONFIG, CRIT,
905 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
906 "line.\n", fname, lineno, cargv[i] );
908 Debug( LDAP_DEBUG_ANY,
909 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
910 fname, lineno, cargv[i] );
914 } else if ( next[0] != '\0' ) {
916 LDAP_LOG( CONFIG, CRIT,
917 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
918 "line ignored.\n", fname, lineno, next );
920 Debug( LDAP_DEBUG_ANY,
921 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
922 fname, lineno, next );
930 /* set regex-based limits */
931 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
934 LDAP_LOG( CONFIG, WARNING,
935 "%s: line %d \"limits\" allowed only in database "
936 "environment.\n", fname, lineno, 0 );
938 Debug( LDAP_DEBUG_ANY,
939 "%s: line %d \"limits\" allowed only in database environment.\n%s",
945 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
949 /* mark this as a subordinate database */
950 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
953 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
954 "subordinate keyword must appear inside a database "
955 "definition.\n", fname, lineno, 0 );
957 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
958 "must appear inside a database definition.\n",
964 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
968 /* add an overlay to this backend */
969 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
972 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
973 "overlay keyword must appear inside a database "
974 "definition.\n", fname, lineno, 0 );
976 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
977 "must appear inside a database definition.\n",
982 } else if ( overlay_config( be, cargv[1] )) {
986 /* set database suffix */
987 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
989 struct berval dn, pdn, ndn;
993 LDAP_LOG( CONFIG, CRIT,
994 "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
997 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
998 "missing dn in \"suffix <dn>\" line\n",
1004 } else if ( cargc > 2 ) {
1006 LDAP_LOG( CONFIG, INFO,
1007 "%s: line %d: extra cruft after <dn> in \"suffix %s\""
1008 " line (ignored).\n", fname, lineno, cargv[1] );
1010 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
1011 "after <dn> in \"suffix %s\" line (ignored)\n",
1012 fname, lineno, cargv[1] );
1018 LDAP_LOG( CONFIG, INFO,
1019 "%s: line %d: suffix line must appear inside a database "
1020 "definition.\n", fname, lineno, 0 );
1022 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
1023 "must appear inside a database definition\n",
1028 #if defined(SLAPD_MONITOR_DN)
1029 /* "cn=Monitor" is reserved for monitoring slap */
1030 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
1032 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
1033 "%s\" is reserved for monitoring slapd\n",
1034 fname, lineno, SLAPD_MONITOR_DN );
1036 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
1037 "%s\" is reserved for monitoring slapd\n",
1038 fname, lineno, SLAPD_MONITOR_DN );
1041 #endif /* SLAPD_MONITOR_DN */
1044 if ( load_ucdata( NULL ) < 0 ) return 1;
1046 dn.bv_val = cargv[1];
1047 dn.bv_len = strlen( cargv[1] );
1049 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1050 if( rc != LDAP_SUCCESS ) {
1052 LDAP_LOG( CONFIG, CRIT,
1053 "%s: line %d: suffix DN is invalid.\n",
1056 Debug( LDAP_DEBUG_ANY,
1057 "%s: line %d: suffix DN is invalid\n",
1063 tmp_be = select_backend( &ndn, 0, 0 );
1064 if ( tmp_be == be ) {
1066 LDAP_LOG( CONFIG, INFO,
1067 "%s: line %d: suffix already served by this backend "
1068 "(ignored)\n", fname, lineno, 0 );
1070 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1071 "already served by this backend (ignored)\n",
1077 } else if ( tmp_be != NULL ) {
1079 LDAP_LOG( CONFIG, INFO,
1080 "%s: line %d: suffix already served by a preceding "
1081 "backend \"%s\"\n", fname, lineno,
1082 tmp_be->be_suffix[0].bv_val );
1084 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1085 "already served by a preceeding backend \"%s\"\n",
1086 fname, lineno, tmp_be->be_suffix[0].bv_val );
1092 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1094 LDAP_LOG( CONFIG, INFO,
1095 "%s: line %d: suffix DN empty and default search "
1096 "base provided \"%s\" (assuming okay).\n",
1097 fname, lineno, default_search_base.bv_val );
1099 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1100 "suffix DN empty and default "
1101 "search base provided \"%s\" (assuming okay)\n",
1102 fname, lineno, default_search_base.bv_val );
1106 ber_bvarray_add( &be->be_suffix, &pdn );
1107 ber_bvarray_add( &be->be_nsuffix, &ndn );
1109 /* set max deref depth */
1110 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1114 LDAP_LOG( CONFIG, CRIT,
1115 "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1116 " line\n", fname, lineno, 0 );
1118 Debug( LDAP_DEBUG_ANY,
1119 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1127 LDAP_LOG( CONFIG, INFO,
1128 "%s: line %d: depth line must appear inside a database "
1129 "definition.\n", fname, lineno ,0 );
1131 Debug( LDAP_DEBUG_ANY,
1132 "%s: line %d: depth line must appear inside a database definition.\n",
1137 } else if ((i = atoi(cargv[1])) < 0) {
1139 LDAP_LOG( CONFIG, INFO,
1140 "%s: line %d: depth must be positive.\n",
1143 Debug( LDAP_DEBUG_ANY,
1144 "%s: line %d: depth must be positive.\n",
1151 be->be_max_deref_depth = i;
1155 /* set magic "root" dn for this database */
1156 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1159 LDAP_LOG( CONFIG, INFO,
1160 "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1163 Debug( LDAP_DEBUG_ANY,
1164 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1173 LDAP_LOG( CONFIG, INFO,
1174 "%s: line %d: rootdn line must appear inside a database "
1175 "definition.\n", fname, lineno ,0 );
1177 Debug( LDAP_DEBUG_ANY,
1178 "%s: line %d: rootdn line must appear inside a database definition.\n",
1186 if ( load_ucdata( NULL ) < 0 ) return 1;
1188 dn.bv_val = cargv[1];
1189 dn.bv_len = strlen( cargv[1] );
1191 rc = dnPrettyNormal( NULL, &dn,
1193 &be->be_rootndn, NULL );
1195 if( rc != LDAP_SUCCESS ) {
1197 LDAP_LOG( CONFIG, CRIT,
1198 "%s: line %d: rootdn DN is invalid.\n",
1201 Debug( LDAP_DEBUG_ANY,
1202 "%s: line %d: rootdn DN is invalid\n",
1209 /* set super-secret magic database password */
1210 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1213 LDAP_LOG( CONFIG, CRIT,
1214 "%s: line %d: missing passwd in \"rootpw <passwd>\""
1215 " line\n", fname, lineno ,0 );
1217 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1218 "missing passwd in \"rootpw <passwd>\" line\n",
1227 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1228 "rootpw line must appear inside a database "
1229 "definition.\n", fname, lineno ,0 );
1231 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1232 "rootpw line must appear inside a database "
1239 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1241 if( tmp_be != be ) {
1243 LDAP_LOG( CONFIG, INFO,
1245 "rootpw can only be set when rootdn is under suffix\n",
1246 fname, lineno, "" );
1248 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1249 "rootpw can only be set when rootdn is under suffix\n",
1255 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1256 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1259 /* make this database read-only */
1260 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1263 LDAP_LOG( CONFIG, CRIT,
1264 "%s: line %d: missing on|off in \"readonly <on|off>\" "
1265 "line.\n", fname, lineno ,0 );
1267 Debug( LDAP_DEBUG_ANY,
1268 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1275 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1276 global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1278 global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1281 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1282 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1284 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1289 /* allow these features */
1290 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1291 strcasecmp( cargv[0], "allow" ) == 0 )
1297 LDAP_LOG( CONFIG, INFO,
1298 "%s: line %d: allow line must appear prior to "
1299 "database definitions.\n", fname, lineno ,0 );
1301 Debug( LDAP_DEBUG_ANY,
1302 "%s: line %d: allow line must appear prior to database definitions\n",
1310 LDAP_LOG( CONFIG, CRIT,
1311 "%s: line %d: missing feature(s) in \"allow <features>\""
1312 " line\n", fname, lineno ,0 );
1314 Debug( LDAP_DEBUG_ANY,
1315 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1324 for( i=1; i < cargc; i++ ) {
1325 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1326 allows |= SLAP_ALLOW_BIND_V2;
1328 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1329 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1331 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1332 allows |= SLAP_ALLOW_BIND_ANON_DN;
1334 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1335 allows |= SLAP_ALLOW_UPDATE_ANON;
1337 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1339 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1340 "unknown feature %s in \"allow <features>\" line.\n",
1341 fname, lineno, cargv[i] );
1343 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1344 "unknown feature %s in \"allow <features>\" line\n",
1345 fname, lineno, cargv[i] );
1352 global_allows = allows;
1354 /* disallow these features */
1355 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1356 strcasecmp( cargv[0], "disallow" ) == 0 )
1358 slap_mask_t disallows;
1362 LDAP_LOG( CONFIG, INFO,
1363 "%s: line %d: disallow line must appear prior to "
1364 "database definitions.\n", fname, lineno ,0 );
1366 Debug( LDAP_DEBUG_ANY,
1367 "%s: line %d: disallow line must appear prior to database definitions\n",
1375 LDAP_LOG( CONFIG, CRIT,
1376 "%s: line %d: missing feature(s) in \"disallow <features>\""
1377 " line.\n", fname, lineno ,0 );
1379 Debug( LDAP_DEBUG_ANY,
1380 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1389 for( i=1; i < cargc; i++ ) {
1390 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1391 disallows |= SLAP_DISALLOW_BIND_ANON;
1393 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1394 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1396 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1397 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1399 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1400 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1402 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1403 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1405 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1407 LDAP_LOG( CONFIG, CRIT,
1408 "%s: line %d: unknown feature %s in "
1409 "\"disallow <features>\" line.\n",
1410 fname, lineno, cargv[i] );
1412 Debug( LDAP_DEBUG_ANY,
1413 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1414 fname, lineno, cargv[i] );
1421 global_disallows = disallows;
1423 /* require these features */
1424 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1425 strcasecmp( cargv[0], "require" ) == 0 )
1427 slap_mask_t requires;
1431 LDAP_LOG( CONFIG, CRIT,
1432 "%s: line %d: missing feature(s) in "
1433 "\"require <features>\" line.\n", fname, lineno ,0 );
1435 Debug( LDAP_DEBUG_ANY,
1436 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1445 for( i=1; i < cargc; i++ ) {
1446 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1447 requires |= SLAP_REQUIRE_BIND;
1449 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1450 requires |= SLAP_REQUIRE_LDAP_V3;
1452 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1453 requires |= SLAP_REQUIRE_AUTHC;
1455 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1456 requires |= SLAP_REQUIRE_SASL;
1458 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1459 requires |= SLAP_REQUIRE_STRONG;
1461 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1463 LDAP_LOG( CONFIG, CRIT,
1464 "%s: line %d: unknown feature %s in "
1465 "\"require <features>\" line.\n",
1466 fname, lineno , cargv[i] );
1468 Debug( LDAP_DEBUG_ANY,
1469 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1470 fname, lineno, cargv[i] );
1478 global_requires = requires;
1480 be->be_requires = requires;
1483 /* required security factors */
1484 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1485 slap_ssf_set_t *set;
1489 LDAP_LOG( CONFIG, CRIT,
1490 "%s: line %d: missing factor(s) in \"security <factors>\""
1491 " line.\n", fname, lineno ,0 );
1493 Debug( LDAP_DEBUG_ANY,
1494 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1502 set = &global_ssf_set;
1504 set = &be->be_ssf_set;
1507 for( i=1; i < cargc; i++ ) {
1508 if( strncasecmp( cargv[i], "ssf=",
1509 sizeof("ssf") ) == 0 )
1512 atoi( &cargv[i][sizeof("ssf")] );
1514 } else if( strncasecmp( cargv[i], "transport=",
1515 sizeof("transport") ) == 0 )
1517 set->sss_transport =
1518 atoi( &cargv[i][sizeof("transport")] );
1520 } else if( strncasecmp( cargv[i], "tls=",
1521 sizeof("tls") ) == 0 )
1524 atoi( &cargv[i][sizeof("tls")] );
1526 } else if( strncasecmp( cargv[i], "sasl=",
1527 sizeof("sasl") ) == 0 )
1530 atoi( &cargv[i][sizeof("sasl")] );
1532 } else if( strncasecmp( cargv[i], "update_ssf=",
1533 sizeof("update_ssf") ) == 0 )
1535 set->sss_update_ssf =
1536 atoi( &cargv[i][sizeof("update_ssf")] );
1538 } else if( strncasecmp( cargv[i], "update_transport=",
1539 sizeof("update_transport") ) == 0 )
1541 set->sss_update_transport =
1542 atoi( &cargv[i][sizeof("update_transport")] );
1544 } else if( strncasecmp( cargv[i], "update_tls=",
1545 sizeof("update_tls") ) == 0 )
1547 set->sss_update_tls =
1548 atoi( &cargv[i][sizeof("update_tls")] );
1550 } else if( strncasecmp( cargv[i], "update_sasl=",
1551 sizeof("update_sasl") ) == 0 )
1553 set->sss_update_sasl =
1554 atoi( &cargv[i][sizeof("update_sasl")] );
1556 } else if( strncasecmp( cargv[i], "simple_bind=",
1557 sizeof("simple_bind") ) == 0 )
1559 set->sss_simple_bind =
1560 atoi( &cargv[i][sizeof("simple_bind")] );
1564 LDAP_LOG( CONFIG, CRIT,
1565 "%s: line %d: unknown factor %S in "
1566 "\"security <factors>\" line.\n",
1567 fname, lineno, cargv[1] );
1569 Debug( LDAP_DEBUG_ANY,
1570 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1571 fname, lineno, cargv[i] );
1577 /* where to send clients when we don't hold it */
1578 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1581 LDAP_LOG( CONFIG, CRIT,
1582 "%s: line %d: missing URL in \"referral <URL>\""
1583 " line.\n", fname, lineno , 0 );
1585 Debug( LDAP_DEBUG_ANY,
1586 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1593 if( validate_global_referral( cargv[1] ) ) {
1595 LDAP_LOG( CONFIG, CRIT,
1596 "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1597 fname, lineno, cargv[1] );
1599 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1600 "invalid URL (%s) in \"referral\" line.\n",
1601 fname, lineno, cargv[1] );
1606 vals[0].bv_val = cargv[1];
1607 vals[0].bv_len = strlen( vals[0].bv_val );
1608 if( value_add( &default_referral, vals ) )
1612 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1616 LDAP_LOG( CONFIG, CRIT,
1617 "%s: line %d: Error in logfile directive, "
1618 "\"logfile <filename>\"\n", fname, lineno , 0 );
1620 Debug( LDAP_DEBUG_ANY,
1621 "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1627 logfile = fopen( cargv[1], "w" );
1628 if ( logfile != NULL ) lutil_debug_file( logfile );
1631 /* start of a new database definition */
1632 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1636 LDAP_LOG( CONFIG, CRIT,
1637 "%s: line %d: Error in debug directive, "
1638 "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1640 Debug( LDAP_DEBUG_ANY,
1641 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1647 level = atoi( cargv[2] );
1648 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1649 lutil_set_debug_level( cargv[1], level );
1650 /* specify an Object Identifier macro */
1651 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1652 rc = parse_oidm( fname, lineno, cargc, cargv );
1655 /* specify an objectclass */
1656 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1659 LDAP_LOG( CONFIG, INFO,
1660 "%s: line %d: illegal objectclass format.\n",
1661 fname, lineno , 0 );
1663 Debug( LDAP_DEBUG_ANY,
1664 "%s: line %d: illegal objectclass format.\n",
1669 } else if ( *cargv[1] == '(' /*')'*/) {
1671 p = strchr(saveline,'(' /*')'*/);
1672 rc = parse_oc( fname, lineno, p, cargv );
1677 LDAP_LOG( CONFIG, INFO,
1678 "%s: line %d: old objectclass format not supported\n",
1679 fname, lineno , 0 );
1681 Debug( LDAP_DEBUG_ANY,
1682 "%s: line %d: old objectclass format not supported.\n",
1687 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1689 p = strchr(saveline,'(' /*')'*/);
1690 rc = parse_cr( fname, lineno, p, cargv );
1693 /* specify an attribute type */
1694 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1695 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1699 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1700 "illegal attribute type format.\n",
1701 fname, lineno , 0 );
1703 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1704 "illegal attribute type format.\n",
1709 } else if ( *cargv[1] == '(' /*')'*/) {
1711 p = strchr(saveline,'(' /*')'*/);
1712 rc = parse_at( fname, lineno, p, cargv );
1717 LDAP_LOG( CONFIG, INFO,
1718 "%s: line %d: old attribute type format not supported.\n",
1719 fname, lineno , 0 );
1721 Debug( LDAP_DEBUG_ANY,
1722 "%s: line %d: old attribute type format not supported.\n",
1728 /* define attribute option(s) */
1729 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1730 ad_define_option( NULL, NULL, 0 );
1731 for ( i = 1; i < cargc; i++ )
1732 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1735 /* turn on/off schema checking */
1736 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1739 LDAP_LOG( CONFIG, CRIT,
1740 "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1741 " line.\n", fname, lineno , 0 );
1743 Debug( LDAP_DEBUG_ANY,
1744 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1750 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1752 LDAP_LOG( CONFIG, CRIT,
1753 "%s: line %d: schema checking disabled! your mileage may "
1754 "vary!\n", fname, lineno , 0 );
1756 Debug( LDAP_DEBUG_ANY,
1757 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1760 global_schemacheck = 0;
1762 global_schemacheck = 1;
1765 /* specify access control info */
1766 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1767 parse_acl( be, fname, lineno, cargc, cargv );
1769 /* debug level to log things to syslog */
1770 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1773 LDAP_LOG( CONFIG, CRIT,
1774 "%s: line %d: missing level in \"loglevel <level>\""
1775 " line.\n", fname, lineno , 0 );
1777 Debug( LDAP_DEBUG_ANY,
1778 "%s: line %d: missing level in \"loglevel <level>\" line\n",
1787 for( i=1; i < cargc; i++ ) {
1788 ldap_syslog += atoi( cargv[1] );
1791 /* list of sync replication information in this backend (slave only) */
1792 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1796 LDAP_LOG( CONFIG, INFO,
1797 "%s: line %d: syncrepl line must appear inside "
1798 "a database definition.\n", fname, lineno, 0);
1800 Debug( LDAP_DEBUG_ANY,
1801 "%s: line %d: syncrepl line must appear inside "
1802 "a database definition.\n", fname, lineno, 0);
1806 } else if ( SLAP_SHADOW( be )) {
1808 LDAP_LOG( CONFIG, INFO,
1809 "%s: line %d: syncrepl: database already shadowed.\n",
1812 Debug( LDAP_DEBUG_ANY,
1813 "%s: line %d: syncrepl: database already shadowed.\n",
1818 } else if ( add_syncrepl( be, cargv, cargc )) {
1822 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1824 /* list of replicas of the data in this backend (master only) */
1825 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1828 LDAP_LOG( CONFIG, CRIT,
1829 "%s: line %d: missing host or uri in \"replica "
1830 " <host[:port]\" line\n", fname, lineno , 0 );
1832 Debug( LDAP_DEBUG_ANY,
1833 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1841 LDAP_LOG( CONFIG, INFO,
1842 "%s: line %d: replica line must appear inside "
1843 "a database definition.\n", fname, lineno, 0);
1845 Debug( LDAP_DEBUG_ANY,
1846 "%s: line %d: replica line must appear inside a database definition\n",
1854 for ( i = 1; i < cargc; i++ ) {
1855 if ( strncasecmp( cargv[i], "host=", 5 )
1857 nr = add_replica_info( be,
1860 } else if (strncasecmp( cargv[i], "uri=", 4 )
1862 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1865 LDAP_LOG( CONFIG, INFO,
1866 "%s: line %d: replica line contains invalid "
1867 "uri definition.\n", fname, lineno, 0);
1869 Debug( LDAP_DEBUG_ANY,
1870 "%s: line %d: replica line contains invalid "
1871 "uri definition.\n", fname, lineno, 0);
1875 if (ludp->lud_host == NULL ) {
1877 LDAP_LOG( CONFIG, INFO,
1878 "%s: line %d: replica line contains invalid "
1879 "uri definition - missing hostname.\n",
1882 Debug( LDAP_DEBUG_ANY,
1883 "%s: line %d: replica line contains invalid "
1884 "uri definition - missing hostname.\n", fname, lineno, 0);
1888 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1889 if ( replicahost == NULL ) {
1891 LDAP_LOG( CONFIG, ERR,
1892 "out of memory in read_config\n", 0, 0,0 );
1894 Debug( LDAP_DEBUG_ANY,
1895 "out of memory in read_config\n", 0, 0, 0 );
1897 ldap_free_urldesc( ludp );
1898 exit( EXIT_FAILURE );
1900 sprintf(replicahost, "%s:%d",
1901 ludp->lud_host, ludp->lud_port);
1902 nr = add_replica_info( be, replicahost );
1903 ldap_free_urldesc( ludp );
1904 ch_free(replicahost);
1910 LDAP_LOG( CONFIG, INFO,
1911 "%s: line %d: missing host or uri in \"replica\" line\n",
1912 fname, lineno , 0 );
1914 Debug( LDAP_DEBUG_ANY,
1915 "%s: line %d: missing host or uri in \"replica\" line\n",
1920 } else if ( nr == -1 ) {
1922 LDAP_LOG( CONFIG, INFO,
1923 "%s: line %d: unable to add"
1924 " replica \"%s\"\n",
1928 Debug( LDAP_DEBUG_ANY,
1929 "%s: line %d: unable to add replica \"%s\"\n",
1930 fname, lineno, cargv[i] + 5 );
1934 for ( i = 1; i < cargc; i++ ) {
1935 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1937 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1940 LDAP_LOG( CONFIG, INFO,
1941 "%s: line %d: suffix \"%s\" in \"replica\""
1942 " line is not valid for backend(ignored)\n",
1943 fname, lineno, cargv[i] + 7 );
1945 Debug( LDAP_DEBUG_ANY,
1946 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1947 fname, lineno, cargv[i] + 7 );
1953 LDAP_LOG( CONFIG, INFO,
1954 "%s: line %d: unable to normalize suffix"
1955 " in \"replica\" line (ignored)\n",
1956 fname, lineno , 0 );
1958 Debug( LDAP_DEBUG_ANY,
1959 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1965 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1967 char *arg = cargv[i] + 4;
1969 if ( arg[0] == '!' ) {
1974 if ( arg[0] != '=' ) {
1978 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1980 LDAP_LOG( CONFIG, INFO,
1981 "%s: line %d: attribute \"%s\" in "
1982 "\"replica\" line is unknown\n",
1983 fname, lineno, arg + 1 );
1985 Debug( LDAP_DEBUG_ANY,
1986 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1987 fname, lineno, arg + 1 );
1996 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1999 /* dn of slave entity allowed to write to replica */
2000 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2003 LDAP_LOG( CONFIG, CRIT,
2004 "%s: line %d: missing dn in \"updatedn <dn>\""
2005 " line.\n", fname, lineno , 0 );
2007 Debug( LDAP_DEBUG_ANY,
2008 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2016 LDAP_LOG( CONFIG, INFO,
2017 "%s: line %d: updatedn line must appear inside "
2018 "a database definition\n",
2019 fname, lineno , 0 );
2021 Debug( LDAP_DEBUG_ANY,
2022 "%s: line %d: updatedn line must appear inside a database definition\n",
2027 } else if ( SLAP_SHADOW(be) ) {
2029 LDAP_LOG( CONFIG, INFO,
2030 "%s: line %d: updatedn: database already shadowed.\n",
2033 Debug( LDAP_DEBUG_ANY,
2034 "%s: line %d: updatedn: database already shadowed.\n",
2042 if ( load_ucdata( NULL ) < 0 ) return 1;
2044 dn.bv_val = cargv[1];
2045 dn.bv_len = strlen( cargv[1] );
2047 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2048 if( rc != LDAP_SUCCESS ) {
2050 LDAP_LOG( CONFIG, CRIT,
2051 "%s: line %d: updatedn DN is invalid.\n",
2052 fname, lineno , 0 );
2054 Debug( LDAP_DEBUG_ANY,
2055 "%s: line %d: updatedn DN is invalid\n",
2062 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2064 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2067 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2068 "missing url in \"updateref <ldapurl>\" line.\n",
2069 fname, lineno , 0 );
2071 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2072 "missing url in \"updateref <ldapurl>\" line\n",
2080 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2081 " line must appear inside a database definition\n",
2082 fname, lineno , 0 );
2084 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2085 " line must appear inside a database definition\n",
2090 } else if ( !SLAP_SHADOW(be) ) {
2092 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2093 "updateref line must come after syncrepl or updatedn.\n",
2094 fname, lineno , 0 );
2096 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2097 "updateref line must after syncrepl or updatedn.\n",
2103 if( validate_global_referral( cargv[1] ) ) {
2105 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2106 "invalid URL (%s) in \"updateref\" line.\n",
2107 fname, lineno, cargv[1] );
2109 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2110 "invalid URL (%s) in \"updateref\" line.\n",
2111 fname, lineno, cargv[1] );
2116 vals[0].bv_val = cargv[1];
2117 vals[0].bv_len = strlen( vals[0].bv_val );
2118 if( value_add( &be->be_update_refs, vals ) ) {
2122 /* replication log file to which changes are appended */
2123 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2126 LDAP_LOG( CONFIG, CRIT,
2127 "%s: line %d: missing filename in \"replogfile <filename>\""
2128 " line.\n", fname, lineno , 0 );
2130 Debug( LDAP_DEBUG_ANY,
2131 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2138 be->be_replogfile = ch_strdup( cargv[1] );
2140 replogfile = ch_strdup( cargv[1] );
2143 /* file from which to read additional rootdse attrs */
2144 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2147 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2148 "missing filename in \"rootDSE <filename>\" line.\n",
2149 fname, lineno , 0 );
2151 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2152 "missing filename in \"rootDSE <filename>\" line.\n",
2158 if( read_root_dse_file( cargv[1] ) ) {
2160 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2161 "could not read \"rootDSE <filename>\" line.\n",
2162 fname, lineno , 0 );
2164 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2165 "could not read \"rootDSE <filename>\" line\n",
2171 /* maintain lastmodified{by,time} attributes */
2172 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2175 LDAP_LOG( CONFIG, CRIT,
2176 "%s: line %d: missing on|off in \"lastmod <on|off>\""
2177 " line.\n", fname, lineno , 0 );
2179 Debug( LDAP_DEBUG_ANY,
2180 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2186 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2188 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2194 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2201 /* turn on/off gentle SIGHUP handling */
2202 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2204 Debug( LDAP_DEBUG_ANY,
2205 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2209 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2210 global_gentlehup = 0;
2212 global_gentlehup = 1;
2216 /* set idle timeout value */
2217 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2221 LDAP_LOG( CONFIG, CRIT,
2222 "%s: line %d: missing timeout value in "
2223 "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2225 Debug( LDAP_DEBUG_ANY,
2226 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2233 i = atoi( cargv[1] );
2237 LDAP_LOG( CONFIG, CRIT,
2238 "%s: line %d: timeout value (%d) invalid "
2239 "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2241 Debug( LDAP_DEBUG_ANY,
2242 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2249 global_idletimeout = i;
2251 /* include another config file */
2252 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2255 LDAP_LOG( CONFIG, CRIT,
2256 "%s: line %d: missing filename in \"include "
2257 "<filename>\" line.\n", fname, lineno , 0 );
2259 Debug( LDAP_DEBUG_ANY,
2260 "%s: line %d: missing filename in \"include <filename>\" line\n",
2266 savefname = ch_strdup( cargv[1] );
2267 savelineno = lineno;
2269 if ( read_config( savefname, depth+1 ) != 0 ) {
2274 lineno = savelineno - 1;
2276 /* location of kerberos srvtab file */
2277 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2280 LDAP_LOG( CONFIG, CRIT,
2281 "%s: line %d: missing filename in \"srvtab "
2282 "<filename>\" line.\n", fname, lineno , 0 );
2284 Debug( LDAP_DEBUG_ANY,
2285 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2291 ldap_srvtab = ch_strdup( cargv[1] );
2293 #ifdef SLAPD_MODULES
2294 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2297 LDAP_LOG( CONFIG, INFO,
2298 "%s: line %d: missing filename in \"moduleload "
2299 "<filename>\" line.\n", fname, lineno , 0 );
2301 Debug( LDAP_DEBUG_ANY,
2302 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2306 exit( EXIT_FAILURE );
2308 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2310 LDAP_LOG( CONFIG, CRIT,
2311 "%s: line %d: failed to load or initialize module %s\n",
2312 fname, lineno, cargv[1] );
2314 Debug( LDAP_DEBUG_ANY,
2315 "%s: line %d: failed to load or initialize module %s\n",
2316 fname, lineno, cargv[1]);
2319 exit( EXIT_FAILURE );
2321 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2324 LDAP_LOG( CONFIG, INFO,
2325 "%s: line %d: missing path in \"modulepath <path>\""
2326 " line\n", fname, lineno , 0 );
2328 Debug( LDAP_DEBUG_ANY,
2329 "%s: line %d: missing path in \"modulepath <path>\" line\n",
2333 exit( EXIT_FAILURE );
2335 if (module_path( cargv[1] )) {
2337 LDAP_LOG( CONFIG, CRIT,
2338 "%s: line %d: failed to set module search path to %s.\n",
2339 fname, lineno, cargv[1] );
2341 Debug( LDAP_DEBUG_ANY,
2342 "%s: line %d: failed to set module search path to %s\n",
2343 fname, lineno, cargv[1]);
2346 exit( EXIT_FAILURE );
2349 #endif /*SLAPD_MODULES*/
2352 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2353 rc = ldap_pvt_tls_set_option( NULL,
2354 LDAP_OPT_X_TLS_RANDOM_FILE,
2359 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2360 rc = ldap_pvt_tls_set_option( NULL,
2361 LDAP_OPT_X_TLS_CIPHER_SUITE,
2366 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2367 rc = ldap_pvt_tls_set_option( NULL,
2368 LDAP_OPT_X_TLS_CERTFILE,
2373 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2374 rc = ldap_pvt_tls_set_option( NULL,
2375 LDAP_OPT_X_TLS_KEYFILE,
2380 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2381 rc = ldap_pvt_tls_set_option( NULL,
2382 LDAP_OPT_X_TLS_CACERTDIR,
2387 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2388 rc = ldap_pvt_tls_set_option( NULL,
2389 LDAP_OPT_X_TLS_CACERTFILE,
2393 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2394 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2396 rc = ldap_pvt_tls_set_option( NULL,
2397 LDAP_OPT_X_TLS_REQUIRE_CERT,
2400 rc = ldap_int_tls_config( NULL,
2401 LDAP_OPT_X_TLS_REQUIRE_CERT,
2410 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2411 #ifdef SLAPD_RLOOKUPS
2414 LDAP_LOG( CONFIG, INFO,
2415 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2416 fname, lineno , 0 );
2418 Debug( LDAP_DEBUG_ANY,
2419 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2425 if ( !strcasecmp( cargv[1], "on" ) ) {
2426 use_reverse_lookup = 1;
2427 } else if ( !strcasecmp( cargv[1], "off" ) ) {
2428 use_reverse_lookup = 0;
2431 LDAP_LOG( CONFIG, INFO,
2432 "%s: line %d: reverse-lookup: "
2433 "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2435 Debug( LDAP_DEBUG_ANY,
2436 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2442 #else /* !SLAPD_RLOOKUPS */
2444 LDAP_LOG( CONFIG, INFO,
2445 "%s: line %d: reverse lookups "
2446 "are not configured (ignored).\n", fname, lineno , 0 );
2448 Debug( LDAP_DEBUG_ANY,
2449 "%s: line %d: reverse lookups are not configured (ignored).\n",
2452 #endif /* !SLAPD_RLOOKUPS */
2454 /* Netscape plugins */
2455 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2456 #if defined( LDAP_SLAPI )
2458 #ifdef notdef /* allow global plugins, too */
2460 * a "plugin" line must be inside a database
2461 * definition, since we implement pre-,post-
2462 * and extended operation plugins
2466 LDAP_LOG( CONFIG, INFO,
2467 "%s: line %d: plugin line must appear "
2468 "insid a database definition.\n",
2471 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2472 "line must appear inside a database "
2473 "definition\n", fname, lineno, 0 );
2479 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
2483 slapi_plugins_used++;
2485 #else /* !defined( LDAP_SLAPI ) */
2487 LDAP_LOG( CONFIG, INFO,
2488 "%s: line %d: SLAPI not supported.\n",
2491 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2492 "not supported.\n", fname, lineno, 0 );
2496 #endif /* !defined( LDAP_SLAPI ) */
2498 /* Netscape plugins */
2499 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2500 #if defined( LDAP_SLAPI )
2503 LDAP_LOG( CONFIG, INFO,
2504 "%s: line %d: missing file name "
2505 "in pluginlog <filename> line.\n",
2508 Debug( LDAP_DEBUG_ANY,
2509 "%s: line %d: missing file name "
2510 "in pluginlog <filename> line.\n",
2516 if ( slapi_log_file != NULL ) {
2517 ch_free( slapi_log_file );
2520 slapi_log_file = ch_strdup( cargv[1] );
2521 #endif /* !defined( LDAP_SLAPI ) */
2523 /* pass anything else to the current backend info/db config routine */
2526 if ( bi->bi_config ) {
2527 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2533 case SLAP_CONF_UNKNOWN:
2535 LDAP_LOG( CONFIG, INFO,
2536 "%s: line %d: unknown directive \"%s\" inside "
2537 "backend info definition (ignored).\n",
2538 fname, lineno, cargv[0] );
2540 Debug( LDAP_DEBUG_ANY,
2541 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2542 fname, lineno, cargv[0] );
2551 } else if ( be != NULL ) {
2552 if ( be->be_config ) {
2553 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2559 case SLAP_CONF_UNKNOWN:
2561 LDAP_LOG( CONFIG, INFO,
2562 "%s: line %d: unknown directive \"%s\" inside "
2563 "backend database definition (ignored).\n",
2564 fname, lineno, cargv[0] );
2566 Debug( LDAP_DEBUG_ANY,
2567 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2568 fname, lineno, cargv[0] );
2579 LDAP_LOG( CONFIG, INFO,
2580 "%s: line %d: unknown directive \"%s\" outside backend "
2581 "info and database definitions (ignored).\n",
2582 fname, lineno, cargv[0] );
2584 Debug( LDAP_DEBUG_ANY,
2585 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2586 fname, lineno, cargv[0] );
2595 if ( depth == 0 ) ch_free( cargv );
2597 if ( !global_schemadn.bv_val ) {
2598 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2600 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2603 if ( load_ucdata( NULL ) < 0 ) return 1;
2615 char logbuf[sizeof("pseudorootpw ***")];
2618 token = strtok_quote( line, " \t" );
2622 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2623 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2624 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2625 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2626 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2628 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2631 if ( strtok_quote_ptr ) {
2632 *strtok_quote_ptr = ' ';
2636 LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2638 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2641 if ( strtok_quote_ptr ) {
2642 *strtok_quote_ptr = '\0';
2645 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2646 if ( cargc == cargv_size - 1 ) {
2648 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2650 if ( tmp == NULL ) {
2652 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2654 Debug( LDAP_DEBUG_ANY,
2655 "line %d: out of memory\n",
2661 cargv_size += ARGS_STEP;
2663 cargv[cargc++] = token;
2665 cargv[cargc] = NULL;
2670 strtok_quote( char *line, char *sep )
2676 strtok_quote_ptr = NULL;
2677 if ( line != NULL ) {
2680 while ( *next && strchr( sep, *next ) ) {
2684 if ( *next == '\0' ) {
2690 for ( inquote = 0; *next; ) {
2698 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2704 next + 1, strlen( next + 1 ) + 1 );
2705 next++; /* dont parse the escaped character */
2710 if ( strchr( sep, *next ) != NULL ) {
2711 strtok_quote_ptr = next;
2724 static char buf[BUFSIZ];
2726 static size_t lmax, lcur;
2728 #define CATLINE( buf ) \
2730 size_t len = strlen( buf ); \
2731 while ( lcur + len + 1 > lmax ) { \
2733 line = (char *) ch_realloc( line, lmax ); \
2735 strcpy( line + lcur, buf ); \
2740 fp_getline( FILE *fp, int *lineno )
2748 /* hack attack - keeps us from having to keep a stack of bufs... */
2749 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2754 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2755 /* trim off \r\n or \n */
2756 if ( (p = strchr( buf, '\n' )) != NULL ) {
2757 if( p > buf && p[-1] == '\r' ) --p;
2761 /* trim off trailing \ and append the next line */
2762 if ( line[ 0 ] != '\0'
2763 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2764 && p[ -1 ] != '\\' ) {
2769 if ( ! isspace( (unsigned char) buf[0] ) ) {
2773 /* change leading whitespace to a space */
2782 return( line[0] ? line : NULL );
2786 fp_getline_init( int *lineno )
2792 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2794 load_ucdata( char *path )
2796 static int loaded = 0;
2802 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2805 LDAP_LOG( CONFIG, CRIT,
2806 "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2808 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2821 ucdata_unload( UCDATA_ALL );
2822 free( global_schemandn.bv_val );
2823 free( global_schemadn.bv_val );
2825 if ( slapd_args_file )
2826 free ( slapd_args_file );
2827 if ( slapd_pid_file )
2828 free ( slapd_pid_file );
2829 if ( default_passwd_hash )
2830 ldap_charray_free( default_passwd_hash );
2831 acl_destroy( global_acl, NULL );
2842 syncinfo_t *si_entry;
2844 int duplicated_replica_id = 0;
2846 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2850 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2852 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2857 si->si_tls = SYNCINFO_TLS_OFF;
2858 if ( be->be_rootndn.bv_val ) {
2859 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2861 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2862 si->si_schemachecking = 0;
2863 ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
2864 &si->si_filterstr );
2865 si->si_base.bv_val = NULL;
2866 si->si_scope = LDAP_SCOPE_SUBTREE;
2867 si->si_attrsonly = 0;
2868 si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2869 si->si_attrs[0] = NULL;
2870 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2871 si->si_interval = 86400;
2872 si->si_syncCookie.ctxcsn = NULL;
2873 si->si_syncCookie.octet_str = NULL;
2874 si->si_syncCookie.sid = -1;
2875 si->si_manageDSAit = 0;
2878 si->si_syncUUID_ndn.bv_val = NULL;
2879 si->si_syncUUID_ndn.bv_len = 0;
2881 si->si_presentlist = NULL;
2882 LDAP_LIST_INIT( &si->si_nonpresentlist );
2884 rc = parse_syncrepl_line( cargv, cargc, si );
2886 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2887 if ( si->si_rid == si_entry->si_rid ) {
2889 LDAP_LOG( CONFIG, ERR,
2890 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
2892 Debug( LDAP_DEBUG_ANY,
2893 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2895 duplicated_replica_id = 1;
2900 if ( rc < 0 || duplicated_replica_id ) {
2901 syncinfo_t *si_entry;
2902 /* Something bad happened - back out */
2904 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2906 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2909 /* If error, remove all syncinfo */
2910 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2911 if ( si_entry->si_updatedn.bv_val ) {
2912 ch_free( si->si_updatedn.bv_val );
2914 if ( si_entry->si_filterstr.bv_val ) {
2915 ch_free( si->si_filterstr.bv_val );
2917 if ( si_entry->si_attrs ) {
2919 while ( si_entry->si_attrs[i] != NULL ) {
2920 ch_free( si_entry->si_attrs[i] );
2923 ch_free( si_entry->si_attrs );
2927 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2928 si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
2929 LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
2930 ch_free( si_entry );
2932 LDAP_STAILQ_INIT( &be->be_syncinfo );
2936 LDAP_LOG ( CONFIG, RESULTS,
2937 "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2938 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2940 Debug( LDAP_DEBUG_CONFIG,
2941 "Config: ** successfully added syncrepl \"%s\"\n",
2942 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2944 if ( !si->si_schemachecking ) {
2945 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2948 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2954 #define PROVIDERSTR "provider"
2955 #define SUFFIXSTR "suffix"
2956 #define UPDATEDNSTR "updatedn"
2957 #define BINDMETHSTR "bindmethod"
2958 #define SIMPLESTR "simple"
2959 #define SASLSTR "sasl"
2960 #define BINDDNSTR "binddn"
2961 #define CREDSTR "credentials"
2962 #define OLDAUTHCSTR "bindprincipal"
2963 #define AUTHCSTR "authcID"
2964 #define AUTHZSTR "authzID"
2965 #define SRVTABSTR "srvtab"
2966 #define SASLMECHSTR "saslmech"
2967 #define REALMSTR "realm"
2968 #define SECPROPSSTR "secprops"
2969 #define STARTTLSSTR "starttls"
2970 #define CRITICALSTR "critical"
2972 #define SCHEMASTR "schemachecking"
2973 #define FILTERSTR "filter"
2974 #define SEARCHBASESTR "searchbase"
2975 #define SCOPESTR "scope"
2976 #define ATTRSSTR "attrs"
2977 #define ATTRSONLYSTR "attrsonly"
2978 #define TYPESTR "type"
2979 #define INTERVALSTR "interval"
2980 #define LASTMODSTR "lastmod"
2981 #define LMREQSTR "req"
2982 #define LMGENSTR "gen"
2983 #define LMNOSTR "no"
2984 #define MANAGEDSAITSTR "manageDSAit"
2985 #define SLIMITSTR "sizelimit"
2986 #define TLIMITSTR "timelimit"
2988 #define GOT_ID 0x0001
2989 #define GOT_PROVIDER 0x0002
2990 #define GOT_METHOD 0x0004
2991 #define GOT_ALL 0x0007
2994 parse_syncrepl_line(
3005 for ( i = 1; i < cargc; i++ ) {
3006 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3008 /* '\0' string terminator accounts for '=' */
3009 val = cargv[ i ] + sizeof( IDSTR );
3011 if ( tmp >= 1000 || tmp < 0 ) {
3012 fprintf( stderr, "Error: parse_syncrepl_line: "
3013 "syncrepl id %d is out of range [0..999]\n", tmp );
3018 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3019 sizeof( PROVIDERSTR ) - 1 )) {
3020 val = cargv[ i ] + sizeof( PROVIDERSTR );
3021 si->si_provideruri = ch_strdup( val );
3022 si->si_provideruri_bv = (BerVarray)
3023 ch_calloc( 2, sizeof( struct berval ));
3024 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3025 0, &si->si_provideruri_bv[0] );
3026 si->si_provideruri_bv[1].bv_len = 0;
3027 si->si_provideruri_bv[1].bv_val = NULL;
3028 gots |= GOT_PROVIDER;
3029 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3030 sizeof(STARTTLSSTR) - 1 ) )
3032 val = cargv[ i ] + sizeof( STARTTLSSTR );
3033 if( !strcasecmp( val, CRITICALSTR ) ) {
3034 si->si_tls = SYNCINFO_TLS_CRITICAL;
3036 si->si_tls = SYNCINFO_TLS_ON;
3038 } else if ( !strncasecmp( cargv[ i ],
3039 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3041 struct berval updatedn = {0, NULL};
3042 val = cargv[ i ] + sizeof( UPDATEDNSTR );
3043 ber_str2bv( val, 0, 0, &updatedn );
3044 ch_free( si->si_updatedn.bv_val );
3045 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3046 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3047 sizeof( BINDMETHSTR ) - 1 ) )
3049 val = cargv[ i ] + sizeof( BINDMETHSTR );
3050 if ( !strcasecmp( val, SIMPLESTR )) {
3051 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3053 } else if ( !strcasecmp( val, SASLSTR )) {
3054 #ifdef HAVE_CYRUS_SASL
3055 si->si_bindmethod = LDAP_AUTH_SASL;
3057 #else /* HAVE_CYRUS_SASL */
3058 fprintf( stderr, "Error: parse_syncrepl_line: "
3059 "not compiled with SASL support\n" );
3061 #endif /* HAVE_CYRUS_SASL */
3063 si->si_bindmethod = -1;
3065 } else if ( !strncasecmp( cargv[ i ],
3066 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3067 val = cargv[ i ] + sizeof( BINDDNSTR );
3068 si->si_binddn = ch_strdup( val );
3069 } else if ( !strncasecmp( cargv[ i ],
3070 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3071 val = cargv[ i ] + sizeof( CREDSTR );
3072 si->si_passwd = ch_strdup( val );
3073 } else if ( !strncasecmp( cargv[ i ],
3074 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3075 val = cargv[ i ] + sizeof( SASLMECHSTR );
3076 si->si_saslmech = ch_strdup( val );
3077 } else if ( !strncasecmp( cargv[ i ],
3078 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3079 val = cargv[ i ] + sizeof( SECPROPSSTR );
3080 si->si_secprops = ch_strdup( val );
3081 } else if ( !strncasecmp( cargv[ i ],
3082 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3083 val = cargv[ i ] + sizeof( REALMSTR );
3084 si->si_realm = ch_strdup( val );
3085 } else if ( !strncasecmp( cargv[ i ],
3086 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3087 val = cargv[ i ] + sizeof( AUTHCSTR );
3088 si->si_authcId = ch_strdup( val );
3089 } else if ( !strncasecmp( cargv[ i ],
3090 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3091 /* Old authcID is provided for some backwards compatibility */
3092 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3093 si->si_authcId = ch_strdup( val );
3094 } else if ( !strncasecmp( cargv[ i ],
3095 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3096 val = cargv[ i ] + sizeof( AUTHZSTR );
3097 si->si_authzId = ch_strdup( val );
3098 } else if ( !strncasecmp( cargv[ i ],
3099 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3101 val = cargv[ i ] + sizeof( SCHEMASTR );
3102 if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
3103 si->si_schemachecking = 1;
3104 } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
3105 si->si_schemachecking = 0;
3107 si->si_schemachecking = 1;
3109 } else if ( !strncasecmp( cargv[ i ],
3110 FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3112 val = cargv[ i ] + sizeof( FILTERSTR );
3113 ber_str2bv( val, 0, 1, &si->si_filterstr );
3114 } else if ( !strncasecmp( cargv[ i ],
3115 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3118 val = cargv[ i ] + sizeof( SEARCHBASESTR );
3119 if ( si->si_base.bv_val ) {
3120 ch_free( si->si_base.bv_val );
3122 ber_str2bv( val, 0, 0, &bv );
3123 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3124 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3127 } else if ( !strncasecmp( cargv[ i ],
3128 SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3130 val = cargv[ i ] + sizeof( SCOPESTR );
3131 if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3132 si->si_scope = LDAP_SCOPE_BASE;
3133 } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3134 si->si_scope = LDAP_SCOPE_ONELEVEL;
3135 #ifdef LDAP_SCOPE_SUBORDINATE
3136 } else if ( !strcasecmp( val, "subordinate" ) ||
3137 !strcasecmp( val, "children" ))
3139 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3141 } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3142 si->si_scope = LDAP_SCOPE_SUBTREE;
3144 fprintf( stderr, "Error: parse_syncrepl_line: "
3145 "unknown scope \"%s\"\n", val);
3148 } else if ( !strncasecmp( cargv[ i ],
3149 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3151 si->si_attrsonly = 1;
3152 } else if ( !strncasecmp( cargv[ i ],
3153 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3155 val = cargv[ i ] + sizeof( ATTRSSTR );
3156 str2clist( &si->si_attrs, val, "," );
3157 } else if ( !strncasecmp( cargv[ i ],
3158 TYPESTR, sizeof( TYPESTR ) - 1 ) )
3160 val = cargv[ i ] + sizeof( TYPESTR );
3161 if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3162 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3163 } else if ( !strncasecmp( val, "refreshAndPersist",
3164 sizeof("refreshAndPersist")-1 ))
3166 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3167 si->si_interval = 60;
3169 fprintf( stderr, "Error: parse_syncrepl_line: "
3170 "unknown sync type \"%s\"\n", val);
3173 } else if ( !strncasecmp( cargv[ i ],
3174 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3181 val = cargv[ i ] + sizeof( INTERVALSTR );
3183 hstr = strchr( dstr, ':' );
3184 if ( hstr == NULL ) {
3185 fprintf( stderr, "Error: parse_syncrepl_line: "
3186 "invalid interval \"%s\"\n", val );
3190 mstr = strchr( hstr, ':' );
3191 if ( mstr == NULL ) {
3192 fprintf( stderr, "Error: parse_syncrepl_line: "
3193 "invalid interval \"%s\"\n", val );
3197 sstr = strchr( mstr, ':' );
3198 if ( sstr == NULL ) {
3199 fprintf( stderr, "Error: parse_syncrepl_line: "
3200 "invalid interval \"%s\"\n", val );
3209 if (( hh > 24 ) || ( hh < 0 ) ||
3210 ( mm > 60 ) || ( mm < 0 ) ||
3211 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3212 fprintf( stderr, "Error: parse_syncrepl_line: "
3213 "invalid interval \"%s\"\n", val );
3216 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3218 if ( si->si_interval < 0 ) {
3219 fprintf( stderr, "Error: parse_syncrepl_line: "
3220 "invalid interval \"%ld\"\n",
3221 (long) si->si_interval);
3224 } else if ( !strncasecmp( cargv[ i ],
3225 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3227 val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3228 si->si_manageDSAit = atoi( val );
3229 } else if ( !strncasecmp( cargv[ i ],
3230 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3232 val = cargv[ i ] + sizeof( SLIMITSTR );
3233 si->si_slimit = atoi( val );
3234 } else if ( !strncasecmp( cargv[ i ],
3235 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3237 val = cargv[ i ] + sizeof( TLIMITSTR );
3238 si->si_tlimit = atoi( val );
3240 fprintf( stderr, "Error: parse_syncrepl_line: "
3241 "unknown keyword \"%s\"\n", cargv[ i ] );
3245 if ( gots != GOT_ALL ) {
3247 "Error: Malformed \"syncrepl\" line in slapd config file" );
3255 str2clist( char ***out, char *in, const char *brkstr )
3264 /* find last element in list */
3265 for (i = 0; *out && *out[i]; i++);
3267 /* protect the input string from strtok */
3268 str = ch_strdup( in );
3270 if ( *str == '\0' ) {
3275 /* Count words in string */
3277 for ( s = str; *s; s++ ) {
3278 if ( strchr( brkstr, *s ) != NULL ) {
3283 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3285 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3287 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3289 *new = ch_strdup( s );