summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-11-30 07:17:31 +0100
committerStefan Metzmacher <metze@samba.org>2011-11-30 13:41:08 +0100
commit4877be53df1181f75d603fa4edc67c34e1ba5141 (patch)
treeabc8c5f1a71ce84cfbd8b50ac4489d82f8e78e06 /source4
parentb51c92a903877015acf268ab8ff0e07d3a82b295 (diff)
downloadsamba-4877be53df1181f75d603fa4edc67c34e1ba5141.tar.gz
samba-4877be53df1181f75d603fa4edc67c34e1ba5141.tar.bz2
samba-4877be53df1181f75d603fa4edc67c34e1ba5141.zip
s4:libcli: move smbcli_transport_establish() logic into smbcli_socket_connect()
metze
Diffstat (limited to 'source4')
-rw-r--r--source4/client/client.c18
-rw-r--r--source4/libcli/cliconnect.c29
-rw-r--r--source4/libcli/libcli.h7
-rw-r--r--source4/torture/basic/base.c16
4 files changed, 32 insertions, 38 deletions
diff --git a/source4/client/client.c b/source4/client/client.c
index 57686bb7ba..d7adc41ca1 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -3184,6 +3184,7 @@ static int do_message_op(const char *netbios_name, const char *desthost,
struct nbt_name called, calling;
const char *server_name;
struct smbcli_state *cli;
+ bool ok;
make_nbt_name_client(&calling, netbios_name);
@@ -3191,17 +3192,18 @@ static int do_message_op(const char *netbios_name, const char *desthost,
server_name = destip ? destip : desthost;
- if (!(cli = smbcli_state_init(NULL)) ||
- !smbcli_socket_connect(cli, server_name, destports,
- ev_ctx, resolve_ctx, options,
- socket_options)) {
- d_printf("Connection to %s failed\n", server_name);
+ cli = smbcli_state_init(NULL);
+ if (cli == NULL) {
+ d_printf("smbcli_state_init() failed\n");
return 1;
}
- if (!smbcli_transport_establish(cli, &calling, &called)) {
- d_printf("session request failed\n");
- talloc_free(cli);
+ ok = smbcli_socket_connect(cli, server_name, destports,
+ ev_ctx, resolve_ctx, options,
+ socket_options,
+ &calling, &called);
+ if (!ok) {
+ d_printf("Connection to %s failed\n", server_name);
return 1;
}
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index e25a400985..cdb04fb1f6 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -35,39 +35,32 @@ bool smbcli_socket_connect(struct smbcli_state *cli, const char *server,
struct tevent_context *ev_ctx,
struct resolve_context *resolve_ctx,
struct smbcli_options *options,
- const char *socket_options)
+ const char *socket_options,
+ struct nbt_name *calling,
+ struct nbt_name *called)
{
struct smbcli_socket *sock;
+ uint32_t timeout_msec = options->request_timeout * 1000;
+ NTSTATUS status;
sock = smbcli_sock_connect_byname(server, ports, NULL,
resolve_ctx, ev_ctx,
socket_options);
if (sock == NULL) return false;
-
- cli->transport = smbcli_transport_init(sock, cli, true, options);
- if (!cli->transport) {
- return false;
- }
-
- return true;
-}
-/* wrapper around smbcli_transport_connect() */
-bool smbcli_transport_establish(struct smbcli_state *cli,
- struct nbt_name *calling,
- struct nbt_name *called)
-{
- uint32_t timeout_msec = cli->transport->options.request_timeout * 1000;
- NTSTATUS status;
-
- status = smbcli_transport_connect(cli->transport->socket,
+ status = smbcli_transport_connect(sock,
timeout_msec,
calling, called);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
+ cli->transport = smbcli_transport_init(sock, cli, true, options);
+ if (!cli->transport) {
+ return false;
+ }
+
return true;
}
diff --git a/source4/libcli/libcli.h b/source4/libcli/libcli.h
index 81a31d1933..9f661e3f4d 100644
--- a/source4/libcli/libcli.h
+++ b/source4/libcli/libcli.h
@@ -88,10 +88,9 @@ bool smbcli_socket_connect(struct smbcli_state *cli, const char *server,
struct tevent_context *ev_ctx,
struct resolve_context *resolve_ctx,
struct smbcli_options *options,
- const char *socket_options);
-bool smbcli_transport_establish(struct smbcli_state *cli,
- struct nbt_name *calling,
- struct nbt_name *called);
+ const char *socket_options,
+ struct nbt_name *calling,
+ struct nbt_name *called);
NTSTATUS smbcli_negprot(struct smbcli_state *cli, bool unicode, int maxprotocol);
NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
struct cli_credentials *credentials,
diff --git a/source4/torture/basic/base.c b/source4/torture/basic/base.c
index 519ad406fe..d1005d0bdc 100644
--- a/source4/torture/basic/base.c
+++ b/source4/torture/basic/base.c
@@ -40,6 +40,7 @@ static struct smbcli_state *open_nbt_connection(struct torture_context *tctx)
struct smbcli_state *cli;
const char *host = torture_setting_string(tctx, "host", NULL);
struct smbcli_options options;
+ bool ok;
make_nbt_name_client(&calling, lpcfg_netbios_name(tctx->lp_ctx));
@@ -53,18 +54,17 @@ static struct smbcli_state *open_nbt_connection(struct torture_context *tctx)
lpcfg_smbcli_options(tctx->lp_ctx, &options);
- if (!smbcli_socket_connect(cli, host, lpcfg_smb_ports(tctx->lp_ctx), tctx->ev,
- lpcfg_resolve_context(tctx->lp_ctx), &options,
- lpcfg_socket_options(tctx->lp_ctx))) {
+ ok = smbcli_socket_connect(cli, host, lpcfg_smb_ports(tctx->lp_ctx),
+ tctx->ev,
+ lpcfg_resolve_context(tctx->lp_ctx),
+ &options,
+ lpcfg_socket_options(tctx->lp_ctx),
+ &calling, &called);
+ if (!ok) {
torture_comment(tctx, "Failed to connect with %s\n", host);
goto failed;
}
- if (!smbcli_transport_establish(cli, &calling, &called)) {
- torture_comment(tctx, "%s rejected the session\n",host);
- goto failed;
- }
-
return cli;
failed: