2001-10-05 09:19:58 +08:00
|
|
|
/* config.c - bdb backend configuration file routine */
|
2000-09-26 05:10:21 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 2000-2004 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-09-26 05:10:21 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2003-04-23 14:34:55 +08:00
|
|
|
#include "external.h"
|
2000-09-26 05:10:21 +08:00
|
|
|
|
2001-12-09 10:34:45 +08:00
|
|
|
#ifdef DB_DIRTY_READ
|
|
|
|
# define SLAP_BDB_ALLOW_DIRTY_READ
|
|
|
|
#endif
|
2001-11-27 12:35:58 +08:00
|
|
|
|
2000-09-26 05:10:21 +08:00
|
|
|
int
|
|
|
|
bdb_db_config(
|
2000-09-28 06:28:59 +08:00
|
|
|
BackendDB *be,
|
|
|
|
const char *fname,
|
|
|
|
int lineno,
|
|
|
|
int argc,
|
|
|
|
char **argv )
|
2000-09-26 05:10:21 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
|
|
|
|
if ( bdb == NULL ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"bdb database info is null!\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
fname, lineno );
|
2000-09-26 05:10:21 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* directory is the DB_HOME */
|
|
|
|
if ( strcasecmp( argv[0], "directory" ) == 0 ) {
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"missing dir in \"directory <dir>\" line\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
fname, lineno );
|
2000-09-26 05:10:21 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( bdb->bi_dbenv_home ) {
|
|
|
|
free( bdb->bi_dbenv_home );
|
|
|
|
}
|
|
|
|
bdb->bi_dbenv_home = ch_strdup( argv[1] );
|
|
|
|
|
2001-11-28 11:11:04 +08:00
|
|
|
#ifdef SLAP_BDB_ALLOW_DIRTY_READ
|
|
|
|
} else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
|
|
|
|
bdb->bi_db_opflags |= DB_DIRTY_READ;
|
2001-11-27 12:35:58 +08:00
|
|
|
#endif
|
2003-04-18 17:43:22 +08:00
|
|
|
/* transaction logging configuration */
|
2000-09-29 08:18:29 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
|
|
|
|
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
|
|
|
|
|
2004-07-23 06:14:35 +08:00
|
|
|
/* slapadd/slapindex logging configuration */
|
2004-07-26 03:49:24 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "fasttool" ) == 0 ) {
|
|
|
|
if ( slapMode & SLAP_TOOL_MODE )
|
2004-07-23 06:14:35 +08:00
|
|
|
bdb->bi_dbenv_xflags |= DB_TXN_NOT_DURABLE;
|
|
|
|
|
2004-07-23 06:32:37 +08:00
|
|
|
/* slapindex algorithm tuning */
|
|
|
|
} else if ( strcasecmp( argv[0], "linearindex" ) == 0 ) {
|
|
|
|
bdb->bi_linear_index = 1;
|
|
|
|
|
2000-09-29 08:18:29 +08:00
|
|
|
/* transaction checkpoint configuration */
|
2000-09-28 12:09:13 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
|
|
|
|
if ( argc < 3 ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"missing parameters in \"checkpoint <kbyte> <min>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bdb->bi_txn_cp = 1;
|
|
|
|
bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
|
|
|
|
bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
|
|
|
|
|
2000-09-29 08:18:29 +08:00
|
|
|
/* lock detect configuration */
|
|
|
|
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
|
2002-09-19 09:13:27 +08:00
|
|
|
if ( argc < 2 ) {
|
2000-09-29 08:18:29 +08:00
|
|
|
fprintf( stderr, "%s: line %d: "
|
2002-09-19 09:13:27 +08:00
|
|
|
"missing parameters in \"lockDetect <policy>\" line\n",
|
2000-09-29 08:18:29 +08:00
|
|
|
fname, lineno );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcasecmp( argv[1], "default" ) == 0 ) {
|
|
|
|
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
|
|
|
|
|
|
|
|
} else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
|
|
|
|
bdb->bi_lock_detect = DB_LOCK_OLDEST;
|
|
|
|
|
|
|
|
} else if( strcasecmp( argv[1], "random" ) == 0 ) {
|
|
|
|
bdb->bi_lock_detect = DB_LOCK_RANDOM;
|
|
|
|
|
|
|
|
} else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
|
|
|
|
bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
|
|
|
|
|
2002-01-18 21:32:01 +08:00
|
|
|
} else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
|
|
|
|
bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
|
|
|
|
|
2000-09-29 08:18:29 +08:00
|
|
|
} else {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
2002-09-19 09:13:27 +08:00
|
|
|
"bad policy (%s) in \"lockDetect <policy>\" line\n",
|
2000-09-29 08:18:29 +08:00
|
|
|
fname, lineno, argv[1] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-09-26 05:10:21 +08:00
|
|
|
/* mode with which to create new database files */
|
|
|
|
} else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"missing mode in \"mode <mode>\" line\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
fname, lineno );
|
2000-09-26 05:10:21 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
|
|
|
|
|
|
|
|
/* attribute to index */
|
|
|
|
} else if ( strcasecmp( argv[0], "index" ) == 0 ) {
|
|
|
|
int rc;
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
fname, lineno );
|
2000-09-26 05:10:21 +08:00
|
|
|
return 1;
|
|
|
|
} else if ( argc > 3 ) {
|
|
|
|
fprintf( stderr, "%s: line %d: "
|
|
|
|
"extra junk after \"index <attr> [pres,eq,approx,sub]\" "
|
|
|
|
"line (ignored)\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
fname, lineno );
|
2000-09-26 05:10:21 +08:00
|
|
|
}
|
2001-10-04 05:11:52 +08:00
|
|
|
rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
|
2000-09-26 05:10:21 +08:00
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) return 1;
|
|
|
|
|
2003-04-18 17:43:22 +08:00
|
|
|
/* unique key for shared memory regions */
|
2003-11-10 10:44:25 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing key in \"shm_key <key>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
bdb->bi_shm_key = atoi( argv[1] );
|
2003-04-18 17:43:22 +08:00
|
|
|
|
2002-01-25 15:19:01 +08:00
|
|
|
/* size of the cache in entries */
|
2003-11-10 10:44:25 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing size in \"cachesize <size>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
bdb->bi_cache.c_maxsize = atoi( argv[1] );
|
2002-01-25 15:19:01 +08:00
|
|
|
|
2002-12-11 04:33:49 +08:00
|
|
|
/* depth of search stack cache in units of (IDL)s */
|
2003-11-10 10:44:25 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
|
2003-04-05 18:05:27 +08:00
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr,
|
2003-11-10 10:44:25 +08:00
|
|
|
"%s: line %d: missing depth in \"searchstack <depth>\" line\n",
|
|
|
|
fname, lineno );
|
2003-04-05 18:05:27 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
bdb->bi_search_stack_depth = atoi( argv[1] );
|
|
|
|
if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: depth %d too small, using %d\n",
|
|
|
|
fname, lineno, bdb->bi_search_stack_depth,
|
|
|
|
MINIMUM_SEARCH_STACK_DEPTH );
|
|
|
|
bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
|
|
|
|
}
|
2002-12-11 04:33:49 +08:00
|
|
|
|
|
|
|
/* size of the IDL cache in entries */
|
2003-11-10 10:44:25 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
|
|
|
|
if ( argc < 2 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: line %d: missing size in \"idlcachesize <size>\" line\n",
|
|
|
|
fname, lineno );
|
|
|
|
return( 1 );
|
|
|
|
}
|
2004-03-07 03:15:39 +08:00
|
|
|
if ( !( slapMode & SLAP_TOOL_MODE ) )
|
|
|
|
bdb->bi_idl_cache_max_size = atoi( argv[1] );
|
2003-11-10 10:44:25 +08:00
|
|
|
} else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
|
|
|
|
int se_id = 0, se_size = 0;
|
|
|
|
struct slap_session_entry *sent;
|
|
|
|
if ( argc < 3 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s: line %d: missing arguments in \"sessionlog <id> <size>\""
|
|
|
|
" line\n", fname, lineno, 0 );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
se_id = atoi( argv[1] );
|
|
|
|
|
|
|
|
if ( se_id < 0 || se_id > 999 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s: line %d: session log id %d is out of range [0..999]\n",
|
|
|
|
fname, lineno , se_id );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2004-04-09 19:22:07 +08:00
|
|
|
se_size = atoi( argv[2] );
|
|
|
|
if ( se_size < 0 ) {
|
2003-11-10 10:44:25 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s: line %d: session log size %d is negative\n",
|
|
|
|
fname, lineno , se_size );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
|
|
|
|
if ( sent->se_id == se_id ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s: line %d: session %d already exists\n",
|
|
|
|
fname, lineno , se_id );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sent = (struct slap_session_entry *) ch_calloc( 1,
|
|
|
|
sizeof( struct slap_session_entry ));
|
|
|
|
sent->se_id = se_id;
|
|
|
|
sent->se_size = se_size;
|
|
|
|
LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
|
|
|
|
|
2000-09-26 05:10:21 +08:00
|
|
|
/* anything else */
|
|
|
|
} else {
|
2003-12-07 15:07:00 +08:00
|
|
|
return SLAP_CONF_UNKNOWN;
|
2000-09-26 05:10:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|