Merge commit 'release-4-0-0alpha1' into v4-0-test
[ira/wip.git] / source / libcli / smb2 / cancel.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 client notify calls
5
6    Copyright (C) Stefan Metzmacher 2006
7    
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26
27 /*
28   send a cancel request
29 */
30 NTSTATUS smb2_cancel(struct smb2_request *r)
31 {
32         NTSTATUS status;
33         struct smb2_request *c;
34         uint32_t old_timeout;
35         uint64_t old_seqnum;
36
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
41          */
42         if (!r->cancel.can_cancel) {
43                 r->cancel.do_cancel++;
44                 return NT_STATUS_OK;
45         }
46
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;
53
54         SIVAL(c->out.hdr, SMB2_HDR_FLAGS,       0x00000002);
55         SSVAL(c->out.hdr, SMB2_HDR_UNKNOWN1,    0x0030);
56         SIVAL(c->out.hdr, SMB2_HDR_PID,         r->cancel.pending_id);
57         SBVAL(c->out.hdr, SMB2_HDR_SEQNUM,      c->seqnum);
58         if (r->session) {
59                 SBVAL(c->out.hdr, SMB2_HDR_UID, r->session->uid);
60         }
61
62         SSVAL(c->out.body, 0x02, 0);
63
64         old_timeout = c->transport->options.timeout;
65         c->transport->options.timeout = 0;
66         smb2_transport_send(c);
67         c->transport->options.timeout = old_timeout;
68
69         if (c->state == SMB2_REQUEST_ERROR) {
70                 status = c->status;
71         } else {
72                 status = NT_STATUS_OK;
73         }
74
75         talloc_free(c);
76         return status;
77 }