summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-03-28 09:42:37 +0100
committerStefan Metzmacher <metze@samba.org>2008-04-01 14:04:22 +0200
commitd20f88c60302b9af21b3a04e1ebc536a0e0c0e36 (patch)
treebaea8c2c768a1df866fbff740df7b5bb585e3572 /source3/lib
parent2fe572d0438fd21f620427b793b65c54d08c7c74 (diff)
downloadsamba-d20f88c60302b9af21b3a04e1ebc536a0e0c0e36.tar.gz
samba-d20f88c60302b9af21b3a04e1ebc536a0e0c0e36.tar.bz2
samba-d20f88c60302b9af21b3a04e1ebc536a0e0c0e36.zip
Add dbwrap_[fetch|store]_uint32
Signed-off-by: Stefan Metzmacher <metze@samba.org> (This used to be commit f1dd915ce802645166e0c8fc79d18d5ad41cfe7a)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/dbwrap_util.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c
index 1572f01723..01d70556d8 100644
--- a/source3/lib/dbwrap_util.c
+++ b/source3/lib/dbwrap_util.c
@@ -59,6 +59,45 @@ int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v)
return NT_STATUS_IS_OK(status) ? 0 : -1;
}
+bool dbwrap_fetch_uint32(struct db_context *db, const char *keystr,
+ uint32_t *val)
+{
+ TDB_DATA dbuf;
+
+ if (db->fetch(db, NULL, string_term_tdb_data(keystr), &dbuf) != 0) {
+ return false;
+ }
+
+ if ((dbuf.dptr == NULL) || (dbuf.dsize != sizeof(uint32_t))) {
+ TALLOC_FREE(dbuf.dptr);
+ return false;
+ }
+
+ *val = IVAL(dbuf.dptr, 0);
+ TALLOC_FREE(dbuf.dptr);
+ return true;
+}
+
+bool dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
+{
+ struct db_record *rec;
+ uint32 v_store;
+ NTSTATUS status;
+
+ rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr));
+ if (rec == NULL) {
+ return false;
+ }
+
+ SIVAL(&v_store, 0, v);
+
+ status = rec->store(rec, make_tdb_data((const uint8 *)&v_store,
+ sizeof(v_store)),
+ TDB_REPLACE);
+ TALLOC_FREE(rec);
+ return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
uint32_t dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
uint32_t *oldval, uint32_t change_val)
{