1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-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>.
20 #include <ac/string.h>
26 # define SLAP_BDB_ALLOW_DIRTY_READ
37 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
40 fprintf( stderr, "%s: line %d: "
41 "bdb database info is null!\n",
46 /* directory is the DB_HOME */
47 if ( strcasecmp( argv[0], "directory" ) == 0 ) {
49 fprintf( stderr, "%s: line %d: "
50 "missing dir in \"directory <dir>\" line\n",
54 if ( bdb->bi_dbenv_home ) {
55 free( bdb->bi_dbenv_home );
57 bdb->bi_dbenv_home = ch_strdup( argv[1] );
59 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
60 } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
61 bdb->bi_db_opflags |= DB_DIRTY_READ;
63 /* transaction logging configuration */
64 } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
65 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
67 /* transaction checkpoint configuration */
68 } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
70 fprintf( stderr, "%s: line %d: "
71 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
76 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
77 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
79 /* lock detect configuration */
80 } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
82 fprintf( stderr, "%s: line %d: "
83 "missing parameters in \"lockDetect <policy>\" line\n",
88 if( strcasecmp( argv[1], "default" ) == 0 ) {
89 bdb->bi_lock_detect = DB_LOCK_DEFAULT;
91 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
92 bdb->bi_lock_detect = DB_LOCK_OLDEST;
94 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
95 bdb->bi_lock_detect = DB_LOCK_RANDOM;
97 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
98 bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
100 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
101 bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
104 fprintf( stderr, "%s: line %d: "
105 "bad policy (%s) in \"lockDetect <policy>\" line\n",
106 fname, lineno, argv[1] );
110 /* mode with which to create new database files */
111 } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
113 fprintf( stderr, "%s: line %d: "
114 "missing mode in \"mode <mode>\" line\n",
118 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
120 /* attribute to index */
121 } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
124 fprintf( stderr, "%s: line %d: "
125 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
128 } else if ( argc > 3 ) {
129 fprintf( stderr, "%s: line %d: "
130 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
134 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
136 if( rc != LDAP_SUCCESS ) return 1;
138 /* unique key for shared memory regions */
139 } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
142 "%s: line %d: missing key in \"shm_key <key>\" line\n",
146 bdb->bi_shm_key = atoi( argv[1] );
148 /* size of the cache in entries */
149 } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
152 "%s: line %d: missing size in \"cachesize <size>\" line\n",
156 bdb->bi_cache.c_maxsize = atoi( argv[1] );
158 /* depth of search stack cache in units of (IDL)s */
159 } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
162 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
166 bdb->bi_search_stack_depth = atoi( argv[1] );
167 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
169 "%s: line %d: depth %d too small, using %d\n",
170 fname, lineno, bdb->bi_search_stack_depth,
171 MINIMUM_SEARCH_STACK_DEPTH );
172 bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
175 #ifdef SLAP_IDL_CACHE
176 /* size of the IDL cache in entries */
177 } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
180 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
184 if ( !( slapMode & SLAP_TOOL_MODE ) )
185 bdb->bi_idl_cache_max_size = atoi( argv[1] );
188 } else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
189 int se_id = 0, se_size = 0;
190 struct slap_session_entry *sent;
193 LDAP_LOG( CONFIG, CRIT,
194 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
195 " line.\n", fname, lineno , 0 );
197 Debug( LDAP_DEBUG_ANY,
198 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
199 " line\n", fname, lineno, 0 );
204 se_id = atoi( argv[1] );
206 if ( se_id < 0 || se_id > 999 ) {
208 LDAP_LOG( CONFIG, CRIT,
209 "%s: line %d: session log id %d is out of range [0..999]\n",
210 fname, lineno , se_id );
212 Debug( LDAP_DEBUG_ANY,
213 "%s: line %d: session log id %d is out of range [0..999]\n",
214 fname, lineno , se_id );
219 se_size = atoi( argv[2] );
222 LDAP_LOG( CONFIG, CRIT,
223 "%s: line %d: session log size %d is negative\n",
224 fname, lineno , se_size );
226 Debug( LDAP_DEBUG_ANY,
227 "%s: line %d: session log size %d is negative\n",
228 fname, lineno , se_size );
233 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
234 if ( sent->se_id == se_id ) {
236 LDAP_LOG( CONFIG, CRIT,
237 "%s: line %d: session %d already exists\n",
238 fname, lineno , se_id );
240 Debug( LDAP_DEBUG_ANY,
241 "%s: line %d: session %d already exists\n",
242 fname, lineno , se_id );
247 sent = (struct slap_session_entry *) ch_calloc( 1,
248 sizeof( struct slap_session_entry ));
250 sent->se_size = se_size;
251 LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
255 return SLAP_CONF_UNKNOWN;