summaryrefslogtreecommitdiff
path: root/lib/dbwrap
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-06-12 12:58:47 +0200
committerStefan Metzmacher <metze@samba.org>2012-06-22 15:16:52 +0200
commitd7b9e0d19a72783b45610dcf006571817338b50f (patch)
tree3853e1137b24fdfc011d9390d395957e09c42286 /lib/dbwrap
parent770d9affd721f05c4729d26dbc674cac491fba7c (diff)
downloadsamba-d7b9e0d19a72783b45610dcf006571817338b50f.tar.gz
samba-d7b9e0d19a72783b45610dcf006571817338b50f.tar.bz2
samba-d7b9e0d19a72783b45610dcf006571817338b50f.zip
dbwrap: Convert fetch_int32 to dbwrap_parse_record
Now dbwrap_fetch_int32 is used in smbd/locking/posix.c is used a lot more often than before. Signed-off-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib/dbwrap')
-rw-r--r--lib/dbwrap/dbwrap_util.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/dbwrap/dbwrap_util.c b/lib/dbwrap/dbwrap_util.c
index 8f2e99744a..b1efae7221 100644
--- a/lib/dbwrap/dbwrap_util.c
+++ b/lib/dbwrap/dbwrap_util.c
@@ -26,29 +26,40 @@
#include "dbwrap.h"
#include "lib/util/util_tdb.h"
+struct dbwrap_fetch_int32_state {
+ NTSTATUS status;
+ int32_t result;
+};
+
+static void dbwrap_fetch_int32_parser(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct dbwrap_fetch_int32_state *state =
+ (struct dbwrap_fetch_int32_state *)private_data;
+
+ if (data.dsize != sizeof(state->result)) {
+ state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+ return;
+ }
+ state->result = IVAL(data.dptr, 0);
+ state->status = NT_STATUS_OK;
+}
+
NTSTATUS dbwrap_fetch_int32(struct db_context *db, TDB_DATA key,
int32_t *result)
{
- TDB_DATA dbuf;
- NTSTATUS status;
+ struct dbwrap_fetch_int32_state state;
if (result == NULL) {
return NT_STATUS_INVALID_PARAMETER;
}
- status = dbwrap_fetch(db, talloc_tos(), key, &dbuf);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ dbwrap_parse_record(db, key, dbwrap_fetch_int32_parser, &state);
- if ((dbuf.dptr == NULL) || (dbuf.dsize != sizeof(int32_t))) {
- TALLOC_FREE(dbuf.dptr);
- return NT_STATUS_NOT_FOUND;
+ if (NT_STATUS_IS_OK(state.status)) {
+ *result = state.result;
}
-
- *result = IVAL(dbuf.dptr, 0);
- TALLOC_FREE(dbuf.dptr);
- return NT_STATUS_OK;
+ return state.status;
}
NTSTATUS dbwrap_fetch_int32_bystring(struct db_context *db, const char *keystr,