summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-11-08 14:15:25 +0100
committerMichael Adam <obnox@samba.org>2012-11-29 17:24:35 +0100
commit8300791a6765499bcc8b892863d319f59332d9e3 (patch)
tree53dc4b7ca7d2e0c163315d83c57c09a8c4cd60a1 /lib
parent26a0ee5a0d915961067050564197a3d44b22d1e3 (diff)
downloadsamba-8300791a6765499bcc8b892863d319f59332d9e3.tar.gz
samba-8300791a6765499bcc8b892863d319f59332d9e3.tar.bz2
samba-8300791a6765499bcc8b892863d319f59332d9e3.zip
dbwrap: Use dbwrap_parse_record in dbwrap_fetch_uint32_bystring
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/dbwrap/dbwrap_util.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/lib/dbwrap/dbwrap_util.c b/lib/dbwrap/dbwrap_util.c
index d0a34cc906..4185fff9dd 100644
--- a/lib/dbwrap/dbwrap_util.c
+++ b/lib/dbwrap/dbwrap_util.c
@@ -97,32 +97,46 @@ NTSTATUS dbwrap_store_int32_bystring(struct db_context *db, const char *keystr,
return status;
}
+struct dbwrap_fetch_uint32_state {
+ NTSTATUS status;
+ uint32_t result;
+};
+
+static void dbwrap_fetch_uint32_parser(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct dbwrap_fetch_uint32_state *state =
+ (struct dbwrap_fetch_uint32_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_uint32_bystring(struct db_context *db,
const char *keystr, uint32_t *val)
{
- TDB_DATA dbuf;
+ struct dbwrap_fetch_uint32_state state;
NTSTATUS status;
if (val == NULL) {
return NT_STATUS_INVALID_PARAMETER;
}
- status = dbwrap_fetch_bystring(db, talloc_tos(), keystr, &dbuf);
+ state.status = NT_STATUS_INTERNAL_ERROR;
+
+ status = dbwrap_parse_record(db, string_term_tdb_data(keystr),
+ dbwrap_fetch_uint32_parser, &state);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
-
- if ((dbuf.dptr == NULL) || (dbuf.dsize == 0)) {
- return NT_STATUS_NOT_FOUND;
- }
- if (dbuf.dsize != sizeof(uint32_t)) {
- TALLOC_FREE(dbuf.dptr);
- return NT_STATUS_UNSUCCESSFUL;
+ if (NT_STATUS_IS_OK(state.status)) {
+ *val = state.result;
}
-
- *val = IVAL(dbuf.dptr, 0);
- TALLOC_FREE(dbuf.dptr);
- return NT_STATUS_OK;
+ return state.status;
}
NTSTATUS dbwrap_store_uint32_bystring(struct db_context *db,