smbd: use vfs_stat() in more places
authorRalph Boehme <slow@samba.org>
Wed, 25 Nov 2020 11:29:40 +0000 (12:29 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:31 +0000 (09:08 +0000)
This replaces the code in a bunch of places where we choose between stat() and
lstat() based on req->posix_pathname. The new code inside vfs_stat() is based on
checking the smb_fname flag SMB_FILENAME_POSIX_PATH.

req->posix_pathname is inherited from the global POSIX pathnames state and the
smb_fname flags is also inherited from that indirectly via the UCF flags.

Tl;dr: no change in behaviour. :)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_acl_tdb.c
source3/modules/vfs_default.c
source3/modules/vfs_streams_xattr.c
source3/smbd/filename.c
source3/smbd/open.c
source3/smbd/reply.c
source3/smbd/smb2_setinfo.c
source3/smbd/trans2.c

index 57c2439a4bd603542aefecb7b974d91868719330..2fb03c03efc21e0f29e9ed9c03f799ae7ef492dc 100644 (file)
@@ -261,12 +261,7 @@ static int unlinkat_acl_tdb(vfs_handle_struct *handle,
                goto out;
        }
 
-       if (smb_fname_tmp->flags & SMB_FILENAME_POSIX_PATH) {
-               ret = SMB_VFS_LSTAT(handle->conn, smb_fname_tmp);
-       } else {
-               ret = SMB_VFS_STAT(handle->conn, smb_fname_tmp);
-       }
-
+       ret = vfs_stat(handle->conn, smb_fname_tmp);
        if (ret == -1) {
                goto out;
        }
index 074de0960c05417d7bfe5242f3a2598a987dcd27..21075d725a97242d334b9c62bd9b13159de3b910 100644 (file)
@@ -3064,11 +3064,7 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
                        return NT_STATUS_NO_MEMORY;
                }
 
-               if (smb_fname_cp->flags & SMB_FILENAME_POSIX_PATH) {
-                       ret = SMB_VFS_LSTAT(handle->conn, smb_fname_cp);
-               } else {
-                       ret = SMB_VFS_STAT(handle->conn, smb_fname_cp);
-               }
+               ret = vfs_stat(handle->conn, smb_fname_cp);
                sbuf = smb_fname_cp->st;
                TALLOC_FREE(smb_fname_cp);
        }
index 1d3f3ca14a74f2c1b7216c6ca576c6efe7e9fd0c..47580a7a53d4bf2dd721c65f5b3a2d179dfcc465 100644 (file)
@@ -226,11 +226,7 @@ static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
                return -1;
        }
 
