1 /* OpenLDAP WiredTiger backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2015 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);
144 Debug( LDAP_DEBUG_ANY,
145 LDAP_XSTRING(wt_id2entry)
146 ": search failed: %s (%d)\n",
147 wiredtiger_strerror(rc), rc, 0 );
151 cursor->get_value(cursor, &item);
152 rc = wt_entry_header( &item, &eh );
153 eoff = eh.data - (char *)item.data;
154 eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size;
155 eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
156 memset(eh.bv.bv_val, 0xff, eh.bv.bv_len);
157 eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
158 memcpy(eh.data, item.data, item.size);
160 rc = entry_decode( &eh, &e );
162 Debug( LDAP_DEBUG_ANY,
163 LDAP_XSTRING(wt_id2entry)
164 ": entry decode error: %s (%d)\n",
173 cursor->close(cursor);
186 /* Our entries are allocated in two blocks; the data comes from
187 * the db itself and the Entry structure and associated pointers
188 * are allocated in entry_decode. The db data pointer is saved
191 if ( e->e_bv.bv_val ) {
193 /* See if the DNs were changed by modrdn */
194 if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
195 e->e_bv.bv_val + e->e_bv.bv_len ) {
196 ch_free(e->e_name.bv_val);
197 ch_free(e->e_nname.bv_val);
200 e->e_name.bv_val = NULL;
201 e->e_nname.bv_val = NULL;
202 /* In tool mode the e_bv buffer is realloc'd, leave it alone */
203 if( !(slapMode & SLAP_TOOL_MODE) ) {
204 free( e->e_bv.bv_val );
206 BER_BVZERO( &e->e_bv );
212 int wt_entry_release(
217 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
218 return wt_entry_return( e );
222 * return LDAP_SUCCESS IFF we can retrieve the specified entry.
228 AttributeDescription *at,
237 * indent-tabs-mode: t