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