2 Unix SMB/CIFS implementation.
4 Copyright (C) Jeremy Allison 2022
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "smbd/smbd.h"
22 #include "passdb/lookup_sid.h"
23 #include "librpc/gen_ndr/ndr_security.h"
24 #include "librpc/gen_ndr/smb3posix.h"
25 #include "libcli/security/security.h"
27 void smb3_file_posix_information_init(
28 connection_struct *conn,
29 const struct stat_ex *st,
31 uint32_t dos_attributes,
32 struct smb3_file_posix_information *dst)
34 *dst = (struct smb3_file_posix_information) {
35 .end_of_file = get_file_size_stat(st),
36 .allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,NULL,st),
37 .device = st->st_ex_dev,
38 .creation_time = unix_timespec_to_nt_time(st->st_ex_btime),
39 .last_access_time = unix_timespec_to_nt_time(st->st_ex_atime),
40 .last_write_time = unix_timespec_to_nt_time(st->st_ex_mtime),
41 .change_time = unix_timespec_to_nt_time(st->st_ex_ctime),
42 .cc.nlinks = st->st_ex_nlink,
43 .cc.reparse_tag = reparse_tag,
44 .cc.posix_perms = unix_perms_to_wire(st->st_ex_mode & ~S_IFMT),
45 .cc.owner = global_sid_NULL,
46 .cc.group = global_sid_NULL,
49 if (st->st_ex_uid != (uid_t)-1) {
50 uid_to_sid(&dst->cc.owner, st->st_ex_uid);
52 if (st->st_ex_gid != (uid_t)-1) {
53 gid_to_sid(&dst->cc.group, st->st_ex_gid);
56 switch (st->st_ex_mode & S_IFMT) {
58 dst->file_attributes = dos_attributes;
61 dst->file_attributes = dos_attributes | FILE_ATTRIBUTE_DIRECTORY;
65 * All non-directory or regular files are reported
66 * as reparse points. Client may or may not be able
69 dst->file_attributes = FILE_ATTRIBUTE_REPARSE_POINT;