[SCM] Samba Shared Repository - branch master updated

Michael Adam obnox at samba.org
Tue Nov 29 11:54:03 MST 2011


The branch, master has been updated
       via  3ab37a0 s3:net registry check: adapt to new semantic of dbwrap_fetch with rbt
       via  bca2677 s3:net registry check: adapt to new semantic of dbwrap_fetch
       via  efb993b s3:dbwrap: turn the fetch dbwrap method to NTSTATUS return code.
       via  819ca3b s3:dbwrap_ctdb: re-use map_nt_error_from_tdb() in local tdb_error_to_ntstatus()
       via  bba62cd s3:net registry check: handle missing version info
       via  c1d83b0 s3:dbwrap_torture: code cleanup
      from  6b5cfa3 s4:libcli/raw: copy smbcli_transport_connect_* to clisocket.c

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3ab37a0d0e8da0a149f3b0c4b0f54d4a7e8a66cf
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Nov 3 14:57:52 2011 +0100

    s3:net registry check: adapt to new semantic of dbwrap_fetch with rbt
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    
    Autobuild-User: Michael Adam <obnox at samba.org>
    Autobuild-Date: Tue Nov 29 19:53:30 CET 2011 on sn-devel-104

commit bca2677afe0646e5436356d73c4acee7844e8056
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Oct 24 10:25:29 2011 +0200

    s3:net registry check: adapt to new semantic of dbwrap_fetch
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit efb993b686e397e06ba647089535c92ec08c4345
Author: Michael Adam <obnox at samba.org>
Date:   Fri Nov 11 00:49:11 2011 +0100

    s3:dbwrap: turn the fetch dbwrap method to NTSTATUS return code.
    
    This implement more correct NTSTATUS handling inside the backends.
    This ensures that data.dptr != NULL if return code is NT_STATUS_OK.

commit 819ca3b697e1b396b83308341cf81c19362c2626
Author: Michael Adam <obnox at samba.org>
Date:   Tue Nov 29 15:57:10 2011 +0100

    s3:dbwrap_ctdb: re-use map_nt_error_from_tdb() in local tdb_error_to_ntstatus()

commit bba62cdb0c5f3ae85a5eeaa9b747e04a2d392440
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Oct 24 14:29:45 2011 +0200

    s3:net registry check: handle missing version info
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit c1d83b0ff2bd400161a21c99b34523164ebd6462
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Oct 20 10:18:24 2011 +0200

    s3:dbwrap_torture: code cleanup
    
    Signed-off-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/lib/dbwrap/dbwrap.c         |   22 +++++------
 source3/lib/dbwrap/dbwrap_ctdb.c    |   53 +++++++------------------
 source3/lib/dbwrap/dbwrap_private.h |    8 ++--
 source3/lib/dbwrap/dbwrap_rbt.c     |   10 ++--
 source3/lib/dbwrap/dbwrap_tdb.c     |   35 ++++++++++++-----
 source3/utils/dbwrap_torture.c      |    6 +-
 source3/utils/net_registry_check.c  |   71 +++++++++++++++++++++++++++--------
 7 files changed, 117 insertions(+), 88 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c
index 38404a8..cdc46c3 100644
--- a/source3/lib/dbwrap/dbwrap.c
+++ b/source3/lib/dbwrap/dbwrap.c
@@ -28,19 +28,20 @@
  * Fall back using fetch_locked if no genuine fetch operation is provided
  */
 
