]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Disable back-bdb native syncrepl support, enable syncprov overlay,
[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-2004 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 #ifdef DB_DIRTY_READ
25 #       define  SLAP_BDB_ALLOW_DIRTY_READ
26 #endif
27
28 int
29 bdb_db_config(
30         BackendDB       *be,
31         const char      *fname,
32         int             lineno,
33         int             argc,
34         char    **argv )
35 {
36         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
37
38         if ( bdb == NULL ) {
39                 fprintf( stderr, "%s: line %d: "
40                         "bdb database info is null!\n",
41                         fname, lineno );
42                 return 1;
43         }
44
45         /* directory is the DB_HOME */
46         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
47                 if ( argc < 2 ) {
48                         fprintf( stderr, "%s: line %d: "
49                                 "missing dir in \"directory <dir>\" line\n",
50                                 fname, lineno );
51                         return 1;
52                 }
53                 if ( bdb->bi_dbenv_home ) {
54                         free( bdb->bi_dbenv_home );
55                 }
56                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
57
58 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
59         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
60                 bdb->bi_db_opflags |= DB_DIRTY_READ;
61 #endif
62         /* transaction logging configuration */
63         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
64                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
65
66         /* slapadd/slapindex logging configuration */
67         } else if ( strcasecmp( argv[0], "fasttool" ) == 0 ) {
68                 if ( slapMode & SLAP_TOOL_MODE )
69 #if DB_VERSION_FULL >= 0x04030015
70                 bdb->bi_dbenv_xflags |= DB_LOG_INMEMORY;
71 #else
72                 bdb->bi_dbenv_xflags |= DB_TXN_NOT_DURABLE;
73 #endif
74
75         /* slapindex algorithm tuning */
76         } else if ( strcasecmp( argv[0], "linearindex" ) == 0 ) {
77                 bdb->bi_linear_index = 1;
78
79         /* transaction checkpoint configuration */
80         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
81                 if ( argc < 3 ) {
82                         fprintf( stderr, "%s: line %d: "
83                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
84                                 fname, lineno );
85                         return 1;
86                 }
87                 bdb->bi_txn_cp = 1;
88                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
89                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
90
91         /* lock detect configuration */
92         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
93                 if ( argc < 2 ) {
94                         fprintf( stderr, "%s: line %d: "
95                                 "missing parameters in \"lockDetect <policy>\" line\n",
96                                 fname, lineno );
97                         return 1;
98                 }
99
100                 if( strcasecmp( argv[1], "default" ) == 0 ) {
101                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
102
103                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
104                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
105
106                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
107                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
108
109                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
110                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
111
112                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
113                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
114
115                 } else {
116                         fprintf( stderr, "%s: line %d: "
117                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
118                                 fname, lineno, argv[1] );
119                         return 1;
120                 }
121
122         /* mode with which to create new database files */
123         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
124                 if ( argc < 2 ) {
125                         fprintf( stderr, "%s: line %d: "
126                                 "missing mode in \"mode <mode>\" line\n",
127                                 fname, lineno );
128                         return 1;
129                 }
130                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
131
132         /* attribute to index */
133         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
134                 int rc;
135                 if ( argc < 2 ) {
136                         fprintf( stderr, "%s: line %d: "
137                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
138                                 fname, lineno );
139                         return 1;
140                 } else if ( argc > 3 ) {
141                         fprintf( stderr, "%s: line %d: "
142                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
143                                 "line (ignored)\n",
144                                 fname, lineno );
145                 }
146                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
147
148                 if( rc != LDAP_SUCCESS ) return 1;
149
150         /* unique key for shared memory regions */
151         } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
152                 if ( argc < 2 ) {
153                         fprintf( stderr,
154                                 "%s: line %d: missing key in \"shm_key <key>\" line\n",
155                                 fname, lineno );
156                         return( 1 );
157                 }
158                 bdb->bi_shm_key = atoi( argv[1] );
159
160         /* size of the cache in entries */
161         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
162                 if ( argc < 2 ) {
163                         fprintf( stderr,
164                                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
165                                 fname, lineno );
166                         return( 1 );
167                 }
168                 bdb->bi_cache.c_maxsize = atoi( argv[1] );
169
170         /* depth of search stack cache in units of (IDL)s */
171         } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
172                 if ( argc < 2 ) {
173                         fprintf( stderr,
174                                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
175                                 fname, lineno );
176                         return( 1 );
177                 }
178                 bdb->bi_search_stack_depth = atoi( argv[1] );
179                 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
180                         fprintf( stderr,
181                 "%s: line %d: depth %d too small, using %d\n",
182                         fname, lineno, bdb->bi_search_stack_depth,
183                         MINIMUM_SEARCH_STACK_DEPTH );
184                         bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
185                 }
186
187         /* size of the IDL cache in entries */
188         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
189                 if ( argc < 2 ) {
190                         fprintf( stderr,
191                                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
192                                 fname, lineno );
193                         return( 1 );
194                 }
195                 if ( !( slapMode & SLAP_TOOL_MODE ) )
196                         bdb->bi_idl_cache_max_size = atoi( argv[1] );
197 #ifdef BDB_PSEARCH
198         } else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
199                 int se_id = 0, se_size = 0;
200                 struct slap_session_entry *sent;
201                 if ( argc < 3 ) {
202                         Debug( LDAP_DEBUG_ANY,
203                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
204                                 " line\n", fname, lineno, 0 );
205                         return( 1 );
206                 }
207
208                 se_id = atoi( argv[1] );
209
210                 if ( se_id < 0 || se_id > 999 ) {
211                         Debug( LDAP_DEBUG_ANY,
212                                 "%s: line %d: session log id %d is out of range [0..999]\n",
213                                 fname, lineno , se_id );
214                         return( 1 );
215                 }
216
217                 se_size = atoi( argv[2] );
218                 if ( se_size < 0 ) {
219                         Debug( LDAP_DEBUG_ANY,
220                                 "%s: line %d: session log size %d is negative\n",
221                                 fname, lineno , se_size );
222                         return( 1 );
223                 }
224
225                 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
226                         if ( sent->se_id == se_id ) {
227                                 Debug( LDAP_DEBUG_ANY,
228                                         "%s: line %d: session %d already exists\n",
229                                         fname, lineno , se_id );
230                                 return( 1 );
231                         }
232                 }
233                 sent = (struct slap_session_entry *) ch_calloc( 1,
234                                                 sizeof( struct slap_session_entry ));
235                 sent->se_id = se_id;
236                 sent->se_size = se_size;
237                 LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
238 #endif /* BDB_PSEARCH */
239         /* anything else */
240         } else {
241                 return SLAP_CONF_UNKNOWN;
242         }
243
244         return 0;
245 }