]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
1c346e38b64005a0d2242ffa55f87b8a4a4fe75f
[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                 bdb->bi_dbenv_xflags |= DB_TXN_NOT_DURABLE;
70
71         /* slapindex algorithm tuning */
72         } else if ( strcasecmp( argv[0], "linearindex" ) == 0 ) {
73                 bdb->bi_linear_index = 1;
74
75         /* transaction checkpoint configuration */
76         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
77                 if ( argc < 3 ) {
78                         fprintf( stderr, "%s: line %d: "
79                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
80                                 fname, lineno );
81                         return 1;
82                 }
83                 bdb->bi_txn_cp = 1;
84                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
85                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
86
87         /* lock detect configuration */
88         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
89                 if ( argc < 2 ) {
90                         fprintf( stderr, "%s: line %d: "
91                                 "missing parameters in \"lockDetect <policy>\" line\n",
92                                 fname, lineno );
93                         return 1;
94                 }
95
96                 if( strcasecmp( argv[1], "default" ) == 0 ) {
97                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
98
99                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
100                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
101
102                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
103                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
104
105                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
106                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
107
108                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
109                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
110
111                 } else {
112                         fprintf( stderr, "%s: line %d: "
113                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
114                                 fname, lineno, argv[1] );
115                         return 1;
116                 }
117
118         /* mode with which to create new database files */
119         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
120                 if ( argc < 2 ) {
121                         fprintf( stderr, "%s: line %d: "
122                                 "missing mode in \"mode <mode>\" line\n",
123                                 fname, lineno );
124                         return 1;
125                 }
126                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
127
128         /* attribute to index */
129         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
130                 int rc;
131                 if ( argc < 2 ) {
132                         fprintf( stderr, "%s: line %d: "
133                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
134                                 fname, lineno );
135                         return 1;
136                 } else if ( argc > 3 ) {
137                         fprintf( stderr, "%s: line %d: "
138                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
139                                 "line (ignored)\n",
140                                 fname, lineno );
141                 }
142                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
143
144                 if( rc != LDAP_SUCCESS ) return 1;
145
146         /* unique key for shared memory regions */
147         } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
148                 if ( argc < 2 ) {
149                         fprintf( stderr,
150                                 "%s: line %d: missing key in \"shm_key <key>\" line\n",
151                                 fname, lineno );
152                         return( 1 );
153                 }
154                 bdb->bi_shm_key = atoi( argv[1] );
155
156         /* size of the cache in entries */
157         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
158                 if ( argc < 2 ) {
159                         fprintf( stderr,
160                                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
161                                 fname, lineno );
162                         return( 1 );
163                 }
164                 bdb->bi_cache.c_maxsize = atoi( argv[1] );
165
166         /* depth of search stack cache in units of (IDL)s */
167         } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
168                 if ( argc < 2 ) {
169                         fprintf( stderr,
170                                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
171                                 fname, lineno );
172                         return( 1 );
173                 }
174                 bdb->bi_search_stack_depth = atoi( argv[1] );
175                 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
176                         fprintf( stderr,
177                 "%s: line %d: depth %d too small, using %d\n",
178                         fname, lineno, bdb->bi_search_stack_depth,
179                         MINIMUM_SEARCH_STACK_DEPTH );
180                         bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
181                 }
182
183         /* size of the IDL cache in entries */
184         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
185                 if ( argc < 2 ) {
186                         fprintf( stderr,
187                                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
188                                 fname, lineno );
189                         return( 1 );
190                 }
191                 if ( !( slapMode & SLAP_TOOL_MODE ) )
192                         bdb->bi_idl_cache_max_size = atoi( argv[1] );
193         } else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
194                 int se_id = 0, se_size = 0;
195                 struct slap_session_entry *sent;
196                 if ( argc < 3 ) {
197                         Debug( LDAP_DEBUG_ANY,
198                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
199                                 " line\n", fname, lineno, 0 );
200                         return( 1 );
201                 }
202
203                 se_id = atoi( argv[1] );
204
205                 if ( se_id < 0 || se_id > 999 ) {
206                         Debug( LDAP_DEBUG_ANY,
207                                 "%s: line %d: session log id %d is out of range [0..999]\n",
208                                 fname, lineno , se_id );
209                         return( 1 );
210                 }
211
212                 se_size = atoi( argv[2] );
213                 if ( se_size < 0 ) {
214                         Debug( LDAP_DEBUG_ANY,
215                                 "%s: line %d: session log size %d is negative\n",
216                                 fname, lineno , se_size );
217                         return( 1 );
218                 }
219
220                 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
221                         if ( sent->se_id == se_id ) {
222                                 Debug( LDAP_DEBUG_ANY,
223                                         "%s: line %d: session %d already exists\n",
224                                         fname, lineno , se_id );
225                                 return( 1 );
226                         }
227                 }
228                 sent = (struct slap_session_entry *) ch_calloc( 1,
229                                                 sizeof( struct slap_session_entry ));
230                 sent->se_id = se_id;
231                 sent->se_size = se_size;
232                 LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
233
234         /* anything else */
235         } else {
236                 return SLAP_CONF_UNKNOWN;
237         }
238
239         return 0;
240 }