2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "smbd/globals.h"
23 #include "../libcli/smb/smb_common.h"
25 static NTSTATUS
smbd_smb2_close(struct smbd_smb2_request
*req
,
27 uint64_t in_file_id_volatile
,
30 NTSTATUS
smbd_smb2_request_process_close(struct smbd_smb2_request
*req
)
33 const uint8_t *inbody
;
34 int i
= req
->current_idx
;
37 size_t expected_body_size
= 0x18;
40 uint64_t in_file_id_persistent
;
41 uint64_t in_file_id_volatile
;
44 inhdr
= (const uint8_t *)req
->in
.vector
[i
+0].iov_base
;
45 if (req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
46 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
49 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
51 body_size
= SVAL(inbody
, 0x00);
52 if (body_size
!= expected_body_size
) {
53 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
56 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x3C);
57 if (outbody
.data
== NULL
) {
58 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
61 in_flags
= SVAL(inbody
, 0x02);
62 in_file_id_persistent
= BVAL(inbody
, 0x08);
63 in_file_id_volatile
= BVAL(inbody
, 0x10);
65 if (req
->compat_chain_fsp
) {
67 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
68 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
71 status
= smbd_smb2_close(req
,
75 if (!NT_STATUS_IS_OK(status
)) {
76 return smbd_smb2_request_error(req
, status
);
79 outhdr
= (uint8_t *)req
->out
.vector
[i
].iov_base
;
80 return smbd_smb2_request_done(req
, outbody
, NULL
);
83 static NTSTATUS
smbd_smb2_close(struct smbd_smb2_request
*req
,
85 uint64_t in_file_id_volatile
,
89 struct smb_request
*smbreq
;
90 connection_struct
*conn
= req
->tcon
->compat_conn
;
92 struct smb_filename
*smb_fname
= NULL
;
93 struct timespec mdate_ts
, adate_ts
, cdate_ts
, create_date_ts
;
94 uint64_t allocation_size
= 0;
95 uint64_t file_size
= 0;
96 uint32_t dos_attrs
= 0;
97 uint16_t out_flags
= 0;
98 bool posix_open
= false;
100 ZERO_STRUCT(create_date_ts
);
101 ZERO_STRUCT(adate_ts
);
102 ZERO_STRUCT(mdate_ts
);
103 ZERO_STRUCT(cdate_ts
);
105 DEBUG(10,("smbd_smb2_close: file_id[0x%016llX]\n",
106 (unsigned long long)in_file_id_volatile
));
108 smbreq
= smbd_smb2_fake_smb_request(req
);
109 if (smbreq
== NULL
) {
110 return NT_STATUS_NO_MEMORY
;
113 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
115 return NT_STATUS_FILE_CLOSED
;
117 if (conn
!= fsp
->conn
) {
118 return NT_STATUS_FILE_CLOSED
;
120 if (req
->session
->vuid
!= fsp
->vuid
) {
121 return NT_STATUS_FILE_CLOSED
;
124 posix_open
= fsp
->posix_open
;
125 status
= copy_smb_filename(talloc_tos(),
128 if (!NT_STATUS_IS_OK(status
)) {
132 status
= close_file(smbreq
, fsp
, NORMAL_CLOSE
);
133 if (!NT_STATUS_IS_OK(status
)) {
134 DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n",
135 fsp_str_dbg(fsp
), nt_errstr(status
)));
139 if (in_flags
& SMB2_CLOSE_FLAGS_FULL_INFORMATION
) {
142 ret
= SMB_VFS_LSTAT(conn
, smb_fname
);
144 ret
= SMB_VFS_STAT(conn
, smb_fname
);
147 out_flags
= SMB2_CLOSE_FLAGS_FULL_INFORMATION
;
148 dos_attrs
= dos_mode(conn
, smb_fname
);
149 mdate_ts
= smb_fname
->st
.st_ex_mtime
;
150 adate_ts
= smb_fname
->st
.st_ex_atime
;
151 create_date_ts
= get_create_timespec(conn
, NULL
, smb_fname
);
152 cdate_ts
= get_change_timespec(conn
, NULL
, smb_fname
);
154 if (lp_dos_filetime_resolution(SNUM(conn
))) {
155 dos_filetime_timespec(&create_date_ts
);
156 dos_filetime_timespec(&mdate_ts
);
157 dos_filetime_timespec(&adate_ts
);
158 dos_filetime_timespec(&cdate_ts
);
160 if (!(dos_attrs
& FILE_ATTRIBUTE_DIRECTORY
)) {
161 file_size
= get_file_size_stat(&smb_fname
->st
);
164 allocation_size
= SMB_VFS_GET_ALLOC_SIZE(conn
, NULL
, &smb_fname
->st
);
168 SSVAL(outbody
->data
, 0x00, 0x3C); /* struct size */
169 SSVAL(outbody
->data
, 0x02, out_flags
); /* flags */
170 SIVAL(outbody
->data
, 0x04, 0); /* reserved */
171 put_long_date_timespec(conn
->ts_res
,
172 (char *)&outbody
->data
[0x8],create_date_ts
); /* creation time */
173 put_long_date_timespec(conn
->ts_res
,
174 (char *)&outbody
->data
[0x10],adate_ts
); /* last access time */
175 put_long_date_timespec(conn
->ts_res
,
176 (char *)&outbody
->data
[0x18],mdate_ts
); /* last write time */
177 put_long_date_timespec(conn
->ts_res
,
178 (char *)&outbody
->data
[0x20],cdate_ts
); /* change time */
179 SBVAL(outbody
->data
, 0x28, allocation_size
);/* allocation size */
180 SBVAL(outbody
->data
, 0x30, file_size
); /* end of file */
181 SIVAL(outbody
->data
, 0x38, dos_attrs
); /* file attributes */