libsmb: Use cli_smb2_qpathinfo_send() for SMB_QUERY_FILE_ALT_NAME_INFO
authorVolker Lendecke <vl@samba.org>
Fri, 30 Jun 2023 21:21:13 +0000 (23:21 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 12 Oct 2023 17:51:44 +0000 (17:51 +0000)
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

source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clifile.c
source3/libsmb/clirap.c

index dc09e9396d135cc4e52b672402186412278070c0..2092fc550480d611f3c219fd43fba0adc56d9df1 100644 (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;
index 7f3d7c2be1bf0bde9064e7237135aaee819a9a7b..cde6a3ac333582c48cbda5419d58e0d3aedcbaf3 100644 (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,
index 6f1625ce1902e9a460198533757906fdb506bc1b..5dc11f69458d2bd27e3eef259fe518788b4df886 100644 (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)
 {
index a4536bfb0bcd148374140f0e719a057614219a9b..21ee346e0aa294fc405604df72947ad494005595 100644 (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);