xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-mdb/key.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1 /*	$NetBSD: key.c,v 1.3 2021/08/14 16:15:00 christos 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-2021 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 <sys/cdefs.h>
20 __RCSID("$NetBSD: key.c,v 1.3 2021/08/14 16:15:00 christos Exp $");
21 
22 #include "portable.h"
23 
24 #include <stdio.h>
25 
26 #include <ac/string.h>
27 #include <ac/socket.h>
28 
29 #include "slap.h"
30 #include "back-mdb.h"
31 #include "idl.h"
32 
33 /* read a key */
34 int
mdb_key_read(Backend * be,MDB_txn * txn,MDB_dbi dbi,struct berval * k,ID * ids,MDB_cursor ** saved_cursor,int get_flag)35 mdb_key_read(
36 	Backend	*be,
37 	MDB_txn *txn,
38 	MDB_dbi dbi,
39 	struct berval *k,
40 	ID *ids,
41 	MDB_cursor **saved_cursor,
42 	int get_flag
43 )
44 {
45 	int rc;
46 	MDB_val key;
47 #ifndef MISALIGNED_OK
48 	int kbuf[2];
49 #endif
50 
51 	Debug( LDAP_DEBUG_TRACE, "=> key_read\n" );
52 
53 #ifndef MISALIGNED_OK
54 	if (k->bv_len & ALIGNER) {
55 		key.mv_size = sizeof(kbuf);
56 		key.mv_data = kbuf;
57 		kbuf[1] = 0;
58 		memcpy(kbuf, k->bv_val, k->bv_len);
59 	} else
60 #endif
61 	{
62 		key.mv_size = k->bv_len;
63 		key.mv_data = k->bv_val;
64 	}
65 
66 	rc = mdb_idl_fetch_key( be, txn, dbi, &key, ids, saved_cursor, get_flag );
67 
68 	if( rc != LDAP_SUCCESS ) {
69 		Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read: failed (%d)\n",
70 			rc );
71 	} else {
72 		Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read %ld candidates\n",
73 			(long) MDB_IDL_N(ids) );
74 	}
75 
76 	return rc;
77 }
78