diff options
author | Gregor Beck <gbeck@sernet.de> | 2011-07-04 10:15:44 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-10-11 14:17:55 +0200 |
commit | 87b68cea5bdec1849a275b37ea8a80a73d036734 (patch) | |
tree | 135b90182ce9f81873bd07ff8fce3bbe30686e68 /source3/lib | |
parent | 87f51bfa99889c4700697556466cc694e2e6644d (diff) | |
download | samba-87b68cea5bdec1849a275b37ea8a80a73d036734.tar.gz samba-87b68cea5bdec1849a275b37ea8a80a73d036734.tar.bz2 samba-87b68cea5bdec1849a275b37ea8a80a73d036734.zip |
s3:dbwrap: add function dbwrap_exists()
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/dbwrap/dbwrap.c | 29 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap.h | 2 |
2 files changed, 31 insertions, 0 deletions
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 @@ -44,6 +44,24 @@ int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, } /* + * 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) { diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h index 2ba96b2482..9ff47c4285 100644 --- a/source3/lib/dbwrap/dbwrap.h +++ b/source3/lib/dbwrap/dbwrap.h @@ -52,6 +52,7 @@ struct db_context { int (*parser)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data); + int (*exists)(struct db_context *db,TDB_DATA key); void *private_data; bool persistent; }; @@ -63,6 +64,7 @@ NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key, TDB_DATA data, int flags); TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key); +bool dbwrap_exists(struct db_context *db, TDB_DATA key); NTSTATUS dbwrap_traverse(struct db_context *db, int (*f)(struct db_record*, void*), void *private_data, |