diff options
author | Martin Hedenfal <martinh@cvs.openbsd.org> | 2010-06-11 07:41:17 +0000 |
---|---|---|
committer | Martin Hedenfal <martinh@cvs.openbsd.org> | 2010-06-11 07:41:17 +0000 |
commit | 1c1419feb1cfe521285f48db35280b345d40eeb7 (patch) | |
tree | 3d3dd61963d0135050fa4ae157f26867aaae45f3 | |
parent | c6279aa0d1afd203ef60acbc76a1347ab34a9a79 (diff) |
Allow functions that accept both a btree and a txn argument to be passed a
NULL btree pointer. In that case the btree is taken from the transaction.
If both a btree and txn pointer is passed, make sure the transaction is
actually opened on the specified btree.
-rw-r--r-- | usr.sbin/ldapd/btree.c | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/usr.sbin/ldapd/btree.c b/usr.sbin/ldapd/btree.c index f1ae013b6a3..a1ca9a3d196 100644 --- a/usr.sbin/ldapd/btree.c +++ b/usr.sbin/ldapd/btree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btree.c,v 1.6 2010/06/11 05:29:22 martinh Exp $ */ +/* $OpenBSD: btree.c,v 1.7 2010/06/11 07:41:16 martinh Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se> @@ -1418,11 +1418,23 @@ btree_txn_get(struct btree *bt, struct btree_txn *txn, struct node *leaf; struct mpage *mp; - assert(bt); assert(key); assert(data); DPRINTF("===> get key [%.*s]", (int)key->size, (char *)key->data); + if (bt != NULL && txn != NULL && bt != txn->bt) { + errno = EINVAL; + return BT_FAIL; + } + + if (bt == NULL) { + if (txn == NULL) { + errno = EINVAL; + return BT_FAIL; + } + bt = txn->bt; + } + if (key->size == 0 || key->size > MAXKEYSIZE) { errno = EINVAL; return BT_FAIL; @@ -1896,6 +1908,19 @@ btree_txn_cursor_open(struct btree *bt, struct btree_txn *txn) { struct cursor *cursor; + if (bt != NULL && txn != NULL && bt != txn->bt) { + errno = EINVAL; + return NULL; + } + + if (bt == NULL) { + if (txn == NULL) { + errno = EINVAL; + return NULL; + } + bt = txn->bt; + } + if ((cursor = calloc(1, sizeof(*cursor))) != NULL) { SLIST_INIT(&cursor->stack); cursor->bt = bt; @@ -2385,9 +2410,21 @@ btree_txn_del(struct btree *bt, struct btree_txn *txn, DPRINTF("========> delete key %.*s", (int)key->size, (char *)key->data); - assert(bt != NULL); assert(key != NULL); + if (bt != NULL && txn != NULL && bt != txn->bt) { + errno = EINVAL; + return BT_FAIL; + } + + if (bt == NULL) { + if (txn == NULL) { + errno = EINVAL; + return BT_FAIL; + } + bt = txn->bt; + } + if (key->size == 0 || key->size > MAXKEYSIZE) { errno = EINVAL; return BT_FAIL; @@ -2682,10 +2719,22 @@ btree_txn_put(struct btree *bt, struct btree_txn *txn, struct mpage *mp; struct btval xkey; - assert(bt != NULL); assert(key != NULL); assert(data != NULL); + if (bt != NULL && txn != NULL && bt != txn->bt) { + errno = EINVAL; + return BT_FAIL; + } + + if (bt == NULL) { + if (txn == NULL) { + errno = EINVAL; + return BT_FAIL; + } + bt = txn->bt; + } + if (key->size == 0 || key->size > MAXKEYSIZE) { errno = EINVAL; return BT_FAIL; |