[SCM] Samba Shared Repository - branch v4-6-test updated

Karolin Seeger kseeger at samba.org
Wed Jun 28 13:20:03 UTC 2017


The branch, v4-6-test has been updated
       via  f625a63 auth/ntlmssp: enforce NTLMSSP_NEGOTIATE_NTLM2 for the NTLMv2 client case
       via  8aea504 s3: smbd: fix regression with non-wide symlinks to directories over SMB3.
       via  79afb2e s3: smbd: Add regression test for non-wide symlinks to directories fail over SMB3.
       via  c850f47 docs-xml: Sort input file list
       via  fad0c0d s3: libsmb: Correctly save and restore connection tcon in smbclient, smbcacls and smbtorture3.
       via  d2a309b s3: libsmb: Correctly do lifecycle management on cli->smb1.tcon and cli->smb2.tcon.
       via  de0fbbe s3: libsmb: Fix cli_state_has_tcon() to cope with SMB2 connections.
       via  8edc00e s3: libsmb: Widen cli_state_get_tid() / cli_state_set_tid() to 32-bits.
       via  c519326 s3: smbtorture: Show correct use of cli_state_save_tcon() / cli_state_restore_tcon().
       via  b17ab94 s3: libsmb: Add cli_state_save_tcon() / cli_state_restore_tcon().
       via  d261f6d libcli: smb: Add smb2cli_tcon_set_id().
       via  0ea8e0b libcli: smb: Add smbXcli_tcon_copy().
       via  9d053cf s3: smbd: When deleting an fsp pointer ensure we don't keep any references to it around.
      from  f10ce74 ctdb-recovery: Do not run local ip verification when in recovery

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-6-test


- Log -----------------------------------------------------------------
commit f625a639e75f5b3a20eb5e35ef1c6fdd9745b50e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Jun 24 13:16:03 2017 +0200

    auth/ntlmssp: enforce NTLMSSP_NEGOTIATE_NTLM2 for the NTLMv2 client case
    
    Some servers may not announce the NTLMSSP_NEGOTIATE_NTLM2
    (a.k.a. NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY) bit.
    
    But if we're acting as a client using NTLMv2 we need to
    enforce this flag, because it's not really a negotiationable
    in that case.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12862
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 8ee4f8236830eb3fa1b273fa6927792a800f86bd)
    
    Autobuild-User(v4-6-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-6-test): Wed Jun 28 15:19:53 CEST 2017 on sn-devel-144

commit 8aea504d02800fa968a8d13de86134e128244f5d
Author: Daniel Kobras <d.kobras at science-computing.de>
Date:   Fri Jun 23 15:39:21 2017 +0200

    s3: smbd: fix regression with non-wide symlinks to directories over SMB3.
    
    The errno returned by open() is ambiguous when called with flags O_NOFOLLOW and
    O_DIRECTORY on a symlink. With ELOOP, we know for certain that we've tried to
    open a symlink. With ENOTDIR, we might have hit a symlink, and need to perform
    further checks to be sure. Adjust non_widelink_open() accordingly. This fixes
    a regression where symlinks to directories within the same share were no
    longer followed for some call paths on systems returning ENOTDIR in the above
    case.
    
    Also remove the knownfail added in previous commit.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12860
    
    Signed-off-by: Daniel Kobras <d.kobras at science-computing.de>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit acc16592b451905dabc093f1d261e93cd3b59520)

commit 79afb2e2d962f161bee33ff234550c5eca4398cd
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jun 23 11:12:22 2017 -0700

    s3: smbd: Add regression test for non-wide symlinks to directories fail over SMB3.
    
    Mark as knownfail.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12860
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit f1f388ef80a6516c2f44b7778420f8ffe28c6471)

commit c850f47d11b1b73af1586d1f70beae1138df8485
Author: Bernhard M. Wiedemann via samba-technical <samba-technical at lists.samba.org>
Date:   Mon Jun 26 09:46:18 2017 +0200

    docs-xml: Sort input file list
    
    because filesystems return entries in undeterministic order
    and that ends up in index.xml and influences index.html
    preventing reproducible builds of samba packages (e.g. for openSUSE)
    
    See https://reproducible-builds.org/ for why this matters
    
    Signed-off-by: Bernhard M. Wiedemann <bwiedemann at suse.de>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    
    Autobuild-User(master): David Disseldorp <ddiss at samba.org>
    Autobuild-Date(master): Tue Jun 27 16:56:06 CEST 2017 on sn-devel-144
    
    (cherry picked from commit eedebe2ef1b6ff92975289b6076f236650744621)
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12854

