[SCM] Samba Shared Repository - branch v3-4-test updated - release-4-0-0alpha7-1000-gab107e8

Michael Adam obnox at samba.org
Fri May 15 16:15:56 GMT 2009


The branch, v3-4-test has been updated
       via  ab107e8bb85131d5a7430b7fe58904b488240279 (commit)
       via  44746461dcead5b42cc2177346c26aee79151c86 (commit)
       via  85e38ebde54fb403dcdcb9da39880c7d776034c6 (commit)
       via  bf0c69834671a6dd6a43a89d6a8abd98f6afaf5f (commit)
       via  c118d03a2b15b75a5025158956a8d8f99682d55c (commit)
       via  5085c853e87cc5875b1a38e6558a5412a69e1d08 (commit)
      from  b5b5718552f44ac4fc961c38eb3a8ff02eab18f9 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-4-test


- Log -----------------------------------------------------------------
commit ab107e8bb85131d5a7430b7fe58904b488240279
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 18:00:59 2009 +0200

    s3:swat: hide "config backend" from swat
    
    Michael
    (cherry picked from commit c085c8311dfadcb05594714149632e9523a27c14)

commit 44746461dcead5b42cc2177346c26aee79151c86
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 01:46:09 2009 +0200

    s3:param: prevent includes from being dumped in dump_*() functions.
    
    This fixes bug #4271: testparm should not print includes.
    
    Michael
    (cherry picked from commit 00297b74ac6320a23ba444647718680ddee37453)

commit 85e38ebde54fb403dcdcb9da39880c7d776034c6
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 15:41:41 2009 +0200

    s3:build: add install-dbwrap_tool target
    
    Michael
    (cherry picked from commit a62e72b825117dc45d434fd1b3645633b5d063d6)

commit bf0c69834671a6dd6a43a89d6a8abd98f6afaf5f
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 15:41:26 2009 +0200

    s3:build dbwrap_tool with make everything
    
    Michael
    (cherry picked from commit b4131ecf811e6f42ebec4154a911a3dfa8416a56)

commit c118d03a2b15b75a5025158956a8d8f99682d55c
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 11:58:17 2009 +0200

    s3:build: rename OBJ collection for dbwrap_tool consistently
    
    Michael
    (cherry picked from commit ad240e199893a5e89cdd5161134171cc600266b8)

commit 5085c853e87cc5875b1a38e6558a5412a69e1d08
Author: Michael Adam <obnox at samba.org>
Date:   Fri May 15 01:48:55 2009 +0200

    s3:first cut at dbwrap_tool - a tdb tool that is CTDB-aware.
    
    This tool (in contrast to tdbtool) reads Samba's configuration
    and if clustering = yes, it talks to CTDB instead of accessing
    the TDB data bases directly. This is done by simply using
    the dbwrap mechanim, just like the Samba daemons.
    
    This first version can read and write int32 and uint32 values
    and delete records from a (c)tdb database.
    More operations will follow.
    
    This tool can already be useful in CTDB environments, e.g. when
    "net idmap restore" fails to set the USER and GROUP HWM keys,
    because the methods are deliberately not implemented in
    idmap_tdb2.c. You can manually set the high water marks
    with
    "dbwrap_tool store idmap_tdb2.tdb 'USER HWM' int32 12345"
    and
    "dbwrap_tool store idmap_tdb2.tdb 'GROUP HWM' int32 67890"
    
    Michael
    (cherry picked from commit 6d82b5975598f1742c53ebdaa2fa89f7cf148b85)

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

Summary of changes:
 source3/Makefile.in         |   17 +++-
 source3/include/smb.h       |    1 +
 source3/param/loadparm.c    |    9 +-
 source3/utils/dbwrap_tool.c |  247 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 270 insertions(+), 4 deletions(-)
 create mode 100644 source3/utils/dbwrap_tool.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 8285ab9..1bdc790 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -222,7 +222,8 @@ BIN_PROGS = @EXTRA_BIN_PROGS@ \
 EVERYTHING_PROGS = bin/debug2html at EXEEXT@ bin/smbfilter at EXEEXT@ \
 	bin/talloctort at EXEEXT@ bin/replacetort at EXEEXT@ \
 	bin/log2pcap at EXEEXT@ \
