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;
106 vals[1].bv_val = NULL;
109 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
110 cargv_size = ARGS_STEP + 1;
113 if ( (fp = fopen( fname, "r" )) == NULL ) {
115 Debug( LDAP_DEBUG_ANY,
116 "could not open config file \"%s\": %s (%d)\n",
117 fname, strerror(errno), errno );
121 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
124 fp_getline_init( &lineno );
126 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
127 /* skip comments and blank lines */
128 if ( line[0] == '#' || line[0] == '\0' ) {
132 /* fp_parse_line is destructive, we save a copy */
133 saveline = ch_strdup( line );
135 if ( fp_parse_line( lineno, line ) != 0 ) {
140 Debug( LDAP_DEBUG_ANY,
141 "%s: line %d: bad config line (ignored)\n",
147 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
149 Debug( LDAP_DEBUG_ANY,
150 "%s: line %d: missing type in \"backend <type>\" line\n",
157 Debug( LDAP_DEBUG_ANY,
158 "%s: line %d: backend line must appear before any database definition\n",
164 bi = backend_info( cargv[1] );
167 Debug( LDAP_DEBUG_ANY,
168 "backend %s initialization failed.\n",
173 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
175 Debug( LDAP_DEBUG_ANY,
176 "%s: line %d: missing type in \"database <type>\" line\n",
183 be = backend_db_init( cargv[1] );
186 Debug( LDAP_DEBUG_ANY,
187 "database %s initialization failed.\n",
193 /* set local security factor */
194 } else if ( strcasecmp( cargv[0], "localSSF" ) == 0 ) {
197 Debug( LDAP_DEBUG_ANY,
198 "%s: line %d: missing ssf in \"localSSF <ssf>\" line\n",
203 ssf = atol( cargv[1] );
206 Debug( LDAP_DEBUG_ANY,
207 "%s: line %d: invalid ssf value (%ld) in "
208 "\"localSSF <ssf>\" line.\n",
209 fname, lineno, ssf );
215 /* set thread concurrency */
216 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
219 Debug( LDAP_DEBUG_ANY,
220 "%s: line %d: missing level in \"concurrency <level>\" line\n",
226 c = strtol( cargv[1], &next, 10 );
227 if ( next == NULL || next[0] != '\0' ) {
228 Debug( LDAP_DEBUG_ANY,
229 "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" line\n",
230 fname, lineno, cargv[1] );
235 Debug( LDAP_DEBUG_ANY,
236 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
242 ldap_pvt_thread_set_concurrency( c );
244 /* set sockbuf max */
245 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
248 Debug( LDAP_DEBUG_ANY,
249 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
255 max = atol( cargv[1] );
258 Debug( LDAP_DEBUG_ANY,
259 "%s: line %d: invalid max value (%ld) in "
260 "\"sockbuf_max_incoming <bytes>\" line.\n",
261 fname, lineno, max );
266 sockbuf_max_incoming = max;
268 /* set sockbuf max authenticated */
269 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
272 Debug( LDAP_DEBUG_ANY,
273 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
279 max = atol( cargv[1] );
282 Debug( LDAP_DEBUG_ANY,
283 "%s: line %d: invalid max value (%ld) in "
284 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
285 fname, lineno, max );
290 sockbuf_max_incoming_auth = max;
292 /* set conn pending max */
293 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
296 Debug( LDAP_DEBUG_ANY,
297 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
303 max = atol( cargv[1] );
306 Debug( LDAP_DEBUG_ANY,
307 "%s: line %d: invalid max value (%ld) in "
308 "\"conn_max_pending <requests>\" line.\n",
309 fname, lineno, max );
314 slap_conn_max_pending = max;
316 /* set conn pending max authenticated */
317 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
320 Debug( LDAP_DEBUG_ANY,
321 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
327 max = atol( cargv[1] );
330 Debug( LDAP_DEBUG_ANY,
331 "%s: line %d: invalid max value (%ld) in "
332 "\"conn_max_pending_auth <requests>\" line.\n",
333 fname, lineno, max );
338 slap_conn_max_pending_auth = max;
340 /* default search base */
341 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
343 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
344 "missing dn in \"defaultSearchBase <dn>\" line\n",
349 } else if ( cargc > 2 ) {
350 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
351 "extra cruft after <dn> in \"defaultSearchBase %s\", "
353 fname, lineno, cargv[1] );
356 if ( bi != NULL || be != NULL ) {
357 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
358 "defaultSearchBaase line must appear prior to "
359 "any backend or database definition\n",
365 if ( default_search_nbase.bv_len ) {
366 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
367 "default search base \"%s\" already defined "
368 "(discarding old)\n",
369 fname, lineno, default_search_base.bv_val );
371 free( default_search_base.bv_val );
372 free( default_search_nbase.bv_val );
375 if ( load_ucdata( NULL ) < 0 ) return 1;
380 dn.bv_val = cargv[1];
381 dn.bv_len = strlen( dn.bv_val );
383 rc = dnPrettyNormal( NULL, &dn,
384 &default_search_base,
385 &default_search_nbase, NULL );
387 if( rc != LDAP_SUCCESS ) {
388 Debug( LDAP_DEBUG_ANY,
389 "%s: line %d: defaultSearchBase DN is invalid\n",
395 /* set maximum threads in thread pool */
396 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
399 Debug( LDAP_DEBUG_ANY,
400 "%s: line %d: missing count in \"threads <count>\" line\n",
406 c = strtol( cargv[1], &next, 10 );
407 if (next == NULL || next[0] != '\0' ) {
408 Debug( LDAP_DEBUG_ANY,
409 "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
410 fname, lineno, cargv[1] );
415 Debug( LDAP_DEBUG_ANY,
416 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
422 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
424 /* save for later use */
425 connection_pool_max = c;
427 /* get pid file name */
428 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
430 Debug( LDAP_DEBUG_ANY,
431 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
437 slapd_pid_file = ch_strdup( cargv[1] );
439 /* get args file name */
440 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
442 Debug( LDAP_DEBUG_ANY,
443 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
449 slapd_args_file = ch_strdup( cargv[1] );
451 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
454 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
457 /* default password hash */
458 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
460 Debug( LDAP_DEBUG_ANY,
461 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
466 if ( default_passwd_hash != NULL ) {
467 Debug( LDAP_DEBUG_ANY,
468 "%s: line %d: already set default password_hash!\n",
474 for(i = 1; i < cargc; i++) {
475 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
476 Debug( LDAP_DEBUG_ANY,
477 "%s: line %d: password scheme \"%s\" not available\n",
478 fname, lineno, cargv[i] );
480 ldap_charray_add( &default_passwd_hash, cargv[i] );
483 if( !default_passwd_hash ) {
484 Debug( LDAP_DEBUG_ANY,
485 "%s: line %d: no valid hashes found\n",
490 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
493 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
494 "\"password-crypt-salt-format <format>\" line\n",
500 lutil_salt_format( cargv[1] );
502 #ifdef SLAP_AUTH_REWRITE
503 /* use authid rewrite instead of sasl regexp */
504 } else if ( strncasecmp( cargv[0], "auth-rewrite",
505 STRLENOF("auth-rewrite") ) == 0 )
507 int rc = slap_sasl_rewrite_config( fname, lineno,
512 #endif /* SLAP_AUTH_REWRITE */
514 /* Auth + SASL config options */
515 } else if ( !strncasecmp( cargv[0], "auth", STRLENOF("auth") ) ||
516 !strncasecmp( cargv[0], "sasl", STRLENOF("sasl") ))
518 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
522 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
525 Debug( LDAP_DEBUG_ANY,
526 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
530 ber_str2bv( cargv[1], 0, 0, &dn );
532 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
533 &be->be_schemandn, NULL );
535 rc = dnPrettyNormal( NULL, &dn, &frontendDB->be_schemadn,
536 &frontendDB->be_schemandn, NULL );
538 if ( rc != LDAP_SUCCESS ) {
539 Debug( LDAP_DEBUG_ANY,
540 "%s: line %d: schemadn DN is invalid\n",
545 /* set UCDATA path */
546 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
549 Debug( LDAP_DEBUG_ANY,
550 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
556 err = load_ucdata( cargv[1] );
559 Debug( LDAP_DEBUG_ANY,
560 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
568 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
570 struct slap_limits_set *lim;
573 Debug( LDAP_DEBUG_ANY,
574 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
581 lim = &frontendDB->be_def_limit;
583 lim = &be->be_def_limit;
586 for ( i = 1; i < cargc; i++ ) {
587 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
588 rc = limits_parse_one( cargv[i], lim );
590 Debug( LDAP_DEBUG_ANY,
591 "%s: line %d: unable "
592 "to parse value \"%s\" "
595 fname, lineno, cargv[i] );
600 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
601 lim->lms_s_soft = -1;
603 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
604 if ( next == cargv[i] ) {
605 Debug( LDAP_DEBUG_ANY,
606 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
607 fname, lineno, cargv[i] );
610 } else if ( next[0] != '\0' ) {
611 Debug( LDAP_DEBUG_ANY,
612 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
613 fname, lineno, next );
621 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
623 struct slap_limits_set *lim;
626 Debug( LDAP_DEBUG_ANY,
627 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
634 lim = &frontendDB->be_def_limit;
636 lim = &be->be_def_limit;
639 for ( i = 1; i < cargc; i++ ) {
640 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
641 rc = limits_parse_one( cargv[i], lim );
643 Debug( LDAP_DEBUG_ANY,
644 "%s: line %d: unable "
645 "to parse value \"%s\" "
648 fname, lineno, cargv[i] );
653 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
654 lim->lms_t_soft = -1;
656 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
657 if ( next == cargv[i] ) {
658 Debug( LDAP_DEBUG_ANY,
659 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
660 fname, lineno, cargv[i] );
663 } else if ( next[0] != '\0' ) {
664 Debug( LDAP_DEBUG_ANY,
665 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
666 fname, lineno, next );
673 /* set regex-based limits */
674 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
676 Debug( LDAP_DEBUG_ANY,
677 "%s: line %d \"limits\" allowed only in database environment.\n%s",
682 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
686 /* mark this as a subordinate database */
687 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
689 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
690 "must appear inside a database definition.\n",
695 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
699 /* add an overlay to this backend */
700 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
702 if ( cargv[1][0] == '-' && overlay_config( frontendDB, &cargv[1][1] ) ) {
704 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
705 "(optional) global overlay \"%s\" configuration "
706 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
707 } else if ( overlay_config( frontendDB, cargv[1] ) ) {
712 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
714 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
715 "(optional) overlay \"%s\" configuration "
716 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
717 } else if ( overlay_config( be, cargv[1] ) ) {
722 /* set database suffix */
723 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
725 struct berval dn, pdn, ndn;
728 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
729 "missing dn in \"suffix <dn>\" line\n",
734 } else if ( cargc > 2 ) {
735 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
736 "after <dn> in \"suffix %s\" line (ignored)\n",
737 fname, lineno, cargv[1] );
741 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
742 "must appear inside a database definition\n",
746 #if defined(SLAPD_MONITOR_DN)
747 /* "cn=Monitor" is reserved for monitoring slap */
748 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
749 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
750 "%s\" is reserved for monitoring slapd\n",
751 fname, lineno, SLAPD_MONITOR_DN );
753 #endif /* SLAPD_MONITOR_DN */
756 if ( load_ucdata( NULL ) < 0 ) return 1;
758 dn.bv_val = cargv[1];
759 dn.bv_len = strlen( cargv[1] );
761 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
762 if( rc != LDAP_SUCCESS ) {
763 Debug( LDAP_DEBUG_ANY,
764 "%s: line %d: suffix DN is invalid\n",
769 tmp_be = select_backend( &ndn, 0, 0 );
770 if ( tmp_be == be ) {
771 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
772 "already served by this backend (ignored)\n",
777 } else if ( tmp_be != NULL ) {
778 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
779 "already served by a preceeding backend \"%s\"\n",
780 fname, lineno, tmp_be->be_suffix[0].bv_val );
785 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
786 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
787 "suffix DN empty and default "
788 "search base provided \"%s\" (assuming okay)\n",
789 fname, lineno, default_search_base.bv_val );
792 ber_bvarray_add( &be->be_suffix, &pdn );
793 ber_bvarray_add( &be->be_nsuffix, &ndn );
795 /* set max deref depth */
796 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
799 Debug( LDAP_DEBUG_ANY,
800 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
806 Debug( LDAP_DEBUG_ANY,
807 "%s: line %d: depth line must appear inside a database definition.\n",
812 i = strtol( cargv[1], &next, 10 );
813 if ( next == NULL || next[0] != '\0' ) {
814 Debug( LDAP_DEBUG_ANY,
815 "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
816 "line.\n", fname, lineno, cargv[1] );
821 Debug( LDAP_DEBUG_ANY,
822 "%s: line %d: depth must be positive.\n",
828 be->be_max_deref_depth = i;
830 /* set magic "root" dn for this database */
831 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
833 Debug( LDAP_DEBUG_ANY,
834 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
841 Debug( LDAP_DEBUG_ANY,
842 "%s: line %d: rootdn line must appear inside a database definition.\n",
849 if ( load_ucdata( NULL ) < 0 ) return 1;
851 dn.bv_val = cargv[1];
852 dn.bv_len = strlen( cargv[1] );
854 rc = dnPrettyNormal( NULL, &dn,
856 &be->be_rootndn, NULL );
858 if( rc != LDAP_SUCCESS ) {
859 Debug( LDAP_DEBUG_ANY,
860 "%s: line %d: rootdn DN is invalid\n",
866 /* set super-secret magic database password */
867 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
869 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
870 "missing passwd in \"rootpw <passwd>\" line\n",
877 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
878 "rootpw line must appear inside a database "
884 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
887 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
888 "rootpw can only be set when rootdn is under suffix\n",
893 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
894 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
897 /* make this database read-only */
898 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
900 Debug( LDAP_DEBUG_ANY,
901 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
907 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
908 frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
910 frontendDB->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
914 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
915 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
917 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
921 /* restricts specific operations */
922 } else if ( strcasecmp( cargv[0], "restrict" ) == 0 ) {
923 slap_mask_t restrictops = 0;
924 struct restrictable_exops_t {
927 } restrictable_exops[] = {
928 { LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
929 { LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
930 { LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
931 { LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
937 Debug( LDAP_DEBUG_ANY,
938 "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
939 "line.\n", fname, lineno, 0 );
943 for ( i = 1; i < cargc; i++ ) {
944 if ( strcasecmp( cargv[ i ], "read" ) == 0 ) {
945 restrictops |= SLAP_RESTRICT_OP_READS;
947 } else if ( strcasecmp( cargv[ i ], "write" ) == 0 ) {
948 restrictops |= SLAP_RESTRICT_OP_WRITES;
950 } else if ( strcasecmp( cargv[ i ], "add" ) == 0 ) {
951 restrictops |= SLAP_RESTRICT_OP_ADD;
953 } else if ( strcasecmp( cargv[ i ], "bind" ) == 0 ) {
954 restrictops |= SLAP_RESTRICT_OP_BIND;
956 } else if ( strcasecmp( cargv[ i ], "compare" ) == 0 ) {
957 restrictops |= SLAP_RESTRICT_OP_COMPARE;
959 } else if ( strcasecmp( cargv[ i ], "delete" ) == 0 ) {
960 restrictops |= SLAP_RESTRICT_OP_DELETE;
962 } else if ( strncasecmp( cargv[ i ], "extended",
963 STRLENOF( "extended" ) ) == 0 )
965 char *e = cargv[ i ] + STRLENOF( "extended" );
971 for ( j = 0; restrictable_exops[ j ].name; j++ ) {
972 if ( strcmp( e, restrictable_exops[j].name ) == 0 )
974 restrictops |= restrictable_exops[ j ].flag;
979 if ( restrictable_exops[ j ].name == NULL ) {
980 goto restrict_unknown;
983 restrictops &= ~SLAP_RESTRICT_OP_EXTENDED;
985 } else if ( e[0] == '\0' ) {
986 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
987 restrictops |= SLAP_RESTRICT_OP_EXTENDED;
990 goto restrict_unknown;
993 } else if ( strcasecmp( cargv[ i ], "modify" ) == 0 ) {
994 restrictops |= SLAP_RESTRICT_OP_MODIFY;
996 } else if ( strcasecmp( cargv[ i ], "rename" ) == 0
997 || strcasecmp( cargv[ i ], "modrdn" ) == 0 )
999 restrictops |= SLAP_RESTRICT_OP_RENAME;
1001 } else if ( strcasecmp( cargv[ i ], "search" ) == 0 ) {
1002 restrictops |= SLAP_RESTRICT_OP_SEARCH;
1007 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1008 "unknown operation %s in \"allow <features>\" line\n",
1009 fname, lineno, cargv[i] );
1015 frontendDB->be_restrictops |= restrictops;
1017 be->be_restrictops |= restrictops;
1020 /* allow these features */
1021 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1022 strcasecmp( cargv[0], "allow" ) == 0 )
1024 slap_mask_t allows = 0;
1027 Debug( LDAP_DEBUG_ANY,
1028 "%s: line %d: allow line must appear prior to database definitions\n",
1034 Debug( LDAP_DEBUG_ANY,
1035 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1041 for( i=1; i < cargc; i++ ) {
1042 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1043 allows |= SLAP_ALLOW_BIND_V2;
1045 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1046 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1048 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1049 allows |= SLAP_ALLOW_BIND_ANON_DN;
1051 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1052 allows |= SLAP_ALLOW_UPDATE_ANON;
1055 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1056 "unknown feature %s in \"allow <features>\" line\n",
1057 fname, lineno, cargv[i] );
1063 global_allows |= allows;
1065 /* disallow these features */
1066 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1067 strcasecmp( cargv[0], "disallow" ) == 0 )
1069 slap_mask_t disallows = 0;
1072 Debug( LDAP_DEBUG_ANY,
1073 "%s: line %d: disallow line must appear prior to database definitions\n",
1079 Debug( LDAP_DEBUG_ANY,
1080 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1086 for( i=1; i < cargc; i++ ) {
1087 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1088 disallows |= SLAP_DISALLOW_BIND_ANON;
1090 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1091 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1093 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1094 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1096 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1097 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1099 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1100 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1103 Debug( LDAP_DEBUG_ANY,
1104 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1105 fname, lineno, cargv[i] );
1111 global_disallows |= disallows;
1113 /* require these features */
1114 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1115 strcasecmp( cargv[0], "require" ) == 0 )
1117 slap_mask_t requires = 0;
1120 Debug( LDAP_DEBUG_ANY,
1121 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1127 for( i=1; i < cargc; i++ ) {
1128 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1129 requires |= SLAP_REQUIRE_BIND;
1131 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1132 requires |= SLAP_REQUIRE_LDAP_V3;
1134 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1135 requires |= SLAP_REQUIRE_AUTHC;
1137 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1138 requires |= SLAP_REQUIRE_SASL;
1140 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1141 requires |= SLAP_REQUIRE_STRONG;
1143 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1144 Debug( LDAP_DEBUG_ANY,
1145 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1146 fname, lineno, cargv[i] );
1153 frontendDB->be_requires = requires;
1155 be->be_requires = requires;
1158 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1159 slap_ssf_set_t *set;
1162 Debug( LDAP_DEBUG_ANY,
1163 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1170 set = &frontendDB->be_ssf_set;
1172 set = &be->be_ssf_set;
1175 for( i=1; i < cargc; i++ ) {
1179 if ( strncasecmp( cargv[i], "ssf=",
1180 STRLENOF("ssf=") ) == 0 )
1182 tgt = &set->sss_ssf;
1183 src = &cargv[i][STRLENOF("ssf=")];
1185 } else if ( strncasecmp( cargv[i], "transport=",
1186 STRLENOF("transport=") ) == 0 )
1188 tgt = &set->sss_transport;
1189 src = &cargv[i][STRLENOF("transport=")];
1191 } else if ( strncasecmp( cargv[i], "tls=",
1192 STRLENOF("tls=") ) == 0 )
1194 tgt = &set->sss_tls;
1195 src = &cargv[i][STRLENOF("tls=")];
1197 } else if ( strncasecmp( cargv[i], "sasl=",
1198 STRLENOF("sasl=") ) == 0 )
1200 tgt = &set->sss_sasl;
1201 src = &cargv[i][STRLENOF("sasl=")];
1203 } else if ( strncasecmp( cargv[i], "update_ssf=",
1204 STRLENOF("update_ssf=") ) == 0 )
1206 tgt = &set->sss_update_ssf;
1207 src = &cargv[i][STRLENOF("update_ssf=")];
1209 } else if ( strncasecmp( cargv[i], "update_transport=",
1210 STRLENOF("update_transport=") ) == 0 )
1212 tgt = &set->sss_update_transport;
1213 src = &cargv[i][STRLENOF("update_transport=")];
1215 } else if ( strncasecmp( cargv[i], "update_tls=",
1216 STRLENOF("update_tls=") ) == 0 )
1218 tgt = &set->sss_update_tls;
1219 src = &cargv[i][STRLENOF("update_tls=")];
1221 } else if ( strncasecmp( cargv[i], "update_sasl=",
1222 STRLENOF("update_sasl=") ) == 0 )
1224 tgt = &set->sss_update_sasl;
1225 src = &cargv[i][STRLENOF("update_sasl=")];
1227 } else if ( strncasecmp( cargv[i], "simple_bind=",
1228 STRLENOF("simple_bind=") ) == 0 )
1230 tgt = &set->sss_simple_bind;
1231 src = &cargv[i][STRLENOF("simple_bind=")];
1234 Debug( LDAP_DEBUG_ANY,
1235 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1236 fname, lineno, cargv[i] );
1241 *tgt = strtol( src, &next, 10 );
1242 if ( next == NULL || next[0] != '\0' ) {
1243 Debug( LDAP_DEBUG_ANY,
1244 "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1245 fname, lineno, cargv[i] );
1251 /* where to send clients when we don't hold it */
1252 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1254 Debug( LDAP_DEBUG_ANY,
1255 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1261 if( validate_global_referral( cargv[1] ) ) {
1262 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1263 "invalid URL (%s) in \"referral\" line.\n",
1264 fname, lineno, cargv[1] );
1268 vals[0].bv_val = cargv[1];
1269 vals[0].bv_len = strlen( vals[0].bv_val );
1270 if( value_add( &default_referral, vals ) )
1273 /* start of a new database definition */
1274 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1277 Debug( LDAP_DEBUG_ANY,
1278 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1282 level = strtol( cargv[2], &next, 10 );
1283 if ( next == NULL || next[0] != '\0' ){
1284 Debug( LDAP_DEBUG_ANY,
1285 "%s: line %d: unable to parse level \"%s\" in debug directive, "
1286 "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1290 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1291 lutil_set_debug_level( cargv[1], level );
1292 /* specify an Object Identifier macro */
1293 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1294 rc = parse_oidm( fname, lineno, cargc, cargv );
1297 /* specify an objectclass */
1298 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1300 Debug( LDAP_DEBUG_ANY,
1301 "%s: line %d: illegal objectclass format.\n",
1305 } else if ( *cargv[1] == '(' /*')'*/) {
1307 p = strchr(saveline,'(' /*')'*/);
1308 rc = parse_oc( fname, lineno, p, cargv );
1312 Debug( LDAP_DEBUG_ANY,
1313 "%s: line %d: old objectclass format not supported.\n",
1317 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1319 p = strchr(saveline,'(' /*')'*/);
1320 rc = parse_cr( fname, lineno, p, cargv );
1323 /* specify an attribute type */
1324 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1325 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1328 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1329 "illegal attribute type format.\n",
1333 } else if ( *cargv[1] == '(' /*')'*/) {
1335 p = strchr(saveline,'(' /*')'*/);
1336 rc = parse_at( fname, lineno, p, cargv );
1340 Debug( LDAP_DEBUG_ANY,
1341 "%s: line %d: old attribute type format not supported.\n",
1346 /* define attribute option(s) */
1347 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1348 ad_define_option( NULL, NULL, 0 );
1349 for ( i = 1; i < cargc; i++ )
1350 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1353 /* turn on/off schema checking */
1354 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1356 Debug( LDAP_DEBUG_ANY,
1357 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1362 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1363 Debug( LDAP_DEBUG_ANY,
1364 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1366 global_schemacheck = 0;
1368 global_schemacheck = 1;
1371 /* specify access control info */
1372 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1373 parse_acl( be, fname, lineno, cargc, cargv );
1375 /* debug level to log things to syslog */
1376 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1378 Debug( LDAP_DEBUG_ANY,
1379 "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1387 for( i=1; i < cargc; i++ ) {
1390 if ( isdigit( cargv[i][0] ) ) {
1391 level = strtol( cargv[i], &next, 10 );
1392 if ( next == NULL || next[0] != '\0' ) {
1393 Debug( LDAP_DEBUG_ANY,
1394 "%s: line %d: unable to parse level \"%s\" "
1395 "in \"loglevel <level> [...]\" line.\n",
1396 fname, lineno , cargv[i] );
1405 { LDAP_DEBUG_TRACE, "Trace" },
1406 { LDAP_DEBUG_PACKETS, "Packets" },
1407 { LDAP_DEBUG_ARGS, "Args" },
1408 { LDAP_DEBUG_CONNS, "Conns" },
1409 { LDAP_DEBUG_BER, "BER" },
1410 { LDAP_DEBUG_FILTER, "Filter" },
1411 { LDAP_DEBUG_CONFIG, "Config" },
1412 { LDAP_DEBUG_ACL, "ACL" },
1413 { LDAP_DEBUG_STATS, "Stats" },
1414 { LDAP_DEBUG_STATS2, "Stats2" },
1415 { LDAP_DEBUG_SHELL, "Shell" },
1416 { LDAP_DEBUG_PARSE, "Parse" },
1417 { LDAP_DEBUG_CACHE, "Cache" },
1418 { LDAP_DEBUG_INDEX, "Index" },
1424 for ( j = 0; int_2_level[j].s; j++ ) {
1425 if ( strcasecmp( cargv[i], int_2_level[j].s ) == 0 ) {
1426 level = int_2_level[j].i;
1431 if ( int_2_level[j].s == NULL ) {
1432 Debug( LDAP_DEBUG_ANY,
1433 "%s: line %d: unknown level \"%s\" "
1434 "in \"loglevel <level> [...]\" line.\n",
1435 fname, lineno , cargv[i] );
1440 ldap_syslog |= level;
1443 /* list of sync replication information in this backend (slave only) */
1444 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1447 Debug( LDAP_DEBUG_ANY,
1448 "%s: line %d: syncrepl line must appear inside "
1449 "a database definition.\n", fname, lineno, 0);
1452 } else if ( SLAP_SHADOW( be )) {
1453 Debug( LDAP_DEBUG_ANY,
1454 "%s: line %d: syncrepl: database already shadowed.\n",
1458 } else if ( add_syncrepl( be, cargv, cargc )) {
1462 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1464 /* list of replicas of the data in this backend (master only) */
1465 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1467 Debug( LDAP_DEBUG_ANY,
1468 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1474 Debug( LDAP_DEBUG_ANY,
1475 "%s: line %d: replica line must appear inside a database definition\n",
1482 for ( i = 1; i < cargc; i++ ) {
1483 if ( strncasecmp( cargv[i], "host=", 5 )
1485 nr = add_replica_info( be,
1488 } else if (strncasecmp( cargv[i], "uri=", 4 )
1490 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1492 Debug( LDAP_DEBUG_ANY,
1493 "%s: line %d: replica line contains invalid "
1494 "uri definition.\n", fname, lineno, 0);
1497 if (ludp->lud_host == NULL ) {
1498 Debug( LDAP_DEBUG_ANY,
1499 "%s: line %d: replica line contains invalid "
1500 "uri definition - missing hostname.\n", fname, lineno, 0);
1503 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1504 if ( replicahost == NULL ) {
1505 Debug( LDAP_DEBUG_ANY,
1506 "out of memory in read_config\n", 0, 0, 0 );
1507 ldap_free_urldesc( ludp );
1508 exit( EXIT_FAILURE );
1510 sprintf(replicahost, "%s:%d",
1511 ludp->lud_host, ludp->lud_port);
1512 nr = add_replica_info( be, replicahost );
1513 ldap_free_urldesc( ludp );
1514 ch_free(replicahost);
1519 Debug( LDAP_DEBUG_ANY,
1520 "%s: line %d: missing host or uri in \"replica\" line\n",
1524 } else if ( nr == -1 ) {
1525 Debug( LDAP_DEBUG_ANY,
1526 "%s: line %d: unable to add replica \"%s\"\n",
1527 fname, lineno, cargv[i] + 5 );
1530 for ( i = 1; i < cargc; i++ ) {
1531 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1533 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1535 Debug( LDAP_DEBUG_ANY,
1536 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1537 fname, lineno, cargv[i] + 7 );
1541 Debug( LDAP_DEBUG_ANY,
1542 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1547 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1549 char *arg = cargv[i] + 4;
1551 if ( arg[0] == '!' ) {
1556 if ( arg[0] != '=' ) {
1560 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1561 Debug( LDAP_DEBUG_ANY,
1562 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1563 fname, lineno, arg + 1 );
1571 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1574 /* dn of slave entity allowed to write to replica */
1575 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1577 Debug( LDAP_DEBUG_ANY,
1578 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1584 Debug( LDAP_DEBUG_ANY,
1585 "%s: line %d: updatedn line must appear inside a database definition\n",
1589 } else if ( SLAP_SHADOW(be) ) {
1590 Debug( LDAP_DEBUG_ANY,
1591 "%s: line %d: updatedn: database already shadowed.\n",
1598 if ( load_ucdata( NULL ) < 0 ) return 1;
1600 dn.bv_val = cargv[1];
1601 dn.bv_len = strlen( cargv[1] );
1603 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1604 if( rc != LDAP_SUCCESS ) {
1605 Debug( LDAP_DEBUG_ANY,
1606 "%s: line %d: updatedn DN is invalid\n",
1612 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
1614 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1616 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1617 "missing url in \"updateref <ldapurl>\" line\n",
1623 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1624 " line must appear inside a database definition\n",
1628 } else if ( !SLAP_SHADOW(be) ) {
1629 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1630 "updateref line must after syncrepl or updatedn.\n",
1635 if( validate_global_referral( cargv[1] ) ) {
1636 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1637 "invalid URL (%s) in \"updateref\" line.\n",
1638 fname, lineno, cargv[1] );
1642 vals[0].bv_val = cargv[1];
1643 vals[0].bv_len = strlen( vals[0].bv_val );
1644 if( value_add( &be->be_update_refs, vals ) ) {
1648 /* replication log file to which changes are appended */
1649 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1651 Debug( LDAP_DEBUG_ANY,
1652 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1658 be->be_replogfile = ch_strdup( cargv[1] );
1660 replogfile = ch_strdup( cargv[1] );
1663 /* file from which to read additional rootdse attrs */
1664 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
1666 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1667 "missing filename in \"rootDSE <filename>\" line.\n",
1672 if( read_root_dse_file( cargv[1] ) ) {
1673 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1674 "could not read \"rootDSE <filename>\" line\n",
1679 /* maintain lastmodified{by,time} attributes */
1680 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1682 Debug( LDAP_DEBUG_ANY,
1683 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1690 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1691 " line must appear inside a database definition\n",
1695 } else if ( SLAP_NOLASTMODCMD(be) ) {
1696 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1697 " not available for %s databases\n",
1698 fname, lineno, be->bd_info->bi_type );
1702 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1703 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
1705 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1709 /* turn on/off gentle SIGHUP handling */
1710 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
1712 Debug( LDAP_DEBUG_ANY,
1713 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
1717 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1718 global_gentlehup = 0;
1720 global_gentlehup = 1;
1724 /* set idle timeout value */
1725 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1728 Debug( LDAP_DEBUG_ANY,
1729 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1735 i = atoi( cargv[1] );
1738 Debug( LDAP_DEBUG_ANY,
1739 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1745 global_idletimeout = i;
1747 /* include another config file */
1748 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1750 Debug( LDAP_DEBUG_ANY,
1751 "%s: line %d: missing filename in \"include <filename>\" line\n",
1756 savefname = ch_strdup( cargv[1] );
1757 savelineno = lineno;
1759 if ( read_config( savefname, depth+1 ) != 0 ) {
1764 lineno = savelineno - 1;
1766 /* location of kerberos srvtab file */
1767 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1769 Debug( LDAP_DEBUG_ANY,
1770 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1775 ldap_srvtab = ch_strdup( cargv[1] );
1777 #ifdef SLAPD_MODULES
1778 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1780 Debug( LDAP_DEBUG_ANY,
1781 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1784 exit( EXIT_FAILURE );
1786 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1787 Debug( LDAP_DEBUG_ANY,
1788 "%s: line %d: failed to load or initialize module %s\n",
1789 fname, lineno, cargv[1]);
1791 exit( EXIT_FAILURE );
1793 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1795 Debug( LDAP_DEBUG_ANY,
1796 "%s: line %d: missing path in \"modulepath <path>\" line\n",
1799 exit( EXIT_FAILURE );
1801 if (module_path( cargv[1] )) {
1802 Debug( LDAP_DEBUG_ANY,
1803 "%s: line %d: failed to set module search path to %s\n",
1804 fname, lineno, cargv[1]);
1806 exit( EXIT_FAILURE );
1809 #endif /*SLAPD_MODULES*/
1812 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
1813 rc = ldap_pvt_tls_set_option( NULL,
1814 LDAP_OPT_X_TLS_RANDOM_FILE,
1819 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1820 rc = ldap_pvt_tls_set_option( NULL,
1821 LDAP_OPT_X_TLS_CIPHER_SUITE,
1826 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1827 rc = ldap_pvt_tls_set_option( NULL,
1828 LDAP_OPT_X_TLS_CERTFILE,
1833 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1834 rc = ldap_pvt_tls_set_option( NULL,
1835 LDAP_OPT_X_TLS_KEYFILE,
1840 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1841 rc = ldap_pvt_tls_set_option( NULL,
1842 LDAP_OPT_X_TLS_CACERTDIR,
1847 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1848 rc = ldap_pvt_tls_set_option( NULL,
1849 LDAP_OPT_X_TLS_CACERTFILE,
1853 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1854 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
1856 rc = ldap_pvt_tls_set_option( NULL,
1857 LDAP_OPT_X_TLS_REQUIRE_CERT,
1860 rc = ldap_int_tls_config( NULL,
1861 LDAP_OPT_X_TLS_REQUIRE_CERT,
1870 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
1871 #ifdef SLAPD_RLOOKUPS
1873 Debug( LDAP_DEBUG_ANY,
1874 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
1879 if ( !strcasecmp( cargv[1], "on" ) ) {
1880 use_reverse_lookup = 1;
1881 } else if ( !strcasecmp( cargv[1], "off" ) ) {
1882 use_reverse_lookup = 0;
1884 Debug( LDAP_DEBUG_ANY,
1885 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
1890 #else /* !SLAPD_RLOOKUPS */
1891 Debug( LDAP_DEBUG_ANY,
1892 "%s: line %d: reverse lookups are not configured (ignored).\n",
1894 #endif /* !SLAPD_RLOOKUPS */
1896 /* Netscape plugins */
1897 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
1898 #if defined( LDAP_SLAPI )
1900 #ifdef notdef /* allow global plugins, too */
1902 * a "plugin" line must be inside a database
1903 * definition, since we implement pre-,post-
1904 * and extended operation plugins
1907 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
1908 "line must appear inside a database "
1909 "definition\n", fname, lineno, 0 );
1914 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
1917 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
1918 "config read failed.\n", fname, lineno, 0 );
1921 slapi_plugins_used++;
1923 #else /* !defined( LDAP_SLAPI ) */
1924 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
1925 "not supported.\n", fname, lineno, 0 );
1928 #endif /* !defined( LDAP_SLAPI ) */
1930 /* Netscape plugins */
1931 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
1932 #if defined( LDAP_SLAPI )
1934 Debug( LDAP_DEBUG_ANY,
1935 "%s: line %d: missing file name "
1936 "in pluginlog <filename> line.\n",
1941 if ( slapi_log_file != NULL ) {
1942 ch_free( slapi_log_file );
1945 slapi_log_file = ch_strdup( cargv[1] );
1946 #endif /* !defined( LDAP_SLAPI ) */
1948 /* pass anything else to the current backend info/db config routine */
1951 if ( bi->bi_config ) {
1952 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
1958 case SLAP_CONF_UNKNOWN:
1959 Debug( LDAP_DEBUG_ANY,
1960 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1961 fname, lineno, cargv[0] );
1969 } else if ( be != NULL ) {
1970 if ( be->be_config ) {
1971 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
1977 case SLAP_CONF_UNKNOWN:
1978 Debug( LDAP_DEBUG_ANY,
1979 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1980 fname, lineno, cargv[0] );
1989 if ( frontendDB->be_config ) {
1990 rc = (*frontendDB->be_config)( frontendDB, fname, lineno, cargc, cargv );
1996 case SLAP_CONF_UNKNOWN:
1997 Debug( LDAP_DEBUG_ANY,
1998 "%s: line %d: unknown directive \"%s\" inside global database definition (ignored)\n",
1999 fname, lineno, cargv[0] );
2012 if ( depth == 0 ) ch_free( cargv );
2014 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2015 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2016 &frontendDB->be_schemadn );
2017 dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2020 if ( load_ucdata( NULL ) < 0 ) return 1;
2032 char logbuf[sizeof("pseudorootpw ***")];
2035 token = strtok_quote( line, " \t" );
2039 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2040 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2041 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2042 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2043 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2045 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2048 if ( strtok_quote_ptr ) {
2049 *strtok_quote_ptr = ' ';
2052 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2054 if ( strtok_quote_ptr ) {
2055 *strtok_quote_ptr = '\0';
2058 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2059 if ( cargc == cargv_size - 1 ) {
2061 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2063 if ( tmp == NULL ) {
2064 Debug( LDAP_DEBUG_ANY,
2065 "line %d: out of memory\n",
2070 cargv_size += ARGS_STEP;
2072 cargv[cargc++] = token;
2074 cargv[cargc] = NULL;
2079 strtok_quote( char *line, char *sep )
2085 strtok_quote_ptr = NULL;
2086 if ( line != NULL ) {
2089 while ( *next && strchr( sep, *next ) ) {
2093 if ( *next == '\0' ) {
2099 for ( inquote = 0; *next; ) {
2107 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2113 next + 1, strlen( next + 1 ) + 1 );
2114 next++; /* dont parse the escaped character */
2119 if ( strchr( sep, *next ) != NULL ) {
2120 strtok_quote_ptr = next;
2133 static char buf[BUFSIZ];
2135 static size_t lmax, lcur;
2137 #define CATLINE( buf ) \
2139 size_t len = strlen( buf ); \
2140 while ( lcur + len + 1 > lmax ) { \
2142 line = (char *) ch_realloc( line, lmax ); \
2144 strcpy( line + lcur, buf ); \
2149 fp_getline( FILE *fp, int *lineno )
2157 /* hack attack - keeps us from having to keep a stack of bufs... */
2158 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2163 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2164 /* trim off \r\n or \n */
2165 if ( (p = strchr( buf, '\n' )) != NULL ) {
2166 if( p > buf && p[-1] == '\r' ) --p;
2170 /* trim off trailing \ and append the next line */
2171 if ( line[ 0 ] != '\0'
2172 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2173 && p[ -1 ] != '\\' ) {
2178 if ( ! isspace( (unsigned char) buf[0] ) ) {
2182 /* change leading whitespace to a space */
2191 return( line[0] ? line : NULL );
2195 fp_getline_init( int *lineno )
2201 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2203 load_ucdata( char *path )
2206 static int loaded = 0;
2212 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2214 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2222 /* ucdata is now hardcoded */
2230 ucdata_unload( UCDATA_ALL );
2232 /* NOTE: in case of early exit, frontendDB can be NULL */
2233 if ( frontendDB->be_schemandn.bv_val )
2234 free( frontendDB->be_schemandn.bv_val );
2235 if ( frontendDB->be_schemadn.bv_val )
2236 free( frontendDB->be_schemadn.bv_val );
2237 if ( frontendDB->be_acl )
2238 acl_destroy( frontendDB->be_acl, NULL );
2241 if ( slapd_args_file )
2242 free ( slapd_args_file );
2243 if ( slapd_pid_file )
2244 free ( slapd_pid_file );
2245 if ( default_passwd_hash )
2246 ldap_charray_free( default_passwd_hash );
2257 syncinfo_t *si_entry;
2259 int duplicated_replica_id = 0;
2261 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2264 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2268 si->si_tls = SYNCINFO_TLS_OFF;
2269 if ( be->be_rootndn.bv_val ) {
2270 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2272 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2273 si->si_schemachecking = 0;
2274 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2275 &si->si_filterstr );
2276 si->si_base.bv_val = NULL;
2277 si->si_scope = LDAP_SCOPE_SUBTREE;
2278 si->si_attrsonly = 0;
2279 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2280 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2281 si->si_attrs = NULL;
2282 si->si_allattrs = 0;
2283 si->si_allopattrs = 0;
2284 si->si_exattrs = NULL;
2285 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2286 si->si_interval = 86400;
2287 si->si_retryinterval = NULL;
2288 si->si_retrynum_init = NULL;
2289 si->si_retrynum = NULL;
2290 si->si_syncCookie.ctxcsn = NULL;
2291 si->si_syncCookie.octet_str = NULL;
2292 si->si_syncCookie.sid = -1;
2293 si->si_manageDSAit = 0;
2296 si->si_syncUUID_ndn.bv_val = NULL;
2297 si->si_syncUUID_ndn.bv_len = 0;
2299 si->si_presentlist = NULL;
2300 LDAP_LIST_INIT( &si->si_nonpresentlist );
2302 rc = parse_syncrepl_line( cargv, cargc, si );
2304 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2305 if ( si->si_rid == si_entry->si_rid ) {
2306 Debug( LDAP_DEBUG_ANY,
2307 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2308 duplicated_replica_id = 1;
2313 if ( rc < 0 || duplicated_replica_id ) {
2314 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2317 Debug( LDAP_DEBUG_CONFIG,
2318 "Config: ** successfully added syncrepl \"%s\"\n",
2319 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2320 if ( !si->si_schemachecking ) {
2321 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2324 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2330 #define PROVIDERSTR "provider"
2331 #define SUFFIXSTR "suffix"
2332 #define UPDATEDNSTR "updatedn"
2333 #define BINDMETHSTR "bindmethod"
2334 #define SIMPLESTR "simple"
2335 #define SASLSTR "sasl"
2336 #define BINDDNSTR "binddn"
2337 #define CREDSTR "credentials"
2338 #define OLDAUTHCSTR "bindprincipal"
2339 #define AUTHCSTR "authcID"
2340 #define AUTHZSTR "authzID"
2341 #define SRVTABSTR "srvtab"
2342 #define SASLMECHSTR "saslmech"
2343 #define REALMSTR "realm"
2344 #define SECPROPSSTR "secprops"
2345 #define STARTTLSSTR "starttls"
2346 #define CRITICALSTR "critical"
2348 #define SCHEMASTR "schemachecking"
2349 #define FILTERSTR "filter"
2350 #define SEARCHBASESTR "searchbase"
2351 #define SCOPESTR "scope"
2352 #define ATTRSSTR "attrs"
2353 #define EXATTRSSTR "exattrs"
2354 #define ATTRSONLYSTR "attrsonly"
2355 #define TYPESTR "type"
2356 #define INTERVALSTR "interval"
2357 #define LASTMODSTR "lastmod"
2358 #define LMREQSTR "req"
2359 #define LMGENSTR "gen"
2360 #define LMNOSTR "no"
2361 #define MANAGEDSAITSTR "manageDSAit"
2362 #define SLIMITSTR "sizelimit"
2363 #define TLIMITSTR "timelimit"
2365 #define RETRYSTR "retry"
2367 #define GOT_ID 0x0001
2368 #define GOT_PROVIDER 0x0002
2369 #define GOT_METHOD 0x0004
2370 #define GOT_ALL 0x0007
2373 parse_syncrepl_line(
2384 for ( i = 1; i < cargc; i++ ) {
2385 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2387 /* '\0' string terminator accounts for '=' */
2388 val = cargv[ i ] + sizeof( IDSTR );
2390 if ( tmp >= 1000 || tmp < 0 ) {
2391 fprintf( stderr, "Error: parse_syncrepl_line: "
2392 "syncrepl id %d is out of range [0..999]\n", tmp );
2397 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2398 sizeof( PROVIDERSTR ) - 1 )) {
2399 val = cargv[ i ] + sizeof( PROVIDERSTR );
2400 si->si_provideruri = ch_strdup( val );
2401 si->si_provideruri_bv = (BerVarray)
2402 ch_calloc( 2, sizeof( struct berval ));
2403 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2404 1, &si->si_provideruri_bv[0] );
2405 si->si_provideruri_bv[1].bv_len = 0;
2406 si->si_provideruri_bv[1].bv_val = NULL;
2407 gots |= GOT_PROVIDER;
2408 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2409 sizeof(STARTTLSSTR) - 1 ) )
2411 val = cargv[ i ] + sizeof( STARTTLSSTR );
2412 if( !strcasecmp( val, CRITICALSTR ) ) {
2413 si->si_tls = SYNCINFO_TLS_CRITICAL;
2415 si->si_tls = SYNCINFO_TLS_ON;
2417 } else if ( !strncasecmp( cargv[ i ],
2418 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
2420 struct berval updatedn = {0, NULL};
2421 val = cargv[ i ] + sizeof( UPDATEDNSTR );
2422 ber_str2bv( val, 0, 0, &updatedn );
2423 ch_free( si->si_updatedn.bv_val );
2424 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
2425 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
2426 sizeof( BINDMETHSTR ) - 1 ) )
2428 val = cargv[ i ] + sizeof( BINDMETHSTR );
2429 if ( !strcasecmp( val, SIMPLESTR )) {
2430 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2432 } else if ( !strcasecmp( val, SASLSTR )) {
2433 #ifdef HAVE_CYRUS_SASL
2434 si->si_bindmethod = LDAP_AUTH_SASL;
2436 #else /* HAVE_CYRUS_SASL */
2437 fprintf( stderr, "Error: parse_syncrepl_line: "
2438 "not compiled with SASL support\n" );
2440 #endif /* HAVE_CYRUS_SASL */
2442 si->si_bindmethod = -1;
2444 } else if ( !strncasecmp( cargv[ i ],
2445 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
2446 val = cargv[ i ] + sizeof( BINDDNSTR );
2447 si->si_binddn = ch_strdup( val );
2448 } else if ( !strncasecmp( cargv[ i ],
2449 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
2450 val = cargv[ i ] + sizeof( CREDSTR );
2451 si->si_passwd = ch_strdup( val );
2452 } else if ( !strncasecmp( cargv[ i ],
2453 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
2454 val = cargv[ i ] + sizeof( SASLMECHSTR );
2455 si->si_saslmech = ch_strdup( val );
2456 } else if ( !strncasecmp( cargv[ i ],
2457 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
2458 val = cargv[ i ] + sizeof( SECPROPSSTR );
2459 si->si_secprops = ch_strdup( val );
2460 } else if ( !strncasecmp( cargv[ i ],
2461 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
2462 val = cargv[ i ] + sizeof( REALMSTR );
2463 si->si_realm = ch_strdup( val );
2464 } else if ( !strncasecmp( cargv[ i ],
2465 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
2466 val = cargv[ i ] + sizeof( AUTHCSTR );
2467 if ( si->si_authcId )
2468 ch_free( si->si_authcId );
2469 si->si_authcId = ch_strdup( val );
2470 } else if ( !strncasecmp( cargv[ i ],
2471 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
2472 /* Old authcID is provided for some backwards compatibility */
2473 val = cargv[ i ] + sizeof( OLDAUTHCSTR );
2474 if ( si->si_authcId )
2475 ch_free( si->si_authcId );
2476 si->si_authcId = ch_strdup( val );
2477 } else if ( !strncasecmp( cargv[ i ],
2478 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
2479 val = cargv[ i ] + sizeof( AUTHZSTR );
2480 si->si_authzId = ch_strdup( val );
2481 } else if ( !strncasecmp( cargv[ i ],
2482 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
2484 val = cargv[ i ] + sizeof( SCHEMASTR );
2485 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2486 si->si_schemachecking = 1;
2487 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2488 si->si_schemachecking = 0;
2490 si->si_schemachecking = 1;
2492 } else if ( !strncasecmp( cargv[ i ],
2493 FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
2495 val = cargv[ i ] + sizeof( FILTERSTR );
2496 ber_str2bv( val, 0, 1, &si->si_filterstr );
2497 } else if ( !strncasecmp( cargv[ i ],
2498 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
2501 val = cargv[ i ] + sizeof( SEARCHBASESTR );
2502 if ( si->si_base.bv_val ) {
2503 ch_free( si->si_base.bv_val );
2505 ber_str2bv( val, 0, 0, &bv );
2506 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
2507 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
2510 } else if ( !strncasecmp( cargv[ i ],
2511 SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
2513 val = cargv[ i ] + sizeof( SCOPESTR );
2514 if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
2515 si->si_scope = LDAP_SCOPE_BASE;
2516 } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
2517 si->si_scope = LDAP_SCOPE_ONELEVEL;
2518 #ifdef LDAP_SCOPE_SUBORDINATE
2519 } else if ( !strcasecmp( val, "subordinate" ) ||
2520 !strcasecmp( val, "children" ))
2522 si->si_scope = LDAP_SCOPE_SUBORDINATE;
2524 } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
2525 si->si_scope = LDAP_SCOPE_SUBTREE;
2527 fprintf( stderr, "Error: parse_syncrepl_line: "
2528 "unknown scope \"%s\"\n", val);
2531 } else if ( !strncasecmp( cargv[ i ],
2532 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
2534 si->si_attrsonly = 1;
2535 } else if ( !strncasecmp( cargv[ i ],
2536 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
2538 val = cargv[ i ] + sizeof( ATTRSSTR );
2539 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2541 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2542 si->si_anlist = file2anlist(
2543 si->si_anlist, attr_fname, " ,\t" );
2544 if ( si->si_anlist == NULL ) {
2545 ch_free( attr_fname );
2548 ch_free( attr_fname );
2550 char *str, *s, *next;
2551 char delimstr[] = " ,\t";
2552 str = ch_strdup( val );
2553 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2555 s = ldap_pvt_strtok( NULL, delimstr, &next )) {
2556 if ( strlen(s) == 1 && *s == '*' ) {
2557 si->si_allattrs = 1;
2558 *(val + ( s - str )) = delimstr[0];
2560 if ( strlen(s) == 1 && *s == '+' ) {
2561 si->si_allopattrs = 1;
2562 *(val + ( s - str )) = delimstr[0];
2566 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2567 if ( si->si_anlist == NULL ) {
2571 } else if ( !strncasecmp( cargv[ i ],
2572 EXATTRSSTR, sizeof( EXATTRSSTR ) - 1 ) )
2574 val = cargv[ i ] + sizeof( EXATTRSSTR );
2575 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2577 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2578 si->si_exanlist = file2anlist(
2579 si->si_exanlist, attr_fname, " ,\t" );
2580 if ( si->si_exanlist == NULL ) {
2581 ch_free( attr_fname );
2584 ch_free( attr_fname );
2587 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2588 if ( si->si_exanlist == NULL ) {
2592 } else if ( !strncasecmp( cargv[ i ],
2593 TYPESTR, sizeof( TYPESTR ) - 1 ) )
2595 val = cargv[ i ] + sizeof( TYPESTR );
2596 if ( !strncasecmp( val, "refreshOnly", STRLENOF("refreshOnly") )) {
2597 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2598 } else if ( !strncasecmp( val, "refreshAndPersist",
2599 STRLENOF("refreshAndPersist") ))
2601 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2602 si->si_interval = 60;
2604 fprintf( stderr, "Error: parse_syncrepl_line: "
2605 "unknown sync type \"%s\"\n", val);
2608 } else if ( !strncasecmp( cargv[ i ],
2609 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
2611 val = cargv[ i ] + sizeof( INTERVALSTR );
2612 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2613 si->si_interval = 0;
2621 hstr = strchr( dstr, ':' );
2622 if ( hstr == NULL ) {
2623 fprintf( stderr, "Error: parse_syncrepl_line: "
2624 "invalid interval \"%s\"\n", val );
2628 mstr = strchr( hstr, ':' );
2629 if ( mstr == NULL ) {
2630 fprintf( stderr, "Error: parse_syncrepl_line: "
2631 "invalid interval \"%s\"\n", val );
2635 sstr = strchr( mstr, ':' );
2636 if ( sstr == NULL ) {
2637 fprintf( stderr, "Error: parse_syncrepl_line: "
2638 "invalid interval \"%s\"\n", val );
2647 if (( hh > 24 ) || ( hh < 0 ) ||
2648 ( mm > 60 ) || ( mm < 0 ) ||
2649 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2650 fprintf( stderr, "Error: parse_syncrepl_line: "
2651 "invalid interval \"%s\"\n", val );
2654 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2656 if ( si->si_interval < 0 ) {
2657 fprintf( stderr, "Error: parse_syncrepl_line: "
2658 "invalid interval \"%ld\"\n",
2659 (long) si->si_interval);
2662 } else if ( !strncasecmp( cargv[ i ],
2663 RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
2669 val = cargv[ i ] + sizeof( RETRYSTR );
2670 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2671 retry_list[0] = NULL;
2673 slap_str2clist( &retry_list, val, " ,\t" );
2675 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2679 "Error: incomplete syncrepl retry list\n" );
2680 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2681 ch_free( retry_list[k] );
2683 ch_free( retry_list );
2684 exit( EXIT_FAILURE );
2686 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2687 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2688 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2689 for ( j = 0; j < n; j++ ) {
2690 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2691 if ( *retry_list[j*2+1] == '+' ) {
2692 si->si_retrynum_init[j] = -1;
2693 si->si_retrynum[j] = -1;
2697 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2698 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2701 si->si_retrynum_init[j] = -2;
2702 si->si_retrynum[j] = -2;
2703 si->si_retryinterval[j] = 0;
2705 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2706 ch_free( retry_list[k] );
2708 ch_free( retry_list );
2709 } else if ( !strncasecmp( cargv[ i ],
2710 MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
2712 val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
2713 si->si_manageDSAit = atoi( val );
2714 } else if ( !strncasecmp( cargv[ i ],
2715 SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
2717 val = cargv[ i ] + sizeof( SLIMITSTR );
2718 si->si_slimit = atoi( val );
2719 } else if ( !strncasecmp( cargv[ i ],
2720 TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
2722 val = cargv[ i ] + sizeof( TLIMITSTR );
2723 si->si_tlimit = atoi( val );
2725 fprintf( stderr, "Error: parse_syncrepl_line: "
2726 "unknown keyword \"%s\"\n", cargv[ i ] );
2730 if ( gots != GOT_ALL ) {
2732 "Error: Malformed \"syncrepl\" line in slapd config file" );
2740 slap_str2clist( char ***out, char *in, const char *brkstr )
2749 /* find last element in list */
2750 for (i = 0; *out && (*out)[i]; i++);
2752 /* protect the input string from strtok */
2753 str = ch_strdup( in );
2755 if ( *str == '\0' ) {
2760 /* Count words in string */
2762 for ( s = str; *s; s++ ) {
2763 if ( strchr( brkstr, *s ) != NULL ) {
2768 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
2770 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
2772 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
2774 *new = ch_strdup( s );