Backport FSCTL codes from master
[Samba.git] / source4 / libcli / smb2 / cancel.c
blob28ef3099f3028a201b8e85ab7803f48d97b33162
1 /*
2 Unix SMB/CIFS implementation.
4 SMB2 client notify calls
6 Copyright (C) Stefan Metzmacher 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
28 send a cancel request
30 NTSTATUS smb2_cancel(struct smb2_request *r)
32 NTSTATUS status;
33 struct smb2_request *c;
34 uint32_t old_timeout;
35 uint64_t old_seqnum;
37 /*
38 * if we don't get a pending id yet, we just
39 * mark the request for pending, so that we directly
40 * send the cancel after getting the pending id
42 if (!r->cancel.can_cancel) {
43 r->cancel.do_cancel++;
44 return NT_STATUS_OK;
47 /* we don't want a seqmun for a SMB2 Cancel */
48 old_seqnum = r->transport->seqnum;
49 c = smb2_request_init(r->transport, SMB2_OP_CANCEL, 0x04, false, 0);
50 r->transport->seqnum = old_seqnum;
51 NT_STATUS_HAVE_NO_MEMORY(c);
52 c->seqnum = 0;
54 SIVAL(c->out.hdr, SMB2_HDR_FLAGS, 0x00000002);
55 SSVAL(c->out.hdr, SMB2_HDR_CREDIT, 0x0030);
56 SBVAL(c->out.hdr, SMB2_HDR_ASYNC_ID, r->cancel.async_id);
57 SBVAL(c->out.hdr, SMB2_HDR_MESSAGE_ID, c->seqnum);
58 if (r->session) {
59 SBVAL(c->out.hdr, SMB2_HDR_SESSION_ID, r->session->uid);
62 SSVAL(c->out.body, 0x02, 0);
64 old_timeout = c->transport->options.request_timeout;
65 c->transport->options.request_timeout = 0;
66 smb2_transport_send(c);
67 c->transport->options.request_timeout = old_timeout;
69 if (c->state == SMB2_REQUEST_ERROR) {
70 status = c->status;
71 } else {
72 status = NT_STATUS_OK;
75 talloc_free(c);
76 return status;