1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

libsmb: Use cli_smb2_qpathinfo_send() for SMB_QUERY_FILE_ALT_NAME_INFO

Remove one sync-only wrapper

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Oct 12 17:51:44 UTC 2023 on atb-devel-224
This commit is contained in:
Volker Lendecke 2023-06-30 23:21:13 +02:00 committed by Jeremy Allison
parent 051492c178
commit 4b9b7f70f2
4 changed files with 46 additions and 104 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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)
{

View File

@ -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);