The branch, v4-18-test has been updated
       via  d35c773e969 pidl: avoid py compile issues with --pidl-developer
       via  29c08b5891d s3:utils: smbget fix a memory leak
       via  694829f1872 smbd: Don't mask open error if fstatat() fails
       via  5d040beed2c tests: Show smbd returns wrong error code when creating 
on r/o fs
       via  14cbe1b8671 error_inject: Enable returning EROFS for O_CREAT
       via  3350e196a7e error_inject: map EROFS
       via  ccb235c2f4e vfs_gpfs: Register smbd process with GPFS
       via  2492a18d762 gpfswrap: Add wrapper for gpfs_register_cifs_export
      from  fe17ff2cfc4 s3:winbind: Fix talloc parent in find_dc() leading to a 
segfault

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-18-test


- Log -----------------------------------------------------------------
commit d35c773e969ff56ee527fbecd385a4a56a878cf0
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 9 10:36:30 2022 +1300

    pidl: avoid py compile issues with --pidl-developer
    
    We get these warnings-as-errors:
    
    librpc/gen_ndr/py_netlogon.c:61903:53: error: stray ‘\’ in program
    61903 |    PyErr_Format(PyExc_TypeError, "Expected type %s",\  //<PIDL> 
Parse::Pidl::Samba4::Python::ConvertObjectFromPythonData  
lib/Parse/Pidl/Samba4/Python.pm:2005
    
    but the '\' is unnecessary and unconventional anyway, since we're in a
    function argument list.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15404
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abart...@samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abart...@samba.org>
    Autobuild-Date(master): Fri Feb  3 03:27:54 UTC 2023 on atb-devel-224
    
    (cherry picked from commit e26a01a48c4a6ca6f9424ced72eda68e6eb1e7e3)
    
    Autobuild-User(v4-18-test): Jule Anger <jan...@samba.org>
    Autobuild-Date(v4-18-test): Mon Jul  3 08:53:24 UTC 2023 on atb-devel-224

commit 29c08b5891d984dad1935dbf1ac72c1bb384ff88
Author: Jones Syue <joness...@qnap.com>
Date:   Tue Jun 27 17:19:59 2023 +0800

    s3:utils: smbget fix a memory leak
    
    Using smbget to download files recursively (-R).
    
    If smbget found that a file is already existed in the destination,
    smbget would said 'File exists', return early, and 'newname' allocated
    memory is never freed, this is found by valgrind.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15403
    
    Signed-off-by: Jones Syue <joness...@qnap.com>
    Reviewed-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>
    
    Autobuild-User(master): Volker Lendecke <v...@samba.org>
    Autobuild-Date(master): Wed Jun 28 07:02:34 UTC 2023 on atb-devel-224
    
    (cherry picked from commit afbed653526b572f7309e67ed742a76ef7b2b8ec)

commit 694829f18723f630a9ca46969c345915c33e9b0a
Author: Volker Lendecke <v...@samba.org>
Date:   Mon Jun 26 13:17:44 2023 +0200

    smbd: Don't mask open error if fstatat() fails
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15402
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    
    Autobuild-User(master): Volker Lendecke <v...@samba.org>
    Autobuild-Date(master): Mon Jun 26 16:53:21 UTC 2023 on atb-devel-224
    
    (cherry picked from commit de2738fb9a7dad84eb50a0cf007d89b6ef53ec9a)

commit 5d040beed2c6012d8d97b0f9e4117931dea754e3
Author: Volker Lendecke <v...@samba.org>
Date:   Mon Jun 26 14:54:00 2023 +0200

    tests: Show smbd returns wrong error code when creating on r/o fs
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15402
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    (cherry picked from commit 13d199bea0f39fafd2bf39516d83e20893003aa2)

commit 14cbe1b86716a83a2619671b65c72d522405e38e
Author: Volker Lendecke <v...@samba.org>
Date:   Mon Jun 26 13:17:19 2023 +0200

    error_inject: Enable returning EROFS for O_CREAT
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15402
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    (cherry picked from commit 37b3667f65d10a39b95dd84c002677d16f8c0776)

commit 3350e196a7e72d5535f88586b95201edb3723739
Author: Volker Lendecke <v...@samba.org>
Date:   Mon Jun 26 12:47:17 2023 +0200

    error_inject: map EROFS
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15402
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    (cherry picked from commit 840480789fcbb2e4ffe8b08818869f8490dc29d5)

commit ccb235c2f4e0a2e6007af6ca206a01a5a59ac09d
Author: Christof Schmitt <c...@samba.org>
Date:   Wed May 31 11:13:51 2023 -0700

    vfs_gpfs: Register smbd process with GPFS
    
    Issue API call to tell the file system that this is a Samba process.
    This fixed the GPFS handling of Samba since the rename of smbd processes
    in commit 5955dc1e4fd.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15381
    
    Signed-off-by: Christof Schmitt <c...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>
    (cherry picked from commit 3b72136f6782d9704a197ab7b17201df6ff4d60d)

commit 2492a18d7624054f65624203f69b86e3994c3bae
Author: Christof Schmitt <c...@samba.org>
Date:   Wed May 24 14:06:36 2023 -0700

    gpfswrap: Add wrapper for gpfs_register_cifs_export
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15381
    
    Signed-off-by: Christof Schmitt <c...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>
    (cherry picked from commit 34b9c54ff2f089dbffe65bdc69f3024b5d3efd5c)

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

Summary of changes:
 lib/util/gpfswrap.c                  | 12 ++++++++++++
 lib/util/gpfswrap.h                  |  1 +
 pidl/lib/Parse/Pidl/Samba4/Python.pm |  8 ++++----
 source3/modules/vfs_error_inject.c   | 20 ++++++++++++++++++++
 source3/modules/vfs_gpfs.c           |  6 ++++++
 source3/script/tests/test_rofs.sh    | 34 ++++++++++++++++++++++++++++++++++
 source3/selftest/tests.py            |  7 +++++++
 source3/smbd/open.c                  |  9 +++++++++
 source3/utils/smbget.c               |  1 +
 9 files changed, 94 insertions(+), 4 deletions(-)
 create mode 100755 source3/script/tests/test_rofs.sh


Changeset truncated at 500 lines:

diff --git a/lib/util/gpfswrap.c b/lib/util/gpfswrap.c
index d05358e141e..2f15bf452cf 100644
--- a/lib/util/gpfswrap.c
+++ b/lib/util/gpfswrap.c
@@ -28,6 +28,7 @@ static int (*gpfs_putacl_fn)(const char *pathname, int flags, 
void *acl);
 static int (*gpfs_get_realfilename_path_fn)(const char *pathname,
                                            char *filenamep,
                                            int *len);
+static int (*gpfs_register_cifs_export_fn)(void);
 static int (*gpfs_set_winattrs_path_fn)(const char *pathname,
                                        int flags,
                                        struct gpfs_winattr *attrs);
@@ -71,6 +72,7 @@ int gpfswrap_init(void)
        gpfs_fgetacl_fn               = dlsym(l, "gpfs_getacl_fd");
        gpfs_putacl_fn                = dlsym(l, "gpfs_putacl");
        gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
+       gpfs_register_cifs_export_fn  = dlsym(l, "gpfs_register_cifs_export");
        gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
        gpfs_set_winattrs_fn          = dlsym(l, "gpfs_set_winattrs");
        gpfs_get_winattrs_fn          = dlsym(l, "gpfs_get_winattrs");
@@ -141,6 +143,16 @@ int gpfswrap_get_realfilename_path(const char *pathname,
        return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
 }
 
+int gpfswrap_register_cifs_export(void)
+{
+       if (gpfs_register_cifs_export_fn == NULL) {
+               errno = ENOSYS;
+               return -1;
+       }
+
+       return gpfs_register_cifs_export_fn();
+}
+
 int gpfswrap_set_winattrs_path(const char *pathname,
                               int flags,
                               struct gpfs_winattr *attrs)
diff --git a/lib/util/gpfswrap.h b/lib/util/gpfswrap.h
index 1e74496c060..e387a56446b 100644
--- a/lib/util/gpfswrap.h
+++ b/lib/util/gpfswrap.h
@@ -34,6 +34,7 @@ int gpfswrap_putacl(const char *pathname, int flags, void 
*acl);
 int gpfswrap_get_realfilename_path(const char *pathname,
                                   char *filenamep,
                                   int *len);
+int gpfswrap_register_cifs_export(void);
 int gpfswrap_set_winattrs_path(const char *pathname,
                               int flags,
                               struct gpfs_winattr *attrs);
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm 
b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 5c4d3e8e087..03a901cc24d 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -1747,7 +1747,7 @@ sub ConvertObjectFromPythonData($$$$$$;$$)
                $self->pidl("}");
                $self->pidl("if (test_var > uint_max) {");
                $self->indent;
-               $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type 
%s within range 0 - %llu, got %llu\",\\");
+               $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type 
%s within range 0 - %llu, got %llu\",");
                $self->pidl("  PyLong_Type.tp_name, uint_max, test_var);");
                $self->pidl($fail);
                $self->deindent;
