From 294f69762b4d3b56694a16909ece6cc575a7c7fa Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 14 Aug 2025 19:20:02 +0200 Subject: [PATCH 1/6] s3/rpc_server/dfs: fix creating a DFS link If there's no existing link, get_referred_path() returns NT_STATUS_OBJECT_PATH_NOT_FOUND. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 2cb2991ccdd5d4f63e4c5b3ccc4454a6b39d6afe) --- source3/rpc_server/dfs/srv_dfs_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source3/rpc_server/dfs/srv_dfs_nt.c b/source3/rpc_server/dfs/srv_dfs_nt.c index 8eaa59a8b0e0..d8aeb76a1fb8 100644 --- a/source3/rpc_server/dfs/srv_dfs_nt.c +++ b/source3/rpc_server/dfs/srv_dfs_nt.c @@ -97,7 +97,9 @@ WERROR _dfs_Add(struct pipes_struct *p, struct dfs_Add *r) remote_address, local_address, jn, &consumedcnt, &self_ref); - if(!NT_STATUS_IS_OK(status)) { + if(!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND)) + { return ntstatus_to_werror(status); } -- 2.50.0 From 8349bf820ec540afe7a8713f0a8894407bea5ea4 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 15 Aug 2025 11:50:26 +0200 Subject: [PATCH 2/6] vfs_xattr_tdb: fix dangling symlink detection The caller might not have called stat on smb_fname. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 2e88ba4b4de146327c19682d59bbe34d68158bf7) --- source3/modules/vfs_xattr_tdb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c index 447d868924d1..19331d0de4f6 100644 --- a/source3/modules/vfs_xattr_tdb.c +++ b/source3/modules/vfs_xattr_tdb.c @@ -604,13 +604,12 @@ static int xattr_tdb_unlinkat(vfs_handle_struct *handle, } else { ret = SMB_VFS_NEXT_STAT(handle, full_fname); if (ret == -1 && (errno == ENOENT || errno == ELOOP)) { - if (VALID_STAT(smb_fname->st) && - S_ISLNK(smb_fname->st.st_ex_mode)) { - /* - * Original name was a link - Could be - * trying to remove a dangling symlink. - */ - ret = SMB_VFS_NEXT_LSTAT(handle, full_fname); + /* + * Could be trying to remove a dangling symlink. + */ + ret = SMB_VFS_NEXT_LSTAT(handle, full_fname); + if (ret == 0 && !S_ISLNK(full_fname->st.st_ex_mode)) { + ret = -1; } } } -- 2.50.0 From 048e464e9c2c83fe67c724f18e2571060ebbfcf9 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 15 Aug 2025 10:14:53 +0200 Subject: [PATCH 3/6] pylibsmb: add SMB2_FIND_ID_BOTH_DIRECTORY_INFO BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 698a0195f72a091e9ed6b0448160c79e37761840) --- source3/libsmb/pylibsmb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index 67872d8e3b1f..cba910d173d8 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -3740,6 +3740,7 @@ MODULE_INIT_FUNC(libsmb_samba_cwrapper) ADD_STRING(SMB2_CREATE_TAG_APP_INSTANCE_ID); ADD_STRING(SVHDX_OPEN_DEVICE_CONTEXT); ADD_STRING(SMB2_CREATE_TAG_POSIX); + ADD_FLAGS(SMB2_FIND_ID_BOTH_DIRECTORY_INFO); ADD_FLAGS(SMB2_FIND_POSIX_INFORMATION); ADD_FLAGS(FILE_SUPERSEDE); ADD_FLAGS(FILE_OPEN); -- 2.50.0 From 87e3bcc7f605cc0f35a92cdf5c3f84fac24c3853 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 15 Aug 2025 11:49:27 +0200 Subject: [PATCH 4/6] python/tests: also populate self.server in calls LibsmbTests setup() BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 5f7b31927733b0ff3e1207be242f1ddb2cb699bd) --- python/samba/tests/libsmb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/samba/tests/libsmb.py b/python/samba/tests/libsmb.py index 3ac1b68a59b4..e3683901df20 100644 --- a/python/samba/tests/libsmb.py +++ b/python/samba/tests/libsmb.py @@ -43,6 +43,7 @@ import stat server_conf_dir = os.path.dirname(server_conf) self.global_inject = os.path.join(server_conf_dir, "global_inject.conf") + self.server = samba.tests.env_get_var_value("SERVER") self.server_ip = samba.tests.env_get_var_value("SERVER_IP") def clean_file(self, conn, filename): -- 2.50.0 From 8e9dd7eafb96aa83b92d3fafb07a3bd55bae6f62 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 14 Aug 2025 17:18:08 +0200 Subject: [PATCH 5/6] CI: add Python test samba.tests.dcerpc.dfs.DfsTests.test_dfs_reparse_tag BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke (cherry picked from commit 43ee86c0c757e95712ed52bd336d2085485498ba) --- python/samba/tests/dcerpc/dfs.py | 48 +++++++++++++++++++++++++ selftest/knownfail.d/samba.tests.dcerpc | 1 + source4/selftest/tests.py | 1 + 3 files changed, 50 insertions(+) create mode 100644 python/samba/tests/dcerpc/dfs.py create mode 100644 selftest/knownfail.d/samba.tests.dcerpc diff --git a/python/samba/tests/dcerpc/dfs.py b/python/samba/tests/dcerpc/dfs.py new file mode 100644 index 000000000000..0fcce324e55a --- /dev/null +++ b/python/samba/tests/dcerpc/dfs.py @@ -0,0 +1,48 @@ +# +# Unix SMB/CIFS implementation. +# Copyright Ralph Boehme 2025 +# +# 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 . +# + +"""Tests for samba.dcerpc.dfs""" + +import os +import logging +import samba +from samba.dcerpc import dfs +from samba.tests import RpcInterfaceTestCase +from samba.logger import get_samba_logger +from samba.credentials import Credentials +from samba.samba3 import libsmb_samba_internal as libsmb +import samba.tests.libsmb +from samba.samba3 import param as s3param + +logger = get_samba_logger(name=__name__) + +class DfsTests(samba.tests.libsmb.LibsmbTests): + def setUp(self): + super().setUp() + self.dfs = dfs.netdfs('ncacn_np:%s[/pipe/netdfs]' % self.server, self.lp, self.creds) + self.c = libsmb.Conn(self.server_ip, "msdfs-share", self.lp, self.creds) + + def tearDown(self): + super().tearDown() + + def test_dfs_reparse_tag(self): + self.dfs.Add('\\\\%s\\msdfs-share\\dfslink' % self.server, self.server, 'tmp', 'comment', 0) + l = self.c.list('', info_level=libsmb.SMB2_FIND_ID_BOTH_DIRECTORY_INFO) + files = {i['name']: i for i in l} + self.assertEqual(files['dfslink']['reparse_tag'], libsmb.IO_REPARSE_TAG_DFS) + self.dfs.Remove('\\\\%s\\msdfs-share\\dfslink' % self.server, self.server, 'tmp') diff --git a/selftest/knownfail.d/samba.tests.dcerpc b/selftest/knownfail.d/samba.tests.dcerpc new file mode 100644 index 000000000000..8d64a4a3dd8c --- /dev/null +++ b/selftest/knownfail.d/samba.tests.dcerpc @@ -0,0 +1 @@ +^samba.tests.dcerpc.dfs.samba.tests.dcerpc.dfs.DfsTests.test_dfs_reparse_tag\(fileserver\) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 50cabb903bba..0cd0a822c942 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -2237,6 +2237,7 @@ planoldpythontestsuite("proclimitdc", planoldpythontestsuite("none", "samba.tests.usage") planpythontestsuite("fileserver", "samba.tests.dcerpc.mdssvc") +planpythontestsuite("fileserver", "samba.tests.dcerpc.dfs") planoldpythontestsuite("none", "samba.tests.compression") planpythontestsuite("none", "samba.tests.security_descriptors") -- 2.50.0 From 1a76e570b8094b5ae399d46f48f1f99e384a80ec Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 15 Aug 2025 10:13:33 +0200 Subject: [PATCH 6/6] smbd: return correct reparse tag DFS when listing directories BUG: https://bugzilla.samba.org/show_bug.cgi?id=15843 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Fri Aug 15 15:37:05 UTC 2025 on atb-devel-224 (cherry picked from commit 0be53d7ac0a39d6a48c6c5e2144f342c0d406781) --- selftest/knownfail.d/samba.tests.dcerpc | 1 - source3/smbd/dir.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 selftest/knownfail.d/samba.tests.dcerpc diff --git a/selftest/knownfail.d/samba.tests.dcerpc b/selftest/knownfail.d/samba.tests.dcerpc deleted file mode 100644 index 8d64a4a3dd8c..000000000000 --- a/selftest/knownfail.d/samba.tests.dcerpc +++ /dev/null @@ -1 +0,0 @@ -^samba.tests.dcerpc.dfs.samba.tests.dcerpc.dfs.DfsTests.test_dfs_reparse_tag\(fileserver\) diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 137d9a1dacde..95869e054f31 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -639,6 +639,8 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx, smb_fname->st.st_ex_mode = (smb_fname->st.st_ex_mode & ~S_IFMT) | S_IFDIR; + smb_fname->fsp->fsp_name->st.st_ex_mode = + smb_fname->st.st_ex_mode; mode = dos_mode_msdfs(conn, dname, &smb_fname->st); get_dosmode = false; -- 2.50.0