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 slap_mask_t global_allows = 0;
50 slap_mask_t global_disallows = 0;
52 int global_gentlehup = 0;
53 int global_idletimeout = 0;
54 char *global_host = NULL;
55 char *global_realm = NULL;
56 char *ldap_srvtab = "";
57 char **default_passwd_hash = NULL;
58 int cargc = 0, cargv_size = 0;
60 struct berval default_search_base = BER_BVNULL;
61 struct berval default_search_nbase = BER_BVNULL;
62 unsigned num_subordinates = 0;
64 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
65 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
67 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
68 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
70 char *slapd_pid_file = NULL;
71 char *slapd_args_file = NULL;
73 char *strtok_quote_ptr;
75 int use_reverse_lookup = 0;
78 int slapi_plugins_used = 0;
81 static char *fp_getline(FILE *fp, int *lineno);
82 static void fp_getline_init(int *lineno);
83 static int fp_parse_line(int lineno, char *line);
85 static char *strtok_quote(char *line, char *sep);
86 static int load_ucdata(char *path);
88 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
89 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
92 read_config( const char *fname, int depth )
95 char *line, *savefname, *saveline;
99 struct berval vals[2];
102 static BackendInfo *bi = NULL;
103 static BackendDB *be = NULL;
107 vals[1].bv_val = NULL;
110 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
111 cargv_size = ARGS_STEP + 1;
114 if ( (fp = fopen( fname, "r" )) == NULL ) {
116 Debug( LDAP_DEBUG_ANY,
117 "could not open config file \"%s\": %s (%d)\n",
118 fname, strerror(errno), errno );
122 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
125 fp_getline_init( &lineno );
127 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
128 /* skip comments and blank lines */
129 if ( line[0] == '#' || line[0] == '\0' ) {
133 /* fp_parse_line is destructive, we save a copy */
134 saveline = ch_strdup( line );
136 if ( fp_parse_line( lineno, line ) != 0 ) {
141 Debug( LDAP_DEBUG_ANY,
142 "%s: line %d: bad config line (ignored)\n",
148 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
150 Debug( LDAP_DEBUG_ANY,
151 "%s: line %d: missing type in \"backend <type>\" line\n",
158 Debug( LDAP_DEBUG_ANY,
159 "%s: line %d: backend line must appear before any database definition\n",
165 bi = backend_info( cargv[1] );
168 Debug( LDAP_DEBUG_ANY,
169 "backend %s initialization failed.\n",
174 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
176 Debug( LDAP_DEBUG_ANY,
177 "%s: line %d: missing type in \"database <type>\" line\n",
184 be = backend_db_init( cargv[1] );
187 Debug( LDAP_DEBUG_ANY,
188 "database %s initialization failed.\n",
194 /* set thread concurrency */
195 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
198 Debug( LDAP_DEBUG_ANY,
199 "%s: line %d: missing level in \"concurrency <level>\" line\n",
205 c = strtol( cargv[1], &next, 10 );
206 if ( next == NULL || next[0] != '\0' ) {
207 Debug( LDAP_DEBUG_ANY,
208 "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" line\n",
209 fname, lineno, cargv[1] );
214 Debug( LDAP_DEBUG_ANY,
215 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
221 ldap_pvt_thread_set_concurrency( c );
223 /* set sockbuf max */
224 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
227 Debug( LDAP_DEBUG_ANY,
228 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
234 max = atol( cargv[1] );
237 Debug( LDAP_DEBUG_ANY,
238 "%s: line %d: invalid max value (%ld) in "
239 "\"sockbuf_max_incoming <bytes>\" line.\n",
240 fname, lineno, max );
245 sockbuf_max_incoming = max;
247 /* set sockbuf max authenticated */
248 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
251 Debug( LDAP_DEBUG_ANY,
252 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
258 max = atol( cargv[1] );
261 Debug( LDAP_DEBUG_ANY,
262 "%s: line %d: invalid max value (%ld) in "
263 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
264 fname, lineno, max );
269 sockbuf_max_incoming_auth = max;
271 /* set conn pending max */
272 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
275 Debug( LDAP_DEBUG_ANY,
276 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
282 max = atol( cargv[1] );
285 Debug( LDAP_DEBUG_ANY,
286 "%s: line %d: invalid max value (%ld) in "
287 "\"conn_max_pending <requests>\" line.\n",
288 fname, lineno, max );
293 slap_conn_max_pending = max;
295 /* set conn pending max authenticated */
296 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
299 Debug( LDAP_DEBUG_ANY,
300 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
306 max = atol( cargv[1] );
309 Debug( LDAP_DEBUG_ANY,
310 "%s: line %d: invalid max value (%ld) in "
311 "\"conn_max_pending_auth <requests>\" line.\n",
312 fname, lineno, max );
317 slap_conn_max_pending_auth = max;
319 /* default search base */
320 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
322 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
323 "missing dn in \"defaultSearchBase <dn>\" line\n",
328 } else if ( cargc > 2 ) {
329 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
330 "extra cruft after <dn> in \"defaultSearchBase %s\", "
332 fname, lineno, cargv[1] );
335 if ( bi != NULL || be != NULL ) {
336 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
337 "defaultSearchBaase line must appear prior to "
338 "any backend or database definition\n",
344 if ( default_search_nbase.bv_len ) {
345 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
346 "default search base \"%s\" already defined "
347 "(discarding old)\n",
348 fname, lineno, default_search_base.bv_val );
350 free( default_search_base.bv_val );
351 free( default_search_nbase.bv_val );
354 if ( load_ucdata( NULL ) < 0 ) return 1;
359 dn.bv_val = cargv[1];
360 dn.bv_len = strlen( dn.bv_val );
362 rc = dnPrettyNormal( NULL, &dn,
363 &default_search_base,
364 &default_search_nbase, NULL );
366 if( rc != LDAP_SUCCESS ) {
367 Debug( LDAP_DEBUG_ANY,
368 "%s: line %d: defaultSearchBase DN is invalid\n",
374 /* set maximum threads in thread pool */
375 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
378 Debug( LDAP_DEBUG_ANY,
379 "%s: line %d: missing count in \"threads <count>\" line\n",
385 c = strtol( cargv[1], &next, 10 );
386 if (next == NULL || next[0] != '\0' ) {
387 Debug( LDAP_DEBUG_ANY,
388 "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
389 fname, lineno, cargv[1] );
394 Debug( LDAP_DEBUG_ANY,
395 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
401 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
403 /* save for later use */
404 connection_pool_max = c;
406 /* get pid file name */
407 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
409 Debug( LDAP_DEBUG_ANY,
410 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
416 slapd_pid_file = ch_strdup( cargv[1] );
418 /* get args file name */
419 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
421 Debug( LDAP_DEBUG_ANY,
422 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
428 slapd_args_file = ch_strdup( cargv[1] );
430 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
433 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
436 /* default password hash */
437 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
439 Debug( LDAP_DEBUG_ANY,
440 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
445 if ( default_passwd_hash != NULL ) {
446 Debug( LDAP_DEBUG_ANY,
447 "%s: line %d: already set default password_hash!\n",
453 for(i = 1; i < cargc; i++) {
454 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
455 Debug( LDAP_DEBUG_ANY,
456 "%s: line %d: password scheme \"%s\" not available\n",
457 fname, lineno, cargv[i] );
459 ldap_charray_add( &default_passwd_hash, cargv[i] );
462 if( !default_passwd_hash ) {
463 Debug( LDAP_DEBUG_ANY,
464 "%s: line %d: no valid hashes found\n",
469 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
472 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
473 "\"password-crypt-salt-format <format>\" line\n",
479 lutil_salt_format( cargv[1] );
481 #ifdef SLAP_AUTH_REWRITE
482 /* use authid rewrite instead of sasl regexp */
483 } else if ( strncasecmp( cargv[0], "auth-rewrite",
484 STRLENOF("auth-rewrite") ) == 0 )
486 int rc = slap_sasl_rewrite_config( fname, lineno,
491 #endif /* SLAP_AUTH_REWRITE */
493 /* Auth + SASL config options */
494 } else if ( !strncasecmp( cargv[0], "auth", STRLENOF("auth") ) ||
495 !strncasecmp( cargv[0], "sasl", STRLENOF("sasl") ))
497 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
501 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
504 Debug( LDAP_DEBUG_ANY,
505 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
509 ber_str2bv( cargv[1], 0, 0, &dn );
511 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
512 &be->be_schemandn, NULL );
514 rc = dnPrettyNormal( NULL, &dn, &frontendDB->be_schemadn,
515 &frontendDB->be_schemandn, NULL );
517 if ( rc != LDAP_SUCCESS ) {
518 Debug( LDAP_DEBUG_ANY,
519 "%s: line %d: schemadn DN is invalid\n",
524 /* set UCDATA path */
525 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
528 Debug( LDAP_DEBUG_ANY,
529 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
535 err = load_ucdata( cargv[1] );
538 Debug( LDAP_DEBUG_ANY,
539 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
547 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
549 struct slap_limits_set *lim;
552 Debug( LDAP_DEBUG_ANY,
553 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
560 lim = &frontendDB->be_def_limit;
562 lim = &be->be_def_limit;
565 for ( i = 1; i < cargc; i++ ) {
566 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
567 rc = limits_parse_one( cargv[i], lim );
569 Debug( LDAP_DEBUG_ANY,
570 "%s: line %d: unable "
571 "to parse value \"%s\" "
574 fname, lineno, cargv[i] );
579 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
580 lim->lms_s_soft = -1;
582 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
583 if ( next == cargv[i] ) {
584 Debug( LDAP_DEBUG_ANY,
585 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
586 fname, lineno, cargv[i] );
589 } else if ( next[0] != '\0' ) {
590 Debug( LDAP_DEBUG_ANY,
591 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
592 fname, lineno, next );
600 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
602 struct slap_limits_set *lim;
605 Debug( LDAP_DEBUG_ANY,
606 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
613 lim = &frontendDB->be_def_limit;
615 lim = &be->be_def_limit;
618 for ( i = 1; i < cargc; i++ ) {
619 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
620 rc = limits_parse_one( cargv[i], lim );
622 Debug( LDAP_DEBUG_ANY,
623 "%s: line %d: unable "
624 "to parse value \"%s\" "
627 fname, lineno, cargv[i] );
632 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
633 lim->lms_t_soft = -1;
635 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
636 if ( next == cargv[i] ) {
637 Debug( LDAP_DEBUG_ANY,
638 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
639 fname, lineno, cargv[i] );
642 } else if ( next[0] != '\0' ) {
643 Debug( LDAP_DEBUG_ANY,
644 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
645 fname, lineno, next );
652 /* set regex-based limits */
653 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
655 Debug( LDAP_DEBUG_ANY,
656 "%s: line %d \"limits\" allowed only in database environment.\n%s",
661 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
665 /* mark this as a subordinate database */
666 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
668 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
669 "must appear inside a database definition.\n",
674 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
678 /* add an overlay to this backend */
679 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
681 if ( cargv[1][0] == '-' && overlay_config( frontendDB, &cargv[1][1] ) ) {
683 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
684 "(optional) global overlay \"%s\" configuration "
685 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
686 } else if ( overlay_config( frontendDB, cargv[1] ) ) {
691 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
693 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
694 "(optional) overlay \"%s\" configuration "
695 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
696 } else if ( overlay_config( be, cargv[1] ) ) {
701 /* set database suffix */
702 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
704 struct berval dn, pdn, ndn;
707 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
708 "missing dn in \"suffix <dn>\" line\n",
713 } else if ( cargc > 2 ) {
714 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
715 "after <dn> in \"suffix %s\" line (ignored)\n",
716 fname, lineno, cargv[1] );
720 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
721 "must appear inside a database definition\n",
725 #if defined(SLAPD_MONITOR_DN)
726 /* "cn=Monitor" is reserved for monitoring slap */
727 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
728 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
729 "%s\" is reserved for monitoring slapd\n",
730 fname, lineno, SLAPD_MONITOR_DN );
732 #endif /* SLAPD_MONITOR_DN */
735 if ( load_ucdata( NULL ) < 0 ) return 1;
737 dn.bv_val = cargv[1];
738 dn.bv_len = strlen( cargv[1] );
740 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
741 if( rc != LDAP_SUCCESS ) {
742 Debug( LDAP_DEBUG_ANY,
743 "%s: line %d: suffix DN is invalid\n",
748 tmp_be = select_backend( &ndn, 0, 0 );
749 if ( tmp_be == be ) {
750 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
751 "already served by this backend (ignored)\n",
756 } else if ( tmp_be != NULL ) {
757 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
758 "already served by a preceeding backend \"%s\"\n",
759 fname, lineno, tmp_be->be_suffix[0].bv_val );
764 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
765 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
766 "suffix DN empty and default "
767 "search base provided \"%s\" (assuming okay)\n",
768 fname, lineno, default_search_base.bv_val );
771 ber_bvarray_add( &be->be_suffix, &pdn );
772 ber_bvarray_add( &be->be_nsuffix, &ndn );
774 /* set max deref depth */
775 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
778 Debug( LDAP_DEBUG_ANY,
779 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
785 Debug( LDAP_DEBUG_ANY,
786 "%s: line %d: depth line must appear inside a database definition.\n",
791 i = strtol( cargv[1], &next, 10 );
792 if ( next == NULL || next[0] != '\0' ) {
793 Debug( LDAP_DEBUG_ANY,
794 "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
795 "line.\n", fname, lineno, cargv[1] );
800 Debug( LDAP_DEBUG_ANY,
801 "%s: line %d: depth must be positive.\n",
807 be->be_max_deref_depth = i;
809 /* set magic "root" dn for this database */
810 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
812 Debug( LDAP_DEBUG_ANY,
813 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
820 Debug( LDAP_DEBUG_ANY,
821 "%s: line %d: rootdn line must appear inside a database definition.\n",
828 if ( load_ucdata( NULL ) < 0 ) return 1;
830 dn.bv_val = cargv[1];
831 dn.bv_len = strlen( cargv[1] );
833 rc = dnPrettyNormal( NULL, &dn,
835 &be->be_rootndn, NULL );
837 if( rc != LDAP_SUCCESS ) {
838 Debug( LDAP_DEBUG_ANY,
839 "%s: line %d: rootdn DN is invalid\n",
845 /* set super-secret magic database password */
846 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
848 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
849 "missing passwd in \"rootpw <passwd>\" line\n",
856 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
857 "rootpw line must appear inside a database "
863 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
866 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
867 "rootpw can only be set when rootdn is under suffix\n",
872 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
873 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
876 /* make this database read-only */
877 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
879 Debug( LDAP_DEBUG_ANY,
880 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
886 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
887 frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
889 frontendDB->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
893 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
894 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
896 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
900 /* restricts specific operations */
901 } else if ( strcasecmp( cargv[0], "restrict" ) == 0 ) {
902 slap_mask_t restrictops = 0;
903 struct restrictable_exops_t {
906 } restrictable_exops[] = {
907 { LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
908 { LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
909 { LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
910 { LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
916 Debug( LDAP_DEBUG_ANY,
917 "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
918 "line.\n", fname, lineno, 0 );
922 for ( i = 1; i < cargc; i++ ) {
923 if ( strcasecmp( cargv[ i ], "read" ) == 0 ) {
924 restrictops |= SLAP_RESTRICT_OP_READS;
926 } else if ( strcasecmp( cargv[ i ], "write" ) == 0 ) {
927 restrictops |= SLAP_RESTRICT_OP_WRITES;
929 } else if ( strcasecmp( cargv[ i ], "add" ) == 0 ) {
930 restrictops |= SLAP_RESTRICT_OP_ADD;
932 } else if ( strcasecmp( cargv[ i ], "bind" ) == 0 ) {
933 restrictops |= SLAP_RESTRICT_OP_BIND;
935 } else if ( strcasecmp( cargv[ i ], "compare" ) == 0 ) {
936 restrictops |= SLAP_RESTRICT_OP_COMPARE;
938 } else if ( strcasecmp( cargv[ i ], "delete" ) == 0 ) {
939 restrictops |= SLAP_RESTRICT_OP_DELETE;
941 } else if ( strncasecmp( cargv[ i ], "extended",
942 STRLENOF( "extended" ) ) == 0 )
944 char *e = cargv[ i ] + STRLENOF( "extended" );
950 for ( j = 0; restrictable_exops[ j ].name; j++ ) {
951 if ( strcmp( e, restrictable_exops[j].name ) == 0 )
953 restrictops |= restrictable_exops[ j ].flag;
958 if ( restrictable_exops[ j ].name == NULL ) {
959 goto restrict_unknown;
962 restrictops &= ~SLAP_RESTRICT_OP_EXTENDED;
964 } else if ( e[0] == '\0' ) {
965 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
966 restrictops |= SLAP_RESTRICT_OP_EXTENDED;
969 goto restrict_unknown;
972 } else if ( strcasecmp( cargv[ i ], "modify" ) == 0 ) {
973 restrictops |= SLAP_RESTRICT_OP_MODIFY;
975 } else if ( strcasecmp( cargv[ i ], "rename" ) == 0
976 || strcasecmp( cargv[ i ], "modrdn" ) == 0 )
978 restrictops |= SLAP_RESTRICT_OP_RENAME;
980 } else if ( strcasecmp( cargv[ i ], "search" ) == 0 ) {
981 restrictops |= SLAP_RESTRICT_OP_SEARCH;
986 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
987 "unknown operation %s in \"allow <features>\" line\n",
988 fname, lineno, cargv[i] );
994 frontendDB->be_restrictops |= restrictops;
996 be->be_restrictops |= restrictops;
999 /* allow these features */
1000 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1001 strcasecmp( cargv[0], "allow" ) == 0 )
1003 slap_mask_t allows = 0;
1006 Debug( LDAP_DEBUG_ANY,
1007 "%s: line %d: allow line must appear prior to database definitions\n",
1013 Debug( LDAP_DEBUG_ANY,
1014 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1020 for( i=1; i < cargc; i++ ) {
1021 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1022 allows |= SLAP_ALLOW_BIND_V2;
1024 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1025 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1027 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1028 allows |= SLAP_ALLOW_BIND_ANON_DN;
1030 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1031 allows |= SLAP_ALLOW_UPDATE_ANON;
1034 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1035 "unknown feature %s in \"allow <features>\" line\n",
1036 fname, lineno, cargv[i] );
1042 global_allows |= allows;
1044 /* disallow these features */
1045 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1046 strcasecmp( cargv[0], "disallow" ) == 0 )
1048 slap_mask_t disallows = 0;
1051 Debug( LDAP_DEBUG_ANY,
1052 "%s: line %d: disallow line must appear prior to database definitions\n",
1058 Debug( LDAP_DEBUG_ANY,
1059 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1065 for( i=1; i < cargc; i++ ) {
1066 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1067 disallows |= SLAP_DISALLOW_BIND_ANON;
1069 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1070 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1072 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1073 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1075 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1076 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1078 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1079 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1082 Debug( LDAP_DEBUG_ANY,
1083 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1084 fname, lineno, cargv[i] );
1090 global_disallows |= disallows;
1092 /* require these features */
1093 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1094 strcasecmp( cargv[0], "require" ) == 0 )
1096 slap_mask_t requires = 0;
1099 Debug( LDAP_DEBUG_ANY,
1100 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1106 for( i=1; i < cargc; i++ ) {
1107 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1108 requires |= SLAP_REQUIRE_BIND;
1110 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1111 requires |= SLAP_REQUIRE_LDAP_V3;
1113 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1114 requires |= SLAP_REQUIRE_AUTHC;
1116 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1117 requires |= SLAP_REQUIRE_SASL;
1119 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1120 requires |= SLAP_REQUIRE_STRONG;
1122 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1123 Debug( LDAP_DEBUG_ANY,
1124 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1125 fname, lineno, cargv[i] );
1132 frontendDB->be_requires = requires;
1134 be->be_requires = requires;
1137 /* required security factors */
1138 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1139 slap_ssf_set_t *set;
1142 Debug( LDAP_DEBUG_ANY,
1143 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1150 set = &frontendDB->be_ssf_set;
1152 set = &be->be_ssf_set;
1155 for( i=1; i < cargc; i++ ) {
1159 if ( strncasecmp( cargv[i], "ssf=",
1160 STRLENOF("ssf=") ) == 0 )
1162 tgt = &set->sss_ssf;
1163 src = &cargv[i][STRLENOF("ssf=")];
1165 } else if ( strncasecmp( cargv[i], "transport=",
1166 STRLENOF("transport=") ) == 0 )
1168 tgt = &set->sss_transport;
1169 src = &cargv[i][STRLENOF("transport=")];
1171 } else if ( strncasecmp( cargv[i], "tls=",
1172 STRLENOF("tls=") ) == 0 )
1174 tgt = &set->sss_tls;
1175 src = &cargv[i][STRLENOF("tls=")];
1177 } else if ( strncasecmp( cargv[i], "sasl=",
1178 STRLENOF("sasl=") ) == 0 )
1180 tgt = &set->sss_sasl;
1181 src = &cargv[i][STRLENOF("sasl=")];
1183 } else if ( strncasecmp( cargv[i], "update_ssf=",
1184 STRLENOF("update_ssf=") ) == 0 )
1186 tgt = &set->sss_update_ssf;
1187 src = &cargv[i][STRLENOF("update_ssf=")];
1189 } else if ( strncasecmp( cargv[i], "update_transport=",
1190 STRLENOF("update_transport=") ) == 0 )
1192 tgt = &set->sss_update_transport;
1193 src = &cargv[i][STRLENOF("update_transport=")];
1195 } else if ( strncasecmp( cargv[i], "update_tls=",
1196 STRLENOF("update_tls=") ) == 0 )
1198 tgt = &set->sss_update_tls;
1199 src = &cargv[i][STRLENOF("update_tls=")];
1201 } else if ( strncasecmp( cargv[i], "update_sasl=",
1202 STRLENOF("update_sasl=") ) == 0 )
1204 tgt = &set->sss_update_sasl;
1205 src = &cargv[i][STRLENOF("update_sasl=")];
1207 } else if ( strncasecmp( cargv[i], "simple_bind=",
1208 STRLENOF("simple_bind=") ) == 0 )
1210 tgt = &set->sss_simple_bind;
1211 src = &cargv[i][STRLENOF("simple_bind=")];
1214 Debug( LDAP_DEBUG_ANY,
1215 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1216 fname, lineno, cargv[i] );
1221 *tgt = strtol( src, &next, 10 );
1222 if ( next == NULL || next[0] != '\0' ) {
1223 Debug( LDAP_DEBUG_ANY,
1224 "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1225 fname, lineno, cargv[i] );
1231 /* where to send clients when we don't hold it */
1232 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1234 Debug( LDAP_DEBUG_ANY,
1235 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1241 if( validate_global_referral( cargv[1] ) ) {
1242 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1243 "invalid URL (%s) in \"referral\" line.\n",
1244 fname, lineno, cargv[1] );
1248 vals[0].bv_val = cargv[1];
1249 vals[0].bv_len = strlen( vals[0].bv_val );
1250 if( value_add( &default_referral, vals ) )
1253 /* start of a new database definition */
1254 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1257 Debug( LDAP_DEBUG_ANY,
1258 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1262 level = strtol( cargv[2], &next, 10 );
1263 if ( next == NULL || next[0] != '\0' ){
1264 Debug( LDAP_DEBUG_ANY,
1265 "%s: line %d: unable to parse level \"%s\" in debug directive, "
1266 "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1270 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1271 lutil_set_debug_level( cargv[1], level );
1272 /* specify an Object Identifier macro */
1273 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1274 rc = parse_oidm( fname, lineno, cargc, cargv );
1277 /* specify an objectclass */
1278 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1280 Debug( LDAP_DEBUG_ANY,
1281 "%s: line %d: illegal objectclass format.\n",
1285 } else if ( *cargv[1] == '(' /*')'*/) {
1287 p = strchr(saveline,'(' /*')'*/);
1288 rc = parse_oc( fname, lineno, p, cargv );
1292 Debug( LDAP_DEBUG_ANY,
1293 "%s: line %d: old objectclass format not supported.\n",
1297 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1299 p = strchr(saveline,'(' /*')'*/);
1300 rc = parse_cr( fname, lineno, p, cargv );
1303 /* specify an attribute type */
1304 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1305 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1308 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1309 "illegal attribute type format.\n",
1313 } else if ( *cargv[1] == '(' /*')'*/) {
1315 p = strchr(saveline,'(' /*')'*/);
1316 rc = parse_at( fname, lineno, p, cargv );
1320 Debug( LDAP_DEBUG_ANY,
1321 "%s: line %d: old attribute type format not supported.\n",
1326 /* define attribute option(s) */
1327 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1328 ad_define_option( NULL, NULL, 0 );
1329 for ( i = 1; i < cargc; i++ )
1330 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1333 /* turn on/off schema checking */
1334 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1336 Debug( LDAP_DEBUG_ANY,
1337 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1342 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1343 Debug( LDAP_DEBUG_ANY,
1344 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1346 global_schemacheck = 0;
1348 global_schemacheck = 1;
1351 /* specify access control info */
1352 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1353 parse_acl( be, fname, lineno, cargc, cargv );
1355 /* debug level to log things to syslog */
1356 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1358 Debug( LDAP_DEBUG_ANY,
1359 "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1367 for( i=1; i < cargc; i++ ) {
1370 if ( isdigit( cargv[i][0] ) ) {
1371 level = strtol( cargv[i], &next, 10 );
1372 if ( next == NULL || next[0] != '\0' ) {
1373 Debug( LDAP_DEBUG_ANY,
1374 "%s: line %d: unable to parse level \"%s\" "
1375 "in \"loglevel <level> [...]\" line.\n",
1376 fname, lineno , cargv[i] );
1385 { LDAP_DEBUG_TRACE, "Trace" },
1386 { LDAP_DEBUG_PACKETS, "Packets" },
1387 { LDAP_DEBUG_ARGS, "Args" },
1388 { LDAP_DEBUG_CONNS, "Conns" },
1389 { LDAP_DEBUG_BER, "BER" },
1390 { LDAP_DEBUG_FILTER, "Filter" },
1391 { LDAP_DEBUG_CONFIG, "Config" },
1392 { LDAP_DEBUG_ACL, "ACL" },
1393 { LDAP_DEBUG_STATS, "Stats" },
1394 { LDAP_DEBUG_STATS2, "Stats2" },
1395 { LDAP_DEBUG_SHELL, "Shell" },
1396 { LDAP_DEBUG_PARSE, "Parse" },
1397 { LDAP_DEBUG_CACHE, "Cache" },
1398 { LDAP_DEBUG_INDEX, "Index" },
1404 for ( j = 0; int_2_level[j].s; j++ ) {
1405 if ( strcasecmp( cargv[i], int_2_level[j].s ) == 0 ) {
1406 level = int_2_level[j].i;
1411 if ( int_2_level[j].s == NULL ) {
1412 Debug( LDAP_DEBUG_ANY,
1413 "%s: line %d: unknown level \"%s\" "
1414 "in \"loglevel <level> [...]\" line.\n",
1415 fname, lineno , cargv[i] );
1420 ldap_syslog |= level;
1423 /* list of sync replication information in this backend (slave only) */
1424 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1427 Debug( LDAP_DEBUG_ANY,
1428 "%s: line %d: syncrepl line must appear inside "
1429 "a database definition.\n", fname, lineno, 0);
1432 } else if ( SLAP_SHADOW( be )) {
1433 Debug( LDAP_DEBUG_ANY,
1434 "%s: line %d: syncrepl: database already shadowed.\n",
1438 } else if ( add_syncrepl( be, cargv, cargc )) {
1442 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1444 /* list of replicas of the data in this backend (master only) */
1445 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1447 Debug( LDAP_DEBUG_ANY,
1448 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1454 Debug( LDAP_DEBUG_ANY,
1455 "%s: line %d: replica line must appear inside a database definition\n",
1462 for ( i = 1; i < cargc; i++ ) {
1463 if ( strncasecmp( cargv[i], "host=", 5 )
1465 nr = add_replica_info( be,
1468 } else if (strncasecmp( cargv[i], "uri=", 4 )
1470 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1472 Debug( LDAP_DEBUG_ANY,
1473 "%s: line %d: replica line contains invalid "
1474 "uri definition.\n", fname, lineno, 0);
1477 if (ludp->lud_host == NULL ) {
1478 Debug( LDAP_DEBUG_ANY,
1479 "%s: line %d: replica line contains invalid "
1480 "uri definition - missing hostname.\n", fname, lineno, 0);
1483 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1484 if ( replicahost == NULL ) {
1485 Debug( LDAP_DEBUG_ANY,
1486 "out of memory in read_config\n", 0, 0, 0 );
1487 ldap_free_urldesc( ludp );
1488 exit( EXIT_FAILURE );
1490 sprintf(replicahost, "%s:%d",
1491 ludp->lud_host, ludp->lud_port);
1492 nr = add_replica_info( be, replicahost );
1493 ldap_free_urldesc( ludp );
1494 ch_free(replicahost);
1499 Debug( LDAP_DEBUG_ANY,
1500 "%s: line %d: missing host or uri in \"replica\" line\n",
1504 } else if ( nr == -1 ) {
1505 Debug( LDAP_DEBUG_ANY,
1506 "%s: line %d: unable to add replica \"%s\"\n",
1507 fname, lineno, cargv[i] + 5 );
1510 for ( i = 1; i < cargc; i++ ) {
1511 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1513 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1515 Debug( LDAP_DEBUG_ANY,
1516 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1517 fname, lineno, cargv[i] + 7 );
1521 Debug( LDAP_DEBUG_ANY,
1522 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1527 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1529 char *arg = cargv[i] + 4;
1531 if ( arg[0] == '!' ) {
1536 if ( arg[0] != '=' ) {
1540 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1541 Debug( LDAP_DEBUG_ANY,
1542 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1543 fname, lineno, arg + 1 );
1551 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1554 /* dn of slave entity allowed to write to replica */
1555 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1557 Debug( LDAP_DEBUG_ANY,
1558 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1564 Debug( LDAP_DEBUG_ANY,
1565 "%s: line %d: updatedn line must appear inside a database definition\n",
1569 } else if ( SLAP_SHADOW(be) ) {
1570 Debug( LDAP_DEBUG_ANY,
1571 "%s: line %d: updatedn: database already shadowed.\n",
1578 if ( load_ucdata( NULL ) < 0 ) return 1;
1580 dn.bv_val = cargv[1];
1581 dn.bv_len = strlen( cargv[1] );
1583 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1584 if( rc != LDAP_SUCCESS ) {
1585 Debug( LDAP_DEBUG_ANY,
1586 "%s: line %d: updatedn DN is invalid\n",
1592 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
1594 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1596 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1597 "missing url in \"updateref <ldapurl>\" line\n",
1603 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1604 " line must appear inside a database definition\n",
1608 } else if ( !SLAP_SHADOW(be) ) {
1609 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1610 "updateref line must after syncrepl or updatedn.\n",
1615 if( validate_global_referral( cargv[1] ) ) {
1616 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1617 "invalid URL (%s) in \"updateref\" line.\n",
1618 fname, lineno, cargv[1] );
1622 vals[0].bv_val = cargv[1];
1623 vals[0].bv_len = strlen( vals[0].bv_val );
1624 if( value_add( &be->be_update_refs, vals ) ) {
1628 /* replication log file to which changes are appended */
1629 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1631 Debug( LDAP_DEBUG_ANY,
1632 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1638 be->be_replogfile = ch_strdup( cargv[1] );
1640 replogfile = ch_strdup( cargv[1] );
1643 /* file from which to read additional rootdse attrs */
1644 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
1646 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1647 "missing filename in \"rootDSE <filename>\" line.\n",
1652 if( read_root_dse_file( cargv[1] ) ) {
1653 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1654 "could not read \"rootDSE <filename>\" line\n",
1659 /* maintain lastmodified{by,time} attributes */
1660 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1662 Debug( LDAP_DEBUG_ANY,
1663 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1670 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1671 " line must appear inside a database definition\n",
1675 } else if ( SLAP_NOLASTMODCMD(be) ) {
1676 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1677 " not available for %s databases\n",
1678 fname, lineno, be->bd_info->bi_type );
1682 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1683 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
1685 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1689 /* turn on/off gentle SIGHUP handling */
1690 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
1692 Debug( LDAP_DEBUG_ANY,
1693 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
1697 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1698 global_gentlehup = 0;
1700 global_gentlehup = 1;
1704 /* set idle timeout value */
1705 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1708 Debug( LDAP_DEBUG_ANY,
1709 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1715 i = atoi( cargv[1] );
1718 Debug( LDAP_DEBUG_ANY,
1719 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1725 global_idletimeout = i;
1727 /* include another config file */
1728 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1730 Debug( LDAP_DEBUG_ANY,
1731 "%s: line %d: missing filename in \"include <filename>\" line\n",
1736 savefname = ch_strdup( cargv[1] );
1737 savelineno = lineno;
1739 if ( read_config( savefname, depth+1 ) != 0 ) {
1744 lineno = savelineno - 1;
1746 /* location of kerberos srvtab file */
1747 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1749 Debug( LDAP_DEBUG_ANY,
1750 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1755 ldap_srvtab = ch_strdup( cargv[1] );
1757 #ifdef SLAPD_MODULES
1758 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1760 Debug( LDAP_DEBUG_ANY,
1761 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1764 exit( EXIT_FAILURE );
1766 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1767 Debug( LDAP_DEBUG_ANY,
1768 "%s: line %d: failed to load or initialize module %s\n",
1769 fname, lineno, cargv[1]);
1771 exit( EXIT_FAILURE );
1773 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1775 Debug( LDAP_DEBUG_ANY,
1776 "%s: line %d: missing path in \"modulepath <path>\" line\n",
1779 exit( EXIT_FAILURE );
1781 if (module_path( cargv[1] )) {
1782 Debug( LDAP_DEBUG_ANY,
1783 "%s: line %d: failed to set module search path to %s\n",
1784 fname, lineno, cargv[1]);
1786 exit( EXIT_FAILURE );
1789 #endif /*SLAPD_MODULES*/
1792 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
1793 rc = ldap_pvt_tls_set_option( NULL,
1794 LDAP_OPT_X_TLS_RANDOM_FILE,
1799 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1800 rc = ldap_pvt_tls_set_option( NULL,
1801 LDAP_OPT_X_TLS_CIPHER_SUITE,
1806 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1807 rc = ldap_pvt_tls_set_option( NULL,
1808 LDAP_OPT_X_TLS_CERTFILE,
1813 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1814 rc = ldap_pvt_tls_set_option( NULL,
1815 LDAP_OPT_X_TLS_KEYFILE,
1820 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1821 rc = ldap_pvt_tls_set_option( NULL,
1822 LDAP_OPT_X_TLS_CACERTDIR,
1827 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1828 rc = ldap_pvt_tls_set_option( NULL,
1829 LDAP_OPT_X_TLS_CACERTFILE,
1833 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1834 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
1836 rc = ldap_pvt_tls_set_option( NULL,
1837 LDAP_OPT_X_TLS_REQUIRE_CERT,
1840 rc = ldap_int_tls_config( NULL,
1841 LDAP_OPT_X_TLS_REQUIRE_CERT,
1850 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
1851 #ifdef SLAPD_RLOOKUPS
1853 Debug( LDAP_DEBUG_ANY,
1854 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
1859 if ( !strcasecmp( cargv[1], "on" ) ) {
1860 use_reverse_lookup = 1;
1861 } else if ( !strcasecmp( cargv[1], "off" ) ) {
1862 use_reverse_lookup = 0;
1864 Debug( LDAP_DEBUG_ANY,
1865 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
1870 #else /* !SLAPD_RLOOKUPS */
1871 Debug( LDAP_DEBUG_ANY,
1872 "%s: line %d: reverse lookups are not configured (ignored).\n",
1874 #endif /* !SLAPD_RLOOKUPS */
1876 /* Netscape plugins */
1877 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
1878 #if defined( LDAP_SLAPI )
1880 #ifdef notdef /* allow global plugins, too */
1882 * a "plugin" line must be inside a database
1883 * definition, since we implement pre-,post-
1884 * and extended operation plugins
1887 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
1888 "line must appear inside a database "
1889 "definition\n", fname, lineno, 0 );
1894 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
1897 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
1898 "config read failed.\n", fname, lineno, 0 );
1901 slapi_plugins_used++;
1903 #else /* !defined( LDAP_SLAPI ) */
1904 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
1905 "not supported.\n", fname, lineno, 0 );
1908 #endif /* !defined( LDAP_SLAPI ) */
1910 /* Netscape plugins */
1911 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
1912 #if defined( LDAP_SLAPI )
1914 Debug( LDAP_DEBUG_ANY,
1915 "%s: line %d: missing file name "
1916 "in pluginlog <filename> line.\n",
1921 if ( slapi_log_file != NULL ) {
1922 ch_free( slapi_log_file );
1925 slapi_log_file = ch_strdup( cargv[1] );
1926 #endif /* !defined( LDAP_SLAPI ) */
1928 /* pass anything else to the current backend info/db config routine */
1931 if ( bi->bi_config ) {
1932 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
1938 case SLAP_CONF_UNKNOWN:
1939 Debug( LDAP_DEBUG_ANY,
1940 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1941 fname, lineno, cargv[0] );
1949 } else if ( be != NULL ) {
1950 if ( be->be_config ) {
1951 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
1957 case SLAP_CONF_UNKNOWN:
1958 Debug( LDAP_DEBUG_ANY,
1959 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1960 fname, lineno, cargv[0] );
1969 if ( frontendDB->be_config ) {
1970 rc = (*frontendDB->be_config)( frontendDB, fname, lineno, cargc, cargv );
1976 case SLAP_CONF_UNKNOWN:
1977 Debug( LDAP_DEBUG_ANY,
1978 "%s: line %d: unknown directive \"%s\" inside global database definition (ignored)\n",
1979 fname, lineno, cargv[0] );
1992 if ( depth == 0 ) ch_free( cargv );
1994 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
1995 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
1996 &frontendDB->be_schemadn );
1997 dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2000 if ( load_ucdata( NULL ) < 0 ) return 1;
2012 char logbuf[sizeof("pseudorootpw ***")];
2015 token = strtok_quote( line, " \t" );
2019 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2020 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2021 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2022 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2023 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2025 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2028 if ( strtok_quote_ptr ) {
2029 *strtok_quote_ptr = ' ';
2032 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2034 if ( strtok_quote_ptr ) {
2035 *strtok_quote_ptr = '\0';
2038 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2039 if ( cargc == cargv_size - 1 ) {
2041 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2043 if ( tmp == NULL ) {
2044 Debug( LDAP_DEBUG_ANY,
2045 "line %d: out of memory\n",
2050 cargv_size += ARGS_STEP;
2052 cargv[cargc++] = token;
2054 cargv[cargc] = NULL;
2059 strtok_quote( char *line, char *sep )
2065 strtok_quote_ptr = NULL;
2066 if ( line != NULL ) {
2069 while ( *next && strchr( sep, *next ) ) {
2073 if ( *next == '\0' ) {
2079 for ( inquote = 0; *next; ) {
2087 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2093 next + 1, strlen( next + 1 ) + 1 );
2094 next++; /* dont parse the escaped character */
2099 if ( strchr( sep, *next ) != NULL ) {
2100 strtok_quote_ptr = next;
2113 static char buf[BUFSIZ];
2115 static size_t lmax, lcur;
2117 #define CATLINE( buf ) \
2119 size_t len = strlen( buf ); \
2120 while ( lcur + len + 1 > lmax ) { \
2122 line = (char *) ch_realloc( line, lmax ); \
2124 strcpy( line + lcur, buf ); \
2129 fp_getline( FILE *fp, int *lineno )
2137 /* hack attack - keeps us from having to keep a stack of bufs... */
2138 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2143 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2144 /* trim off \r\n or \n */
2145 if ( (p = strchr( buf, '\n' )) != NULL ) {
2146 if( p > buf && p[-1] == '\r' ) --p;
2150 /* trim off trailing \ and append the next line */
2151 if ( line[ 0 ] != '\0'
2152 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2153 && p[ -1 ] != '\\' ) {
2158 if ( ! isspace( (unsigned char) buf[0] ) ) {
2162 /* change leading whitespace to a space */
2171 return( line[0] ? line : NULL );
2175 fp_getline_init( int *lineno )
2181 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2183 load_ucdata( char *path )
2186 static int loaded = 0;
2192 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2194 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2202 /* ucdata is now hardcoded */
2210 ucdata_unload( UCDATA_ALL );
2212 /* NOTE: in case of early exit, frontendDB can be NULL */
2213 if ( frontendDB->be_schemandn.bv_val )
2214 free( frontendDB->be_schemandn.bv_val );
2215 if ( frontendDB->be_schemadn.bv_val )
2216 free( frontendDB->be_schemadn.bv_val );
2217 if ( frontendDB->be_acl )
2218 acl_destroy( frontendDB->be_acl, NULL );
2221 if ( slapd_args_file )
2222 free ( slapd_args_file );
2223 if ( slapd_pid_file )
2224 free ( slapd_pid_file );
2225 if ( default_passwd_hash )
2226 ldap_charray_free( default_passwd_hash );
2237 syncinfo_t *si_entry;
2239 int duplicated_replica_id = 0;
2241 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2244 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2248 si->si_tls = SYNCINFO_TLS_OFF;
2249 if ( be->be_rootndn.bv_val ) {
2250 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2252 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2253 si->si_schemachecking = 0;
2254 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 0,
2255 &si->si_filterstr );
2256 si->si_base.bv_val = NULL;
2257 si->si_scope = LDAP_SCOPE_SUBTREE;
2258 si->si_attrsonly = 0;
2259 si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2260 si->si_attrs[0] = NULL;
2261 si->si_exattrs = (char **) ch_calloc( 1, sizeof( char * ));
2262 si->si_exattrs[0] = NULL;
2263 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2264 si->si_interval = 86400;
2265 si->si_retryinterval = 0;
2266 si->si_retrynum_init = 0;
2267 si->si_retrynum = 0;
2268 si->si_syncCookie.ctxcsn = NULL;
2269 si->si_syncCookie.octet_str = NULL;
2270 si->si_syncCookie.sid = -1;
2271 si->si_manageDSAit = 0;
2274 si->si_syncUUID_ndn.bv_val = NULL;
2275 si->si_syncUUID_ndn.bv_len = 0;
2277 si->si_presentlist = NULL;
2278 LDAP_LIST_INIT( &si->si_nonpresentlist );
2280 rc = parse_syncrepl_line( cargv, cargc, si );
2282 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2283 if ( si->si_rid == si_entry->si_rid ) {
2284 Debug( LDAP_DEBUG_ANY,
2285 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2286 duplicated_replica_id = 1;
2291 if ( rc < 0 || duplicated_replica_id ) {
2292 syncinfo_t *si_entry;
2293 /* Something bad happened - back out */
2294 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2296 /* If error, remove all syncinfo */
2297 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2298 if ( si_entry->si_updatedn.bv_val ) {
2299 ch_free( si->si_updatedn.bv_val );
2301 if ( si_entry->si_filterstr.bv_val ) {
2302 ch_free( si->si_filterstr.bv_val );
2304 if ( si_entry->si_attrs ) {
2306 while ( si_entry->si_attrs[i] != NULL ) {
2307 ch_free( si_entry->si_attrs[i] );
2310 ch_free( si_entry->si_attrs );
2312 if ( si_entry->si_exattrs ) {
2314 while ( si_entry->si_exattrs[i] != NULL ) {
2315 ch_free( si_entry->si_exattrs[i] );
2318 ch_free( si_entry->si_exattrs );
2322 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2323 si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
2324 LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
2325 ch_free( si_entry );
2327 LDAP_STAILQ_INIT( &be->be_syncinfo );
2330 Debug( LDAP_DEBUG_CONFIG,
2331 "Config: ** successfully added syncrepl \"%s\"\n",
2332 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2333 if ( !si->si_schemachecking ) {
2334 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2337 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2343 #define PROVIDERSTR "provider"
2344 #define SUFFIXSTR "suffix"
2345 #define UPDATEDNSTR "updatedn"
2346 #define BINDMETHSTR "bindmethod"
2347 #define SIMPLESTR "simple"
2348 #define SASLSTR "sasl"
2349 #define BINDDNSTR "binddn"
2350 #define CREDSTR "credentials"
2351 #define OLDAUTHCSTR "bindprincipal"
2352 #define AUTHCSTR "authcID"
2353 #define AUTHZSTR "authzID"
2354 #define SRVTABSTR "srvtab"
2355 #define SASLMECHSTR "saslmech"
2356 #define REALMSTR "realm"
2357 #define SECPROPSSTR "secprops"
2358 #define STARTTLSSTR "starttls"
2359 #define CRITICALSTR "critical"
2361 #define SCHEMASTR "schemachecking"
2362 #define FILTERSTR "filter"
2363 #define SEARCHBASESTR "searchbase"
2364 #define SCOPESTR "scope"
2365 #define ATTRSSTR "attrs"
2366 #define ATTRSONLYSTR "attrsonly"
2367 #define EXATTRSSTR "exattrs"
2368 #define TYPESTR "type"
2369 #define INTERVALSTR "interval"
2370 #define LASTMODSTR "lastmod"
2371 #define LMREQSTR "req"
2372 #define LMGENSTR "gen"
2373 #define LMNOSTR "no"
2374 #define MANAGEDSAITSTR "manageDSAit"
2375 #define SLIMITSTR "sizelimit"
2376 #define TLIMITSTR "timelimit"
2378 #define RETRYSTR "retry"
2380 #define GOT_ID 0x0001
2381 #define GOT_PROVIDER 0x0002
2382 #define GOT_METHOD 0x0004
2383 #define GOT_ALL 0x0007
2386 parse_syncrepl_line(
2397 for ( i = 1; i < cargc; i++ ) {
2398 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2400 /* '\0' string terminator accounts for '=' */
2401 val = cargv[ i ] + sizeof( IDSTR );
2403 if ( tmp >= 1000 || tmp < 0 ) {
2404 fprintf( stderr, "Error: parse_syncrepl_line: "
2405 "syncrepl id %d is out of range [0..999]\n", tmp );
2410 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2411 sizeof( PROVIDERSTR ) - 1 )) {
2412 val = cargv[ i ] + sizeof( PROVIDERSTR );
2413 si->si_provideruri = ch_strdup( val );
2414 si->si_provideruri_bv = (BerVarray)
2415 ch_calloc( 2, sizeof( struct berval ));
2416 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2417 0, &si->si_provideruri_bv[0] );
2418 si->si_provideruri_bv[1].bv_len = 0;
2419 si->si_provideruri_bv[1].bv_val = NULL;
2420 gots |= GOT_PROVIDER;
2421 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2422 sizeof(STARTTLSSTR) - 1 ) )
2424 val = cargv[ i ] + sizeof( STARTTLSSTR );
2425 if( !strcasecmp( val, CRITICALSTR ) ) {
2426 si->si_tls = SYNCINFO_TLS_CRITICAL;
2428 si->si_tls = SYNCINFO_TLS_ON;
2430 } else if ( !strncasecmp( cargv[ i ],
2431 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
2433 struct berval updatedn = {0, NULL};
2434 val = cargv[ i ] + sizeof( UPDATEDNSTR );
2435 ber_str2bv( val, 0, 0, &updatedn );
2436 ch_free( si->si_updatedn.bv_val );
2437 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
2438 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
2439 sizeof( BINDMETHSTR ) - 1 ) )
2441 val = cargv[ i ] + sizeof( BINDMETHSTR );
2442 if ( !strcasecmp( val, SIMPLESTR )) {
2443 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2445 } else if ( !strcasecmp( val, SASLSTR )) {
2446 #ifdef HAVE_CYRUS_SASL
2447 si->si_bindmethod = LDAP_AUTH_SASL;
2449 #else /* HAVE_CYRUS_SASL */
2450 fprintf( stderr, "Error: parse_syncrepl_line: "
2451 "not compiled with SASL support\n" );
2453 #endif /* HAVE_CYRUS_SASL */
2455 si->si_bindmethod = -1;
2457 } else if ( !strncasecmp( cargv[ i ],
2458 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
2459 val = cargv[ i ] + sizeof( BINDDNSTR );
2460 si->si_binddn = ch_strdup( val );
2461 } else if ( !strncasecmp( cargv[ i ],
2462 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
2463 val = cargv[ i ] + sizeof( CREDSTR );
2464 si->si_passwd = ch_strdup( val );
2465 } else if ( !strncasecmp( cargv[ i ],
2466 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
2467 val = cargv[ i ] + sizeof( SASLMECHSTR );
2468 si->si_saslmech = ch_strdup( val );
2469 } else if ( !strncasecmp( cargv[ i ],
2470 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
2471 val = cargv[ i ] + sizeof( SECPROPSSTR );
2472 si->si_secprops = ch_strdup( val );
2473 } else if ( !strncasecmp( cargv[ i ],
2474 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
2475 val = cargv[ i ] + sizeof( REALMSTR );
2476 si->si_realm = ch_strdup( val );
2477 } else if ( !strncasecmp( cargv[ i ],
2478 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
2479 val = cargv[ i ] + sizeof( AUTHCSTR );
2480 si->si_authcId = ch_strdup( val );
2481 } else if ( !strncasecmp( cargv[ i ],
2482 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
2483 /* Old authcID is provided for some backwards compatibility */
2484 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
2485 si->si_authcId = ch_strdup( val );
2486 } else if ( !strncasecmp( cargv[ i ],
2487 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
2488 val = cargv[ i ] + sizeof( AUTHZSTR );
2489 si->si_authzId = ch_strdup( val );
2490 } else if ( !strncasecmp( cargv[ i ],
2491 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
2493 val = cargv[ i ] + sizeof( SCHEMASTR );
2494 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2495 si->si_schemachecking = 1;
2496 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2497 si->si_schemachecking = 0;
2499 si->si_schemachecking = 1;
2501 } else if ( !strncasecmp( cargv[ i ],
2502 FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
2504 val = cargv[ i ] + sizeof( FILTERSTR );
2505 ber_str2bv( val, 0, 1, &si->si_filterstr );
2506 } else if ( !strncasecmp( cargv[ i ],
2507 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
2510 val = cargv[ i ] + sizeof( SEARCHBASESTR );
2511 if ( si->si_base.bv_val ) {
2512 ch_free( si->si_base.bv_val );
2514 ber_str2bv( val, 0, 0, &bv );
2515 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
2516 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
2519 } else if ( !strncasecmp( cargv[ i ],
2520 SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
2522 val = cargv[ i ] + sizeof( SCOPESTR );
2523 if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
2524 si->si_scope = LDAP_SCOPE_BASE;
2525 } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
2526 si->si_scope = LDAP_SCOPE_ONELEVEL;
2527 #ifdef LDAP_SCOPE_SUBORDINATE
2528 } else if ( !strcasecmp( val, "subordinate" ) ||
2529 !strcasecmp( val, "children" ))
2531 si->si_scope = LDAP_SCOPE_SUBORDINATE;
2533 } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
2534 si->si_scope = LDAP_SCOPE_SUBTREE;
2536 fprintf( stderr, "Error: parse_syncrepl_line: "
2537 "unknown scope \"%s\"\n", val);
2540 } else if ( !strncasecmp( cargv[ i ],
2541 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
2543 si->si_attrsonly = 1;
2544 } else if ( !strncasecmp( cargv[ i ],
2545 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
2547 val = cargv[ i ] + sizeof( ATTRSSTR );
2548 str2clist( &si->si_attrs, val, "," );
2549 } else if ( !strncasecmp( cargv[ i ],
2550 EXATTRSSTR, sizeof( EXATTRSSTR ) - 1 ) )
2552 val = cargv[ i ] + sizeof( EXATTRSSTR );
2553 str2clist( &si->si_exattrs, val, "," );
2554 } else if ( !strncasecmp( cargv[ i ],
2555 TYPESTR, sizeof( TYPESTR ) - 1 ) )
2557 val = cargv[ i ] + sizeof( TYPESTR );
2558 if ( !strncasecmp( val, "refreshOnly", STRLENOF("refreshOnly") )) {
2559 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2560 } else if ( !strncasecmp( val, "refreshAndPersist",
2561 STRLENOF("refreshAndPersist") ))
2563 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2564 si->si_interval = 60;
2566 fprintf( stderr, "Error: parse_syncrepl_line: "
2567 "unknown sync type \"%s\"\n", val);
2570 } else if ( !strncasecmp( cargv[ i ],
2571 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
2573 val = cargv[ i ] + sizeof( INTERVALSTR );
2574 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2575 si->si_interval = 0;
2583 hstr = strchr( dstr, ':' );
2584 if ( hstr == NULL ) {
2585 fprintf( stderr, "Error: parse_syncrepl_line: "
2586 "invalid interval \"%s\"\n", val );
2590 mstr = strchr( hstr, ':' );
2591 if ( mstr == NULL ) {
2592 fprintf( stderr, "Error: parse_syncrepl_line: "
2593 "invalid interval \"%s\"\n", val );
2597 sstr = strchr( mstr, ':' );
2598 if ( sstr == NULL ) {
2599 fprintf( stderr, "Error: parse_syncrepl_line: "
2600 "invalid interval \"%s\"\n", val );
2609 if (( hh > 24 ) || ( hh < 0 ) ||
2610 ( mm > 60 ) || ( mm < 0 ) ||
2611 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2612 fprintf( stderr, "Error: parse_syncrepl_line: "
2613 "invalid interval \"%s\"\n", val );
2616 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2618 if ( si->si_interval < 0 ) {
2619 fprintf( stderr, "Error: parse_syncrepl_line: "
2620 "invalid interval \"%ld\"\n",
2621 (long) si->si_interval);
2624 } else if ( !strncasecmp( cargv[ i ],
2625 RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
2631 val = cargv[ i ] + sizeof( RETRYSTR );
2632 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2633 retry_list[0] = NULL;
2635 str2clist( &retry_list, val, " ,\t" );
2637 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2641 "Error: incomplete syncrepl retry list\n" );
2642 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2643 ch_free( retry_list[k] );
2645 ch_free( retry_list );
2646 exit( EXIT_FAILURE );
2648 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2649 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2650 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2651 for ( j = 0; j < n; j++ ) {
2652 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2653 if ( *retry_list[j*2+1] == '+' ) {
2654 si->si_retrynum_init[j] = -1;
2655 si->si_retrynum[j] = -1;
2659 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2660 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2663 si->si_retrynum_init[j] = -2;
2664 si->si_retrynum[j] = -2;
2665 si->si_retryinterval[j] = 0;
2667 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2668 ch_free( retry_list[k] );
2670 ch_free( retry_list );
2671 } else if ( !strncasecmp( cargv[ i ],
2672 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
2674 val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
2675 si->si_manageDSAit = atoi( val );
2676 } else if ( !strncasecmp( cargv[ i ],
2677 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
2679 val = cargv[ i ] + sizeof( SLIMITSTR );
2680 si->si_slimit = atoi( val );
2681 } else if ( !strncasecmp( cargv[ i ],
2682 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
2684 val = cargv[ i ] + sizeof( TLIMITSTR );
2685 si->si_tlimit = atoi( val );
2687 fprintf( stderr, "Error: parse_syncrepl_line: "
2688 "unknown keyword \"%s\"\n", cargv[ i ] );
2692 if ( gots != GOT_ALL ) {
2694 "Error: Malformed \"syncrepl\" line in slapd config file" );
2702 str2clist( char ***out, char *in, const char *brkstr )
2711 /* find last element in list */
2712 for (i = 0; *out && *out[i]; i++);
2714 /* protect the input string from strtok */
2715 str = ch_strdup( in );
2717 if ( *str == '\0' ) {
2722 /* Count words in string */
2724 for ( s = str; *s; s++ ) {
2725 if ( strchr( brkstr, *s ) != NULL ) {
2730 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
2732 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
2734 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
2736 *new = ch_strdup( s );