From: Volker Lendecke Date: Fri, 20 Sep 2024 17:36:25 +0000 (+0200) Subject: libsmb: Rename and simplify unix_filetype_from_wire() X-Git-Tag: tdb-1.4.13~1069 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c9aa5fa15b13b5a2532f421b0584216a52875cb;p=thirdparty%2Fsamba.git libsmb: Rename and simplify unix_filetype_from_wire() Align naming with the perms functions, use the fact that the unix types are numbered the way they are Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/libcli/smb/smb_util.h b/libcli/smb/smb_util.h index f2cc0fba9cc..b6fa797dc9d 100644 --- a/libcli/smb/smb_util.h +++ b/libcli/smb/smb_util.h @@ -32,7 +32,7 @@ const char *smb_protocol_types_string(enum protocol_types protocol); 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 unix_filetype_from_wire(uint32_t wire_type); +mode_t wire_filetype_to_unix(uint32_t wire_type); 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 baae532b55a..50c136244c0 100644 --- a/libcli/smb/util.c +++ b/libcli/smb/util.c @@ -162,40 +162,24 @@ mode_t wire_perms_to_unix(uint32_t perms) return ret; } + /**************************************************************************** - Return the file type from the wire filetype for UNIX extensions. -****************************************************************************/ + * Return the file type from the wire filetype for UNIX extensions. + * + * This uses the fact that the unix file types are numbered from + * FILE=0 to SOCKET=6. This is an accepted protocol element that will + * never change. + ****************************************************************************/ -mode_t unix_filetype_from_wire(uint32_t wire_type) +static mode_t unix_filetypes[] = + {S_IFREG, S_IFDIR, S_IFLNK, S_IFCHR, S_IFBLK, S_IFIFO, S_IFSOCK}; + +mode_t wire_filetype_to_unix(uint32_t wire_type) { - switch (wire_type) { - case UNIX_TYPE_FILE: - return S_IFREG; - case UNIX_TYPE_DIR: - return S_IFDIR; -#ifdef S_IFLNK - case UNIX_TYPE_SYMLINK: - return S_IFLNK; -#endif -#ifdef S_IFCHR - case UNIX_TYPE_CHARDEV: - return S_IFCHR; -#endif -#ifdef S_IFBLK - case UNIX_TYPE_BLKDEV: - return S_IFBLK; -#endif -#ifdef S_IFIFO - case UNIX_TYPE_FIFO: - return S_IFIFO; -#endif -#ifdef S_IFSOCK - case UNIX_TYPE_SOCKET: - return S_IFSOCK; -#endif - default: - return (mode_t)0; + if (wire_type > ARRAY_SIZE(unix_filetypes)) { + return (mode_t)0; } + return unix_filetypes[wire_type]; } bool smb_buffer_oob(uint32_t bufsize, uint32_t offset, uint32_t length) diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 30d08d6f6f2..812050d7e64 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -862,7 +862,7 @@ static void cli_posix_stat_done(struct tevent_req *subreq) sbuf->st_ex_uid = (uid_t) IVAL(data, 40); /* user ID of owner */ sbuf->st_ex_gid = (gid_t) IVAL(data, 48); /* group ID of owner */ - sbuf->st_ex_mode = unix_filetype_from_wire(IVAL(data, 56)); + sbuf->st_ex_mode = wire_filetype_to_unix(IVAL(data, 56)); #if defined(HAVE_MAKEDEV) {