1 /* OpenLDAP WiredTiger backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2017 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.
25 static int wt_id2entry_put(
32 WT_CURSOR *cursor = NULL;
36 rc = entry_encode( e, &bv );
37 if(rc != LDAP_SUCCESS){
40 item.size = bv.bv_len;
41 item.data = bv.bv_val;
43 rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL,
46 Debug( LDAP_DEBUG_ANY,
47 LDAP_XSTRING(wt_id2entry_put)
48 ": open_cursor failed: %s (%d)\n",
49 wiredtiger_strerror(rc), rc, 0 );
52 cursor->set_key(cursor, e->e_id);
53 cursor->set_value(cursor, e->e_ndn, &item);
54 rc = cursor->insert(cursor);
56 Debug( LDAP_DEBUG_ANY,
57 LDAP_XSTRING(wt_id2entry_put)
58 ": insert failed: %s (%d)\n",
59 wiredtiger_strerror(rc), rc, 0 );
66 cursor->close(cursor);
76 return wt_id2entry_put(op, session, e, "overwrite=false");
79 int wt_id2entry_update(
84 return wt_id2entry_put(op, session, e, "overwrite=true");
87 int wt_id2entry_delete(
93 WT_CURSOR *cursor = NULL;
94 rc = session->open_cursor(session, WT_TABLE_ID2ENTRY, NULL,
97 Debug( LDAP_DEBUG_ANY,
98 LDAP_XSTRING(wt_id2entry_delete)
99 ": open_cursor failed: %s (%d)\n",
100 wiredtiger_strerror(rc), rc, 0 );
103 cursor->set_key(cursor, e->e_id);
104 rc = cursor->remove(cursor);
106 Debug( LDAP_DEBUG_ANY,
107 LDAP_XSTRING(wt_id2entry_delete)
108 ": remove failed: %s (%d)\n",
109 wiredtiger_strerror(rc), rc, 0 );
115 cursor->close(cursor);
120 int wt_id2entry( BackendDB *be,
125 WT_CURSOR *cursor = NULL;
131 rc = session->open_cursor(session, WT_TABLE_ID2ENTRY"(entry)", NULL,
134 Debug( LDAP_DEBUG_ANY,
135 LDAP_XSTRING(wt_id2entry)
136 ": open_cursor failed: %s (%d)\n",
137 wiredtiger_strerror(rc), rc, 0 );
141 cursor->set_key(cursor, id);
142 rc = cursor->search(cursor);
147 cursor->get_value(cursor, &item);
148 rc = wt_entry_header( &item, &eh );
149 eoff = eh.data - (char *)item.data;
150 eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size;
151 eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
152 memset(eh.bv.bv_val, 0xff, eh.bv.bv_len);
153 eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
154 memcpy(eh.data, item.data, item.size);
156 rc = entry_decode( &eh, &e );
158 Debug( LDAP_DEBUG_ANY,
159 LDAP_XSTRING(wt_id2entry)
160 ": entry decode error: %s (%d)\n",
169 cursor->close(cursor);
182 /* Our entries are allocated in two blocks; the data comes from
183 * the db itself and the Entry structure and associated pointers
184 * are allocated in entry_decode. The db data pointer is saved
187 if ( e->e_bv.bv_val ) {
189 /* See if the DNs were changed by modrdn */
190 if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
191 e->e_bv.bv_val + e->e_bv.bv_len ) {
192 ch_free(e->e_name.bv_val);
193 ch_free(e->e_nname.bv_val);
196 e->e_name.bv_val = NULL;
197 e->e_nname.bv_val = NULL;
198 /* In tool mode the e_bv buffer is realloc'd, leave it alone */
199 if( !(slapMode & SLAP_TOOL_MODE) ) {
200 free( e->e_bv.bv_val );
202 BER_BVZERO( &e->e_bv );
208 int wt_entry_release(
213 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
214 return wt_entry_return( e );
218 * return LDAP_SUCCESS IFF we can retrieve the specified entry.
224 AttributeDescription *at,
233 * indent-tabs-mode: t