From: Volker Lendecke Date: Tue, 10 Oct 2023 13:36:56 +0000 (+0200) Subject: smbd: Move filename_convert_smb1_search_path() to smb1-only code X-Git-Tag: talloc-2.4.2~945 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92606a46b330c2a0f182a8f68c7c99d13acd7d81;p=thirdparty%2Fsamba.git smbd: Move filename_convert_smb1_search_path() to smb1-only code Just general cleanup. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 29e3d9d19cf..7032d218e52 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -483,93 +483,6 @@ char *get_original_lcomp(TALLOC_CTX *ctx, return orig_lcomp; } -/* - * Deal with the SMB1 semantics of sending a pathname with a - * wildcard as the terminal component for a SMB1search or - * trans2 findfirst. - */ - -NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx, - connection_struct *conn, - char *name_in, - uint32_t ucf_flags, - struct files_struct **_dirfsp, - struct smb_filename **_smb_fname_out, - char **_mask_out) -{ - NTSTATUS status; - char *p = NULL; - char *mask = NULL; - struct smb_filename *smb_fname = NULL; - NTTIME twrp = 0; - - *_smb_fname_out = NULL; - *_dirfsp = NULL; - *_mask_out = NULL; - - DBG_DEBUG("name_in: %s\n", name_in); - - if (ucf_flags & UCF_GMT_PATHNAME) { - extract_snapshot_token(name_in, &twrp); - ucf_flags &= ~UCF_GMT_PATHNAME; - } - - /* Get the original lcomp. */ - mask = get_original_lcomp(ctx, - conn, - name_in, - ucf_flags); - if (mask == NULL) { - return NT_STATUS_NO_MEMORY; - } - - if (mask[0] == '\0') { - /* Windows and OS/2 systems treat search on the root as * */ - TALLOC_FREE(mask); - mask = talloc_strdup(ctx, "*"); - if (mask == NULL) { - return NT_STATUS_NO_MEMORY; - } - } - - DBG_DEBUG("mask = %s\n", mask); - - /* - * Remove the terminal component so - * filename_convert_dirfsp never sees the mask. - */ - p = strrchr_m(name_in,'/'); - if (p == NULL) { - /* filename_convert_dirfsp handles a '\0' name. */ - name_in[0] = '\0'; - } else { - *p = '\0'; - } - - DBG_DEBUG("For filename_convert_dirfsp: name_in = %s\n", - name_in); - - /* Convert the parent directory path. */ - status = filename_convert_dirfsp(ctx, - conn, - name_in, - ucf_flags, - twrp, - _dirfsp, - &smb_fname); - - if (!NT_STATUS_IS_OK(status)) { - DBG_DEBUG("filename_convert error for %s: %s\n", - name_in, - nt_errstr(status)); - } - - *_smb_fname_out = talloc_move(ctx, &smb_fname); - *_mask_out = talloc_move(ctx, &mask); - - return status; -} - /* * Get the correct capitalized stream name hanging off * base_fsp. Equivalent of get_real_filename(), but for streams. diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 0200c39778d..ad8f52efbff 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -343,13 +343,6 @@ char *get_original_lcomp(TALLOC_CTX *ctx, connection_struct *conn, const char *filename_in, uint32_t ucf_flags); -NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx, - connection_struct *conn, - char *name_in, - uint32_t ucf_flags, - struct files_struct **_dirfsp, - struct smb_filename **_smb_fname_out, - char **_mask_out); NTSTATUS get_real_filename_at(struct files_struct *dirfsp, const char *name, TALLOC_CTX *mem_ctx, diff --git a/source3/smbd/smb1_utils.c b/source3/smbd/smb1_utils.c index 5092aa51929..bdd842c504f 100644 --- a/source3/smbd/smb1_utils.c +++ b/source3/smbd/smb1_utils.c @@ -176,3 +176,86 @@ ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags) return result; } + +/* + * Deal with the SMB1 semantics of sending a pathname with a + * wildcard as the terminal component for a SMB1search or + * trans2 findfirst. + */ + +NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx, + connection_struct *conn, + char *name_in, + uint32_t ucf_flags, + struct files_struct **_dirfsp, + struct smb_filename **_smb_fname_out, + char **_mask_out) +{ + NTSTATUS status; + char *p = NULL; + char *mask = NULL; + struct smb_filename *smb_fname = NULL; + NTTIME twrp = 0; + + *_smb_fname_out = NULL; + *_dirfsp = NULL; + *_mask_out = NULL; + + DBG_DEBUG("name_in: %s\n", name_in); + + if (ucf_flags & UCF_GMT_PATHNAME) { + extract_snapshot_token(name_in, &twrp); + ucf_flags &= ~UCF_GMT_PATHNAME; + } + + /* Get the original lcomp. */ + mask = get_original_lcomp(ctx, conn, name_in, ucf_flags); + if (mask == NULL) { + return NT_STATUS_NO_MEMORY; + } + + if (mask[0] == '\0') { + /* Windows and OS/2 systems treat search on the root as * */ + TALLOC_FREE(mask); + mask = talloc_strdup(ctx, "*"); + if (mask == NULL) { + return NT_STATUS_NO_MEMORY; + } + } + + DBG_DEBUG("mask = %s\n", mask); + + /* + * Remove the terminal component so + * filename_convert_dirfsp never sees the mask. + */ + p = strrchr_m(name_in, '/'); + if (p == NULL) { + /* filename_convert_dirfsp handles a '\0' name. */ + name_in[0] = '\0'; + } else { + *p = '\0'; + } + + DBG_DEBUG("For filename_convert_dirfsp: name_in = %s\n", name_in); + + /* Convert the parent directory path. */ + status = filename_convert_dirfsp(ctx, + conn, + name_in, + ucf_flags, + twrp, + _dirfsp, + &smb_fname); + + if (!NT_STATUS_IS_OK(status)) { + DBG_DEBUG("filename_convert error for %s: %s\n", + name_in, + nt_errstr(status)); + } + + *_smb_fname_out = talloc_move(ctx, &smb_fname); + *_mask_out = talloc_move(ctx, &mask); + + return status; +} diff --git a/source3/smbd/smb1_utils.h b/source3/smbd/smb1_utils.h index 6f791e2ff80..539648e28ca 100644 --- a/source3/smbd/smb1_utils.h +++ b/source3/smbd/smb1_utils.h @@ -35,5 +35,12 @@ struct files_struct *fcb_or_dos_open( uint32_t private_flags); bool send_keepalive(int client); ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags); +NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx, + connection_struct *conn, + char *name_in, + uint32_t ucf_flags, + struct files_struct **_dirfsp, + struct smb_filename **_smb_fname_out, + char **_mask_out); #endif