[SCM] Samba Shared Repository - branch master updated

Günther Deschner gd at samba.org
Sat Sep 18 18:48:26 MDT 2010


The branch, master has been updated
       via  9e058c6 s3-rpcclient: add some winreg commands.
       via  1d80941 s3-nltest: add dsregdns command to nltest.
       via  8e73826 s3-libnetapi: support NETLOGON_CONTROL_FORCE_DNS_REG in I_NetLogonControl().
       via  47a7a58 libnetapi: deal with NULL data in I_NetLogonControl2().
      from  1473330 s3: Add a missing prototype

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


- Log -----------------------------------------------------------------
commit 9e058c6e7292b628ca08bb34b5930d0f4a77ef27
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 17 13:17:12 2010 +0200

    s3-rpcclient: add some winreg commands.
    
    Guenther

commit 1d8094172c69ec8d64701b70a87ddf31b0d8f4f9
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 17 13:16:26 2010 +0200

    s3-nltest: add dsregdns command to nltest.
    
    Guenther

commit 8e73826b3c2323c6e81a285f49c6b9d606cb7a53
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 17 13:15:35 2010 +0200

    s3-libnetapi: support NETLOGON_CONTROL_FORCE_DNS_REG in I_NetLogonControl().
    
    Guenther

commit 47a7a5830c145dd12e200fa12fec41bc745046d3
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 17 13:14:50 2010 +0200

    libnetapi: deal with NULL data in I_NetLogonControl2().
    
    Guenther

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

Summary of changes:
 source3/Makefile.in                           |    2 +
 source3/lib/netapi/examples/netlogon/nltest.c |   22 ++-
 source3/lib/netapi/netlogon.c                 |    4 +
 source3/librpc/idl/libnetapi.idl              |    2 +-
 source3/rpcclient/cmd_winreg.c                |  321 +++++++++++++++++++++++++
 source3/rpcclient/rpcclient.c                 |    2 +
 6 files changed, 351 insertions(+), 2 deletions(-)
 create mode 100644 source3/rpcclient/cmd_winreg.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index d712df6..295ab98 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1007,6 +1007,7 @@ RPCCLIENT_OBJ1 = rpcclient/rpcclient.o rpcclient/cmd_lsarpc.o \
 		 rpcclient/cmd_shutdown.o rpcclient/cmd_test.o \
 		 rpcclient/cmd_wkssvc.o rpcclient/cmd_ntsvcs.o \
 		 rpcclient/cmd_drsuapi.o rpcclient/cmd_eventlog.o \
+		 rpcclient/cmd_winreg.o \
 		 $(DISPLAY_SEC_OBJ)
 
 RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \
@@ -1026,6 +1027,7 @@ RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \
 	     $(LIBCLI_SRVSVC_OBJ) \
 	     $(LIBCLI_LSA_OBJ) \
 	     $(LIBCLI_SAMR_OBJ) \
+	     $(LIBCLI_WINREG_OBJ) \
 	     $(LIBCLI_NETLOGON_OBJ) \
 	     $(RPC_CLIENT_SCHANNEL_OBJ) \
 	     rpc_client/init_netlogon.o \
