config.c revision 1.1.1.2 1 /* $NetBSD: config.c,v 1.1.1.2 2025/09/05 21:09:50 christos Exp $ */
2
3 /* OpenLDAP WiredTiger backend */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2002-2024 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18 /* ACKNOWLEDGEMENTS:
19 * This work was developed by HAMANO Tsukasa <hamano (at) osstech.co.jp>
20 * based on back-bdb for inclusion in OpenLDAP Software.
21 * WiredTiger is a product of MongoDB Inc.
22 */
23
24 #include <sys/cdefs.h>
25 __RCSID("$NetBSD: config.c,v 1.1.1.2 2025/09/05 21:09:50 christos Exp $");
26
27 #include "portable.h"
28
29 #include <stdio.h>
30 #include <ac/string.h>
31 #include "back-wt.h"
32 #include "slap-config.h"
33
34 #include "lutil.h"
35 #include "ldap_rq.h"
36
37 static ConfigDriver wt_cf_gen;
38
39 enum {
40 WT_DIRECTORY = 1,
41 WT_CONFIG,
42 WT_INDEX,
43 WT_MODE,
44 WT_IDLCACHE,
45 };
46
47 static ConfigTable wtcfg[] = {
48 { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_DIRECTORY,
49 wt_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
50 "DESC 'Directory for database content' "
51 "EQUALITY caseIgnoreMatch "
52 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
53 { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|WT_INDEX,
54 wt_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
55 "DESC 'Attribute index parameters' "
56 "EQUALITY caseIgnoreMatch "
57 "SYNTAX OMsDirectoryString )", NULL, NULL },
58 { "mode", "mode", 2, 2, 0, ARG_MAGIC|WT_MODE,
59 wt_cf_gen, "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
60 "DESC 'Unix permissions of database files' "
61 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
62 { "wtconfig", "config", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_CONFIG,
63 wt_cf_gen, "( OLcfgDbAt:13.1 NAME 'olcWtConfig' "
64 "DESC 'Configuration for WiredTiger' "
65 "EQUALITY caseIgnoreMatch "
66 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
67 { "idlcache", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|WT_IDLCACHE,
68 wt_cf_gen, "( OLcfgDbAt:13.2 NAME 'olcIDLcache' "
69 "DESC 'enable IDL cache' "
70 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
71 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
72 NULL, NULL, NULL, NULL }
73 };
74
75 static ConfigOCs wtocs[] = {
76 { "( OLcfgDbOc:13.1 "
77 "NAME 'olcWtConfig' "
78 "DESC 'Wt backend configuration' "
79 "SUP olcDatabaseConfig "
80 "MUST olcDbDirectory "
81 "MAY ( olcWtConfig $ olcDbIndex $ olcDbMode $ olcIDLcache) )",
82 Cft_Database, wtcfg },
83 { NULL, 0, NULL }
84 };
85
86 /* reindex entries on the fly */
87 static void *
88 wt_online_index( void *ctx, void *arg )
89 {
90 // Not implement yet
91 return NULL;
92 }
93
94 /* Cleanup loose ends after Modify completes */
95 static int
96 wt_cf_cleanup( ConfigArgs *c )
97 {
98 // Not implement yet
99 return 0;
100 }
101
102 static int
103 wt_cf_gen( ConfigArgs *c )
104 {
105 struct wt_info *wi = (struct wt_info *) c->be->be_private;
106 int rc;
107
108 if( c->op == SLAP_CONFIG_EMIT ) {
109 rc = 0;
110 switch( c->type ) {
111 case WT_DIRECTORY:
112 if ( wi->wi_home ) {
113 c->value_string = ch_strdup( wi->wi_home );
114 } else {
115 rc = 1;
116 }
117 break;
118 case WT_INDEX:
119 wt_attr_index_unparse( wi, &c->rvalue_vals );
120 if ( !c->rvalue_vals ) rc = 1;
121 break;
122 case WT_IDLCACHE:
123 if ( wi->wi_flags & WT_USE_IDLCACHE) {
124 c->value_int = 1;
125 }
126 break;
127 }
128 return rc;
129 } else if ( c->op == LDAP_MOD_DELETE ) {
130 rc = 0;
131 return rc;
132 }
133
134 switch( c->type ) {
135 case WT_DIRECTORY:
136 ch_free( wi->wi_home );
137 wi->wi_home = c->value_string;
138 break;
139 case WT_CONFIG:
140 if(strlen(wi->wi_config) + 1 + strlen(c->value_string) > WT_CONFIG_MAX){
141 fprintf( stderr, "%s: "
142 "\"wtconfig\" are too long. Increase WT_CONFIG_MAX or you may realloc the buffer.\n",
143 c->log );
144 return 1;
145 }
146 /* size of wi->wi_config is WT_CONFIG_MAX + 1, it's guaranteed with NUL-terminate. */
147 strcat(wi->wi_config, ",");
148 strcat(wi->wi_config, c->value_string);
149 break;
150
151 case WT_INDEX:
152 rc = wt_attr_index_config( wi, c->fname, c->lineno,
153 c->argc - 1, &c->argv[1], &c->reply);
154
155 if( rc != LDAP_SUCCESS ) return 1;
156 wi->wi_flags |= WT_OPEN_INDEX;
157
158 if ( wi->wi_flags & WT_IS_OPEN ) {
159 config_push_cleanup( c, wt_cf_cleanup );
160
161 if ( !wi->wi_index_task ) {
162 /* Start the task as soon as we finish here. Set a long
163 * interval (10 hours) so that it only gets scheduled once.
164 */
165 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
166 fprintf( stderr, "%s: "
167 "\"index\" must occur after \"suffix\".\n",
168 c->log );
169 return 1;
170 }
171 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
172 wi->wi_index_task = ldap_pvt_runqueue_insert(&slapd_rq, 36000,
173 wt_online_index, c->be,
174 LDAP_XSTRING(wt_online_index),
175 c->be->be_suffix[0].bv_val );
176 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
177 }
178 }
179 break;
180
181 case WT_MODE:
182 fprintf( stderr, "%s: "
183 "back-wt does not support \"mode\" option. use umask instead.\n",
184 c->log );
185 return 1;
186
187 case WT_IDLCACHE:
188 if ( c->value_int ) {
189 wi->wi_flags |= WT_USE_IDLCACHE;
190 } else {
191 wi->wi_flags &= ~WT_USE_IDLCACHE;
192 }
193 break;
194 }
195 return LDAP_SUCCESS;
196 }
197
198 int wt_back_init_cf( BackendInfo *bi )
199 {
200 int rc;
201 bi->bi_cf_ocs = wtocs;
202
203 rc = config_register_schema( wtcfg, wtocs );
204 if ( rc ) return rc;
205 return 0;
206 }
207
208 /*
209 * Local variables:
210 * indent-tabs-mode: t
211 * tab-width: 4
212 * c-basic-offset: 4
213 * End:
214 */
215