Line data Source code
1 : /* 2 : Unix SMB/CIFS implementation. 3 : SMB2 POSIX code. 4 : Copyright (C) Jeremy Allison 2022 5 : 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. 10 : 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. 15 : 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/>. 18 : */ 19 : 20 : #include "includes.h" 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" 26 : 27 1449 : void smb3_file_posix_information_init( 28 : connection_struct *conn, 29 : const struct stat_ex *st, 30 : uint32_t reparse_tag, 31 : uint32_t dos_attributes, 32 : struct smb3_file_posix_information *dst) 33 : { 34 2898 : *dst = (struct smb3_file_posix_information) { 35 1449 : .end_of_file = get_file_size_stat(st), 36 1449 : .allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,NULL,st), 37 1449 : .inode = SMB_VFS_FS_FILE_ID(conn, st), 38 1449 : .device = st->st_ex_dev, 39 1449 : .creation_time = unix_timespec_to_nt_time(st->st_ex_btime), 40 1449 : .last_access_time = unix_timespec_to_nt_time(st->st_ex_atime), 41 1449 : .last_write_time = unix_timespec_to_nt_time(st->st_ex_mtime), 42 1449 : .change_time = unix_timespec_to_nt_time(st->st_ex_ctime), 43 1449 : .cc.nlinks = st->st_ex_nlink, 44 : .cc.reparse_tag = reparse_tag, 45 1449 : .cc.posix_perms = unix_perms_to_wire(st->st_ex_mode & ~S_IFMT), 46 : .cc.owner = global_sid_NULL, 47 : .cc.group = global_sid_NULL, 48 : }; 49 : 50 1449 : if (st->st_ex_uid != (uid_t)-1) { 51 1443 : uid_to_sid(&dst->cc.owner, st->st_ex_uid); 52 : } 53 1449 : if (st->st_ex_gid != (uid_t)-1) { 54 1443 : gid_to_sid(&dst->cc.group, st->st_ex_gid); 55 : } 56 : 57 1449 : switch (st->st_ex_mode & S_IFMT) { 58 655 : case S_IFREG: 59 655 : dst->file_attributes = dos_attributes; 60 655 : break; 61 794 : case S_IFDIR: 62 794 : dst->file_attributes = dos_attributes | FILE_ATTRIBUTE_DIRECTORY; 63 794 : break; 64 0 : default: 65 : /* 66 : * All non-directory or regular files are reported 67 : * as reparse points. Client may or may not be able 68 : * to access these. 69 : */ 70 0 : dst->file_attributes = FILE_ATTRIBUTE_REPARSE_POINT; 71 0 : break; 72 : } 73 1449 : }