r25554: Convert last instances of BOOL, True and False to the standard types.
[kamenim/samba.git] / source4 / libcli / smb2 / notify.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 notify request
29 */
30 struct smb2_request *smb2_notify_send(struct smb2_tree *tree, struct smb2_notify *io)
31 {
32         struct smb2_request *req;
33         uint32_t old_timeout;
34
35         req = smb2_request_init_tree(tree, SMB2_OP_NOTIFY, 0x20, false, 0);
36         if (req == NULL) return NULL;
37
38         SSVAL(req->out.hdr,  SMB2_HDR_UNKNOWN1, 0x0030);
39
40         SSVAL(req->out.body, 0x02, io->in.recursive);
41         SIVAL(req->out.body, 0x04, io->in.buffer_size);
42         smb2_push_handle(req->out.body+0x08, &io->in.file.handle);
43         SIVAL(req->out.body, 0x18, io->in.completion_filter);
44         SIVAL(req->out.body, 0x1C, io->in.unknown);
45
46         old_timeout = req->transport->options.timeout;
47         req->transport->options.timeout = 0;
48         smb2_transport_send(req);
49         req->transport->options.timeout = old_timeout;
50
51         return req;
52 }
53
54
55 /*
56   recv a notify reply
57 */
58 NTSTATUS smb2_notify_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
59                           struct smb2_notify *io)
60 {
61         NTSTATUS status;
62         DATA_BLOB blob;
63         uint32_t ofs, i;
64
65         if (!smb2_request_receive(req) || 
66             !smb2_request_is_ok(req)) {
67                 return smb2_request_destroy(req);
68         }
69
70         SMB2_CHECK_PACKET_RECV(req, 0x08, true);
71
72         status = smb2_pull_o16s32_blob(&req->in, mem_ctx, req->in.body+0x02, &blob);
73         if (!NT_STATUS_IS_OK(status)) {
74                 return status;
75         }
76
77         io->out.changes = NULL;
78         io->out.num_changes = 0;
79
80         /* count them */
81         for (ofs=0; blob.length - ofs > 12; ) {
82                 uint32_t next = IVAL(blob.data, ofs);
83                 io->out.num_changes++;
84                 if (next == 0 || (ofs + next) >= blob.length) break;
85                 ofs += next;
86         }
87
88         /* allocate array */
89         io->out.changes = talloc_array(mem_ctx, struct notify_changes, io->out.num_changes);
90         if (!io->out.changes) {
91                 return NT_STATUS_NO_MEMORY;
92         }
93
94         for (i=ofs=0; i<io->out.num_changes; i++) {
95                 io->out.changes[i].action = IVAL(blob.data, ofs+4);
96                 smbcli_blob_pull_string(NULL, mem_ctx, &blob,
97                                         &io->out.changes[i].name,
98                                         ofs+8, ofs+12, STR_UNICODE);
99                 ofs += IVAL(blob.data, ofs);
100         }
101
102         return smb2_request_destroy(req);
103 }
104
105 /*
106   sync notify request
107 */
108 NTSTATUS smb2_notify(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
109                      struct smb2_notify *io)
110 {
111         struct smb2_request *req = smb2_notify_send(tree, io);
112         return smb2_notify_recv(req, mem_ctx, io);
113 }