]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Rename and simplify unix_filetype_from_wire()
authorVolker Lendecke <vl@samba.org>
Fri, 20 Sep 2024 17:36:25 +0000 (19:36 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 26 Sep 2024 15:22:46 +0000 (15:22 +0000)
Align naming with the perms functions, use the fact that the unix
types are numbered the way they are

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
libcli/smb/smb_util.h
libcli/smb/util.c
source3/libsmb/clifile.c

index f2cc0fba9ccecb005bacd73b1f378ff988edacc5..b6fa797dc9d4ef4b8f7b66ff6ec4f61b2a14e014 100644 (file)
@@ -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);
 
index baae532b55a2a384d62c8fbac4094484513ac38c..50c136244c044787e44106be0d852720c6b2af89 100644 (file)
@@ -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)
index 30d08d6f6f2e97a53fea60a2fef1e8c433b81a89..812050d7e640d0e84dd812e505061f83fb9a88d4 100644 (file)
@@ -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)
        {