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>
36 #include <ac/unistd.h>
40 #include "slapi/slapi.h"
47 * defaults for various global variables
49 int cargc = 0, cargv_size = 0;
52 char *strtok_quote_ptr;
54 static char *fp_getline(FILE *fp, int *lineno);
55 static void fp_getline_init(int *lineno);
56 static int fp_parse_line(int lineno, char *line);
58 static char *strtok_quote(char *line, char *sep);
59 static int load_ucdata(char *path);
61 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
62 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
64 Global slap_Configuration;
65 extern BackendDB slap_frontendDB, *frontendDB;
67 void config_init(void) {
68 /* system config defaults */
69 Global *g = &slap_Configuration;
70 memset(g, 0, sizeof(slap_Configuration));
72 /* because we need frontendDB* before frontend_init, paint it black */
73 frontendDB = &slap_frontendDB;
74 memset(frontendDB, 0, sizeof(frontendDB));
76 g->schemachecking = 1;
78 g->connection_pool_max = SLAP_MAX_WORKER_THREADS;
80 g->sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
81 g->sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
83 g->conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
84 g->conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
86 g->local_ssf = LDAP_PVT_SASL_LOCAL_SSF;
91 g->syslog = LDAP_DEBUG_STATS;
95 g->syslog_level = LOG_DEBUG;
100 g->dtblsize = sysconf( _SC_OPEN_MAX );
101 #elif HAVE_GETDTABLESIZE
102 g->dtblsize = getdtablesize();
104 g->dtblsize = FD_SETSIZE;
108 if(g->dtblsize > FD_SETSIZE) g->dtblsize = FD_SETSIZE;
109 #endif /* !FD_SETSIZE */
111 g->index_substr_if_minlen = SLAP_INDEX_SUBSTR_IF_MINLEN_DEFAULT;
112 g->index_substr_if_maxlen = SLAP_INDEX_SUBSTR_IF_MAXLEN_DEFAULT;
113 g->index_substr_any_len = SLAP_INDEX_SUBSTR_ANY_LEN_DEFAULT;
114 g->index_substr_any_step = SLAP_INDEX_SUBSTR_ANY_STEP_DEFAULT;
116 /* XXX when doing mutex, we may have to know slapMode */
118 frontendDB->be_private = g;
123 read_config( const char *fname, int depth )
126 char *line, *savefname, *saveline;
130 struct berval vals[2];
133 static BackendInfo *bi = NULL;
134 static BackendDB *be = NULL;
137 vals[1].bv_val = NULL;
140 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
141 cargv_size = ARGS_STEP + 1;
144 if ( (fp = fopen( fname, "r" )) == NULL ) {
146 Debug( LDAP_DEBUG_ANY,
147 "could not open config file \"%s\": %s (%d)\n",
148 fname, strerror(errno), errno );
152 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
155 fp_getline_init( &lineno );
157 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
158 /* skip comments and blank lines */
159 if ( line[0] == '#' || line[0] == '\0' ) {
163 /* fp_parse_line is destructive, we save a copy */
164 saveline = ch_strdup( line );
166 if ( fp_parse_line( lineno, line ) != 0 ) {
171 Debug( LDAP_DEBUG_ANY,
172 "%s: line %d: bad config line (ignored)\n",
178 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
180 Debug( LDAP_DEBUG_ANY,
181 "%s: line %d: missing type in \"backend <type>\" line\n",
188 Debug( LDAP_DEBUG_ANY,
189 "%s: line %d: backend line must appear before any database definition\n",
195 bi = backend_info( cargv[1] );
198 Debug( LDAP_DEBUG_ANY,
199 "backend %s initialization failed.\n",
204 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
206 Debug( LDAP_DEBUG_ANY,
207 "%s: line %d: missing type in \"database <type>\" line\n",
214 be = backend_db_init( cargv[1] );
217 Debug( LDAP_DEBUG_ANY,
218 "database %s initialization failed.\n",
224 /* set local security factor */
225 } else if ( strcasecmp( cargv[0], "localSSF" ) == 0 ) {
228 Debug( LDAP_DEBUG_ANY,
229 "%s: line %d: missing ssf in \"localSSF <ssf>\" line\n",
234 ssf = atol( cargv[1] );
237 Debug( LDAP_DEBUG_ANY,
238 "%s: line %d: invalid ssf value (%ld) in "
239 "\"localSSF <ssf>\" line.\n",
240 fname, lineno, ssf );
244 SLAPD_GLOBAL(local_ssf) = ssf;
246 /* set thread concurrency */
247 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
250 Debug( LDAP_DEBUG_ANY,
251 "%s: line %d: missing level in \"concurrency <level>\" line\n",
257 c = strtol( cargv[1], &next, 10 );
258 if ( next == NULL || next[0] != '\0' ) {
259 Debug( LDAP_DEBUG_ANY,
260 "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" line\n",
261 fname, lineno, cargv[1] );
266 Debug( LDAP_DEBUG_ANY,
267 "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
273 ldap_pvt_thread_set_concurrency( c );
274 SLAPD_GLOBAL(conf_concurrency) = c;
276 /* set substring initial/final index minimum length */
277 } else if ( strcasecmp( cargv[0], "index_substr_if_minlen" ) == 0 ) {
280 Debug( LDAP_DEBUG_ANY,
281 "%s: line %d: missing min in \"index_substr_if_minlen <length>\" line\n",
285 min = atoi( cargv[1] );
286 if( min < 1 || min > SLAPD_GLOBAL(index_substr_if_maxlen) ) {
287 Debug( LDAP_DEBUG_ANY,
288 "%s: line %d: invalid min value (%ld) in "
289 "\"index_substr_if_minlen <length>\" line.\n",
290 fname, lineno, min );
293 SLAPD_GLOBAL(index_substr_if_minlen) = min;
295 /* set substring initial/final index maximum length */
296 } else if ( strcasecmp( cargv[0], "index_substr_if_maxlen" ) == 0 ) {
299 Debug( LDAP_DEBUG_ANY,
300 "%s: line %d: missing max in \"index_substr_if_maxlen <length>\" line\n",
304 max = atol( cargv[1] );
305 if( max < 1 || max < SLAPD_GLOBAL(index_substr_if_minlen) ) {
306 Debug( LDAP_DEBUG_ANY,
307 "%s: line %d: invalid max value (%ld) in "
308 "\"index_substr_maxlen <length>\" line.\n",
309 fname, lineno, max );
312 SLAPD_GLOBAL(index_substr_if_maxlen) = max;
314 /* set substring any index len */
315 } else if ( strcasecmp( cargv[0], "index_substr_any_len" ) == 0 ) {
318 Debug( LDAP_DEBUG_ANY,
319 "%s: line %d: missing len in \"index_substr_any_len <len>\" line\n",
323 len = atol( cargv[1] );
325 Debug( LDAP_DEBUG_ANY,
326 "%s: line %d: invalid len value (%ld) in "
327 "\"index_substr_any_len <len>\" line.\n",
328 fname, lineno, len );
331 SLAPD_GLOBAL(index_substr_any_len) = len;
333 /* set substring any index step */
334 } else if ( strcasecmp( cargv[0], "index_substr_any_step" ) == 0 ) {
337 Debug( LDAP_DEBUG_ANY,
338 "%s: line %d: missing step in \"index_substr_any_step <step>\" line\n",
342 step = atol( cargv[1] );
344 Debug( LDAP_DEBUG_ANY,
345 "%s: line %d: invalid step value (%ld) in "
346 "\"index_substr_any_step <step>\" line.\n",
347 fname, lineno, step );
350 SLAPD_GLOBAL(index_substr_any_step) = step;
352 /* set sockbuf max */
353 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
356 Debug( LDAP_DEBUG_ANY,
357 "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
363 max = atol( cargv[1] );
366 Debug( LDAP_DEBUG_ANY,
367 "%s: line %d: invalid max value (%ld) in "
368 "\"sockbuf_max_incoming <bytes>\" line.\n",
369 fname, lineno, max );
374 SLAPD_GLOBAL(sockbuf_max_incoming) = max;
376 /* set sockbuf max authenticated */
377 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
380 Debug( LDAP_DEBUG_ANY,
381 "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
387 max = atol( cargv[1] );
390 Debug( LDAP_DEBUG_ANY,
391 "%s: line %d: invalid max value (%ld) in "
392 "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
393 fname, lineno, max );
398 SLAPD_GLOBAL(sockbuf_max_incoming_auth) = max;
400 /* set conn pending max */
401 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
404 Debug( LDAP_DEBUG_ANY,
405 "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
411 max = atol( cargv[1] );
414 Debug( LDAP_DEBUG_ANY,
415 "%s: line %d: invalid max value (%ld) in "
416 "\"conn_max_pending <requests>\" line.\n",
417 fname, lineno, max );
422 SLAPD_GLOBAL(conn_max_pending) = max;
424 /* set conn pending max authenticated */
425 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
428 Debug( LDAP_DEBUG_ANY,
429 "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
435 max = atol( cargv[1] );
438 Debug( LDAP_DEBUG_ANY,
439 "%s: line %d: invalid max value (%ld) in "
440 "\"conn_max_pending_auth <requests>\" line.\n",
441 fname, lineno, max );
446 SLAPD_GLOBAL(conn_max_pending_auth) = max;
448 /* default search base */
449 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
451 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
452 "missing dn in \"defaultSearchBase <dn>\" line\n",
457 } else if ( cargc > 2 ) {
458 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
459 "extra cruft after <dn> in \"defaultSearchBase %s\", "
461 fname, lineno, cargv[1] );
464 if ( bi != NULL || be != NULL ) {
465 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
466 "defaultSearchBaase line must appear prior to "
467 "any backend or database definition\n",
473 if ( SLAPD_GLOBAL(default_search_nbase).bv_len ) {
474 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
475 "default search base \"%s\" already defined "
476 "(discarding old)\n",
477 fname, lineno, SLAPD_GLOBAL(default_search_base).bv_val );
479 free( SLAPD_GLOBAL(default_search_base).bv_val );
480 free( SLAPD_GLOBAL(default_search_nbase).bv_val );
483 if ( load_ucdata( NULL ) < 0 ) return 1;
488 dn.bv_val = cargv[1];
489 dn.bv_len = strlen( dn.bv_val );
491 rc = dnPrettyNormal( NULL, &dn,
492 &SLAPD_GLOBAL(default_search_base),
493 &SLAPD_GLOBAL(default_search_nbase), NULL );
495 if( rc != LDAP_SUCCESS ) {
496 Debug( LDAP_DEBUG_ANY,
497 "%s: line %d: defaultSearchBase DN is invalid\n",
503 /* set maximum threads in thread pool */
504 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
507 Debug( LDAP_DEBUG_ANY,
508 "%s: line %d: missing count in \"threads <count>\" line\n",
514 c = strtol( cargv[1], &next, 10 );
515 if (next == NULL || next[0] != '\0' ) {
516 Debug( LDAP_DEBUG_ANY,
517 "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
518 fname, lineno, cargv[1] );
523 Debug( LDAP_DEBUG_ANY,
524 "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
530 ldap_pvt_thread_pool_maxthreads( &SLAPD_GLOBAL(connection_pool), c );
532 /* save for later use */
533 SLAPD_GLOBAL(connection_pool_max) = c;
535 /* get pid file name */
536 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
538 Debug( LDAP_DEBUG_ANY,
539 "%s: line %d: missing file name in \"pidfile <file>\" line\n",
545 SLAPD_GLOBAL(pid_file) = ch_strdup( cargv[1] );
547 /* get args file name */
548 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
550 Debug( LDAP_DEBUG_ANY,
551 "%s: line %d: missing file name in \"argsfile <file>\" line\n",
557 SLAPD_GLOBAL(args_file) = ch_strdup( cargv[1] );
559 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
562 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
565 /* default password hash */
566 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
568 Debug( LDAP_DEBUG_ANY,
569 "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
574 if ( SLAPD_GLOBAL(default_passwd_hash) != NULL ) {
575 Debug( LDAP_DEBUG_ANY,
576 "%s: line %d: already set default password_hash!\n",
582 for(i = 1; i < cargc; i++) {
583 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
584 Debug( LDAP_DEBUG_ANY,
585 "%s: line %d: password scheme \"%s\" not available\n",
586 fname, lineno, cargv[i] );
588 ldap_charray_add( &SLAPD_GLOBAL(default_passwd_hash), cargv[i] );
591 if( !SLAPD_GLOBAL(default_passwd_hash) ) {
592 Debug( LDAP_DEBUG_ANY,
593 "%s: line %d: no valid hashes found\n",
598 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
601 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
602 "\"password-crypt-salt-format <format>\" line\n",
608 lutil_salt_format( cargv[1] );
609 SLAPD_GLOBAL(conf_salt_format) = ch_strdup(cargv[1]);
611 #ifdef SLAP_AUTH_REWRITE
612 /* use authid rewrite instead of sasl regexp */
613 } else if ( strncasecmp( cargv[0], "auth-rewrite",
614 STRLENOF("auth-rewrite") ) == 0 )
616 int rc = slap_sasl_rewrite_config( fname, lineno,
621 #endif /* SLAP_AUTH_REWRITE */
623 /* Auth + SASL config options */
624 } else if ( !strncasecmp( cargv[0], "auth", STRLENOF("auth") ) ||
625 !strncasecmp( cargv[0], "sasl", STRLENOF("sasl") ))
627 if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
631 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
634 Debug( LDAP_DEBUG_ANY,
635 "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
639 ber_str2bv( cargv[1], 0, 0, &dn );
641 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
642 &be->be_schemandn, NULL );
644 rc = dnPrettyNormal( NULL, &dn, &frontendDB->be_schemadn,
645 &frontendDB->be_schemandn, NULL );
647 if ( rc != LDAP_SUCCESS ) {
648 Debug( LDAP_DEBUG_ANY,
649 "%s: line %d: schemadn DN is invalid\n",
654 /* set UCDATA path */
655 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
658 Debug( LDAP_DEBUG_ANY,
659 "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
665 err = load_ucdata( cargv[1] );
668 Debug( LDAP_DEBUG_ANY,
669 "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
677 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
679 struct slap_limits_set *lim;
682 Debug( LDAP_DEBUG_ANY,
683 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
690 lim = &frontendDB->be_def_limit;
692 lim = &be->be_def_limit;
695 for ( i = 1; i < cargc; i++ ) {
696 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
697 rc = limits_parse_one( cargv[i], lim );
699 Debug( LDAP_DEBUG_ANY,
700 "%s: line %d: unable "
701 "to parse value \"%s\" "
704 fname, lineno, cargv[i] );
709 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
710 lim->lms_s_soft = -1;
712 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
713 if ( next == cargv[i] ) {
714 Debug( LDAP_DEBUG_ANY,
715 "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
716 fname, lineno, cargv[i] );
719 } else if ( next[0] != '\0' ) {
720 Debug( LDAP_DEBUG_ANY,
721 "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
722 fname, lineno, next );
730 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
732 struct slap_limits_set *lim;
735 Debug( LDAP_DEBUG_ANY,
736 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
743 lim = &frontendDB->be_def_limit;
745 lim = &be->be_def_limit;
748 for ( i = 1; i < cargc; i++ ) {
749 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
750 rc = limits_parse_one( cargv[i], lim );
752 Debug( LDAP_DEBUG_ANY,
753 "%s: line %d: unable "
754 "to parse value \"%s\" "
757 fname, lineno, cargv[i] );
762 if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
763 lim->lms_t_soft = -1;
765 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
766 if ( next == cargv[i] ) {
767 Debug( LDAP_DEBUG_ANY,
768 "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
769 fname, lineno, cargv[i] );
772 } else if ( next[0] != '\0' ) {
773 Debug( LDAP_DEBUG_ANY,
774 "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
775 fname, lineno, next );
782 /* set regex-based limits */
783 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
785 Debug( LDAP_DEBUG_ANY,
786 "%s: line %d \"limits\" allowed only in database environment.\n%s",
791 if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
795 /* mark this as a subordinate database */
796 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
798 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
799 "must appear inside a database definition.\n",
804 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
805 SLAPD_GLOBAL(num_subordinates)++;
808 /* add an overlay to this backend */
809 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
811 if ( cargv[1][0] == '-' && overlay_config( frontendDB, &cargv[1][1] ) ) {
813 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
814 "(optional) global overlay \"%s\" configuration "
815 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
816 } else if ( overlay_config( frontendDB, cargv[1] ) ) {
821 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
823 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
824 "(optional) overlay \"%s\" configuration "
825 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
826 } else if ( overlay_config( be, cargv[1] ) ) {
831 /* set database suffix */
832 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
834 struct berval dn, pdn, ndn;
837 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
838 "missing dn in \"suffix <dn>\" line\n",
843 } else if ( cargc > 2 ) {
844 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
845 "after <dn> in \"suffix %s\" line (ignored)\n",
846 fname, lineno, cargv[1] );
850 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
851 "must appear inside a database definition\n",
855 #if defined(SLAPD_MONITOR_DN)
856 /* "cn=Monitor" is reserved for monitoring slap */
857 } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
858 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
859 "%s\" is reserved for monitoring slapd\n",
860 fname, lineno, SLAPD_MONITOR_DN );
862 #endif /* SLAPD_MONITOR_DN */
865 if ( load_ucdata( NULL ) < 0 ) return 1;
867 dn.bv_val = cargv[1];
868 dn.bv_len = strlen( cargv[1] );
870 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
871 if( rc != LDAP_SUCCESS ) {
872 Debug( LDAP_DEBUG_ANY,
873 "%s: line %d: suffix DN is invalid\n",
878 tmp_be = select_backend( &ndn, 0, 0 );
879 if ( tmp_be == be ) {
880 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
881 "already served by this backend (ignored)\n",
886 } else if ( tmp_be != NULL ) {
887 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
888 "already served by a preceeding backend \"%s\"\n",
889 fname, lineno, tmp_be->be_suffix[0].bv_val );
894 } else if( pdn.bv_len == 0 && SLAPD_GLOBAL(default_search_nbase).bv_len ) {
895 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
896 "suffix DN empty and default "
897 "search base provided \"%s\" (assuming okay)\n",
898 fname, lineno, SLAPD_GLOBAL(default_search_base).bv_val );
901 ber_bvarray_add( &be->be_suffix, &pdn );
902 ber_bvarray_add( &be->be_nsuffix, &ndn );
904 /* set max deref depth */
905 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
908 Debug( LDAP_DEBUG_ANY,
909 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
915 Debug( LDAP_DEBUG_ANY,
916 "%s: line %d: depth line must appear inside a database definition.\n",
921 i = strtol( cargv[1], &next, 10 );
922 if ( next == NULL || next[0] != '\0' ) {
923 Debug( LDAP_DEBUG_ANY,
924 "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
925 "line.\n", fname, lineno, cargv[1] );
930 Debug( LDAP_DEBUG_ANY,
931 "%s: line %d: depth must be positive.\n",
937 be->be_max_deref_depth = i;
939 /* set magic "root" dn for this database */
940 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
942 Debug( LDAP_DEBUG_ANY,
943 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
950 Debug( LDAP_DEBUG_ANY,
951 "%s: line %d: rootdn line must appear inside a database definition.\n",
958 if ( load_ucdata( NULL ) < 0 ) return 1;
960 dn.bv_val = cargv[1];
961 dn.bv_len = strlen( cargv[1] );
963 rc = dnPrettyNormal( NULL, &dn,
965 &be->be_rootndn, NULL );
967 if( rc != LDAP_SUCCESS ) {
968 Debug( LDAP_DEBUG_ANY,
969 "%s: line %d: rootdn DN is invalid\n",
975 /* set super-secret magic database password */
976 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
978 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
979 "missing passwd in \"rootpw <passwd>\" line\n",
986 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
987 "rootpw line must appear inside a database "
993 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
996 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
997 "rootpw can only be set when rootdn is under suffix\n",
1002 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1003 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1006 /* make this database read-only */
1007 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1009 Debug( LDAP_DEBUG_ANY,
1010 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1016 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1017 frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1019 frontendDB->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1023 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1024 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1026 be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1030 /* restricts specific operations */
1031 } else if ( strcasecmp( cargv[0], "restrict" ) == 0 ) {
1032 slap_mask_t restrictops = 0;
1033 struct restrictable_exops_t {
1036 } restrictable_exops[] = {
1037 { LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1038 { LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1039 { LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1040 { LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1046 Debug( LDAP_DEBUG_ANY,
1047 "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
1048 "line.\n", fname, lineno, 0 );
1052 for ( i = 1; i < cargc; i++ ) {
1053 if ( strcasecmp( cargv[ i ], "read" ) == 0 ) {
1054 restrictops |= SLAP_RESTRICT_OP_READS;
1056 } else if ( strcasecmp( cargv[ i ], "write" ) == 0 ) {
1057 restrictops |= SLAP_RESTRICT_OP_WRITES;
1059 } else if ( strcasecmp( cargv[ i ], "add" ) == 0 ) {
1060 restrictops |= SLAP_RESTRICT_OP_ADD;
1062 } else if ( strcasecmp( cargv[ i ], "bind" ) == 0 ) {
1063 restrictops |= SLAP_RESTRICT_OP_BIND;
1065 } else if ( strcasecmp( cargv[ i ], "compare" ) == 0 ) {
1066 restrictops |= SLAP_RESTRICT_OP_COMPARE;
1068 } else if ( strcasecmp( cargv[ i ], "delete" ) == 0 ) {
1069 restrictops |= SLAP_RESTRICT_OP_DELETE;
1071 } else if ( strncasecmp( cargv[ i ], "extended",
1072 STRLENOF( "extended" ) ) == 0 )
1074 char *e = cargv[ i ] + STRLENOF( "extended" );
1076 if ( e[0] == '=' ) {
1080 for ( j = 0; restrictable_exops[ j ].name; j++ ) {
1081 if ( strcmp( e, restrictable_exops[j].name ) == 0 )
1083 restrictops |= restrictable_exops[ j ].flag;
1088 if ( restrictable_exops[ j ].name == NULL ) {
1089 goto restrict_unknown;
1092 restrictops &= ~SLAP_RESTRICT_OP_EXTENDED;
1094 } else if ( e[0] == '\0' ) {
1095 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1096 restrictops |= SLAP_RESTRICT_OP_EXTENDED;
1099 goto restrict_unknown;
1102 } else if ( strcasecmp( cargv[ i ], "modify" ) == 0 ) {
1103 restrictops |= SLAP_RESTRICT_OP_MODIFY;
1105 } else if ( strcasecmp( cargv[ i ], "rename" ) == 0
1106 || strcasecmp( cargv[ i ], "modrdn" ) == 0 )
1108 restrictops |= SLAP_RESTRICT_OP_RENAME;
1110 } else if ( strcasecmp( cargv[ i ], "search" ) == 0 ) {
1111 restrictops |= SLAP_RESTRICT_OP_SEARCH;
1116 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1117 "unknown operation %s in \"allow <features>\" line\n",
1118 fname, lineno, cargv[i] );
1124 frontendDB->be_restrictops |= restrictops;
1126 be->be_restrictops |= restrictops;
1129 /* allow these features */
1130 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1131 strcasecmp( cargv[0], "allow" ) == 0 )
1133 slap_mask_t allows = 0;
1136 Debug( LDAP_DEBUG_ANY,
1137 "%s: line %d: allow line must appear prior to database definitions\n",
1143 Debug( LDAP_DEBUG_ANY,
1144 "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1150 for( i=1; i < cargc; i++ ) {
1151 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1152 allows |= SLAP_ALLOW_BIND_V2;
1154 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1155 allows |= SLAP_ALLOW_BIND_ANON_CRED;
1157 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1158 allows |= SLAP_ALLOW_BIND_ANON_DN;
1160 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1161 allows |= SLAP_ALLOW_UPDATE_ANON;
1164 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1165 "unknown feature %s in \"allow <features>\" line\n",
1166 fname, lineno, cargv[i] );
1172 SLAPD_GLOBAL(allows) |= allows;
1174 /* disallow these features */
1175 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1176 strcasecmp( cargv[0], "disallow" ) == 0 )
1178 slap_mask_t disallows = 0;
1181 Debug( LDAP_DEBUG_ANY,
1182 "%s: line %d: disallow line must appear prior to database definitions\n",
1188 Debug( LDAP_DEBUG_ANY,
1189 "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1195 for( i=1; i < cargc; i++ ) {
1196 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1197 disallows |= SLAP_DISALLOW_BIND_ANON;
1199 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1200 disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1202 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1203 disallows |= SLAP_DISALLOW_BIND_KRBV4;
1205 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1206 disallows |= SLAP_DISALLOW_TLS_2_ANON;
1208 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1209 disallows |= SLAP_DISALLOW_TLS_AUTHC;
1212 Debug( LDAP_DEBUG_ANY,
1213 "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1214 fname, lineno, cargv[i] );
1220 SLAPD_GLOBAL(disallows) |= disallows;
1222 /* require these features */
1223 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1224 strcasecmp( cargv[0], "require" ) == 0 )
1226 slap_mask_t requires = 0;
1229 Debug( LDAP_DEBUG_ANY,
1230 "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1236 for( i=1; i < cargc; i++ ) {
1237 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1238 requires |= SLAP_REQUIRE_BIND;
1240 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1241 requires |= SLAP_REQUIRE_LDAP_V3;
1243 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1244 requires |= SLAP_REQUIRE_AUTHC;
1246 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1247 requires |= SLAP_REQUIRE_SASL;
1249 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1250 requires |= SLAP_REQUIRE_STRONG;
1252 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1253 Debug( LDAP_DEBUG_ANY,
1254 "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1255 fname, lineno, cargv[i] );
1262 frontendDB->be_requires = requires;
1264 be->be_requires = requires;
1267 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1268 slap_ssf_set_t *set;
1271 Debug( LDAP_DEBUG_ANY,
1272 "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1279 set = &frontendDB->be_ssf_set;
1281 set = &be->be_ssf_set;
1284 for( i=1; i < cargc; i++ ) {
1288 if ( strncasecmp( cargv[i], "ssf=",
1289 STRLENOF("ssf=") ) == 0 )
1291 tgt = &set->sss_ssf;
1292 src = &cargv[i][STRLENOF("ssf=")];
1294 } else if ( strncasecmp( cargv[i], "transport=",
1295 STRLENOF("transport=") ) == 0 )
1297 tgt = &set->sss_transport;
1298 src = &cargv[i][STRLENOF("transport=")];
1300 } else if ( strncasecmp( cargv[i], "tls=",
1301 STRLENOF("tls=") ) == 0 )
1303 tgt = &set->sss_tls;
1304 src = &cargv[i][STRLENOF("tls=")];
1306 } else if ( strncasecmp( cargv[i], "sasl=",
1307 STRLENOF("sasl=") ) == 0 )
1309 tgt = &set->sss_sasl;
1310 src = &cargv[i][STRLENOF("sasl=")];
1312 } else if ( strncasecmp( cargv[i], "update_ssf=",
1313 STRLENOF("update_ssf=") ) == 0 )
1315 tgt = &set->sss_update_ssf;
1316 src = &cargv[i][STRLENOF("update_ssf=")];
1318 } else if ( strncasecmp( cargv[i], "update_transport=",
1319 STRLENOF("update_transport=") ) == 0 )
1321 tgt = &set->sss_update_transport;
1322 src = &cargv[i][STRLENOF("update_transport=")];
1324 } else if ( strncasecmp( cargv[i], "update_tls=",
1325 STRLENOF("update_tls=") ) == 0 )
1327 tgt = &set->sss_update_tls;
1328 src = &cargv[i][STRLENOF("update_tls=")];
1330 } else if ( strncasecmp( cargv[i], "update_sasl=",
1331 STRLENOF("update_sasl=") ) == 0 )
1333 tgt = &set->sss_update_sasl;
1334 src = &cargv[i][STRLENOF("update_sasl=")];
1336 } else if ( strncasecmp( cargv[i], "simple_bind=",
1337 STRLENOF("simple_bind=") ) == 0 )
1339 tgt = &set->sss_simple_bind;
1340 src = &cargv[i][STRLENOF("simple_bind=")];
1343 Debug( LDAP_DEBUG_ANY,
1344 "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1345 fname, lineno, cargv[i] );
1350 *tgt = strtol( src, &next, 10 );
1351 if ( next == NULL || next[0] != '\0' ) {
1352 Debug( LDAP_DEBUG_ANY,
1353 "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1354 fname, lineno, cargv[i] );
1360 /* where to send clients when we don't hold it */
1361 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1363 Debug( LDAP_DEBUG_ANY,
1364 "%s: line %d: missing URL in \"referral <URL>\" line\n",
1370 if( validate_global_referral( cargv[1] ) ) {
1371 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1372 "invalid URL (%s) in \"referral\" line.\n",
1373 fname, lineno, cargv[1] );
1377 vals[0].bv_val = cargv[1];
1378 vals[0].bv_len = strlen( vals[0].bv_val );
1379 if( value_add( &SLAPD_GLOBAL(default_referral), vals ) )
1382 /* start of a new database definition */
1383 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1386 Debug( LDAP_DEBUG_ANY,
1387 "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1391 level = strtol( cargv[2], &next, 10 );
1392 if ( next == NULL || next[0] != '\0' ){
1393 Debug( LDAP_DEBUG_ANY,
1394 "%s: line %d: unable to parse level \"%s\" in debug directive, "
1395 "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1399 if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1400 lutil_set_debug_level( cargv[1], level );
1401 /* specify an Object Identifier macro */
1402 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1403 rc = parse_oidm( fname, lineno, cargc, cargv );
1406 /* specify an objectclass */
1407 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1409 Debug( LDAP_DEBUG_ANY,
1410 "%s: line %d: illegal objectclass format.\n",
1414 } else if ( *cargv[1] == '(' /*')'*/) {
1416 p = strchr(saveline,'(' /*')'*/);
1417 rc = parse_oc( fname, lineno, p, cargv );
1421 Debug( LDAP_DEBUG_ANY,
1422 "%s: line %d: old objectclass format not supported.\n",
1426 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1428 p = strchr(saveline,'(' /*')'*/);
1429 rc = parse_cr( fname, lineno, p, cargv );
1432 /* specify an attribute type */
1433 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1434 || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1437 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1438 "illegal attribute type format.\n",
1442 } else if ( *cargv[1] == '(' /*')'*/) {
1444 p = strchr(saveline,'(' /*')'*/);
1445 rc = parse_at( fname, lineno, p, cargv );
1449 Debug( LDAP_DEBUG_ANY,
1450 "%s: line %d: old attribute type format not supported.\n",
1455 /* define attribute option(s) */
1456 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1457 ad_define_option( NULL, NULL, 0 );
1458 for ( i = 1; i < cargc; i++ )
1459 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1462 /* turn on/off schema checking */
1463 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1465 Debug( LDAP_DEBUG_ANY,
1466 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1471 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1472 Debug( LDAP_DEBUG_ANY,
1473 "%s: line %d: schema checking disabled! your mileage may vary!\n",
1475 SLAPD_GLOBAL(schemachecking) = 0;
1477 SLAPD_GLOBAL(schemachecking) = 1;
1480 /* specify access control info */
1481 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1482 parse_acl( be, fname, lineno, cargc, cargv );
1484 /* debug level to log things to ldap_syslog */
1485 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1487 Debug( LDAP_DEBUG_ANY,
1488 "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1496 for( i=1; i < cargc; i++ ) {
1499 if ( isdigit( cargv[i][0] ) ) {
1500 level = strtol( cargv[i], &next, 10 );
1501 if ( next == NULL || next[0] != '\0' ) {
1502 Debug( LDAP_DEBUG_ANY,
1503 "%s: line %d: unable to parse level \"%s\" "
1504 "in \"loglevel <level> [...]\" line.\n",
1505 fname, lineno , cargv[i] );
1514 { LDAP_DEBUG_TRACE, "Trace" },
1515 { LDAP_DEBUG_PACKETS, "Packets" },
1516 { LDAP_DEBUG_ARGS, "Args" },
1517 { LDAP_DEBUG_CONNS, "Conns" },
1518 { LDAP_DEBUG_BER, "BER" },
1519 { LDAP_DEBUG_FILTER, "Filter" },
1520 { LDAP_DEBUG_CONFIG, "Config" },
1521 { LDAP_DEBUG_ACL, "ACL" },
1522 { LDAP_DEBUG_STATS, "Stats" },
1523 { LDAP_DEBUG_STATS2, "Stats2" },
1524 { LDAP_DEBUG_SHELL, "Shell" },
1525 { LDAP_DEBUG_PARSE, "Parse" },
1526 { LDAP_DEBUG_CACHE, "Cache" },
1527 { LDAP_DEBUG_INDEX, "Index" },
1533 for ( j = 0; int_2_level[j].s; j++ ) {
1534 if ( strcasecmp( cargv[i], int_2_level[j].s ) == 0 ) {
1535 level = int_2_level[j].i;
1540 if ( int_2_level[j].s == NULL ) {
1541 Debug( LDAP_DEBUG_ANY,
1542 "%s: line %d: unknown level \"%s\" "
1543 "in \"loglevel <level> [...]\" line.\n",
1544 fname, lineno , cargv[i] );
1549 ldap_syslog |= level;
1552 /* list of sync replication information in this backend (slave only) */
1553 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1556 Debug( LDAP_DEBUG_ANY,
1557 "%s: line %d: syncrepl line must appear inside "
1558 "a database definition.\n", fname, lineno, 0);
1561 } else if ( SLAP_SHADOW( be )) {
1562 Debug( LDAP_DEBUG_ANY,
1563 "%s: line %d: syncrepl: database already shadowed.\n",
1567 } else if ( add_syncrepl( be, cargv, cargc )) {
1571 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1573 /* list of replicas of the data in this backend (master only) */
1574 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1576 Debug( LDAP_DEBUG_ANY,
1577 "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1583 Debug( LDAP_DEBUG_ANY,
1584 "%s: line %d: replica line must appear inside a database definition\n",
1591 for ( i = 1; i < cargc; i++ ) {
1592 if ( strncasecmp( cargv[i], "host=", 5 )
1594 nr = add_replica_info( be,
1597 } else if (strncasecmp( cargv[i], "uri=", 4 )
1599 if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1601 Debug( LDAP_DEBUG_ANY,
1602 "%s: line %d: replica line contains invalid "
1603 "uri definition.\n", fname, lineno, 0);
1606 if (ludp->lud_host == NULL ) {
1607 Debug( LDAP_DEBUG_ANY,
1608 "%s: line %d: replica line contains invalid "
1609 "uri definition - missing hostname.\n", fname, lineno, 0);
1612 replicahost = ch_malloc( strlen( cargv[ i ] ) );
1613 if ( replicahost == NULL ) {
1614 Debug( LDAP_DEBUG_ANY,
1615 "out of memory in read_config\n", 0, 0, 0 );
1616 ldap_free_urldesc( ludp );
1617 exit( EXIT_FAILURE );
1619 sprintf(replicahost, "%s:%d",
1620 ludp->lud_host, ludp->lud_port);
1621 nr = add_replica_info( be, replicahost );
1622 ldap_free_urldesc( ludp );
1623 ch_free(replicahost);
1628 Debug( LDAP_DEBUG_ANY,
1629 "%s: line %d: missing host or uri in \"replica\" line\n",
1633 } else if ( nr == -1 ) {
1634 Debug( LDAP_DEBUG_ANY,
1635 "%s: line %d: unable to add replica \"%s\"\n",
1636 fname, lineno, cargv[i] + 5 );
1639 for ( i = 1; i < cargc; i++ ) {
1640 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1642 switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1644 Debug( LDAP_DEBUG_ANY,
1645 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1646 fname, lineno, cargv[i] + 7 );
1650 Debug( LDAP_DEBUG_ANY,
1651 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1656 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1658 char *arg = cargv[i] + 4;
1660 if ( arg[0] == '!' ) {
1665 if ( arg[0] != '=' ) {
1669 if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1670 Debug( LDAP_DEBUG_ANY,
1671 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1672 fname, lineno, arg + 1 );
1680 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
1683 /* dn of slave entity allowed to write to replica */
1684 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1686 Debug( LDAP_DEBUG_ANY,
1687 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1693 Debug( LDAP_DEBUG_ANY,
1694 "%s: line %d: updatedn line must appear inside a database definition\n",
1698 } else if ( SLAP_SHADOW(be) ) {
1699 Debug( LDAP_DEBUG_ANY,
1700 "%s: line %d: updatedn: database already shadowed.\n",
1707 if ( load_ucdata( NULL ) < 0 ) return 1;
1709 dn.bv_val = cargv[1];
1710 dn.bv_len = strlen( cargv[1] );
1712 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1713 if( rc != LDAP_SUCCESS ) {
1714 Debug( LDAP_DEBUG_ANY,
1715 "%s: line %d: updatedn DN is invalid\n",
1721 SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
1723 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1725 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1726 "missing url in \"updateref <ldapurl>\" line\n",
1732 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1733 " line must appear inside a database definition\n",
1737 } else if ( !SLAP_SHADOW(be) ) {
1738 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1739 "updateref line must after syncrepl or updatedn.\n",
1744 if( validate_global_referral( cargv[1] ) ) {
1745 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1746 "invalid URL (%s) in \"updateref\" line.\n",
1747 fname, lineno, cargv[1] );
1751 vals[0].bv_val = cargv[1];
1752 vals[0].bv_len = strlen( vals[0].bv_val );
1753 if( value_add( &be->be_update_refs, vals ) ) {
1757 /* replication log file to which changes are appended */
1758 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1760 Debug( LDAP_DEBUG_ANY,
1761 "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1767 be->be_replogfile = ch_strdup( cargv[1] );
1769 frontendDB->be_replogfile = ch_strdup( cargv[1] );
1772 /* file from which to read additional rootdse attrs */
1773 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
1775 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1776 "missing filename in \"rootDSE <filename>\" line.\n",
1781 if( read_root_dse_file( cargv[1] ) ) {
1782 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1783 "could not read \"rootDSE <filename>\" line\n",
1788 /* maintain lastmodified{by,time} attributes */
1789 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1791 Debug( LDAP_DEBUG_ANY,
1792 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1799 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1800 " line must appear inside a database definition\n",
1804 } else if ( SLAP_NOLASTMODCMD(be) ) {
1805 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
1806 " not available for %s databases\n",
1807 fname, lineno, be->bd_info->bi_type );
1811 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1812 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
1814 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1818 /* turn on/off gentle SIGHUP handling */
1819 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
1821 Debug( LDAP_DEBUG_ANY,
1822 "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
1826 if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1827 SLAPD_GLOBAL(gentlehup) = 0;
1829 SLAPD_GLOBAL(gentlehup) = 1;
1833 /* set idle timeout value */
1834 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1837 Debug( LDAP_DEBUG_ANY,
1838 "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1844 i = atoi( cargv[1] );
1847 Debug( LDAP_DEBUG_ANY,
1848 "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1854 SLAPD_GLOBAL(idletimeout) = i;
1856 /* include another config file */
1857 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1859 Debug( LDAP_DEBUG_ANY,
1860 "%s: line %d: missing filename in \"include <filename>\" line\n",
1865 savefname = ch_strdup( cargv[1] );
1866 savelineno = lineno;
1868 if ( read_config( savefname, depth+1 ) != 0 ) {
1873 lineno = savelineno - 1;
1875 /* location of kerberos srvtab file */
1876 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1878 Debug( LDAP_DEBUG_ANY,
1879 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1884 SLAPD_GLOBAL(ldap_srvtab) = ch_strdup( cargv[1] );
1886 #ifdef SLAPD_MODULES
1887 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1889 Debug( LDAP_DEBUG_ANY,
1890 "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1893 exit( EXIT_FAILURE );
1895 if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1896 Debug( LDAP_DEBUG_ANY,
1897 "%s: line %d: failed to load or initialize module %s\n",
1898 fname, lineno, cargv[1]);
1900 exit( EXIT_FAILURE );
1902 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1904 Debug( LDAP_DEBUG_ANY,
1905 "%s: line %d: missing path in \"modulepath <path>\" line\n",
1908 exit( EXIT_FAILURE );
1910 if (module_path( cargv[1] )) {
1911 Debug( LDAP_DEBUG_ANY,
1912 "%s: line %d: failed to set module search path to %s\n",
1913 fname, lineno, cargv[1]);
1915 exit( EXIT_FAILURE );
1918 #endif /*SLAPD_MODULES*/
1921 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
1922 rc = ldap_pvt_tls_set_option( NULL,
1923 LDAP_OPT_X_TLS_RANDOM_FILE,
1928 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1929 rc = ldap_pvt_tls_set_option( NULL,
1930 LDAP_OPT_X_TLS_CIPHER_SUITE,
1935 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1936 rc = ldap_pvt_tls_set_option( NULL,
1937 LDAP_OPT_X_TLS_CERTFILE,
1942 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1943 rc = ldap_pvt_tls_set_option( NULL,
1944 LDAP_OPT_X_TLS_KEYFILE,
1949 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1950 rc = ldap_pvt_tls_set_option( NULL,
1951 LDAP_OPT_X_TLS_CACERTDIR,
1956 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1957 rc = ldap_pvt_tls_set_option( NULL,
1958 LDAP_OPT_X_TLS_CACERTFILE,
1962 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1963 if ( isdigit( (unsigned char) cargv[1][0] ) ) {
1965 rc = ldap_pvt_tls_set_option( NULL,
1966 LDAP_OPT_X_TLS_REQUIRE_CERT,
1969 rc = ldap_int_tls_config( NULL,
1970 LDAP_OPT_X_TLS_REQUIRE_CERT,
1979 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
1980 #ifdef SLAPD_RLOOKUPS
1982 Debug( LDAP_DEBUG_ANY,
1983 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
1988 if ( !strcasecmp( cargv[1], "on" ) ) {
1989 SLAPD_GLOBAL(use_reverse_lookup) = 1;
1990 } else if ( !strcasecmp( cargv[1], "off" ) ) {
1991 SLAPD_GLOBAL(use_reverse_lookup) = 0;
1993 Debug( LDAP_DEBUG_ANY,
1994 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
1999 #else /* !SLAPD_RLOOKUPS */
2000 Debug( LDAP_DEBUG_ANY,
2001 "%s: line %d: reverse lookups are not configured (ignored).\n",
2003 #endif /* !SLAPD_RLOOKUPS */
2005 /* Netscape plugins */
2006 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2007 #if defined( LDAP_SLAPI )
2009 #ifdef notdef /* allow global plugins, too */
2011 * a "plugin" line must be inside a database
2012 * definition, since we implement pre-,post-
2013 * and extended operation plugins
2016 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2017 "line must appear inside a database "
2018 "definition\n", fname, lineno, 0 );
2023 if ( slapi_int_read_config( be, fname, lineno, cargc, cargv )
2026 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2027 "config read failed.\n", fname, lineno, 0 );
2030 SLAPD_GLOBAL(slapi_plugins_used)++;
2032 #else /* !defined( LDAP_SLAPI ) */
2033 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2034 "not supported.\n", fname, lineno, 0 );
2037 #endif /* !defined( LDAP_SLAPI ) */
2039 /* Netscape plugins */
2040 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2041 #if defined( LDAP_SLAPI )
2043 Debug( LDAP_DEBUG_ANY,
2044 "%s: line %d: missing file name "
2045 "in pluginlog <filename> line.\n",
2050 if ( slapi_log_file != NULL ) {
2051 ch_free( slapi_log_file );
2054 slapi_log_file = ch_strdup( cargv[1] );
2055 #endif /* !defined( LDAP_SLAPI ) */
2057 /* pass anything else to the current backend info/db config routine */
2060 if ( bi->bi_config ) {
2061 rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2067 case SLAP_CONF_UNKNOWN:
2068 Debug( LDAP_DEBUG_ANY,
2069 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2070 fname, lineno, cargv[0] );
2078 } else if ( be != NULL ) {
2079 if ( be->be_config ) {
2080 rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2086 case SLAP_CONF_UNKNOWN:
2087 Debug( LDAP_DEBUG_ANY,
2088 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2089 fname, lineno, cargv[0] );
2098 if ( frontendDB->be_config ) {
2099 rc = (*frontendDB->be_config)( frontendDB, fname, lineno, cargc, cargv );
2105 case SLAP_CONF_UNKNOWN:
2106 Debug( LDAP_DEBUG_ANY,
2107 "%s: line %d: unknown directive \"%s\" inside global database definition (ignored)\n",
2108 fname, lineno, cargv[0] );
2121 if ( depth == 0 ) ch_free( cargv );
2123 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2124 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2125 &frontendDB->be_schemadn );
2126 dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2129 if ( load_ucdata( NULL ) < 0 ) return 1;
2141 char logbuf[sizeof("pseudorootpw ***")];
2144 token = strtok_quote( line, " \t" );
2148 if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2149 strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
2150 strcasecmp( token, "bindpw" ) == 0 || /* used in back-ldap */
2151 strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
2152 strcasecmp( token, "dbpasswd" ) == 0 ) ) /* used in back-sql */
2154 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2157 if ( strtok_quote_ptr ) {
2158 *strtok_quote_ptr = ' ';
2161 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2163 if ( strtok_quote_ptr ) {
2164 *strtok_quote_ptr = '\0';
2167 for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2168 if ( cargc == cargv_size - 1 ) {
2170 tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2172 if ( tmp == NULL ) {
2173 Debug( LDAP_DEBUG_ANY,
2174 "line %d: out of memory\n",
2179 cargv_size += ARGS_STEP;
2181 cargv[cargc++] = token;
2183 cargv[cargc] = NULL;
2188 strtok_quote( char *line, char *sep )
2194 strtok_quote_ptr = NULL;
2195 if ( line != NULL ) {
2198 while ( *next && strchr( sep, *next ) ) {
2202 if ( *next == '\0' ) {
2208 for ( inquote = 0; *next; ) {
2216 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2222 next + 1, strlen( next + 1 ) + 1 );
2223 next++; /* dont parse the escaped character */
2228 if ( strchr( sep, *next ) != NULL ) {
2229 strtok_quote_ptr = next;
2242 static char buf[BUFSIZ];
2244 static size_t lmax, lcur;
2246 #define CATLINE( buf ) \
2248 size_t len = strlen( buf ); \
2249 while ( lcur + len + 1 > lmax ) { \
2251 line = (char *) ch_realloc( line, lmax ); \
2253 strcpy( line + lcur, buf ); \
2258 fp_getline( FILE *fp, int *lineno )
2266 /* hack attack - keeps us from having to keep a stack of bufs... */
2267 if ( strncasecmp( line, "include", 7 ) == 0 ) {
2272 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2273 /* trim off \r\n or \n */
2274 if ( (p = strchr( buf, '\n' )) != NULL ) {
2275 if( p > buf && p[-1] == '\r' ) --p;
2279 /* trim off trailing \ and append the next line */
2280 if ( line[ 0 ] != '\0'
2281 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2282 && p[ -1 ] != '\\' ) {
2287 if ( ! isspace( (unsigned char) buf[0] ) ) {
2291 /* change leading whitespace to a space */
2300 return( line[0] ? line : NULL );
2304 fp_getline_init( int *lineno )
2310 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2312 load_ucdata( char *path )
2315 static int loaded = 0;
2321 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2323 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2331 /* ucdata is now hardcoded */
2339 ucdata_unload( UCDATA_ALL );
2341 /* NOTE: in case of early exit, frontendDB can be NULL */
2342 if ( frontendDB->be_schemandn.bv_val )
2343 free( frontendDB->be_schemandn.bv_val );
2344 if ( frontendDB->be_schemadn.bv_val )
2345 free( frontendDB->be_schemadn.bv_val );
2346 if ( frontendDB->be_acl )
2347 acl_destroy( frontendDB->be_acl, NULL );
2348 /* globals are part of frontendDB */
2349 if ( SLAPD_GLOBAL(args_file) )
2350 free ( SLAPD_GLOBAL(args_file) );
2351 if ( SLAPD_GLOBAL(pid_file) )
2352 free ( SLAPD_GLOBAL(pid_file) );
2353 if ( SLAPD_GLOBAL(default_passwd_hash) )
2354 ldap_charray_free( SLAPD_GLOBAL(default_passwd_hash) );
2367 syncinfo_t *si_entry;
2369 int duplicated_replica_id = 0;
2371 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2374 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2378 si->si_tls = SYNCINFO_TLS_OFF;
2379 if ( be->be_rootndn.bv_val ) {
2380 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2382 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2383 si->si_schemachecking = 0;
2384 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2385 &si->si_filterstr );
2386 si->si_base.bv_val = NULL;
2387 si->si_scope = LDAP_SCOPE_SUBTREE;
2388 si->si_attrsonly = 0;
2389 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2390 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2391 si->si_attrs = NULL;
2392 si->si_allattrs = 0;
2393 si->si_allopattrs = 0;
2394 si->si_exattrs = NULL;
2395 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2396 si->si_interval = 86400;
2397 si->si_retryinterval = NULL;
2398 si->si_retrynum_init = NULL;
2399 si->si_retrynum = NULL;
2400 si->si_syncCookie.ctxcsn = NULL;
2401 si->si_syncCookie.octet_str = NULL;
2402 si->si_syncCookie.sid = -1;
2403 si->si_manageDSAit = 0;
2406 si->si_syncUUID_ndn.bv_val = NULL;
2407 si->si_syncUUID_ndn.bv_len = 0;
2409 si->si_presentlist = NULL;
2410 LDAP_LIST_INIT( &si->si_nonpresentlist );
2412 rc = parse_syncrepl_line( cargv, cargc, si );
2414 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2415 if ( si->si_rid == si_entry->si_rid ) {
2416 Debug( LDAP_DEBUG_ANY,
2417 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2418 duplicated_replica_id = 1;
2423 if ( rc < 0 || duplicated_replica_id ) {
2424 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2425 syncinfo_free( si );
2428 Debug( LDAP_DEBUG_CONFIG,
2429 "Config: ** successfully added syncrepl \"%s\"\n",
2430 si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2431 if ( !si->si_schemachecking ) {
2432 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2435 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2440 /* NOTE: used & documented in slapd.conf(5) */
2442 #define PROVIDERSTR "provider"
2443 #define TYPESTR "type"
2444 #define INTERVALSTR "interval"
2445 #define SEARCHBASESTR "searchbase"
2446 #define FILTERSTR "filter"
2447 #define SCOPESTR "scope"
2448 #define ATTRSSTR "attrs"
2449 #define ATTRSONLYSTR "attrsonly"
2450 #define SLIMITSTR "sizelimit"
2451 #define TLIMITSTR "timelimit"
2452 #define SCHEMASTR "schemachecking"
2453 #define UPDATEDNSTR "updatedn"
2454 #define BINDMETHSTR "bindmethod"
2455 #define SIMPLESTR "simple"
2456 #define SASLSTR "sasl"
2457 #define BINDDNSTR "binddn"
2458 #define SASLMECHSTR "saslmech"
2459 #define AUTHCSTR "authcID"
2460 #define AUTHZSTR "authzID"
2461 #define CREDSTR "credentials"
2462 #define REALMSTR "realm"
2463 #define SECPROPSSTR "secprops"
2465 /* FIXME: undocumented */
2466 #define OLDAUTHCSTR "bindprincipal"
2467 #define STARTTLSSTR "starttls"
2468 #define CRITICALSTR "critical"
2469 #define EXATTRSSTR "exattrs"
2470 #define MANAGEDSAITSTR "manageDSAit"
2471 #define RETRYSTR "retry"
2474 #define LASTMODSTR "lastmod"
2475 #define LMGENSTR "gen"
2476 #define LMNOSTR "no"
2477 #define LMREQSTR "req"
2478 #define SRVTABSTR "srvtab"
2479 #define SUFFIXSTR "suffix"
2482 #define GOT_ID 0x0001
2483 #define GOT_PROVIDER 0x0002
2484 #define GOT_METHOD 0x0004
2487 #define GOT_ALL (GOT_ID|GOT_PROVIDER|GOT_METHOD)
2490 parse_syncrepl_line(
2501 for ( i = 1; i < cargc; i++ ) {
2502 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2503 STRLENOF( IDSTR "=" ) ) )
2506 /* '\0' string terminator accounts for '=' */
2507 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2509 if ( tmp >= 1000 || tmp < 0 ) {
2510 fprintf( stderr, "Error: parse_syncrepl_line: "
2511 "syncrepl id %d is out of range [0..999]\n", tmp );
2516 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2517 STRLENOF( PROVIDERSTR "=" ) ) )
2519 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2520 si->si_provideruri = ch_strdup( val );
2521 si->si_provideruri_bv = (BerVarray)
2522 ch_calloc( 2, sizeof( struct berval ));
2523 ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2524 1, &si->si_provideruri_bv[0] );
2525 si->si_provideruri_bv[1].bv_len = 0;
2526 si->si_provideruri_bv[1].bv_val = NULL;
2527 gots |= GOT_PROVIDER;
2528 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR "=",
2529 STRLENOF(STARTTLSSTR "=") ) )
2531 val = cargv[ i ] + STRLENOF( STARTTLSSTR "=" );
2532 if( !strcasecmp( val, CRITICALSTR ) ) {
2533 si->si_tls = SYNCINFO_TLS_CRITICAL;
2535 si->si_tls = SYNCINFO_TLS_ON;
2537 } else if ( !strncasecmp( cargv[ i ], UPDATEDNSTR "=",
2538 STRLENOF( UPDATEDNSTR "=" ) ) )
2540 struct berval updatedn = BER_BVNULL;
2542 val = cargv[ i ] + STRLENOF( UPDATEDNSTR "=" );
2543 ber_str2bv( val, 0, 0, &updatedn );
2544 ch_free( si->si_updatedn.bv_val );
2545 dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
2546 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR "=",
2547 STRLENOF( BINDMETHSTR "=" ) ) )
2549 val = cargv[ i ] + STRLENOF( BINDMETHSTR "=" );
2550 if ( !strcasecmp( val, SIMPLESTR )) {
2551 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2553 } else if ( !strcasecmp( val, SASLSTR )) {
2554 #ifdef HAVE_CYRUS_SASL
2555 si->si_bindmethod = LDAP_AUTH_SASL;
2557 #else /* HAVE_CYRUS_SASL */
2558 fprintf( stderr, "Error: parse_syncrepl_line: "
2559 "not compiled with SASL support\n" );
2561 #endif /* HAVE_CYRUS_SASL */
2563 si->si_bindmethod = -1;
2565 } else if ( !strncasecmp( cargv[ i ], BINDDNSTR "=",
2566 STRLENOF( BINDDNSTR "=" ) ) )
2568 val = cargv[ i ] + STRLENOF( BINDDNSTR "=" );
2569 si->si_binddn = ch_strdup( val );
2570 } else if ( !strncasecmp( cargv[ i ], CREDSTR "=",
2571 STRLENOF( CREDSTR "=" ) ) )
2573 val = cargv[ i ] + STRLENOF( CREDSTR "=" );
2574 si->si_passwd = ch_strdup( val );
2575 } else if ( !strncasecmp( cargv[ i ], SASLMECHSTR "=",
2576 STRLENOF( SASLMECHSTR "=" ) ) )
2578 val = cargv[ i ] + STRLENOF( SASLMECHSTR "=" );
2579 si->si_saslmech = ch_strdup( val );
2580 } else if ( !strncasecmp( cargv[ i ], SECPROPSSTR "=",
2581 STRLENOF( SECPROPSSTR "=" ) ) )
2583 val = cargv[ i ] + STRLENOF( SECPROPSSTR "=" );
2584 si->si_secprops = ch_strdup( val );
2585 } else if ( !strncasecmp( cargv[ i ], REALMSTR "=",
2586 STRLENOF( REALMSTR "=" ) ) )
2588 val = cargv[ i ] + STRLENOF( REALMSTR "=" );
2589 si->si_realm = ch_strdup( val );
2590 } else if ( !strncasecmp( cargv[ i ], AUTHCSTR "=",
2591 STRLENOF( AUTHCSTR "=" ) ) )
2593 val = cargv[ i ] + STRLENOF( AUTHCSTR "=" );
2594 if ( si->si_authcId )
2595 ch_free( si->si_authcId );
2596 si->si_authcId = ch_strdup( val );
2597 } else if ( !strncasecmp( cargv[ i ], OLDAUTHCSTR "=",
2598 STRLENOF( OLDAUTHCSTR "=" ) ) )
2600 /* Old authcID is provided for some backwards compatibility */
2601 val = cargv[ i ] + STRLENOF( OLDAUTHCSTR "=" );
2602 if ( si->si_authcId )
2603 ch_free( si->si_authcId );
2604 si->si_authcId = ch_strdup( val );
2605 } else if ( !strncasecmp( cargv[ i ], AUTHZSTR "=",
2606 STRLENOF( AUTHZSTR "=" ) ) )
2608 val = cargv[ i ] + STRLENOF( AUTHZSTR "=" );
2609 si->si_authzId = ch_strdup( val );
2610 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2611 STRLENOF( SCHEMASTR "=" ) ) )
2613 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2614 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2615 si->si_schemachecking = 1;
2616 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2617 si->si_schemachecking = 0;
2619 si->si_schemachecking = 1;
2621 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2622 STRLENOF( FILTERSTR "=" ) ) )
2624 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2625 ber_str2bv( val, 0, 1, &si->si_filterstr );
2626 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2627 STRLENOF( SEARCHBASESTR "=" ) ) )
2630 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2631 if ( si->si_base.bv_val ) {
2632 ch_free( si->si_base.bv_val );
2634 ber_str2bv( val, 0, 0, &bv );
2635 if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
2636 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
2639 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2640 STRLENOF( SCOPESTR "=" ) ) )
2642 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2643 if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
2644 si->si_scope = LDAP_SCOPE_BASE;
2645 } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
2646 si->si_scope = LDAP_SCOPE_ONELEVEL;
2647 #ifdef LDAP_SCOPE_SUBORDINATE
2648 } else if ( !strcasecmp( val, "subordinate" ) ||
2649 !strcasecmp( val, "children" ))
2651 si->si_scope = LDAP_SCOPE_SUBORDINATE;
2653 } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
2654 si->si_scope = LDAP_SCOPE_SUBTREE;
2656 fprintf( stderr, "Error: parse_syncrepl_line: "
2657 "unknown scope \"%s\"\n", val);
2660 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2661 STRLENOF( ATTRSONLYSTR "=" ) ) )
2663 si->si_attrsonly = 1;
2664 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2665 STRLENOF( ATTRSSTR "=" ) ) )
2667 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2668 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2670 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2671 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2672 if ( si->si_anlist == NULL ) {
2673 ch_free( attr_fname );
2676 ch_free( attr_fname );
2678 char *str, *s, *next;
2679 char delimstr[] = " ,\t";
2680 str = ch_strdup( val );
2681 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2683 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2685 if ( strlen(s) == 1 && *s == '*' ) {
2686 si->si_allattrs = 1;
2687 *(val + ( s - str )) = delimstr[0];
2689 if ( strlen(s) == 1 && *s == '+' ) {
2690 si->si_allopattrs = 1;
2691 *(val + ( s - str )) = delimstr[0];
2695 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2696 if ( si->si_anlist == NULL ) {
2700 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2701 STRLENOF( EXATTRSSTR "=" ) ) )
2703 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2704 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2706 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2707 si->si_exanlist = file2anlist(
2708 si->si_exanlist, attr_fname, " ,\t" );
2709 if ( si->si_exanlist == NULL ) {
2710 ch_free( attr_fname );
2713 ch_free( attr_fname );
2716 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2717 if ( si->si_exanlist == NULL ) {
2721 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2722 STRLENOF( TYPESTR "=" ) ) )
2724 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2725 if ( !strncasecmp( val, "refreshOnly",
2726 STRLENOF("refreshOnly") ))
2728 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2729 } else if ( !strncasecmp( val, "refreshAndPersist",
2730 STRLENOF("refreshAndPersist") ))
2732 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2733 si->si_interval = 60;
2735 fprintf( stderr, "Error: parse_syncrepl_line: "
2736 "unknown sync type \"%s\"\n", val);
2739 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2740 STRLENOF( INTERVALSTR "=" ) ) )
2742 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2743 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2744 si->si_interval = 0;
2752 hstr = strchr( dstr, ':' );
2753 if ( hstr == NULL ) {
2754 fprintf( stderr, "Error: parse_syncrepl_line: "
2755 "invalid interval \"%s\"\n", val );
2759 mstr = strchr( hstr, ':' );
2760 if ( mstr == NULL ) {
2761 fprintf( stderr, "Error: parse_syncrepl_line: "
2762 "invalid interval \"%s\"\n", val );
2766 sstr = strchr( mstr, ':' );
2767 if ( sstr == NULL ) {
2768 fprintf( stderr, "Error: parse_syncrepl_line: "
2769 "invalid interval \"%s\"\n", val );
2778 if (( hh > 24 ) || ( hh < 0 ) ||
2779 ( mm > 60 ) || ( mm < 0 ) ||
2780 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2781 fprintf( stderr, "Error: parse_syncrepl_line: "
2782 "invalid interval \"%s\"\n", val );
2785 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2787 if ( si->si_interval < 0 ) {
2788 fprintf( stderr, "Error: parse_syncrepl_line: "
2789 "invalid interval \"%ld\"\n",
2790 (long) si->si_interval);
2793 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2794 STRLENOF( RETRYSTR "=" ) ) )
2800 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2801 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2802 retry_list[0] = NULL;
2804 slap_str2clist( &retry_list, val, " ,\t" );
2806 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2810 "Error: incomplete syncrepl retry list\n" );
2811 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2812 ch_free( retry_list[k] );
2814 ch_free( retry_list );
2815 exit( EXIT_FAILURE );
2817 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2818 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2819 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2820 for ( j = 0; j < n; j++ ) {
2821 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2822 if ( *retry_list[j*2+1] == '+' ) {
2823 si->si_retrynum_init[j] = -1;
2824 si->si_retrynum[j] = -1;
2828 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2829 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2832 si->si_retrynum_init[j] = -2;
2833 si->si_retrynum[j] = -2;
2834 si->si_retryinterval[j] = 0;
2836 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2837 ch_free( retry_list[k] );
2839 ch_free( retry_list );
2840 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2841 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2843 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2844 si->si_manageDSAit = atoi( val );
2845 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2846 STRLENOF( SLIMITSTR "=") ) )
2848 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2849 si->si_slimit = atoi( val );
2850 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2851 STRLENOF( TLIMITSTR "=" ) ) )
2853 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2854 si->si_tlimit = atoi( val );
2856 fprintf( stderr, "Error: parse_syncrepl_line: "
2857 "unknown keyword \"%s\"\n", cargv[ i ] );
2861 if ( gots != GOT_ALL ) {
2863 "Error: Malformed \"syncrepl\" line in slapd config file" );
2871 slap_str2clist( char ***out, char *in, const char *brkstr )
2880 /* find last element in list */
2881 for (i = 0; *out && (*out)[i]; i++);
2883 /* protect the input string from strtok */
2884 str = ch_strdup( in );
2886 if ( *str == '\0' ) {
2891 /* Count words in string */
2893 for ( s = str; *s; s++ ) {
2894 if ( strchr( brkstr, *s ) != NULL ) {
2899 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
2901 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
2903 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
2905 *new = ch_strdup( s );