2 Unix SMB/CIFS implementation.
4 Copyright (C) Gregor Beck 2013
5 Copyright (C) Stefan Metzmacher 2013
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 "system/network.h"
23 #include "lib/util/tevent_ntstatus.h"
24 #include "smb_common.h"
25 #include "smbXcli_base.h"
27 struct smb1cli_close_state
{
31 static void smb1cli_close_done(struct tevent_req
*subreq
);
34 * Send an asynchronous SMB_COM_CLOSE request.
35 * <a href="http://msdn.microsoft.com/en-us/library/ee442151.aspx">MS-CIFS 2.2.4.5.1</a>
36 * @see smb1cli_close_recv(), smb1cli_close()
38 * @param[in] mem_ctx The memory context for the result.
39 * @param[in] ev The event context to work on.
40 * @param[in] conn The smb connection.
41 * @param[in] timeout_msec If positiv a timeout for the request.
42 * @param[in] pid The process identifier.
43 * @param[in] tcon The smb tree connect.
44 * @param[in] session The smb session.
45 * @param[in] fnum The file id of the file to be closed.
46 * @param[in] last_modified If not 0 or 0xFFFFFFFF request to set modification time to this number of seconds since January 1, 1970.
48 * @return a tevent_req or NULL.
50 struct tevent_req
*smb1cli_close_send(TALLOC_CTX
*mem_ctx
,
51 struct tevent_context
*ev
,
52 struct smbXcli_conn
*conn
,
53 uint32_t timeout_msec
,
55 struct smbXcli_tcon
*tcon
,
56 struct smbXcli_session
*session
,
58 uint32_t last_modified
)
60 struct tevent_req
*req
, *subreq
;
61 struct smb1cli_close_state
*state
;
63 req
= tevent_req_create(mem_ctx
, &state
, struct smb1cli_close_state
);
68 SSVAL(state
->vwv
+0, 0, fnum
);
69 SIVALS(state
->vwv
+1, 0, last_modified
);
71 subreq
= smb1cli_req_send(state
, ev
, conn
, SMBclose
,
74 timeout_msec
, pid
, tcon
, session
,
75 ARRAY_SIZE(state
->vwv
), state
->vwv
,
77 if (tevent_req_nomem(subreq
, req
)) {
78 return tevent_req_post(req
, ev
);
80 tevent_req_set_callback(subreq
, smb1cli_close_done
, req
);
84 static void smb1cli_close_done(struct tevent_req
*subreq
)
86 struct tevent_req
*req
= tevent_req_callback_data(
87 subreq
, struct tevent_req
);
88 struct smb1cli_close_state
*state
= tevent_req_data(
89 req
, struct smb1cli_close_state
);
91 static const struct smb1cli_req_expected_response expected
[] = {
93 .status
= NT_STATUS_OK
,
98 status
= smb1cli_req_recv(subreq
, state
,
103 NULL
, /* pvwv_offset */
104 NULL
, /* num_bytes */
106 NULL
, /* pbytes_offset */
108 expected
, ARRAY_SIZE(expected
));
110 if (tevent_req_nterror(req
, status
)) {
114 tevent_req_done(req
);
118 * Receive the response to an asynchronous SMB_COM_CLOSE request.
119 * <a href="http://msdn.microsoft.com/en-us/library/ee441667.aspx">MS-CIFS 2.2.4.5.2</a>
121 * @param req A tevent_req created with smb1cli_close_send()
123 * @return NT_STATUS_OK on success
125 NTSTATUS
smb1cli_close_recv(struct tevent_req
*req
)
127 return tevent_req_simple_recv_ntstatus(req
);
131 * Send an synchronous SMB_COM_CLOSE request.
132 * <a href="http://msdn.microsoft.com/en-us/library/ee441493.aspx">MS-CIFS 2.2.4.5</a>
133 * @see smb1cli_close_send(), smb1cli_close_recv()
135 * @param[in] conn The smb connection.
136 * @param[in] timeout_msec If positiv a timeout for the request.
137 * @param[in] pid The process identifier.
138 * @param[in] tcon The smb tree connect.
139 * @param[in] session The smb session.
140 * @param[in] fnum The file id of the file to be closed.
141 * @param[in] last_modified If not 0 or 0xFFFFFFFF request to set modification time to this number of seconds since J
143 * @return NT_STATUS_OK on success.
145 NTSTATUS
smb1cli_close(struct smbXcli_conn
*conn
,
146 uint32_t timeout_msec
,
148 struct smbXcli_tcon
*tcon
,
149 struct smbXcli_session
*session
,
151 uint32_t last_modified
)
153 NTSTATUS status
= NT_STATUS_OK
;
154 struct tevent_req
*req
;
155 TALLOC_CTX
*frame
= talloc_stackframe();
156 struct tevent_context
*ev
;
158 if (smbXcli_conn_has_async_calls(conn
)) {
160 * Can't use sync call while an async call is in flight
162 status
= NT_STATUS_INVALID_PARAMETER
;
166 ev
= samba_tevent_context_init(frame
);
168 status
= NT_STATUS_NO_MEMORY
;
172 req
= smb1cli_close_send(frame
, ev
, conn
,
173 timeout_msec
, pid
, tcon
, session
,
174 fnum
, last_modified
);
176 status
= NT_STATUS_NO_MEMORY
;
180 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
184 status
= smb1cli_close_recv(req
);