-int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			  TDB_DATA key, TDB_DATA *data)
+NTSTATUS dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			       TDB_DATA key, TDB_DATA *data)
 {
 	struct db_record *rec;
 
-	if (!(rec = db->fetch_locked(db, mem_ctx, key))) {
-		return -1;
+	rec = db->fetch_locked(db, mem_ctx, key);
+	if (rec == NULL) {
+		return NT_STATUS_UNSUCCESSFUL;
 	}
 
 	data->dsize = rec->value.dsize;
 	data->dptr = talloc_move(mem_ctx, &rec->value.dptr);
 	TALLOC_FREE(rec);
-	return 0;
+	return NT_STATUS_OK;
 }
 
 /*
@@ -65,9 +66,10 @@ int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
 {
 	TDB_DATA data;
 	int res;
+	NTSTATUS status;
 
-	res = db->fetch(db, talloc_tos(), key, &data);
-	if (res != 0) {
+	status = db->fetch(db, talloc_tos(), key, &data);
+	if (!NT_STATUS_IS_OK(status)) {
 		return -1;
 	}
 
@@ -137,11 +139,7 @@ NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 		return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	if (db->fetch(db, mem_ctx, key, value) != 0) {
-		return NT_STATUS_NOT_FOUND;
-	}
-
-	return NT_STATUS_OK;
+	return db->fetch(db, mem_ctx, key, value);
 }
 
 bool dbwrap_exists(struct db_context *db, TDB_DATA key)
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index aae5c06..7262b87 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -82,22 +82,9 @@ struct db_ctdb_rec {
 
 static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb)
 {
-	NTSTATUS status;
 	enum TDB_ERROR tret = tdb_error(tdb);
 
-	switch (tret) {
-	case TDB_ERR_EXISTS:
-		status = NT_STATUS_OBJECT_NAME_COLLISION;
-		break;
-	case TDB_ERR_NOEXIST:
-		status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
-		break;
-	default:
-		status = NT_STATUS_INTERNAL_DB_CORRUPTION;
-		break;
-	}
-
-	return status;
+	return map_nt_error_from_tdb(tret);
 }
 
 
@@ -469,9 +456,9 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
 /*
   fetch a record inside a transaction
  */
-static int db_ctdb_transaction_fetch(struct db_ctdb_ctx *db, 
-				     TALLOC_CTX *mem_ctx, 
-				     TDB_DATA key, TDB_DATA *data)
+static NTSTATUS db_ctdb_transaction_fetch(struct db_ctdb_ctx *db,
+					  TALLOC_CTX *mem_ctx,
+					  TDB_DATA key, TDB_DATA *data)
 {
 	struct db_ctdb_transaction_handle *h = db->transaction;
 	NTSTATUS status;
@@ -480,18 +467,16 @@ static int db_ctdb_transaction_fetch(struct db_ctdb_ctx *db,
 	found = pull_newest_from_marshall_buffer(h->m_write, key, NULL,
 						 mem_ctx, data);
 	if (found) {
-		return 0;
+		return NT_STATUS_OK;
 	}
 
 	status = db_ctdb_ltdb_fetch(h->ctx, key, NULL, mem_ctx, data);
 
 	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		*data = tdb_null;
-	} else if (!NT_STATUS_IS_OK(status)) {
-		return -1;
 	}
 
-	return 0;
+	return status;
 }
 
 /**
@@ -505,9 +490,9 @@ static int db_ctdb_transaction_fetch(struct db_ctdb_ctx *db,
  * of records bump their RSN and hence render the persistent
  * database inconsistent.
  */
-static int db_ctdb_fetch_persistent(struct db_ctdb_ctx *db,
-				    TALLOC_CTX *mem_ctx,
-				    TDB_DATA key, TDB_DATA *data)
+static NTSTATUS db_ctdb_fetch_persistent(struct db_ctdb_ctx *db,
+					 TALLOC_CTX *mem_ctx,
+					 TDB_DATA key, TDB_DATA *data)
 {
 	NTSTATUS status;
 
@@ -515,11 +500,9 @@ static int db_ctdb_fetch_persistent(struct db_ctdb_ctx *db,
 
 	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		*data = tdb_null;
-	} else if (!NT_STATUS_IS_OK(status)) {
-		return -1;
 	}
 
-	return 0;
+	return status;
 }
 
 static NTSTATUS db_ctdb_store_transaction(struct db_record *rec, TDB_DATA data, int flag);
@@ -1157,8 +1140,8 @@ static struct db_record *db_ctdb_fetch_locked(struct db_context *db,
 /*
   fetch (unlocked, no migration) operation on ctdb
  */
-static int db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			 TDB_DATA key, TDB_DATA *data)
+static NTSTATUS db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			      TDB_DATA key, TDB_DATA *data)
 {
 	struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data,
 							struct db_ctdb_ctx);
