]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Introduce fsp_is_alternate_stream()
authorVolker Lendecke <vl@samba.org>
Fri, 11 Feb 2022 08:37:35 +0000 (09:37 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 11 Feb 2022 20:54:37 +0000 (20:54 +0000)
To me this is more descriptive than "fsp->base_fsp != NULL". If this
turns out to be a performance problem, I would go and make this a
static inline in smbd/proto.h.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
14 files changed:
source3/lib/adouble.c
source3/modules/vfs_catia.c
source3/modules/vfs_fruit.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_streams_xattr.c
source3/smbd/aio.c
source3/smbd/close.c
source3/smbd/files.c
source3/smbd/open.c
source3/smbd/proto.h
source3/smbd/reply.c
source3/smbd/smb2_read.c
source3/smbd/smb2_server.c
source3/smbd/vfs.c

index aa78007dadd31a4293c7aeaf3166ecfb9f41bc76..148da7fce0b48abf8cf895a8503e59ba6d1b8edc 100644 (file)
@@ -2290,7 +2290,7 @@ NTSTATUS adouble_open_from_base_fsp(const struct files_struct *dirfsp,
        *_ad_fsp = NULL;
 
        SMB_ASSERT(base_fsp != NULL);
-       SMB_ASSERT(base_fsp->base_fsp == NULL);
+       SMB_ASSERT(!fsp_is_alternate_stream(base_fsp));
 
        switch (type) {
        case ADOUBLE_META:
@@ -2590,7 +2590,7 @@ static struct adouble *ad_get_internal(TALLOC_CTX *ctx,
        int mode;
 
        if (fsp != NULL) {
-               if (fsp->base_fsp != NULL) {
+               if (fsp_is_alternate_stream(fsp)) {
                        smb_fname = fsp->base_fsp->fsp_name;
                } else {
                        smb_fname = fsp->fsp_name;
index c4d0e4dd7d8d3ce13450534850b40592594d0c79..f40bec3b74c98f347af364606f121d4ee8c74453 100644 (file)
@@ -286,7 +286,7 @@ static struct catia_cache *catia_validate_and_apply_cc(
 
                if ((cc->fname != fsp->fsp_name->base_name)
                    ||
-                   ((fsp->base_fsp != NULL) &&
+                   (fsp_is_alternate_stream(fsp) &&
                     (cc->base_fname != fsp->base_fsp->fsp_name->base_name)))
                {
                        CATIA_DEBUG_CC(10, cc, fsp);
@@ -312,7 +312,7 @@ static struct catia_cache *catia_validate_and_apply_cc(
 
        if ((cc->orig_fname != fsp->fsp_name->base_name)
            ||
-           ((fsp->base_fsp != NULL) &&
+           (fsp_is_alternate_stream(fsp) &&
             (cc->orig_base_fname != fsp->base_fsp->fsp_name->base_name)))
        {
                /*
@@ -331,7 +331,7 @@ static struct catia_cache *catia_validate_and_apply_cc(
         * names from the cache and mark the cc as busy.
         */
        fsp->fsp_name->base_name = cc->fname;
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                fsp->base_fsp->fsp_name->base_name = cc->base_fname;
        }
 
@@ -407,7 +407,7 @@ static int catia_fetch_fsp_pre_next(TALLOC_CTX *mem_ctx,
        }
        talloc_steal(mem_ctx, cc->fname);
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                status = catia_string_replace_allocate(
                        handle->conn,
                        fsp->base_fsp->fsp_name->base_name,
@@ -424,7 +424,7 @@ static int catia_fetch_fsp_pre_next(TALLOC_CTX *mem_ctx,
        cc->orig_fname = fsp->fsp_name->base_name;
        fsp->fsp_name->base_name = cc->fname;
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                cc->orig_base_fname = fsp->base_fsp->fsp_name->base_name;
                fsp->base_fsp->fsp_name->base_name = cc->base_fname;
        }
@@ -472,7 +472,7 @@ static void catia_fetch_fsp_post_next(struct catia_cache **_cc,
        *_cc = NULL;
 
        fsp->fsp_name->base_name = cc->orig_fname;
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                fsp->base_fsp->fsp_name->base_name = cc->orig_base_fname;
        }
 
index 303df41258e9b811e80c3352cbbd3a2a78e2027e..15491e52af6dce853a4ce7218c223339465aa067 100644 (file)
@@ -1473,7 +1473,7 @@ static int fruit_open_meta_netatalk(vfs_handle_struct *handle,
         * We know this is a stream open, so fsp->base_fsp must
         * already be open.
         */
-       SMB_ASSERT(fsp->base_fsp != NULL);
+       SMB_ASSERT(fsp_is_alternate_stream(fsp));
        SMB_ASSERT(fsp->base_fsp->fsp_name->fsp == fsp->base_fsp);
 
        ad = ad_get(talloc_tos(), handle, fsp->base_fsp->fsp_name, ADOUBLE_META);
@@ -1963,7 +1963,7 @@ static int fruit_unlink_meta_netatalk(vfs_handle_struct *handle,
                                      const struct smb_filename *smb_fname)
 {
        SMB_ASSERT(smb_fname->fsp != NULL);
-       SMB_ASSERT(smb_fname->fsp->base_fsp != NULL);
+       SMB_ASSERT(fsp_is_alternate_stream(smb_fname->fsp));
        return SMB_VFS_FREMOVEXATTR(smb_fname->fsp->base_fsp,
                                   AFPINFO_EA_NETATALK);
 }
index d61b3eac4b9d518a082521e4f8de427049f54fd5..acd42d4942fbbd892b946c1879c4abf3e1be4c43 100644 (file)
@@ -1382,7 +1382,7 @@ static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
        orig_smb_fname = fsp->fsp_name;
        fsp->fsp_name = &vss_smb_fname;
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                vss_base_smb_fname = *fsp->base_fsp->fsp_name;
                vss_base_smb_fname.base_name = vss_smb_fname.base_name;
                orig_base_smb_fname = fsp->base_fsp->fsp_name;
@@ -1407,7 +1407,7 @@ static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
 
 out:
        fsp->fsp_name = orig_smb_fname;
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                fsp->base_fsp->fsp_name = orig_base_smb_fname;
        }
 
index 682d492fee3dc7bd853a182efaab3a2c20441fa0..0f745c63fbd50692a93d881ecaf405789ef053f4 100644 (file)
@@ -182,7 +182,7 @@ static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
        struct stream_io *io = (struct stream_io *)
                VFS_FETCH_FSP_EXTENSION(handle, fsp);
 
-       if (io == NULL || fsp->base_fsp == NULL) {
+       if (io == NULL || !fsp_is_alternate_stream(fsp)) {
                return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
        }
 
@@ -498,7 +498,7 @@ static int streams_xattr_unlink_internal(vfs_handle_struct *handle,
        }
 
        SMB_ASSERT(smb_fname->fsp != NULL);
-       SMB_ASSERT(smb_fname->fsp->base_fsp != NULL);
+       SMB_ASSERT(fsp_is_alternate_stream(smb_fname->fsp));
 
        ret = SMB_VFS_FREMOVEXATTR(smb_fname->fsp->base_fsp, xattr_name);
 
index 95f1821786820e0e94f59c770d8cbdb51f143ec6..0aa2b2fdfccd4cba1ce4b85397427d9a114a8c60 100644 (file)
@@ -171,8 +171,7 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       if (fsp->base_fsp != NULL) {
-               /* No AIO on streams yet */
+       if (fsp_is_alternate_stream(fsp)) {
                DEBUG(10, ("AIO on streams not yet supported\n"));
                return NT_STATUS_RETRY;
        }
@@ -443,8 +442,7 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
        size_t min_aio_write_size = lp_aio_write_size(SNUM(conn));
        struct tevent_req *req;
 
-       if (fsp->base_fsp != NULL) {
-               /* No AIO on streams yet */
+       if (fsp_is_alternate_stream(fsp)) {
                DEBUG(10, ("AIO on streams not yet supported\n"));
                return NT_STATUS_RETRY;
        }
@@ -693,8 +691,7 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       if (fsp->base_fsp != NULL) {
-               /* No AIO on streams yet */
+       if (fsp_is_alternate_stream(fsp)) {
                DEBUG(10, ("AIO on streams not yet supported\n"));
                return NT_STATUS_RETRY;
        }
@@ -833,7 +830,7 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
        size_t min_aio_write_size = lp_aio_write_size(SNUM(conn));
        struct tevent_req *req;
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                /* No AIO on streams yet */
                DEBUG(10, ("AIO on streams not yet supported\n"));
                return NT_STATUS_RETRY;
index 206515202e06f7159d37616e4b1490283fb48238..c13826567d5ff8ff16f2b300e1638f5150406282 100644 (file)
@@ -1520,12 +1520,12 @@ NTSTATUS close_file_smb(struct smb_request *req,
                status = close_normal_file(req, fsp, close_type);
        }
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                /*
                 * fsp was a stream, its base_fsp can't be a stream
                 * as well
                 */
-               SMB_ASSERT(fsp->base_fsp->base_fsp == NULL);
+               SMB_ASSERT(!fsp_is_alternate_stream(fsp->base_fsp));
 
                /*
                 * There's a 1:1 relationship between fsp and a base_fsp
index 3fc1992ce4d503b9722dedcfe8d872d3611d288e..bac5f2e5cacd5495589a2da73b48609c09421aa9 100644 (file)
@@ -368,7 +368,7 @@ static int smb_fname_fsp_destructor(struct smb_filename *smb_fname)
                return 0;
        }
 
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                struct files_struct *tmp_base_fsp = fsp->base_fsp;
 
                fsp_set_base_fsp(fsp, NULL);
@@ -583,7 +583,7 @@ fail:
        if (fsp == NULL) {
                return status;
        }
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                struct files_struct *tmp_base_fsp = fsp->base_fsp;
 
                fsp_set_base_fsp(fsp, NULL);
@@ -761,7 +761,7 @@ NTSTATUS parent_pathref(TALLOC_CTX *mem_ctx,
 
 static bool close_file_in_loop(struct files_struct *fsp)
 {
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                /*
                 * This is a stream, it can't be a base
                 */
@@ -1601,3 +1601,8 @@ void fsp_set_base_fsp(struct files_struct *fsp, struct files_struct *base_fsp)
                fsp->base_fsp->stream_fsp = fsp;
        }
 }
+
+bool fsp_is_alternate_stream(const struct files_struct *fsp)
+{
+       return (fsp->base_fsp != NULL);
+}
index aaf5f55dccf0edd3f396a309d9c94b48f3563fa6..ddc9866605ee5f410b7ed39674d042b8c7648526 100644 (file)
@@ -5802,7 +5802,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                        goto fail;
                }
 
-               if (fsp->base_fsp != NULL) {
+               if (fsp_is_alternate_stream(fsp)) {
                        struct files_struct *tmp_base_fsp = fsp->base_fsp;
 
                        fsp_set_base_fsp(fsp, NULL);
@@ -5988,8 +5988,9 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                fsp->initial_allocation_size = 0;
        }
 
-       if ((info == FILE_WAS_CREATED) && lp_nt_acl_support(SNUM(conn)) &&
-                               fsp->base_fsp == NULL) {
+       if ((info == FILE_WAS_CREATED) &&
+           lp_nt_acl_support(SNUM(conn)) &&
+           !fsp_is_alternate_stream(fsp)) {
                if (sd != NULL) {
                        /*
                         * According to the MS documentation, the only time the security
index db70dfb27b9c5cb67112cbea4f9f2a80672cf436..f9aa1f2a39e20345f8b10e6d4a29a4498e661858 100644 (file)
@@ -436,6 +436,7 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                           const struct smb_filename *smb_fname_in);
 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen);
 void fsp_set_base_fsp(struct files_struct *fsp, struct files_struct *base_fsp);
+bool fsp_is_alternate_stream(const struct files_struct *fsp);
 
 NTSTATUS create_internal_fsp(connection_struct *conn,
                             const struct smb_filename *smb_fname,
index ee53fe3c89ea5e02f6cf331f17e0ff8a05ec4b0b..955ebdd7829b11639e4d9b0fa06f4ab5118ff7d3 100644 (file)
@@ -3480,8 +3480,10 @@ static void send_file_readbraw(connection_struct *conn,
         * reply_readbraw has already checked the length.
         */
 
-       if ( !req_is_in_chain(req) && (nread > 0) && (fsp->base_fsp == NULL) &&
-           lp_use_sendfile(SNUM(conn), xconn->smb1.signing_state) ) {
+       if ( !req_is_in_chain(req) &&
+            (nread > 0) &&
+            !fsp_is_alternate_stream(fsp) &&
+            lp_use_sendfile(SNUM(conn), xconn->smb1.signing_state) ) {
                ssize_t sendfile_read = -1;
                char header[4];
                DATA_BLOB header_blob;
@@ -4065,7 +4067,7 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
 
        if (!req_is_in_chain(req) &&
            !req->encrypted &&
-           (fsp->base_fsp == NULL) &&
+           !fsp_is_alternate_stream(fsp) &&
            lp_use_sendfile(SNUM(conn), xconn->smb1.signing_state) ) {
                uint8_t headerbuf[smb_size + 12 * 2 + 1 /* padding byte */];
                DATA_BLOB header;
@@ -5062,7 +5064,7 @@ bool is_valid_writeX_buffer(struct smbXsrv_connection *xconn,
                DEBUG(10,("is_valid_writeX_buffer: printing tid\n"));
                return false;
        }
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                DEBUG(10,("is_valid_writeX_buffer: stream fsp\n"));
                return false;
        }
index 1547c41fc3ec0377985e33cef6dd2f68b36e92f5..4c6822f2c74ef741314d8b0ce30bd7ccd78bf47d 100644 (file)
@@ -365,7 +365,7 @@ static NTSTATUS schedule_smb2_sendfile_read(struct smbd_smb2_request *smb2req,
            smb2req->do_signing ||
            smb2req->do_encryption ||
            smbd_smb2_is_compound(smb2req) ||
-           (fsp->base_fsp != NULL) ||
+           fsp_is_alternate_stream(fsp) ||
            (!S_ISREG(fsp->fsp_name->st.st_ex_mode)) ||
            (state->in_offset >= fsp->fsp_name->st.st_ex_size) ||
            (fsp->fsp_name->st.st_ex_size < state->in_offset + state->in_length))
index caf6b6add1df5da9bc59cdfedfb3ead4b7e6a53b..e8a91238baf46c5ddba4e758c038ff07d4f7c7b8 100644 (file)
@@ -4461,7 +4461,7 @@ static bool is_smb2_recvfile_write(struct smbd_smb2_request_read_state *state)
        if (IS_PRINT(fsp->conn)) {
                return false;
        }
-       if (fsp->base_fsp != NULL) {
+       if (fsp_is_alternate_stream(fsp)) {
                return false;
        }
 
index cd412a3d57a4b7698cb59e4491fbca4baddf7245..1b3ddc286c089fad3d855345ef392e7877902e41 100644 (file)
@@ -755,7 +755,7 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
        num_to_write = len - fsp->fsp_name->st.st_ex_size;
 
        /* Only do this on non-stream file handles. */
-       if (fsp->base_fsp == NULL) {
+       if (!fsp_is_alternate_stream(fsp)) {
                /* for allocation try fallocate first. This can fail on some
                 * platforms e.g. when the filesystem doesn't support it and no
                 * emulation is being done by the libc (like on AIX with JFS1). In that