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