]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
ee8e11ed09f4c106475ecb939b53ef3524048f80
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include "back-bdb.h"
23
24 #include "config.h"
25
26 #include "lutil.h"
27 #include "ldap_rq.h"
28
29 #ifdef DB_DIRTY_READ
30 #       define  SLAP_BDB_ALLOW_DIRTY_READ
31 #endif
32
33 #define bdb_cf_gen                      BDB_SYMBOL(cf_gen)
34 #define bdb_cf_cleanup          BDB_SYMBOL(cf_cleanup)
35 #define bdb_checkpoint          BDB_SYMBOL(checkpoint)
36 #define bdb_online_index        BDB_SYMBOL(online_index)
37
38 static ConfigDriver bdb_cf_gen;
39
40 enum {
41         BDB_CHKPT = 1,
42         BDB_CONFIG,
43         BDB_DIRECTORY,
44         BDB_NOSYNC,
45         BDB_DIRTYR,
46         BDB_INDEX,
47         BDB_LOCKD,
48         BDB_SSTACK
49 };
50
51 static ConfigTable bdbcfg[] = {
52         { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
53                 bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
54                         "DESC 'Directory for database content' "
55                         "EQUALITY caseIgnoreMatch "
56                         "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
57         { "cachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
58                 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
59                 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
60                         "DESC 'Entry cache size in entries' "
61                         "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
62         { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
63                 bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
64                         "DESC 'Database checkpoint interval in kbytes and minutes' "
65                         "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
66         { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
67                 bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
68                         "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
69                         "SYNTAX OMsDirectoryString )",NULL, NULL },
70         { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
71                 bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
72                         "DESC 'Disable synchronous database writes' "
73                         "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
74         { "dirtyread", NULL, 1, 2, 0,
75 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
76                 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
77 #else
78                 ARG_IGNORED, NULL,
79 #endif
80                 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
81                 "DESC 'Allow reads of uncommitted data' "
82                 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
83         { "idlcachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
84                 (void *)offsetof(struct bdb_info,bi_idl_cache_max_size),
85                 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
86                 "DESC 'IDL cache size in IDLs' "
87                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
88         { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
89                 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
90                 "DESC 'Attribute index parameters' "
91                 "EQUALITY caseIgnoreMatch "
92                 "SYNTAX OMsDirectoryString )", NULL, NULL },
93         { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
94                 (void *)offsetof(struct bdb_info, bi_linear_index), 
95                 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
96                 "DESC 'Index attributes one at a time' "
97                 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
98         { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
99                 bdb_cf_gen, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
100                 "DESC 'Deadlock detection algorithm' "
101                 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
102         { "mode", "mode", 2, 2, 0, ARG_INT|ARG_OFFSET,
103                 (void *)offsetof(struct bdb_info, bi_dbenv_mode),
104                 "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
105                 "DESC 'Unix permissions of database files' "
106                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
107         { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
108                 bdb_cf_gen, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
109                 "DESC 'Depth of search stack in IDLs' "
110                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
111         { "shm_key", "key", 2, 2, 0, ARG_INT|ARG_OFFSET,
112                 (void *)offsetof(struct bdb_info, bi_shm_key), 
113                 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
114                 "DESC 'Key for shared memory region' "
115                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
116         { NULL, NULL, 0, 0, 0, ARG_IGNORED,
117                 NULL, NULL, NULL, NULL }
118 };
119
120 static ConfigOCs bdbocs[] = {
121         { "( OLcfgDbOc:1.1 "
122                 "NAME 'olcBdbConfig' "
123                 "DESC 'BDB backend configuration' "
124                 "SUP olcDatabaseConfig "
125                 "MUST olcDbDirectory "
126                 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
127                 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
128                 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
129                 "olcDbMode $ olcDbSearchStack $ olcDbShmKey ) )",
130                         Cft_Database, bdbcfg },
131         { NULL, 0, NULL }
132 };
133
134 static slap_verbmasks bdb_lockd[] = {
135         { BER_BVC("default"), DB_LOCK_DEFAULT },
136         { BER_BVC("oldest"), DB_LOCK_OLDEST },
137         { BER_BVC("random"), DB_LOCK_RANDOM },
138         { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
139         { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
140         { BER_BVNULL, 0 }
141 };
142
143 /* perform periodic checkpoints */
144 static void *
145 bdb_checkpoint( void *ctx, void *arg )
146 {
147         struct re_s *rtask = arg;
148         struct bdb_info *bdb = rtask->arg;
149         
150         TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
151                 bdb->bi_txn_cp_min, 0 );
152         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
153         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
154         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
155         return NULL;
156 }
157
158 /* reindex entries on the fly */
159 static void *
160 bdb_online_index( void *ctx, void *arg )
161 {
162         struct re_s *rtask = arg;
163         BackendDB *be = rtask->arg;
164         struct bdb_info *bdb = be->be_private;
165
166         Connection conn = {0};
167         char opbuf[OPERATION_BUFFER_SIZE];
168         Operation *op = (Operation *)opbuf;
169
170         DBC *curs;
171         DBT key, data;
172         DB_TXN *txn;
173         DB_LOCK lock;
174         u_int32_t locker;
175         ID id, nid;
176         EntryInfo *ei;
177         int rc, getnext = 1;
178
179         connection_fake_init( &conn, op, ctx );
180
181         op->o_bd = be;
182
183         DBTzero( &key );
184         DBTzero( &data );
185         
186         id = 1;
187         key.data = &nid;
188         key.size = key.ulen = sizeof(ID);
189         key.flags = DB_DBT_USERMEM;
190
191         data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
192         data.dlen = data.ulen = 0;
193
194         while ( 1 ) {
195                 if ( slapd_shutdown )
196                         break;
197
198                 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &txn, bdb->bi_db_opflags );
199                 if ( rc ) 
200                         break;
201                 locker = TXN_ID( txn );
202                 if ( getnext ) {
203                         getnext = 0;
204                         BDB_ID2DISK( id, &nid );
205                         rc = bdb->bi_id2entry->bdi_db->cursor(
206                                 bdb->bi_id2entry->bdi_db, txn, &curs, bdb->bi_db_opflags );
207                         if ( rc ) {
208                                 TXN_ABORT( txn );
209                                 break;
210                         }
211                         rc = curs->c_get( curs, &key, &data, DB_SET_RANGE );
212                         curs->c_close( curs );
213                         if ( rc ) {
214                                 TXN_ABORT( txn );
215                                 if ( rc == DB_NOTFOUND )
216                                         rc = 0;
217                                 if ( rc == DB_LOCK_DEADLOCK ) {
218                                         ldap_pvt_thread_yield();
219                                         continue;
220                                 }
221                                 break;
222                         }
223                         BDB_DISK2ID( &nid, &id );
224                 }
225
226                 ei = NULL;
227                 rc = bdb_cache_find_id( op, txn, id, &ei, 0, locker, &lock );
228                 if ( rc ) {
229                         TXN_ABORT( txn );
230                         if ( rc == DB_LOCK_DEADLOCK ) {
231                                 ldap_pvt_thread_yield();
232                                 continue;
233                         }
234                         if ( rc == DB_NOTFOUND ) {
235                                 id++;
236                                 getnext = 1;
237                                 continue;
238                         }
239                         break;
240                 }
241                 if ( ei->bei_e ) {
242                         rc = bdb_index_entry( op, txn, BDB_INDEX_UPDATE_OP, ei->bei_e );
243                         if ( rc == DB_LOCK_DEADLOCK ) {
244                                 TXN_ABORT( txn );
245                                 ldap_pvt_thread_yield();
246                                 continue;
247                         }
248                         if ( rc == 0 ) {
249                                 rc = TXN_COMMIT( txn, 0 );
250                                 txn = NULL;
251                         }
252                         if ( rc )
253                                 break;
254                 }
255                 id++;
256                 getnext = 1;
257         }
258 out:
259         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
260         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
261         bdb->bi_index_task = NULL;
262         ldap_pvt_runqueue_remove( &slapd_rq, rtask );
263         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
264
265         return NULL;
266 }
267
268 /* Cleanup loose ends after Modify completes */
269 static int
270 bdb_cf_cleanup( ConfigArgs *c )
271 {
272         struct bdb_info *bdb = c->be->be_private;
273         int rc = 0;
274
275         if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
276                 if ( bdb->bi_db_config ) {
277                         int i;
278                         FILE *f = fopen( bdb->bi_db_config_path, "w" );
279                         if ( f ) {
280                                 for (i=0; bdb->bi_db_config[i].bv_val; i++)
281                                         fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
282                                 fclose( f );
283                         }
284                 } else {
285                         unlink( bdb->bi_db_config_path );
286                 }
287                 bdb->bi_flags ^= BDB_UPD_CONFIG;
288         }
289
290         if ( bdb->bi_flags & BDB_DEL_INDEX ) {
291                 bdb_attr_flush( bdb );
292                 bdb->bi_flags ^= BDB_DEL_INDEX;
293         }
294         
295         if ( bdb->bi_flags & BDB_RE_OPEN ) {
296                 bdb->bi_flags ^= BDB_RE_OPEN;
297                 rc = c->be->bd_info->bi_db_close( c->be );
298                 if ( rc == 0 )
299                         rc = c->be->bd_info->bi_db_open( c->be );
300                 /* If this fails, we need to restart */
301                 if ( rc ) {
302                         slapd_shutdown = 2;
303                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
304                                 ": failed to reopen database, rc=%d", rc, 0, 0 );
305                 }
306         }
307         return rc;
308 }
309
310 static int
311 bdb_cf_gen(ConfigArgs *c)
312 {
313         struct bdb_info *bdb = c->be->be_private;
314         int rc;
315
316         if ( c->op == SLAP_CONFIG_EMIT ) {
317                 rc = 0;
318                 switch( c->type ) {
319                 case BDB_CHKPT:
320                         if (bdb->bi_txn_cp ) {
321                                 char buf[64];
322                                 struct berval bv;
323                                 bv.bv_len = sprintf( buf, "%d %d", bdb->bi_txn_cp_kbyte,
324                                         bdb->bi_txn_cp_min );
325                                 bv.bv_val = buf;
326                                 value_add_one( &c->rvalue_vals, &bv );
327                         } else{
328                                 rc = 1;
329                         }
330                         break;
331
332                 case BDB_DIRECTORY:
333                         if ( bdb->bi_dbenv_home ) {
334                                 c->value_string = ch_strdup( bdb->bi_dbenv_home );
335                         } else {
336                                 rc = 1;
337                         }
338                         break;
339
340                 case BDB_CONFIG:
341                         if (( slapMode&SLAP_SERVER_MODE ) && !( bdb->bi_flags&BDB_IS_OPEN )
342                                 && !bdb->bi_db_config ) {
343                                 char    buf[SLAP_TEXT_BUFLEN];
344                                 FILE *f = fopen( bdb->bi_db_config_path, "r" );
345                                 struct berval bv;
346
347                                 if ( f ) {
348                                         bdb->bi_flags |= BDB_HAS_CONFIG;
349                                         while ( fgets( buf, sizeof(buf), f )) {
350                                                 ber_str2bv( buf, 0, 1, &bv );
351                                                 if ( bv.bv_val[bv.bv_len-1] == '\n' ) {
352                                                         bv.bv_len--;
353                                                         bv.bv_val[bv.bv_len] = '\0';
354                                                 }
355                                                 /* shouldn't need this, but ... */
356                                                 if ( bv.bv_val[bv.bv_len-1] == '\r' ) {
357                                                         bv.bv_len--;
358                                                         bv.bv_val[bv.bv_len] = '\0';
359                                                 }
360                                                 ber_bvarray_add( &bdb->bi_db_config, &bv );
361                                         }
362                                         fclose( f );
363                                 }
364                         }
365                         if ( bdb->bi_db_config ) {
366                                 int i;
367                                 struct berval bv;
368
369                                 bv.bv_val = c->log;
370                                 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
371                                         bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
372                                                 bdb->bi_db_config[i].bv_val );
373                                         value_add_one( &c->rvalue_vals, &bv );
374                                 }
375                         }
376                         if ( !c->rvalue_vals ) rc = 1;
377                         break;
378
379                 case BDB_NOSYNC:
380                         if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
381                                 c->value_int = 1;
382                         break;
383                         
384                 case BDB_INDEX:
385                         bdb_attr_index_unparse( bdb, &c->rvalue_vals );
386                         if ( !c->rvalue_vals ) rc = 1;
387                         break;
388
389                 case BDB_LOCKD:
390                         rc = 1;
391                         if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
392                                 int i;
393                                 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
394                                         if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
395                                                 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
396                                                 rc = 0;
397                                                 break;
398                                         }
399                                 }
400                         }
401                         break;
402
403                 case BDB_SSTACK:
404                         c->value_int = bdb->bi_search_stack_depth;
405                         break;
406                 }
407                 return rc;
408         } else if ( c->op == LDAP_MOD_DELETE ) {
409                 rc = 0;
410                 switch( c->type ) {
411                 /* single-valued no-ops */
412                 case BDB_LOCKD:
413                 case BDB_SSTACK:
414                         break;
415
416                 case BDB_CHKPT:
417                         if ( bdb->bi_txn_cp_task ) {
418                                 struct re_s *re = bdb->bi_txn_cp_task;
419                                 bdb->bi_txn_cp_task = NULL;
420                                 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
421                                         ldap_pvt_runqueue_stoptask( &slapd_rq, re );
422                                 ldap_pvt_runqueue_remove( &slapd_rq, re );
423                         }
424                         bdb->bi_txn_cp = 0;
425                         break;
426                 case BDB_CONFIG:
427                         if ( c->valx < 0 ) {
428                                 ber_bvarray_free( bdb->bi_db_config );
429                                 bdb->bi_db_config = NULL;
430                         } else {
431                                 int i = c->valx;
432                                 ch_free( bdb->bi_db_config[i].bv_val );
433                                 for (; bdb->bi_db_config[i].bv_val; i++)
434                                         bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
435                         }
436                         bdb->bi_flags |= BDB_UPD_CONFIG;
437                         c->cleanup = bdb_cf_cleanup;
438                         break;
439                 case BDB_DIRECTORY:
440                         bdb->bi_flags |= BDB_RE_OPEN;
441                         bdb->bi_flags ^= BDB_HAS_CONFIG;
442                         ch_free( bdb->bi_dbenv_home );
443                         bdb->bi_dbenv_home = NULL;
444                         ch_free( bdb->bi_db_config_path );
445                         bdb->bi_db_config_path = NULL;
446                         c->cleanup = bdb_cf_cleanup;
447                         ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
448                         ldap_pvt_thread_pool_purgekey( ((char *)bdb->bi_dbenv) + 1 );
449                         break;
450                 case BDB_NOSYNC:
451                         bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
452                         break;
453                 case BDB_INDEX: {
454                         AttributeDescription *ad = NULL;
455                         struct berval bv, def = BER_BVC("default");
456                         char *ptr;
457                         const char *text;
458                         for (ptr = c->line; !isspace( *ptr ); ptr++);
459                         bv.bv_val = c->line;
460                         bv.bv_len = ptr - bv.bv_val;
461                         if ( bvmatch( &bv, &def )) {
462                                 bdb->bi_defaultmask = 0;
463                         } else {
464                                 slap_bv2ad( &bv, &ad, &text );
465                                 if ( ad ) {
466                                         AttrInfo *ai = bdb_attr_mask( bdb, ad );
467                                         ai->ai_indexmask |= BDB_INDEX_DELETING;
468                                         bdb->bi_flags |= BDB_DEL_INDEX;
469                                         c->cleanup = bdb_cf_cleanup;
470                                 }
471                         }
472                         }
473                         break;
474                 }
475                 return rc;
476         }
477
478         switch( c->type ) {
479         case BDB_CHKPT:
480                 bdb->bi_txn_cp = 1;
481                 bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
482                 bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
483                 /* If we're in server mode and time-based checkpointing is enabled,
484                  * submit a task to perform periodic checkpoints.
485                  */
486                 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
487                         struct re_s *re = bdb->bi_txn_cp_task;
488                         if ( re ) {
489                                 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
490                         } else {
491                                 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
492                                         fprintf( stderr, "%s: "
493                                                 "\"checkpoint\" must occur after \"suffix\".\n",
494                                                 c->log );
495                                         return 1;
496                                 }
497                                 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
498                                         bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
499                                         LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
500                         }
501                 }
502                 break;
503
504         case BDB_CONFIG: {
505                 char *ptr = c->line + STRLENOF("dbconfig");
506                 struct berval bv;
507                 while (!isspace(*ptr)) ptr++;
508                 while (isspace(*ptr)) ptr++;
509                 
510                 if ( bdb->bi_flags & BDB_IS_OPEN ) {
511                         bdb->bi_flags |= BDB_UPD_CONFIG;
512                         c->cleanup = bdb_cf_cleanup;
513                 } else {
514                 /* If we're just starting up...
515                  */
516                         FILE *f;
517                         /* If a DB_CONFIG file exists, or we don't know the path
518                          * to the DB_CONFIG file, ignore these directives
519                          */
520                         if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
521                                 break;
522                         f = fopen( bdb->bi_db_config_path, "a" );
523                         if ( f ) {
524                                 /* FIXME: EBCDIC probably needs special handling */
525                                 fprintf( f, "%s\n", ptr );
526                                 fclose( f );
527                         }
528                 }
529                 ber_str2bv( ptr, 0, 1, &bv );
530                 ber_bvarray_add( &bdb->bi_db_config, &bv );
531                 }
532                 break;
533
534         case BDB_DIRECTORY: {
535                 FILE *f;
536                 char *ptr;
537
538                 if ( bdb->bi_dbenv_home )
539                         ch_free( bdb->bi_dbenv_home );
540                 bdb->bi_dbenv_home = c->value_string;
541
542                 /* See if a DB_CONFIG file already exists here */
543                 if ( bdb->bi_db_config_path )
544                         ch_free( bdb->bi_db_config_path );
545                 bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
546                         STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
547                 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
548                 *ptr++ = LDAP_DIRSEP[0];
549                 strcpy( ptr, "DB_CONFIG" );
550
551                 f = fopen( bdb->bi_db_config_path, "r" );
552                 if ( f ) {
553                         bdb->bi_flags |= BDB_HAS_CONFIG;
554                         fclose(f);
555                 }
556                 }
557                 break;
558
559         case BDB_NOSYNC:
560                 if ( c->value_int )
561                         bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
562                 else
563                         bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
564                 if ( bdb->bi_flags & BDB_IS_OPEN ) {
565                         bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
566                                 c->value_int );
567                 }
568                 break;
569
570         case BDB_INDEX:
571                 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
572                         c->argc - 1, &c->argv[1] );
573
574                 if( rc != LDAP_SUCCESS ) return 1;
575                 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
576                         /* Start the task as soon as we finish here. Set a long
577                          * interval (10 hours) so that it only gets scheduled once.
578                          */
579                         if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
580                                 fprintf( stderr, "%s: "
581                                         "\"index\" must occur after \"suffix\".\n",
582                                         c->log );
583                                 return 1;
584                         }
585                         bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
586                                 bdb_online_index, c->be,
587                                 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
588                 }
589                 break;
590
591         case BDB_LOCKD:
592                 rc = verb_to_mask( c->argv[1], bdb_lockd );
593                 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
594                         fprintf( stderr, "%s: "
595                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
596                                 c->log, c->argv[1] );
597                         return 1;
598                 }
599                 bdb->bi_lock_detect = rc;
600                 break;
601
602         case BDB_SSTACK:
603                 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
604                         fprintf( stderr,
605                 "%s: depth %d too small, using %d\n",
606                         c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
607                         c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
608                 }
609                 bdb->bi_search_stack_depth = c->value_int;
610                 break;
611         }
612         return 0;
613 }
614
615 int bdb_back_init_cf( BackendInfo *bi )
616 {
617         int rc;
618         bi->bi_cf_ocs = bdbocs;
619
620         rc = config_register_schema( bdbcfg, bdbocs );
621         if ( rc ) return rc;
622         return 0;
623 }