]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add smb3_file_posix_information_init()
authorVolker Lendecke <vl@samba.org>
Wed, 27 Sep 2023 08:44:30 +0000 (10:44 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 4 Oct 2023 20:31:36 +0000 (20:31 +0000)
Copy the logic from store_smb2_posix_info() to allow use of
ndr_push_smb3_file_posix_information().

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/proto.h
source3/smbd/smb2_posix.c

index 04b1b053ae6fd45be219cf4b411e4ff955294d7e..a0a5c168cc0bf4f22f79837857bf1fe0ca5ace05 100644 (file)
@@ -1276,4 +1276,12 @@ ssize_t store_smb2_posix_info(
        uint8_t *buf,
        size_t buflen);
 
+struct smb3_file_posix_information;
+void smb3_file_posix_information_init(
+       connection_struct *conn,
+       const struct stat_ex *st,
+       uint32_t reparse_tag,
+       uint32_t dos_attributes,
+       struct smb3_file_posix_information *dst);
+
 #endif /* _SMBD_PROTO_H_ */
index 7c56af917e4a7b14444215cd4851a943983cf2a2..6908eb9a7b74e44d215b8c4ef8d6591ed6afe64f 100644 (file)
@@ -21,6 +21,7 @@
 #include "smbd/smbd.h"
 #include "passdb/lookup_sid.h"
 #include "librpc/gen_ndr/ndr_security.h"
+#include "librpc/gen_ndr/smb3posix.h"
 #include "libcli/security/security.h"
 
 /*
@@ -177,3 +178,49 @@ ssize_t store_smb2_posix_info(
 
        return cc_len + 68;
 }
+
+void smb3_file_posix_information_init(
+       connection_struct *conn,
+       const struct stat_ex *st,
+       uint32_t reparse_tag,
+       uint32_t dos_attributes,
+       struct smb3_file_posix_information *dst)
+{
+       *dst = (struct smb3_file_posix_information) {
+               .end_of_file = get_file_size_stat(st),
+               .allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,NULL,st),
+               .device = st->st_ex_dev,
+               .creation_time = unix_timespec_to_nt_time(st->st_ex_btime),
+               .last_access_time = unix_timespec_to_nt_time(st->st_ex_atime),
+               .last_write_time = unix_timespec_to_nt_time(st->st_ex_mtime),
+               .change_time = unix_timespec_to_nt_time(st->st_ex_ctime),
+               .cc.reparse_tag = reparse_tag,
+               .cc.posix_perms = unix_perms_to_wire(st->st_ex_mode & ~S_IFMT),
+               .cc.owner = global_sid_NULL,
+               .cc.group = global_sid_NULL,
+       };
+
+       if (st->st_ex_uid != (uid_t)-1) {
+               uid_to_sid(&dst->cc.owner, st->st_ex_uid);
+       }
+       if (st->st_ex_gid != (uid_t)-1) {
+               uid_to_sid(&dst->cc.owner, st->st_ex_gid);
+       }
+
+       switch (st->st_ex_mode & S_IFMT) {
+       case S_IFREG:
+               dst->file_attributes = dos_attributes;
+               break;
+       case S_IFDIR:
+               dst->file_attributes = dos_attributes | FILE_ATTRIBUTE_DIRECTORY;
+               break;
+       default:
+               /*
+                * All non-directory or regular files are reported
+                * as reparse points. Client may or may not be able
+                * to access these.
+                */
+               dst->file_attributes = FILE_ATTRIBUTE_REPARSE_POINT;
+               break;
+       }
+}