s4:libcli: move smbcli_transport_establish() logic into smbcli_socket_connect()
authorStefan Metzmacher <metze@samba.org>
Wed, 30 Nov 2011 06:17:31 +0000 (07:17 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 30 Nov 2011 12:41:08 +0000 (13:41 +0100)
metze

source4/client/client.c
source4/libcli/cliconnect.c
source4/libcli/libcli.h
source4/torture/basic/base.c

index 57686bb7baf709444785c60271396df3575778fd..d7adc41ca1a7157cc56ae54ca718d1df17c7e29b 100644 (file)
@@ -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;
        }
 
index e25a4009859d05fd272ffd6649ced37757149d76..cdb04fb1f6bdd15af03ee39d665c02e89df97de8 100644 (file)
@@ -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;
 }
 
index 81a31d1933fe72b626279cbdb951e9f8d22bbf2d..9f661e3f4ddfe06d63f6939bcc532deaa5ad47a6 100644 (file)
@@ -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,
index 519ad406fef76d2d86b0fc1fa50cfdb811f649e4..d1005d0bdce2ce20de4a3c9f234efca46206688e 100644 (file)
@@ -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: