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 */
60 AccessControl *global_acl = NULL;
61 slap_access_t global_default_access = ACL_READ;
62 slap_mask_t global_restrictops = 0;
63 slap_mask_t global_allows = 0;
64 slap_mask_t global_disallows = 0;
65 slap_mask_t global_requires = 0;
66 slap_ssf_set_t global_ssf_set;
68 int global_gentlehup = 0;
69 int global_idletimeout = 0;
70 char *global_host = NULL;
71 char *global_realm = NULL;
72 char *ldap_srvtab = "";
73 char **default_passwd_hash = NULL;
74 int cargc = 0, cargv_size = 0;
76 struct berval default_search_base = { 0, NULL };
77 struct berval default_search_nbase = { 0, NULL };
78 unsigned num_subordinates = 0;
79 struct berval global_schemadn = { 0, NULL };
80 struct berval global_schemandn = { 0, NULL };
82 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
83 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
85 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
86 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
88 char *slapd_pid_file = NULL;
89 char *slapd_args_file = NULL;
91 char *strtok_quote_ptr;
93 int use_reverse_lookup = 0;
96 int slapi_plugins_used = 0;
99 static char *fp_getline(FILE *fp, int *lineno);
100 static void fp_getline_init(int *lineno);
101 static int fp_parse_line(int lineno, char *line);
103 static char *strtok_quote(char *line, char *sep);
104 static int load_ucdata(char *path);
106 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
107 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
110 read_config( const char *fname, int depth )
113 char *line, *savefname, *saveline;
117 struct berval vals[2];
120 static int lastmod = 1;
121 static BackendInfo *bi = NULL;
122 static BackendDB *be = NULL;
124 vals[1].bv_val = NULL;
127 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
128 cargv_size = ARGS_STEP + 1;
131 if ( (fp = fopen( fname, "r" )) == NULL ) {
134 LDAP_LOG( CONFIG, ENTRY,
135 "read_config: " "could not open config file \"%s\": %s (%d)\n",
136 fname, strerror(errno), errno );
138 Debug( LDAP_DEBUG_ANY,
139 "could not open config file \"%s\": %s (%d)\n",
140 fname, strerror(errno), errno );
146 LDAP_LOG( CONFIG, ENTRY,
147 "read_config: reading config file %s\n", fname, 0, 0 );
149 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
153 fp_getline_init( &lineno );
155 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
156 /* skip comments and blank lines */
157 if ( line[0] == '#' || line[0] == '\0' ) {
161 /* fp_parse_line is destructive, we save a copy */
162 saveline = ch_strdup( line );
164 if ( fp_parse_line( lineno, line ) != 0 ) {
170 LDAP_LOG( CONFIG, INFO,
171 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
173 Debug( LDAP_DEBUG_ANY,
174 "%s: line %d: bad config line (ignored)\n",
181 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
184 LDAP_LOG( CONFIG, CRIT,
185 "%s : line %d: missing type in \"backend\" line.\n",
188 Debug( LDAP_DEBUG_ANY,
189 "%s: line %d: missing type in \"backend <type>\" line\n",
198 LDAP_LOG( CONFIG, CRIT,
199 "%s: line %d: backend line must appear before any "
200 "database definition.\n", fname, lineno , 0 );
202 Debug( LDAP_DEBUG_ANY,
203 "%s: line %d: backend line must appear before any database definition\n",
210 bi = backend_info( cargv[1] );
214 LDAP_LOG( CONFIG, CRIT,
215 "read_config: backend %s initialization failed.\n",
218 Debug( LDAP_DEBUG_ANY,
219 "backend %s initialization failed.\n",
225 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
228 LDAP_LOG( CONFIG, CRIT,
229 "%s: line %d: missing type in \"database <type>\" line\n",
232 Debug( LDAP_DEBUG_ANY,
233 "%s: line %d: missing type in \"database <type>\" line\n",
241 be = backend_db_init( cargv[1] );
245 LDAP_LOG( CONFIG, CRIT,
246 "database %s initialization failed.\n", cargv[1], 0, 0 );
248 Debug( LDAP_DEBUG_ANY,
249 "database %s initialization failed.\n",
256 /* set thread concurrency */
257 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
261 LDAP_LOG( CONFIG, CRIT,
262 "%s: line %d: missing level in \"concurrency <level\" "
263 " line\n", fname, lineno, 0 );
265 Debug( LDAP_DEBUG_ANY,
266 "%s: line %d: missing level in \"concurrency <level>\" line\n",
273 c = atoi( cargv[1] );
277 LDAP_LOG( CONFIG, CRIT,
278 "%s: line %d: invalid level (%d) in "
279 "\"concurrency <level>\" line.\n", fname, lineno, c );
281 Debug( LDAP_DEBUG_ANY,
282 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
289 ldap_pvt_thread_set_concurrency( c );
291 /* set sockbuf max */
292 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
296 LDAP_LOG( CONFIG, CRIT,
297 "%s: line %d: missing max in \"sockbuf_max_incoming "
298 "<bytes>\" line\n", fname, lineno, 0 );
300 Debug( LDAP_DEBUG_ANY,
301 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
308 max = atol( cargv[1] );
312 LDAP_LOG( CONFIG, CRIT,
313 "%s: line %d: invalid max value (%ld) in "
314 "\"sockbuf_max_incoming <bytes>\" line.\n",
315 fname, lineno, max );
317 Debug( LDAP_DEBUG_ANY,
318 "%s: line %d: invalid max value (%ld) in "
319 "\"sockbuf_max_incoming <bytes>\" line.\n",
320 fname, lineno, max );
326 sockbuf_max_incoming = max;
328 /* set sockbuf max authenticated */
329 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
333 LDAP_LOG( CONFIG, CRIT,
334 "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
335 "<bytes>\" line\n", fname, lineno, 0 );
337 Debug( LDAP_DEBUG_ANY,
338 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
345 max = atol( cargv[1] );
349 LDAP_LOG( CONFIG, CRIT,
350 "%s: line %d: invalid max value (%ld) in "
351 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
352 fname, lineno, max );
354 Debug( LDAP_DEBUG_ANY,
355 "%s: line %d: invalid max value (%ld) in "
356 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
357 fname, lineno, max );
363 sockbuf_max_incoming_auth = max;
365 /* set conn pending max */
366 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
370 LDAP_LOG( CONFIG, CRIT,
371 "%s: line %d: missing max in \"conn_max_pending "
372 "<requests>\" line\n", fname, lineno, 0 );
374 Debug( LDAP_DEBUG_ANY,
375 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
382 max = atol( cargv[1] );
386 LDAP_LOG( CONFIG, CRIT,
387 "%s: line %d: invalid max value (%ld) in "
388 "\"conn_max_pending <requests>\" line.\n",
389 fname, lineno, max );
391 Debug( LDAP_DEBUG_ANY,
392 "%s: line %d: invalid max value (%ld) in "
393 "\"conn_max_pending <requests>\" line.\n",
394 fname, lineno, max );
400 slap_conn_max_pending = max;
402 /* set conn pending max authenticated */
403 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
407 LDAP_LOG( CONFIG, CRIT,
408 "%s: line %d: missing max in \"conn_max_pending_auth "
409 "<requests>\" line\n", fname, lineno, 0 );
411 Debug( LDAP_DEBUG_ANY,
412 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
419 max = atol( cargv[1] );
423 LDAP_LOG( CONFIG, CRIT,
424 "%s: line %d: invalid max value (%ld) in "
425 "\"conn_max_pending_auth <requests>\" line.\n",
426 fname, lineno, max );
428 Debug( LDAP_DEBUG_ANY,
429 "%s: line %d: invalid max value (%ld) in "
430 "\"conn_max_pending_auth <requests>\" line.\n",
431 fname, lineno, max );
437 slap_conn_max_pending_auth = max;
439 /* default search base */
440 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
443 LDAP_LOG( CONFIG, CRIT,
444 "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
445 "line\n", fname, lineno, 0 );
447 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
448 "missing dn in \"defaultSearchBase <dn>\" line\n",
454 } else if ( cargc > 2 ) {
456 LDAP_LOG( CONFIG, INFO,
457 "%s: line %d: extra cruft after <dn> in "
458 "\"defaultSearchBase %s\" line (ignored)\n",
459 fname, lineno, cargv[1] );
461 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
462 "extra cruft after <dn> in \"defaultSearchBase %s\", "
464 fname, lineno, cargv[1] );
468 if ( bi != NULL || be != NULL ) {
470 LDAP_LOG( CONFIG, CRIT,
471 "%s: line %d: defaultSearchBase line must appear "
472 "prior to any backend or database definitions\n",
475 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
476 "defaultSearchBaase line must appear prior to "
477 "any backend or database definition\n",
484 if ( default_search_nbase.bv_len ) {
486 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
487 "default search base \"%s\" already defined "
488 "(discarding old)\n", fname, lineno,
489 default_search_base.bv_val );
491 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
492 "default search base \"%s\" already defined "
493 "(discarding old)\n",
494 fname, lineno, default_search_base.bv_val );
497 free( default_search_base.bv_val );
498 free( default_search_nbase.bv_val );
501 if ( load_ucdata( NULL ) < 0 ) return 1;
506 dn.bv_val = cargv[1];
507 dn.bv_len = strlen( dn.bv_val );
509 rc = dnPrettyNormal( NULL, &dn,
510 &default_search_base,
511 &default_search_nbase, NULL );
513 if( rc != LDAP_SUCCESS ) {
515 LDAP_LOG( CONFIG, CRIT,
516 "%s: line %d: defaultSearchBase DN is invalid.\n",
519 Debug( LDAP_DEBUG_ANY,
520 "%s: line %d: defaultSearchBase DN is invalid\n",
527 /* set maximum threads in thread pool */
528 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
532 LDAP_LOG( CONFIG, CRIT,
533 "%s: line %d: missing count in \"threads <count>\" line\n",
536 Debug( LDAP_DEBUG_ANY,
537 "%s: line %d: missing count in \"threads <count>\" line\n",
544 c = atoi( cargv[1] );
548 LDAP_LOG( CONFIG, CRIT,
549 "%s: line %d: invalid level (%d) in \"threads <count>\""
550 "line\n", fname, lineno, c );
552 Debug( LDAP_DEBUG_ANY,
553 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
560 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
562 /* save for later use */
563 connection_pool_max = c;
565 /* get pid file name */
566 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
569 LDAP_LOG( CONFIG, CRIT,
570 "%s: line %d missing file name in \"pidfile <file>\" "
571 "line.\n", fname, lineno, 0 );
573 Debug( LDAP_DEBUG_ANY,
574 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
581 slapd_pid_file = ch_strdup( cargv[1] );
583 /* get args file name */
584 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
587 LDAP_LOG( CONFIG, CRIT,
588 "%s: %d: missing file name in "
589 "\"argsfile <file>\" line.\n",
592 Debug( LDAP_DEBUG_ANY,
593 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
600 slapd_args_file = ch_strdup( cargv[1] );
602 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
605 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
608 /* default password hash */
609 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
612 LDAP_LOG( CONFIG, CRIT,
613 "%s: line %d: missing hash in "
614 "\"password-hash <hash>\" line.\n",
617 Debug( LDAP_DEBUG_ANY,
618 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
624 if ( default_passwd_hash != NULL ) {
626 LDAP_LOG( CONFIG, CRIT,
627 "%s: line %d: already set default password_hash!\n",
630 Debug( LDAP_DEBUG_ANY,
631 "%s: line %d: already set default password_hash!\n",
638 for(i = 1; i < cargc; i++) {
639 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
641 LDAP_LOG( CONFIG, CRIT,
642 "%s: line %d: password scheme \"%s\" not available\n",
643 fname, lineno, cargv[i] );
645 Debug( LDAP_DEBUG_ANY,
646 "%s: line %d: password scheme \"%s\" not available\n",
647 fname, lineno, cargv[i] );
650 ldap_charray_add( &default_passwd_hash, cargv[i] );
653 if( !default_passwd_hash ) {
655 LDAP_LOG( CONFIG, CRIT,
656 "%s: line %d: no valid hashes found\n",
659 Debug( LDAP_DEBUG_ANY,
660 "%s: line %d: no valid hashes found\n",
666 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
670 LDAP_LOG( CONFIG, CRIT,
671 "%s: line %d: missing format in "
672 "\"password-crypt-salt-format <format>\" line\n",
675 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
676 "\"password-crypt-salt-format <format>\" line\n",
683 lutil_salt_format( cargv[1] );
685 /* SASL config options */
686 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
687 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
689 #ifdef SLAP_X_SASL_REWRITE
690 /* use authid rewrite instead of sasl regexp */
691 } else if ( strncasecmp( cargv[0], "authid-rewrite", sizeof("authid-rewrite") - 1 ) == 0 ) {
692 int rc = slap_sasl_rewrite_config( fname, lineno,
697 #endif /* SLAP_X_SASL_REWRITE */
699 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
703 LDAP_LOG( CONFIG, CRIT,
704 "%s: line %d: missing dn in "
705 "\"schemadn <dn>\" line.\n", fname, lineno, 0 );
707 Debug( LDAP_DEBUG_ANY,
708 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
713 ber_str2bv( cargv[1], 0, 0, &dn );
715 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
716 &be->be_schemandn, NULL );
718 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
719 &global_schemandn, NULL );
721 if ( rc != LDAP_SUCCESS ) {
723 LDAP_LOG( CONFIG, CRIT,
724 "%s: line %d: schemadn DN is invalid.\n",
727 Debug( LDAP_DEBUG_ANY,
728 "%s: line %d: schemadn DN is invalid\n",
734 /* set UCDATA path */
735 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
739 LDAP_LOG( CONFIG, CRIT,
740 "%s: line %d: missing path in "
741 "\"ucdata-path <path>\" line.\n", fname, lineno, 0 );
743 Debug( LDAP_DEBUG_ANY,
744 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
751 err = load_ucdata( cargv[1] );
755 LDAP_LOG( CONFIG, CRIT,
756 "%s: line %d: ucdata already loaded, ucdata-path "
757 "must be set earlier in the file and/or be "
758 "specified only once!\n", fname, lineno, 0 );
760 Debug( LDAP_DEBUG_ANY,
761 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
770 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
772 struct slap_limits_set *lim;
776 LDAP_LOG( CONFIG, CRIT,
777 "%s: line %d: missing limit in \"sizelimit <limit>\" "
778 "line.\n", fname, lineno, 0 );
780 Debug( LDAP_DEBUG_ANY,
781 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
791 lim = &be->be_def_limit;
794 for ( i = 1; i < cargc; i++ ) {
795 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
796 rc = limits_parse_one( cargv[i], lim );
799 LDAP_LOG( CONFIG, CRIT,
800 "%s: line %d: unable "
801 "to parse value \"%s\" in \"sizelimit "
802 "<limit>\" line.\n", fname, lineno, cargv[i] );
804 Debug( LDAP_DEBUG_ANY,
805 "%s: line %d: unable "
806 "to parse value \"%s\" "
809 fname, lineno, cargv[i] );
815 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
816 lim->lms_s_soft = -1;
820 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
821 if ( next == cargv[i] ) {
823 LDAP_LOG( CONFIG, CRIT,
824 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
825 "line.\n", fname, lineno, cargv[i] );
827 Debug( LDAP_DEBUG_ANY,
828 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
829 fname, lineno, cargv[i] );
833 } else if ( next[0] != '\0' ) {
835 LDAP_LOG( CONFIG, CRIT,
836 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
837 "line ignored.\n", fname, lineno, next );
839 Debug( LDAP_DEBUG_ANY,
840 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
841 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 );
929 /* set regex-based limits */
930 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
933 LDAP_LOG( CONFIG, WARNING,
934 "%s: line %d \"limits\" allowed only in database "
935 "environment.\n", fname, lineno, 0 );
937 Debug( LDAP_DEBUG_ANY,
938 "%s: line %d \"limits\" allowed only in database environment.\n%s",
944 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
948 /* mark this as a subordinate database */
949 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
952 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
953 "subordinate keyword must appear inside a database "
954 "definition.\n", fname, lineno, 0 );
956 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
957 "must appear inside a database definition.\n",
963 be->be_flags |= SLAP_BFLAG_GLUE_SUBORDINATE;
967 /* add an overlay to this backend */
968 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
971 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
972 "overlay keyword must appear inside a database "
973 "definition.\n", fname, lineno, 0 );
975 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
976 "must appear inside a database definition.\n",
981 } else if ( overlay_config( be, cargv[1] )) {
985 /* set database suffix */
986 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
988 struct berval dn, pdn, ndn;
992 LDAP_LOG( CONFIG, CRIT,
993 "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
996 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
997 "missing dn in \"suffix <dn>\" line\n",
1003 } else if ( cargc > 2 ) {
1005 LDAP_LOG( CONFIG, INFO,
1006 "%s: line %d: extra cruft after <dn> in \"suffix %s\""
1007 " line (ignored).\n", fname, lineno, cargv[1] );
1009 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
1010 "after <dn> in \"suffix %s\" line (ignored)\n",
1011 fname, lineno, cargv[1] );
1017 LDAP_LOG( CONFIG, INFO,
1018 "%s: line %d: suffix line must appear inside a database "
1019 "definition.\n", fname, lineno, 0 );
1021 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
1022 "must appear inside a database definition\n",
1027 #if defined(SLAPD_MONITOR_DN)
1028 /* "cn=Monitor" is reserved for monitoring slap */
1029 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
1031 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
1032 "%s\" is reserved for monitoring slapd\n",
1033 fname, lineno, SLAPD_MONITOR_DN );
1035 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
1036 "%s\" is reserved for monitoring slapd\n",
1037 fname, lineno, SLAPD_MONITOR_DN );
1040 #endif /* SLAPD_MONITOR_DN */
1043 if ( load_ucdata( NULL ) < 0 ) return 1;
1045 dn.bv_val = cargv[1];
1046 dn.bv_len = strlen( cargv[1] );
1048 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1049 if( rc != LDAP_SUCCESS ) {
1051 LDAP_LOG( CONFIG, CRIT,
1052 "%s: line %d: suffix DN is invalid.\n",
1055 Debug( LDAP_DEBUG_ANY,
1056 "%s: line %d: suffix DN is invalid\n",
1062 tmp_be = select_backend( &ndn, 0, 0 );
1063 if ( tmp_be == be ) {
1065 LDAP_LOG( CONFIG, INFO,
1066 "%s: line %d: suffix already served by this backend "
1067 "(ignored)\n", fname, lineno, 0 );
1069 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1070 "already served by this backend (ignored)\n",
1076 } else if ( tmp_be != NULL ) {
1078 LDAP_LOG( CONFIG, INFO,
1079 "%s: line %d: suffix already served by a preceding "
1080 "backend \"%s\"\n", fname, lineno,
1081 tmp_be->be_suffix[0].bv_val );
1083 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1084 "already served by a preceeding backend \"%s\"\n",
1085 fname, lineno, tmp_be->be_suffix[0].bv_val );
1091 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1093 LDAP_LOG( CONFIG, INFO,
1094 "%s: line %d: suffix DN empty and default search "
1095 "base provided \"%s\" (assuming okay).\n",
1096 fname, lineno, default_search_base.bv_val );
1098 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1099 "suffix DN empty and default "
1100 "search base provided \"%s\" (assuming okay)\n",
1101 fname, lineno, default_search_base.bv_val );
1105 ber_bvarray_add( &be->be_suffix, &pdn );
1106 ber_bvarray_add( &be->be_nsuffix, &ndn );
1108 /* set max deref depth */
1109 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1113 LDAP_LOG( CONFIG, CRIT,
1114 "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1115 " line\n", fname, lineno, 0 );
1117 Debug( LDAP_DEBUG_ANY,
1118 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1126 LDAP_LOG( CONFIG, INFO,
1127 "%s: line %d: depth line must appear inside a database "
1128 "definition.\n", fname, lineno ,0 );
1130 Debug( LDAP_DEBUG_ANY,
1131 "%s: line %d: depth line must appear inside a database definition.\n",
1136 } else if ((i = atoi(cargv[1])) < 0) {
1138 LDAP_LOG( CONFIG, INFO,
1139 "%s: line %d: depth must be positive.\n",
1142 Debug( LDAP_DEBUG_ANY,
1143 "%s: line %d: depth must be positive.\n",
1150 be->be_max_deref_depth = i;
1154 /* set magic "root" dn for this database */
1155 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1158 LDAP_LOG( CONFIG, INFO,
1159 "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1162 Debug( LDAP_DEBUG_ANY,
1163 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1172 LDAP_LOG( CONFIG, INFO,
1173 "%s: line %d: rootdn line must appear inside a database "
1174 "definition.\n", fname, lineno ,0 );
1176 Debug( LDAP_DEBUG_ANY,
1177 "%s: line %d: rootdn line must appear inside a database definition.\n",
1185 if ( load_ucdata( NULL ) < 0 ) return 1;
1187 dn.bv_val = cargv[1];
1188 dn.bv_len = strlen( cargv[1] );
1190 rc = dnPrettyNormal( NULL, &dn,
1192 &be->be_rootndn, NULL );
1194 if( rc != LDAP_SUCCESS ) {
1196 LDAP_LOG( CONFIG, CRIT,
1197 "%s: line %d: rootdn DN is invalid.\n",
1200 Debug( LDAP_DEBUG_ANY,
1201 "%s: line %d: rootdn DN is invalid\n",
1208 /* set super-secret magic database password */
1209 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1212 LDAP_LOG( CONFIG, CRIT,
1213 "%s: line %d: missing passwd in \"rootpw <passwd>\""
1214 " line\n", fname, lineno ,0 );
1216 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1217 "missing passwd in \"rootpw <passwd>\" line\n",
1226 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1227 "rootpw line must appear inside a database "
1228 "definition.\n", fname, lineno ,0 );
1230 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1231 "rootpw line must appear inside a database "
1238 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1240 if( tmp_be != be ) {
1242 LDAP_LOG( CONFIG, INFO,
1244 "rootpw can only be set when rootdn is under suffix\n",
1245 fname, lineno, "" );
1247 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1248 "rootpw can only be set when rootdn is under suffix\n",
1254 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1255 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1258 /* make this database read-only */
1259 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1262 LDAP_LOG( CONFIG, CRIT,
1263 "%s: line %d: missing on|off in \"readonly <on|off>\" "
1264 "line.\n", fname, lineno ,0 );
1266 Debug( LDAP_DEBUG_ANY,
1267 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1274 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1275 global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1277 global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1280 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1281 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1283 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1288 /* allow these features */
1289 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1290 strcasecmp( cargv[0], "allow" ) == 0 )
1296 LDAP_LOG( CONFIG, INFO,
1297 "%s: line %d: allow line must appear prior to "
1298 "database definitions.\n", fname, lineno ,0 );
1300 Debug( LDAP_DEBUG_ANY,
1301 "%s: line %d: allow line must appear prior to database definitions\n",
1309 LDAP_LOG( CONFIG, CRIT,
1310 "%s: line %d: missing feature(s) in \"allow <features>\""
1311 " line\n", fname, lineno ,0 );
1313 Debug( LDAP_DEBUG_ANY,
1314 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1323 for( i=1; i < cargc; i++ ) {
1324 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1325 allows |= SLAP_ALLOW_BIND_V2;
1327 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1328 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1330 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1331 allows |= SLAP_ALLOW_BIND_ANON_DN;
1333 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1334 allows |= SLAP_ALLOW_UPDATE_ANON;
1336 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1338 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1339 "unknown feature %s in \"allow <features>\" line.\n",
1340 fname, lineno, cargv[1] );
1342 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1343 "unknown feature %s in \"allow <features>\" line\n",
1344 fname, lineno, cargv[i] );
1351 global_allows = allows;
1353 /* disallow these features */
1354 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1355 strcasecmp( cargv[0], "disallow" ) == 0 )
1357 slap_mask_t disallows;
1361 LDAP_LOG( CONFIG, INFO,
1362 "%s: line %d: disallow line must appear prior to "
1363 "database definitions.\n", fname, lineno ,0 );
1365 Debug( LDAP_DEBUG_ANY,
1366 "%s: line %d: disallow line must appear prior to database definitions\n",
1374 LDAP_LOG( CONFIG, CRIT,
1375 "%s: line %d: missing feature(s) in \"disallow <features>\""
1376 " line.\n", fname, lineno ,0 );
1378 Debug( LDAP_DEBUG_ANY,
1379 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1388 for( i=1; i < cargc; i++ ) {
1389 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1390 disallows |= SLAP_DISALLOW_BIND_ANON;
1392 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1393 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1395 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1396 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1398 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1399 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1401 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1402 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1404 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1406 LDAP_LOG( CONFIG, CRIT,
1407 "%s: line %d: unknown feature %s in "
1408 "\"disallow <features>\" line.\n",
1409 fname, lineno, cargv[i] );
1411 Debug( LDAP_DEBUG_ANY,
1412 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1413 fname, lineno, cargv[i] );
1420 global_disallows = disallows;
1422 /* require these features */
1423 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1424 strcasecmp( cargv[0], "require" ) == 0 )
1426 slap_mask_t requires;
1430 LDAP_LOG( CONFIG, CRIT,
1431 "%s: line %d: missing feature(s) in "
1432 "\"require <features>\" line.\n", fname, lineno ,0 );
1434 Debug( LDAP_DEBUG_ANY,
1435 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1444 for( i=1; i < cargc; i++ ) {
1445 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1446 requires |= SLAP_REQUIRE_BIND;
1448 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1449 requires |= SLAP_REQUIRE_LDAP_V3;
1451 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1452 requires |= SLAP_REQUIRE_AUTHC;
1454 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1455 requires |= SLAP_REQUIRE_SASL;
1457 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1458 requires |= SLAP_REQUIRE_STRONG;
1460 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1462 LDAP_LOG( CONFIG, CRIT,
1463 "%s: line %d: unknown feature %s in "
1464 "\"require <features>\" line.\n",
1465 fname, lineno , cargv[i] );
1467 Debug( LDAP_DEBUG_ANY,
1468 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1469 fname, lineno, cargv[i] );
1477 global_requires = requires;
1479 be->be_requires = requires;
1482 /* required security factors */
1483 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1484 slap_ssf_set_t *set;
1488 LDAP_LOG( CONFIG, CRIT,
1489 "%s: line %d: missing factor(s) in \"security <factors>\""
1490 " line.\n", fname, lineno ,0 );
1492 Debug( LDAP_DEBUG_ANY,
1493 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1501 set = &global_ssf_set;
1503 set = &be->be_ssf_set;
1506 for( i=1; i < cargc; i++ ) {
1507 if( strncasecmp( cargv[i], "ssf=",
1508 sizeof("ssf") ) == 0 )
1511 atoi( &cargv[i][sizeof("ssf")] );
1513 } else if( strncasecmp( cargv[i], "transport=",
1514 sizeof("transport") ) == 0 )
1516 set->sss_transport =
1517 atoi( &cargv[i][sizeof("transport")] );
1519 } else if( strncasecmp( cargv[i], "tls=",
1520 sizeof("tls") ) == 0 )
1523 atoi( &cargv[i][sizeof("tls")] );
1525 } else if( strncasecmp( cargv[i], "sasl=",
1526 sizeof("sasl") ) == 0 )
1529 atoi( &cargv[i][sizeof("sasl")] );
1531 } else if( strncasecmp( cargv[i], "update_ssf=",
1532 sizeof("update_ssf") ) == 0 )
1534 set->sss_update_ssf =
1535 atoi( &cargv[i][sizeof("update_ssf")] );
1537 } else if( strncasecmp( cargv[i], "update_transport=",
1538 sizeof("update_transport") ) == 0 )
1540 set->sss_update_transport =
1541 atoi( &cargv[i][sizeof("update_transport")] );
1543 } else if( strncasecmp( cargv[i], "update_tls=",
1544 sizeof("update_tls") ) == 0 )
1546 set->sss_update_tls =
1547 atoi( &cargv[i][sizeof("update_tls")] );
1549 } else if( strncasecmp( cargv[i], "update_sasl=",
1550 sizeof("update_sasl") ) == 0 )
1552 set->sss_update_sasl =
1553 atoi( &cargv[i][sizeof("update_sasl")] );
1555 } else if( strncasecmp( cargv[i], "simple_bind=",
1556 sizeof("simple_bind") ) == 0 )
1558 set->sss_simple_bind =
1559 atoi( &cargv[i][sizeof("simple_bind")] );
1563 LDAP_LOG( CONFIG, CRIT,
1564 "%s: line %d: unknown factor %S in "
1565 "\"security <factors>\" line.\n",
1566 fname, lineno, cargv[1] );
1568 Debug( LDAP_DEBUG_ANY,
1569 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1570 fname, lineno, cargv[i] );
1576 /* where to send clients when we don't hold it */
1577 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1580 LDAP_LOG( CONFIG, CRIT,
1581 "%s: line %d: missing URL in \"referral <URL>\""
1582 " line.\n", fname, lineno , 0 );
1584 Debug( LDAP_DEBUG_ANY,
1585 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1592 if( validate_global_referral( cargv[1] ) ) {
1594 LDAP_LOG( CONFIG, CRIT,
1595 "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1596 fname, lineno, cargv[1] );
1598 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1599 "invalid URL (%s) in \"referral\" line.\n",
1600 fname, lineno, cargv[1] );
1605 vals[0].bv_val = cargv[1];
1606 vals[0].bv_len = strlen( vals[0].bv_val );
1607 if( value_add( &default_referral, vals ) )
1611 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1615 LDAP_LOG( CONFIG, CRIT,
1616 "%s: line %d: Error in logfile directive, "
1617 "\"logfile <filename>\"\n", fname, lineno , 0 );
1619 Debug( LDAP_DEBUG_ANY,
1620 "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1626 logfile = fopen( cargv[1], "w" );
1627 if ( logfile != NULL ) lutil_debug_file( logfile );
1630 /* start of a new database definition */
1631 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1635 LDAP_LOG( CONFIG, CRIT,
1636 "%s: line %d: Error in debug directive, "
1637 "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1639 Debug( LDAP_DEBUG_ANY,
1640 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1646 level = atoi( cargv[2] );
1647 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1648 lutil_set_debug_level( cargv[1], level );
1649 /* specify an Object Identifier macro */
1650 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1651 rc = parse_oidm( fname, lineno, cargc, cargv );
1654 /* specify an objectclass */
1655 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1658 LDAP_LOG( CONFIG, INFO,
1659 "%s: line %d: illegal objectclass format.\n",
1660 fname, lineno , 0 );
1662 Debug( LDAP_DEBUG_ANY,
1663 "%s: line %d: illegal objectclass format.\n",
1668 } else if ( *cargv[1] == '(' /*')'*/) {
1670 p = strchr(saveline,'(' /*')'*/);
1671 rc = parse_oc( fname, lineno, p, cargv );
1676 LDAP_LOG( CONFIG, INFO,
1677 "%s: line %d: old objectclass format not supported\n",
1678 fname, lineno , 0 );
1680 Debug( LDAP_DEBUG_ANY,
1681 "%s: line %d: old objectclass format not supported.\n",
1686 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1688 p = strchr(saveline,'(' /*')'*/);
1689 rc = parse_cr( fname, lineno, p, cargv );
1692 /* specify an attribute type */
1693 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1694 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1698 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1699 "illegal attribute type format.\n",
1700 fname, lineno , 0 );
1702 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1703 "illegal attribute type format.\n",
1708 } else if ( *cargv[1] == '(' /*')'*/) {
1710 p = strchr(saveline,'(' /*')'*/);
1711 rc = parse_at( fname, lineno, p, cargv );
1716 LDAP_LOG( CONFIG, INFO,
1717 "%s: line %d: old attribute type format not supported.\n",
1718 fname, lineno , 0 );
1720 Debug( LDAP_DEBUG_ANY,
1721 "%s: line %d: old attribute type format not supported.\n",
1727 /* define attribute option(s) */
1728 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1729 ad_define_option( NULL, NULL, 0 );
1730 for ( i = 1; i < cargc; i++ )
1731 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1734 /* turn on/off schema checking */
1735 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1738 LDAP_LOG( CONFIG, CRIT,
1739 "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1740 " line.\n", fname, lineno , 0 );
1742 Debug( LDAP_DEBUG_ANY,
1743 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1749 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1751 LDAP_LOG( CONFIG, CRIT,
1752 "%s: line %d: schema checking disabled! your mileage may "
1753 "vary!\n", fname, lineno , 0 );
1755 Debug( LDAP_DEBUG_ANY,
1756 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1759 global_schemacheck = 0;
1761 global_schemacheck = 1;
1764 /* specify access control info */
1765 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1766 parse_acl( be, fname, lineno, cargc, cargv );
1768 /* debug level to log things to syslog */
1769 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1772 LDAP_LOG( CONFIG, CRIT,
1773 "%s: line %d: missing level in \"loglevel <level>\""
1774 " line.\n", fname, lineno , 0 );
1776 Debug( LDAP_DEBUG_ANY,
1777 "%s: line %d: missing level in \"loglevel <level>\" line\n",
1786 for( i=1; i < cargc; i++ ) {
1787 ldap_syslog += atoi( cargv[1] );
1790 /* list of sync replication information in this backend (slave only) */
1791 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1795 LDAP_LOG( CONFIG, INFO,
1796 "%s: line %d: syncrepl line must appear inside "
1797 "a database definition.\n", fname, lineno, 0);
1799 Debug( LDAP_DEBUG_ANY,
1800 "%s: line %d: syncrepl line must appear inside "
1801 "a database definition.\n", fname, lineno, 0);
1805 if ( add_syncrepl( be, cargv, cargc )) {
1810 /* list of replicas of the data in this backend (master only) */
1811 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1814 LDAP_LOG( CONFIG, CRIT,
1815 "%s: line %d: missing host or uri in \"replica "
1816 " <host[:port]\" line\n", fname, lineno , 0 );
1818 Debug( LDAP_DEBUG_ANY,
1819 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1827 LDAP_LOG( CONFIG, INFO,
1828 "%s: line %d: replica line must appear inside "
1829 "a database definition.\n", fname, lineno, 0);
1831 Debug( LDAP_DEBUG_ANY,
1832 "%s: line %d: replica line must appear inside a database definition\n",
1840 for ( i = 1; i < cargc; i++ ) {
1841 if ( strncasecmp( cargv[i], "host=", 5 )
1843 nr = add_replica_info( be,
1846 } else if (strncasecmp( cargv[i], "uri=", 4 )
1848 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1851 LDAP_LOG( CONFIG, INFO,
1852 "%s: line %d: replica line contains invalid "
1853 "uri definition.\n", fname, lineno, 0);
1855 Debug( LDAP_DEBUG_ANY,
1856 "%s: line %d: replica line contains invalid "
1857 "uri definition.\n", fname, lineno, 0);
1861 if (ludp->lud_host == NULL ) {
1863 LDAP_LOG( CONFIG, INFO,
1864 "%s: line %d: replica line contains invalid "
1865 "uri definition - missing hostname.\n",
1868 Debug( LDAP_DEBUG_ANY,
1869 "%s: line %d: replica line contains invalid "
1870 "uri definition - missing hostname.\n", fname, lineno, 0);
1874 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1875 if ( replicahost == NULL ) {
1877 LDAP_LOG( CONFIG, ERR,
1878 "out of memory in read_config\n", 0, 0,0 );
1880 Debug( LDAP_DEBUG_ANY,
1881 "out of memory in read_config\n", 0, 0, 0 );
1883 ldap_free_urldesc( ludp );
1884 exit( EXIT_FAILURE );
1886 sprintf(replicahost, "%s:%d",
1887 ludp->lud_host, ludp->lud_port);
1888 nr = add_replica_info( be, replicahost );
1889 ldap_free_urldesc( ludp );
1890 ch_free(replicahost);
1896 LDAP_LOG( CONFIG, INFO,
1897 "%s: line %d: missing host or uri in \"replica\" line\n",
1898 fname, lineno , 0 );
1900 Debug( LDAP_DEBUG_ANY,
1901 "%s: line %d: missing host or uri in \"replica\" line\n",
1906 } else if ( nr == -1 ) {
1908 LDAP_LOG( CONFIG, INFO,
1909 "%s: line %d: unable to add"
1910 " replica \"%s\"\n",
1914 Debug( LDAP_DEBUG_ANY,
1915 "%s: line %d: unable to add replica \"%s\"\n",
1916 fname, lineno, cargv[i] + 5 );
1920 for ( i = 1; i < cargc; i++ ) {
1921 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1923 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1926 LDAP_LOG( CONFIG, INFO,
1927 "%s: line %d: suffix \"%s\" in \"replica\""
1928 " line is not valid for backend(ignored)\n",
1929 fname, lineno, cargv[i] + 7 );
1931 Debug( LDAP_DEBUG_ANY,
1932 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1933 fname, lineno, cargv[i] + 7 );
1939 LDAP_LOG( CONFIG, INFO,
1940 "%s: line %d: unable to normalize suffix"
1941 " in \"replica\" line (ignored)\n",
1942 fname, lineno , 0 );
1944 Debug( LDAP_DEBUG_ANY,
1945 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1951 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1953 char *arg = cargv[i] + 4;
1955 if ( arg[0] == '!' ) {
1960 if ( arg[0] != '=' ) {
1964 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1966 LDAP_LOG( CONFIG, INFO,
1967 "%s: line %d: attribute \"%s\" in "
1968 "\"replica\" line is unknown\n",
1969 fname, lineno, arg + 1 );
1971 Debug( LDAP_DEBUG_ANY,
1972 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1973 fname, lineno, arg + 1 );
1982 /* dn of slave entity allowed to write to replica */
1983 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1986 LDAP_LOG( CONFIG, CRIT,
1987 "%s: line %d: missing dn in \"updatedn <dn>\""
1988 " line.\n", fname, lineno , 0 );
1990 Debug( LDAP_DEBUG_ANY,
1991 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1999 LDAP_LOG( CONFIG, INFO,
2000 "%s: line %d: updatedn line must appear inside "
2001 "a database definition\n",
2002 fname, lineno , 0 );
2004 Debug( LDAP_DEBUG_ANY,
2005 "%s: line %d: updatedn line must appear inside a database definition\n",
2013 if ( load_ucdata( NULL ) < 0 ) return 1;
2015 dn.bv_val = cargv[1];
2016 dn.bv_len = strlen( cargv[1] );
2018 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2019 if( rc != LDAP_SUCCESS ) {
2021 LDAP_LOG( CONFIG, CRIT,
2022 "%s: line %d: updatedn DN is invalid.\n",
2023 fname, lineno , 0 );
2025 Debug( LDAP_DEBUG_ANY,
2026 "%s: line %d: updatedn DN is invalid\n",
2033 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2036 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2037 "missing url in \"updateref <ldapurl>\" line.\n",
2038 fname, lineno , 0 );
2040 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2041 "missing url in \"updateref <ldapurl>\" line\n",
2049 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2050 " line must appear inside a database definition\n",
2051 fname, lineno , 0 );
2053 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2054 " line must appear inside a database definition\n",
2059 } else if ( !be->be_update_ndn.bv_len ) {
2061 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2062 "updateref line must come after updatedn.\n",
2063 fname, lineno , 0 );
2065 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2066 "updateref line must after updatedn.\n",
2072 if( validate_global_referral( cargv[1] ) ) {
2074 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2075 "invalid URL (%s) in \"updateref\" line.\n",
2076 fname, lineno, cargv[1] );
2078 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2079 "invalid URL (%s) in \"updateref\" line.\n",
2080 fname, lineno, cargv[1] );
2085 vals[0].bv_val = cargv[1];
2086 vals[0].bv_len = strlen( vals[0].bv_val );
2087 if( value_add( &be->be_update_refs, vals ) )
2090 /* replication log file to which changes are appended */
2091 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2094 LDAP_LOG( CONFIG, CRIT,
2095 "%s: line %d: missing filename in \"replogfile <filename>\""
2096 " line.\n", fname, lineno , 0 );
2098 Debug( LDAP_DEBUG_ANY,
2099 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2106 be->be_replogfile = ch_strdup( cargv[1] );
2108 replogfile = ch_strdup( cargv[1] );
2111 /* file from which to read additional rootdse attrs */
2112 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2115 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2116 "missing filename in \"rootDSE <filename>\" line.\n",
2117 fname, lineno , 0 );
2119 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2120 "missing filename in \"rootDSE <filename>\" line.\n",
2126 if( read_root_dse_file( cargv[1] ) ) {
2128 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2129 "could not read \"rootDSE <filename>\" line.\n",
2130 fname, lineno , 0 );
2132 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2133 "could not read \"rootDSE <filename>\" line\n",
2139 /* maintain lastmodified{by,time} attributes */
2140 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2143 LDAP_LOG( CONFIG, CRIT,
2144 "%s: line %d: missing on|off in \"lastmod <on|off>\""
2145 " line.\n", fname, lineno , 0 );
2147 Debug( LDAP_DEBUG_ANY,
2148 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2154 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2156 be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
2162 be->be_flags |= SLAP_BFLAG_NOLASTMOD;
2169 /* turn on/off gentle SIGHUP handling */
2170 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2172 Debug( LDAP_DEBUG_ANY,
2173 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2177 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2178 global_gentlehup = 0;
2180 global_gentlehup = 1;
2184 /* set idle timeout value */
2185 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2189 LDAP_LOG( CONFIG, CRIT,
2190 "%s: line %d: missing timeout value in "
2191 "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2193 Debug( LDAP_DEBUG_ANY,
2194 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2201 i = atoi( cargv[1] );
2205 LDAP_LOG( CONFIG, CRIT,
2206 "%s: line %d: timeout value (%d) invalid "
2207 "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2209 Debug( LDAP_DEBUG_ANY,
2210 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2217 global_idletimeout = i;
2219 /* include another config file */
2220 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2223 LDAP_LOG( CONFIG, CRIT,
2224 "%s: line %d: missing filename in \"include "
2225 "<filename>\" line.\n", fname, lineno , 0 );
2227 Debug( LDAP_DEBUG_ANY,
2228 "%s: line %d: missing filename in \"include <filename>\" line\n",
2234 savefname = ch_strdup( cargv[1] );
2235 savelineno = lineno;
2237 if ( read_config( savefname, depth+1 ) != 0 ) {
2242 lineno = savelineno - 1;
2244 /* location of kerberos srvtab file */
2245 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2248 LDAP_LOG( CONFIG, CRIT,
2249 "%s: line %d: missing filename in \"srvtab "
2250 "<filename>\" line.\n", fname, lineno , 0 );
2252 Debug( LDAP_DEBUG_ANY,
2253 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2259 ldap_srvtab = ch_strdup( cargv[1] );
2261 #ifdef SLAPD_MODULES
2262 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2265 LDAP_LOG( CONFIG, INFO,
2266 "%s: line %d: missing filename in \"moduleload "
2267 "<filename>\" line.\n", fname, lineno , 0 );
2269 Debug( LDAP_DEBUG_ANY,
2270 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2274 exit( EXIT_FAILURE );
2276 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2278 LDAP_LOG( CONFIG, CRIT,
2279 "%s: line %d: failed to load or initialize module %s\n",
2280 fname, lineno, cargv[1] );
2282 Debug( LDAP_DEBUG_ANY,
2283 "%s: line %d: failed to load or initialize module %s\n",
2284 fname, lineno, cargv[1]);
2287 exit( EXIT_FAILURE );
2289 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2292 LDAP_LOG( CONFIG, INFO,
2293 "%s: line %d: missing path in \"modulepath <path>\""
2294 " line\n", fname, lineno , 0 );
2296 Debug( LDAP_DEBUG_ANY,
2297 "%s: line %d: missing path in \"modulepath <path>\" line\n",
2301 exit( EXIT_FAILURE );
2303 if (module_path( cargv[1] )) {
2305 LDAP_LOG( CONFIG, CRIT,
2306 "%s: line %d: failed to set module search path to %s.\n",
2307 fname, lineno, cargv[1] );
2309 Debug( LDAP_DEBUG_ANY,
2310 "%s: line %d: failed to set module search path to %s\n",
2311 fname, lineno, cargv[1]);
2314 exit( EXIT_FAILURE );
2317 #endif /*SLAPD_MODULES*/
2320 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2321 rc = ldap_pvt_tls_set_option( NULL,
2322 LDAP_OPT_X_TLS_RANDOM_FILE,
2327 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2328 rc = ldap_pvt_tls_set_option( NULL,
2329 LDAP_OPT_X_TLS_CIPHER_SUITE,
2334 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2335 rc = ldap_pvt_tls_set_option( NULL,
2336 LDAP_OPT_X_TLS_CERTFILE,
2341 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2342 rc = ldap_pvt_tls_set_option( NULL,
2343 LDAP_OPT_X_TLS_KEYFILE,
2348 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2349 rc = ldap_pvt_tls_set_option( NULL,
2350 LDAP_OPT_X_TLS_CACERTDIR,
2355 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2356 rc = ldap_pvt_tls_set_option( NULL,
2357 LDAP_OPT_X_TLS_CACERTFILE,
2361 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2362 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2364 rc = ldap_pvt_tls_set_option( NULL,
2365 LDAP_OPT_X_TLS_REQUIRE_CERT,
2368 rc = ldap_int_tls_config( NULL,
2369 LDAP_OPT_X_TLS_REQUIRE_CERT,
2378 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2379 #ifdef SLAPD_RLOOKUPS
2382 LDAP_LOG( CONFIG, INFO,
2383 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2384 fname, lineno , 0 );
2386 Debug( LDAP_DEBUG_ANY,
2387 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2393 if ( !strcasecmp( cargv[1], "on" ) ) {
2394 use_reverse_lookup = 1;
2395 } else if ( !strcasecmp( cargv[1], "off" ) ) {
2396 use_reverse_lookup = 0;
2399 LDAP_LOG( CONFIG, INFO,
2400 "%s: line %d: reverse-lookup: "
2401 "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2403 Debug( LDAP_DEBUG_ANY,
2404 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2410 #else /* !SLAPD_RLOOKUPS */
2412 LDAP_LOG( CONFIG, INFO,
2413 "%s: line %d: reverse lookups "
2414 "are not configured (ignored).\n", fname, lineno , 0 );
2416 Debug( LDAP_DEBUG_ANY,
2417 "%s: line %d: reverse lookups are not configured (ignored).\n",
2420 #endif /* !SLAPD_RLOOKUPS */
2422 /* Netscape plugins */
2423 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2424 #if defined( LDAP_SLAPI )
2426 #ifdef notdef /* allow global plugins, too */
2428 * a "plugin" line must be inside a database
2429 * definition, since we implement pre-,post-
2430 * and extended operation plugins
2434 LDAP_LOG( CONFIG, INFO,
2435 "%s: line %d: plugin line must appear "
2436 "insid a database definition.\n",
2439 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2440 "line must appear inside a database "
2441 "definition\n", fname, lineno, 0 );
2447 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
2451 slapi_plugins_used++;
2453 #else /* !defined( LDAP_SLAPI ) */
2455 LDAP_LOG( CONFIG, INFO,
2456 "%s: line %d: SLAPI not supported.\n",
2459 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2460 "not supported.\n", fname, lineno, 0 );
2464 #endif /* !defined( LDAP_SLAPI ) */
2466 /* Netscape plugins */
2467 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2468 #if defined( LDAP_SLAPI )
2471 LDAP_LOG( CONFIG, INFO,
2472 "%s: line %d: missing file name "
2473 "in pluginlog <filename> line.\n",
2476 Debug( LDAP_DEBUG_ANY,
2477 "%s: line %d: missing file name "
2478 "in pluginlog <filename> line.\n",
2484 if ( slapi_log_file != NULL ) {
2485 ch_free( slapi_log_file );
2488 slapi_log_file = ch_strdup( cargv[1] );
2489 #endif /* !defined( LDAP_SLAPI ) */
2491 /* pass anything else to the current backend info/db config routine */
2494 if ( bi->bi_config ) {
2495 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2501 case SLAP_CONF_UNKNOWN:
2503 LDAP_LOG( CONFIG, INFO,
2504 "%s: line %d: unknown directive \"%s\" inside "
2505 "backend info definition (ignored).\n",
2506 fname, lineno, cargv[0] );
2508 Debug( LDAP_DEBUG_ANY,
2509 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2510 fname, lineno, cargv[0] );
2519 } else if ( be != NULL ) {
2520 if ( be->be_config ) {
2521 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2527 case SLAP_CONF_UNKNOWN:
2529 LDAP_LOG( CONFIG, INFO,
2530 "%s: line %d: unknown directive \"%s\" inside "
2531 "backend database definition (ignored).\n",
2532 fname, lineno, cargv[0] );
2534 Debug( LDAP_DEBUG_ANY,
2535 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2536 fname, lineno, cargv[0] );
2547 LDAP_LOG( CONFIG, INFO,
2548 "%s: line %d: unknown directive \"%s\" outside backend "
2549 "info and database definitions (ignored).\n",
2550 fname, lineno, cargv[0] );
2552 Debug( LDAP_DEBUG_ANY,
2553 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2554 fname, lineno, cargv[0] );
2563 if ( depth == 0 ) ch_free( cargv );
2565 if ( !global_schemadn.bv_val ) {
2566 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2568 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2571 if ( load_ucdata( NULL ) < 0 ) return 1;
2583 char logbuf[sizeof("pseudorootpw ***")];
2586 token = strtok_quote( line, " \t" );
2590 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2591 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2592 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2593 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2594 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2596 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2599 if ( strtok_quote_ptr ) {
2600 *strtok_quote_ptr = ' ';
2604 LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2606 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2609 if ( strtok_quote_ptr ) {
2610 *strtok_quote_ptr = '\0';
2613 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2614 if ( cargc == cargv_size - 1 ) {
2616 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2618 if ( tmp == NULL ) {
2620 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2622 Debug( LDAP_DEBUG_ANY,
2623 "line %d: out of memory\n",
2629 cargv_size += ARGS_STEP;
2631 cargv[cargc++] = token;
2633 cargv[cargc] = NULL;
2638 strtok_quote( char *line, char *sep )
2644 strtok_quote_ptr = NULL;
2645 if ( line != NULL ) {
2648 while ( *next && strchr( sep, *next ) ) {
2652 if ( *next == '\0' ) {
2658 for ( inquote = 0; *next; ) {
2666 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2672 next + 1, strlen( next + 1 ) + 1 );
2673 next++; /* dont parse the escaped character */
2678 if ( strchr( sep, *next ) != NULL ) {
2679 strtok_quote_ptr = next;
2692 static char buf[BUFSIZ];
2694 static size_t lmax, lcur;
2696 #define CATLINE( buf ) \
2698 size_t len = strlen( buf ); \
2699 while ( lcur + len + 1 > lmax ) { \
2701 line = (char *) ch_realloc( line, lmax ); \
2703 strcpy( line + lcur, buf ); \
2708 fp_getline( FILE *fp, int *lineno )
2716 /* hack attack - keeps us from having to keep a stack of bufs... */
2717 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2722 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2723 /* trim off \r\n or \n */
2724 if ( (p = strchr( buf, '\n' )) != NULL ) {
2725 if( p > buf && p[-1] == '\r' ) --p;
2729 /* trim off trailing \ and append the next line */
2730 if ( line[ 0 ] != '\0'
2731 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2732 && p[ -1 ] != '\\' ) {
2737 if ( ! isspace( (unsigned char) buf[0] ) ) {
2741 /* change leading whitespace to a space */
2750 return( line[0] ? line : NULL );
2754 fp_getline_init( int *lineno )
2760 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2762 load_ucdata( char *path )
2764 static int loaded = 0;
2770 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2773 LDAP_LOG( CONFIG, CRIT,
2774 "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2776 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2789 ucdata_unload( UCDATA_ALL );
2790 free( global_schemandn.bv_val );
2791 free( global_schemadn.bv_val );
2793 if ( slapd_args_file )
2794 free ( slapd_args_file );
2795 if ( slapd_pid_file )
2796 free ( slapd_pid_file );
2797 if ( default_passwd_hash )
2798 ldap_charray_free( default_passwd_hash );
2799 acl_destroy( global_acl, NULL );
2810 syncinfo_t *si_entry;
2812 int duplicated_replica_id = 0;
2814 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2818 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2820 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2825 si->si_tls = SYNCINFO_TLS_OFF;
2826 if ( be->be_rootndn.bv_val ) {
2827 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2829 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2830 si->si_schemachecking = 0;
2831 ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
2832 &si->si_filterstr );
2833 si->si_base.bv_val = NULL;
2834 si->si_scope = LDAP_SCOPE_SUBTREE;
2835 si->si_attrsonly = 0;
2836 si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2837 si->si_attrs[0] = NULL;
2838 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2839 si->si_interval = 86400;
2840 si->si_syncCookie.ctxcsn = NULL;
2841 si->si_syncCookie.octet_str = NULL;
2842 si->si_syncCookie.sid = -1;
2843 si->si_manageDSAit = 0;
2846 si->si_syncUUID_ndn.bv_val = NULL;
2847 si->si_syncUUID_ndn.bv_len = 0;
2849 si->si_presentlist = NULL;
2850 LDAP_LIST_INIT( &si->si_nonpresentlist );
2852 rc = parse_syncrepl_line( cargv, cargc, si );
2854 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2855 if ( si->si_rid == si_entry->si_rid ) {
2857 LDAP_LOG( CONFIG, ERR,
2858 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
2860 Debug( LDAP_DEBUG_ANY,
2861 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2863 duplicated_replica_id = 1;
2868 if ( rc < 0 || duplicated_replica_id ) {
2869 syncinfo_t *si_entry;
2870 /* Something bad happened - back out */
2872 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2874 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2877 /* If error, remove all syncinfo */
2878 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2879 if ( si_entry->si_updatedn.bv_val ) {
2880 ch_free( si->si_updatedn.bv_val );
2882 if ( si_entry->si_filterstr.bv_val ) {
2883 ch_free( si->si_filterstr.bv_val );
2885 if ( si_entry->si_attrs ) {
2887 while ( si_entry->si_attrs[i] != NULL ) {
2888 ch_free( si_entry->si_attrs[i] );
2891 ch_free( si_entry->si_attrs );
2895 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2896 si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
2897 LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
2898 ch_free( si_entry );
2900 LDAP_STAILQ_INIT( &be->be_syncinfo );
2904 LDAP_LOG ( CONFIG, RESULTS,
2905 "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2906 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2908 Debug( LDAP_DEBUG_CONFIG,
2909 "Config: ** successfully added syncrepl \"%s\"\n",
2910 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2912 if ( !si->si_schemachecking ) {
2913 be->be_flags |= SLAP_BFLAG_NO_SCHEMA_CHECK;
2916 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2922 #define PROVIDERSTR "provider"
2923 #define SUFFIXSTR "suffix"
2924 #define UPDATEDNSTR "updatedn"
2925 #define BINDMETHSTR "bindmethod"
2926 #define SIMPLESTR "simple"
2927 #define SASLSTR "sasl"
2928 #define BINDDNSTR "binddn"
2929 #define CREDSTR "credentials"
2930 #define OLDAUTHCSTR "bindprincipal"
2931 #define AUTHCSTR "authcID"
2932 #define AUTHZSTR "authzID"
2933 #define SRVTABSTR "srvtab"
2934 #define SASLMECHSTR "saslmech"
2935 #define REALMSTR "realm"
2936 #define SECPROPSSTR "secprops"
2937 #define STARTTLSSTR "starttls"
2938 #define CRITICALSTR "critical"
2940 #define SCHEMASTR "schemachecking"
2941 #define FILTERSTR "filter"
2942 #define SEARCHBASESTR "searchbase"
2943 #define SCOPESTR "scope"
2944 #define ATTRSSTR "attrs"
2945 #define ATTRSONLYSTR "attrsonly"
2946 #define TYPESTR "type"
2947 #define INTERVALSTR "interval"
2948 #define LASTMODSTR "lastmod"
2949 #define LMREQSTR "req"
2950 #define LMGENSTR "gen"
2951 #define LMNOSTR "no"
2952 #define MANAGEDSAITSTR "manageDSAit"
2953 #define SLIMITSTR "sizelimit"
2954 #define TLIMITSTR "timelimit"
2956 #define GOT_ID 0x0001
2957 #define GOT_PROVIDER 0x0002
2958 #define GOT_METHOD 0x0004
2959 #define GOT_ALL 0x0007
2962 parse_syncrepl_line(
2973 for ( i = 1; i < cargc; i++ ) {
2974 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2976 /* '\0' string terminator accounts for '=' */
2977 val = cargv[ i ] + sizeof( IDSTR );
2979 if ( tmp >= 1000 || tmp < 0 ) {
2980 fprintf( stderr, "Error: parse_syncrepl_line: "
2981 "syncrepl id %d is out of range [0..999]\n", tmp );
2986 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2987 sizeof( PROVIDERSTR ) - 1 )) {
2988 val = cargv[ i ] + sizeof( PROVIDERSTR );
2989 si->si_provideruri = ch_strdup( val );
2990 si->si_provideruri_bv = (BerVarray)
2991 ch_calloc( 2, sizeof( struct berval ));
2992 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2993 0, &si->si_provideruri_bv[0] );
2994 si->si_provideruri_bv[1].bv_len = 0;
2995 si->si_provideruri_bv[1].bv_val = NULL;
2996 gots |= GOT_PROVIDER;
2997 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2998 sizeof(STARTTLSSTR) - 1 ) )
3000 val = cargv[ i ] + sizeof( STARTTLSSTR );
3001 if( !strcasecmp( val, CRITICALSTR ) ) {
3002 si->si_tls = SYNCINFO_TLS_CRITICAL;
3004 si->si_tls = SYNCINFO_TLS_ON;
3006 } else if ( !strncasecmp( cargv[ i ],
3007 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3009 struct berval updatedn = {0, NULL};
3010 val = cargv[ i ] + sizeof( UPDATEDNSTR );
3011 ber_str2bv( val, 0, 0, &updatedn );
3012 ch_free( si->si_updatedn.bv_val );
3013 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3014 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3015 sizeof( BINDMETHSTR ) - 1 ) )
3017 val = cargv[ i ] + sizeof( BINDMETHSTR );
3018 if ( !strcasecmp( val, SIMPLESTR )) {
3019 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3021 } else if ( !strcasecmp( val, SASLSTR )) {
3022 #ifdef HAVE_CYRUS_SASL
3023 si->si_bindmethod = LDAP_AUTH_SASL;
3025 #else /* HAVE_CYRUS_SASL */
3026 fprintf( stderr, "Error: parse_syncrepl_line: "
3027 "not compiled with SASL support\n" );
3029 #endif /* HAVE_CYRUS_SASL */
3031 si->si_bindmethod = -1;
3033 } else if ( !strncasecmp( cargv[ i ],
3034 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3035 val = cargv[ i ] + sizeof( BINDDNSTR );
3036 si->si_binddn = ch_strdup( val );
3037 } else if ( !strncasecmp( cargv[ i ],
3038 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3039 val = cargv[ i ] + sizeof( CREDSTR );
3040 si->si_passwd = ch_strdup( val );
3041 } else if ( !strncasecmp( cargv[ i ],
3042 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3043 val = cargv[ i ] + sizeof( SASLMECHSTR );
3044 si->si_saslmech = ch_strdup( val );
3045 } else if ( !strncasecmp( cargv[ i ],
3046 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3047 val = cargv[ i ] + sizeof( SECPROPSSTR );
3048 si->si_secprops = ch_strdup( val );
3049 } else if ( !strncasecmp( cargv[ i ],
3050 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3051 val = cargv[ i ] + sizeof( REALMSTR );
3052 si->si_realm = ch_strdup( val );
3053 } else if ( !strncasecmp( cargv[ i ],
3054 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3055 val = cargv[ i ] + sizeof( AUTHCSTR );
3056 si->si_authcId = ch_strdup( val );
3057 } else if ( !strncasecmp( cargv[ i ],
3058 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3059 /* Old authcID is provided for some backwards compatibility */
3060 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3061 si->si_authcId = ch_strdup( val );
3062 } else if ( !strncasecmp( cargv[ i ],
3063 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3064 val = cargv[ i ] + sizeof( AUTHZSTR );
3065 si->si_authzId = ch_strdup( val );
3066 } else if ( !strncasecmp( cargv[ i ],
3067 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3069 val = cargv[ i ] + sizeof( SCHEMASTR );
3070 if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
3071 si->si_schemachecking = 1;
3072 } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
3073 si->si_schemachecking = 0;
3075 si->si_schemachecking = 1;
3077 } else if ( !strncasecmp( cargv[ i ],
3078 FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3080 val = cargv[ i ] + sizeof( FILTERSTR );
3081 ber_str2bv( val, 0, 1, &si->si_filterstr );
3082 } else if ( !strncasecmp( cargv[ i ],
3083 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3086 val = cargv[ i ] + sizeof( SEARCHBASESTR );
3087 if ( si->si_base.bv_val ) {
3088 ch_free( si->si_base.bv_val );
3090 ber_str2bv( val, 0, 0, &bv );
3091 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3092 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3095 } else if ( !strncasecmp( cargv[ i ],
3096 SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3098 val = cargv[ i ] + sizeof( SCOPESTR );
3099 if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3100 si->si_scope = LDAP_SCOPE_BASE;
3101 } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3102 si->si_scope = LDAP_SCOPE_ONELEVEL;
3103 } else if ( !strcasecmp( val, "subordinate" ) ||
3104 !strcasecmp( val, "children" ))
3106 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3107 } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3108 si->si_scope = LDAP_SCOPE_SUBTREE;
3110 fprintf( stderr, "Error: parse_syncrepl_line: "
3111 "unknown scope \"%s\"\n", val);
3114 } else if ( !strncasecmp( cargv[ i ],
3115 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3117 si->si_attrsonly = 1;
3118 } else if ( !strncasecmp( cargv[ i ],
3119 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3121 val = cargv[ i ] + sizeof( ATTRSSTR );
3122 str2clist( &si->si_attrs, val, "," );
3123 } else if ( !strncasecmp( cargv[ i ],
3124 TYPESTR, sizeof( TYPESTR ) - 1 ) )
3126 val = cargv[ i ] + sizeof( TYPESTR );
3127 if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3128 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3129 } else if ( !strncasecmp( val, "refreshAndPersist",
3130 sizeof("refreshAndPersist")-1 ))
3132 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3133 si->si_interval = 60;
3135 fprintf( stderr, "Error: parse_syncrepl_line: "
3136 "unknown sync type \"%s\"\n", val);
3139 } else if ( !strncasecmp( cargv[ i ],
3140 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3142 val = cargv[ i ] + sizeof( INTERVALSTR );
3143 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3144 si->si_interval = 0;
3152 hstr = strchr( dstr, ':' );
3153 if ( hstr == NULL ) {
3154 fprintf( stderr, "Error: parse_syncrepl_line: "
3155 "invalid interval \"%s\"\n", val );
3159 mstr = strchr( hstr, ':' );
3160 if ( mstr == NULL ) {
3161 fprintf( stderr, "Error: parse_syncrepl_line: "
3162 "invalid interval \"%s\"\n", val );
3166 sstr = strchr( mstr, ':' );
3167 if ( sstr == NULL ) {
3168 fprintf( stderr, "Error: parse_syncrepl_line: "
3169 "invalid interval \"%s\"\n", val );
3178 if (( hh > 24 ) || ( hh < 0 ) ||
3179 ( mm > 60 ) || ( mm < 0 ) ||
3180 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3181 fprintf( stderr, "Error: parse_syncrepl_line: "
3182 "invalid interval \"%s\"\n", val );
3185 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3187 if ( si->si_interval < 0 ) {
3188 fprintf( stderr, "Error: parse_syncrepl_line: "
3189 "invalid interval \"%ld\"\n",
3190 (long) si->si_interval);
3193 } else if ( !strncasecmp( cargv[ i ],
3194 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3196 val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3197 si->si_manageDSAit = atoi( val );
3198 } else if ( !strncasecmp( cargv[ i ],
3199 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3201 val = cargv[ i ] + sizeof( SLIMITSTR );
3202 si->si_slimit = atoi( val );
3203 } else if ( !strncasecmp( cargv[ i ],
3204 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3206 val = cargv[ i ] + sizeof( TLIMITSTR );
3207 si->si_tlimit = atoi( val );
3209 fprintf( stderr, "Error: parse_syncrepl_line: "
3210 "unknown keyword \"%s\"\n", cargv[ i ] );
3214 if ( gots != GOT_ALL ) {
3216 "Error: Malformed \"syncrepl\" line in slapd config file" );
3224 str2clist( char ***out, char *in, const char *brkstr )
3233 /* find last element in list */
3234 for (i = 0; *out && *out[i]; i++);
3236 /* protect the input string from strtok */
3237 str = ch_strdup( in );
3239 if ( *str == '\0' ) {
3244 /* Count words in string */
3246 for ( s = str; *s; s++ ) {
3247 if ( strchr( brkstr, *s ) != NULL ) {
3252 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3254 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3256 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3258 *new = ch_strdup( s );