1 /* $NetBSD: key.c,v 1.1.1.1 2014/05/28 09:58:50 tron Exp $ */ 2 3 /* index.c - routines for dealing with attribute indexes */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2000-2014 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 19 #include "portable.h" 20 21 #include <stdio.h> 22 23 #include <ac/string.h> 24 #include <ac/socket.h> 25 26 #include "slap.h" 27 #include "back-mdb.h" 28 #include "idl.h" 29 30 /* read a key */ 31 int 32 mdb_key_read( 33 Backend *be, 34 MDB_txn *txn, 35 MDB_dbi dbi, 36 struct berval *k, 37 ID *ids, 38 MDB_cursor **saved_cursor, 39 int get_flag 40 ) 41 { 42 int rc; 43 MDB_val key; 44 #ifndef MISALIGNED_OK 45 int kbuf[2]; 46 #endif 47 48 Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 ); 49 50 #ifndef MISALIGNED_OK 51 if (k->bv_len & ALIGNER) { 52 key.mv_size = sizeof(kbuf); 53 key.mv_data = kbuf; 54 kbuf[1] = 0; 55 memcpy(kbuf, k->bv_val, k->bv_len); 56 } else 57 #endif 58 { 59 key.mv_size = k->bv_len; 60 key.mv_data = k->bv_val; 61 } 62 63 rc = mdb_idl_fetch_key( be, txn, dbi, &key, ids, saved_cursor, get_flag ); 64 65 if( rc != LDAP_SUCCESS ) { 66 Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read: failed (%d)\n", 67 rc, 0, 0 ); 68 } else { 69 Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read %ld candidates\n", 70 (long) MDB_IDL_N(ids), 0, 0 ); 71 } 72 73 return rc; 74 } 75