-       if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
-               ret = SMB_VFS_LSTAT(handle->conn, smb_fname_base);
-       } else {
-               ret = SMB_VFS_STAT(handle->conn, smb_fname_base);
-       }
+       ret = vfs_stat(handle->conn, smb_fname_base);
        *sbuf = smb_fname_base->st;
 
        if (ret == -1) {
index 937fc3c0f6330464b04959268090828a2d6d8f63..748d1effc165c4eb14067fc13b9f369ac74e213d 100644 (file)
@@ -662,11 +662,7 @@ static NTSTATUS unix_convert_step_stat(struct uc_state *state)
 
        DBG_DEBUG("smb_fname [%s]\n", smb_fname_str_dbg(state->smb_fname));
 
-       if (state->posix_pathnames) {
-               ret = SMB_VFS_LSTAT(state->conn, state->smb_fname);
-       } else {
-               ret = SMB_VFS_STAT(state->conn, state->smb_fname);
-       }
+       ret = vfs_stat(state->conn, state->smb_fname);
        if (ret == 0) {
                /*
                 * It exists. it must either be a directory or this must
@@ -826,12 +822,7 @@ static NTSTATUS unix_convert_step_stat(struct uc_state *state)
                 * if it exists. JRA.
                 */
 
-               if (state->posix_pathnames) {
-                       ret = SMB_VFS_LSTAT(state->conn, state->smb_fname);
-               } else {
-                       ret = SMB_VFS_STAT(state->conn, state->smb_fname);
-               }
-
+               ret = vfs_stat(state->conn, state->smb_fname);
                if (ret != 0) {
                        SET_STAT_INVALID(state->smb_fname->st);
                }
@@ -1177,12 +1168,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                 * there was one) and be done!
                 */
 
-               if (state->posix_pathnames) {
-                       ret = SMB_VFS_LSTAT(state->conn, state->smb_fname);
-               } else {
-                       ret = SMB_VFS_STAT(state->conn, state->smb_fname);
-               }
-
+               ret = vfs_stat(state->conn, state->smb_fname);
                if (ret == 0) {
                        status = check_for_dot_component(state->smb_fname);
                        if (!NT_STATUS_IS_OK(status)) {
@@ -1267,13 +1253,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                                        status = NT_STATUS_NO_MEMORY;
                                        goto fail;
                                }
-                               if (state->posix_pathnames) {
-                                       ret = SMB_VFS_LSTAT(state->conn,
-                                                           parent_fname);
-                               } else {
-                                       ret = SMB_VFS_STAT(state->conn,
-                                                          parent_fname);
-                               }
+                               ret = vfs_stat(state->conn, parent_fname);
                                TALLOC_FREE(parent_fname);
                                if (ret == -1) {
                                        if (errno == ENOTDIR ||
index 857643ddacfaa6da478c03d878586fa153133110..e05bd9ace35bb49347f76f4f7fff4b9f433fcce2 100644 (file)
@@ -6159,12 +6159,7 @@ NTSTATUS create_file_default(connection_struct *conn,
                        status = NT_STATUS_NOT_A_DIRECTORY;
                        goto fail;
                }
-               if (req != NULL && req->posix_pathnames) {
-                       ret = SMB_VFS_LSTAT(conn, smb_fname);
-               } else {
-                       ret = SMB_VFS_STAT(conn, smb_fname);
-               }
-
+               ret = vfs_stat(conn, smb_fname);
                if (ret == 0 && VALID_STAT_OF_DIR(smb_fname->st)) {
                        status = NT_STATUS_FILE_IS_A_DIRECTORY;
                        goto fail;
index 6fcca84b496b96cd4f2e821f9b425cc25a066447..43e23635ba963060a79a12b3410021b11e927e32 100644 (file)
@@ -1826,11 +1826,7 @@ void reply_search(struct smb_request *req)
                 * so FILE_OPEN disposition knows the directory
                 * exists.
                 */
-               if (req->posix_pathnames) {
-                       ret = SMB_VFS_LSTAT(conn, smb_dname);
-               } else {
-                       ret = SMB_VFS_STAT(conn, smb_dname);
-               }
+               ret = vfs_stat(conn, smb_dname);
                if (ret == -1) {
                        nt_status = map_nt_error_from_unix(errno);
                        reply_nterror(req, nt_status);
@@ -3138,7 +3134,6 @@ static NTSTATUS do_unlink(connection_struct *conn,
        uint32_t dirtype_orig = dirtype;
        NTSTATUS status;
        int ret;
-       bool posix_paths = (req != NULL && req->posix_pathnames);
        struct smb2_create_blobs *posx = NULL;
 
        DEBUG(10,("do_unlink: %s, dirtype = %d\n",
@@ -3149,11 +3144,7 @@ static NTSTATUS do_unlink(connection_struct *conn,
                return NT_STATUS_MEDIA_WRITE_PROTECTED;
        }
 
-       if (posix_paths) {
-               ret = SMB_VFS_LSTAT(conn, smb_fname);
-       } else {
-               ret = SMB_VFS_STAT(conn, smb_fname);
-       }
+       ret = vfs_stat(conn, smb_fname);
        if (ret != 0) {
                return map_nt_error_from_unix(errno);
        }
@@ -3211,7 +3202,7 @@ static NTSTATUS do_unlink(connection_struct *conn,
                return NT_STATUS_OBJECT_NAME_INVALID;
 #endif /* JRATEST */
 
-       if (posix_paths) {
+       if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) {
                status = make_smb2_posix_create_ctx(
                        talloc_tos(), &posx, 0777);
                if (!NT_STATUS_IS_OK(status)) {
@@ -7898,7 +7889,6 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
        char *talloced = NULL;
        long offset = 0;
        int create_options = 0;
-       bool posix_pathnames = (req != NULL && req->posix_pathnames);
        struct smb2_create_blobs *posx = NULL;
        int rc;
        bool src_has_wild = false;
@@ -7921,7 +7911,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                goto out;
        }
 
-       if (req != NULL && !req->posix_pathnames) {
+       if (!(smb_fname_src->flags & SMB_FILENAME_POSIX_PATH)) {
                /*
                 * Check the wildcard mask *before*
                 * unmangling. As mangling is done
@@ -7955,7 +7945,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                }
        }
 
-       if (posix_pathnames) {
+       if (smb_fname_src->flags & SMB_FILENAME_POSIX_PATH) {
                status = make_smb2_posix_create_ctx(talloc_tos(), &posx, 0777);
                if (!NT_STATUS_IS_OK(status)) {
                        DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
@@ -8017,11 +8007,8 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                }
 
                ZERO_STRUCT(smb_fname_src->st);
-               if (posix_pathnames) {
-                       rc = SMB_VFS_LSTAT(conn, smb_fname_src);
-               } else {
-                       rc = SMB_VFS_STAT(conn, smb_fname_src);
-               }
+
+               rc = vfs_stat(conn, smb_fname_src);
                if (rc == -1) {
                        status = map_nt_error_from_unix_common(errno);
                        goto out;
@@ -8193,11 +8180,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                smb_fname_dst->base_name = destname;
 
                ZERO_STRUCT(smb_fname_src->st);
-               if (posix_pathnames) {
-                       SMB_VFS_LSTAT(conn, smb_fname_src);
-               } else {
-                       SMB_VFS_STAT(conn, smb_fname_src);
-               }
+               vfs_stat(conn, smb_fname_src);
 
                status = openat_pathref_fsp(conn->cwd_fsp, smb_fname_src);
                if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) {
index 83706b44c925b5eb79a8062dd734a7360ab285b9..646e009a746de33b5d930d9555625f4c3fd885d7 100644 (file)
@@ -379,6 +379,7 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
        connection_struct *conn = smb2req->tcon->compat;
        struct share_mode_lock *lck = NULL;
        NTSTATUS status;
+       int ret;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smbd_smb2_setinfo_state);
@@ -421,27 +422,14 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
                         * handle (returned from an NT SMB). NT5.0 seems
                         * to do this call. JRA.
                         */
-                       if (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH) {
-                               /* Always do lstat for UNIX calls. */
-                               if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) {
-                                       DEBUG(3,("smbd_smb2_setinfo_send: "
-                                                "SMB_VFS_LSTAT of %s failed "
-                                                "(%s)\n", fsp_str_dbg(fsp),
-                                                strerror(errno)));
-                                       status = map_nt_error_from_unix(errno);
-                                       tevent_req_nterror(req, status);
-                                       return tevent_req_post(req, ev);
-                               }
-                       } else {
-                               if (SMB_VFS_STAT(conn, fsp->fsp_name) != 0) {
-                                       DEBUG(3,("smbd_smb2_setinfo_send: "
-                                                "fileinfo of %s failed (%s)\n",
-                                                fsp_str_dbg(fsp),
-                                                strerror(errno)));
-                                       status = map_nt_error_from_unix(errno);
-                                       tevent_req_nterror(req, status);
-                                       return tevent_req_post(req, ev);
-                               }
+                       ret = vfs_stat(fsp->conn, fsp->fsp_name);
+                       if (ret != 0) {
+                               DBG_WARNING("vfs_stat() of %s failed (%s)\n",
+                                           fsp_str_dbg(fsp),
+                                           strerror(errno));
+                               status = map_nt_error_from_unix(errno);
+                               tevent_req_nterror(req, status);
+                               return tevent_req_post(req, ev);
                        }
                } else if (fsp->print_file) {
                        /*
@@ -586,7 +574,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
                struct file_quota_information info = {0};
                SMB_NTQUOTA_STRUCT qt = {0};
                enum ndr_err_code err;
-               int ret;
 
                if (!fsp->fake_file_handle) {
                        tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
index 6023f444660c9a9fec96100167f80510d3cac3bf..a188641e3477adf9a4e43ed3101b208d3c1c91f8 100644 (file)
@@ -2952,12 +2952,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
         * so FILE_OPEN disposition knows the directory
         * exists.
         */
-       if (req->posix_pathnames) {
-               ret = SMB_VFS_LSTAT(conn, smb_dname);
-       } else {
-               ret = SMB_VFS_STAT(conn, smb_dname);
-       }
-
+       ret = vfs_stat(conn, smb_dname);
        if (ret == -1) {
                ntstatus = map_nt_error_from_unix(errno);
                reply_nterror(req, ntstatus);