summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>2000-04-05 06:37:30 +0000
committerLuke Leighton <lkcl@samba.org>2000-04-05 06:37:30 +0000
commitedca5a4600580eda6c180efefcb77cc99cf98f3d (patch)
tree6513f3434d91c57de2d063d5d45fa70780546ddd
parent029ae0a14da97d51e962eb983df8935ac4c350fc (diff)
downloadsamba-edca5a4600580eda6c180efefcb77cc99cf98f3d.tar.gz
added TDB_MODIFY flag. this says, "if it don't already exist, fail to update".
-rw-r--r--source/tdb/tdb.c14
-rw-r--r--source/tdb/tdb.h3
2 files changed, 13 insertions, 4 deletions
diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c
index 388f4f419fe..7d99773e6f8 100644
--- a/source/tdb/tdb.c
+++ b/source/tdb/tdb.c
@@ -2,7 +2,8 @@
Unix SMB/Netbios implementation.
Version 3.0
Samba database functions
- Copyright (C) Andrew Tridgell 1999
+ Copyright (C) Andrew Tridgell 1999-2000
+ Copyright (C) Luke Kenneth Casson Leighton 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -600,6 +601,7 @@ char *tdb_error(TDB_CONTEXT *tdb)
{TDB_ERR_LOCK, "Locking error"},
{TDB_ERR_OOM, "Out of memory"},
{TDB_ERR_EXISTS, "Record exists"},
+ {TDB_ERR_NOEXIST, "Record does not exist"},
{-1, NULL}};
if (tdb != NULL) {
for (i=0;emap[i].estring;i++) {
@@ -1025,13 +1027,19 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
/* find which hash bucket it is in */
hash = tdb_hash(&key);
- /* check for it existing */
+ /* check for it existing, on insert. */
if (flag == TDB_INSERT && tdb_exists(tdb, key)) {
tdb->ecode = TDB_ERR_EXISTS;
return -1;
}
- /* first try in-place update */
+ /* check for it _not_ existing, on modify. */
+ if (flag == TDB_MODIFY && !tdb_exists(tdb, key)) {
+ tdb->ecode = TDB_ERR_NOEXIST;
+ return -1;
+ }
+
+ /* first try in-place update, on modify or replace. */
if (flag != TDB_INSERT && tdb_update(tdb, key, dbuf) == 0) {
return 0;
}
diff --git a/source/tdb/tdb.h b/source/tdb/tdb.h
index b24f08b648f..405b2014d42 100644
--- a/source/tdb/tdb.h
+++ b/source/tdb/tdb.h
@@ -51,13 +51,14 @@ typedef struct {
/* flags to tdb_store() */
#define TDB_REPLACE 1
#define TDB_INSERT 2
+#define TDB_MODIFY 3
/* flags for tdb_open() */
#define TDB_CLEAR_IF_FIRST 1
/* error codes */
enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
- TDB_ERR_OOM, TDB_ERR_EXISTS};
+ TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST };
#if STANDALONE
TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,