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"
26 #include "source3/modules/util_reparse.h"
27 #include "libcli/smb/reparse.h"
29 static NTSTATUS
reparse_buffer_parse_posix_type(uint32_t reparse_tag
,
34 struct reparse_data_buffer
*reparse
= NULL
;
37 if (reparse_tag
== IO_REPARSE_TAG_SYMLINK
) {
41 if (reparse_tag
!= IO_REPARSE_TAG_NFS
) {
43 * Clients can create reparse points with arbitrary tags, return
44 * anything that is not a NFS one (or symlink) as S_IFREG.
46 DBG_INFO("Unhandled NFS reparse tag: 0x%" PRIx32
"\n",
52 reparse
= talloc_zero(talloc_tos(), struct reparse_data_buffer
);
53 if (reparse
== NULL
) {
54 DBG_ERR("talloc_zero() failed\n");
55 return NT_STATUS_NO_MEMORY
;
58 status
= reparse_data_buffer_parse(reparse
, reparse
, data
, len
);
59 if (!NT_STATUS_IS_OK(status
)) {
64 switch (reparse
->parsed
.nfs
.type
) {
65 case NFS_SPECFILE_CHR
:
68 case NFS_SPECFILE_BLK
:
71 case NFS_SPECFILE_FIFO
:
74 case NFS_SPECFILE_SOCK
:
78 DBG_ERR("Unhandled NFS reparse type: 0x%" PRIx64
"\n",
79 reparse
->parsed
.nfs
.type
);
81 return NT_STATUS_REPARSE_POINT_NOT_RESOLVED
;
88 NTSTATUS
smb3_file_posix_information_init(
89 connection_struct
*conn
,
90 const struct smb_filename
*smb_fname
,
91 uint32_t dos_attributes
,
92 struct smb3_file_posix_information
*dst
)
94 const struct stat_ex
*st
= &smb_fname
->st
;
95 mode_t mode
= st
->st_ex_mode
;
96 uint32_t reparse_tag
= 0;
99 switch (mode
& S_IFMT
) {
105 * All non-directory or regular files are reported
106 * as reparse points. Client may or may not be able
107 * to access these. This should already be set by
108 * fdos_mode(), assert this.
110 SMB_ASSERT(dos_attributes
& FILE_ATTRIBUTE_REPARSE_POINT
);
114 if (dos_attributes
& FILE_ATTRIBUTE_REPARSE_POINT
) {
115 uint8_t *reparse_data
= NULL
;
116 uint32_t reparse_len
;
117 mode_t type
= S_IFREG
;
119 status
= fsctl_get_reparse_point(smb_fname
->fsp
,
125 if (!NT_STATUS_IS_OK(status
)) {
126 DBG_DEBUG("Could not get reparse point for %s: %s\n",
127 smb_fname_str_dbg(smb_fname
),
132 status
= reparse_buffer_parse_posix_type(reparse_tag
,
136 TALLOC_FREE(reparse_data
);
137 if (!NT_STATUS_IS_OK(status
)) {
138 DBG_DEBUG("Could not parse reparse data for %s: %s\n",
139 smb_fname_str_dbg(smb_fname
),
145 * Remove the type info we got via stat() and use what
146 * we got from the reparse point.
152 *dst
= (struct smb3_file_posix_information
) {
153 .end_of_file
= get_file_size_stat(st
),
154 .allocation_size
= SMB_VFS_GET_ALLOC_SIZE(conn
,NULL
,st
),
155 .inode
= SMB_VFS_FS_FILE_ID(conn
, st
),
156 .device
= st
->st_ex_dev
,
157 .creation_time
= unix_timespec_to_nt_time(st
->st_ex_btime
),
158 .last_access_time
= unix_timespec_to_nt_time(st
->st_ex_atime
),
159 .last_write_time
= unix_timespec_to_nt_time(st
->st_ex_mtime
),
160 .change_time
= unix_timespec_to_nt_time(st
->st_ex_ctime
),
161 .file_attributes
= dos_attributes
,
162 .cc
.nlinks
= st
->st_ex_nlink
,
163 .cc
.reparse_tag
= reparse_tag
,
164 .cc
.posix_mode
= unix_mode_to_wire(mode
),
165 .cc
.owner
= global_sid_NULL
,
166 .cc
.group
= global_sid_NULL
,
169 if (st
->st_ex_uid
!= (uid_t
)-1) {
170 uid_to_sid(&dst
->cc
.owner
, st
->st_ex_uid
);
172 if (st
->st_ex_gid
!= (uid_t
)-1) {
173 gid_to_sid(&dst
->cc
.group
, st
->st_ex_gid
);