@@ -1756,7 +1756,7 @@ sub ConvertObjectFromPythonData($$$$$$;$$)
                $self->deindent;
                $self->pidl("} else {");
                $self->indent;
-               $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type 
%s\",\\");
+               $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type 
%s\",");
                $self->pidl("  PyLong_Type.tp_name);");
                $self->pidl($fail);
                $self->deindent;
@@ -1786,7 +1786,7 @@ sub ConvertObjectFromPythonData($$$$$$;$$)
                $self->pidl("}");
                $self->pidl("if (test_var < int_min || test_var > int_max) {");
                $self->indent;
-               $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type 
%s within range %lld - %lld, got %lld\",\\");
+               $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type 
%s within range %lld - %lld, got %lld\",");
                $self->pidl("  PyLong_Type.tp_name, int_min, int_max, 
test_var);");
                $self->pidl($fail);
                $self->deindent;
@@ -1795,7 +1795,7 @@ sub ConvertObjectFromPythonData($$$$$$;$$)
                $self->deindent;
                $self->pidl("} else {");
                $self->indent;
-               $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type 
%s\",\\");
+               $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type 
%s\",");
                $self->pidl("  PyLong_Type.tp_name);");
                $self->pidl($fail);
                $self->deindent;
diff --git a/source3/modules/vfs_error_inject.c 
b/source3/modules/vfs_error_inject.c
index 1a327097b30..edb7c64a92a 100644
--- a/source3/modules/vfs_error_inject.c
+++ b/source3/modules/vfs_error_inject.c
@@ -31,6 +31,7 @@ struct unix_error_map {
        {       "EBADF",        EBADF   },
        {       "EINTR",        EINTR   },
        {       "EACCES",       EACCES  },
+       {       "EROFS",        EROFS   },
 };
 
 static int find_unix_error_from_string(const char *err_str)