commit fad0c0da857b140932327962128e071eba965b9a
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:56:48 2017 -0700

    s3: libsmb: Correctly save and restore connection tcon in smbclient, smbcacls and smbtorture3.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit bd31d538a26bb21cbb53986a6105204da4392e2d)

commit d2a309b90e50d7d15175031dc5881ea722ed1317
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:37:39 2017 -0700

    s3: libsmb: Correctly do lifecycle management on cli->smb1.tcon and cli->smb2.tcon.
    
    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 at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit 50f50256aa8805921c42d0f9f2f8f89d06d9bd93)

commit de0fbbe0dd1005247f79288af8b51732d4c4b7fe
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:36:54 2017 -0700

    s3: libsmb: Fix cli_state_has_tcon() to cope with SMB2 connections.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit c9178ed9cc69b9089292db28ac1a0b7a0519bc2c)

commit 8edc00ea2817cac87f094baf6cfac0143e5ff431
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:26:00 2017 -0700

    s3: libsmb: Widen cli_state_get_tid() / cli_state_set_tid() to 32-bits.
    
    Copes with SMB2 connections.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit 93fa0c8660e47cb2605d70dac1156576ab719d64)

commit c5193260ebf55a39096c81f9c5cf6da39f709f9e
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:25:25 2017 -0700

    s3: smbtorture: Show correct use of cli_state_save_tcon() / cli_state_restore_tcon().
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit 5c0efc9a5ef8ddf96dc394110063bebd5f057415)

commit b17ab94a38d5e90c7547c8c5dce75fd18f3ed15b
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:15:00 2017 -0700

    s3: libsmb: Add cli_state_save_tcon() / cli_state_restore_tcon().
    
    Save and restore tcon pointers in smb1 or smb2 structs.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit 39026f1c5dbb83120b70b3d9131138a9c2344ba6)

commit d261f6d026e6b3433147d7f1051bb9d26dda8c9f
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:08:22 2017 -0700

    libcli: smb: Add smb2cli_tcon_set_id().
    
    Will be used in test and client code.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit e726b60226105d0f52a66dac47bfc5797cfc18e7)

commit 0ea8e0b04adf2b4b5d547350097f084225b738ae
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 13 16:06:22 2017 -0700

    libcli: smb: Add smbXcli_tcon_copy().
    
    Makes a deep copy of a struct smbXcli_tcon *, will
    be used later.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12831
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit 655e10685840fd5ebfde24396853b74020a1dc85)

commit 9d053cf5babc8aaab02bfb56e2e87320c32ed68d
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Jun 20 11:20:38 2017 -0700

    s3: smbd: When deleting an fsp pointer ensure we don't keep any references to it around.
    
    Based on a suggestion from <lev at zadarastorage.com>
    
    https://bugzilla.samba.org/show_bug.cgi?id=12818
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Jun 22 00:12:49 CEST 2017 on sn-devel-144

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

Summary of changes:
 auth/ntlmssp/ntlmssp_util.c               | 21 ++++++++++
 docs-xml/Makefile                         |  2 +-
 libcli/smb/smbXcli_base.c                 | 37 +++++++++++++++++
 libcli/smb/smbXcli_base.h                 |  3 ++
 selftest/target/Samba3.pm                 |  7 ++++
 source3/client/client.c                   |  5 ++-
 source3/lib/util_sd.c                     | 24 +++++++++--
 source3/libsmb/cliconnect.c               | 23 ++++++++++-
 source3/libsmb/clidfs.c                   | 18 +++++++--
 source3/libsmb/clientgen.c                | 67 ++++++++++++++++++++++++-------
 source3/libsmb/proto.h                    |  7 +++-
 source3/script/tests/test_smbclient_s3.sh | 55 +++++++++++++++++++++++++
 source3/smbd/files.c                      |  4 +-
 source3/smbd/open.c                       | 24 ++++++++++-
 source3/torture/test_smb2.c               |  8 ++--
 source3/torture/torture.c                 | 24 +++++++++--
 source3/utils/net_rpc.c                   | 12 ++++--
 source3/utils/smbcacls.c                  | 12 +++++-
 18 files changed, 307 insertions(+), 46 deletions(-)


