]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pysmbd: fix samba.tests.samba_tool.ntacl failure due to errno overwrite
authorNoel Power <noel.power@suse.com>
Wed, 23 Apr 2025 16:15:40 +0000 (17:15 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 28 Apr 2025 14:31:15 +0000 (14:31 +0000)
some functions in source3/smbd/pysmbd.c when deleting stack frame
can modify errno. (and in one case causes failure with
test samba.tests.samba_tool.ntacl)

this is related to newer versions of lmdb (at least version 0.9.30)

[1(0)/1 at 20s] samba.tests.samba_tool.ntacl(ad_dc:local)
2025-04-23T16:18:23.341528+00:00 addc.addom.samba.example.com [13640]: set_nt_acl_conn: init_files_struct failed: NT_STATUS_OBJECT_NAME_NOT_FOUND
UNEXPECTED(failure): samba.tests.samba_tool.ntacl.samba.tests.samba_tool.ntacl.NtACLCmdGetSetTestCase.test_set_expect_file_not_found(ad_dc:local)
REASON: Exception: Exception: Traceback (most recent call last):
  File "/home/npower/samba-temp/bin/python/samba/tests/samba_tool/ntacl.py", line 142, in test_set_expect_file_not_found
    "No such file or directory expected")
AssertionError: 'No such file or directory' not found in "ERROR: Could not set acl for setExpectFileNotFound-a94c241d9550d581e51d: [Errno 11] Resource temporarily unavailable: 'setExpectFileNotFound-a94c241d9550d581e51d'\n" : No such file or directory expected
teardown_env(ad_dc)

This patch saves/sets errno explicitly before calling PyErr_SetFromErrno to
ensure the correct errno is used.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Mon Apr 28 14:31:15 UTC 2025 on atb-devel-224

source3/smbd/pysmbd.c

index 79e6d558c82af465702ec676707de8c1dfdb930e..b112440e2c82ebd2819a7e633cb1ba2261dedaa7 100644 (file)
@@ -851,6 +851,7 @@ static PyObject *py_smbd_set_nt_acl(PyObject *self, PyObject *args, PyObject *kw
                        /*
                         * This will show up as a FileNotFoundError in python.
                         */
+                       errno = ENOENT;
                        PyErr_SetFromErrnoWithFilename(PyExc_OSError, fname);
                } else {
                        PyErr_SetNTSTATUS(status);
@@ -929,6 +930,7 @@ static PyObject *py_smbd_get_nt_acl(PyObject *self, PyObject *args, PyObject *kw
                         * from which samba-tool can at least produce a short
                         * message containing the problematic filename.
                         */
+                       errno = ENOENT;
                        PyErr_SetFromErrnoWithFilename(PyExc_OSError, fname);
                } else {
                        PyErr_SetNTSTATUS(status);
@@ -1092,7 +1094,9 @@ static PyObject *py_smbd_get_sys_acl(PyObject *self, PyObject *args, PyObject *k
 
        acl = SMB_VFS_SYS_ACL_GET_FD(smb_fname->fsp, acl_type, frame);
        if (!acl) {
+               int err = errno;
                TALLOC_FREE(frame);
+               errno = err;
                return PyErr_SetFromErrno(PyExc_OSError);
        }