1 /* OpenLDAP WiredTiger backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2016 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
18 * based on back-bdb for inclusion in OpenLDAP Software.
19 * WiredTiger is a product of MongoDB Inc.
30 mkrevdn(struct berval src){
35 p = dst = ch_malloc(src.bv_len + 2);
37 rdn = ber_bvrchr( &src, ',' );
40 src.bv_len = rdn - src.bv_val;
41 rdn_len -= src.bv_len + 1;
49 AC_MEMCPY( p, rdn, rdn_len );
65 WT_CURSOR *cursor = NULL;
68 Debug( LDAP_DEBUG_TRACE, "=> wt_dn2id_add 0x%lx: \"%s\"\n",
69 e->e_id, e->e_ndn, 0 );
70 assert( e->e_id != NOID );
73 revdn = mkrevdn(e->e_nname);
75 rc = session->open_cursor(session, WT_TABLE_DN2ID, NULL,
78 Debug( LDAP_DEBUG_ANY,
79 LDAP_XSTRING(wt_dn2id_add)
80 ": open_cursor failed: %s (%d)\n",
81 wiredtiger_strerror(rc), rc, 0 );
84 cursor->set_key(cursor, e->e_ndn);
85 cursor->set_value(cursor, e->e_id, pid, revdn);
86 rc = cursor->insert(cursor);
88 Debug( LDAP_DEBUG_ANY,
89 LDAP_XSTRING(wt_dn2id_add)
90 ": insert failed: %s (%d)\n",
91 wiredtiger_strerror(rc), rc, 0 );
100 cursor->close(cursor);
102 Debug( LDAP_DEBUG_TRACE, "<= wt_dn2id_add 0x%lx: %d\n", e->e_id, rc, 0 );
113 WT_CURSOR *cursor = NULL;
115 Debug( LDAP_DEBUG_TRACE, "=> wt_dn2id_delete %s\n", ndn->bv_val, 0, 0 );
117 rc = session->open_cursor(session, WT_TABLE_DN2ID, NULL,
120 Debug( LDAP_DEBUG_ANY,
121 LDAP_XSTRING(wt_dn2id_delete)
122 ": open_cursor failed: %s (%d)\n",
123 wiredtiger_strerror(rc), rc, 0 );
127 cursor->set_key(cursor, ndn->bv_val);
128 rc = cursor->remove(cursor);
130 Debug( LDAP_DEBUG_ANY,
131 LDAP_XSTRING(wt_dn2id_delete)
132 ": remove failed: %s (%d)\n",
133 wiredtiger_strerror(rc), rc, 0 );
137 Debug( LDAP_DEBUG_TRACE,
138 "<= wt_dn2id_delete %s: %d\n",
139 ndn->bv_val, rc, 0 );
142 cursor->close(cursor);
154 WT_CURSOR *cursor = NULL;
155 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
159 Debug( LDAP_DEBUG_TRACE, "=> wt_dn2id(\"%s\")\n",
162 if ( ndn->bv_len == 0 ) {
167 rc = session->open_cursor(session, WT_TABLE_DN2ID
169 NULL, NULL, &cursor);
171 Debug( LDAP_DEBUG_ANY,
172 LDAP_XSTRING(wt_dn2id)
173 ": cursor open failed: %s (%d)\n",
174 wiredtiger_strerror(rc), rc, 0 );
178 cursor->set_key(cursor, ndn->bv_val);
179 rc = cursor->search(cursor);
186 Debug( LDAP_DEBUG_ANY,
187 LDAP_XSTRING(wt_dn2id)
188 ": search failed: %s (%d)\n",
189 wiredtiger_strerror(rc), rc, 0 );
192 rc = cursor->get_value(cursor, id);
194 Debug( LDAP_DEBUG_ANY,
195 LDAP_XSTRING(wt_dn2id)
196 ": get_value failed: %s (%d)\n",
197 wiredtiger_strerror(rc), rc, 0 );
203 cursor->close(cursor);
207 Debug( LDAP_DEBUG_TRACE, "<= wt_dn2id: get failed: %s (%d)\n",
208 wiredtiger_strerror(rc), rc, 0 );
210 Debug( LDAP_DEBUG_TRACE, "<= wt_dn2id: got id=0x%lx\n",
218 wt_dn2id_has_children(
223 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
224 WT_CURSOR *cursor = NULL;
228 rc = session->open_cursor(session, WT_INDEX_PID,
229 NULL, NULL, &cursor);
231 Debug( LDAP_DEBUG_ANY,
232 LDAP_XSTRING(wt_dn2id_has_children)
233 ": cursor open failed: %s (%d)\n",
234 wiredtiger_strerror(rc), rc, 0 );
238 cursor->set_key(cursor, key);
239 rc = cursor->search(cursor);
243 cursor->close(cursor);
258 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
259 WT_CURSOR *cursor = NULL;
267 Debug( LDAP_DEBUG_TRACE,
268 "=> wt_dn2idl(\"%s\")\n",
271 if(op->ors_scope != LDAP_SCOPE_ONELEVEL &&
272 be_issuffix( op->o_bd, &e->e_nname )){
277 revdn = mkrevdn(*ndn);
278 revdn_len = strlen(revdn);
279 rc = session->open_cursor(session, WT_INDEX_REVDN"(id, pid)",
280 NULL, NULL, &cursor);
282 Debug( LDAP_DEBUG_ANY,
283 LDAP_XSTRING(wt_dn2idl)
284 ": cursor open failed: %s (%d)\n",
285 wiredtiger_strerror(rc), rc, 0 );
288 cursor->set_key(cursor, revdn);
289 rc = cursor->search_near(cursor, &exact);
291 Debug( LDAP_DEBUG_ANY,
292 LDAP_XSTRING(wt_dn2idl)
293 ": search failed: %s (%d)\n",
294 wiredtiger_strerror(rc), rc, 0 );
299 rc = cursor->get_key(cursor, &key);
301 Debug( LDAP_DEBUG_ANY,
302 LDAP_XSTRING(wt_dn2idl)
303 ": get_key failed: %s (%d)\n",
304 wiredtiger_strerror(rc), rc, 0 );
308 if( strncmp(revdn, key, revdn_len) ){
310 rc = cursor->next(cursor);
320 rc = cursor->get_value(cursor, &id, &pid);
322 Debug( LDAP_DEBUG_ANY,
323 LDAP_XSTRING(wt_dn2id)
324 ": get_value failed: %s (%d)\n",
325 wiredtiger_strerror(rc), rc, 0 );
328 if( op->ors_scope == LDAP_SCOPE_ONELEVEL &&
330 rc = cursor->next(cursor);
336 wt_idl_append_one(ids, id);
338 rc = cursor->next(cursor);
341 if (rc == WT_NOTFOUND ) {
350 cursor->close(cursor);
363 struct wt_info *wi = (struct wy_info *) op->o_bd->be_private;
364 WT_CURSOR *cursor = NULL;
366 Debug( LDAP_DEBUG_TRACE, "=> wt_dn2id(\"%s\")\n", dn->bv_val, 0, 0 );
368 rc = session->open_cursor(session, WT_INDEX_DN"(id)",
369 NULL, NULL, &cursor);
371 Debug( LDAP_DEBUG_ANY,
372 LDAP_XSTRING(wt_dn2id)
373 ": cursor open failed: %s (%d)\n",
374 wiredtiger_strerror(rc), rc, 0 );
377 cursor->set_key(cursor, dn->bv_val);
378 rc = cursor->search(cursor);
380 cursor->get_key(cursor, &id);
382 cursor->close(cursor);
389 * indent-tabs-mode: t