[SCM] Samba Shared Repository - branch v3-3-test updated -
release-3-2-0pre2-2556-g9971118
Michael Adam
obnox at samba.org
Thu May 22 09:30:53 GMT 2008
The branch, v3-3-test has been updated
via 9971118c23900d81e885a013e738a67df790c90c (commit)
via 3ec3ab4e5309c63bbf2fa5efa5d2c47856560a0f (commit)
via f7db445c828c0eef2c08b538bd07d485dc248689 (commit)
from 9e39ac1cc31d48db968e79c4698901e079007ff7 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test
- Log -----------------------------------------------------------------
commit 9971118c23900d81e885a013e738a67df790c90c
Author: Michael Adam <obnox at samba.org>
Date: Thu May 22 11:16:57 2008 +0200
rpc_client: make rpc_pipe_open_tcp_port and rpc_pipe_get_tcp_port static.
Slim the interface...
Michael
commit 3ec3ab4e5309c63bbf2fa5efa5d2c47856560a0f
Author: Michael Adam <obnox at samba.org>
Date: Thu May 22 11:08:47 2008 +0200
torture: add a test program rpc_open_tcp() to test the rpc_pipe_open_tcp() func.
This is still very raw and has yet to be integrated into the test suite.
Michael
commit f7db445c828c0eef2c08b538bd07d485dc248689
Author: Michael Adam <obnox at samba.org>
Date: Tue May 20 18:08:41 2008 +0200
rpc_client: use endpoint mapper to get the port for rpc_pipe_open_tcp().
Michael
-----------------------------------------------------------------------
Summary of changes:
source/Makefile.in | 27 ++++++-
source/client/client_proto.h | 1 -
source/include/proto.h | 1 -
source/rpc_client/cli_pipe.c | 167 +++++++++++++++++++++++++++++++++++++++--
source/torture/rpc_open_tcp.c | 115 ++++++++++++++++++++++++++++
5 files changed, 299 insertions(+), 12 deletions(-)
create mode 100644 source/torture/rpc_open_tcp.c
Changeset truncated at 500 lines:
diff --git a/source/Makefile.in b/source/Makefile.in
index 6899faf..1a970bf 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -750,7 +750,7 @@ SMBCONTROL_OBJ = utils/smbcontrol.o $(LOCKING_OBJ) $(PARAM_OBJ) \
SMBTREE_OBJ = utils/smbtree.o $(PARAM_OBJ) \
$(PROFILE_OBJ) $(LIB_NONSMBD_OBJ) $(LIBSMB_OBJ) \
$(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) \
- rpc_client/cli_pipe.o $(RPC_PARSE_OBJ2) \
+ rpc_client/cli_pipe.o librpc/rpc/binding.o $(RPC_PARSE_OBJ2) \
$(RPC_CLIENT_OBJ1) \
$(PASSDB_OBJ) @LIBWBCLIENT_STATIC@ $(SMBLDAP_OBJ) $(LDB_OBJ) $(GROUPDB_OBJ) \
$(LIBMSRPC_GEN_OBJ)
@@ -829,6 +829,7 @@ LIBBIGBALLOFMUD_OBJ = $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
$(GROUPDB_OBJ) $(KRBCLIENT_OBJ) $(SMBLDAP_OBJ) $(LDB_OBJ)
CLIENT_OBJ1 = client/client.o client/clitar.o rpc_client/cli_pipe.o \
+ librpc/rpc/binding.o \
client/dnsbrowse.o \
$(RPC_CLIENT_OBJ1) \
$(RPC_PARSE_OBJ2)
@@ -837,7 +838,7 @@ CLIENT_OBJ = $(CLIENT_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \
$(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(LIBMSRPC_GEN_OBJ) \
$(READLINE_OBJ) $(POPT_LIB_OBJ) \
$(PASSDB_OBJ) @LIBWBCLIENT_STATIC@ $(SMBLDAP_OBJ) $(GROUPDB_OBJ) $(LDB_OBJ) \
- $(DISPLAY_SEC_OBJ)
+ $(DISPLAY_SEC_OBJ)
LIBNETAPI_OBJ1 = lib/netapi/netapi.o \
lib/netapi/cm.o \
@@ -1144,7 +1145,7 @@ NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
librpc/gen_ndr/ndr_netlogon.o
-VLP_OBJ1 = ../testsuite/printing/vlp.o $(RPC_CLIENT_OBJ1) $(RPC_PARSE_OBJ2) $(RPC_CLIENT_OBJ)
+VLP_OBJ1 = ../testsuite/printing/vlp.o $(RPC_CLIENT_OBJ1) $(RPC_PARSE_OBJ2) $(RPC_CLIENT_OBJ) librpc/rpc/binding.o
VLP_OBJ = $(VLP_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \
$(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(LIBMSRPC_GEN_OBJ) \
@@ -1152,6 +1153,20 @@ VLP_OBJ = $(VLP_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \
$(PASSDB_OBJ) @LIBWBCLIENT_STATIC@ $(SMBLDAP_OBJ) $(GROUPDB_OBJ) $(LDB_OBJ) \
$(DISPLAY_SEC_OBJ)
+RPC_OPEN_TCP_OBJ = torture/rpc_open_tcp.o \
+ $(LIBSMB_OBJ) \
+ $(PARAM_OBJ) \
+ $(PASSDB_OBJ) \
+ @LIBWBCLIENT_STATIC@ $(SMBLDAP_OBJ) $(LDB_OBJ) $(GROUPDB_OBJ) \
+ $(LIB_NONSMBD_OBJ) \
+ $(KRBCLIENT_OBJ) \
+ $(RPC_PARSE_OBJ2) \
+ $(RPC_CLIENT_OBJ1) \
+ rpc_client/cli_pipe.o \
+ librpc/rpc/binding.o \
+ $(LIBMSRPC_GEN_OBJ)
+
+
######################################################################
# now the rules...
######################################################################
@@ -2072,6 +2087,12 @@ bin/timelimit at EXEEXT@: script/tests/timelimit.o
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(DYNEXP) script/tests/timelimit.o
+bin/rpc_open_tcp at EXEEXT@: $(BINARY_PREREQS) $(RPC_OPEN_TCP_OBJ) @LIBTALLOC_SHARED@ @LIBTDB_SHARED@ @LIBWBCLIENT_SHARED@
+ @echo "Linking $@"
+ @$(CC) $(FLAGS) -o $@ $(RPC_OPEN_TCP_OBJ) $(LDFLAGS) $(DYNEXP) \
+ $(LIBS) @LIBTALLOC_LIBS@ @LIBTDB_SHARED@ @WINBIND_LIBS@ \
+ $(LDAP_LIBS) $(KRB5LIBS) $(NSCD_LIBS)
+
install:: installservers installbin @INSTALL_CIFSMOUNT@ @INSTALL_CIFSSPNEGO@ installman \
installscripts installdat installmodules @SWAT_INSTALL_TARGETS@ \
installlibtalloc \
diff --git a/source/client/client_proto.h b/source/client/client_proto.h
index d88805a..7adc086 100644
--- a/source/client/client_proto.h
+++ b/source/client/client_proto.h
@@ -123,7 +123,6 @@ NTSTATUS rpccli_kerberos_bind_data(TALLOC_CTX *mem_ctx,
const char *password,
struct cli_pipe_auth_data **presult);
NTSTATUS rpc_pipe_open_tcp(TALLOC_CTX *mem_ctx, const char *host,
- uint16_t port,
const struct ndr_syntax_id *abstract_syntax,
struct rpc_pipe_client **presult);
struct rpc_pipe_client *cli_rpc_pipe_open_noauth(struct cli_state *cli, int pipe_idx, NTSTATUS *perr);
diff --git a/source/include/proto.h b/source/include/proto.h
index f76e43a..e30bb32 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -7062,7 +7062,6 @@ NTSTATUS rpccli_kerberos_bind_data(TALLOC_CTX *mem_ctx,
const char *password,
struct cli_pipe_auth_data **presult);
NTSTATUS rpc_pipe_open_tcp(TALLOC_CTX *mem_ctx, const char *host,
- uint16_t port,
const struct ndr_syntax_id *abstract_syntax,
struct rpc_pipe_client **presult);
NTSTATUS rpc_pipe_open_ncalrpc(TALLOC_CTX *mem_ctx, const char *socket_path,
diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c
index 9908c69..2705fd8 100644
--- a/source/rpc_client/cli_pipe.c
+++ b/source/rpc_client/cli_pipe.c
@@ -18,6 +18,7 @@
*/
#include "includes.h"
+#include "librpc/gen_ndr/cli_epmapper.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_CLI
@@ -2509,13 +2510,13 @@ static int rpc_pipe_sock_destructor(struct rpc_pipe_client *p)
return 0;
}
-/********************************************************************
- Create a rpc pipe client struct, connecting to a tcp port
- ********************************************************************/
-NTSTATUS rpc_pipe_open_tcp(TALLOC_CTX *mem_ctx, const char *host,
- uint16_t port,
- const struct ndr_syntax_id *abstract_syntax,
- struct rpc_pipe_client **presult)
+/**
+ * Create an rpc pipe client struct, connecting to a tcp port.
+ */
+static NTSTATUS rpc_pipe_open_tcp_port(TALLOC_CTX *mem_ctx, const char *host,
+ uint16_t port,
+ const struct ndr_syntax_id *abstract_syntax,
+ struct rpc_pipe_client **presult)
{
struct rpc_pipe_client *result;
struct sockaddr_storage addr;
@@ -2563,6 +2564,158 @@ NTSTATUS rpc_pipe_open_tcp(TALLOC_CTX *mem_ctx, const char *host,
return status;
}
+/**
+ * Determine the tcp port on which a dcerpc interface is listening
+ * for the ncacn_ip_tcp transport via the endpoint mapper of the
+ * target host.
+ */
+static NTSTATUS rpc_pipe_get_tcp_port(const char *host,
+ const struct ndr_syntax_id *abstract_syntax,
+ uint16_t *pport)
+{
+ NTSTATUS status;
+ struct rpc_pipe_client *epm_pipe = NULL;
+ struct cli_pipe_auth_data *auth = NULL;
+ struct dcerpc_binding *map_binding = NULL;
+ struct dcerpc_binding *res_binding = NULL;
+ struct epm_twr_t *map_tower = NULL;
+ struct epm_twr_t *res_towers = NULL;
+ struct policy_handle *entry_handle = NULL;
+ uint32_t num_towers = 0;
+ uint32_t max_towers = 1;
+ struct epm_twr_p_t towers;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
+
+ if (pport == NULL) {
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* open the connection to the endpoint mapper */
+ status = rpc_pipe_open_tcp_port(tmp_ctx, host, 135,
+ &ndr_table_epmapper.syntax_id,
+ &epm_pipe);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ status = rpccli_anon_bind_data(tmp_ctx, &auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ status = rpc_pipe_bind(epm_pipe, auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ /* create tower for asking the epmapper */
+
+ map_binding = TALLOC_ZERO_P(tmp_ctx, struct dcerpc_binding);
+ if (map_binding == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ map_binding->transport = NCACN_IP_TCP;
+ map_binding->object = *abstract_syntax;
+ map_binding->host = host; /* needed? */
+ map_binding->endpoint = "0"; /* correct? needed? */
+
+ map_tower = TALLOC_ZERO_P(tmp_ctx, struct epm_twr_t);
+ if (map_tower == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ status = dcerpc_binding_build_tower(tmp_ctx, map_binding,
+ &(map_tower->tower));
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ /* allocate further parameters for the epm_Map call */
+
+ res_towers = TALLOC_ARRAY(tmp_ctx, struct epm_twr_t, max_towers);
+ if (res_towers == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+ towers.twr = res_towers;
+
+ entry_handle = TALLOC_ZERO_P(tmp_ctx, struct policy_handle);
+ if (entry_handle == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ /* ask the endpoint mapper for the port */
+
+ status = rpccli_epm_Map(epm_pipe,
+ tmp_ctx,
+ &(abstract_syntax->uuid),
+ map_tower,
+ entry_handle,
+ max_towers,
+ &num_towers,
+ &towers);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (num_towers != 1) {
+ status = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
+
+ /* extract the port from the answer */
+
+ status = dcerpc_binding_from_tower(tmp_ctx,
+ &(towers.twr->tower),
+ &res_binding);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ /* are further checks here necessary? */
+ if (res_binding->transport != NCACN_IP_TCP) {
+ status = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
+
+ *pport = (uint16_t)atoi(res_binding->endpoint);
+
+done:
+ TALLOC_FREE(tmp_ctx);
+ return status;
+}
+
+/**
+ * Create a rpc pipe client struct, connecting to a host via tcp.
+ * The port is determined by asking the endpoint mapper on the given
+ * host.
+ */
+NTSTATUS rpc_pipe_open_tcp(TALLOC_CTX *mem_ctx, const char *host,
+ const struct ndr_syntax_id *abstract_syntax,
+ struct rpc_pipe_client **presult)
+{
+ NTSTATUS status;
+ uint16_t port;
+
+ status = rpc_pipe_get_tcp_port(host, abstract_syntax, &port);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ status = rpc_pipe_open_tcp_port(mem_ctx, host, port,
+ abstract_syntax, presult);
+
+done:
+ return status;
+}
+
/********************************************************************
Create a rpc pipe client struct, connecting to a unix domain socket
********************************************************************/
diff --git a/source/torture/rpc_open_tcp.c b/source/torture/rpc_open_tcp.c
new file mode 100644
index 0000000..c28c722
--- /dev/null
+++ b/source/torture/rpc_open_tcp.c
@@ -0,0 +1,115 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * test program for rpc_pipe_open_tcp().
+ *
+ * Copyright (C) Michael Adam 2008
+ *
+ * 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 "librpc/gen_ndr/ndr_dfs.h"
+#if 0
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#endif
+#include "librpc/gen_ndr/ndr_dssetup.h"
+#include "librpc/gen_ndr/ndr_echo.h"
+#include "librpc/gen_ndr/ndr_epmapper.h"
+#include "librpc/gen_ndr/ndr_eventlog.h"
+#include "librpc/gen_ndr/ndr_initshutdown.h"
+#include "librpc/gen_ndr/ndr_lsa.h"
+#include "librpc/gen_ndr/ndr_netlogon.h"
+#include "librpc/gen_ndr/ndr_ntsvcs.h"
+#include "librpc/gen_ndr/ndr_samr.h"
+#include "librpc/gen_ndr/ndr_srvsvc.h"
+#include "librpc/gen_ndr/ndr_svcctl.h"
+#include "librpc/gen_ndr/ndr_winreg.h"
+#include "librpc/gen_ndr/ndr_wkssvc.h"
+
+extern const struct ndr_interface_table ndr_table_netdfs;
+#if 0
+extern const struct ndr_interface_table ndr_table_drsuapi;
+#endif
+extern const struct ndr_interface_table ndr_table_dssetup;
+extern const struct ndr_interface_table ndr_table_rpcecho;
+extern const struct ndr_interface_table ndr_table_epmapper;
+extern const struct ndr_interface_table ndr_table_eventlog;
+extern const struct ndr_interface_table ndr_table_initshutdown;
+extern const struct ndr_interface_table ndr_table_lsarpc;
+extern const struct ndr_interface_table ndr_table_netlogon;
+extern const struct ndr_interface_table ndr_table_ntsvcs;
+extern const struct ndr_interface_table ndr_table_samr;
+extern const struct ndr_interface_table ndr_table_srvsvc;
+extern const struct ndr_interface_table ndr_table_svcctl;
+extern const struct ndr_interface_table ndr_table_winreg;
+extern const struct ndr_interface_table ndr_table_wkssvc;
+
+const struct ndr_interface_table *tables[] = {
+ &ndr_table_netdfs,
+#if 0
+ &ndr_table_drsuapi,
+#endif
+ &ndr_table_dssetup,
+ &ndr_table_rpcecho,
+ &ndr_table_epmapper,
+ &ndr_table_eventlog,
+ &ndr_table_initshutdown,
+ &ndr_table_lsarpc,
+ &ndr_table_netlogon,
+ &ndr_table_ntsvcs,
+ &ndr_table_samr,
+ &ndr_table_srvsvc,
+ &ndr_table_svcctl,
+ &ndr_table_winreg,
+ &ndr_table_wkssvc,
+ NULL
+};
+
+int main(int argc, const char **argv)
+{
+ const struct ndr_interface_table **table;
+ NTSTATUS status;
+ struct rpc_pipe_client *rpc_pipe = NULL;
+ TALLOC_CTX *mem_ctx = talloc_stackframe();
+
+ if (argc != 3) {
+ d_printf("USAGE: %s interface host\n", argv[0]);
+ return -1;
+ }
+
+ for (table = tables; *table != NULL; table++) {
+ if (strequal((*table)->name, argv[1])) {
+ break;
+ }
+ }
+
+ if (*table == NULL) {
+ d_printf("ERROR: unknown interface '%s' given\n", argv[1]);
+ return -1;
+ }
+
+ status = rpc_pipe_open_tcp(mem_ctx, argv[2], &((*table)->syntax_id),
+ &rpc_pipe);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("ERROR calling rpc_pipe_open_tcp(): %s\n",
+ nt_errstr(status));
+ return -1;
+ }
+
+ TALLOC_FREE(mem_ctx);
+
+ return 0;
+}
+
--
Samba Shared Repository
More information about the samba-cvs
mailing list