]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
da6a7db39f3d3b35c6ffa24572854d4c868b788f
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14
15 #define SLAP_BDB_ALLOW_DBNOTXN
16
17 int
18 bdb_db_config(
19         BackendDB       *be,
20         const char      *fname,
21         int             lineno,
22         int             argc,
23         char    **argv )
24 {
25         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
26
27         if ( bdb == NULL ) {
28                 fprintf( stderr, "%s: line %d: "
29                         "bdb database info is null!\n",
30                         fname, lineno );
31                 return 1;
32         }
33
34         /* directory is the DB_HOME */
35         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
36                 if ( argc < 2 ) {
37                         fprintf( stderr, "%s: line %d: "
38                                 "missing dir in \"directory <dir>\" line\n",
39                                 fname, lineno );
40                         return 1;
41                 }
42                 if ( bdb->bi_dbenv_home ) {
43                         free( bdb->bi_dbenv_home );
44                 }
45                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
46
47 #ifdef SLAP_BDB_ALLOW_DBNOTXN
48         /* turn off transactions, use CDB mode instead */
49         } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) {
50                 bdb->bi_txn = 0;
51 #endif
52         /* transaction checkpoint configuration */
53         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
54                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
55
56         /* transaction checkpoint configuration */
57         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
58                 if ( argc < 3 ) {
59                         fprintf( stderr, "%s: line %d: "
60                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
61                                 fname, lineno );
62                         return 1;
63                 }
64                 bdb->bi_txn_cp = 1;
65                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
66                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
67
68         /* lock detect configuration */
69         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
70 #ifndef NO_THREADS
71                 if ( argc < 3 ) {
72                         fprintf( stderr, "%s: line %d: "
73                                 "missing parameters in \"lockDetect <policy> <seconds>\" line\n",
74                                 fname, lineno );
75                         return 1;
76                 }
77
78                 if( strcasecmp( argv[1], "default" ) == 0 ) {
79                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
80
81                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
82                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
83
84                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
85                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
86
87                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
88                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
89
90                 } else {
91                         fprintf( stderr, "%s: line %d: "
92                                 "bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
93                                 fname, lineno, argv[1] );
94                         return 1;
95                 }
96
97                 bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
98                 if( bdb->bi_lock_detect_seconds < 1 ) {
99                         fprintf( stderr, "%s: line %d: "
100                                 "bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
101                                 fname, lineno, argv[2] );
102                         return 1;
103                 }
104 #else
105                 fprintf( stderr, "%s: line %d: "
106                         "NO THREADS: lockDetect line ignored\n",
107                         fname, lineno );
108 #endif
109
110         /* mode with which to create new database files */
111         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
112                 if ( argc < 2 ) {
113                         fprintf( stderr, "%s: line %d: "
114                                 "missing mode in \"mode <mode>\" line\n",
115                                 fname, lineno );
116                         return 1;
117                 }
118                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
119
120 #if BDB_FILTER_INDICES
121         /* attribute to index */
122         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
123                 int rc;
124                 if ( argc < 2 ) {
125                         fprintf( stderr, "%s: line %d: "
126                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
127                                 fname, lineno );
128                         return 1;
129                 } else if ( argc > 3 ) {
130                         fprintf( stderr, "%s: line %d: "
131                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
132                                 "line (ignored)\n",
133                                 fname, lineno );
134                 }
135                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
136
137                 if( rc != LDAP_SUCCESS ) return 1;
138 #endif
139
140         /* anything else */
141         } else {
142                 fprintf( stderr, "%s: line %d: "
143                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
144                         fname, lineno, argv[0] );
145         }
146
147         return 0;
148 }