s3: libsmb: Correctly do lifecycle management on cli->smb1.tcon and cli->smb2.tcon.
authorJeremy Allison <jra@samba.org>
Tue, 13 Jun 2017 23:37:39 +0000 (16:37 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 17 Jun 2017 04:39:20 +0000 (06:39 +0200)
Treat them identically. Create them on demand after for a tcon call,
and delete them on a tdis call.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
source3/libsmb/cliconnect.c
source3/libsmb/clientgen.c

index 200657aff09bb34c977faa2a8ccd822e183a81c0..3fa80a2ec36b08763ceaca539713d300ddb2514c 100644 (file)
@@ -1948,6 +1948,13 @@ struct tevent_req *cli_tcon_andx_create(TALLOC_CTX *mem_ctx,
        state->cli = cli;
        vwv = state->vwv;
 
+       TALLOC_FREE(cli->smb1.tcon);
+       cli->smb1.tcon = smbXcli_tcon_create(cli);
+       if (tevent_req_nomem(cli->smb1.tcon, req)) {
+               return tevent_req_post(req, ev);
+       }
+       smb1cli_tcon_set_id(cli->smb1.tcon, UINT16_MAX);
+
        cli->share = talloc_strdup(cli, share);
        if (!cli->share) {
                return NULL;
@@ -2257,6 +2264,7 @@ static struct tevent_req *cli_tree_connect_send(
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
                char *unc;
 
+               TALLOC_FREE(cli->smb2.tcon);
                cli->smb2.tcon = smbXcli_tcon_create(cli);
                if (tevent_req_nomem(cli->smb2.tcon, req)) {
                        return tevent_req_post(req, ev);
@@ -2429,7 +2437,7 @@ static void cli_tdis_done(struct tevent_req *subreq)
                tevent_req_nterror(req, status);
                return;
        }
-       cli_state_set_tid(state->cli, UINT16_MAX);
+       TALLOC_FREE(state->cli->smb1.tcon);
        tevent_req_done(req);
 }
 
@@ -2445,10 +2453,14 @@ NTSTATUS cli_tdis(struct cli_state *cli)
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               return smb2cli_tdis(cli->conn,
+               status = smb2cli_tdis(cli->conn,
                                    cli->timeout,
                                    cli->smb2.session,
                                    cli->smb2.tcon);
+               if (NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(cli->smb2.tcon);
+               }
+               return status;
        }
 
        if (smbXcli_conn_has_async_calls(cli->conn)) {
@@ -3623,6 +3635,13 @@ static struct tevent_req *cli_raw_tcon_send(
                return tevent_req_post(req, ev);
        }
 
+       TALLOC_FREE(cli->smb1.tcon);
+       cli->smb1.tcon = smbXcli_tcon_create(cli);
+       if (tevent_req_nomem(cli->smb1.tcon, req)) {
+               return tevent_req_post(req, ev);
+       }
+       smb1cli_tcon_set_id(cli->smb1.tcon, UINT16_MAX);
+
        bytes = talloc_array(state, uint8_t, 0);
        bytes = smb_bytes_push_bytes(bytes, 4, NULL, 0);
        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn),
index 4541763ea3f2ce4bebc41629ad3530b4b68b4f1d..2b53a930809a305d749e1236256cb506020da33a 100644 (file)
@@ -227,11 +227,6 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
 
        cli->smb1.pid = (uint32_t)getpid();
        cli->smb1.vc_num = cli->smb1.pid;
-       cli->smb1.tcon = smbXcli_tcon_create(cli);
-       if (cli->smb1.tcon == NULL) {
-               goto error;
-       }
-       smb1cli_tcon_set_id(cli->smb1.tcon, UINT16_MAX);
        cli->smb1.session = smbXcli_session_create(cli, cli->conn);
        if (cli->smb1.session == NULL) {
                goto error;