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>
39 #include "slapi/slapi.h"
46 * defaults for various global variables
48 slap_mask_t global_allows = 0;
49 slap_mask_t global_disallows = 0;
51 int global_gentlehup = 0;
52 int global_idletimeout = 0;
53 char *global_host = NULL;
54 char *global_realm = NULL;
55 char *ldap_srvtab = "";
56 char **default_passwd_hash = NULL;
57 int cargc = 0, cargv_size = 0;
59 struct berval default_search_base = BER_BVNULL;
60 struct berval default_search_nbase = BER_BVNULL;
61 unsigned num_subordinates = 0;
63 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
64 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
66 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
67 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
69 char *slapd_pid_file = NULL;
70 char *slapd_args_file = NULL;
72 char *strtok_quote_ptr;
74 int use_reverse_lookup = 0;
77 int slapi_plugins_used = 0;
80 static char *fp_getline(FILE *fp, int *lineno);
81 static void fp_getline_init(int *lineno);
82 static int fp_parse_line(int lineno, char *line);
84 static char *strtok_quote(char *line, char *sep);
85 static int load_ucdata(char *path);
87 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
88 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
91 read_config( const char *fname, int depth )
94 char *line, *savefname, *saveline;
98 struct berval vals[2];
101 static BackendInfo *bi = NULL;
102 static BackendDB *be = NULL;
105 vals[1].bv_val = NULL;
108 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
109 cargv_size = ARGS_STEP + 1;
112 if ( (fp = fopen( fname, "r" )) == NULL ) {
114 Debug( LDAP_DEBUG_ANY,
115 "could not open config file \"%s\": %s (%d)\n",
116 fname, strerror(errno), errno );
120 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
123 fp_getline_init( &lineno );
125 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
126 /* skip comments and blank lines */
127 if ( line[0] == '#' || line[0] == '\0' ) {
131 /* fp_parse_line is destructive, we save a copy */
132 saveline = ch_strdup( line );
134 if ( fp_parse_line( lineno, line ) != 0 ) {
139 Debug( LDAP_DEBUG_ANY,
140 "%s: line %d: bad config line (ignored)\n",
146 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
148 Debug( LDAP_DEBUG_ANY,
149 "%s: line %d: missing type in \"backend <type>\" line\n",
156 Debug( LDAP_DEBUG_ANY,
157 "%s: line %d: backend line must appear before any database definition\n",
163 bi = backend_info( cargv[1] );
166 Debug( LDAP_DEBUG_ANY,
167 "backend %s initialization failed.\n",
172 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
174 Debug( LDAP_DEBUG_ANY,
175 "%s: line %d: missing type in \"database <type>\" line\n",
182 be = backend_db_init( cargv[1] );
185 Debug( LDAP_DEBUG_ANY,
186 "database %s initialization failed.\n",
192 /* set local security factor */
193 } else if ( strcasecmp( cargv[0], "localSSF" ) == 0 ) {
196 Debug( LDAP_DEBUG_ANY,
197 "%s: line %d: missing ssf in \"localSSF <ssf>\" line\n",
202 ssf = atol( cargv[1] );
205 Debug( LDAP_DEBUG_ANY,
206 "%s: line %d: invalid ssf value (%ld) in "
207 "\"localSSF <ssf>\" line.\n",
208 fname, lineno, ssf );
214 /* set thread concurrency */
215 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
218 Debug( LDAP_DEBUG_ANY,
219 "%s: line %d: missing level in \"concurrency <level>\" line\n",
225 c = strtol( cargv[1], &next, 10 );
226 if ( next == NULL || next[0] != '\0' ) {
227 Debug( LDAP_DEBUG_ANY,
228 "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" line\n",
229 fname, lineno, cargv[1] );
234 Debug( LDAP_DEBUG_ANY,
235 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
241 ldap_pvt_thread_set_concurrency( c );
243 /* set substring initial/final index minimum length */
244 } else if ( strcasecmp( cargv[0], "index_substr_if_minlen" ) == 0 ) {
247 Debug( LDAP_DEBUG_ANY,
248 "%s: line %d: missing min in \"index_substr_if_minlen <length>\" line\n",
252 min = atoi( cargv[1] );
253 if( min < 1 || min > index_substr_if_maxlen ) {
254 Debug( LDAP_DEBUG_ANY,
255 "%s: line %d: invalid min value (%ld) in "
256 "\"index_substr_if_minlen <length>\" line.\n",
257 fname, lineno, min );
260 index_substr_if_minlen = min;
262 /* set substring initial/final index maximum length */
263 } else if ( strcasecmp( cargv[0], "index_substr_if_maxlen" ) == 0 ) {
266 Debug( LDAP_DEBUG_ANY,
267 "%s: line %d: missing max in \"index_substr_if_maxlen <length>\" line\n",
271 max = atol( cargv[1] );
272 if( max < 1 || max < index_substr_if_minlen ) {
273 Debug( LDAP_DEBUG_ANY,
274 "%s: line %d: invalid max value (%ld) in "
275 "\"index_substr_maxlen <length>\" line.\n",
276 fname, lineno, max );
279 index_substr_if_maxlen = max;
281 /* set substring any index len */
282 } else if ( strcasecmp( cargv[0], "index_substr_any_len" ) == 0 ) {
285 Debug( LDAP_DEBUG_ANY,
286 "%s: line %d: missing len in \"index_substr_any_len <len>\" line\n",
290 len = atol( cargv[1] );
292 Debug( LDAP_DEBUG_ANY,
293 "%s: line %d: invalid len value (%ld) in "
294 "\"index_substr_any_len <len>\" line.\n",
295 fname, lineno, len );
298 index_substr_any_len = len;
300 /* set substring any index step */
301 } else if ( strcasecmp( cargv[0], "index_substr_any_step" ) == 0 ) {
304 Debug( LDAP_DEBUG_ANY,
305 "%s: line %d: missing step in \"index_substr_any_step <step>\" line\n",
309 step = atol( cargv[1] );
311 Debug( LDAP_DEBUG_ANY,
312 "%s: line %d: invalid step value (%ld) in "
313 "\"index_substr_any_step <step>\" line.\n",
314 fname, lineno, step );
317 index_substr_any_step = step;
319 /* set sockbuf max */
320 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
323 Debug( LDAP_DEBUG_ANY,
324 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
330 max = atol( cargv[1] );
333 Debug( LDAP_DEBUG_ANY,
334 "%s: line %d: invalid max value (%ld) in "
335 "\"sockbuf_max_incoming <bytes>\" line.\n",
336 fname, lineno, max );
341 sockbuf_max_incoming = max;
343 /* set sockbuf max authenticated */
344 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
347 Debug( LDAP_DEBUG_ANY,
348 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
354 max = atol( cargv[1] );
357 Debug( LDAP_DEBUG_ANY,
358 "%s: line %d: invalid max value (%ld) in "
359 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
360 fname, lineno, max );
365 sockbuf_max_incoming_auth = max;
367 /* set conn pending max */
368 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
371 Debug( LDAP_DEBUG_ANY,
372 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
378 max = atol( cargv[1] );
381 Debug( LDAP_DEBUG_ANY,
382 "%s: line %d: invalid max value (%ld) in "
383 "\"conn_max_pending <requests>\" line.\n",
384 fname, lineno, max );
389 slap_conn_max_pending = max;
391 /* set conn pending max authenticated */
392 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
395 Debug( LDAP_DEBUG_ANY,
396 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
402 max = atol( cargv[1] );
405 Debug( LDAP_DEBUG_ANY,
406 "%s: line %d: invalid max value (%ld) in "
407 "\"conn_max_pending_auth <requests>\" line.\n",
408 fname, lineno, max );
413 slap_conn_max_pending_auth = max;
415 /* default search base */
416 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
418 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
419 "missing dn in \"defaultSearchBase <dn>\" line\n",
424 } else if ( cargc > 2 ) {
425 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
426 "extra cruft after <dn> in \"defaultSearchBase %s\", "
428 fname, lineno, cargv[1] );
431 if ( bi != NULL || be != NULL ) {
432 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
433 "defaultSearchBaase line must appear prior to "
434 "any backend or database definition\n",
440 if ( default_search_nbase.bv_len ) {
441 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
442 "default search base \"%s\" already defined "
443 "(discarding old)\n",
444 fname, lineno, default_search_base.bv_val );
446 free( default_search_base.bv_val );
447 free( default_search_nbase.bv_val );
450 if ( load_ucdata( NULL ) < 0 ) return 1;
455 dn.bv_val = cargv[1];
456 dn.bv_len = strlen( dn.bv_val );
458 rc = dnPrettyNormal( NULL, &dn,
459 &default_search_base,
460 &default_search_nbase, NULL );
462 if( rc != LDAP_SUCCESS ) {
463 Debug( LDAP_DEBUG_ANY,
464 "%s: line %d: defaultSearchBase DN is invalid\n",
470 /* set maximum threads in thread pool */
471 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
474 Debug( LDAP_DEBUG_ANY,
475 "%s: line %d: missing count in \"threads <count>\" line\n",
481 c = strtol( cargv[1], &next, 10 );
482 if (next == NULL || next[0] != '\0' ) {
483 Debug( LDAP_DEBUG_ANY,
484 "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
485 fname, lineno, cargv[1] );
490 Debug( LDAP_DEBUG_ANY,
491 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
497 ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
499 /* save for later use */
500 connection_pool_max = c;
502 /* get pid file name */
503 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
505 Debug( LDAP_DEBUG_ANY,
506 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
512 slapd_pid_file = ch_strdup( cargv[1] );
514 /* get args file name */
515 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
517 Debug( LDAP_DEBUG_ANY,
518 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
524 slapd_args_file = ch_strdup( cargv[1] );
526 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
529 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
532 /* default password hash */
533 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
535 Debug( LDAP_DEBUG_ANY,
536 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
541 if ( default_passwd_hash != NULL ) {
542 Debug( LDAP_DEBUG_ANY,
543 "%s: line %d: already set default password_hash!\n",
549 for(i = 1; i < cargc; i++) {
550 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
551 Debug( LDAP_DEBUG_ANY,
552 "%s: line %d: password scheme \"%s\" not available\n",
553 fname, lineno, cargv[i] );
555 ldap_charray_add( &default_passwd_hash, cargv[i] );
558 if( !default_passwd_hash ) {
559 Debug( LDAP_DEBUG_ANY,
560 "%s: line %d: no valid hashes found\n",
565 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
568 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
569 "\"password-crypt-salt-format <format>\" line\n",
575 lutil_salt_format( cargv[1] );
577 #ifdef SLAP_AUTH_REWRITE
578 /* use authid rewrite instead of sasl regexp */
579 } else if ( strncasecmp( cargv[0], "auth-rewrite",
580 STRLENOF("auth-rewrite") ) == 0 )
582 int rc = slap_sasl_rewrite_config( fname, lineno,
587 #endif /* SLAP_AUTH_REWRITE */
589 /* Auth + SASL config options */
590 } else if ( !strncasecmp( cargv[0], "auth", STRLENOF("auth") ) ||
591 !strncasecmp( cargv[0], "sasl", STRLENOF("sasl") ))
593 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
597 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
600 Debug( LDAP_DEBUG_ANY,
601 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
605 ber_str2bv( cargv[1], 0, 0, &dn );
607 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
608 &be->be_schemandn, NULL );
610 rc = dnPrettyNormal( NULL, &dn, &frontendDB->be_schemadn,
611 &frontendDB->be_schemandn, NULL );
613 if ( rc != LDAP_SUCCESS ) {
614 Debug( LDAP_DEBUG_ANY,
615 "%s: line %d: schemadn DN is invalid\n",
620 /* set UCDATA path */
621 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
624 Debug( LDAP_DEBUG_ANY,
625 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
631 err = load_ucdata( cargv[1] );
634 Debug( LDAP_DEBUG_ANY,
635 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
643 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
645 struct slap_limits_set *lim;
648 Debug( LDAP_DEBUG_ANY,
649 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
656 lim = &frontendDB->be_def_limit;
658 lim = &be->be_def_limit;
661 for ( i = 1; i < cargc; i++ ) {
662 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
663 rc = limits_parse_one( cargv[i], lim );
665 Debug( LDAP_DEBUG_ANY,
666 "%s: line %d: unable "
667 "to parse value \"%s\" "
670 fname, lineno, cargv[i] );
675 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
676 lim->lms_s_soft = -1;
678 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
679 if ( next == cargv[i] ) {
680 Debug( LDAP_DEBUG_ANY,
681 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
682 fname, lineno, cargv[i] );
685 } else if ( next[0] != '\0' ) {
686 Debug( LDAP_DEBUG_ANY,
687 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
688 fname, lineno, next );
696 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
698 struct slap_limits_set *lim;
701 Debug( LDAP_DEBUG_ANY,
702 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
709 lim = &frontendDB->be_def_limit;
711 lim = &be->be_def_limit;
714 for ( i = 1; i < cargc; i++ ) {
715 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
716 rc = limits_parse_one( cargv[i], lim );
718 Debug( LDAP_DEBUG_ANY,
719 "%s: line %d: unable "
720 "to parse value \"%s\" "
723 fname, lineno, cargv[i] );
728 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
729 lim->lms_t_soft = -1;
731 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
732 if ( next == cargv[i] ) {
733 Debug( LDAP_DEBUG_ANY,
734 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
735 fname, lineno, cargv[i] );
738 } else if ( next[0] != '\0' ) {
739 Debug( LDAP_DEBUG_ANY,
740 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
741 fname, lineno, next );
748 /* set regex-based limits */
749 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
751 Debug( LDAP_DEBUG_ANY,
752 "%s: line %d \"limits\" allowed only in database environment.\n%s",
757 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
761 /* mark this as a subordinate database */
762 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
764 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
765 "must appear inside a database definition.\n",
770 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
774 /* add an overlay to this backend */
775 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
777 if ( cargv[1][0] == '-' && overlay_config( frontendDB, &cargv[1][1] ) ) {
779 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
780 "(optional) global overlay \"%s\" configuration "
781 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
782 } else if ( overlay_config( frontendDB, cargv[1] ) ) {
787 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
789 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
790 "(optional) overlay \"%s\" configuration "
791 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
792 } else if ( overlay_config( be, cargv[1] ) ) {
797 /* set database suffix */
798 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
800 struct berval dn, pdn, ndn;
803 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
804 "missing dn in \"suffix <dn>\" line\n",
809 } else if ( cargc > 2 ) {
810 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
811 "after <dn> in \"suffix %s\" line (ignored)\n",
812 fname, lineno, cargv[1] );
816 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
817 "must appear inside a database definition\n",
821 #if defined(SLAPD_MONITOR_DN)
822 /* "cn=Monitor" is reserved for monitoring slap */
823 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
824 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
825 "%s\" is reserved for monitoring slapd\n",
826 fname, lineno, SLAPD_MONITOR_DN );
828 #endif /* SLAPD_MONITOR_DN */
831 if ( load_ucdata( NULL ) < 0 ) return 1;
833 dn.bv_val = cargv[1];
834 dn.bv_len = strlen( cargv[1] );
836 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
837 if( rc != LDAP_SUCCESS ) {
838 Debug( LDAP_DEBUG_ANY,
839 "%s: line %d: suffix DN is invalid\n",
844 tmp_be = select_backend( &ndn, 0, 0 );
845 if ( tmp_be == be ) {
846 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
847 "already served by this backend (ignored)\n",
852 } else if ( tmp_be != NULL ) {
853 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
854 "already served by a preceeding backend \"%s\"\n",
855 fname, lineno, tmp_be->be_suffix[0].bv_val );
860 } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
861 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
862 "suffix DN empty and default "
863 "search base provided \"%s\" (assuming okay)\n",
864 fname, lineno, default_search_base.bv_val );
867 ber_bvarray_add( &be->be_suffix, &pdn );
868 ber_bvarray_add( &be->be_nsuffix, &ndn );
870 /* set max deref depth */
871 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
874 Debug( LDAP_DEBUG_ANY,
875 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
881 Debug( LDAP_DEBUG_ANY,
882 "%s: line %d: depth line must appear inside a database definition.\n",
887 i = strtol( cargv[1], &next, 10 );
888 if ( next == NULL || next[0] != '\0' ) {
889 Debug( LDAP_DEBUG_ANY,
890 "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
891 "line.\n", fname, lineno, cargv[1] );
896 Debug( LDAP_DEBUG_ANY,
897 "%s: line %d: depth must be positive.\n",
903 be->be_max_deref_depth = i;
905 /* set magic "root" dn for this database */
906 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
908 Debug( LDAP_DEBUG_ANY,
909 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
916 Debug( LDAP_DEBUG_ANY,
917 "%s: line %d: rootdn line must appear inside a database definition.\n",
924 if ( load_ucdata( NULL ) < 0 ) return 1;
926 dn.bv_val = cargv[1];
927 dn.bv_len = strlen( cargv[1] );
929 rc = dnPrettyNormal( NULL, &dn,
931 &be->be_rootndn, NULL );
933 if( rc != LDAP_SUCCESS ) {
934 Debug( LDAP_DEBUG_ANY,
935 "%s: line %d: rootdn DN is invalid\n",
941 /* set super-secret magic database password */
942 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
944 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
945 "missing passwd in \"rootpw <passwd>\" line\n",
952 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
953 "rootpw line must appear inside a database "
959 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
962 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
963 "rootpw can only be set when rootdn is under suffix\n",
968 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
969 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
972 /* make this database read-only */
973 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
975 Debug( LDAP_DEBUG_ANY,
976 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
982 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
983 frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
985 frontendDB->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
989 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
990 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
992 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
996 /* restricts specific operations */
997 } else if ( strcasecmp( cargv[0], "restrict" ) == 0 ) {
998 slap_mask_t restrictops = 0;
999 struct restrictable_exops_t {
1002 } restrictable_exops[] = {
1003 { LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1004 { LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1005 { LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1006 { LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1012 Debug( LDAP_DEBUG_ANY,
1013 "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
1014 "line.\n", fname, lineno, 0 );
1018 for ( i = 1; i < cargc; i++ ) {
1019 if ( strcasecmp( cargv[ i ], "read" ) == 0 ) {
1020 restrictops |= SLAP_RESTRICT_OP_READS;
1022 } else if ( strcasecmp( cargv[ i ], "write" ) == 0 ) {
1023 restrictops |= SLAP_RESTRICT_OP_WRITES;
1025 } else if ( strcasecmp( cargv[ i ], "add" ) == 0 ) {
1026 restrictops |= SLAP_RESTRICT_OP_ADD;
1028 } else if ( strcasecmp( cargv[ i ], "bind" ) == 0 ) {
1029 restrictops |= SLAP_RESTRICT_OP_BIND;
1031 } else if ( strcasecmp( cargv[ i ], "compare" ) == 0 ) {
1032 restrictops |= SLAP_RESTRICT_OP_COMPARE;
1034 } else if ( strcasecmp( cargv[ i ], "delete" ) == 0 ) {
1035 restrictops |= SLAP_RESTRICT_OP_DELETE;
1037 } else if ( strncasecmp( cargv[ i ], "extended",
1038 STRLENOF( "extended" ) ) == 0 )
1040 char *e = cargv[ i ] + STRLENOF( "extended" );
1042 if ( e[0] == '=' ) {
1046 for ( j = 0; restrictable_exops[ j ].name; j++ ) {
1047 if ( strcmp( e, restrictable_exops[j].name ) == 0 )
1049 restrictops |= restrictable_exops[ j ].flag;
1054 if ( restrictable_exops[ j ].name == NULL ) {
1055 goto restrict_unknown;
1058 restrictops &= ~SLAP_RESTRICT_OP_EXTENDED;
1060 } else if ( e[0] == '\0' ) {
1061 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1062 restrictops |= SLAP_RESTRICT_OP_EXTENDED;
1065 goto restrict_unknown;
1068 } else if ( strcasecmp( cargv[ i ], "modify" ) == 0 ) {
1069 restrictops |= SLAP_RESTRICT_OP_MODIFY;
1071 } else if ( strcasecmp( cargv[ i ], "rename" ) == 0
1072 || strcasecmp( cargv[ i ], "modrdn" ) == 0 )
1074 restrictops |= SLAP_RESTRICT_OP_RENAME;
1076 } else if ( strcasecmp( cargv[ i ], "search" ) == 0 ) {
1077 restrictops |= SLAP_RESTRICT_OP_SEARCH;
1082 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1083 "unknown operation %s in \"allow <features>\" line\n",
1084 fname, lineno, cargv[i] );
1090 frontendDB->be_restrictops |= restrictops;
1092 be->be_restrictops |= restrictops;
1095 /* allow these features */
1096 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1097 strcasecmp( cargv[0], "allow" ) == 0 )
1099 slap_mask_t allows = 0;
1102 Debug( LDAP_DEBUG_ANY,
1103 "%s: line %d: allow line must appear prior to database definitions\n",
1109 Debug( LDAP_DEBUG_ANY,
1110 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1116 for( i=1; i < cargc; i++ ) {
1117 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1118 allows |= SLAP_ALLOW_BIND_V2;
1120 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1121 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1123 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1124 allows |= SLAP_ALLOW_BIND_ANON_DN;
1126 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1127 allows |= SLAP_ALLOW_UPDATE_ANON;
1130 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1131 "unknown feature %s in \"allow <features>\" line\n",
1132 fname, lineno, cargv[i] );
1138 global_allows |= allows;
1140 /* disallow these features */
1141 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1142 strcasecmp( cargv[0], "disallow" ) == 0 )
1144 slap_mask_t disallows = 0;
1147 Debug( LDAP_DEBUG_ANY,
1148 "%s: line %d: disallow line must appear prior to database definitions\n",
1154 Debug( LDAP_DEBUG_ANY,
1155 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1161 for( i=1; i < cargc; i++ ) {
1162 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1163 disallows |= SLAP_DISALLOW_BIND_ANON;
1165 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1166 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1168 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1169 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1171 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1172 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1174 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1175 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1178 Debug( LDAP_DEBUG_ANY,
1179 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1180 fname, lineno, cargv[i] );
1186 global_disallows |= disallows;
1188 /* require these features */
1189 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1190 strcasecmp( cargv[0], "require" ) == 0 )
1192 slap_mask_t requires = 0;
1195 Debug( LDAP_DEBUG_ANY,
1196 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1202 for( i=1; i < cargc; i++ ) {
1203 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1204 requires |= SLAP_REQUIRE_BIND;
1206 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1207 requires |= SLAP_REQUIRE_LDAP_V3;
1209 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1210 requires |= SLAP_REQUIRE_AUTHC;
1212 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1213 requires |= SLAP_REQUIRE_SASL;
1215 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1216 requires |= SLAP_REQUIRE_STRONG;
1218 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1219 Debug( LDAP_DEBUG_ANY,
1220 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1221 fname, lineno, cargv[i] );
1228 frontendDB->be_requires = requires;
1230 be->be_requires = requires;
1233 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1234 slap_ssf_set_t *set;
1237 Debug( LDAP_DEBUG_ANY,
1238 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1245 set = &frontendDB->be_ssf_set;
1247 set = &be->be_ssf_set;
1250 for( i=1; i < cargc; i++ ) {
1254 if ( strncasecmp( cargv[i], "ssf=",
1255 STRLENOF("ssf=") ) == 0 )
1257 tgt = &set->sss_ssf;
1258 src = &cargv[i][STRLENOF("ssf=")];
1260 } else if ( strncasecmp( cargv[i], "transport=",
1261 STRLENOF("transport=") ) == 0 )
1263 tgt = &set->sss_transport;
1264 src = &cargv[i][STRLENOF("transport=")];
1266 } else if ( strncasecmp( cargv[i], "tls=",
1267 STRLENOF("tls=") ) == 0 )
1269 tgt = &set->sss_tls;
1270 src = &cargv[i][STRLENOF("tls=")];
1272 } else if ( strncasecmp( cargv[i], "sasl=",
1273 STRLENOF("sasl=") ) == 0 )
1275 tgt = &set->sss_sasl;
1276 src = &cargv[i][STRLENOF("sasl=")];
1278 } else if ( strncasecmp( cargv[i], "update_ssf=",
1279 STRLENOF("update_ssf=") ) == 0 )
1281 tgt = &set->sss_update_ssf;
1282 src = &cargv[i][STRLENOF("update_ssf=")];
1284 } else if ( strncasecmp( cargv[i], "update_transport=",
1285 STRLENOF("update_transport=") ) == 0 )
1287 tgt = &set->sss_update_transport;
1288 src = &cargv[i][STRLENOF("update_transport=")];
1290 } else if ( strncasecmp( cargv[i], "update_tls=",
1291 STRLENOF("update_tls=") ) == 0 )
1293 tgt = &set->sss_update_tls;
1294 src = &cargv[i][STRLENOF("update_tls=")];
1296 } else if ( strncasecmp( cargv[i], "update_sasl=",
1297 STRLENOF("update_sasl=") ) == 0 )
1299 tgt = &set->sss_update_sasl;
1300 src = &cargv[i][STRLENOF("update_sasl=")];
1302 } else if ( strncasecmp( cargv[i], "simple_bind=",
1303 STRLENOF("simple_bind=") ) == 0 )
1305 tgt = &set->sss_simple_bind;
1306 src = &cargv[i][STRLENOF("simple_bind=")];
1309 Debug( LDAP_DEBUG_ANY,
1310 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1311 fname, lineno, cargv[i] );
1316 *tgt = strtol( src, &next, 10 );
1317 if ( next == NULL || next[0] != '\0' ) {
1318 Debug( LDAP_DEBUG_ANY,
1319 "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1320 fname, lineno, cargv[i] );
1326 /* where to send clients when we don't hold it */
1327 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1329 Debug( LDAP_DEBUG_ANY,
1330 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1336 if( validate_global_referral( cargv[1] ) ) {
1337 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1338 "invalid URL (%s) in \"referral\" line.\n",
1339 fname, lineno, cargv[1] );
1343 vals[0].bv_val = cargv[1];
1344 vals[0].bv_len = strlen( vals[0].bv_val );
1345 if( value_add( &default_referral, vals ) )
1348 /* start of a new database definition */
1349 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1352 Debug( LDAP_DEBUG_ANY,
1353 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1357 level = strtol( cargv[2], &next, 10 );
1358 if ( next == NULL || next[0] != '\0' ){
1359 Debug( LDAP_DEBUG_ANY,
1360 "%s: line %d: unable to parse level \"%s\" in debug directive, "
1361 "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1365 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1366 lutil_set_debug_level( cargv[1], level );
1367 /* specify an Object Identifier macro */
1368 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1369 rc = parse_oidm( fname, lineno, cargc, cargv );
1372 /* specify an objectclass */
1373 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1375 Debug( LDAP_DEBUG_ANY,
1376 "%s: line %d: illegal objectclass format.\n",
1380 } else if ( *cargv[1] == '(' /*')'*/) {
1382 p = strchr(saveline,'(' /*')'*/);
1383 rc = parse_oc( fname, lineno, p, cargv );
1387 Debug( LDAP_DEBUG_ANY,
1388 "%s: line %d: old objectclass format not supported.\n",
1392 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1394 p = strchr(saveline,'(' /*')'*/);
1395 rc = parse_cr( fname, lineno, p, cargv );
1398 /* specify an attribute type */
1399 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1400 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1403 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1404 "illegal attribute type format.\n",
1408 } else if ( *cargv[1] == '(' /*')'*/) {
1410 p = strchr(saveline,'(' /*')'*/);
1411 rc = parse_at( fname, lineno, p, cargv );
1415 Debug( LDAP_DEBUG_ANY,
1416 "%s: line %d: old attribute type format not supported.\n",
1421 /* define attribute option(s) */
1422 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1423 ad_define_option( NULL, NULL, 0 );
1424 for ( i = 1; i < cargc; i++ )
1425 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1428 /* turn on/off schema checking */
1429 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1431 Debug( LDAP_DEBUG_ANY,
1432 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1437 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1438 Debug( LDAP_DEBUG_ANY,
1439 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1441 global_schemacheck = 0;
1443 global_schemacheck = 1;
1446 /* specify access control info */
1447 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1448 parse_acl( be, fname, lineno, cargc, cargv );
1450 /* debug level to log things to syslog */
1451 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1453 Debug( LDAP_DEBUG_ANY,
1454 "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1462 for( i=1; i < cargc; i++ ) {
1465 if ( isdigit( cargv[i][0] ) ) {
1466 level = strtol( cargv[i], &next, 10 );
1467 if ( next == NULL || next[0] != '\0' ) {
1468 Debug( LDAP_DEBUG_ANY,
1469 "%s: line %d: unable to parse level \"%s\" "
1470 "in \"loglevel <level> [...]\" line.\n",
1471 fname, lineno , cargv[i] );
1480 { LDAP_DEBUG_TRACE, "Trace" },
1481 { LDAP_DEBUG_PACKETS, "Packets" },
1482 { LDAP_DEBUG_ARGS, "Args" },
1483 { LDAP_DEBUG_CONNS, "Conns" },
1484 { LDAP_DEBUG_BER, "BER" },
1485 { LDAP_DEBUG_FILTER, "Filter" },
1486 { LDAP_DEBUG_CONFIG, "Config" },
1487 { LDAP_DEBUG_ACL, "ACL" },
1488 { LDAP_DEBUG_STATS, "Stats" },
1489 { LDAP_DEBUG_STATS2, "Stats2" },
1490 { LDAP_DEBUG_SHELL, "Shell" },
1491 { LDAP_DEBUG_PARSE, "Parse" },
1492 { LDAP_DEBUG_CACHE, "Cache" },
1493 { LDAP_DEBUG_INDEX, "Index" },
1499 for ( j = 0; int_2_level[j].s; j++ ) {
1500 if ( strcasecmp( cargv[i], int_2_level[j].s ) == 0 ) {
1501 level = int_2_level[j].i;
1506 if ( int_2_level[j].s == NULL ) {
1507 Debug( LDAP_DEBUG_ANY,
1508 "%s: line %d: unknown level \"%s\" "
1509 "in \"loglevel <level> [...]\" line.\n",
1510 fname, lineno , cargv[i] );
1515 ldap_syslog |= level;
1518 /* list of sync replication information in this backend (slave only) */
1519 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1522 Debug( LDAP_DEBUG_ANY,
1523 "%s: line %d: syncrepl line must appear inside "
1524 "a database definition.\n", fname, lineno, 0);
1527 } else if ( SLAP_SHADOW( be )) {
1528 Debug( LDAP_DEBUG_ANY,
1529 "%s: line %d: syncrepl: database already shadowed.\n",
1533 } else if ( add_syncrepl( be, cargv, cargc )) {
1537 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1539 /* list of replicas of the data in this backend (master only) */
1540 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1542 Debug( LDAP_DEBUG_ANY,
1543 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1549 Debug( LDAP_DEBUG_ANY,
1550 "%s: line %d: replica line must appear inside a database definition\n",
1557 for ( i = 1; i < cargc; i++ ) {
1558 if ( strncasecmp( cargv[i], "host=", 5 )
1560 nr = add_replica_info( be,
1563 } else if (strncasecmp( cargv[i], "uri=", 4 )
1565 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1567 Debug( LDAP_DEBUG_ANY,
1568 "%s: line %d: replica line contains invalid "
1569 "uri definition.\n", fname, lineno, 0);
1572 if (ludp->lud_host == NULL ) {
1573 Debug( LDAP_DEBUG_ANY,
1574 "%s: line %d: replica line contains invalid "
1575 "uri definition - missing hostname.\n", fname, lineno, 0);
1578 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1579 if ( replicahost == NULL ) {
1580 Debug( LDAP_DEBUG_ANY,
1581 "out of memory in read_config\n", 0, 0, 0 );
1582 ldap_free_urldesc( ludp );
1583 exit( EXIT_FAILURE );
1585 sprintf(replicahost, "%s:%d",
1586 ludp->lud_host, ludp->lud_port);
1587 nr = add_replica_info( be, replicahost );
1588 ldap_free_urldesc( ludp );
1589 ch_free(replicahost);
1594 Debug( LDAP_DEBUG_ANY,
1595 "%s: line %d: missing host or uri in \"replica\" line\n",
1599 } else if ( nr == -1 ) {
1600 Debug( LDAP_DEBUG_ANY,
1601 "%s: line %d: unable to add replica \"%s\"\n",
1602 fname, lineno, cargv[i] + 5 );
1605 for ( i = 1; i < cargc; i++ ) {
1606 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1608 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1610 Debug( LDAP_DEBUG_ANY,
1611 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1612 fname, lineno, cargv[i] + 7 );
1616 Debug( LDAP_DEBUG_ANY,
1617 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1622 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1624 char *arg = cargv[i] + 4;
1626 if ( arg[0] == '!' ) {
1631 if ( arg[0] != '=' ) {
1635 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1636 Debug( LDAP_DEBUG_ANY,
1637 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1638 fname, lineno, arg + 1 );
1646 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1649 /* dn of slave entity allowed to write to replica */
1650 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1652 Debug( LDAP_DEBUG_ANY,
1653 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1659 Debug( LDAP_DEBUG_ANY,
1660 "%s: line %d: updatedn line must appear inside a database definition\n",
1664 } else if ( SLAP_SHADOW(be) ) {
1665 Debug( LDAP_DEBUG_ANY,
1666 "%s: line %d: updatedn: database already shadowed.\n",
1673 if ( load_ucdata( NULL ) < 0 ) return 1;
1675 dn.bv_val = cargv[1];
1676 dn.bv_len = strlen( cargv[1] );
1678 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1679 if( rc != LDAP_SUCCESS ) {
1680 Debug( LDAP_DEBUG_ANY,
1681 "%s: line %d: updatedn DN is invalid\n",
1687 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
1689 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1691 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1692 "missing url in \"updateref <ldapurl>\" line\n",
1698 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1699 " line must appear inside a database definition\n",
1703 } else if ( !SLAP_SHADOW(be) ) {
1704 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1705 "updateref line must after syncrepl or updatedn.\n",
1710 if( validate_global_referral( cargv[1] ) ) {
1711 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1712 "invalid URL (%s) in \"updateref\" line.\n",
1713 fname, lineno, cargv[1] );
1717 vals[0].bv_val = cargv[1];
1718 vals[0].bv_len = strlen( vals[0].bv_val );
1719 if( value_add( &be->be_update_refs, vals ) ) {
1723 /* replication log file to which changes are appended */
1724 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1726 Debug( LDAP_DEBUG_ANY,
1727 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1733 be->be_replogfile = ch_strdup( cargv[1] );
1735 replogfile = ch_strdup( cargv[1] );
1738 /* file from which to read additional rootdse attrs */
1739 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
1741 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1742 "missing filename in \"rootDSE <filename>\" line.\n",
1747 if( read_root_dse_file( cargv[1] ) ) {
1748 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1749 "could not read \"rootDSE <filename>\" line\n",
1754 /* maintain lastmodified{by,time} attributes */
1755 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1757 Debug( LDAP_DEBUG_ANY,
1758 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1765 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1766 " line must appear inside a database definition\n",
1770 } else if ( SLAP_NOLASTMODCMD(be) ) {
1771 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1772 " not available for %s databases\n",
1773 fname, lineno, be->bd_info->bi_type );
1777 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1778 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
1780 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1784 /* turn on/off gentle SIGHUP handling */
1785 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
1787 Debug( LDAP_DEBUG_ANY,
1788 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
1792 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1793 global_gentlehup = 0;
1795 global_gentlehup = 1;
1799 /* set idle timeout value */
1800 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1803 Debug( LDAP_DEBUG_ANY,
1804 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1810 i = atoi( cargv[1] );
1813 Debug( LDAP_DEBUG_ANY,
1814 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1820 global_idletimeout = i;
1822 /* include another config file */
1823 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1825 Debug( LDAP_DEBUG_ANY,
1826 "%s: line %d: missing filename in \"include <filename>\" line\n",
1831 savefname = ch_strdup( cargv[1] );
1832 savelineno = lineno;
1834 if ( read_config( savefname, depth+1 ) != 0 ) {
1839 lineno = savelineno - 1;
1841 /* location of kerberos srvtab file */
1842 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1844 Debug( LDAP_DEBUG_ANY,
1845 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1850 ldap_srvtab = ch_strdup( cargv[1] );
1852 #ifdef SLAPD_MODULES
1853 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1855 Debug( LDAP_DEBUG_ANY,
1856 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1859 exit( EXIT_FAILURE );
1861 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1862 Debug( LDAP_DEBUG_ANY,
1863 "%s: line %d: failed to load or initialize module %s\n",
1864 fname, lineno, cargv[1]);
1866 exit( EXIT_FAILURE );
1868 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1870 Debug( LDAP_DEBUG_ANY,
1871 "%s: line %d: missing path in \"modulepath <path>\" line\n",
1874 exit( EXIT_FAILURE );
1876 if (module_path( cargv[1] )) {
1877 Debug( LDAP_DEBUG_ANY,
1878 "%s: line %d: failed to set module search path to %s\n",
1879 fname, lineno, cargv[1]);
1881 exit( EXIT_FAILURE );
1884 #endif /*SLAPD_MODULES*/
1887 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
1888 rc = ldap_pvt_tls_set_option( NULL,
1889 LDAP_OPT_X_TLS_RANDOM_FILE,
1894 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1895 rc = ldap_pvt_tls_set_option( NULL,
1896 LDAP_OPT_X_TLS_CIPHER_SUITE,
1901 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1902 rc = ldap_pvt_tls_set_option( NULL,
1903 LDAP_OPT_X_TLS_CERTFILE,
1908 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1909 rc = ldap_pvt_tls_set_option( NULL,
1910 LDAP_OPT_X_TLS_KEYFILE,
1915 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1916 rc = ldap_pvt_tls_set_option( NULL,
1917 LDAP_OPT_X_TLS_CACERTDIR,
1922 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1923 rc = ldap_pvt_tls_set_option( NULL,
1924 LDAP_OPT_X_TLS_CACERTFILE,
1928 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1929 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
1931 rc = ldap_pvt_tls_set_option( NULL,
1932 LDAP_OPT_X_TLS_REQUIRE_CERT,
1935 rc = ldap_int_tls_config( NULL,
1936 LDAP_OPT_X_TLS_REQUIRE_CERT,
1945 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
1946 #ifdef SLAPD_RLOOKUPS
1948 Debug( LDAP_DEBUG_ANY,
1949 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
1954 if ( !strcasecmp( cargv[1], "on" ) ) {
1955 use_reverse_lookup = 1;
1956 } else if ( !strcasecmp( cargv[1], "off" ) ) {
1957 use_reverse_lookup = 0;
1959 Debug( LDAP_DEBUG_ANY,
1960 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
1965 #else /* !SLAPD_RLOOKUPS */
1966 Debug( LDAP_DEBUG_ANY,
1967 "%s: line %d: reverse lookups are not configured (ignored).\n",
1969 #endif /* !SLAPD_RLOOKUPS */
1971 /* Netscape plugins */
1972 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
1973 #if defined( LDAP_SLAPI )
1975 #ifdef notdef /* allow global plugins, too */
1977 * a "plugin" line must be inside a database
1978 * definition, since we implement pre-,post-
1979 * and extended operation plugins
1982 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
1983 "line must appear inside a database "
1984 "definition\n", fname, lineno, 0 );
1989 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
1992 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
1993 "config read failed.\n", fname, lineno, 0 );
1996 slapi_plugins_used++;
1998 #else /* !defined( LDAP_SLAPI ) */
1999 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2000 "not supported.\n", fname, lineno, 0 );
2003 #endif /* !defined( LDAP_SLAPI ) */
2005 /* Netscape plugins */
2006 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2007 #if defined( LDAP_SLAPI )
2009 Debug( LDAP_DEBUG_ANY,
2010 "%s: line %d: missing file name "
2011 "in pluginlog <filename> line.\n",
2016 if ( slapi_log_file != NULL ) {
2017 ch_free( slapi_log_file );
2020 slapi_log_file = ch_strdup( cargv[1] );
2021 #endif /* !defined( LDAP_SLAPI ) */
2023 /* pass anything else to the current backend info/db config routine */
2026 if ( bi->bi_config ) {
2027 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2033 case SLAP_CONF_UNKNOWN:
2034 Debug( LDAP_DEBUG_ANY,
2035 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2036 fname, lineno, cargv[0] );
2044 } else if ( be != NULL ) {
2045 if ( be->be_config ) {
2046 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2052 case SLAP_CONF_UNKNOWN:
2053 Debug( LDAP_DEBUG_ANY,
2054 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2055 fname, lineno, cargv[0] );
2064 if ( frontendDB->be_config ) {
2065 rc = (*frontendDB->be_config)( frontendDB, fname, lineno, cargc, cargv );
2071 case SLAP_CONF_UNKNOWN:
2072 Debug( LDAP_DEBUG_ANY,
2073 "%s: line %d: unknown directive \"%s\" inside global database definition (ignored)\n",
2074 fname, lineno, cargv[0] );
2087 if ( depth == 0 ) ch_free( cargv );
2089 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2090 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2091 &frontendDB->be_schemadn );
2092 dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2095 if ( load_ucdata( NULL ) < 0 ) return 1;
2107 char logbuf[sizeof("pseudorootpw ***")];
2110 token = strtok_quote( line, " \t" );
2114 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2115 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2116 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2117 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2118 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2120 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2123 if ( strtok_quote_ptr ) {
2124 *strtok_quote_ptr = ' ';
2127 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2129 if ( strtok_quote_ptr ) {
2130 *strtok_quote_ptr = '\0';
2133 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2134 if ( cargc == cargv_size - 1 ) {
2136 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2138 if ( tmp == NULL ) {
2139 Debug( LDAP_DEBUG_ANY,
2140 "line %d: out of memory\n",
2145 cargv_size += ARGS_STEP;
2147 cargv[cargc++] = token;
2149 cargv[cargc] = NULL;
2154 strtok_quote( char *line, char *sep )
2160 strtok_quote_ptr = NULL;
2161 if ( line != NULL ) {
2164 while ( *next && strchr( sep, *next ) ) {
2168 if ( *next == '\0' ) {
2174 for ( inquote = 0; *next; ) {
2182 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2188 next + 1, strlen( next + 1 ) + 1 );
2189 next++; /* dont parse the escaped character */
2194 if ( strchr( sep, *next ) != NULL ) {
2195 strtok_quote_ptr = next;
2208 static char buf[BUFSIZ];
2210 static size_t lmax, lcur;
2212 #define CATLINE( buf ) \
2214 size_t len = strlen( buf ); \
2215 while ( lcur + len + 1 > lmax ) { \
2217 line = (char *) ch_realloc( line, lmax ); \
2219 strcpy( line + lcur, buf ); \
2224 fp_getline( FILE *fp, int *lineno )
2232 /* hack attack - keeps us from having to keep a stack of bufs... */
2233 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2238 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2239 /* trim off \r\n or \n */
2240 if ( (p = strchr( buf, '\n' )) != NULL ) {
2241 if( p > buf && p[-1] == '\r' ) --p;
2245 /* trim off trailing \ and append the next line */
2246 if ( line[ 0 ] != '\0'
2247 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2248 && p[ -1 ] != '\\' ) {
2253 if ( ! isspace( (unsigned char) buf[0] ) ) {
2257 /* change leading whitespace to a space */
2266 return( line[0] ? line : NULL );
2270 fp_getline_init( int *lineno )
2276 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2278 load_ucdata( char *path )
2281 static int loaded = 0;
2287 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2289 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2297 /* ucdata is now hardcoded */
2305 ucdata_unload( UCDATA_ALL );
2307 /* NOTE: in case of early exit, frontendDB can be NULL */
2308 if ( frontendDB->be_schemandn.bv_val )
2309 free( frontendDB->be_schemandn.bv_val );
2310 if ( frontendDB->be_schemadn.bv_val )
2311 free( frontendDB->be_schemadn.bv_val );
2312 if ( frontendDB->be_acl )
2313 acl_destroy( frontendDB->be_acl, NULL );
2316 if ( slapd_args_file )
2317 free ( slapd_args_file );
2318 if ( slapd_pid_file )
2319 free ( slapd_pid_file );
2320 if ( default_passwd_hash )
2321 ldap_charray_free( default_passwd_hash );
2332 syncinfo_t *si_entry;
2334 int duplicated_replica_id = 0;
2336 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2339 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2343 si->si_tls = SYNCINFO_TLS_OFF;
2344 if ( be->be_rootndn.bv_val ) {
2345 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2347 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2348 si->si_schemachecking = 0;
2349 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2350 &si->si_filterstr );
2351 si->si_base.bv_val = NULL;
2352 si->si_scope = LDAP_SCOPE_SUBTREE;
2353 si->si_attrsonly = 0;
2354 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2355 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2356 si->si_attrs = NULL;
2357 si->si_allattrs = 0;
2358 si->si_allopattrs = 0;
2359 si->si_exattrs = NULL;
2360 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2361 si->si_interval = 86400;
2362 si->si_retryinterval = NULL;
2363 si->si_retrynum_init = NULL;
2364 si->si_retrynum = NULL;
2365 si->si_syncCookie.ctxcsn = NULL;
2366 si->si_syncCookie.octet_str = NULL;
2367 si->si_syncCookie.sid = -1;
2368 si->si_manageDSAit = 0;
2371 si->si_syncUUID_ndn.bv_val = NULL;
2372 si->si_syncUUID_ndn.bv_len = 0;
2374 si->si_presentlist = NULL;
2375 LDAP_LIST_INIT( &si->si_nonpresentlist );
2377 rc = parse_syncrepl_line( cargv, cargc, si );
2379 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2380 if ( si->si_rid == si_entry->si_rid ) {
2381 Debug( LDAP_DEBUG_ANY,
2382 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2383 duplicated_replica_id = 1;
2388 if ( rc < 0 || duplicated_replica_id ) {
2389 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2390 syncinfo_free( si );
2393 Debug( LDAP_DEBUG_CONFIG,
2394 "Config: ** successfully added syncrepl \"%s\"\n",
2395 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2396 if ( !si->si_schemachecking ) {
2397 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2400 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2405 /* NOTE: used & documented in slapd.conf(5) */
2407 #define PROVIDERSTR "provider"
2408 #define TYPESTR "type"
2409 #define INTERVALSTR "interval"
2410 #define SEARCHBASESTR "searchbase"
2411 #define FILTERSTR "filter"
2412 #define SCOPESTR "scope"
2413 #define ATTRSSTR "attrs"
2414 #define ATTRSONLYSTR "attrsonly"
2415 #define SLIMITSTR "sizelimit"
2416 #define TLIMITSTR "timelimit"
2417 #define SCHEMASTR "schemachecking"
2418 #define UPDATEDNSTR "updatedn"
2419 #define BINDMETHSTR "bindmethod"
2420 #define SIMPLESTR "simple"
2421 #define SASLSTR "sasl"
2422 #define BINDDNSTR "binddn"
2423 #define SASLMECHSTR "saslmech"
2424 #define AUTHCSTR "authcID"
2425 #define AUTHZSTR "authzID"
2426 #define CREDSTR "credentials"
2427 #define REALMSTR "realm"
2428 #define SECPROPSSTR "secprops"
2430 /* FIXME: undocumented */
2431 #define OLDAUTHCSTR "bindprincipal"
2432 #define STARTTLSSTR "starttls"
2433 #define CRITICALSTR "critical"
2434 #define EXATTRSSTR "exattrs"
2435 #define MANAGEDSAITSTR "manageDSAit"
2436 #define RETRYSTR "retry"
2439 #define LASTMODSTR "lastmod"
2440 #define LMGENSTR "gen"
2441 #define LMNOSTR "no"
2442 #define LMREQSTR "req"
2443 #define SRVTABSTR "srvtab"
2444 #define SUFFIXSTR "suffix"
2447 #define GOT_ID 0x0001
2448 #define GOT_PROVIDER 0x0002
2449 #define GOT_METHOD 0x0004
2452 #define GOT_ALL (GOT_ID|GOT_PROVIDER|GOT_METHOD)
2455 parse_syncrepl_line(
2466 for ( i = 1; i < cargc; i++ ) {
2467 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2468 STRLENOF( IDSTR "=" ) ) )
2471 /* '\0' string terminator accounts for '=' */
2472 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2474 if ( tmp >= 1000 || tmp < 0 ) {
2475 fprintf( stderr, "Error: parse_syncrepl_line: "
2476 "syncrepl id %d is out of range [0..999]\n", tmp );
2481 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2482 STRLENOF( PROVIDERSTR "=" ) ) )
2484 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2485 si->si_provideruri = ch_strdup( val );
2486 si->si_provideruri_bv = (BerVarray)
2487 ch_calloc( 2, sizeof( struct berval ));
2488 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2489 1, &si->si_provideruri_bv[0] );
2490 si->si_provideruri_bv[1].bv_len = 0;
2491 si->si_provideruri_bv[1].bv_val = NULL;
2492 gots |= GOT_PROVIDER;
2493 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR "=",
2494 STRLENOF(STARTTLSSTR "=") ) )
2496 val = cargv[ i ] + STRLENOF( STARTTLSSTR "=" );
2497 if( !strcasecmp( val, CRITICALSTR ) ) {
2498 si->si_tls = SYNCINFO_TLS_CRITICAL;
2500 si->si_tls = SYNCINFO_TLS_ON;
2502 } else if ( !strncasecmp( cargv[ i ], UPDATEDNSTR "=",
2503 STRLENOF( UPDATEDNSTR "=" ) ) )
2505 struct berval updatedn = BER_BVNULL;
2507 val = cargv[ i ] + STRLENOF( UPDATEDNSTR "=" );
2508 ber_str2bv( val, 0, 0, &updatedn );
2509 ch_free( si->si_updatedn.bv_val );
2510 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
2511 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR "=",
2512 STRLENOF( BINDMETHSTR "=" ) ) )
2514 val = cargv[ i ] + STRLENOF( BINDMETHSTR "=" );
2515 if ( !strcasecmp( val, SIMPLESTR )) {
2516 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2518 } else if ( !strcasecmp( val, SASLSTR )) {
2519 #ifdef HAVE_CYRUS_SASL
2520 si->si_bindmethod = LDAP_AUTH_SASL;
2522 #else /* HAVE_CYRUS_SASL */
2523 fprintf( stderr, "Error: parse_syncrepl_line: "
2524 "not compiled with SASL support\n" );
2526 #endif /* HAVE_CYRUS_SASL */
2528 si->si_bindmethod = -1;
2530 } else if ( !strncasecmp( cargv[ i ], BINDDNSTR "=",
2531 STRLENOF( BINDDNSTR "=" ) ) )
2533 val = cargv[ i ] + STRLENOF( BINDDNSTR "=" );
2534 si->si_binddn = ch_strdup( val );
2535 } else if ( !strncasecmp( cargv[ i ], CREDSTR "=",
2536 STRLENOF( CREDSTR "=" ) ) )
2538 val = cargv[ i ] + STRLENOF( CREDSTR "=" );
2539 si->si_passwd = ch_strdup( val );
2540 } else if ( !strncasecmp( cargv[ i ], SASLMECHSTR "=",
2541 STRLENOF( SASLMECHSTR "=" ) ) )
2543 val = cargv[ i ] + STRLENOF( SASLMECHSTR "=" );
2544 si->si_saslmech = ch_strdup( val );
2545 } else if ( !strncasecmp( cargv[ i ], SECPROPSSTR "=",
2546 STRLENOF( SECPROPSSTR "=" ) ) )
2548 val = cargv[ i ] + STRLENOF( SECPROPSSTR "=" );
2549 si->si_secprops = ch_strdup( val );
2550 } else if ( !strncasecmp( cargv[ i ], REALMSTR "=",
2551 STRLENOF( REALMSTR "=" ) ) )
2553 val = cargv[ i ] + STRLENOF( REALMSTR "=" );
2554 si->si_realm = ch_strdup( val );
2555 } else if ( !strncasecmp( cargv[ i ], AUTHCSTR "=",
2556 STRLENOF( AUTHCSTR "=" ) ) )
2558 val = cargv[ i ] + STRLENOF( AUTHCSTR "=" );
2559 if ( si->si_authcId )
2560 ch_free( si->si_authcId );
2561 si->si_authcId = ch_strdup( val );
2562 } else if ( !strncasecmp( cargv[ i ], OLDAUTHCSTR "=",
2563 STRLENOF( OLDAUTHCSTR "=" ) ) )
2565 /* Old authcID is provided for some backwards compatibility */
2566 val = cargv[ i ] + STRLENOF( OLDAUTHCSTR "=" );
2567 if ( si->si_authcId )
2568 ch_free( si->si_authcId );
2569 si->si_authcId = ch_strdup( val );
2570 } else if ( !strncasecmp( cargv[ i ], AUTHZSTR "=",
2571 STRLENOF( AUTHZSTR "=" ) ) )
2573 val = cargv[ i ] + STRLENOF( AUTHZSTR "=" );
2574 si->si_authzId = ch_strdup( val );
2575 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2576 STRLENOF( SCHEMASTR "=" ) ) )
2578 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2579 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2580 si->si_schemachecking = 1;
2581 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2582 si->si_schemachecking = 0;
2584 si->si_schemachecking = 1;
2586 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2587 STRLENOF( FILTERSTR "=" ) ) )
2589 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2590 ber_str2bv( val, 0, 1, &si->si_filterstr );
2591 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2592 STRLENOF( SEARCHBASESTR "=" ) ) )
2595 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2596 if ( si->si_base.bv_val ) {
2597 ch_free( si->si_base.bv_val );
2599 ber_str2bv( val, 0, 0, &bv );
2600 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
2601 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
2604 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2605 STRLENOF( SCOPESTR "=" ) ) )
2607 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2608 if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
2609 si->si_scope = LDAP_SCOPE_BASE;
2610 } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
2611 si->si_scope = LDAP_SCOPE_ONELEVEL;
2612 #ifdef LDAP_SCOPE_SUBORDINATE
2613 } else if ( !strcasecmp( val, "subordinate" ) ||
2614 !strcasecmp( val, "children" ))
2616 si->si_scope = LDAP_SCOPE_SUBORDINATE;
2618 } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
2619 si->si_scope = LDAP_SCOPE_SUBTREE;
2621 fprintf( stderr, "Error: parse_syncrepl_line: "
2622 "unknown scope \"%s\"\n", val);
2625 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2626 STRLENOF( ATTRSONLYSTR "=" ) ) )
2628 si->si_attrsonly = 1;
2629 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2630 STRLENOF( ATTRSSTR "=" ) ) )
2632 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2633 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2635 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2636 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2637 if ( si->si_anlist == NULL ) {
2638 ch_free( attr_fname );
2641 ch_free( attr_fname );
2643 char *str, *s, *next;
2644 char delimstr[] = " ,\t";
2645 str = ch_strdup( val );
2646 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2648 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2650 if ( strlen(s) == 1 && *s == '*' ) {
2651 si->si_allattrs = 1;
2652 *(val + ( s - str )) = delimstr[0];
2654 if ( strlen(s) == 1 && *s == '+' ) {
2655 si->si_allopattrs = 1;
2656 *(val + ( s - str )) = delimstr[0];
2660 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2661 if ( si->si_anlist == NULL ) {
2665 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2666 STRLENOF( EXATTRSSTR "=" ) ) )
2668 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2669 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2671 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2672 si->si_exanlist = file2anlist(
2673 si->si_exanlist, attr_fname, " ,\t" );
2674 if ( si->si_exanlist == NULL ) {
2675 ch_free( attr_fname );
2678 ch_free( attr_fname );
2681 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2682 if ( si->si_exanlist == NULL ) {
2686 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2687 STRLENOF( TYPESTR "=" ) ) )
2689 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2690 if ( !strncasecmp( val, "refreshOnly",
2691 STRLENOF("refreshOnly") ))
2693 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2694 } else if ( !strncasecmp( val, "refreshAndPersist",
2695 STRLENOF("refreshAndPersist") ))
2697 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2698 si->si_interval = 60;
2700 fprintf( stderr, "Error: parse_syncrepl_line: "
2701 "unknown sync type \"%s\"\n", val);
2704 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2705 STRLENOF( INTERVALSTR "=" ) ) )
2707 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2708 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2709 si->si_interval = 0;
2717 hstr = strchr( dstr, ':' );
2718 if ( hstr == NULL ) {
2719 fprintf( stderr, "Error: parse_syncrepl_line: "
2720 "invalid interval \"%s\"\n", val );
2724 mstr = strchr( hstr, ':' );
2725 if ( mstr == NULL ) {
2726 fprintf( stderr, "Error: parse_syncrepl_line: "
2727 "invalid interval \"%s\"\n", val );
2731 sstr = strchr( mstr, ':' );
2732 if ( sstr == NULL ) {
2733 fprintf( stderr, "Error: parse_syncrepl_line: "
2734 "invalid interval \"%s\"\n", val );
2743 if (( hh > 24 ) || ( hh < 0 ) ||
2744 ( mm > 60 ) || ( mm < 0 ) ||
2745 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2746 fprintf( stderr, "Error: parse_syncrepl_line: "
2747 "invalid interval \"%s\"\n", val );
2750 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2752 if ( si->si_interval < 0 ) {
2753 fprintf( stderr, "Error: parse_syncrepl_line: "
2754 "invalid interval \"%ld\"\n",
2755 (long) si->si_interval);
2758 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2759 STRLENOF( RETRYSTR "=" ) ) )
2765 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2766 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2767 retry_list[0] = NULL;
2769 slap_str2clist( &retry_list, val, " ,\t" );
2771 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2775 "Error: incomplete syncrepl retry list\n" );
2776 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2777 ch_free( retry_list[k] );
2779 ch_free( retry_list );
2780 exit( EXIT_FAILURE );
2782 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2783 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2784 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2785 for ( j = 0; j < n; j++ ) {
2786 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2787 if ( *retry_list[j*2+1] == '+' ) {
2788 si->si_retrynum_init[j] = -1;
2789 si->si_retrynum[j] = -1;
2793 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2794 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2797 si->si_retrynum_init[j] = -2;
2798 si->si_retrynum[j] = -2;
2799 si->si_retryinterval[j] = 0;
2801 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2802 ch_free( retry_list[k] );
2804 ch_free( retry_list );
2805 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2806 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2808 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2809 si->si_manageDSAit = atoi( val );
2810 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2811 STRLENOF( SLIMITSTR "=") ) )
2813 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2814 si->si_slimit = atoi( val );
2815 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2816 STRLENOF( TLIMITSTR "=" ) ) )
2818 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2819 si->si_tlimit = atoi( val );
2821 fprintf( stderr, "Error: parse_syncrepl_line: "
2822 "unknown keyword \"%s\"\n", cargv[ i ] );
2826 if ( gots != GOT_ALL ) {
2828 "Error: Malformed \"syncrepl\" line in slapd config file" );
2836 slap_str2clist( char ***out, char *in, const char *brkstr )
2845 /* find last element in list */
2846 for (i = 0; *out && (*out)[i]; i++);
2848 /* protect the input string from strtok */
2849 str = ch_strdup( in );
2851 if ( *str == '\0' ) {
2856 /* Count words in string */
2858 for ( s = str; *s; s++ ) {
2859 if ( strchr( brkstr, *s ) != NULL ) {
2864 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
2866 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
2868 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
2870 *new = ch_strdup( s );