-	bin/vlp at EXEEXT@ bin/smbiconv at EXEEXT@
+	bin/vlp at EXEEXT@ bin/smbiconv at EXEEXT@ \
+	bin/dbwrap_tool at EXEEXT@
 
 PAM_MODULES = @PAM_MODULES@
 
@@ -1199,6 +1200,10 @@ RPC_OPEN_TCP_OBJ = torture/rpc_open_tcp.o \
 		   ../librpc/rpc/binding.o \
 		   $(LIBMSRPC_GEN_OBJ)
 
+DBWRAP_TOOL_OBJ = utils/dbwrap_tool.o \
+		  $(PARAM_OBJ) \
+		  $(LIB_NONSMBD_OBJ) \
+		  $(LIBSAMBA_OBJ)
 
 ######################################################################
 # now the rules...
@@ -2755,6 +2760,16 @@ bin/test_lp_load at EXEEXT@: $(BINARY_PREREQS) $(TEST_LP_LOAD_OBJ) @BUILD_POPT@ @LI
 		$(LDAP_LIBS) \
 		$(POPT_LIBS) $(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
 
+bin/dbwrap_tool at EXEEXT@: $(DBWRAP_TOOL_OBJ) @LIBTALLOC_TARGET@ @LIBTDB_TARGET@
+	@echo "Linking $@"
+	@$(CC) -o $@ $(DBWRAP_TOOL_OBJ)\
+		$(LDFLAGS) $(DYNEEXP) $(LIBS) \
+		$(LDAP_LIBS) \
+		$(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
+
+install-dbwrap_tool:: bin/dbwrap_tool at EXEEXT@
+	@$(SHELL) script/installbin.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(prefix) $(BINDIR) $<
+
 install:: installservers installbin @INSTALL_CIFSMOUNT@ @INSTALL_CIFSUPCALL@ installman \
 		installscripts installdat installmodules @SWAT_INSTALL_TARGETS@ \
 		@INSTALL_PAM_MODULES@ installlibs installmo
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 281a218..9cae327 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -926,6 +926,7 @@ struct parm_struct {
 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
 #define FLAG_HIDE  	0x2000 /* options that should be hidden in SWAT */
 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
+#define FLAG_META	0x8000 /* A meta directive - not a real parameter */
 
 struct bitmap {
 	uint32 *b;
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 08cd800..09d7378 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1034,7 +1034,7 @@ static struct parm_struct parm_table[] = {
 		.ptr		= &Globals.ConfigBackend,
 		.special	= NULL,
 		.enum_list	= enum_config_backend,
-		.flags		= FLAG_ADVANCED,
+		.flags		= FLAG_HIDE|FLAG_ADVANCED|FLAG_META,
 	},
 
 	{N_("Security Options"), P_SEP, P_SEPARATOR},
@@ -3736,7 +3736,7 @@ static struct parm_struct parm_table[] = {
 		.ptr		= &Globals.szConfigFile,
 		.special	= NULL,
 		.enum_list	= NULL,
-		.flags		= FLAG_HIDE,
+		.flags		= FLAG_HIDE|FLAG_META,
 	},
 	{
 		.label		= "preload",
@@ -3999,7 +3999,7 @@ static struct parm_struct parm_table[] = {
 		.ptr		= &sDefault.szInclude,
 		.special	= handle_include,
 		.enum_list	= NULL,
-		.flags		= FLAG_HIDE,
+		.flags		= FLAG_HIDE|FLAG_META,
 	},
 	{
 		.label		= "preexec",
@@ -7772,6 +7772,7 @@ static void dump_globals(FILE *f)
 
 	for (i = 0; parm_table[i].label; i++)
 		if (parm_table[i].p_class == P_GLOBAL &&
+		    !(parm_table[i].flags & FLAG_META) &&
 		    parm_table[i].ptr &&
 		    (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr))) {
 			if (defaults_saved && is_default(i))
@@ -7818,6 +7819,7 @@ static void dump_a_service(struct service *pService, FILE * f)
 	for (i = 0; parm_table[i].label; i++) {
 
 		if (parm_table[i].p_class == P_LOCAL &&
+		    !(parm_table[i].flags & FLAG_META) &&
 		    parm_table[i].ptr &&
 		    (*parm_table[i].label != '-') &&
 		    (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr))) 
@@ -7894,6 +7896,7 @@ bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
 
 	for (i = 0; parm_table[i].label; i++) {
 		if (strwicmp(parm_table[i].label, parm_name) == 0 &&
+		    !(parm_table[i].flags & FLAG_META) &&
 		    (parm_table[i].p_class == p_class || parm_table[i].flags & flag) &&
 		    parm_table[i].ptr &&
 		    (*parm_table[i].label != '-') &&
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
new file mode 100644
index 0000000..5172112
--- /dev/null
+++ b/source3/utils/dbwrap_tool.c
@@ -0,0 +1,247 @@
+/*
+   Samba Unix/Linux CIFS implementation
+
+   low level TDB/CTDB tool using the dbwrap interface
+
+   Copyright (C) 2009 Michael Adam <obnox at samba.org>
+
+   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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+extern bool AllowDebugChange;
+
+typedef enum { OP_FETCH, OP_STORE, OP_DELETE } dbwrap_op;
+
+typedef enum { TYPE_INT32, TYPE_UINT32 } dbwrap_type;
+
+static int dbwrap_tool_fetch_int32(struct db_context *db,
+				   const char *keyname,
+				   void *data)
+{
+	int32_t value;
+
+	value = dbwrap_fetch_int32(db, keyname);
+	d_printf("%d\n", value);
+
+	return 0;
+}
+
+static int dbwrap_tool_fetch_uint32(struct db_context *db,
+				    const char *keyname,
+				    void *data)
+{
+	uint32_t value;
+	bool ret;
+
+	ret = dbwrap_fetch_uint32(db, keyname, &value);
+	if (ret) {
+		d_printf("%u\n", value);
+		return 0;
+	} else {
+		d_fprintf(stderr, "ERROR: could not fetch uint32 key '%s'\n",
+			  keyname);
+		return -1;
+	}
+}
+
+static int dbwrap_tool_store_int32(struct db_context *db,
+				   const char *keyname,
+				   void *data)
+{
+	NTSTATUS status;
+	int32_t value = *((int32_t *)data);
+
+	status = dbwrap_trans_store_int32(db, keyname, value);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "ERROR: could not store int32 key '%s': %s\n",
+			  keyname, nt_errstr(status));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int dbwrap_tool_store_uint32(struct db_context *db,
+				    const char *keyname,
+				    void *data)
+{
+	NTSTATUS status;
+	uint32_t value = *((uint32_t *)data);
+
+	status = dbwrap_trans_store_uint32(db, keyname, value);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr,
+			  "ERROR: could not store uint32 key '%s': %s\n",
+			  keyname, nt_errstr(status));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int dbwrap_tool_delete(struct db_context *db,
+			      const char *keyname,
+			      void *data)
+{
+	NTSTATUS status;
+
+	status = dbwrap_trans_delete_bystring(db, keyname);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "ERROR deleting record %s : %s\n",
+			  keyname, nt_errstr(status));
+		return -1;
+	}
+
+	return 0;
+}
+
+struct dbwrap_op_dispatch_table {
+	dbwrap_op op;
+	dbwrap_type type;
+	int (*cmd)(struct db_context *db,
+		   const char *keyname,
+		   void *data);
+};
+
+struct dbwrap_op_dispatch_table dispatch_table[] = {
+	{ OP_FETCH,  TYPE_INT32,  dbwrap_tool_fetch_int32 },
+	{ OP_FETCH,  TYPE_UINT32, dbwrap_tool_fetch_uint32 },
+	{ OP_STORE,  TYPE_INT32,  dbwrap_tool_store_int32 },
+	{ OP_STORE,  TYPE_UINT32, dbwrap_tool_store_uint32 },
+	{ OP_DELETE, TYPE_INT32,  dbwrap_tool_delete },
+	{ OP_DELETE, TYPE_UINT32, dbwrap_tool_delete },
+	{ 0, 0, NULL },
+};
+
+int main(int argc, const char **argv)
+{
+	struct tevent_context *evt_ctx;
+	struct messaging_context *msg_ctx;
+	struct db_context *db;
+
+	uint16_t count;
+
+	const char *dbname;
+	const char *opname;
+	dbwrap_op op;
+	const char *keyname;
+	const char *keytype = "int32";
+	dbwrap_type type;
+	const char *valuestr = "0";
+	int32_t value = 0;
+
+	TALLOC_CTX *mem_ctx = talloc_stackframe();
+
+	int ret = 1;
+
+	load_case_tables();
+	DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
+	dbf = x_stderr;
+	AllowDebugChange = false;
+	lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
+
+	if ((argc != 4) && (argc != 5) && (argc != 6)) {
+		d_fprintf(stderr,
+			  "USAGE: %s <database> <op> <key> [<type> [<value>]]\n"
+			  "       ops: fetch, store, delete\n"
+			  "       types: int32, uint32\n",
+			 argv[0]);
+		goto done;
+	}
+
+	dbname = argv[1];
+	opname = argv[2];
+	keyname = argv[3];
+
+	if (strcmp(opname, "store") == 0) {
+		if (argc != 6) {
+			d_fprintf(stderr, "ERROR: operation 'store' requires "
+				  "value argument\n");
+			goto done;
+		}
+		valuestr = argv[5];
+		keytype = argv[4];
+		op = OP_STORE;
+	} else if (strcmp(opname, "fetch") == 0) {
+		if (argc != 5) {
+			d_fprintf(stderr, "ERROR: operation 'fetch' requires "
+				  "type but not value argument\n");
+			goto done;
+		}
+		op = OP_FETCH;
+		keytype = argv[4];
+	} else if (strcmp(opname, "delete") == 0) {
+		if (argc != 4) {
+			d_fprintf(stderr, "ERROR: operation 'delete' does "
+				  "not allow type nor value argument\n");
+			goto done;
+		}
+		op = OP_DELETE;
+	} else {
+		d_fprintf(stderr,
+			  "ERROR: invalid op '%s' specified\n"
+			  "       supported ops: fetch, store, delete\n",
+			  opname);
+		goto done;
+	}
+
+	if (strcmp(keytype, "int32") == 0) {
+		type = TYPE_INT32;
+		value = (int32_t)strtol(valuestr, NULL, 10);
+	} else if (strcmp(keytype, "uint32") == 0) {
+		type = TYPE_UINT32;
+		value = (int32_t)strtoul(valuestr, NULL, 10);
+	} else {
+		d_fprintf(stderr, "ERROR: invalid type '%s' specified.\n"
+				  "       supported types: int32, uint32\n",
+				  keytype);
+		goto done;
+	}
+
+	evt_ctx = tevent_context_init(mem_ctx);
+	if (evt_ctx == NULL) {
+		d_fprintf(stderr, "ERROR: could not init event context\n");
+		goto done;
+	}
+
+	msg_ctx = messaging_init(mem_ctx, server_id_self(), evt_ctx);
+	if (msg_ctx == NULL) {
+		d_fprintf(stderr, "ERROR: could not init messaging context\n");
+		goto done;
+	}
+
+	db = db_open(mem_ctx, dbname, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644);
+	if (db == NULL) {
+		d_fprintf(stderr, "ERROR: could not open dbname\n");
+		goto done;
+	}
+
+	for (count = 0; dispatch_table[count].cmd != NULL; count++) {
+		if ((op == dispatch_table[count].op) &&
+		    (type == dispatch_table[count].type))
+		{
+			ret = dispatch_table[count].cmd(db, keyname, &value);
+			break;
+		}
+	}
+
+done:
+	TALLOC_FREE(mem_ctx);
+	return ret;
+}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list