]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/config.c
Cleanup result handling
[openldap] / servers / slapd / back-ldbm / config.c
1 /* config.c - ldbm backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-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
21 #include <ac/socket.h>
22 #include <ac/string.h>
23
24 #include "slap.h"
25 #include "back-ldbm.h"
26
27 int
28 ldbm_back_db_config(
29     Backend     *be,
30     const char  *fname,
31     int         lineno,
32     int         argc,
33     char        **argv
34 )
35 {
36         int rc;
37         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38
39         if ( li == NULL ) {
40                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
41                     fname, lineno );
42                 return( 1 );
43         }
44
45         /* directory where database files live */
46         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
47                 if ( argc < 2 ) {
48                         fprintf( stderr,
49                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
50                             fname, lineno );
51                         return( 1 );
52                 }
53                 if ( li->li_directory )
54                         free( li->li_directory );
55                 li->li_directory = ch_strdup( argv[1] );
56
57         /* mode with which to create new database files */
58         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
59                 if ( argc < 2 ) {
60                         fprintf( stderr,
61                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
62                             fname, lineno );
63                         return( 1 );
64                 }
65                 li->li_mode = strtol( argv[1], NULL, 0 );
66
67         /* attribute to index */
68         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
69                 if ( argc < 2 ) {
70                         fprintf( stderr,
71 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
72                             fname, lineno );
73                         return( 1 );
74                 } else if ( argc > 3 ) {
75                         fprintf( stderr,
76 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
77                             fname, lineno );
78                 }
79                 rc = attr_index_config( li, fname, lineno, argc - 1, &argv[1] );
80
81                 if( rc != LDAP_SUCCESS ) return 1;
82
83         /* size of the cache in entries */
84         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
85                 if ( argc < 2 ) {
86                         fprintf( stderr,
87                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
88                             fname, lineno );
89                         return( 1 );
90                 }
91                 li->li_cache.c_maxsize = atoi( argv[1] );
92
93         /* size of each dbcache in bytes */
94         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
95                 if ( argc < 2 ) {
96                         fprintf( stderr,
97                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
98                             fname, lineno );
99                         return( 1 );
100                 }
101                 li->li_dbcachesize = atoi( argv[1] );
102
103         /* no locking (not safe) */
104         } else if ( strcasecmp( argv[0], "dbnolocking" ) == 0 ) {
105                 li->li_dblocking = 0;
106
107         /* no write sync (not safe) */
108         } else if ( ( strcasecmp( argv[0], "dbnosync" ) == 0 )
109                 || ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) )
110         {
111                 li->li_dbwritesync = 0;
112
113         /* run sync thread */
114         } else if ( strcasecmp( argv[0], "dbsync" ) == 0 ) {
115 #ifndef NO_THREADS
116                 int i;
117                 if ( argc < 2 ) {
118 #ifdef NEW_LOGGING
119                         LDAP_LOG ( CONFIG, ERR, "ldbm_back_db_config: %s: "
120                                 "line %d: missing frequency value in \"dbsync <frequency> "
121                                 "[<wait-times> [wait-interval]]\" line\n", fname, lineno, 0 );
122 #else   
123                         Debug( LDAP_DEBUG_ANY,
124     "%s: line %d: missing frquency value in \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
125                             fname, lineno, 0 );
126 #endif
127                         return 1;
128                 }
129
130                 i = atoi( argv[1] );
131
132                 if( i < 0 ) {
133 #ifdef NEW_LOGGING
134                         LDAP_LOG ( CONFIG, ERR, 
135                                 "ldbm_back_db_config: %s: "
136                                 "line %d: frequency value (%d) invalid \"dbsync "
137                                 "<frequency> [<wait-times> [wait-interval]]\" line\n", 
138                                 fname, lineno, i );
139 #else   
140                         Debug( LDAP_DEBUG_ANY,
141     "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
142                             fname, lineno, i );
143 #endif
144                         return 1;
145                 }
146
147                 li->li_dbsyncfreq = i;
148
149                 if ( argc > 2 ) {
150                         i = atoi( argv[2] );
151                         if ( i < 0 ) {
152 #ifdef NEW_LOGGING
153                                 LDAP_LOG ( CONFIG,ERR, "ldbm_back_db_config: %s: "
154                                         "line %d: frequency value (%d) invalid \"dbsync "
155                                         "<frequency> [<wait-times> [wait-interval]]\" line\n", 
156                                         fname, lineno, i );
157 #else   
158                                 Debug( LDAP_DEBUG_ANY,
159             "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
160                                     fname, lineno, i );
161 #endif
162                                 return 1;
163                         }
164                         li ->li_dbsyncwaitn = i;
165                 }
166
167                 if ( argc > 3 ) {
168                         i = atoi( argv[3] );
169                         if ( i <= 0 ) {
170 #ifdef NEW_LOGGING
171                                 LDAP_LOG ( CONFIG,ERR, "ldbm_back_db_config: %s: "
172                                         "line %d: frequency value (%d) invalid \"dbsync "
173                                         "<frequency> [<wait-times> [wait-interval]]\" line\n", 
174                                         fname, lineno, i );
175 #else   
176                                 Debug( LDAP_DEBUG_ANY,
177             "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
178                                     fname, lineno, i );
179 #endif
180                                 return 1;
181                         }
182                         li ->li_dbsyncwaitinterval = i;
183                 }
184
185                 /* turn off writesync when sync policy is in place */
186                 li->li_dbwritesync = 0;
187
188 #else
189 #ifdef NEW_LOGGING
190                 LDAP_LOG ( CONFIG, ERR, "ldbm_back_db_config: \"dbsync\""
191                         " policies not supported in non-threaded environments\n", 0, 0, 0 );
192 #else   
193                 Debug( LDAP_DEBUG_ANY,
194     "\"dbsync\" policies not supported in non-threaded environments\n", 0, 0, 0);
195 #endif
196                 return 1;
197 #endif
198
199
200         /* anything else */
201         } else {
202                 return SLAP_CONF_UNKNOWN;
203         }
204
205         return 0;
206 }