From 4b9b7f70f25b2260334664393e788e8a74da9252 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 30 Jun 2023 23:21:13 +0200 Subject: [PATCH] libsmb: Use cli_smb2_qpathinfo_send() for SMB_QUERY_FILE_ALT_NAME_INFO MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Remove one sync-only wrapper Signed-off-by: Volker Lendecke Reviewed-by: Ralph Böhme Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Oct 12 17:51:44 UTC 2023 on atb-devel-224 --- source3/libsmb/cli_smb2_fnum.c | 95 ------------------------------------------ source3/libsmb/cli_smb2_fnum.h | 3 -- source3/libsmb/clifile.c | 46 ++++++++++++++++++++ source3/libsmb/clirap.c | 6 --- 4 files changed, 46 insertions(+), 104 deletions(-) diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index dc09e9396d1..2092fc55048 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -2183,101 +2183,6 @@ static NTSTATUS get_fnum_from_path(struct cli_state *cli, return status; } -/*************************************************************** - Wrapper that allows SMB2 to query a path info (ALTNAME level). - Synchronous only. -***************************************************************/ - -NTSTATUS cli_smb2_qpathinfo_alt_name(struct cli_state *cli, - const char *name, - fstring alt_name) -{ - NTSTATUS status; - DATA_BLOB outbuf = data_blob_null; - uint16_t fnum = 0xffff; - uint32_t altnamelen = 0; - 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; - } - - status = cli_smb2_query_info_fnum( - cli, - fnum, - 1, /* in_info_type */ - (SMB_FILE_ALTERNATE_NAME_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 (outbuf.length < 4) { - status = NT_STATUS_INVALID_NETWORK_RESPONSE; - goto fail; - } - - altnamelen = IVAL(outbuf.data, 0); - if (altnamelen > outbuf.length - 4) { - status = NT_STATUS_INVALID_NETWORK_RESPONSE; - goto fail; - } - - if (altnamelen > 0) { - size_t ret = 0; - char *short_name = NULL; - ret = pull_string_talloc(frame, - outbuf.data, - FLAGS2_UNICODE_STRINGS, - &short_name, - outbuf.data + 4, - altnamelen, - STR_UNICODE); - if (ret == (size_t)-1) { - /* Bad conversion. */ - status = NT_STATUS_INVALID_NETWORK_RESPONSE; - goto fail; - } - - fstrcpy(alt_name, short_name); - } else { - alt_name[0] = '\0'; - } - - status = NT_STATUS_OK; - - fail: - - if (fnum != 0xffff) { - cli_smb2_close_fnum(cli, fnum); - } - - cli->raw_status = status; - - TALLOC_FREE(frame); - return status; -} - struct cli_smb2_qpathinfo_state { struct tevent_context *ev; struct cli_state *cli; diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h index 7f3d7c2be1b..cde6a3ac333 100644 --- a/source3/libsmb/cli_smb2_fnum.h +++ b/source3/libsmb/cli_smb2_fnum.h @@ -116,9 +116,6 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli, const char *name, SMB_STRUCT_STAT *sbuf, uint32_t *attributes); -NTSTATUS cli_smb2_qpathinfo_alt_name(struct cli_state *cli, - const char *name, - fstring alt_name); struct tevent_req *cli_smb2_qpathinfo_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli, diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 6f1625ce190..5dc11f69458 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -6759,6 +6759,7 @@ struct cli_qpathinfo_state { }; static void cli_qpathinfo_done(struct tevent_req *subreq); +static void cli_qpathinfo_done2(struct tevent_req *subreq); struct tevent_req *cli_qpathinfo_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -6775,6 +6776,33 @@ struct tevent_req *cli_qpathinfo_send(TALLOC_CTX *mem_ctx, if (req == NULL) { return NULL; } + + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + uint16_t smb2_level = 0; + + switch (level) { + case SMB_QUERY_FILE_ALT_NAME_INFO: + smb2_level = FSCC_FILE_ALTERNATE_NAME_INFORMATION; + break; + default: + tevent_req_nterror(req, NT_STATUS_INVALID_LEVEL); + return tevent_req_post(req, ev); + } + + subreq = cli_smb2_qpathinfo_send(state, + ev, + cli, + fname, + smb2_level, + min_rdata, + max_rdata); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_qpathinfo_done2, req); + return req; + } + state->min_rdata = min_rdata; SSVAL(state->setup, 0, TRANSACT2_QPATHINFO); @@ -6849,6 +6877,24 @@ static void cli_qpathinfo_done(struct tevent_req *subreq) tevent_req_done(req); } +static void cli_qpathinfo_done2(struct tevent_req *subreq) +{ + struct tevent_req *req = + tevent_req_callback_data(subreq, struct tevent_req); + struct cli_qpathinfo_state *state = + tevent_req_data(req, struct cli_qpathinfo_state); + NTSTATUS status; + + status = cli_smb2_qpathinfo_recv(subreq, + state, + &state->rdata, + &state->num_rdata); + if (tevent_req_nterror(req, status)) { + return; + } + tevent_req_done(req); +} + NTSTATUS cli_qpathinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, uint8_t **rdata, uint32_t *num_rdata) { diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index a4536bfb0bc..21ee346e0aa 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -1693,12 +1693,6 @@ NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstrin size_t converted_size = 0; NTSTATUS status; - if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { - return cli_smb2_qpathinfo_alt_name(cli, - fname, - alt_name); - } - status = cli_qpathinfo(talloc_tos(), cli, fname, SMB_QUERY_FILE_ALT_NAME_INFO, 4, CLI_BUFFER_SIZE, &rdata, &num_rdata); -- 2.11.4.GIT