From: Volker Lendecke Date: Wed, 27 Sep 2023 08:44:30 +0000 (+0200) Subject: smbd: Add smb3_file_posix_information_init() X-Git-Tag: tevent-0.16.0~243 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=36fd98a5ef527347ed2c7b766383418920fe498e;p=thirdparty%2Fsamba.git smbd: Add smb3_file_posix_information_init() Copy the logic from store_smb2_posix_info() to allow use of ndr_push_smb3_file_posix_information(). Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 04b1b053ae6..a0a5c168cc0 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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_ */ diff --git a/source3/smbd/smb2_posix.c b/source3/smbd/smb2_posix.c index 7c56af917e4..6908eb9a7b7 100644 --- a/source3/smbd/smb2_posix.c +++ b/source3/smbd/smb2_posix.c @@ -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; + } +}