diff --git a/source3/lib/netapi/examples/netlogon/nltest.c b/source3/lib/netapi/examples/netlogon/nltest.c
index e3ced90..0c393ea 100644
--- a/source3/lib/netapi/examples/netlogon/nltest.c
+++ b/source3/lib/netapi/examples/netlogon/nltest.c
@@ -58,7 +58,8 @@ enum {
 	OPT_SITE,
 	OPT_ACCOUNT,
 	OPT_RET_DNS,
-	OPT_RET_NETBIOS
+	OPT_RET_NETBIOS,
+	OPT_DSREGDNS
 };
 
 /****************************************************************
@@ -207,6 +208,7 @@ int main(int argc, const char **argv)
 	char *opt_account = NULL;
 	int opt_ret_dns = 0;
 	int opt_ret_netbios = 0;
+	int opt_dsregdns = 0;
 	uint32_t query_level = 0;
 	uint8_t *buffer = NULL;
 	uint32_t flags = 0;
@@ -244,6 +246,7 @@ int main(int argc, const char **argv)
 		{"account", 0, POPT_ARG_STRING, &opt_account, OPT_ACCOUNT, "ACCOUNT"},
 		{"ret_dns", 0, POPT_ARG_NONE, &opt_ret_dns, OPT_RET_DNS, NULL},
 		{"ret_netbios", 0, POPT_ARG_NONE, &opt_ret_netbios, OPT_RET_NETBIOS, NULL},
+		{"dsregdns", 0, POPT_ARG_NONE, &opt_dsregdns, OPT_DSREGDNS, "Force registration of all DC-specific DNS records"},
 		POPT_COMMON_LIBNETAPI_EXAMPLES
 		POPT_TABLEEND
 	};
@@ -363,6 +366,23 @@ int main(int argc, const char **argv)
 			print_netlogon_info_result(query_level, buffer);
 
 			break;
+		case OPT_DSREGDNS:
+			query_level = 1;
+			status = I_NetLogonControl2(opt_server,
+						    NETLOGON_CONTROL_FORCE_DNS_REG,
+						    query_level,
+						    NULL,
+						    &buffer);
+			if (status != 0) {
+				fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
+					status, status,
+					libnetapi_get_error_string(ctx, status));
+				goto done;
+			}
+
+			print_netlogon_info_result(query_level, buffer);
+
+			break;
 		case OPT_DSGETDC:
 			if (opt_pdc)
 				flags |= DS_PDC_REQUIRED;
diff --git a/source3/lib/netapi/netlogon.c b/source3/lib/netapi/netlogon.c
index d58b7cc..932ab8b 100644
--- a/source3/lib/netapi/netlogon.c
+++ b/source3/lib/netapi/netlogon.c
@@ -43,6 +43,9 @@ static WERROR construct_data(enum netr_LogonControlCode function_code,
 	case NETLOGON_CONTROL_SET_DBFLAG:
 		data_out->debug_level = atoi((const char *)data_in);
 		break;
+	case NETLOGON_CONTROL_FORCE_DNS_REG:
+		ZERO_STRUCTP(data_out);
+		break;
 	default:
 		return WERR_INVALID_PARAM;
 	}
@@ -193,6 +196,7 @@ WERROR I_NetLogonControl2_r(struct libnetapi_ctx *ctx,
 	switch (r->in.function_code) {
 	case NETLOGON_CONTROL_TC_VERIFY:
 	case NETLOGON_CONTROL_SET_DBFLAG:
+	case NETLOGON_CONTROL_FORCE_DNS_REG:
 		status = rpccli_netr_LogonControl2Ex(pipe_cli, ctx,
 						     r->in.server_name,
 						     r->in.function_code,
diff --git a/source3/librpc/idl/libnetapi.idl b/source3/librpc/idl/libnetapi.idl
index f83896c..935256a 100644
--- a/source3/librpc/idl/libnetapi.idl
+++ b/source3/librpc/idl/libnetapi.idl
@@ -1936,7 +1936,7 @@ interface libnetapi
 		[in] string server_name,
 		[in] uint32 function_code,
 		[in] uint32 query_level,
-		[in] uint8 *data,
+		[in,unique] uint8 *data,
 		[out,ref] uint8 **buffer
 	);
 }
diff --git a/source3/rpcclient/cmd_winreg.c b/source3/rpcclient/cmd_winreg.c
new file mode 100644
index 0000000..6fcb528
--- /dev/null
+++ b/source3/rpcclient/cmd_winreg.c
@@ -0,0 +1,321 @@
+/*
+   Unix SMB/CIFS implementation.
+   RPC pipe client
+
+   Copyright (C) Guenther Deschner 2009
+
+   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"
+#include "rpcclient.h"
+#include "../librpc/gen_ndr/cli_winreg.h"
+#include "../librpc/gen_ndr/ndr_misc.h"
+
+static WERROR cmd_winreg_enumkeys(struct rpc_pipe_client *cli,
+				  TALLOC_CTX *mem_ctx, int argc,
+				  const char **argv)
+{
+	NTSTATUS status;
+	WERROR werr;
+	struct policy_handle handle;
+	uint32_t enum_index = 0;
+	struct winreg_StringBuf name;
+
+	if (argc < 2) {
+		printf("usage: %s [name]\n", argv[0]);
+		return WERR_OK;
+	}
+
+	status = rpccli_winreg_OpenHKLM(cli, mem_ctx,
+					NULL,
+					SEC_FLAG_MAXIMUM_ALLOWED,
+					&handle,
+					&werr);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!W_ERROR_IS_OK(werr)) {
+		return werr;
+	}
+
+	ZERO_STRUCT(name);
+
+	name.name = argv[1];
+	name.length = strlen_m_term_null(name.name)*2;
+	name.size = name.length;
+
+	status = rpccli_winreg_EnumKey(cli, mem_ctx,
+				       &handle,
+				       enum_index,
+				       &name,
+				       NULL,
+				       NULL,
+				       &werr);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!W_ERROR_IS_OK(werr)) {
+		return werr;
+	}
+
+	return WERR_OK;
+}
+
+/****************************************************************************
+****************************************************************************/
+
+static WERROR pull_winreg_Data(TALLOC_CTX *mem_ctx,
+			       const DATA_BLOB *blob,
+			       union winreg_Data *data,
+			       enum winreg_Type type)
+{
+	enum ndr_err_code ndr_err;
+	ndr_err = ndr_pull_union_blob(blob, mem_ctx, data, type,
+			(ndr_pull_flags_fn_t)ndr_pull_winreg_Data);
+	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+		return WERR_GENERAL_FAILURE;
+	}
+	return WERR_OK;
+}
+
+/****************************************************************************
+****************************************************************************/
+
+static void display_winreg_data(const char *v,
+				enum winreg_Type type,
+				uint8_t *data,
+				uint32_t length)
+{
+	int i;
+	union winreg_Data r;
+	DATA_BLOB blob = data_blob_const(data, length);
+	WERROR result;
+
+	result = pull_winreg_Data(talloc_tos(), &blob, &r, type);
+	if (!W_ERROR_IS_OK(result)) {
+		return;
+	}
+
+	switch (type) {
+	case REG_DWORD:
+		printf("%s: REG_DWORD: 0x%08x\n", v, r.value);
+		break;
+	case REG_SZ:
+		printf("%s: REG_SZ: %s\n", v, r.string);
+		break;
+	case REG_BINARY: {
+		char *hex = hex_encode_talloc(NULL,
+			r.binary.data, r.binary.length);
+		size_t len;
+		printf("%s: REG_BINARY:", v);
+		len = strlen(hex);
+		for (i=0; i<len; i++) {
+			if (hex[i] == '\0') {
+				break;
+			}
+			if (i%40 == 0) {
+				putchar('\n');
+			}
+			putchar(hex[i]);
+		}
+		TALLOC_FREE(hex);
+		putchar('\n');
+		break;
+	}
+	case REG_MULTI_SZ:
+		printf("%s: REG_MULTI_SZ: ", v);
+		for (i=0; r.string_array[i] != NULL; i++) {
+			printf("%s ", r.string_array[i]);
+		}
+		printf("\n");
+		break;
+	default:
+		printf("%s: unknown type 0x%02x:\n", v, type);
+		break;
+	}
+}
+
+
+static WERROR cmd_winreg_querymultiplevalues_ex(struct rpc_pipe_client *cli,
+						TALLOC_CTX *mem_ctx, int argc,
+						const char **argv, bool multiplevalues2)
+{
+	NTSTATUS status;
+	WERROR werr;
+	struct policy_handle handle, key_handle;
+	struct winreg_String key_name;
+
+	struct QueryMultipleValue *values_in, *values_out;
+	uint32_t num_values;
+	uint8_t *buffer = NULL;
+	int i;
+
+
+	if (argc < 2) {
+		printf("usage: %s [key] [value1] [value2] ...\n", argv[0]);
+		return WERR_OK;
+	}
+
+	status = rpccli_winreg_OpenHKLM(cli, mem_ctx,
+					NULL,
+					SEC_FLAG_MAXIMUM_ALLOWED,
+					&handle,
+					&werr);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!W_ERROR_IS_OK(werr)) {
+		return werr;
+	}
+
+	key_name.name = argv[1];
+
+	status = rpccli_winreg_OpenKey(cli, mem_ctx,
+				       &handle,
+				       key_name,
+				       0, /* options */
+				       SEC_FLAG_MAXIMUM_ALLOWED,
+				       &key_handle,
+				       &werr);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!W_ERROR_IS_OK(werr)) {
+		return werr;
+	}
+
+	num_values = argc-2;
+
+	values_in = talloc_zero_array(mem_ctx, struct QueryMultipleValue, num_values);
+	if (values_in == NULL) {
+		return WERR_NOMEM;
+	}
+
+	values_out = talloc_zero_array(mem_ctx, struct QueryMultipleValue, num_values);
+	if (values_out == NULL) {
+		return WERR_NOMEM;
+	}
+
+	for (i=0; i < num_values; i++) {
+
+		values_in[i].ve_valuename = talloc_zero(values_in, struct winreg_ValNameBuf);
+		if (values_in[i].ve_valuename == NULL) {
+			return WERR_NOMEM;
+		}
+
+		values_in[i].ve_valuename->name = talloc_strdup(values_in[i].ve_valuename, argv[i+2]);
+		values_in[i].ve_valuename->length = strlen_m_term_null(values_in[i].ve_valuename->name)*2;
+		values_in[i].ve_valuename->size = values_in[i].ve_valuename->length;
+	}
+
+	if (multiplevalues2) {
+
+		uint32_t offered = 0, needed = 0;
+
+		status = rpccli_winreg_QueryMultipleValues2(cli, mem_ctx,
+							   &key_handle,
+							   values_in,
+							   values_out,
+							   num_values,
+							   buffer,
+							   &offered,
+							   &needed,
+							   &werr);
+		if (W_ERROR_EQUAL(werr, WERR_MORE_DATA)) {
+			offered = needed;
+
+			buffer = talloc_zero_array(mem_ctx, uint8_t, needed);
+			if (buffer == NULL) {
+				return WERR_NOMEM;
+			}
+
+			status = rpccli_winreg_QueryMultipleValues2(cli, mem_ctx,
+								    &key_handle,
+								    values_in,
+								    values_out,
+								    num_values,
+								    buffer,
+								    &offered,
+								    &needed,
+								    &werr);
+			if (!NT_STATUS_IS_OK(status)) {
+				return ntstatus_to_werror(status);
+			}
+			if (!W_ERROR_IS_OK(werr)) {
+				return werr;
+			}
+		}
+
+	} else {
+
+		uint32_t buffer_size = 0xff;
+
+		buffer = talloc_zero_array(mem_ctx, uint8_t, buffer_size);
+		if (buffer == NULL) {
+			return WERR_NOMEM;
+		}
+
+		status = rpccli_winreg_QueryMultipleValues(cli, mem_ctx,
+							   &key_handle,
+							   values_in,
+							   values_out,
+							   num_values,
+							   buffer,
+							   &buffer_size,
+							   &werr);
+		if (!NT_STATUS_IS_OK(status)) {
+			return ntstatus_to_werror(status);
+		}
+		if (!W_ERROR_IS_OK(werr)) {
+			return werr;
+		}
+	}
+
+	for (i=0; i < num_values; i++) {
+		if (buffer) {
+			display_winreg_data(values_in[i].ve_valuename->name,
+					    values_out[i].ve_type,
+					    buffer + values_out[i].ve_valueptr,
+					    values_out[i].ve_valuelen);
+		}
+	}
+
+	return WERR_OK;
+}
+
+static WERROR cmd_winreg_querymultiplevalues(struct rpc_pipe_client *cli,
+					     TALLOC_CTX *mem_ctx, int argc,
+					     const char **argv)
+{
+	return cmd_winreg_querymultiplevalues_ex(cli, mem_ctx, argc, argv, false);
+}
+
+static WERROR cmd_winreg_querymultiplevalues2(struct rpc_pipe_client *cli,
+					      TALLOC_CTX *mem_ctx, int argc,
+					      const char **argv)
+{
+	return cmd_winreg_querymultiplevalues_ex(cli, mem_ctx, argc, argv, true);
+}
+
+/* List of commands exported by this module */
+
+struct cmd_set winreg_commands[] = {
+
+	{ "WINREG" },
+	{ "enumkey", RPC_RTYPE_WERROR, NULL, cmd_winreg_enumkeys, &ndr_table_winreg.syntax_id, NULL, "Enumerate Keys", "" },
+	{ "querymultiplevalues", RPC_RTYPE_WERROR, NULL, cmd_winreg_querymultiplevalues, &ndr_table_winreg.syntax_id, NULL, "Query multiple values", "" },
+	{ "querymultiplevalues2", RPC_RTYPE_WERROR, NULL, cmd_winreg_querymultiplevalues2, &ndr_table_winreg.syntax_id, NULL, "Query multiple values", "" },
+	{ NULL }
+};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index b34ef2c..5fa8132 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -599,6 +599,7 @@ extern struct cmd_set wkssvc_commands[];
 extern struct cmd_set ntsvcs_commands[];
 extern struct cmd_set drsuapi_commands[];
 extern struct cmd_set eventlog_commands[];
+extern struct cmd_set winreg_commands[];
 
 static struct cmd_set *rpcclient_command_list[] = {
 	rpcclient_commands,
@@ -617,6 +618,7 @@ static struct cmd_set *rpcclient_command_list[] = {
 	ntsvcs_commands,
 	drsuapi_commands,
 	eventlog_commands,
+	winreg_commands,
 	NULL
 };
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list