Changeset truncated at 500 lines:

diff --git a/auth/ntlmssp/ntlmssp_util.c b/auth/ntlmssp/ntlmssp_util.c
index 4ae6101..9c7325a 100644
--- a/auth/ntlmssp/ntlmssp_util.c
+++ b/auth/ntlmssp/ntlmssp_util.c
@@ -75,6 +75,27 @@ NTSTATUS ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
 {
 	uint32_t missing_flags = ntlmssp_state->required_flags;
 
+	if (ntlmssp_state->use_ntlmv2) {
+		/*
+		 * Using NTLMv2 as a client implies
+		 * using NTLMSSP_NEGOTIATE_NTLM2
+		 * (NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY)
+		 *
+		 * Note that 'use_ntlmv2' is only set
+		 * true in the client case.
+		 *
+		 * Even if the server has a bug and does not announce
+		 * it, we need to assume it's present.
+		 *
+		 * Note that we also have the flag
+		 * in ntlmssp_state->required_flags,
+		 * see gensec_ntlmssp_client_start().
+		 *
+		 * See bug #12862.
+		 */
+		flags |= NTLMSSP_NEGOTIATE_NTLM2;
+	}
+
 	if (flags & NTLMSSP_NEGOTIATE_UNICODE) {
 		ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
 		ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM;
diff --git a/docs-xml/Makefile b/docs-xml/Makefile
index d9ae92b..6a33b17 100644
--- a/docs-xml/Makefile
+++ b/docs-xml/Makefile
@@ -8,7 +8,7 @@ include Makefile.settings
 
 # Docs to build
 MAIN_DOCS = $(patsubst %/index.xml,%,$(wildcard */index.xml))
-MANPAGES = $(wildcard $(MANPAGEDIR)/*.?.xml)
+MANPAGES = $(sort $(wildcard $(MANPAGEDIR)/*.?.xml))
 
 # Lists of files to process
 MANPAGES_PLUCKER = $(patsubst $(MANPAGEDIR)/%.xml,$(PLUCKERDIR)/%.pdb,$(MANPAGES))
diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c
index 593edf9..b21d796 100644
--- a/libcli/smb/smbXcli_base.c
+++ b/libcli/smb/smbXcli_base.c
@@ -6118,6 +6118,38 @@ struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx)
 	return tcon;
 }
 
+/*
+ * Return a deep structure copy of a struct smbXcli_tcon *
+ */
+
+struct smbXcli_tcon *smbXcli_tcon_copy(TALLOC_CTX *mem_ctx,
+				const struct smbXcli_tcon *tcon_in)
+{
+	struct smbXcli_tcon *tcon;
+
+	tcon = talloc_memdup(mem_ctx, tcon_in, sizeof(struct smbXcli_tcon));
+	if (tcon == NULL) {
+		return NULL;
+	}
+
+	/* Deal with the SMB1 strings. */
+	if (tcon_in->smb1.service != NULL) {
+		tcon->smb1.service = talloc_strdup(tcon, tcon_in->smb1.service);
+		if (tcon->smb1.service == NULL) {
+			TALLOC_FREE(tcon);
+			return NULL;
+		}
+	}
+	if (tcon->smb1.fs_type != NULL) {
+		tcon->smb1.fs_type = talloc_strdup(tcon, tcon_in->smb1.fs_type);
+		if (tcon->smb1.fs_type == NULL) {
+			TALLOC_FREE(tcon);
+			return NULL;
+		}
+	}
+	return tcon;
+}
+
 void smbXcli_tcon_set_fs_attributes(struct smbXcli_tcon *tcon,
 				    uint32_t fs_attributes)
 {
@@ -6196,6 +6228,11 @@ uint32_t smb2cli_tcon_current_id(struct smbXcli_tcon *tcon)
 	return tcon->smb2.tcon_id;
 }
 
+void smb2cli_tcon_set_id(struct smbXcli_tcon *tcon, uint32_t tcon_id)
+{
+	tcon->smb2.tcon_id = tcon_id;
+}
+
 uint32_t smb2cli_tcon_capabilities(struct smbXcli_tcon *tcon)
 {
 	return tcon->smb2.capabilities;
diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
index 702eedf..e48fc35 100644
--- a/libcli/smb/smbXcli_base.h
+++ b/libcli/smb/smbXcli_base.h
@@ -496,6 +496,8 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
 NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session);
 
 struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx);
+struct smbXcli_tcon *smbXcli_tcon_copy(TALLOC_CTX *mem_ctx,
+				const struct smbXcli_tcon *tcon_in);
 void smbXcli_tcon_set_fs_attributes(struct smbXcli_tcon *tcon,
 				    uint32_t fs_attributes);
 uint32_t smbXcli_tcon_get_fs_attributes(struct smbXcli_tcon *tcon);
@@ -510,6 +512,7 @@ bool smb1cli_tcon_set_values(struct smbXcli_tcon *tcon,
 			     const char *service,
 			     const char *fs_type);
 uint32_t smb2cli_tcon_current_id(struct smbXcli_tcon *tcon);
+void smb2cli_tcon_set_id(struct smbXcli_tcon *tcon, uint32_t tcon_id);
 uint32_t smb2cli_tcon_capabilities(struct smbXcli_tcon *tcon);
 uint32_t smb2cli_tcon_flags(struct smbXcli_tcon *tcon);
 void smb2cli_tcon_set_values(struct smbXcli_tcon *tcon,
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index fb6d0f4..a7699f8 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1356,6 +1356,9 @@ sub provision($$$$$$$$)
 	my $nosymlinks_shrdir="$shrdir/nosymlinks";
 	push(@dirs,$nosymlinks_shrdir);
 
+	my $local_symlinks_shrdir="$shrdir/local_symlinks";
+	push(@dirs,$local_symlinks_shrdir);
+
 	# this gets autocreated by winbindd
 	my $wbsockdir="$prefix_abs/winbindd";
 	my $wbsockprivdir="$lockdir/winbindd_privileged";
@@ -1981,6 +1984,10 @@ sub provision($$$$$$$$)
 	copy = tmp
 	path = $nosymlinks_shrdir
 	follow symlinks = no
+[local_symlinks]
+	copy = tmp
+	path = $local_symlinks_shrdir
+	follow symlinks = yes
 [kernel_oplocks]
 	copy = tmp
 	kernel oplocks = yes
diff --git a/source3/client/client.c b/source3/client/client.c
index 226eb27..f808c9c 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -4703,7 +4703,10 @@ static int cmd_tid(void)
 			d_printf("no tcon currently\n");
 		}
 	} else {
-		uint16_t tid = atoi(tid_str);
+		uint32_t tid = atoi(tid_str);
+		if (!cli_state_has_tcon(cli)) {
+			d_printf("no tcon currently\n");
+		}
 		cli_state_set_tid(cli, tid);
 	}
 
diff --git a/source3/lib/util_sd.c b/source3/lib/util_sd.c
index d79fe79..aa6d4809 100644
--- a/source3/lib/util_sd.c
+++ b/source3/lib/util_sd.c
@@ -84,7 +84,7 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
 				   enum lsa_SidType *type,
 				   char **domain, char **name)
 {
-	uint16_t orig_cnum = cli_state_get_tid(cli);
+	struct smbXcli_tcon *orig_tcon = NULL;
 	struct rpc_pipe_client *p = NULL;
 	struct policy_handle handle;
 	NTSTATUS status;
@@ -93,6 +93,14 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
 	char **domains;
 	char **names;
 
+	if (cli_state_has_tcon(cli)) {
+		orig_tcon = cli_state_save_tcon(cli);
+		if (orig_tcon == NULL) {
+			status = NT_STATUS_NO_MEMORY;
+			goto tcon_fail;
+		}
+	}
+
 	status = cli_tree_connect(cli, "IPC$", "?????", NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto tcon_fail;
@@ -125,7 +133,7 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
 	TALLOC_FREE(p);
 	cli_tdis(cli);
  tcon_fail:
-	cli_state_set_tid(cli, orig_cnum);
+	cli_state_restore_tcon(cli, orig_tcon);
 	TALLOC_FREE(frame);
 	return status;
 }
@@ -165,7 +173,7 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
 				    enum lsa_SidType *type,
 				    struct dom_sid *sid)
 {
-	uint16_t orig_cnum = cli_state_get_tid(cli);
+	struct smbXcli_tcon *orig_tcon = NULL;
 	struct rpc_pipe_client *p;
 	struct policy_handle handle;
 	NTSTATUS status;
@@ -173,6 +181,14 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
 	struct dom_sid *sids;
 	enum lsa_SidType *types;
 
+	if (cli_state_has_tcon(cli)) {
+		orig_tcon = cli_state_save_tcon(cli);
+		if (orig_tcon == NULL) {
+			status = NT_STATUS_NO_MEMORY;
+			goto tcon_fail;
+		}
+	}
+
 	status = cli_tree_connect(cli, "IPC$", "?????", NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto tcon_fail;
@@ -204,7 +220,7 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
 	TALLOC_FREE(p);
 	cli_tdis(cli);
  tcon_fail:
-	cli_state_set_tid(cli, orig_cnum);
+	cli_state_restore_tcon(cli, orig_tcon);
 	TALLOC_FREE(frame);
 	return status;
 }
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index ef03da1..6803d02 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -1945,6 +1945,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;
@@ -2254,6 +2261,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);
@@ -2426,7 +2434,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);
 }
 
