From 87b68cea5bdec1849a275b37ea8a80a73d036734 Mon Sep 17 00:00:00 2001 From: Gregor Beck Date: Mon, 4 Jul 2011 10:15:44 +0200 Subject: s3:dbwrap: add function dbwrap_exists() Signed-off-by: Michael Adam --- source3/lib/dbwrap/dbwrap.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source3/lib/dbwrap/dbwrap.c') diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c index c2d28b3a0e..9ec7a3e59a 100644 --- a/source3/lib/dbwrap/dbwrap.c +++ b/source3/lib/dbwrap/dbwrap.c @@ -43,6 +43,24 @@ int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, return 0; } +/* + * Fall back using fetch if no genuine exists operation is provided + */ + +static int dbwrap_fallback_exists(struct db_context *db, TDB_DATA key) +{ + TDB_DATA val; + if ( db->fetch(db, talloc_tos(), key, &val) != 0 ) { + return 0; + } + if (val.dptr == NULL ) { + return 0; + } else { + TALLOC_FREE(val.dptr); + return 1; + } +} + /* * Fall back using fetch if no genuine parse operation is provided */ @@ -79,6 +97,17 @@ TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, return result; } +bool dbwrap_exists(struct db_context *db, TDB_DATA key) +{ + int result; + if (db->exists != NULL) { + result = db->exists(db, key); + } else { + result = dbwrap_fallback_exists(db,key); + } + return (result == 1); +} + NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key, TDB_DATA data, int flags) { -- cgit