return status;
}
-/***************************************************************
- Wrapper that allows SMB2 to list a directory.
-***************************************************************/
-
-struct cli_smb2_list_sync_state {
- const char *pathname;
- uint32_t attribute;
- NTSTATUS (*fn)(struct file_info *finfo,
- const char *mask,
- void *private_data);
- void *private_data;
- NTSTATUS status;
- bool processed_file;
-};
-
-static void cli_smb2_list_sync_cb(struct tevent_req *subreq)
-{
- struct cli_smb2_list_sync_state *state =
- tevent_req_callback_data_void(subreq);
- struct file_info *finfo = NULL;
- bool ok;
-
- state->status = cli_smb2_list_recv(subreq, talloc_tos(), &finfo);
- /* No TALLOC_FREE(subreq), we get here more than once */
-
- if (!NT_STATUS_IS_OK(state->status)) {
- return;
- }
-
- ok = dir_check_ftype(finfo->attr, state->attribute);
- if (ok) {
- /*
- * Only process if attributes match. SMB1 servers do
- * the filtering, so with SMB2 we need to emulate it
- * in the client.
- *
- * https://bugzilla.samba.org/show_bug.cgi?id=10260
- */
- state->status = state->fn(
- finfo, state->pathname, state->private_data);
-
- state->processed_file = true;
- }
-
- TALLOC_FREE(finfo);
-}
-
-NTSTATUS cli_smb2_list(struct cli_state *cli,
- const char *pathname,
- uint32_t attribute,
- NTSTATUS (*fn)(struct file_info *finfo,
- const char *mask,
- void *private_data),
- void *private_data)
-{
- TALLOC_CTX *frame = talloc_stackframe();
- struct cli_smb2_list_sync_state state = {
- .pathname = pathname,
- .attribute = attribute,
- .fn = fn,
- .private_data = private_data,
- };
- struct tevent_context *ev = NULL;
- struct tevent_req *req = NULL;
- NTSTATUS status = NT_STATUS_NO_MEMORY;
-
- if (smbXcli_conn_has_async_calls(cli->conn)) {
- /*
- * Can't use sync call while an async call is in flight
- */
- status = NT_STATUS_INVALID_PARAMETER;
- goto fail;
- }
-
- ev = samba_tevent_context_init(frame);
- if (ev == NULL) {
- goto fail;
- }
- req = cli_smb2_list_send(frame, ev, cli, pathname);
- if (req == NULL) {
- goto fail;
- }
- tevent_req_set_callback(req, cli_smb2_list_sync_cb, &state);
-
- if (!tevent_req_poll_ntstatus(req, ev, &status)) {
- goto fail;
- }
-
- status = state.status;
-
- if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_FILES)) {
- if (state.processed_file) {
- status = NT_STATUS_OK;
- } else {
- status = NT_STATUS_NO_SUCH_FILE;
- }
- }
-
-fail:
- TALLOC_FREE(req);
- TALLOC_FREE(ev);
- TALLOC_FREE(frame);
- return status;
-}
-
/***************************************************************
Wrapper that allows SMB2 to query a path info (basic level).
Synchronous only.