@@ -1188,11 +1171,6 @@ static int db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 		/* we are the dmaster - avoid the ctdb protocol op */
 
 		data->dsize = ctdb_data.dsize - sizeof(struct ctdb_ltdb_header);
-		if (data->dsize == 0) {
-			SAFE_FREE(ctdb_data.dptr);
-			data->dptr = NULL;
-			return 0;
-		}
 
 		data->dptr = (uint8 *)talloc_memdup(
 			mem_ctx, ctdb_data.dptr+sizeof(struct ctdb_ltdb_header),
@@ -1201,9 +1179,9 @@ static int db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 		SAFE_FREE(ctdb_data.dptr);
 
 		if (data->dptr == NULL) {
-			return -1;
+			return NT_STATUS_NO_MEMORY;
 		}
-		return 0;
+		return NT_STATUS_OK;
 	}
 
 	SAFE_FREE(ctdb_data.dptr);
@@ -1213,10 +1191,9 @@ static int db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 			     mem_ctx, data);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(5, ("ctdbd_fetch failed: %s\n", nt_errstr(status)));
-		return -1;
 	}
 
-	return 0;
+	return status;
 }
 
 struct traverse_state {
diff --git a/source3/lib/dbwrap/dbwrap_private.h b/source3/lib/dbwrap/dbwrap_private.h
index 0a8581a..e7bd480 100644
--- a/source3/lib/dbwrap/dbwrap_private.h
+++ b/source3/lib/dbwrap/dbwrap_private.h
@@ -34,8 +34,8 @@ struct db_context {
 	struct db_record *(*fetch_locked)(struct db_context *db,
 					  TALLOC_CTX *mem_ctx,
 					  TDB_DATA key);
-	int (*fetch)(struct db_context *db, TALLOC_CTX *mem_ctx,
-		     TDB_DATA key, TDB_DATA *data);
+	NTSTATUS (*fetch)(struct db_context *db, TALLOC_CTX *mem_ctx,
+			  TDB_DATA key, TDB_DATA *data);
 	int (*traverse)(struct db_context *db,
 			int (*f)(struct db_record *rec,
 				 void *private_data),
@@ -59,8 +59,8 @@ struct db_context {
 	bool persistent;
 };
 
-int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			  TDB_DATA key, TDB_DATA *data);
+NTSTATUS dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			       TDB_DATA key, TDB_DATA *data);
 
 
 int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
diff --git a/source3/lib/dbwrap/dbwrap_rbt.c b/source3/lib/dbwrap/dbwrap_rbt.c
index 98541ea..3f280c2 100644
--- a/source3/lib/dbwrap/dbwrap_rbt.c
+++ b/source3/lib/dbwrap/dbwrap_rbt.c
@@ -344,8 +344,8 @@ static int db_rbt_parse_record(struct db_context *db, TDB_DATA key,
 	return parser(res.key, res.val, private_data);
 }
 
-static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			TDB_DATA key, TDB_DATA *data)
+static NTSTATUS db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			     TDB_DATA key, TDB_DATA *data)
 {
 	uint8_t *result;
 	struct db_rbt_search_result res;
@@ -354,17 +354,17 @@ static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 
 	if (!found) {
 		*data = tdb_null;
-		return 0;
+		return NT_STATUS_NOT_FOUND;
 	}
 
 	result = (uint8_t*)talloc_memdup(mem_ctx, res.val.dptr, res.val.dsize);
 	if (result == NULL) {
-		return -1;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	data->dptr = result;
 	data->dsize = res.val.dsize;
-	return 0;
+	return NT_STATUS_OK;
 }
 
 static int db_rbt_traverse_internal(struct rb_node *n,
diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c
index e9e4900..cf761e2 100644
--- a/source3/lib/dbwrap/dbwrap_tdb.c
+++ b/source3/lib/dbwrap/dbwrap_tdb.c
@@ -23,6 +23,7 @@
 #include "dbwrap/dbwrap_tdb.h"
 #include "lib/util/tdb_wrap.h"
 #include "lib/param/param.h"
+#include "util_tdb.h"
 
 struct db_tdb_ctx {
 	struct tdb_wrap *wtdb;
@@ -135,7 +136,7 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db,
 
 struct tdb_fetch_state {
 	TALLOC_CTX *mem_ctx;
-	int result;
+	NTSTATUS result;
 	TDB_DATA data;
 };
 
@@ -145,19 +146,25 @@ static int db_tdb_fetch_parse(TDB_DATA key, TDB_DATA data,
 	struct tdb_fetch_state *state =
 		(struct tdb_fetch_state *)private_data;
 
+	if (data.dptr == NULL) {
+		/* should not happen */
+		state->result = NT_STATUS_INTERNAL_DB_ERROR;
+		return -1;
+	}
+
 	state->data.dptr = (uint8 *)talloc_memdup(state->mem_ctx, data.dptr,
 						  data.dsize);
 	if (state->data.dptr == NULL) {
-		state->result = -1;
-		return 0;
+		state->result = NT_STATUS_NO_MEMORY;
+		return -1;
 	}
 
 	state->data.dsize = data.dsize;
 	return 0;
 }
 
-static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			TDB_DATA key, TDB_DATA *pdata)
+static NTSTATUS db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			     TDB_DATA key, TDB_DATA *pdata)
 {
 	struct db_tdb_ctx *ctx = talloc_get_type_abort(
 		db->private_data, struct db_tdb_ctx);
@@ -166,21 +173,29 @@ static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 	int ret;
 
 	state.mem_ctx = mem_ctx;
-	state.result = 0;
+	state.result = NT_STATUS_OK;
 	state.data = tdb_null;
 
 	ret = tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_fetch_parse, &state);
 
 	if (ret != 0) {
-		return -1;
+		NTSTATUS status;
+
+		if (!NT_STATUS_IS_OK(state.result)) {
+			/* the parser has set an error code. return it */
+			return state.result;
+		}
+
+		status = map_nt_error_from_tdb(tdb_error(ctx->wtdb->tdb));
+		return status;
 	}
 
-	if (state.result == -1) {
-		return -1;
+	if (!NT_STATUS_IS_OK(state.result)) {
+		return NT_STATUS_INTERNAL_DB_CORRUPTION;
 	}
 
 	*pdata = state.data;
-	return 0;
+	return NT_STATUS_OK;
 }
 
 static int db_tdb_exists(struct db_context *db, TDB_DATA key)
diff --git a/source3/utils/dbwrap_torture.c b/source3/utils/dbwrap_torture.c
index c48f09a..3ce1f53 100644
--- a/source3/utils/dbwrap_torture.c
+++ b/source3/utils/dbwrap_torture.c
@@ -25,6 +25,7 @@
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
 #include "messages.h"
+#include "lib/util/util_tdb.h"
 
 #if 0
 #include "lib/events/events.h"
@@ -42,7 +43,7 @@ static int timelimit = 10;
 static int torture_delay = 0;
 static int verbose = 0;
 static int no_trans = 0;
-static char *db_name = (char *)discard_const(DEFAULT_DB_NAME);
+static const char *db_name = DEFAULT_DB_NAME;
 
 
 static unsigned int pnn;
@@ -129,8 +130,7 @@ static void test_store_records(struct db_context *db, struct tevent_context *ev)
 	TALLOC_CTX *tmp_ctx = talloc_stackframe();
 	struct timeval start;
 
-	key.dptr = (unsigned char *)discard_const("testkey");
-	key.dsize = strlen((const char *)key.dptr)+1;
+	key = string_term_tdb_data("testkey");
 
 	start = timeval_current();
 	while ((timelimit == 0) || (timeval_elapsed(&start) < timelimit)) {
diff --git a/source3/utils/net_registry_check.c b/source3/utils/net_registry_check.c
index 8e67edd..ce7032a 100644
--- a/source3/utils/net_registry_check.c
+++ b/source3/utils/net_registry_check.c
@@ -264,22 +264,19 @@ static struct regkey*
 check_ctx_lookup_key(struct check_ctx *ctx, const char *path) {
 	struct regkey *ret = NULL;
 	NTSTATUS status;
-	TDB_DATA val;
+	TDB_DATA val = tdb_null;
 
 	if ( path == NULL) {
 		return ctx->root;
 	}
 
 	status = dbwrap_fetch(ctx->reg, ctx, string_term_tdb_data(path), &val);
-	if (!NT_STATUS_IS_OK(status)) {
-		return NULL;
-	}
-	if (val.dptr != NULL) {
+	if (NT_STATUS_IS_OK(status)) {
 		if (ctx->opt.verbose) {
 			printf("Open: %s\n", path);
 		}
 		ret = *(struct regkey**)val.dptr;
-	} else {
+	} else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		/* not yet existing, create */
 		char *pp;
 		if (ctx->opt.verbose) {
@@ -304,6 +301,9 @@ check_ctx_lookup_key(struct check_ctx *ctx, const char *path) {
 
 		dbwrap_store(ctx->reg, string_term_tdb_data(path),
 			     make_tdb_data((void*)&ret, sizeof(ret)), 0);
+	} else {
+		DEBUG(0, ("lookup key: failed to fetch %s: %s\n", path,
+			  nt_errstr(status)));
 	}
 done:
 	talloc_free(val.dptr);
@@ -893,18 +893,21 @@ dbwrap_store_verbose(struct db_context *db, const char *key, TDB_DATA nval)
 	NTSTATUS status;
 
 	status = dbwrap_fetch_bystring(db, mem_ctx, key, &oval);
-	if (!NT_STATUS_IS_OK(status)) {
-		printf ("store %s failed to fetch old value: %s\n", key,
-			nt_errstr(status));
-		goto done;
-	}
+	if (NT_STATUS_IS_OK(status)) {
+		if (tdb_data_equal(nval, oval)) {
+			goto done;
+		}
+		printf("store %s:\n  overwrite: %s\n  with:      %s\n", key,
+		       tdb_data_print(mem_ctx, oval),
+		       tdb_data_print(mem_ctx, nval));
 
-	if (!tdb_data_is_empty(oval) && !tdb_data_equal(nval, oval)) {
-		printf("store %s:\n"
-		       "  overwrite: %s\n"
-		       "  with:      %s\n",
-		       key, tdb_data_print(mem_ctx, oval),
+	} else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		printf("store %s:\n  write: %s\n", key,
 		       tdb_data_print(mem_ctx, nval));
+	} else {
+		printf ("store %s:\n  failed to fetch old value: %s\n", key,
+			nt_errstr(status));
+		goto done;
 	}
 
 	status = dbwrap_store_bystring(db, key, nval, 0);
@@ -917,6 +920,36 @@ done:
 	return NT_STATUS_IS_OK(status);
 }
 
+static bool
+dbwrap_store_uint32_verbose(struct db_context *db, const char *key, uint32_t nval)
+{
+	uint32_t oval;
+	NTSTATUS status;
+
+	status = dbwrap_fetch_uint32(db, key, &oval);
+	if (NT_STATUS_IS_OK(status)) {
+		if (nval == oval) {
+			goto done;
+		}
+		printf("store %s:\n overwrite: %d\n with:      %d\n", key,
+		       (int)oval, (int)nval);
+
+	} else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		printf("store %s:\n write: %d\n", key, (int)nval);
+	} else {
+		printf ("store %s:\n  failed to fetch old value: %s\n", key,
+			nt_errstr(status));
+		goto done;
+	}
+
+	status = dbwrap_store_uint32(db, key, nval);
+	if (!NT_STATUS_IS_OK(status)) {
+		printf ("store %s failed: %s\n", key, nt_errstr(status));
+	}
+
+done:
+	return NT_STATUS_IS_OK(status);
+}
 
 static int cmp_keynames(char **p1, char **p2)
 {
@@ -1200,6 +1233,12 @@ static bool check_ctx_fix_inplace(struct check_ctx *ctx) {
 		DEBUG(0, ("delete traverse failed: %s\n", nt_errstr(status)));
 		return false;
 	}
+
+	if (!dbwrap_store_uint32_verbose(ctx->odb, "INFO/version", ctx->version)) {
+		DEBUG(0, ("storing version failed: %s\n", nt_errstr(status)));
+		return false;
+	}
+
 	return true;
 }
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list