From 6084914e22feee578b2c28230dea4b65a9f98bfd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 20 Sep 2024 19:43:18 +0200 Subject: [PATCH] libsmb: Move unix_filetype_to_wire() to libcli/smb Mostly symmetry reasons, we have the opposite function here as well Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- libcli/smb/smb_util.h | 1 + libcli/smb/util.c | 13 +++++++++++++ source3/smbd/smb2_trans2.c | 37 +------------------------------------ 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/libcli/smb/smb_util.h b/libcli/smb/smb_util.h index b6fa797dc9d..3c71f50b442 100644 --- a/libcli/smb/smb_util.h +++ b/libcli/smb/smb_util.h @@ -33,6 +33,7 @@ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib); uint32_t unix_perms_to_wire(mode_t perms); mode_t wire_perms_to_unix(uint32_t perms); mode_t wire_filetype_to_unix(uint32_t wire_type); +uint32_t unix_filetype_to_wire(mode_t mode); bool smb_buffer_oob(uint32_t bufsize, uint32_t offset, uint32_t length); diff --git a/libcli/smb/util.c b/libcli/smb/util.c index 50c136244c0..b134aaf8b89 100644 --- a/libcli/smb/util.c +++ b/libcli/smb/util.c @@ -182,6 +182,19 @@ mode_t wire_filetype_to_unix(uint32_t wire_type) return unix_filetypes[wire_type]; } +uint32_t unix_filetype_to_wire(mode_t mode) +{ + mode_t type = mode & S_IFMT; + size_t i; + + for (i = 0; i < ARRAY_SIZE(unix_filetypes); i++) { + if (type == unix_filetypes[i]) { + return i; + } + } + return UNIX_TYPE_UNKNOWN; +} + bool smb_buffer_oob(uint32_t bufsize, uint32_t offset, uint32_t length) { if ((offset + length < offset) || (offset + length < length)) { diff --git a/source3/smbd/smb2_trans2.c b/source3/smbd/smb2_trans2.c index e8af2bef08f..de0105e5c21 100644 --- a/source3/smbd/smb2_trans2.c +++ b/source3/smbd/smb2_trans2.c @@ -887,41 +887,6 @@ static struct ea_list *ea_list_union(struct ea_list *name_list, struct ea_list * return name_list; } -/**************************************************************************** - Return the filetype for UNIX extensions. -****************************************************************************/ - -static uint32_t unix_filetype(mode_t mode) -{ - if(S_ISREG(mode)) - return UNIX_TYPE_FILE; - else if(S_ISDIR(mode)) - return UNIX_TYPE_DIR; -#ifdef S_ISLNK - else if(S_ISLNK(mode)) - return UNIX_TYPE_SYMLINK; -#endif -#ifdef S_ISCHR - else if(S_ISCHR(mode)) - return UNIX_TYPE_CHARDEV; -#endif -#ifdef S_ISBLK - else if(S_ISBLK(mode)) - return UNIX_TYPE_BLKDEV; -#endif -#ifdef S_ISFIFO - else if(S_ISFIFO(mode)) - return UNIX_TYPE_FIFO; -#endif -#ifdef S_ISSOCK - else if(S_ISSOCK(mode)) - return UNIX_TYPE_SOCKET; -#endif - - DEBUG(0,("unix_filetype: unknown filetype %u\n", (unsigned)mode)); - return UNIX_TYPE_UNKNOWN; -} - /**************************************************************************** Map wire perms onto standard UNIX permissions. Obey share restrictions. ****************************************************************************/ @@ -2797,7 +2762,7 @@ char *store_file_unix_basic(connection_struct *conn, SIVAL(pdata,4,0); pdata += 8; - SIVAL(pdata,0,unix_filetype(psbuf->st_ex_mode)); + SIVAL(pdata, 0, unix_filetype_to_wire(psbuf->st_ex_mode)); pdata += 4; if (S_ISBLK(psbuf->st_ex_mode) || S_ISCHR(psbuf->st_ex_mode)) {