added a TDB_MODIFY flag to tdb_store() that says "if the record
authorAndrew Tridgell <tridge@samba.org>
Sun, 28 Mar 2004 01:38:42 +0000 (01:38 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 28 Mar 2004 01:38:42 +0000 (01:38 +0000)
doesn't exist then fail the store"
(This used to be commit 6aec1457f8772cf81b88a0a00cc2ad7c16cd0d87)

source4/lib/tdb/tdb.c
source4/lib/tdb/tdb.h

index 8fbf1289146f7c67353d708af943f5cb1b80b9a4..5f57f05778622354efa53c00e70f993d53db6e0d 100644 (file)
@@ -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;
index b3a28b7440e1289f2d8ca162c11abd3443113146..b7c51b55195c3d12b5f9c1e20dac98a0d45493a0 100644 (file)
@@ -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 */