]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Move unix_filetype_to_wire() to libcli/smb
authorVolker Lendecke <vl@samba.org>
Fri, 20 Sep 2024 17:43:18 +0000 (19:43 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 26 Sep 2024 15:22:46 +0000 (15:22 +0000)
Mostly symmetry reasons, we have the opposite function here as well

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/smbd/smb2_trans2.c

index b6fa797dc9d4ef4b8f7b66ff6ec4f61b2a14e014..3c71f50b442f800924e55d9c5322850d99a3d105 100644 (file)
@@ -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);
 
index 50c136244c044787e44106be0d852720c6b2af89..b134aaf8b89f041890583259df2463463294a740 100644 (file)
@@ -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)) {
index e8af2bef08f45ab0dcbc9b85c87d9b3a2e02fb09..de0105e5c212be40ddfcf3e03b77a25332ab5f0a 100644 (file)
@@ -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)) {