s3-printing: remove print_parse_jobid() calls from printing.c
[Samba.git] / source3 / smbd / smb2_close.c
blob9459503ba681f39c14d6b1100f5ee0ea938b6a63
1 /*
2 Unix SMB/CIFS implementation.
3 Core SMB2 server
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/>.
21 #include "includes.h"
22 #include "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/smb/smb_common.h"
26 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
27 struct files_struct *fsp,
28 uint16_t in_flags,
29 DATA_BLOB *outbody);
31 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
33 const uint8_t *inbody;
34 int i = req->current_idx;
35 uint8_t *outhdr;
36 DATA_BLOB outbody;
37 uint16_t in_flags;
38 uint64_t in_file_id_persistent;
39 uint64_t in_file_id_volatile;
40 struct files_struct *in_fsp;
41 NTSTATUS status;
43 status = smbd_smb2_request_verify_sizes(req, 0x18);
44 if (!NT_STATUS_IS_OK(status)) {
45 return smbd_smb2_request_error(req, status);
47 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
49 outbody = data_blob_talloc(req->out.vector, NULL, 0x3C);
50 if (outbody.data == NULL) {
51 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
54 in_flags = SVAL(inbody, 0x02);
55 in_file_id_persistent = BVAL(inbody, 0x08);
56 in_file_id_volatile = BVAL(inbody, 0x10);
58 in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
59 if (in_fsp == NULL) {
60 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
63 status = smbd_smb2_close(req,
64 in_fsp,
65 in_flags,
66 &outbody);
67 if (!NT_STATUS_IS_OK(status)) {
68 return smbd_smb2_request_error(req, status);
71 outhdr = (uint8_t *)req->out.vector[i].iov_base;
72 return smbd_smb2_request_done(req, outbody, NULL);
75 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
76 struct files_struct *fsp,
77 uint16_t in_flags,
78 DATA_BLOB *outbody)
80 NTSTATUS status;
81 struct smb_request *smbreq;
82 connection_struct *conn = req->tcon->compat_conn;
83 struct smb_filename *smb_fname = NULL;
84 struct timespec mdate_ts, adate_ts, cdate_ts, create_date_ts;
85 uint64_t allocation_size = 0;
86 uint64_t file_size = 0;
87 uint32_t dos_attrs = 0;
88 uint16_t out_flags = 0;
89 bool posix_open = false;
91 ZERO_STRUCT(create_date_ts);
92 ZERO_STRUCT(adate_ts);
93 ZERO_STRUCT(mdate_ts);
94 ZERO_STRUCT(cdate_ts);
96 DEBUG(10,("smbd_smb2_close: %s - fnum[%d]\n",
97 fsp_str_dbg(fsp), fsp->fnum));
99 smbreq = smbd_smb2_fake_smb_request(req);
100 if (smbreq == NULL) {
101 return NT_STATUS_NO_MEMORY;
104 posix_open = fsp->posix_open;
105 status = copy_smb_filename(talloc_tos(),
106 fsp->fsp_name,
107 &smb_fname);
108 if (!NT_STATUS_IS_OK(status)) {
109 return status;
112 status = close_file(smbreq, fsp, NORMAL_CLOSE);
113 if (!NT_STATUS_IS_OK(status)) {
114 DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n",
115 fsp_str_dbg(fsp), nt_errstr(status)));
116 return status;
119 if (in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) {
120 int ret;
121 if (posix_open) {
122 ret = SMB_VFS_LSTAT(conn, smb_fname);
123 } else {
124 ret = SMB_VFS_STAT(conn, smb_fname);
126 if (ret == 0) {
127 out_flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
128 dos_attrs = dos_mode(conn, smb_fname);
129 mdate_ts = smb_fname->st.st_ex_mtime;
130 adate_ts = smb_fname->st.st_ex_atime;
131 create_date_ts = get_create_timespec(conn, NULL, smb_fname);
132 cdate_ts = get_change_timespec(conn, NULL, smb_fname);
134 if (lp_dos_filetime_resolution(SNUM(conn))) {
135 dos_filetime_timespec(&create_date_ts);
136 dos_filetime_timespec(&mdate_ts);
137 dos_filetime_timespec(&adate_ts);
138 dos_filetime_timespec(&cdate_ts);
140 if (!(dos_attrs & FILE_ATTRIBUTE_DIRECTORY)) {
141 file_size = get_file_size_stat(&smb_fname->st);
144 allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
148 SSVAL(outbody->data, 0x00, 0x3C); /* struct size */
149 SSVAL(outbody->data, 0x02, out_flags); /* flags */
150 SIVAL(outbody->data, 0x04, 0); /* reserved */
151 put_long_date_timespec(conn->ts_res,
152 (char *)&outbody->data[0x8],create_date_ts); /* creation time */
153 put_long_date_timespec(conn->ts_res,
154 (char *)&outbody->data[0x10],adate_ts); /* last access time */
155 put_long_date_timespec(conn->ts_res,
156 (char *)&outbody->data[0x18],mdate_ts); /* last write time */
157 put_long_date_timespec(conn->ts_res,
158 (char *)&outbody->data[0x20],cdate_ts); /* change time */
159 SBVAL(outbody->data, 0x28, allocation_size);/* allocation size */
160 SBVAL(outbody->data, 0x30, file_size); /* end of file */
161 SIVAL(outbody->data, 0x38, dos_attrs); /* file attributes */
163 return NT_STATUS_OK;