From: Volker Lendecke Date: Fri, 11 Feb 2022 08:37:35 +0000 (+0100) Subject: smbd: Introduce fsp_is_alternate_stream() X-Git-Tag: tevent-0.12.0~735 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21b380ca133417df096e2b262a5da41faff186ea;p=thirdparty%2Fsamba.git smbd: Introduce fsp_is_alternate_stream() 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c index aa78007dadd..148da7fce0b 100644 --- a/source3/lib/adouble.c +++ b/source3/lib/adouble.c @@ -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; diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index c4d0e4dd7d8..f40bec3b74c 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -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; } diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 303df41258e..15491e52af6 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -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); } diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index d61b3eac4b9..acd42d4942f 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -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; } diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 682d492fee3..0f745c63fbd 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -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); diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c index 95f18217868..0aa2b2fdfcc 100644 --- a/source3/smbd/aio.c +++ b/source3/smbd/aio.c @@ -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; diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 206515202e0..c13826567d5 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -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 diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 3fc1992ce4d..bac5f2e5cac 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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); +} diff --git a/source3/smbd/open.c b/source3/smbd/open.c index aaf5f55dccf..ddc9866605e 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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 diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index db70dfb27b9..f9aa1f2a39e 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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, diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index ee53fe3c89e..955ebdd7829 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -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; } diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c index 1547c41fc3e..4c6822f2c74 100644 --- a/source3/smbd/smb2_read.c +++ b/source3/smbd/smb2_read.c @@ -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)) diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index caf6b6add1d..e8a91238baf 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -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; } diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index cd412a3d57a..1b3ddc286c0 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -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