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/>.
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/raw/raw_proto.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
31 struct smb2_request
*smb2_notify_send(struct smb2_tree
*tree
, struct smb2_notify
*io
)
33 struct smb2_request
*req
;
36 req
= smb2_request_init_tree(tree
, SMB2_OP_NOTIFY
, 0x20, false, 0);
37 if (req
== NULL
) return NULL
;
39 SSVAL(req
->out
.hdr
, SMB2_HDR_CREDIT
, 0x0030);
41 SSVAL(req
->out
.body
, 0x02, io
->in
.recursive
);
42 SIVAL(req
->out
.body
, 0x04, io
->in
.buffer_size
);
43 smb2_push_handle(req
->out
.body
+0x08, &io
->in
.file
.handle
);
44 SIVAL(req
->out
.body
, 0x18, io
->in
.completion_filter
);
45 SIVAL(req
->out
.body
, 0x1C, io
->in
.unknown
);
47 old_timeout
= req
->transport
->options
.request_timeout
;
48 req
->transport
->options
.request_timeout
= 0;
49 smb2_transport_send(req
);
50 req
->transport
->options
.request_timeout
= old_timeout
;
59 NTSTATUS
smb2_notify_recv(struct smb2_request
*req
, TALLOC_CTX
*mem_ctx
,
60 struct smb2_notify
*io
)
66 if (!smb2_request_receive(req
) ||
67 !smb2_request_is_ok(req
)) {
68 return smb2_request_destroy(req
);
71 SMB2_CHECK_PACKET_RECV(req
, 0x08, true);
73 status
= smb2_pull_o16s32_blob(&req
->in
, mem_ctx
, req
->in
.body
+0x02, &blob
);
74 if (!NT_STATUS_IS_OK(status
)) {
78 io
->out
.changes
= NULL
;
79 io
->out
.num_changes
= 0;
82 for (ofs
=0; blob
.length
- ofs
> 12; ) {
83 uint32_t next
= IVAL(blob
.data
, ofs
);
84 io
->out
.num_changes
++;
85 if (next
== 0 || (ofs
+ next
) >= blob
.length
) break;
90 io
->out
.changes
= talloc_array(mem_ctx
, struct notify_changes
, io
->out
.num_changes
);
91 if (!io
->out
.changes
) {
92 return NT_STATUS_NO_MEMORY
;
95 for (i
=ofs
=0; i
<io
->out
.num_changes
; i
++) {
96 io
->out
.changes
[i
].action
= IVAL(blob
.data
, ofs
+4);
97 smbcli_blob_pull_string(NULL
, mem_ctx
, &blob
,
98 &io
->out
.changes
[i
].name
,
99 ofs
+8, ofs
+12, STR_UNICODE
);
100 ofs
+= IVAL(blob
.data
, ofs
);
103 return smb2_request_destroy(req
);
109 NTSTATUS
smb2_notify(struct smb2_tree
*tree
, TALLOC_CTX
*mem_ctx
,
110 struct smb2_notify
*io
)
112 struct smb2_request
*req
= smb2_notify_send(tree
, io
);
113 return smb2_notify_recv(req
, mem_ctx
, io
);