From d314fc5874e243f9fd659aa9fdf3c5ed6c0c6a22 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 4 Nov 2023 16:17:36 +0100 Subject: [PATCH] smbd: Make get_real_filename_cache_key() static in files.c Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Tue Nov 7 13:58:07 UTC 2023 on atb-devel-224 --- source3/smbd/filename.c | 46 -------------------------------------- source3/smbd/files.c | 49 +++++++++++++++++++++++++++++++++++++++++ source3/smbd/proto.h | 4 ---- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 91d16e07495..5219fcd721e 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -404,52 +404,6 @@ NTSTATUS get_real_filename_at(struct files_struct *dirfsp, return status; } -/* - * Create the memcache-key for GETREALFILENAME_CACHE: This supplements - * the stat cache for the last component to be looked up. Cache - * contents is the correctly capitalized translation of the parameter - * "name" as it exists on disk. This is indexed by inode of the dirfsp - * and name, and contrary to stat_cahce_lookup() it does not - * vfs_stat() the last component. This will be taken care of by an - * attempt to do a openat_pathref_fsp(). - */ -bool get_real_filename_cache_key(TALLOC_CTX *mem_ctx, - struct files_struct *dirfsp, - const char *name, - DATA_BLOB *_key) -{ - struct file_id fid = vfs_file_id_from_sbuf( - dirfsp->conn, &dirfsp->fsp_name->st); - char *upper = NULL; - uint8_t *key = NULL; - size_t namelen, keylen; - - upper = talloc_strdup_upper(mem_ctx, name); - if (upper == NULL) { - return false; - } - namelen = talloc_get_size(upper); - - keylen = namelen + sizeof(fid); - if (keylen < sizeof(fid)) { - TALLOC_FREE(upper); - return false; - } - - key = talloc_size(mem_ctx, keylen); - if (key == NULL) { - TALLOC_FREE(upper); - return false; - } - - memcpy(key, &fid, sizeof(fid)); - memcpy(key + sizeof(fid), upper, namelen); - TALLOC_FREE(upper); - - *_key = (DATA_BLOB) { .data = key, .length = keylen, }; - return true; -} - /* * Lightweight function to just get last component * for rename / enumerate directory calls. diff --git a/source3/smbd/files.c b/source3/smbd/files.c index b94468ad6af..28a741c8b54 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -832,6 +832,55 @@ NTSTATUS create_open_symlink_err(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +/* + * Create the memcache-key for GETREALFILENAME_CACHE: This supplements + * the stat cache for the last component to be looked up. Cache + * contents is the correctly capitalized translation of the parameter + * "name" as it exists on disk. This is indexed by inode of the dirfsp + * and name, and contrary to stat_cahce_lookup() it does not + * vfs_stat() the last component. This will be taken care of by an + * attempt to do a openat_pathref_fsp(). + */ +static bool get_real_filename_cache_key(TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const char *name, + DATA_BLOB *_key) +{ + struct file_id fid = vfs_file_id_from_sbuf(dirfsp->conn, + &dirfsp->fsp_name->st); + char *upper = NULL; + uint8_t *key = NULL; + size_t namelen, keylen; + + upper = talloc_strdup_upper(mem_ctx, name); + if (upper == NULL) { + return false; + } + namelen = talloc_get_size(upper); + + keylen = namelen + sizeof(fid); + if (keylen < sizeof(fid)) { + TALLOC_FREE(upper); + return false; + } + + key = talloc_size(mem_ctx, keylen); + if (key == NULL) { + TALLOC_FREE(upper); + return false; + } + + memcpy(key, &fid, sizeof(fid)); + memcpy(key + sizeof(fid), upper, namelen); + TALLOC_FREE(upper); + + *_key = (DATA_BLOB){ + .data = key, + .length = keylen, + }; + return true; +} + static int smb_vfs_openat_ci(TALLOC_CTX *mem_ctx, bool case_sensitive, struct connection_struct *conn, diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index e2902783efb..adc4be7755a 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -339,10 +339,6 @@ NTSTATUS get_real_filename_full_scan_at(struct files_struct *dirfsp, bool mangled, TALLOC_CTX *mem_ctx, char **found_name); -bool get_real_filename_cache_key(TALLOC_CTX *mem_ctx, - struct files_struct *dirfsp, - const char *name, - DATA_BLOB *_key); char *get_original_lcomp(TALLOC_CTX *ctx, connection_struct *conn, const char *filename_in, -- 2.47.3