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