summaryrefslogtreecommitdiff
path: root/usr.sbin/ldapd
diff options
context:
space:
mode:
authorMartin Hedenfal <martinh@cvs.openbsd.org>2010-07-02 01:43:01 +0000
committerMartin Hedenfal <martinh@cvs.openbsd.org>2010-07-02 01:43:01 +0000
commit7972b7daae82d0de24e15b162d5df2a3e9205297 (patch)
tree24de9b8caf6b1ac64052fc38537137be34f82472 /usr.sbin/ldapd
parent4b4319aebff370a2f5a571161480688b172a6dd8 (diff)
Add a BT_CURSOR_EXACT operation to btree_cursor_get. It behaves like
BT_CURSOR, but fails if the key is not found.
Diffstat (limited to 'usr.sbin/ldapd')
-rw-r--r--usr.sbin/ldapd/btree.c23
-rw-r--r--usr.sbin/ldapd/btree.h3
2 files changed, 19 insertions, 7 deletions
diff --git a/usr.sbin/ldapd/btree.c b/usr.sbin/ldapd/btree.c
index 127c24f6d2f..9d3b6590871 100644
--- a/usr.sbin/ldapd/btree.c
+++ b/usr.sbin/ldapd/btree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btree.c,v 1.21 2010/07/02 01:08:35 martinh Exp $ */
+/* $OpenBSD: btree.c,v 1.22 2010/07/02 01:43:00 martinh Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -284,7 +284,7 @@ static int btree_sibling(struct cursor *cursor, int move_right);
static int btree_cursor_next(struct cursor *cursor,
struct btval *key, struct btval *data);
static int btree_cursor_set(struct cursor *cursor,
- struct btval *key, struct btval *data);
+ struct btval *key, struct btval *data, int *exactp);
static int btree_cursor_first(struct cursor *cursor,
struct btval *key, struct btval *data);
@@ -1709,7 +1709,8 @@ btree_cursor_next(struct cursor *cursor, struct btval *key, struct btval *data)
}
static int
-btree_cursor_set(struct cursor *cursor, struct btval *key, struct btval *data)
+btree_cursor_set(struct cursor *cursor, struct btval *key, struct btval *data,
+ int *exactp)
{
int rc;
struct node *leaf;
@@ -1726,7 +1727,13 @@ btree_cursor_set(struct cursor *cursor, struct btval *key, struct btval *data)
assert(IS_LEAF(mp));
top = CURSOR_TOP(cursor);
- leaf = btree_search_node(cursor->bt, mp, key, NULL, &top->ki);
+ leaf = btree_search_node(cursor->bt, mp, key, exactp, &top->ki);
+ if (exactp != NULL && !*exactp) {
+ /* BT_CURSOR_EXACT specified and not an exact match. */
+ errno = ENOENT;
+ return BT_FAIL;
+ }
+
if (leaf == NULL) {
DPRINTF("===> inexact leaf not found, goto sibling");
if (btree_sibling(cursor, 1) != BT_SUCCESS)
@@ -1782,18 +1789,22 @@ btree_cursor_get(struct cursor *cursor, struct btval *key, struct btval *data,
enum cursor_op op)
{
int rc;
+ int exact = 0;
assert(cursor);
switch (op) {
case BT_CURSOR:
+ case BT_CURSOR_EXACT:
while (CURSOR_TOP(cursor) != NULL)
cursor_pop_page(cursor);
if (key == NULL || key->size == 0 || key->size > MAXKEYSIZE) {
errno = EINVAL;
rc = BT_FAIL;
- } else
- rc = btree_cursor_set(cursor, key, data);
+ } else if (op == BT_CURSOR_EXACT)
+ rc = btree_cursor_set(cursor, key, data, &exact);
+ else
+ rc = btree_cursor_set(cursor, key, data, NULL);
break;
case BT_NEXT:
if (!cursor->initialized)
diff --git a/usr.sbin/ldapd/btree.h b/usr.sbin/ldapd/btree.h
index 161a8a8ca36..a9eca5af2f3 100644
--- a/usr.sbin/ldapd/btree.h
+++ b/usr.sbin/ldapd/btree.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: btree.h,v 1.5 2010/06/23 13:10:14 martinh Exp $ */
+/* $OpenBSD: btree.h,v 1.6 2010/07/02 01:43:00 martinh Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -42,6 +42,7 @@ typedef void (*bt_prefix_func)(const struct btval *a,
enum cursor_op { /* cursor operations */
BT_CURSOR, /* position at given key */
+ BT_CURSOR_EXACT, /* position at key, or fail */
BT_FIRST,
BT_NEXT,
BT_LAST, /* not implemented */