From: Andrew Tridgell Date: Sun, 28 Mar 2004 01:38:42 +0000 (+0000) Subject: added a TDB_MODIFY flag to tdb_store() that says "if the record X-Git-Tag: samba-4.0.0alpha6~801^3~14722 X-Git-Url: http://git.samba.org/?p=samba.git;a=commitdiff_plain;h=ad15f42b6d50eff9199aef7497d24b2c9167fea1;hp=2fe43ec90f6c76ced5e697f4a26630bd72accdc5 added a TDB_MODIFY flag to tdb_store() that says "if the record doesn't exist then fail the store" (This used to be commit 6aec1457f8772cf81b88a0a00cc2ad7c16cd0d87) --- diff --git a/source4/lib/tdb/tdb.c b/source4/lib/tdb/tdb.c index 8fbf1289146..5f57f057786 100644 --- a/source4/lib/tdb/tdb.c +++ b/source4/lib/tdb/tdb.c @@ -1479,6 +1479,12 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) /* first try in-place update, on modify or replace. */ if (tdb_update_hash(tdb, key, hash, dbuf) == 0) goto out; + if (tdb->ecode == TDB_ERR_NOEXIST && + flag == TDB_MODIFY) { + /* if the record doesn't exist and we are in TDB_MODIFY mode then + we should fail the store */ + goto fail; + } } /* reset the error code potentially set by the tdb_update() */ tdb->ecode = TDB_SUCCESS; diff --git a/source4/lib/tdb/tdb.h b/source4/lib/tdb/tdb.h index b3a28b7440e..b7c51b55195 100644 --- a/source4/lib/tdb/tdb.h +++ b/source4/lib/tdb/tdb.h @@ -29,6 +29,7 @@ extern "C" { /* flags to tdb_store() */ #define TDB_REPLACE 1 #define TDB_INSERT 2 +#define TDB_MODIFY 3 /* flags for tdb_open() */ #define TDB_DEFAULT 0 /* just a readability place holder */