@@ -115,6 +116,7 @@ static int vfs_error_inject_openat(struct vfs_handle_struct 
*handle,
                                   const struct vfs_open_how *how)
 {
        int error = inject_unix_error("openat", handle);
+       int create_error = inject_unix_error("openat_create", handle);
        int dirfsp_flags = (O_NOFOLLOW|O_DIRECTORY);
        bool return_error;
 
@@ -126,6 +128,24 @@ static int vfs_error_inject_openat(struct 
vfs_handle_struct *handle,
 #endif
 #endif
 
+       if ((create_error != 0) && (how->flags & O_CREAT)) {
+               struct stat_ex st = {
+                       .st_ex_nlink = 0,
+               };
+               int ret;
+
+               ret = SMB_VFS_FSTATAT(handle->conn,
+                                     dirfsp,
+                                     smb_fname,
+                                     &st,
+                                     AT_SYMLINK_NOFOLLOW);
+
+               if ((ret == -1) && (errno == ENOENT)) {
+                       errno = create_error;
+                       return -1;
+               }
+       }
+
        return_error = (error != 0);
        return_error &= !fsp->fsp_flags.is_pathref;
        return_error &= ((how->flags & dirfsp_flags) != dirfsp_flags);
diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 969e7744fce..93748eab54c 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -2043,6 +2043,12 @@ static int vfs_gpfs_connect(struct vfs_handle_struct 
*handle,
 
        gpfswrap_lib_init(0);
 
+       ret = gpfswrap_register_cifs_export();
+       if (ret < 0) {
+               DBG_ERR("Failed to register with GPFS: %s\n", strerror(errno));
+               return ret;
+       }
+
        config = talloc_zero(handle->conn, struct gpfs_config_data);
        if (!config) {
                DEBUG(0, ("talloc_zero() failed\n"));
diff --git a/source3/script/tests/test_rofs.sh 
b/source3/script/tests/test_rofs.sh
new file mode 100755
index 00000000000..72901e5845a
--- /dev/null
+++ b/source3/script/tests/test_rofs.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# Test smbd handling EROFS when creating a file
+# Copyright (C) 2023 Volker Lendecke
+
+if [ $# -ne 4 ]; then
+       echo Usage: $0 SERVERCONFFILE SMBCLIENT SERVER SHARE
+       exit 1
+fi
+
+CONF=$1
+shift 1
+SMBCLIENT=$1
+shift 1
+SERVER=$1
+shift 1
+SHARE=$1
+shift 1
+
+incdir=$(dirname $0)/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+error_inject_conf=$(dirname ${SERVERCONFFILE})/error_inject.conf
+echo "error_inject:openat_create = EROFS" >${error_inject_conf}
+
+failed=0
+
+out=$(${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
+                  -c "put VERSION")
+testit_grep "Expect MEDIA_WRITE_PROTECTED" NT_STATUS_MEDIA_WRITE_PROTECTED \
+    echo "$out" || failed=$(expr $failed + 1)
+
+>${error_inject_conf}
+
+testok $0 $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 6e4ed6713f6..90806f9ca92 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -1420,6 +1420,13 @@ plantestsuite("samba3.blackbox.chdir-cache", 
"simpleserver:local",
                '$PREFIX',
                'simpleserver'])
 
+plantestsuite("samba3.blackbox.rofs_error", "simpleserver",
+              [os.path.join(samba3srcdir, "script/tests/test_rofs.sh"),
+               configuration,
+               os.path.join(bindir(), "smbclient"),
+               '$SERVER_IP',
+               "error_inject"])
+
 plantestsuite("samba3.blackbox.zero_readsize",
               "simpleserver:local",
               [os.path.join(samba3srcdir,
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index da0498f9e7d..94f50becb24 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -780,6 +780,15 @@ again:
                        smb_fname_rel,
                        &fsp->fsp_name->st,
                        AT_SYMLINK_NOFOLLOW);
+
+               if (ret == -1) {
+                       /*
+                        * Keep the original error. Otherwise we would
+                        * mask for example EROFS for open(O_CREAT),
+                        * turning it into ENOENT.
+                        */
+                       goto out;
+               }
        } else {
                ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
        }
diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
index 5f3ac16b204..227f5c638e1 100644
--- a/source3/utils/smbget.c
+++ b/source3/utils/smbget.c
@@ -265,6 +265,7 @@ static bool smb_download_dir(const char *base, const char 
*name, int resume)
                if (!ok) {
                        fprintf(stderr, "Failed to download %s: %s\n",
                                newname, strerror(errno));
+                       free(newname);
                        free(tmpname);
                        return false;
                }


-- 
Samba Shared Repository

Reply via email to