1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 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>.
21 #include <ac/string.h>
32 # define SLAP_BDB_ALLOW_DIRTY_READ
35 #define bdb_cf_gen BDB_SYMBOL(cf_gen)
36 #define bdb_cf_cleanup BDB_SYMBOL(cf_cleanup)
37 #define bdb_checkpoint BDB_SYMBOL(checkpoint)
38 #define bdb_online_index BDB_SYMBOL(online_index)
40 static ConfigDriver bdb_cf_gen;
58 static ConfigTable bdbcfg[] = {
59 { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
60 bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
61 "DESC 'Directory for database content' "
62 "EQUALITY caseIgnoreMatch "
63 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
64 { "cachefree", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
65 (void *)offsetof(struct bdb_info, bi_cache.c_minfree),
66 "( OLcfgDbAt:1.11 NAME 'olcDbCacheFree' "
67 "DESC 'Number of extra entries to free when max is reached' "
68 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
69 { "cachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
70 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
71 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
72 "DESC 'Entry cache size in entries' "
73 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
74 { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
75 bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
76 "DESC 'Database checkpoint interval in kbytes and minutes' "
77 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
78 { "checksum", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_CHECKSUM,
79 bdb_cf_gen, "( OLcfgDbAt:1.16 NAME 'olcDbChecksum' "
80 "DESC 'Enable database checksum validation' "
81 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
82 { "cryptfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_CRYPTFILE,
83 bdb_cf_gen, "( OLcfgDbAt:1.13 NAME 'olcDbCryptFile' "
84 "DESC 'Pathname of file containing the DB encryption key' "
85 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
86 { "cryptkey", "key", 2, 2, 0, ARG_BERVAL|ARG_MAGIC|BDB_CRYPTKEY,
87 bdb_cf_gen, "( OLcfgDbAt:1.14 NAME 'olcDbCryptKey' "
88 "DESC 'DB encryption key' "
89 "SYNTAX OMsOctetString SINGLE-VALUE )",NULL, NULL },
90 { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
91 bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
92 "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
93 "SYNTAX OMsIA5String X-ORDERED 'VALUES' )", NULL, NULL },
94 { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
95 bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
96 "DESC 'Disable synchronous database writes' "
97 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
98 { "dbpagesize", "db> <size", 3, 3, 0, ARG_MAGIC|BDB_PGSIZE,
99 bdb_cf_gen, "( OLcfgDbAt:1.15 NAME 'olcDbPageSize' "
100 "DESC 'Page size of specified DB, in Kbytes' "
101 "EQUALITY caseExactMatch "
102 "SYNTAX OMsDirectoryString )", NULL, NULL },
103 { "dirtyread", NULL, 1, 2, 0,
104 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
105 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
109 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
110 "DESC 'Allow reads of uncommitted data' "
111 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
112 { "dncachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
113 (void *)offsetof(struct bdb_info, bi_cache.c_eimax),
114 "( OLcfgDbAt:1.12 NAME 'olcDbDNcacheSize' "
115 "DESC 'DN cache size' "
116 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
117 { "idlcachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
118 (void *)offsetof(struct bdb_info, bi_idl_cache_max_size),
119 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
120 "DESC 'IDL cache size in IDLs' "
121 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
122 { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
123 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
124 "DESC 'Attribute index parameters' "
125 "EQUALITY caseIgnoreMatch "
126 "SYNTAX OMsDirectoryString )", NULL, NULL },
127 { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
128 (void *)offsetof(struct bdb_info, bi_linear_index),
129 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
130 "DESC 'Index attributes one at a time' "
131 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
132 { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
133 bdb_cf_gen, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
134 "DESC 'Deadlock detection algorithm' "
135 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
136 { "mode", "mode", 2, 2, 0, ARG_MAGIC|BDB_MODE,
137 bdb_cf_gen, "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
138 "DESC 'Unix permissions of database files' "
139 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
140 { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
141 bdb_cf_gen, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
142 "DESC 'Depth of search stack in IDLs' "
143 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
144 { "shm_key", "key", 2, 2, 0, ARG_LONG|ARG_OFFSET,
145 (void *)offsetof(struct bdb_info, bi_shm_key),
146 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
147 "DESC 'Key for shared memory region' "
148 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
149 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
150 NULL, NULL, NULL, NULL }
153 static ConfigOCs bdbocs[] = {
157 "NAME 'olcHdbConfig' "
158 "DESC 'HDB backend configuration' "
161 "NAME 'olcBdbConfig' "
162 "DESC 'BDB backend configuration' "
164 "SUP olcDatabaseConfig "
165 "MUST olcDbDirectory "
166 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
167 "olcDbCryptFile $ olcDbCryptKey $ "
168 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
169 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
170 "olcDbMode $ olcDbSearchStack $ olcDbShmKey $ "
171 "olcDbCacheFree $ olcDbDNcacheSize $ olcDbPageSize ) )",
172 Cft_Database, bdbcfg },
176 static slap_verbmasks bdb_lockd[] = {
177 { BER_BVC("default"), DB_LOCK_DEFAULT },
178 { BER_BVC("oldest"), DB_LOCK_OLDEST },
179 { BER_BVC("random"), DB_LOCK_RANDOM },
180 { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
181 { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
185 /* perform periodic checkpoints */
187 bdb_checkpoint( void *ctx, void *arg )
189 struct re_s *rtask = arg;
190 struct bdb_info *bdb = rtask->arg;
192 TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
193 bdb->bi_txn_cp_min, 0 );
194 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
195 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
196 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
200 /* reindex entries on the fly */
202 bdb_online_index( void *ctx, void *arg )
204 struct re_s *rtask = arg;
205 BackendDB *be = rtask->arg;
206 struct bdb_info *bdb = be->be_private;
208 Connection conn = {0};
209 OperationBuffer opbuf;
221 connection_fake_init( &conn, &opbuf, ctx );
231 key.size = key.ulen = sizeof(ID);
232 key.flags = DB_DBT_USERMEM;
234 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
235 data.dlen = data.ulen = 0;
238 if ( slapd_shutdown )
241 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &txn, bdb->bi_db_opflags );
246 BDB_ID2DISK( id, &nid );
247 rc = bdb->bi_id2entry->bdi_db->cursor(
248 bdb->bi_id2entry->bdi_db, txn, &curs, bdb->bi_db_opflags );
253 rc = curs->c_get( curs, &key, &data, DB_SET_RANGE );
254 curs->c_close( curs );
257 if ( rc == DB_NOTFOUND )
259 if ( rc == DB_LOCK_DEADLOCK ) {
260 ldap_pvt_thread_yield();
265 BDB_DISK2ID( &nid, &id );
269 rc = bdb_cache_find_id( op, txn, id, &ei, 0, &lock );
272 if ( rc == DB_LOCK_DEADLOCK ) {
273 ldap_pvt_thread_yield();
276 if ( rc == DB_NOTFOUND ) {
284 rc = bdb_index_entry( op, txn, BDB_INDEX_UPDATE_OP, ei->bei_e );
285 if ( rc == DB_LOCK_DEADLOCK ) {
287 ldap_pvt_thread_yield();
291 rc = TXN_COMMIT( txn, 0 );
301 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
302 if ( bdb->bi_attrs[ i ]->ai_indexmask & BDB_INDEX_DELETING
303 || bdb->bi_attrs[ i ]->ai_newmask == 0 )
307 bdb->bi_attrs[ i ]->ai_indexmask = bdb->bi_attrs[ i ]->ai_newmask;
308 bdb->bi_attrs[ i ]->ai_newmask = 0;
311 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
312 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
313 bdb->bi_index_task = NULL;
314 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
315 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
320 /* Cleanup loose ends after Modify completes */
322 bdb_cf_cleanup( ConfigArgs *c )
324 struct bdb_info *bdb = c->be->be_private;
327 if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
328 if ( bdb->bi_db_config ) {
330 FILE *f = fopen( bdb->bi_db_config_path, "w" );
332 for (i=0; bdb->bi_db_config[i].bv_val; i++)
333 fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
337 unlink( bdb->bi_db_config_path );
339 bdb->bi_flags ^= BDB_UPD_CONFIG;
342 if ( bdb->bi_flags & BDB_DEL_INDEX ) {
343 bdb_attr_flush( bdb );
344 bdb->bi_flags ^= BDB_DEL_INDEX;
347 if ( bdb->bi_flags & BDB_RE_OPEN ) {
348 bdb->bi_flags ^= BDB_RE_OPEN;
349 rc = c->be->bd_info->bi_db_close( c->be, &c->reply );
351 rc = c->be->bd_info->bi_db_open( c->be, &c->reply );
352 /* If this fails, we need to restart */
355 snprintf( c->cr_msg, sizeof( c->cr_msg ),
356 "failed to reopen database, rc=%d", rc );
357 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
358 ": %s\n", c->cr_msg, 0, 0 );
366 bdb_cf_gen( ConfigArgs *c )
368 struct bdb_info *bdb = c->be->be_private;
371 if ( c->op == SLAP_CONFIG_EMIT ) {
377 bv.bv_len = snprintf( buf, sizeof(buf), "0%o", bdb->bi_dbenv_mode );
378 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
380 value_add_one( &c->rvalue_vals, &bv );
387 if ( bdb->bi_txn_cp ) {
390 bv.bv_len = snprintf( buf, sizeof(buf), "%d %d", bdb->bi_txn_cp_kbyte,
391 bdb->bi_txn_cp_min );
392 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
394 value_add_one( &c->rvalue_vals, &bv );
404 if ( bdb->bi_db_crypt_file ) {
405 c->value_string = ch_strdup( bdb->bi_db_crypt_file );
411 /* If a crypt file has been set, its contents are copied here.
412 * But we don't want the key to be incorporated here.
415 if ( !bdb->bi_db_crypt_file && !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
416 value_add_one( &c->rvalue_vals, &bdb->bi_db_crypt_key );
423 if ( bdb->bi_dbenv_home ) {
424 c->value_string = ch_strdup( bdb->bi_dbenv_home );
431 if ( !( bdb->bi_flags & BDB_IS_OPEN )
432 && !bdb->bi_db_config )
434 char buf[SLAP_TEXT_BUFLEN];
435 FILE *f = fopen( bdb->bi_db_config_path, "r" );
439 bdb->bi_flags |= BDB_HAS_CONFIG;
440 while ( fgets( buf, sizeof(buf), f )) {
441 ber_str2bv( buf, 0, 1, &bv );
442 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\n' ) {
444 bv.bv_val[bv.bv_len] = '\0';
446 /* shouldn't need this, but ... */
447 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\r' ) {
449 bv.bv_val[bv.bv_len] = '\0';
451 ber_bvarray_add( &bdb->bi_db_config, &bv );
456 if ( bdb->bi_db_config ) {
461 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
462 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
463 bdb->bi_db_config[i].bv_val );
464 value_add_one( &c->rvalue_vals, &bv );
467 if ( !c->rvalue_vals ) rc = 1;
471 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
476 if ( bdb->bi_flags & BDB_CHKSUM )
481 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
482 if ( !c->rvalue_vals ) rc = 1;
487 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
489 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
490 if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
491 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
500 c->value_int = bdb->bi_search_stack_depth;
504 struct bdb_db_pgsize *ps;
505 char buf[SLAP_TEXT_BUFLEN];
510 for ( ps = bdb->bi_pagesizes; ps; ps = ps->bdp_next ) {
511 bv.bv_len = sprintf( buf, "%s %d", ps->bdp_name.bv_val,
512 ps->bdp_size / 1024 );
513 value_add_one( &c->rvalue_vals, &bv );
521 } else if ( c->op == LDAP_MOD_DELETE ) {
526 /* FIXME: does it make any sense to change the mode,
527 * if we don't exec a chmod()? */
528 bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
532 /* single-valued no-ops */
538 if ( bdb->bi_txn_cp_task ) {
539 struct re_s *re = bdb->bi_txn_cp_task;
540 bdb->bi_txn_cp_task = NULL;
541 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
542 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
543 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
544 ldap_pvt_runqueue_remove( &slapd_rq, re );
545 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
551 ber_bvarray_free( bdb->bi_db_config );
552 bdb->bi_db_config = NULL;
555 ch_free( bdb->bi_db_config[i].bv_val );
556 for (; bdb->bi_db_config[i].bv_val; i++)
557 bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
559 bdb->bi_flags |= BDB_UPD_CONFIG;
560 c->cleanup = bdb_cf_cleanup;
562 /* Doesn't really make sense to change these on the fly;
563 * the entire DB must be dumped and reloaded
566 if ( bdb->bi_db_crypt_file ) {
567 ch_free( bdb->bi_db_crypt_file );
568 bdb->bi_db_crypt_file = NULL;
572 if ( !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
573 ch_free( bdb->bi_db_crypt_key.bv_val );
574 BER_BVZERO( &bdb->bi_db_crypt_key );
578 bdb->bi_flags |= BDB_RE_OPEN;
579 bdb->bi_flags ^= BDB_HAS_CONFIG;
580 ch_free( bdb->bi_dbenv_home );
581 bdb->bi_dbenv_home = NULL;
582 ch_free( bdb->bi_db_config_path );
583 bdb->bi_db_config_path = NULL;
584 c->cleanup = bdb_cf_cleanup;
585 ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
588 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
591 bdb->bi_flags &= ~BDB_CHKSUM;
594 if ( c->valx == -1 ) {
597 /* delete all (FIXME) */
598 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
599 bdb->bi_attrs[i]->ai_indexmask |= BDB_INDEX_DELETING;
601 bdb->bi_flags |= BDB_DEL_INDEX;
602 c->cleanup = bdb_cf_cleanup;
605 struct berval bv, def = BER_BVC("default");
608 for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++);
611 bv.bv_len = ptr - bv.bv_val;
612 if ( bvmatch( &bv, &def )) {
613 bdb->bi_defaultmask = 0;
620 sep = bv.bv_val[ bv.bv_len ];
621 bv.bv_val[ bv.bv_len ] = '\0';
622 attrs = ldap_str2charray( bv.bv_val, "," );
624 for ( i = 0; attrs[ i ]; i++ ) {
625 AttributeDescription *ad = NULL;
629 slap_str2ad( attrs[ i ], &ad, &text );
630 /* if we got here... */
631 assert( ad != NULL );
633 ai = bdb_attr_mask( bdb, ad );
634 /* if we got here... */
635 assert( ai != NULL );
637 ai->ai_indexmask |= BDB_INDEX_DELETING;
638 bdb->bi_flags |= BDB_DEL_INDEX;
639 c->cleanup = bdb_cf_cleanup;
642 bv.bv_val[ bv.bv_len ] = sep;
643 ldap_charray_free( attrs );
647 /* doesn't make sense on the fly; the DB file must be
651 struct bdb_db_pgsize *ps, **prev;
654 for ( i = 0, prev = &bdb->bi_pagesizes, ps = *prev; ps;
655 prev = &ps->bdp_next, ps = ps->bdp_next, i++ ) {
656 if ( c->valx == -1 || i == c->valx ) {
657 *prev = ps->bdp_next;
660 if ( i == c->valx ) break;
671 if ( ASCII_DIGIT( c->argv[1][0] ) ) {
675 mode = strtol( c->argv[1], &next, 0 );
676 if ( errno != 0 || next == c->argv[1] || next[0] != '\0' ) {
677 fprintf( stderr, "%s: "
678 "unable to parse mode=\"%s\".\n",
679 c->log, c->argv[1] );
682 bdb->bi_dbenv_mode = mode;
685 char *m = c->argv[1];
686 int who, what, mode = 0;
688 if ( strlen( m ) != STRLENOF("-rwxrwxrwx") ) {
697 for ( who = 0; who < 3; who++ ) {
698 for ( what = 0; what < 3; what++, m++ ) {
701 } else if ( m[0] != "rwx"[what] ) {
704 mode += ((1 << (2 - what)) << 3*(2 - who));
707 bdb->bi_dbenv_mode = mode;
713 if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
714 fprintf( stderr, "%s: "
715 "invalid kbyte \"%s\" in \"checkpoint\".\n",
716 c->log, c->argv[1] );
719 bdb->bi_txn_cp_kbyte = l;
720 if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
721 fprintf( stderr, "%s: "
722 "invalid minutes \"%s\" in \"checkpoint\".\n",
723 c->log, c->argv[2] );
726 bdb->bi_txn_cp_min = l;
727 /* If we're in server mode and time-based checkpointing is enabled,
728 * submit a task to perform periodic checkpoints.
730 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
731 struct re_s *re = bdb->bi_txn_cp_task;
733 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
735 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
736 fprintf( stderr, "%s: "
737 "\"checkpoint\" must occur after \"suffix\".\n",
741 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
742 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
743 bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
744 LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
745 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
754 if ( c->op == SLAP_CONFIG_ADD ) {
755 ptr += STRLENOF("dbconfig");
756 while (!isspace((unsigned char)*ptr)) ptr++;
757 while (isspace((unsigned char)*ptr)) ptr++;
760 if ( bdb->bi_flags & BDB_IS_OPEN ) {
761 bdb->bi_flags |= BDB_UPD_CONFIG;
762 c->cleanup = bdb_cf_cleanup;
764 /* If we're just starting up...
767 /* If a DB_CONFIG file exists, or we don't know the path
768 * to the DB_CONFIG file, ignore these directives
770 if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
772 f = fopen( bdb->bi_db_config_path, "a" );
774 /* FIXME: EBCDIC probably needs special handling */
775 fprintf( f, "%s\n", ptr );
779 ber_str2bv( ptr, 0, 1, &bv );
780 ber_bvarray_add( &bdb->bi_db_config, &bv );
785 rc = lutil_get_filed_password( c->value_string, &bdb->bi_db_crypt_key );
787 bdb->bi_db_crypt_file = c->value_string;
791 /* Cannot set key if file was already set */
793 if ( bdb->bi_db_crypt_file ) {
796 bdb->bi_db_crypt_key = c->value_bv;
800 case BDB_DIRECTORY: {
802 char *ptr, *testpath;
805 len = strlen( c->value_string );
806 testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 );
807 ptr = lutil_strcopy( testpath, c->value_string );
808 *ptr++ = LDAP_DIRSEP[0];
809 strcpy( ptr, "DUMMY" );
810 f = fopen( testpath, "w" );
817 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
818 c->log, strerror( errno ));
819 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
823 if ( bdb->bi_dbenv_home )
824 ch_free( bdb->bi_dbenv_home );
825 bdb->bi_dbenv_home = c->value_string;
827 /* See if a DB_CONFIG file already exists here */
828 if ( bdb->bi_db_config_path )
829 ch_free( bdb->bi_db_config_path );
830 bdb->bi_db_config_path = ch_malloc( len +
831 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
832 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
833 *ptr++ = LDAP_DIRSEP[0];
834 strcpy( ptr, "DB_CONFIG" );
836 f = fopen( bdb->bi_db_config_path, "r" );
838 bdb->bi_flags |= BDB_HAS_CONFIG;
846 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
848 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
849 if ( bdb->bi_flags & BDB_IS_OPEN ) {
850 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
857 bdb->bi_flags |= BDB_CHKSUM;
859 bdb->bi_flags &= ~BDB_CHKSUM;
863 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
864 c->argc - 1, &c->argv[1], &c->reply);
866 if( rc != LDAP_SUCCESS ) return 1;
867 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
868 /* Start the task as soon as we finish here. Set a long
869 * interval (10 hours) so that it only gets scheduled once.
871 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
872 fprintf( stderr, "%s: "
873 "\"index\" must occur after \"suffix\".\n",
877 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
878 bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
879 bdb_online_index, c->be,
880 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
881 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
886 rc = verb_to_mask( c->argv[1], bdb_lockd );
887 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
888 fprintf( stderr, "%s: "
889 "bad policy (%s) in \"lockDetect <policy>\" line\n",
890 c->log, c->argv[1] );
893 bdb->bi_lock_detect = rc;
897 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
899 "%s: depth %d too small, using %d\n",
900 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
901 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
903 bdb->bi_search_stack_depth = c->value_int;
907 struct bdb_db_pgsize *ps, **prev;
910 s = atoi(c->argv[2]);
911 if ( s < 1 || s > 64 ) {
912 snprintf( c->cr_msg, sizeof( c->cr_msg ),
913 "%s: size must be > 0 and <= 64: %d",
915 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
918 i = strlen(c->argv[1]);
919 ps = ch_malloc( sizeof(struct bdb_db_pgsize) + i + 1 );
921 ps->bdp_name.bv_len = i;
922 ps->bdp_name.bv_val = (char *)(ps+1);
923 strcpy( ps->bdp_name.bv_val, c->argv[1] );
924 ps->bdp_size = s * 1024;
925 for ( prev = &bdb->bi_pagesizes; *prev; prev = &(*prev)->bdp_next )
934 int bdb_back_init_cf( BackendInfo *bi )
937 bi->bi_cf_ocs = bdbocs;
939 rc = config_register_schema( bdbcfg, bdbocs );