@@ -2442,10 +2450,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)) {
@@ -3619,6 +3631,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),
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index c477d7c..75012b2 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -1205,7 +1205,7 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
 	size_t consumed = 0;
 	char *fullpath = NULL;
 	bool res;
-	uint16_t cnum;
+	struct smbXcli_tcon *orig_tcon = NULL;
 	char *newextrapath = NULL;
 	NTSTATUS status;
 	const char *remote_name;
@@ -1215,7 +1215,6 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
 	}
 
 	remote_name = smbXcli_conn_remote_name(cli->conn);
-	cnum = cli_state_get_tid(cli);
 
 	/* special case.  never check for a referral on the IPC$ share */
 
@@ -1230,15 +1229,25 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
 		return false;
 	}
 
+	/* Store tcon state. */
+	if (cli_state_has_tcon(cli)) {
+		orig_tcon = cli_state_save_tcon(cli);
+		if (orig_tcon == NULL) {
+			return false;
+		}
+	}
+
 	/* check for the referral */
 
 	if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", NULL))) {
+		cli_state_restore_tcon(cli, orig_tcon);
 		return false;
 	}
 
 	if (force_encrypt) {
 		status = cli_cm_force_encryption_creds(cli, creds, "IPC$");
 		if (!NT_STATUS_IS_OK(status)) {
+			cli_state_restore_tcon(cli, orig_tcon);
 			return false;
 		}
 	}
