1 /* config.c - configuration file handling routines */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
14 #include <ac/signal.h>
15 #include <ac/socket.h>
28 * defaults for various global variables
30 struct slap_limits_set deflimit = {
31 SLAPD_DEFAULT_TIMELIMIT, /* backward compatible limits */
34 SLAPD_DEFAULT_SIZELIMIT, /* backward compatible limits */
36 -1, /* no limit on unchecked size */
38 0 /* hide number of entries left */
41 AccessControl *global_acl = NULL;
42 slap_access_t global_default_access = ACL_READ;
43 slap_mask_t global_restrictops = 0;
44 slap_mask_t global_allows = 0;
45 slap_mask_t global_disallows = 0;
46 slap_mask_t global_requires = 0;
47 slap_ssf_set_t global_ssf_set;
49 int global_gentlehup = 0;
50 int global_idletimeout = 0;
51 char *global_host = NULL;
52 char *global_realm = NULL;
53 char *ldap_srvtab = "";
54 char *default_passwd_hash = NULL;
55 int cargc = 0, cargv_size = 0;
57 struct berval default_search_base = { 0, NULL };
58 struct berval default_search_nbase = { 0, NULL };
59 unsigned num_subordinates = 0;
60 struct berval global_schemadn = { 0, NULL };
61 struct berval global_schemandn = { 0, NULL };
63 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
64 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
66 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
67 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
69 char *slapd_pid_file = NULL;
70 char *slapd_args_file = NULL;
72 char *strtok_quote_ptr;
74 int use_reverse_lookup = 0;
76 static char *fp_getline(FILE *fp, int *lineno);
77 static void fp_getline_init(int *lineno);
78 static int fp_parse_line(int lineno, char *line);
80 static char *strtok_quote(char *line, char *sep);
81 static int load_ucdata(char *path);
83 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
84 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
87 read_config( const char *fname, int depth )
90 char *line, *savefname, *saveline;
94 struct berval vals[2];
97 static int lastmod = 1;
98 static BackendInfo *bi = NULL;
99 static BackendDB *be = NULL;
101 vals[1].bv_val = NULL;
104 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
105 cargv_size = ARGS_STEP + 1;
108 if ( (fp = fopen( fname, "r" )) == NULL ) {
111 LDAP_LOG( CONFIG, ENTRY,
112 "read_config: " "could not open config file \"%s\": %s (%d)\n",
113 fname, strerror(errno), errno );
115 Debug( LDAP_DEBUG_ANY,
116 "could not open config file \"%s\": %s (%d)\n",
117 fname, strerror(errno), errno );
123 LDAP_LOG( CONFIG, ENTRY,
124 "read_config: reading config file %s\n", fname, 0, 0 );
126 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
130 fp_getline_init( &lineno );
132 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
133 /* skip comments and blank lines */
134 if ( line[0] == '#' || line[0] == '\0' ) {
138 /* fp_parse_line is destructive, we save a copy */
139 saveline = ch_strdup( line );
141 if ( fp_parse_line( lineno, line ) != 0 ) {
147 LDAP_LOG( CONFIG, INFO,
148 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
150 Debug( LDAP_DEBUG_ANY,
151 "%s: line %d: bad config line (ignored)\n",
158 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
161 LDAP_LOG( CONFIG, CRIT,
162 "%s : line %d: missing type in \"backend\" line.\n",
165 Debug( LDAP_DEBUG_ANY,
166 "%s: line %d: missing type in \"backend <type>\" line\n",
175 LDAP_LOG( CONFIG, CRIT,
176 "%s: line %d: backend line must appear before any "
177 "database definition.\n", fname, lineno , 0 );
179 Debug( LDAP_DEBUG_ANY,
180 "%s: line %d: backend line must appear before any database definition\n",
187 bi = backend_info( cargv[1] );
191 LDAP_LOG( CONFIG, CRIT,
192 "read_config: backend %s initialization failed.\n",
195 Debug( LDAP_DEBUG_ANY,
196 "backend %s initialization failed.\n",
202 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
205 LDAP_LOG( CONFIG, CRIT,
206 "%s: line %d: missing type in \"database <type>\" line\n",
209 Debug( LDAP_DEBUG_ANY,
210 "%s: line %d: missing type in \"database <type>\" line\n",
218 be = backend_db_init( cargv[1] );
222 LDAP_LOG( CONFIG, CRIT,
223 "database %s initialization failed.\n", cargv[1], 0, 0 );
225 Debug( LDAP_DEBUG_ANY,
226 "database %s initialization failed.\n",
233 /* set thread concurrency */
234 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
238 LDAP_LOG( CONFIG, CRIT,
239 "%s: line %d: missing level in \"concurrency <level\" "
240 " line\n", fname, lineno, 0 );
242 Debug( LDAP_DEBUG_ANY,
243 "%s: line %d: missing level in \"concurrency <level>\" line\n",
250 c = atoi( cargv[1] );
254 LDAP_LOG( CONFIG, CRIT,
255 "%s: line %d: invalid level (%d) in "
256 "\"concurrency <level>\" line.\n", fname, lineno, c );
258 Debug( LDAP_DEBUG_ANY,
259 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
266 ldap_pvt_thread_set_concurrency( c );
268 /* set sockbuf max */
269 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
273 LDAP_LOG( CONFIG, CRIT,
274 "%s: line %d: missing max in \"sockbuf_max_incoming "
275 "<bytes>\" line\n", fname, lineno, 0 );
277 Debug( LDAP_DEBUG_ANY,
278 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
285 max = atol( cargv[1] );
289 LDAP_LOG( CONFIG, CRIT,
290 "%s: line %d: invalid max value (%ld) in "
291 "\"sockbuf_max_incoming <bytes>\" line.\n",
292 fname, lineno, max );
294 Debug( LDAP_DEBUG_ANY,
295 "%s: line %d: invalid max value (%ld) in "
296 "\"sockbuf_max_incoming <bytes>\" line.\n",
297 fname, lineno, max );
303 sockbuf_max_incoming = max;
305 /* set sockbuf max authenticated */
306 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
310 LDAP_LOG( CONFIG, CRIT,
311 "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
312 "<bytes>\" line\n", fname, lineno, 0 );
314 Debug( LDAP_DEBUG_ANY,
315 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
322 max = atol( cargv[1] );
326 LDAP_LOG( CONFIG, CRIT,
327 "%s: line %d: invalid max value (%ld) in "
328 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
329 fname, lineno, max );
331 Debug( LDAP_DEBUG_ANY,
332 "%s: line %d: invalid max value (%ld) in "
333 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
334 fname, lineno, max );
340 sockbuf_max_incoming_auth = max;
342 /* set conn pending max */
343 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
347 LDAP_LOG( CONFIG, CRIT,
348 "%s: line %d: missing max in \"conn_max_pending "
349 "<requests>\" line\n", fname, lineno, 0 );
351 Debug( LDAP_DEBUG_ANY,
352 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
359 max = atol( cargv[1] );
363 LDAP_LOG( CONFIG, CRIT,
364 "%s: line %d: invalid max value (%ld) in "
365 "\"conn_max_pending <requests>\" line.\n",
366 fname, lineno, max );
368 Debug( LDAP_DEBUG_ANY,
369 "%s: line %d: invalid max value (%ld) in "
370 "\"conn_max_pending <requests>\" line.\n",
371 fname, lineno, max );
377 slap_conn_max_pending = max;
379 /* set conn pending max authenticated */
380 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
384 LDAP_LOG( CONFIG, CRIT,
385 "%s: line %d: missing max in \"conn_max_pending_auth "
386 "<requests>\" line\n", fname, lineno, 0 );
388 Debug( LDAP_DEBUG_ANY,
389 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
396 max = atol( cargv[1] );
400 LDAP_LOG( CONFIG, CRIT,
401 "%s: line %d: invalid max value (%ld) in "
402 "\"conn_max_pending_auth <requests>\" line.\n",
403 fname, lineno, max );
405 Debug( LDAP_DEBUG_ANY,
406 "%s: line %d: invalid max value (%ld) in "
407 "\"conn_max_pending_auth <requests>\" line.\n",
408 fname, lineno, max );
414 slap_conn_max_pending_auth = max;
416 /* default search base */
417 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
420 LDAP_LOG( CONFIG, CRIT,
421 "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
422 "line\n", fname, lineno, 0 );
424 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
425 "missing dn in \"defaultSearchBase <dn>\" line\n",
431 } else if ( cargc > 2 ) {
433 LDAP_LOG( CONFIG, INFO,
434 "%s: line %d: extra cruft after <dn> in "
435 "\"defaultSearchBase %s\" line (ignored)\n",
436 fname, lineno, cargv[1] );
438 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
439 "extra cruft after <dn> in \"defaultSearchBase %s\", "
441 fname, lineno, cargv[1] );
445 if ( bi != NULL || be != NULL ) {
447 LDAP_LOG( CONFIG, CRIT,
448 "%s: line %d: defaultSearchBase line must appear "
449 "prior to any backend or database definitions\n",
452 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
453 "defaultSearchBaase line must appear prior to "
454 "any backend or database definition\n",
461 if ( default_search_nbase.bv_len ) {
463 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
464 "default search base \"%s\" already defined "
465 "(discarding old)\n", fname, lineno,
466 default_search_base.bv_val );
468 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
469 "default search base \"%s\" already defined "
470 "(discarding old)\n",
471 fname, lineno, default_search_base.bv_val );
474 free( default_search_base.bv_val );
475 free( default_search_nbase.bv_val );
478 if ( load_ucdata( NULL ) < 0 ) return 1;
483 dn.bv_val = cargv[1];
484 dn.bv_len = strlen( dn.bv_val );
486 rc = dnPrettyNormal( NULL, &dn,
487 &default_search_base,
488 &default_search_nbase, NULL );
490 if( rc != LDAP_SUCCESS ) {
492 LDAP_LOG( CONFIG, CRIT,
493 "%s: line %d: defaultSearchBase DN is invalid.\n",
496 Debug( LDAP_DEBUG_ANY,
497 "%s: line %d: defaultSearchBase DN is invalid\n",
504 /* set maximum threads in thread pool */
505 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
509 LDAP_LOG( CONFIG, CRIT,
510 "%s: line %d: missing count in \"threads <count>\" line\n",
513 Debug( LDAP_DEBUG_ANY,
514 "%s: line %d: missing count in \"threads <count>\" line\n",
521 c = atoi( cargv[1] );
525 LDAP_LOG( CONFIG, CRIT,
526 "%s: line %d: invalid level (%d) in \"threads <count>\""
527 "line\n", fname, lineno, c );
529 Debug( LDAP_DEBUG_ANY,
530 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
537 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
539 /* save for later use */
540 connection_pool_max = c;
542 /* get pid file name */
543 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
546 LDAP_LOG( CONFIG, CRIT,
547 "%s: line %d missing file name in \"pidfile <file>\" "
548 "line.\n", fname, lineno, 0 );
550 Debug( LDAP_DEBUG_ANY,
551 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
558 slapd_pid_file = ch_strdup( cargv[1] );
560 /* get args file name */
561 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
564 LDAP_LOG( CONFIG, CRIT,
565 "%s: %d: missing file name in "
566 "\"argsfile <file>\" line.\n",
569 Debug( LDAP_DEBUG_ANY,
570 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
577 slapd_args_file = ch_strdup( cargv[1] );
579 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
582 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
585 /* default password hash */
586 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
589 LDAP_LOG( CONFIG, CRIT,
590 "%s: line %d: missing hash in "
591 "\"password-hash <hash>\" line.\n",
594 Debug( LDAP_DEBUG_ANY,
595 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
601 if ( default_passwd_hash != NULL ) {
603 LDAP_LOG( CONFIG, CRIT,
604 "%s: line %d: already set default password_hash!\n",
607 Debug( LDAP_DEBUG_ANY,
608 "%s: line %d: already set default password_hash!\n",
616 if ( lutil_passwd_scheme( cargv[1] ) == 0 ) {
618 LDAP_LOG( CONFIG, CRIT,
619 "%s: line %d: password scheme \"%s\" not available\n",
620 fname, lineno, cargv[1] );
622 Debug( LDAP_DEBUG_ANY,
623 "%s: line %d: password scheme \"%s\" not available\n",
624 fname, lineno, cargv[1] );
629 default_passwd_hash = ch_strdup( cargv[1] );
631 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
635 LDAP_LOG( CONFIG, CRIT,
636 "%s: line %d: missing format in "
637 "\"password-crypt-salt-format <format>\" line\n",
640 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
641 "\"password-crypt-salt-format <format>\" line\n",
648 lutil_salt_format( cargv[1] );
650 /* SASL config options */
651 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
652 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
655 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
659 LDAP_LOG( CONFIG, CRIT,
660 "%s: line %d: missing dn in "
661 "\"schemadn <dn>\" line.\n", fname, lineno, 0 );
663 Debug( LDAP_DEBUG_ANY,
664 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
669 ber_str2bv( cargv[1], 0, 0, &dn );
671 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
672 &be->be_schemandn, NULL );
674 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
675 &global_schemandn, NULL );
677 if ( rc != LDAP_SUCCESS ) {
679 LDAP_LOG( CONFIG, CRIT,
680 "%s: line %d: schemadn DN is invalid.\n",
683 Debug( LDAP_DEBUG_ANY,
684 "%s: line %d: schemadn DN is invalid\n",
690 /* set UCDATA path */
691 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
695 LDAP_LOG( CONFIG, CRIT,
696 "%s: line %d: missing path in "
697 "\"ucdata-path <path>\" line.\n", fname, lineno, 0 );
699 Debug( LDAP_DEBUG_ANY,
700 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
707 err = load_ucdata( cargv[1] );
711 LDAP_LOG( CONFIG, CRIT,
712 "%s: line %d: ucdata already loaded, ucdata-path "
713 "must be set earlier in the file and/or be "
714 "specified only once!\n", fname, lineno, 0 );
716 Debug( LDAP_DEBUG_ANY,
717 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
726 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
728 struct slap_limits_set *lim;
732 LDAP_LOG( CONFIG, CRIT,
733 "%s: line %d: missing limit in \"sizelimit <limit>\" "
734 "line.\n", fname, lineno, 0 );
736 Debug( LDAP_DEBUG_ANY,
737 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
747 lim = &be->be_def_limit;
750 for ( i = 1; i < cargc; i++ ) {
751 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
752 rc = parse_limit( cargv[i], lim );
755 LDAP_LOG( CONFIG, CRIT,
756 "%s: line %d: unable "
757 "to parse value \"%s\" in \"sizelimit "
758 "<limit>\" line.\n", fname, lineno, cargv[i] );
760 Debug( LDAP_DEBUG_ANY,
761 "%s: line %d: unable "
762 "to parse value \"%s\" "
765 fname, lineno, cargv[i] );
771 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
772 lim->lms_s_soft = -1;
776 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
777 if ( next == cargv[i] ) {
779 LDAP_LOG( CONFIG, CRIT,
780 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
781 "line.\n", fname, lineno, cargv[i] );
783 Debug( LDAP_DEBUG_ANY,
784 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
785 fname, lineno, cargv[i] );
789 } else if ( next[0] != '\0' ) {
791 LDAP_LOG( CONFIG, CRIT,
792 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
793 "line ignored.\n", fname, lineno, next );
795 Debug( LDAP_DEBUG_ANY,
796 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
797 fname, lineno, next );
806 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
808 struct slap_limits_set *lim;
812 LDAP_LOG( CONFIG, CRIT,
813 "%s: line %d missing limit in \"timelimit <limit>\" "
814 "line.\n", fname, lineno, 0 );
816 Debug( LDAP_DEBUG_ANY,
817 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
827 lim = &be->be_def_limit;
830 for ( i = 1; i < cargc; i++ ) {
831 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
832 rc = parse_limit( cargv[i], lim );
835 LDAP_LOG( CONFIG, CRIT,
836 "%s: line %d: unable to parse value \"%s\" "
837 "in \"timelimit <limit>\" line.\n",
838 fname, lineno, cargv[i] );
840 Debug( LDAP_DEBUG_ANY,
841 "%s: line %d: unable "
842 "to parse value \"%s\" "
845 fname, lineno, cargv[i] );
851 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
852 lim->lms_t_soft = -1;
856 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
857 if ( next == cargv[i] ) {
859 LDAP_LOG( CONFIG, CRIT,
860 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
861 "line.\n", fname, lineno, cargv[i] );
863 Debug( LDAP_DEBUG_ANY,
864 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
865 fname, lineno, cargv[i] );
869 } else if ( next[0] != '\0' ) {
871 LDAP_LOG( CONFIG, CRIT,
872 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
873 "line ignored.\n", fname, lineno, next );
875 Debug( LDAP_DEBUG_ANY,
876 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
877 fname, lineno, next );
885 /* set regex-based limits */
886 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
889 LDAP_LOG( CONFIG, WARNING,
890 "%s: line %d \"limits\" allowed only in database "
891 "environment.\n", fname, lineno, 0 );
893 Debug( LDAP_DEBUG_ANY,
894 "%s: line %d \"limits\" allowed only in database environment.\n%s",
900 if ( parse_limits( be, fname, lineno, cargc, cargv ) ) {
904 /* mark this as a subordinate database */
905 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
908 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
909 "subordinate keyword must appear inside a database "
910 "definition.\n", fname, lineno, 0 );
912 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
913 "must appear inside a database definition.\n",
919 be->be_flags |= SLAP_BFLAG_GLUE_SUBORDINATE;
923 /* add an overlay to this backend */
924 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
927 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
928 "overlay keyword must appear inside a database "
929 "definition.\n", fname, lineno, 0 );
931 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
932 "must appear inside a database definition.\n",
937 } else if ( overlay_config( be, cargv[1] )) {
941 /* set database suffix */
942 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
944 struct berval dn, pdn, ndn;
948 LDAP_LOG( CONFIG, CRIT,
949 "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
952 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
953 "missing dn in \"suffix <dn>\" line\n",
959 } else if ( cargc > 2 ) {
961 LDAP_LOG( CONFIG, INFO,
962 "%s: line %d: extra cruft after <dn> in \"suffix %s\""
963 " line (ignored).\n", fname, lineno, cargv[1] );
965 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
966 "after <dn> in \"suffix %s\" line (ignored)\n",
967 fname, lineno, cargv[1] );
973 LDAP_LOG( CONFIG, INFO,
974 "%s: line %d: suffix line must appear inside a database "
975 "definition.\n", fname, lineno, 0 );
977 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
978 "must appear inside a database definition\n",
983 #if defined(SLAPD_MONITOR_DN)
984 /* "cn=Monitor" is reserved for monitoring slap */
985 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
987 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
988 "%s\" is reserved for monitoring slapd\n",
989 fname, lineno, SLAPD_MONITOR_DN );
991 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
992 "%s\" is reserved for monitoring slapd\n",
993 fname, lineno, SLAPD_MONITOR_DN );
996 #endif /* SLAPD_MONITOR_DN */
999 if ( load_ucdata( NULL ) < 0 ) return 1;
1001 dn.bv_val = cargv[1];
1002 dn.bv_len = strlen( cargv[1] );
1004 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1005 if( rc != LDAP_SUCCESS ) {
1007 LDAP_LOG( CONFIG, CRIT,
1008 "%s: line %d: suffix DN is invalid.\n",
1011 Debug( LDAP_DEBUG_ANY,
1012 "%s: line %d: suffix DN is invalid\n",
1018 tmp_be = select_backend( &ndn, 0, 0 );
1019 if ( tmp_be == be ) {
1021 LDAP_LOG( CONFIG, INFO,
1022 "%s: line %d: suffix already served by this backend "
1023 "(ignored)\n", fname, lineno, 0 );
1025 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1026 "already served by this backend (ignored)\n",
1032 } else if ( tmp_be != NULL ) {
1034 LDAP_LOG( CONFIG, INFO,
1035 "%s: line %d: suffix already served by a preceding "
1036 "backend \"%s\"\n", fname, lineno,
1037 tmp_be->be_suffix[0].bv_val );
1039 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1040 "already served by a preceeding backend \"%s\"\n",
1041 fname, lineno, tmp_be->be_suffix[0].bv_val );
1047 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1049 LDAP_LOG( CONFIG, INFO,
1050 "%s: line %d: suffix DN empty and default search "
1051 "base provided \"%s\" (assuming okay).\n",
1052 fname, lineno, default_search_base.bv_val );
1054 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1055 "suffix DN empty and default "
1056 "search base provided \"%s\" (assuming okay)\n",
1057 fname, lineno, default_search_base.bv_val );
1061 ber_bvarray_add( &be->be_suffix, &pdn );
1062 ber_bvarray_add( &be->be_nsuffix, &ndn );
1064 /* set max deref depth */
1065 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1069 LDAP_LOG( CONFIG, CRIT,
1070 "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1071 " line\n", fname, lineno, 0 );
1073 Debug( LDAP_DEBUG_ANY,
1074 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1082 LDAP_LOG( CONFIG, INFO,
1083 "%s: line %d: depth line must appear inside a database "
1084 "definition.\n", fname, lineno ,0 );
1086 Debug( LDAP_DEBUG_ANY,
1087 "%s: line %d: depth line must appear inside a database definition.\n",
1092 } else if ((i = atoi(cargv[1])) < 0) {
1094 LDAP_LOG( CONFIG, INFO,
1095 "%s: line %d: depth must be positive.\n",
1098 Debug( LDAP_DEBUG_ANY,
1099 "%s: line %d: depth must be positive.\n",
1106 be->be_max_deref_depth = i;
1110 /* set magic "root" dn for this database */
1111 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1114 LDAP_LOG( CONFIG, INFO,
1115 "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1118 Debug( LDAP_DEBUG_ANY,
1119 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1128 LDAP_LOG( CONFIG, INFO,
1129 "%s: line %d: rootdn line must appear inside a database "
1130 "definition.\n", fname, lineno ,0 );
1132 Debug( LDAP_DEBUG_ANY,
1133 "%s: line %d: rootdn line must appear inside a database definition.\n",
1141 if ( load_ucdata( NULL ) < 0 ) return 1;
1143 dn.bv_val = cargv[1];
1144 dn.bv_len = strlen( cargv[1] );
1146 rc = dnPrettyNormal( NULL, &dn,
1148 &be->be_rootndn, NULL );
1150 if( rc != LDAP_SUCCESS ) {
1152 LDAP_LOG( CONFIG, CRIT,
1153 "%s: line %d: rootdn DN is invalid.\n",
1156 Debug( LDAP_DEBUG_ANY,
1157 "%s: line %d: rootdn DN is invalid\n",
1164 /* set super-secret magic database password */
1165 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1168 LDAP_LOG( CONFIG, CRIT,
1169 "%s: line %d: missing passwd in \"rootpw <passwd>\""
1170 " line\n", fname, lineno ,0 );
1172 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1173 "missing passwd in \"rootpw <passwd>\" line\n",
1182 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1183 "rootpw line must appear inside a database "
1184 "definition.\n", fname, lineno ,0 );
1186 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1187 "rootpw line must appear inside a database "
1194 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1196 if( tmp_be != be ) {
1198 LDAP_LOG( CONFIG, INFO,
1200 "rootpw can only be set when rootdn is under suffix\n",
1201 fname, lineno, "" );
1203 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1204 "rootpw can only be set when rootdn is under suffix\n",
1210 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1211 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1214 /* make this database read-only */
1215 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1218 LDAP_LOG( CONFIG, CRIT,
1219 "%s: line %d: missing on|off in \"readonly <on|off>\" "
1220 "line.\n", fname, lineno ,0 );
1222 Debug( LDAP_DEBUG_ANY,
1223 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1230 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1231 global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1233 global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1236 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1237 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1239 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1244 /* allow these features */
1245 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1246 strcasecmp( cargv[0], "allow" ) == 0 )
1252 LDAP_LOG( CONFIG, INFO,
1253 "%s: line %d: allow line must appear prior to "
1254 "database definitions.\n", fname, lineno ,0 );
1256 Debug( LDAP_DEBUG_ANY,
1257 "%s: line %d: allow line must appear prior to database definitions\n",
1265 LDAP_LOG( CONFIG, CRIT,
1266 "%s: line %d: missing feature(s) in \"allow <features>\""
1267 " line\n", fname, lineno ,0 );
1269 Debug( LDAP_DEBUG_ANY,
1270 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1279 for( i=1; i < cargc; i++ ) {
1280 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1281 allows |= SLAP_ALLOW_BIND_V2;
1283 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1284 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1286 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1287 allows |= SLAP_ALLOW_BIND_ANON_DN;
1289 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1290 allows |= SLAP_ALLOW_UPDATE_ANON;
1292 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1294 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1295 "unknown feature %s in \"allow <features>\" line.\n",
1296 fname, lineno, cargv[1] );
1298 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1299 "unknown feature %s in \"allow <features>\" line\n",
1300 fname, lineno, cargv[i] );
1307 global_allows = allows;
1309 /* disallow these features */
1310 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1311 strcasecmp( cargv[0], "disallow" ) == 0 )
1313 slap_mask_t disallows;
1317 LDAP_LOG( CONFIG, INFO,
1318 "%s: line %d: disallow line must appear prior to "
1319 "database definitions.\n", fname, lineno ,0 );
1321 Debug( LDAP_DEBUG_ANY,
1322 "%s: line %d: disallow line must appear prior to database definitions\n",
1330 LDAP_LOG( CONFIG, CRIT,
1331 "%s: line %d: missing feature(s) in \"disallow <features>\""
1332 " line.\n", fname, lineno ,0 );
1334 Debug( LDAP_DEBUG_ANY,
1335 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1344 for( i=1; i < cargc; i++ ) {
1345 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1346 disallows |= SLAP_DISALLOW_BIND_ANON;
1348 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1349 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1351 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1352 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1354 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1355 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1357 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1358 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1360 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1362 LDAP_LOG( CONFIG, CRIT,
1363 "%s: line %d: unknown feature %s in "
1364 "\"disallow <features>\" line.\n",
1365 fname, lineno, cargv[i] );
1367 Debug( LDAP_DEBUG_ANY,
1368 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1369 fname, lineno, cargv[i] );
1376 global_disallows = disallows;
1378 /* require these features */
1379 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1380 strcasecmp( cargv[0], "require" ) == 0 )
1382 slap_mask_t requires;
1386 LDAP_LOG( CONFIG, CRIT,
1387 "%s: line %d: missing feature(s) in "
1388 "\"require <features>\" line.\n", fname, lineno ,0 );
1390 Debug( LDAP_DEBUG_ANY,
1391 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1400 for( i=1; i < cargc; i++ ) {
1401 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1402 requires |= SLAP_REQUIRE_BIND;
1404 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1405 requires |= SLAP_REQUIRE_LDAP_V3;
1407 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1408 requires |= SLAP_REQUIRE_AUTHC;
1410 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1411 requires |= SLAP_REQUIRE_SASL;
1413 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1414 requires |= SLAP_REQUIRE_STRONG;
1416 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1418 LDAP_LOG( CONFIG, CRIT,
1419 "%s: line %d: unknown feature %s in "
1420 "\"require <features>\" line.\n",
1421 fname, lineno , cargv[i] );
1423 Debug( LDAP_DEBUG_ANY,
1424 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1425 fname, lineno, cargv[i] );
1433 global_requires = requires;
1435 be->be_requires = requires;
1438 /* required security factors */
1439 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1440 slap_ssf_set_t *set;
1444 LDAP_LOG( CONFIG, CRIT,
1445 "%s: line %d: missing factor(s) in \"security <factors>\""
1446 " line.\n", fname, lineno ,0 );
1448 Debug( LDAP_DEBUG_ANY,
1449 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1457 set = &global_ssf_set;
1459 set = &be->be_ssf_set;
1462 for( i=1; i < cargc; i++ ) {
1463 if( strncasecmp( cargv[i], "ssf=",
1464 sizeof("ssf") ) == 0 )
1467 atoi( &cargv[i][sizeof("ssf")] );
1469 } else if( strncasecmp( cargv[i], "transport=",
1470 sizeof("transport") ) == 0 )
1472 set->sss_transport =
1473 atoi( &cargv[i][sizeof("transport")] );
1475 } else if( strncasecmp( cargv[i], "tls=",
1476 sizeof("tls") ) == 0 )
1479 atoi( &cargv[i][sizeof("tls")] );
1481 } else if( strncasecmp( cargv[i], "sasl=",
1482 sizeof("sasl") ) == 0 )
1485 atoi( &cargv[i][sizeof("sasl")] );
1487 } else if( strncasecmp( cargv[i], "update_ssf=",
1488 sizeof("update_ssf") ) == 0 )
1490 set->sss_update_ssf =
1491 atoi( &cargv[i][sizeof("update_ssf")] );
1493 } else if( strncasecmp( cargv[i], "update_transport=",
1494 sizeof("update_transport") ) == 0 )
1496 set->sss_update_transport =
1497 atoi( &cargv[i][sizeof("update_transport")] );
1499 } else if( strncasecmp( cargv[i], "update_tls=",
1500 sizeof("update_tls") ) == 0 )
1502 set->sss_update_tls =
1503 atoi( &cargv[i][sizeof("update_tls")] );
1505 } else if( strncasecmp( cargv[i], "update_sasl=",
1506 sizeof("update_sasl") ) == 0 )
1508 set->sss_update_sasl =
1509 atoi( &cargv[i][sizeof("update_sasl")] );
1511 } else if( strncasecmp( cargv[i], "simple_bind=",
1512 sizeof("simple_bind") ) == 0 )
1514 set->sss_simple_bind =
1515 atoi( &cargv[i][sizeof("simple_bind")] );
1519 LDAP_LOG( CONFIG, CRIT,
1520 "%s: line %d: unknown factor %S in "
1521 "\"security <factors>\" line.\n",
1522 fname, lineno, cargv[1] );
1524 Debug( LDAP_DEBUG_ANY,
1525 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1526 fname, lineno, cargv[i] );
1532 /* where to send clients when we don't hold it */
1533 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1536 LDAP_LOG( CONFIG, CRIT,
1537 "%s: line %d: missing URL in \"referral <URL>\""
1538 " line.\n", fname, lineno , 0 );
1540 Debug( LDAP_DEBUG_ANY,
1541 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1548 if( validate_global_referral( cargv[1] ) ) {
1550 LDAP_LOG( CONFIG, CRIT,
1551 "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1552 fname, lineno, cargv[1] );
1554 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1555 "invalid URL (%s) in \"referral\" line.\n",
1556 fname, lineno, cargv[1] );
1561 vals[0].bv_val = cargv[1];
1562 vals[0].bv_len = strlen( vals[0].bv_val );
1563 if( value_add( &default_referral, vals ) )
1567 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1571 LDAP_LOG( CONFIG, CRIT,
1572 "%s: line %d: Error in logfile directive, "
1573 "\"logfile <filename>\"\n", fname, lineno , 0 );
1575 Debug( LDAP_DEBUG_ANY,
1576 "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1582 logfile = fopen( cargv[1], "w" );
1583 if ( logfile != NULL ) lutil_debug_file( logfile );
1586 /* start of a new database definition */
1587 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1591 LDAP_LOG( CONFIG, CRIT,
1592 "%s: line %d: Error in debug directive, "
1593 "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1595 Debug( LDAP_DEBUG_ANY,
1596 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1602 level = atoi( cargv[2] );
1603 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1604 lutil_set_debug_level( cargv[1], level );
1605 /* specify an Object Identifier macro */
1606 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1607 rc = parse_oidm( fname, lineno, cargc, cargv );
1610 /* specify an objectclass */
1611 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1614 LDAP_LOG( CONFIG, INFO,
1615 "%s: line %d: illegal objectclass format.\n",
1616 fname, lineno , 0 );
1618 Debug( LDAP_DEBUG_ANY,
1619 "%s: line %d: illegal objectclass format.\n",
1624 } else if ( *cargv[1] == '(' /*')'*/) {
1626 p = strchr(saveline,'(' /*')'*/);
1627 rc = parse_oc( fname, lineno, p, cargv );
1632 LDAP_LOG( CONFIG, INFO,
1633 "%s: line %d: old objectclass format not supported\n",
1634 fname, lineno , 0 );
1636 Debug( LDAP_DEBUG_ANY,
1637 "%s: line %d: old objectclass format not supported.\n",
1642 #ifdef SLAP_EXTENDED_SCHEMA
1643 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1645 p = strchr(saveline,'(' /*')'*/);
1646 rc = parse_cr( fname, lineno, p, cargv );
1650 /* specify an attribute type */
1651 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1652 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1656 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1657 "illegal attribute type format.\n",
1658 fname, lineno , 0 );
1660 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1661 "illegal attribute type format.\n",
1666 } else if ( *cargv[1] == '(' /*')'*/) {
1668 p = strchr(saveline,'(' /*')'*/);
1669 rc = parse_at( fname, lineno, p, cargv );
1674 LDAP_LOG( CONFIG, INFO,
1675 "%s: line %d: old attribute type format not supported.\n",
1676 fname, lineno , 0 );
1678 Debug( LDAP_DEBUG_ANY,
1679 "%s: line %d: old attribute type format not supported.\n",
1685 /* define attribute option(s) */
1686 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1687 ad_define_option( NULL, NULL, 0 );
1688 for ( i = 1; i < cargc; i++ )
1689 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1692 /* turn on/off schema checking */
1693 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1696 LDAP_LOG( CONFIG, CRIT,
1697 "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1698 " line.\n", fname, lineno , 0 );
1700 Debug( LDAP_DEBUG_ANY,
1701 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1707 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1709 LDAP_LOG( CONFIG, CRIT,
1710 "%s: line %d: schema checking disabled! your mileage may "
1711 "vary!\n", fname, lineno , 0 );
1713 Debug( LDAP_DEBUG_ANY,
1714 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1717 global_schemacheck = 0;
1719 global_schemacheck = 1;
1722 /* specify access control info */
1723 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1724 parse_acl( be, fname, lineno, cargc, cargv );
1726 /* debug level to log things to syslog */
1727 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1730 LDAP_LOG( CONFIG, CRIT,
1731 "%s: line %d: missing level in \"loglevel <level>\""
1732 " line.\n", fname, lineno , 0 );
1734 Debug( LDAP_DEBUG_ANY,
1735 "%s: line %d: missing level in \"loglevel <level>\" line\n",
1744 for( i=1; i < cargc; i++ ) {
1745 ldap_syslog += atoi( cargv[1] );
1748 /* list of sync replication information in this backend (slave only) */
1749 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1753 LDAP_LOG( CONFIG, INFO,
1754 "%s: line %d: syncrepl line must appear inside "
1755 "a database definition.\n", fname, lineno, 0);
1757 Debug( LDAP_DEBUG_ANY,
1758 "%s: line %d: syncrepl line must appear inside "
1759 "a database definition.\n", fname, lineno, 0);
1763 if ( add_syncrepl( be, cargv, cargc )) {
1768 /* list of replicas of the data in this backend (master only) */
1769 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1772 LDAP_LOG( CONFIG, CRIT,
1773 "%s: line %d: missing host or uri in \"replica "
1774 " <host[:port]\" line\n", fname, lineno , 0 );
1776 Debug( LDAP_DEBUG_ANY,
1777 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1785 LDAP_LOG( CONFIG, INFO,
1786 "%s: line %d: replica line must appear inside "
1787 "a database definition.\n", fname, lineno, 0);
1789 Debug( LDAP_DEBUG_ANY,
1790 "%s: line %d: replica line must appear inside a database definition\n",
1798 for ( i = 1; i < cargc; i++ ) {
1799 if ( strncasecmp( cargv[i], "host=", 5 )
1801 nr = add_replica_info( be,
1804 } else if (strncasecmp( cargv[i], "uri=", 4 )
1806 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1809 LDAP_LOG( CONFIG, INFO,
1810 "%s: line %d: replica line contains invalid "
1811 "uri definition.\n", fname, lineno, 0);
1813 Debug( LDAP_DEBUG_ANY,
1814 "%s: line %d: replica line contains invalid "
1815 "uri definition.\n", fname, lineno, 0);
1819 if (ludp->lud_host == NULL ) {
1821 LDAP_LOG( CONFIG, INFO,
1822 "%s: line %d: replica line contains invalid "
1823 "uri definition - missing hostname.\n",
1826 Debug( LDAP_DEBUG_ANY,
1827 "%s: line %d: replica line contains invalid "
1828 "uri definition - missing hostname.\n", fname, lineno, 0);
1832 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1833 if ( replicahost == NULL ) {
1835 LDAP_LOG( CONFIG, ERR,
1836 "out of memory in read_config\n", 0, 0,0 );
1838 Debug( LDAP_DEBUG_ANY,
1839 "out of memory in read_config\n", 0, 0, 0 );
1841 ldap_free_urldesc( ludp );
1842 exit( EXIT_FAILURE );
1844 sprintf(replicahost, "%s:%d",
1845 ludp->lud_host, ludp->lud_port);
1846 nr = add_replica_info( be, replicahost );
1847 ldap_free_urldesc( ludp );
1848 ch_free(replicahost);
1854 LDAP_LOG( CONFIG, INFO,
1855 "%s: line %d: missing host or uri in \"replica\" line\n",
1856 fname, lineno , 0 );
1858 Debug( LDAP_DEBUG_ANY,
1859 "%s: line %d: missing host or uri in \"replica\" line\n",
1864 } else if ( nr == -1 ) {
1866 LDAP_LOG( CONFIG, INFO,
1867 "%s: line %d: unable to add"
1868 " replica \"%s\"\n",
1872 Debug( LDAP_DEBUG_ANY,
1873 "%s: line %d: unable to add replica \"%s\"\n",
1874 fname, lineno, cargv[i] + 5 );
1878 for ( i = 1; i < cargc; i++ ) {
1879 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1881 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1884 LDAP_LOG( CONFIG, INFO,
1885 "%s: line %d: suffix \"%s\" in \"replica\""
1886 " line is not valid for backend(ignored)\n",
1887 fname, lineno, cargv[i] + 7 );
1889 Debug( LDAP_DEBUG_ANY,
1890 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1891 fname, lineno, cargv[i] + 7 );
1897 LDAP_LOG( CONFIG, INFO,
1898 "%s: line %d: unable to normalize suffix"
1899 " in \"replica\" line (ignored)\n",
1900 fname, lineno , 0 );
1902 Debug( LDAP_DEBUG_ANY,
1903 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1909 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1911 char *arg = cargv[i] + 4;
1913 if ( arg[0] == '!' ) {
1918 if ( arg[0] != '=' ) {
1922 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1924 LDAP_LOG( CONFIG, INFO,
1925 "%s: line %d: attribute \"%s\" in "
1926 "\"replica\" line is unknown\n",
1927 fname, lineno, arg + 1 );
1929 Debug( LDAP_DEBUG_ANY,
1930 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1931 fname, lineno, arg + 1 );
1940 /* dn of master entity allowed to write to replica */
1941 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1944 LDAP_LOG( CONFIG, CRIT,
1945 "%s: line %d: missing dn in \"updatedn <dn>\""
1946 " line.\n", fname, lineno , 0 );
1948 Debug( LDAP_DEBUG_ANY,
1949 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1957 LDAP_LOG( CONFIG, INFO,
1958 "%s: line %d: updatedn line must appear inside "
1959 "a database definition\n",
1960 fname, lineno , 0 );
1962 Debug( LDAP_DEBUG_ANY,
1963 "%s: line %d: updatedn line must appear inside a database definition\n",
1971 if ( load_ucdata( NULL ) < 0 ) return 1;
1973 dn.bv_val = cargv[1];
1974 dn.bv_len = strlen( cargv[1] );
1976 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1977 if( rc != LDAP_SUCCESS ) {
1979 LDAP_LOG( CONFIG, CRIT,
1980 "%s: line %d: updatedn DN is invalid.\n",
1981 fname, lineno , 0 );
1983 Debug( LDAP_DEBUG_ANY,
1984 "%s: line %d: updatedn DN is invalid\n",
1991 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1994 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1995 "missing url in \"updateref <ldapurl>\" line.\n",
1996 fname, lineno , 0 );
1998 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1999 "missing url in \"updateref <ldapurl>\" line\n",
2007 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2008 " line must appear inside a database definition\n",
2009 fname, lineno , 0 );
2011 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2012 " line must appear inside a database definition\n",
2017 } else if ( !be->be_update_ndn.bv_len ) {
2019 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2020 "updateref line must come after updatedn.\n",
2021 fname, lineno , 0 );
2023 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2024 "updateref line must after updatedn.\n",
2030 if( validate_global_referral( cargv[1] ) ) {
2032 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2033 "invalid URL (%s) in \"updateref\" line.\n",
2034 fname, lineno, cargv[1] );
2036 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2037 "invalid URL (%s) in \"updateref\" line.\n",
2038 fname, lineno, cargv[1] );
2043 vals[0].bv_val = cargv[1];
2044 vals[0].bv_len = strlen( vals[0].bv_val );
2045 if( value_add( &be->be_update_refs, vals ) )
2048 /* replication log file to which changes are appended */
2049 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2052 LDAP_LOG( CONFIG, CRIT,
2053 "%s: line %d: missing filename in \"replogfile <filename>\""
2054 " line.\n", fname, lineno , 0 );
2056 Debug( LDAP_DEBUG_ANY,
2057 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2064 be->be_replogfile = ch_strdup( cargv[1] );
2066 replogfile = ch_strdup( cargv[1] );
2069 /* file from which to read additional rootdse attrs */
2070 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2073 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2074 "missing filename in \"rootDSE <filename>\" line.\n",
2075 fname, lineno , 0 );
2077 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2078 "missing filename in \"rootDSE <filename>\" line.\n",
2084 if( read_root_dse_file( cargv[1] ) ) {
2086 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2087 "could not read \"rootDSE <filename>\" line.\n",
2088 fname, lineno , 0 );
2090 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2091 "could not read \"rootDSE <filename>\" line\n",
2097 /* maintain lastmodified{by,time} attributes */
2098 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2101 LDAP_LOG( CONFIG, CRIT,
2102 "%s: line %d: missing on|off in \"lastmod <on|off>\""
2103 " line.\n", fname, lineno , 0 );
2105 Debug( LDAP_DEBUG_ANY,
2106 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2112 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2114 be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
2120 be->be_flags |= SLAP_BFLAG_NOLASTMOD;
2127 /* turn on/off gentle SIGHUP handling */
2128 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2130 Debug( LDAP_DEBUG_ANY,
2131 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2135 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2136 global_gentlehup = 0;
2138 global_gentlehup = 1;
2142 /* set idle timeout value */
2143 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2147 LDAP_LOG( CONFIG, CRIT,
2148 "%s: line %d: missing timeout value in "
2149 "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2151 Debug( LDAP_DEBUG_ANY,
2152 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2159 i = atoi( cargv[1] );
2163 LDAP_LOG( CONFIG, CRIT,
2164 "%s: line %d: timeout value (%d) invalid "
2165 "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2167 Debug( LDAP_DEBUG_ANY,
2168 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2175 global_idletimeout = i;
2177 /* include another config file */
2178 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2181 LDAP_LOG( CONFIG, CRIT,
2182 "%s: line %d: missing filename in \"include "
2183 "<filename>\" line.\n", fname, lineno , 0 );
2185 Debug( LDAP_DEBUG_ANY,
2186 "%s: line %d: missing filename in \"include <filename>\" line\n",
2192 savefname = ch_strdup( cargv[1] );
2193 savelineno = lineno;
2195 if ( read_config( savefname, depth+1 ) != 0 ) {
2200 lineno = savelineno - 1;
2202 /* location of kerberos srvtab file */
2203 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2206 LDAP_LOG( CONFIG, CRIT,
2207 "%s: line %d: missing filename in \"srvtab "
2208 "<filename>\" line.\n", fname, lineno , 0 );
2210 Debug( LDAP_DEBUG_ANY,
2211 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2217 ldap_srvtab = ch_strdup( cargv[1] );
2219 #ifdef SLAPD_MODULES
2220 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2223 LDAP_LOG( CONFIG, INFO,
2224 "%s: line %d: missing filename in \"moduleload "
2225 "<filename>\" line.\n", fname, lineno , 0 );
2227 Debug( LDAP_DEBUG_ANY,
2228 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2232 exit( EXIT_FAILURE );
2234 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2236 LDAP_LOG( CONFIG, CRIT,
2237 "%s: line %d: failed to load or initialize module %s\n",
2238 fname, lineno, cargv[1] );
2240 Debug( LDAP_DEBUG_ANY,
2241 "%s: line %d: failed to load or initialize module %s\n",
2242 fname, lineno, cargv[1]);
2245 exit( EXIT_FAILURE );
2247 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2250 LDAP_LOG( CONFIG, INFO,
2251 "%s: line %d: missing path in \"modulepath <path>\""
2252 " line\n", fname, lineno , 0 );
2254 Debug( LDAP_DEBUG_ANY,
2255 "%s: line %d: missing path in \"modulepath <path>\" line\n",
2259 exit( EXIT_FAILURE );
2261 if (module_path( cargv[1] )) {
2263 LDAP_LOG( CONFIG, CRIT,
2264 "%s: line %d: failed to set module search path to %s.\n",
2265 fname, lineno, cargv[1] );
2267 Debug( LDAP_DEBUG_ANY,
2268 "%s: line %d: failed to set module search path to %s\n",
2269 fname, lineno, cargv[1]);
2272 exit( EXIT_FAILURE );
2275 #endif /*SLAPD_MODULES*/
2278 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2279 rc = ldap_pvt_tls_set_option( NULL,
2280 LDAP_OPT_X_TLS_RANDOM_FILE,
2285 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2286 rc = ldap_pvt_tls_set_option( NULL,
2287 LDAP_OPT_X_TLS_CIPHER_SUITE,
2292 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2293 rc = ldap_pvt_tls_set_option( NULL,
2294 LDAP_OPT_X_TLS_CERTFILE,
2299 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2300 rc = ldap_pvt_tls_set_option( NULL,
2301 LDAP_OPT_X_TLS_KEYFILE,
2306 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2307 rc = ldap_pvt_tls_set_option( NULL,
2308 LDAP_OPT_X_TLS_CACERTDIR,
2313 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2314 rc = ldap_pvt_tls_set_option( NULL,
2315 LDAP_OPT_X_TLS_CACERTFILE,
2319 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2320 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2322 rc = ldap_pvt_tls_set_option( NULL,
2323 LDAP_OPT_X_TLS_REQUIRE_CERT,
2326 rc = ldap_int_tls_config( NULL,
2327 LDAP_OPT_X_TLS_REQUIRE_CERT,
2336 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2337 #ifdef SLAPD_RLOOKUPS
2340 LDAP_LOG( CONFIG, INFO,
2341 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2342 fname, lineno , 0 );
2344 Debug( LDAP_DEBUG_ANY,
2345 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2351 if ( !strcasecmp( cargv[1], "on" ) ) {
2352 use_reverse_lookup = 1;
2353 } else if ( !strcasecmp( cargv[1], "off" ) ) {
2354 use_reverse_lookup = 0;
2357 LDAP_LOG( CONFIG, INFO,
2358 "%s: line %d: reverse-lookup: "
2359 "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2361 Debug( LDAP_DEBUG_ANY,
2362 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2368 #else /* !SLAPD_RLOOKUPS */
2370 LDAP_LOG( CONFIG, INFO,
2371 "%s: line %d: reverse lookups "
2372 "are not configured (ignored).\n", fname, lineno , 0 );
2374 Debug( LDAP_DEBUG_ANY,
2375 "%s: line %d: reverse lookups are not configured (ignored).\n",
2378 #endif /* !SLAPD_RLOOKUPS */
2380 /* Netscape plugins */
2381 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2382 #if defined( LDAP_SLAPI )
2384 #ifdef notdef /* allow global plugins, too */
2386 * a "plugin" line must be inside a database
2387 * definition, since we implement pre-,post-
2388 * and extended operation plugins
2392 LDAP_LOG( CONFIG, INFO,
2393 "%s: line %d: plugin line must appear "
2394 "insid a database definition.\n",
2397 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2398 "line must appear inside a database "
2399 "definition\n", fname, lineno, 0 );
2405 if ( netscape_plugin( be, fname, lineno, cargc, cargv )
2410 #else /* !defined( LDAP_SLAPI ) */
2412 LDAP_LOG( CONFIG, INFO,
2413 "%s: line %d: SLAPI not supported.\n",
2416 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2417 "not supported.\n", fname, lineno, 0 );
2421 #endif /* !defined( LDAP_SLAPI ) */
2423 /* Netscape plugins */
2424 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2425 #if defined( LDAP_SLAPI )
2428 LDAP_LOG( CONFIG, INFO,
2429 "%s: line %d: missing file name "
2430 "in pluginlog <filename> line.\n",
2433 Debug( LDAP_DEBUG_ANY,
2434 "%s: line %d: missing file name "
2435 "in pluginlog <filename> line.\n",
2441 if ( slapi_log_file != NULL ) {
2442 ch_free( slapi_log_file );
2445 slapi_log_file = ch_strdup( cargv[1] );
2446 #endif /* !defined( LDAP_SLAPI ) */
2448 /* pass anything else to the current backend info/db config routine */
2451 if ( bi->bi_config == 0 ) {
2453 LDAP_LOG( CONFIG, INFO,
2454 "%s: line %d: unknown directive \"%s\" inside "
2455 "backend info definition (ignored).\n",
2456 fname, lineno, cargv[0] );
2458 Debug( LDAP_DEBUG_ANY,
2459 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2460 fname, lineno, cargv[0] );
2464 if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2470 } else if ( be != NULL ) {
2471 if ( be->be_config == 0 ) {
2473 LDAP_LOG( CONFIG, INFO,
2474 "%s: line %d: uknown directive \"%s\" inside "
2475 "backend database definition (ignored).\n",
2476 fname, lineno, cargv[0] );
2478 Debug( LDAP_DEBUG_ANY,
2479 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2480 fname, lineno, cargv[0] );
2484 if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2492 LDAP_LOG( CONFIG, INFO,
2493 "%s: line %d: unknown directive \"%s\" outside backend "
2494 "info and database definitions (ignored).\n",
2495 fname, lineno, cargv[0] );
2497 Debug( LDAP_DEBUG_ANY,
2498 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2499 fname, lineno, cargv[0] );
2508 if ( depth == 0 ) ch_free( cargv );
2510 if ( !global_schemadn.bv_val ) {
2511 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2513 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2516 if ( load_ucdata( NULL ) < 0 ) return 1;
2528 char logbuf[sizeof("pseudorootpw ***")];
2531 token = strtok_quote( line, " \t" );
2535 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2536 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2537 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2538 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2539 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2541 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2544 if ( strtok_quote_ptr ) {
2545 *strtok_quote_ptr = ' ';
2549 LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2551 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2554 if ( strtok_quote_ptr ) {
2555 *strtok_quote_ptr = '\0';
2558 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2559 if ( cargc == cargv_size - 1 ) {
2561 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2563 if ( tmp == NULL ) {
2565 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2567 Debug( LDAP_DEBUG_ANY,
2568 "line %d: out of memory\n",
2574 cargv_size += ARGS_STEP;
2576 cargv[cargc++] = token;
2578 cargv[cargc] = NULL;
2583 strtok_quote( char *line, char *sep )
2589 strtok_quote_ptr = NULL;
2590 if ( line != NULL ) {
2593 while ( *next && strchr( sep, *next ) ) {
2597 if ( *next == '\0' ) {
2603 for ( inquote = 0; *next; ) {
2611 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2617 next + 1, strlen( next + 1 ) + 1 );
2618 next++; /* dont parse the escaped character */
2623 if ( strchr( sep, *next ) != NULL ) {
2624 strtok_quote_ptr = next;
2637 static char buf[BUFSIZ];
2639 static size_t lmax, lcur;
2641 #define CATLINE( buf ) \
2643 size_t len = strlen( buf ); \
2644 while ( lcur + len + 1 > lmax ) { \
2646 line = (char *) ch_realloc( line, lmax ); \
2648 strcpy( line + lcur, buf ); \
2653 fp_getline( FILE *fp, int *lineno )
2661 /* hack attack - keeps us from having to keep a stack of bufs... */
2662 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2667 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2668 /* trim off \r\n or \n */
2669 if ( (p = strchr( buf, '\n' )) != NULL ) {
2670 if( p > buf && p[-1] == '\r' ) --p;
2674 /* trim off trailing \ and append the next line */
2675 if ( line[ 0 ] != '\0'
2676 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2677 && p[ -1 ] != '\\' ) {
2682 if ( ! isspace( (unsigned char) buf[0] ) ) {
2686 /* change leading whitespace to a space */
2695 return( line[0] ? line : NULL );
2699 fp_getline_init( int *lineno )
2705 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2707 load_ucdata( char *path )
2709 static int loaded = 0;
2715 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2718 LDAP_LOG( CONFIG, CRIT,
2719 "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2721 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2734 ucdata_unload( UCDATA_ALL );
2735 free( global_schemandn.bv_val );
2736 free( global_schemadn.bv_val );
2738 if ( slapd_args_file )
2739 free ( slapd_args_file );
2740 if ( slapd_pid_file )
2741 free ( slapd_pid_file );
2742 if ( default_passwd_hash )
2743 free( default_passwd_hash );
2744 acl_destroy( global_acl, NULL );
2756 if ( be->syncinfo ) {
2758 LDAP_LOG( CONFIG, INFO,
2759 "add_syncrepl: multiple syncrepl lines in a database "
2760 "definition are yet to be supported.\n", 0, 0, 0 );
2762 Debug( LDAP_DEBUG_ANY,
2763 "add_syncrepl: multiple syncrepl lines in a database "
2764 "definition are yet to be supported.\n", 0, 0, 0 );
2769 si = be->syncinfo = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2773 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2775 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2781 if ( be->be_rootndn.bv_val )
2782 ber_dupbv( &si->updatedn, &be->be_rootndn );
2783 si->bindmethod = LDAP_AUTH_SIMPLE;
2784 si->schemachecking = 0;
2785 si->filterstr = "(objectclass=*)";
2786 if ( be->be_suffix && be->be_suffix[0].bv_val )
2787 si->base = ch_strdup( be->be_suffix[0].bv_val );
2788 si->scope = LDAP_SCOPE_SUBTREE;
2790 si->attrs = (char **) ch_calloc( 1, sizeof( char * ));
2791 si->attrs[0] = NULL;
2792 si->type = LDAP_SYNC_REFRESH_ONLY;
2793 si->interval = 86400;
2794 si->syncCookie = NULL;
2795 si->manageDSAit = 0;
2798 si->syncUUID = NULL;
2799 si->syncUUID_ndn = NULL;
2800 si->sync_mode = LDAP_SYNC_STATE_MODE;
2802 si->presentlist = NULL;
2803 LDAP_LIST_INIT( &si->nonpresentlist );
2805 if ( parse_syncrepl_line( cargv, cargc, si ) < 0 ) {
2806 /* Something bad happened - back out */
2808 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2810 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2813 be->syncinfo = NULL;
2817 LDAP_LOG ( CONFIG, RESULTS,
2818 "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2819 si->provideruri == NULL ? "(null)" : si->provideruri, 0, 0 );
2821 Debug( LDAP_DEBUG_CONFIG,
2822 "Config: ** successfully added syncrepl \"%s\"\n",
2823 si->provideruri == NULL ? "(null)" : si->provideruri, 0, 0 );
2825 if ( !si->schemachecking ) {
2826 be->be_flags |= SLAP_BFLAG_NO_SCHEMA_CHECK;
2834 #define PROVIDERSTR "provider"
2835 #define SUFFIXSTR "suffix"
2836 #define UPDATEDNSTR "updatedn"
2837 #define BINDMETHSTR "bindmethod"
2838 #define SIMPLESTR "simple"
2839 #define SASLSTR "sasl"
2840 #define BINDDNSTR "binddn"
2841 #define CREDSTR "credentials"
2842 #define OLDAUTHCSTR "bindprincipal"
2843 #define AUTHCSTR "authcID"
2844 #define AUTHZSTR "authzID"
2845 #define SRVTABSTR "srvtab"
2846 #define SASLMECHSTR "saslmech"
2847 #define REALMSTR "realm"
2848 #define SECPROPSSTR "secprops"
2849 #define STARTTLSSTR "starttls"
2850 #define CRITICALSTR "critical"
2852 #define SCHEMASTR "schemachecking"
2853 #define FILTERSTR "filter"
2854 #define SEARCHBASESTR "searchbase"
2855 #define SCOPESTR "scope"
2856 #define ATTRSSTR "attrs"
2857 #define ATTRSONLYSTR "attrsonly"
2858 #define TYPESTR "type"
2859 #define INTERVALSTR "interval"
2860 #define COOKIESTR "cookie"
2861 #define LASTMODSTR "lastmod"
2862 #define LMREQSTR "req"
2863 #define LMGENSTR "gen"
2864 #define LMNOSTR "no"
2865 #define MANAGEDSAITSTR "manageDSAit"
2866 #define SLIMITSTR "sizelimit"
2867 #define TLIMITSTR "timelimit"
2869 #define GOT_ID 0x0001
2870 #define GOT_PROVIDER 0x0002
2871 #define GOT_METHOD 0x0004
2872 #define GOT_ALL 0x0007
2875 parse_syncrepl_line(
2886 for ( i = 1; i < cargc; i++ ) {
2887 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2888 /* '\0' string terminator accounts for '=' */
2889 val = cargv[ i ] + sizeof( IDSTR );
2890 si->id = atoi( val );
2892 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2893 sizeof( PROVIDERSTR ) - 1 )) {
2894 val = cargv[ i ] + sizeof( PROVIDERSTR );
2895 si->provideruri = ch_strdup( val );
2896 si->provideruri_bv = (BerVarray) ch_calloc( 2, sizeof( struct berval ));
2897 ber_str2bv( si->provideruri, strlen( si->provideruri ), 0, &si->provideruri_bv[0] );
2898 si->provideruri_bv[1].bv_len = 0;
2899 si->provideruri_bv[1].bv_val = NULL;
2900 gots |= GOT_PROVIDER;
2901 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2902 sizeof(STARTTLSSTR) - 1 ) )
2904 val = cargv[ i ] + sizeof( STARTTLSSTR );
2905 if( !strcasecmp( val, CRITICALSTR ) ) {
2906 si->tls = TLS_CRITICAL;
2910 } else if ( !strncasecmp( cargv[ i ],
2911 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) ) {
2913 struct berval updatedn = {0, NULL};
2914 val = cargv[ i ] + sizeof( UPDATEDNSTR );
2915 str = ch_strdup( val );
2916 ber_str2bv( str, strlen(str), 1, &updatedn );
2917 dnNormalize( 0, NULL, NULL, &updatedn, &si->updatedn, NULL );
2919 ch_free( updatedn.bv_val );
2920 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
2921 sizeof( BINDMETHSTR ) - 1 ) ) {
2922 val = cargv[ i ] + sizeof( BINDMETHSTR );
2923 if ( !strcasecmp( val, SIMPLESTR )) {
2924 si->bindmethod = LDAP_AUTH_SIMPLE;
2926 } else if ( !strcasecmp( val, SASLSTR )) {
2927 si->bindmethod = LDAP_AUTH_SASL;
2930 si->bindmethod = -1;
2932 } else if ( !strncasecmp( cargv[ i ],
2933 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
2934 val = cargv[ i ] + sizeof( BINDDNSTR );
2935 si->binddn = ch_strdup( val );
2936 } else if ( !strncasecmp( cargv[ i ],
2937 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
2938 val = cargv[ i ] + sizeof( CREDSTR );
2939 si->passwd = ch_strdup( val );
2940 } else if ( !strncasecmp( cargv[ i ],
2941 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
2942 val = cargv[ i ] + sizeof( SASLMECHSTR );
2943 si->saslmech = ch_strdup( val );
2944 } else if ( !strncasecmp( cargv[ i ],
2945 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
2946 val = cargv[ i ] + sizeof( SECPROPSSTR );
2947 si->secprops = ch_strdup( val );
2948 } else if ( !strncasecmp( cargv[ i ],
2949 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
2950 val = cargv[ i ] + sizeof( REALMSTR );
2951 si->realm = ch_strdup( val );
2952 } else if ( !strncasecmp( cargv[ i ],
2953 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
2954 val = cargv[ i ] + sizeof( AUTHCSTR );
2955 si->authcId = ch_strdup( val );
2956 } else if ( !strncasecmp( cargv[ i ],
2957 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
2958 /* Old authcID is provided for some backwards compatibility */
2959 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
2960 si->authcId = ch_strdup( val );
2961 } else if ( !strncasecmp( cargv[ i ],
2962 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
2963 val = cargv[ i ] + sizeof( AUTHZSTR );
2964 si->authzId = ch_strdup( val );
2965 } else if ( !strncasecmp( cargv[ i ],
2966 SRVTABSTR, sizeof( SRVTABSTR ) - 1 ) ) {
2967 val = cargv[ i ] + sizeof( SRVTABSTR );
2968 if ( si->srvtab != NULL ) {
2971 si->srvtab = ch_strdup( val );
2972 } else if ( !strncasecmp( cargv[ i ],
2973 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) ) {
2974 val = cargv[ i ] + sizeof( SCHEMASTR );
2975 if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
2976 si->schemachecking = 1;
2977 } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
2978 si->schemachecking = 0;
2980 si->schemachecking = 1;
2982 } else if ( !strncasecmp( cargv[ i ],
2983 FILTERSTR, sizeof( FILTERSTR ) - 1 ) ) {
2984 val = cargv[ i ] + sizeof( FILTERSTR );
2985 si->filterstr = ch_strdup( val );
2986 } else if ( !strncasecmp( cargv[ i ],
2987 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) ) {
2988 val = cargv[ i ] + sizeof( SEARCHBASESTR );
2989 si->base = ch_strdup( val );
2990 } else if ( !strncasecmp( cargv[ i ],
2991 SCOPESTR, sizeof( SCOPESTR ) - 1 ) ) {
2992 val = cargv[ i ] + sizeof( SCOPESTR );
2993 if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
2994 si->scope = LDAP_SCOPE_BASE;
2995 } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
2996 si->scope = LDAP_SCOPE_ONELEVEL;
2997 } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
2998 si->scope = LDAP_SCOPE_SUBTREE;
3000 fprintf( stderr, "Error: parse_syncrepl_line: "
3001 "unknown scope \"%s\"\n", val);
3004 } else if ( !strncasecmp( cargv[ i ],
3005 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) ) {
3007 } else if ( !strncasecmp( cargv[ i ],
3008 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) ) {
3009 val = cargv[ i ] + sizeof( ATTRSSTR );
3010 str2clist( &si->attrs, val, "," );
3011 } else if ( !strncasecmp( cargv[ i ],
3012 TYPESTR, sizeof( TYPESTR ) - 1 ) ) {
3013 val = cargv[ i ] + sizeof( TYPESTR );
3014 if ( !strncasecmp( val, "refreshOnly", sizeof( "refreshOnly" ) - 1 )) {
3015 si->type = LDAP_SYNC_REFRESH_ONLY;
3016 } else if ( !strncasecmp( val, "refreshAndPersist", sizeof( "refreshAndPersist" ) - 1 )) {
3017 si->type = LDAP_SYNC_REFRESH_AND_PERSIST;
3020 fprintf( stderr, "Error: parse_syncrepl_line: "
3021 "unknown sync type \"%s\"\n", val);
3024 } else if ( !strncasecmp( cargv[ i ],
3025 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) {
3026 val = cargv[ i ] + sizeof( INTERVALSTR );
3027 if ( si->type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3034 hstr = strchr( dstr, ':' );
3035 if ( hstr == NULL ) {
3036 fprintf( stderr, "Error: parse_syncrepl_line: "
3037 "invalid interval \"%s\"\n", val );
3041 mstr = strchr( hstr, ':' );
3042 if ( mstr == NULL ) {
3043 fprintf( stderr, "Error: parse_syncrepl_line: "
3044 "invalid interval \"%s\"\n", val );
3048 si->interval = (( atoi( dstr ) * 24 + atoi( hstr )) * 60
3049 + atoi( mstr )) * 60;
3051 if ( si->interval < 0 ) {
3052 fprintf( stderr, "Error: parse_syncrepl_line: "
3053 "invalid interval \"%ld\"\n",
3054 (long) si->interval);
3057 } else if ( !strncasecmp( cargv[ i ],
3058 COOKIESTR, sizeof( COOKIESTR ) - 1 ) ) {
3059 val = cargv[ i ] + sizeof( COOKIESTR );
3060 si->syncCookie = ber_str2bv( val, strlen( val ), 1, NULL );
3061 } else if ( !strncasecmp( cargv[ i ],
3062 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) ) {
3063 val = cargv[ i ] + sizeof( COOKIESTR );
3064 si->manageDSAit = atoi( val );
3065 } else if ( !strncasecmp( cargv[ i ],
3066 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) ) {
3067 val = cargv[ i ] + sizeof( SLIMITSTR );
3068 si->slimit = atoi( val );
3069 } else if ( !strncasecmp( cargv[ i ],
3070 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) ) {
3071 val = cargv[ i ] + sizeof( TLIMITSTR );
3072 si->tlimit = atoi( val );
3074 fprintf( stderr, "Error: parse_syncrepl_line: "
3075 "unknown keyword \"%s\"\n", cargv[ i ] );
3079 if ( gots != GOT_ALL ) {
3080 fprintf( stderr, "Error: Malformed \"syncrepl\" line in slapd config file"
3089 str2clist( char ***out, char *in, const char *brkstr )
3098 /* find last element in list */
3099 for (i = 0; *out && *out[i]; i++);
3101 /* protect the input string from strtok */
3102 str = ch_strdup( in );
3104 if ( *str == '\0' ) {
3109 /* Count words in string */
3111 for ( s = str; *s; s++ ) {
3112 if ( strchr( brkstr, *s ) != NULL ) {
3117 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3119 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3121 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3123 *new = ch_strdup( s );