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