]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/config.c
428792378fc9bc4d50b6c6cd54c4532652bb5c6c
[openldap] / servers / slapd / back-ldbm / config.c
1 /* config.c - ldbm 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
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17
18
19 int
20 ldbm_back_config(
21     BackendInfo *bi,
22     const char  *fname,
23     int         lineno,
24     int         argc,
25     char        **argv
26 )
27 {
28         struct ldbm_backend_info *lbi =
29                 (struct ldbm_backend_info *) bi->bi_private;
30
31         if ( lbi == NULL ) {
32                 fprintf( stderr, "%s: line %d: ldbm backend info is null!\n",
33                     fname, lineno );
34                 return 1;
35         }
36
37         /* directory where database files live */
38         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
39                 if ( argc < 2 ) {
40                         fprintf( stderr,
41                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
42                             fname, lineno );
43                         return( 1 );
44                 }
45                 if ( lbi->lbi_directory ) {
46                         free( lbi->lbi_directory );
47                 }
48                 lbi->lbi_directory = ch_strdup( argv[1] );
49
50         /* anything else */
51         } else {
52                 fprintf( stderr,
53 "%s: line %d: unknown directive \"%s\" in ldbm backend definition (ignored)\n",
54                     fname, lineno, argv[0] );
55         }
56
57         return 0;
58 }
59
60 int
61 ldbm_back_db_config(
62     Backend     *be,
63     const char  *fname,
64     int         lineno,
65     int         argc,
66     char        **argv
67 )
68 {
69         int rc;
70         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
71
72         if ( li == NULL ) {
73                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
74                     fname, lineno );
75                 return( 1 );
76         }
77
78         /* directory where database files live */
79         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
80                 if ( argc < 2 ) {
81                         fprintf( stderr,
82                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
83                             fname, lineno );
84                         return( 1 );
85                 }
86                 if ( li->li_directory )
87                         free( li->li_directory );
88                 li->li_directory = ch_strdup( argv[1] );
89
90         /* mode with which to create new database files */
91         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
92                 if ( argc < 2 ) {
93                         fprintf( stderr,
94                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
95                             fname, lineno );
96                         return( 1 );
97                 }
98                 li->li_mode = strtol( argv[1], NULL, 0 );
99
100         /* attribute to index */
101         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
102                 if ( argc < 2 ) {
103                         fprintf( stderr,
104 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
105                             fname, lineno );
106                         return( 1 );
107                 } else if ( argc > 3 ) {
108                         fprintf( stderr,
109 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
110                             fname, lineno );
111                 }
112                 rc = attr_index_config( li, fname, lineno, argc - 1, &argv[1] );
113
114                 if( rc != LDAP_SUCCESS ) return 1;
115
116         /* size of the cache in entries */
117         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
118                 if ( argc < 2 ) {
119                         fprintf( stderr,
120                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
121                             fname, lineno );
122                         return( 1 );
123                 }
124                 li->li_cache.c_maxsize = atoi( argv[1] );
125
126         /* size of each dbcache in bytes */
127         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
128                 if ( argc < 2 ) {
129                         fprintf( stderr,
130                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
131                             fname, lineno );
132                         return( 1 );
133                 }
134                 li->li_dbcachesize = atoi( argv[1] );
135
136         /* no locking (not safe) */
137         } else if ( strcasecmp( argv[0], "dbnolocking" ) == 0 ) {
138                 li->li_dblocking = 0;
139
140         /* no write sync (not safe) */
141         } else if ( ( strcasecmp( argv[0], "dbnosync" ) == 0 )
142                 || ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) )
143         {
144                 li->li_dbwritesync = 0;
145
146         /* anything else */
147         } else {
148                 fprintf( stderr,
149 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
150                     fname, lineno, argv[0] );
151         }
152
153         return 0;
154 }