2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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_find_send(struct smb2_tree
*tree
, struct smb2_find
*io
)
33 struct smb2_request
*req
;
36 req
= smb2_request_init_tree(tree
, SMB2_OP_FIND
, 0x20, true, 0);
37 if (req
== NULL
) return NULL
;
39 SCVAL(req
->out
.body
, 0x02, io
->in
.level
);
40 SCVAL(req
->out
.body
, 0x03, io
->in
.continue_flags
);
41 SIVAL(req
->out
.body
, 0x04, io
->in
.file_index
);
42 smb2_push_handle(req
->out
.body
+0x08, &io
->in
.file
.handle
);
44 status
= smb2_push_o16s16_string(&req
->out
, 0x18, io
->in
.pattern
);
45 if (!NT_STATUS_IS_OK(status
)) {
50 SIVAL(req
->out
.body
, 0x1C, io
->in
.max_response_size
);
52 smb2_transport_send(req
);
61 NTSTATUS
smb2_find_recv(struct smb2_request
*req
, TALLOC_CTX
*mem_ctx
,
66 if (!smb2_request_receive(req
) ||
67 smb2_request_is_error(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
,
74 req
->in
.body
+0x02, &io
->out
.blob
);
75 if (!NT_STATUS_IS_OK(status
)) {
79 return smb2_request_destroy(req
);
85 NTSTATUS
smb2_find(struct smb2_tree
*tree
, TALLOC_CTX
*mem_ctx
,
88 struct smb2_request
*req
= smb2_find_send(tree
, io
);
89 return smb2_find_recv(req
, mem_ctx
, io
);
94 a varient of smb2_find_recv that parses the resulting blob into
95 smb_search_data structures
97 NTSTATUS
smb2_find_level_recv(struct smb2_request
*req
, TALLOC_CTX
*mem_ctx
,
98 uint8_t level
, unsigned int *count
,
99 union smb_search_data
**io
)
104 enum smb_search_data_level smb_level
;
105 unsigned int next_ofs
=0;
108 case SMB2_FIND_DIRECTORY_INFO
:
109 smb_level
= RAW_SEARCH_DATA_DIRECTORY_INFO
;
111 case SMB2_FIND_FULL_DIRECTORY_INFO
:
112 smb_level
= RAW_SEARCH_DATA_FULL_DIRECTORY_INFO
;
114 case SMB2_FIND_BOTH_DIRECTORY_INFO
:
115 smb_level
= RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO
;
117 case SMB2_FIND_NAME_INFO
:
118 smb_level
= RAW_SEARCH_DATA_NAME_INFO
;
120 case SMB2_FIND_ID_FULL_DIRECTORY_INFO
:
121 smb_level
= RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO
;
123 case SMB2_FIND_ID_BOTH_DIRECTORY_INFO
:
124 smb_level
= RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO
;
127 return NT_STATUS_INVALID_INFO_CLASS
;
130 status
= smb2_find_recv(req
, mem_ctx
, &f
);
131 NT_STATUS_NOT_OK_RETURN(status
);
138 union smb_search_data
*io2
;
140 io2
= talloc_realloc(mem_ctx
, *io
, union smb_search_data
, (*count
)+1);
142 data_blob_free(&f
.out
.blob
);
144 return NT_STATUS_NO_MEMORY
;
148 status
= smb_raw_search_common(*io
, smb_level
, &b
, (*io
) + (*count
),
149 &next_ofs
, STR_UNICODE
);
151 if (NT_STATUS_IS_OK(status
) &&
152 next_ofs
>= b
.length
) {
153 data_blob_free(&f
.out
.blob
);
155 return NT_STATUS_INFO_LENGTH_MISMATCH
;
160 b
= data_blob_const(b
.data
+next_ofs
, b
.length
- next_ofs
);
161 } while (NT_STATUS_IS_OK(status
) && next_ofs
!= 0);
163 data_blob_free(&f
.out
.blob
);
169 a varient of smb2_find that parses the resulting blob into
170 smb_search_data structures
172 NTSTATUS
smb2_find_level(struct smb2_tree
*tree
, TALLOC_CTX
*mem_ctx
,
174 unsigned int *count
, union smb_search_data
**io
)
176 struct smb2_request
*req
;
178 req
= smb2_find_send(tree
, f
);
179 return smb2_find_level_recv(req
, mem_ctx
, f
->in
.level
, count
, io
);