@@ -1248,12 +1257,13 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
 	res = NT_STATUS_IS_OK(status);
 
 	status = cli_tdis(cli);
+
+	cli_state_restore_tcon(cli, orig_tcon);
+
 	if (!NT_STATUS_IS_OK(status)) {
 		return false;
 	}
 
-	cli_state_set_tid(cli, cnum);
-
 	if (!res || !num_refs) {
 		return false;
 	}
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index bc5c1b1..2b53a93 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -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;
@@ -341,27 +336,69 @@ uint32_t cli_getpid(struct cli_state *cli)
 
 bool cli_state_has_tcon(struct cli_state *cli)
 {
-	uint16_t tid = cli_state_get_tid(cli);
-
-	if (tid == UINT16_MAX) {
-		return false;
+	uint32_t tid;
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		if (cli->smb2.tcon == NULL) {
+			return false;
+		}
+		tid = cli_state_get_tid(cli);
+		if (tid == UINT32_MAX) {
+			return false;
+		}
+	} else {
+		if (cli->smb1.tcon == NULL) {
+			return false;
+		}
+		tid = cli_state_get_tid(cli);
+		if (tid == UINT16_MAX) {
+			return false;
+		}
 	}
-
 	return true;
 }
 
-uint16_t cli_state_get_tid(struct cli_state *cli)
+uint32_t cli_state_get_tid(struct cli_state *cli)
 {
-	return smb1cli_tcon_current_id(cli->smb1.tcon);
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		return smb2cli_tcon_current_id(cli->smb2.tcon);
+	} else {
+		return (uint32_t)smb1cli_tcon_current_id(cli->smb1.tcon);
+	}
 }
 
