From 50a958ff1d7f3bba413da3ba2fdaa6fd809849e3 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 23 Apr 2025 17:15:40 +0100 Subject: [PATCH] pysmbd: fix samba.tests.samba_tool.ntacl failure due to errno overwrite 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 Reviewed-by: Stefan Metzmacher Autobuild-User(master): Stefan Metzmacher Autobuild-Date(master): Mon Apr 28 14:31:15 UTC 2025 on atb-devel-224 --- source3/smbd/pysmbd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index 79e6d558c82..b112440e2c8 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -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); } -- 2.47.3