From: Volker Lendecke Date: Fri, 18 Aug 2023 13:47:20 +0000 (+0200) Subject: libsmb: Use cli_smb2_qpathinfo() for streams X-Git-Tag: tevent-0.16.0~863 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50edb0266f92cf2f00bbd9f242bb7ee1fd6d9024;p=thirdparty%2Fsamba.git libsmb: Use cli_smb2_qpathinfo() for streams Remove sync cli_smb2_qpathinfo_streams() wrapper. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index cc70af1a876..14fa8ae2708 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -2611,80 +2611,6 @@ NTSTATUS cli_smb2_qpathinfo2_recv(struct tevent_req *req, return NT_STATUS_OK; } -/*************************************************************** - Wrapper that allows SMB2 to query pathname streams. - Synchronous only. -***************************************************************/ - -NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli, - const char *name, - TALLOC_CTX *mem_ctx, - unsigned int *pnum_streams, - struct stream_struct **pstreams) -{ - NTSTATUS status; - uint16_t fnum = 0xffff; - DATA_BLOB outbuf = data_blob_null; - TALLOC_CTX *frame = talloc_stackframe(); - - 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; - } - - status = get_fnum_from_path(cli, - name, - FILE_READ_ATTRIBUTES, - &fnum); - - if (!NT_STATUS_IS_OK(status)) { - goto fail; - } - - /* getinfo on the handle with info_type SMB2_GETINFO_FILE (1), - level 22 (SMB2_FILE_STREAM_INFORMATION). */ - - status = cli_smb2_query_info_fnum( - cli, - fnum, - 1, /* in_info_type */ - (SMB_FILE_STREAM_INFORMATION - 1000), /* in_file_info_class */ - 0xFFFF, /* in_max_output_length */ - NULL, /* in_input_buffer */ - 0, /* in_additional_info */ - 0, /* in_flags */ - frame, - &outbuf); - - if (!NT_STATUS_IS_OK(status)) { - goto fail; - } - - /* Parse the reply. */ - if (!parse_streams_blob(mem_ctx, - outbuf.data, - outbuf.length, - pnum_streams, - pstreams)) { - status = NT_STATUS_INVALID_NETWORK_RESPONSE; - goto fail; - } - - fail: - - if (fnum != 0xffff) { - cli_smb2_close_fnum(cli, fnum); - } - - cli->raw_status = status; - - TALLOC_FREE(frame); - return status; -} - /*************************************************************** Wrapper that allows SMB2 to set SMB_FILE_BASIC_INFORMATION on a pathname. diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h index 60ed108334d..1068165dcdb 100644 --- a/source3/libsmb/cli_smb2_fnum.h +++ b/source3/libsmb/cli_smb2_fnum.h @@ -187,11 +187,6 @@ NTSTATUS cli_smb2_qpathinfo2_recv(struct tevent_req *req, off_t *size, uint32_t *attr, SMB_INO_T *ino); -NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli, - const char *name, - TALLOC_CTX *mem_ctx, - unsigned int *pnum_streams, - struct stream_struct **pstreams); NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli, const char *name, uint8_t in_info_type, diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index 25edd217715..ebe97d8c0e5 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -1099,6 +1099,7 @@ struct cli_qpathinfo_streams_state { }; static void cli_qpathinfo_streams_done(struct tevent_req *subreq); +static void cli_qpathinfo_streams_done2(struct tevent_req *subreq); struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -1113,6 +1114,22 @@ struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx, if (req == NULL) { return NULL; } + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + subreq = cli_smb2_qpathinfo_send(state, + ev, + cli, + fname, + FSCC_FILE_STREAM_INFORMATION, + 0, + CLI_BUFFER_SIZE); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, + cli_qpathinfo_streams_done2, + req); + return req; + } subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_FILE_STREAM_INFORMATION, 0, CLI_BUFFER_SIZE); @@ -1133,12 +1150,22 @@ static void cli_qpathinfo_streams_done(struct tevent_req *subreq) status = cli_qpathinfo_recv(subreq, state, &state->data, &state->num_data); - TALLOC_FREE(subreq); - if (!NT_STATUS_IS_OK(status)) { - tevent_req_nterror(req, status); - return; - } - tevent_req_done(req); + tevent_req_simple_finish_ntstatus(subreq, status); +} + +static void cli_qpathinfo_streams_done2(struct tevent_req *subreq) +{ + struct tevent_req *req = + tevent_req_callback_data(subreq, struct tevent_req); + struct cli_qpathinfo_streams_state *state = + tevent_req_data(req, struct cli_qpathinfo_streams_state); + NTSTATUS status; + + status = cli_smb2_qpathinfo_recv(subreq, + state, + &state->data, + &state->num_data); + tevent_req_simple_finish_ntstatus(subreq, status); } NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req, @@ -1170,14 +1197,6 @@ NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname, struct tevent_req *req; NTSTATUS status = NT_STATUS_NO_MEMORY; - if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { - return cli_smb2_qpathinfo_streams(cli, - fname, - mem_ctx, - pnum_streams, - pstreams); - } - frame = talloc_stackframe(); if (smbXcli_conn_has_async_calls(cli->conn)) {