-uint16_t cli_state_set_tid(struct cli_state *cli, uint16_t tid)
+uint32_t cli_state_set_tid(struct cli_state *cli, uint32_t tid)
 {
-	uint16_t ret = smb1cli_tcon_current_id(cli->smb1.tcon);
-	smb1cli_tcon_set_id(cli->smb1.tcon, tid);
+	uint32_t ret;
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		ret = smb2cli_tcon_current_id(cli->smb2.tcon);
+		smb2cli_tcon_set_id(cli->smb1.tcon, tid);
+	} else {
+		ret = smb1cli_tcon_current_id(cli->smb1.tcon);
+		smb1cli_tcon_set_id(cli->smb1.tcon, tid);
+	}
 	return ret;
 }
 
+struct smbXcli_tcon *cli_state_save_tcon(struct cli_state *cli)
+{
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		return smbXcli_tcon_copy(cli, cli->smb2.tcon);
+	} else {
+		return smbXcli_tcon_copy(cli, cli->smb1.tcon);
+	}
+}
+
+void cli_state_restore_tcon(struct cli_state *cli, struct smbXcli_tcon *tcon)
+{
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		TALLOC_FREE(cli->smb2.tcon);
+		cli->smb2.tcon = tcon;
+	} else {
+		TALLOC_FREE(cli->smb1.tcon);
+		cli->smb1.tcon = tcon;
+	}
+}
+
 uint16_t cli_state_get_uid(struct cli_state *cli)
 {
 	return smb1cli_session_current_id(cli->smb1.session);
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index 764f3fc..a583a8e 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -196,8 +196,11 @@ uint16_t cli_state_get_vc_num(struct cli_state *cli);
 uint32_t cli_setpid(struct cli_state *cli, uint32_t pid);
 uint32_t cli_getpid(struct cli_state *cli);
 bool cli_state_has_tcon(struct cli_state *cli);
-uint16_t cli_state_get_tid(struct cli_state *cli);
-uint16_t cli_state_set_tid(struct cli_state *cli, uint16_t tid);
+uint32_t cli_state_get_tid(struct cli_state *cli);
+uint32_t cli_state_set_tid(struct cli_state *cli, uint32_t tid);
+struct smbXcli_tcon;
+struct smbXcli_tcon *cli_state_save_tcon(struct cli_state *cli);
+void cli_state_restore_tcon(struct cli_state *cli, struct smbXcli_tcon *tcon);
 uint16_t cli_state_get_uid(struct cli_state *cli);
 uint16_t cli_state_set_uid(struct cli_state *cli, uint16_t uid);
 bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive);
diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh
index be7aafb..ce1cb08 100755
--- a/source3/script/tests/test_smbclient_s3.sh
+++ b/source3/script/tests/test_smbclient_s3.sh
@@ -1215,6 +1215,57 @@ EOF
     fi
 }
 
+# Test we can follow normal symlinks.
+# Bug: https://bugzilla.samba.org/show_bug.cgi?id=12860
+# Note - this needs to be tested over SMB3, not SMB1.
+
+test_local_symlinks()
+{
+# Setup test dirs.
+    LOCAL_RAWARGS="${CONFIGURATION} -mSMB3"
+    LOCAL_ADDARGS="${LOCAL_RAWARGS} $*"
+
+    test_dir="$LOCAL_PATH/local_symlinks/test"
+
+    slink_name="$test_dir/sym_name"
+    slink_target_dir="$test_dir/dir1"
+
+    rm -rf $test_dir
+
+    mkdir -p $test_dir


-- 
Samba Shared Repository



More information about the samba-cvs mailing list