Bug 16098 - Not possible to set set-user-ID, set-group-ID and sticky bits with SMB3 POSIX
Summary: Not possible to set set-user-ID, set-group-ID and sticky bits with SMB3 POSIX
Status: ASSIGNED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Ralph Böhme
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-06-08 17:20 UTC by Ralph Böhme
Modified: 2026-06-08 17:20 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Böhme 2026-06-08 17:20:34 UTC
In check_smb2_posix_chmod_ace() we filter out the special bits:

        *pmode &= (S_IRWXU | S_IRWXG | S_IRWXO);

Fixing this is trivial, the CI test will require some work.

From 676875f04fb269ba0ffb9b8c9d47b36a76c570b6 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow@samba.org>
Date: Mon, 8 Jun 2026 10:59:56 +0200
Subject: [PATCH] WIP

test wip:

        sd = security.descriptor.from_sddl(ntacl_sd, self.domain_sid)

        fnum = self.create(
            Name=filename,
            DesiredAccess=access_mask,
            ShareAccess=(FILE_SHARE_READ|FILE_SHARE_WRITE))
        try:
            self.set_sd(fnum, sd, SECINFO_DACL)

            wire_mode = libsmb.unix_mode_to_wire(0o600)

            res = c.list("", info_level=libsmb.SMB2_FIND_POSIX_INFORMATION)

            found_files = {get_string(i['name']): i for i in res}
            for fname,perm in test_files.items():
                self.assertIn(get_string(fname), found_files.keys(),
                              'Test file not found')

                found_unixmode = found_files[fname]['perms']
                found_perms = found_unixmode & (stat.S_IRWXU|
                                                stat.S_IRWXG|
                                                stat.S_IRWXO|
                                                stat.S_ISUID|
                                                stat.S_ISGID|
                                                stat.S_ISVTX)

                self.assertEqual(test_files[fname], found_perms,
                                 'Requested %04o, Received %04o' % \
                                 (test_files[fname], found_perms))
---
 source3/libsmb/pylibsmb.c   | 4 ++++
 source3/smbd/smb2_nttrans.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
index be2f2cbcd7eb..9bc46ee63dba 100644
--- a/source3/libsmb/pylibsmb.c
+++ b/source3/libsmb/pylibsmb.c
@@ -3752,5 +3752,9 @@ MODULE_INIT_FUNC(libsmb_samba_cwrapper)
 
 	ADD_FLAGS(SMB2_CLOSE_FLAGS_FULL_INFORMATION);
 
+	ADD_FLAGS(SECINFO_OWNER);
+	ADD_FLAGS(SECINFO_GROUP);
+	ADD_FLAGS(SECINFO_DACL);
+
 	return m;
 }
diff --git a/source3/smbd/smb2_nttrans.c b/source3/smbd/smb2_nttrans.c
index 780fc64e5298..fef83b2bd7ed 100644
--- a/source3/smbd/smb2_nttrans.c
+++ b/source3/smbd/smb2_nttrans.c
@@ -224,7 +224,7 @@ static bool check_smb2_posix_chmod_ace(const struct files_struct *fsp,
 	}
 
 	*pmode = (mode_t)ace->trustee.sub_auths[2];
-	*pmode &= (S_IRWXU | S_IRWXG | S_IRWXO);
+	*pmode &= (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
 
 	return true;
 }
-- 
2.54.0