The branch, master has been updated
       via  50a958ff1d7 pysmbd: fix samba.tests.samba_tool.ntacl failure due to 
errno overwrite
       via  783ca9dc434 s3:rpc_server: make sure we can bind to the same port 
on all ip addresses
      from  5cab6a9be79 vfs_ceph_new: Enhance logging for improved debugging 
and code flow visibility (part 2)

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 50a958ff1d7f3bba413da3ba2fdaa6fd809849e3
Author: Noel Power <[email protected]>
Date:   Wed Apr 23 17:15:40 2025 +0100

    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 <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    
    Autobuild-User(master): Stefan Metzmacher <[email protected]>
    Autobuild-Date(master): Mon Apr 28 14:31:15 UTC 2025 on atb-devel-224

commit 783ca9dc434bd1d18b762185ee936fcbcf292124
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Apr 23 10:58:55 2025 +0200

    s3:rpc_server: make sure we can bind to the same port on all ip addresses
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15851
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

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

Summary of changes:
 source3/rpc_server/rpc_sock_helper.c | 114 +++++++++++++++++++++++++----------
 source3/smbd/pysmbd.c                |   4 ++
 2 files changed, 85 insertions(+), 33 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/rpc_server/rpc_sock_helper.c 
b/source3/rpc_server/rpc_sock_helper.c
index 364b889d9b7..cc11e1221db 100644
--- a/source3/rpc_server/rpc_sock_helper.c
+++ b/source3/rpc_server/rpc_sock_helper.c
@@ -110,32 +110,16 @@ out:
  ********************************************************************/
 
 static NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(
-       const struct sockaddr_storage *ifss, uint16_t *port, int *out_fd)
+       const struct sockaddr_storage *ifss,
+       uint16_t port,
+       bool rebind,
+       int *out_fd)
 {
        int fd = -1;
 
-       if (*port == 0) {
-               static uint16_t low = 0;
-               uint16_t i;
-
-               if (low == 0) {
-                       low = lp_rpc_low_port();
-               }
-
-               for (i = low; i <= lp_rpc_high_port(); i++) {
-                       fd = open_socket_in(SOCK_STREAM, ifss, i, false);
-                       if (fd >= 0) {
-                               *port = i;
-                               low = i+1;
-                               break;
-                       }
-               }
-       } else {
-               fd = open_socket_in(SOCK_STREAM, ifss, *port, true);
-       }
-
+       fd = open_socket_in(SOCK_STREAM, ifss, port, rebind);
        if (fd < 0) {
-               DBG_ERR("Failed to create socket on port %u!\n", *port);
+               DBG_ERR("Failed to create socket on port %u!\n", port);
                return map_nt_error_from_unix(-fd);
        }
 
@@ -143,7 +127,7 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(
        set_socket_options(fd, "SO_KEEPALIVE");
        set_socket_options(fd, lp_socket_options());
 
-       DBG_DEBUG("Opened ncacn_ip_tcp socket fd %d for port %u\n", fd, *port);
+       DBG_DEBUG("Opened ncacn_ip_tcp socket fd %d for port %u\n", fd, port);
 
        *out_fd = fd;
 
@@ -156,15 +140,24 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
        size_t *pnum_fds,
        int **pfds)
 {
+       static uint16_t next_low_port;
+       static uint16_t conf_high_port;
        uint16_t port = 0;
+       uint16_t highest_port = 0;
        char port_str[11];
        const char *endpoint = NULL;
        size_t i = 0, num_fds;
        int *fds = NULL;
        struct samba_sockaddr *addrs = NULL;
        NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
+       bool rebind = false;
        bool ok;
 
+       if (next_low_port == 0) {
+               next_low_port = lp_rpc_low_port();
+               conf_high_port = lp_rpc_high_port();
+       }
+
        endpoint = dcerpc_binding_get_string_option(b, "endpoint");
        if (endpoint != NULL) {
                port = atoi(endpoint);
@@ -181,15 +174,21 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
 
        addrs = talloc_array(mem_ctx, struct samba_sockaddr, num_fds);
        if (addrs == NULL) {
+               num_fds = 0; /* nothing to close */
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
        fds = talloc_array(mem_ctx, int, num_fds);
        if (fds == NULL) {
+               num_fds = 0; /* nothing to close */
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
 
+       for (i=0; i<num_fds; i++) {
+               fds[i] = -1;
+       }
+
        /*
         * Fill "addrs"
         */
@@ -202,7 +201,6 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
                        ok = sockaddr_storage_to_samba_sockaddr(
                                &addrs[i], ifss);
                        if (!ok) {
-                               i = 0; /* nothing to close */
                                goto fail;
                        }
                }
@@ -234,13 +232,60 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
                }
        }
 
-       for (i=0; i<num_fds; i++) {
-               status = dcesrv_create_ncacn_ip_tcp_socket(
-                       &addrs[i].u.ss, &port, &fds[i]);
-               if (!NT_STATUS_IS_OK(status)) {
-                       goto fail;
+       if (port != 0) {
+               rebind = true;
+               highest_port = port;
+       } else {
+               rebind = false;
+               port = next_low_port;
+               highest_port = conf_high_port;
+       }
+
+       for (; port <= highest_port; port += 1) {
+               for (i=0; i<num_fds; i++) {
+                       status = dcesrv_create_ncacn_ip_tcp_socket(
+                                               &addrs[i].u.ss,
+                                               port,
+                                               rebind,
+                                               &fds[i]);
+                       if (NT_STATUS_EQUAL(status,
+                           NT_STATUS_ADDRESS_ALREADY_ASSOCIATED))
+                       {
+                               break;
+                       }
+                       if (!NT_STATUS_IS_OK(status)) {
+                               goto fail;
+                       }
+                       samba_sockaddr_set_port(&addrs[i], port);
                }
-               samba_sockaddr_set_port(&addrs[i], port);
+
+               if (port == next_low_port) {
+                       next_low_port += 1;
+               }
+
+               if (i == num_fds) {
+                       /*
+                        * We were able to bind to the same port on all
+                        * addresses
+                        */
+                       break;
+               }
+
+               /*
+                * The port was not available on at least one address, so close
+                * them all and try the next port or return the error.
+                */
+               for (i=0; i<num_fds; i++) {
+                       if (fds[i] == -1) {
+                               continue;
+                       }
+                       close(fds[i]);
+                       fds[i] = -1;
+               }
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
        }
 
        /* Set the port in the endpoint */
@@ -261,9 +306,12 @@ static NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
        return NT_STATUS_OK;
 
 fail:
-       while (i > 0) {
-               close(fds[i-1]);
-               i -= 1;
+       for (i=0; i<num_fds; i++) {
+               if (fds[i] == -1) {
+                       continue;
+               }
+               close(fds[i]);
+               fds[i] = -1;
        }
        TALLOC_FREE(fds);
        TALLOC_FREE(addrs);
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);
        }
 


-- 
Samba Shared Repository

Reply via email to