]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Use cli_smb2_qpathinfo_basic() in cli_getatr()
authorVolker Lendecke <vl@samba.org>
Fri, 18 Aug 2023 14:15:19 +0000 (16:15 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 22 Aug 2023 16:45:31 +0000 (16:45 +0000)
cli_smb2_qpathinfo_basic() uses the smb_create_returns and avoids a
round-trip.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clifile.c

index 76eeaff42b3df7ec6a9673d2ecb6844aca7d2110..a7d51b6ae615d99f540e3fe2feb2b91c4e0cedfe 100644 (file)
@@ -2389,68 +2389,6 @@ NTSTATUS cli_smb2_qpathinfo_recv(struct tevent_req *req,
        return NT_STATUS_OK;
 }
 
-/***************************************************************
- Wrapper that allows SMB2 to get pathname attributes.
- Synchronous only.
-***************************************************************/
-
-NTSTATUS cli_smb2_getatr(struct cli_state *cli,
-                       const char *name,
-                       uint32_t *pattr,
-                       off_t *size,
-                       time_t *write_time)
-{
-       NTSTATUS status;
-       uint16_t fnum = 0xffff;
-       struct timespec write_time_ts;
-       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_qfileinfo_basic(
-               cli,
-               fnum,
-               pattr,
-               size,
-               NULL,           /* create_time */
-               NULL,           /* access_time */
-               &write_time_ts,
-               NULL,           /* change_time */
-               NULL);          /* ino */
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-       if (write_time != NULL) {
-               *write_time = write_time_ts.tv_sec;
-       }
-
-  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.
index ed8da5b9c33d18ed8ee547c639aed94e6602f354..0eb2a026527653023095a2cb4f622bb7c42993dd 100644 (file)
@@ -170,11 +170,6 @@ NTSTATUS cli_smb2_query_info_fnum(
        uint32_t in_flags,
        TALLOC_CTX *mem_ctx,
        DATA_BLOB *outbuf);
-NTSTATUS cli_smb2_getatr(struct cli_state *cli,
-                       const char *name,
-                       uint32_t *pattr,
-                       off_t *size,
-                       time_t *write_time);
 NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli,
                        const char *name,
                        uint8_t in_info_type,
index 483e453d854fa3cf8d16d3c666f8288ade319177..5f8f27e65f776532ee59fc043e727e962932af97 100644 (file)
@@ -4582,11 +4582,26 @@ NTSTATUS cli_getatr(struct cli_state *cli,
        NTSTATUS status = NT_STATUS_OK;
 
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               return cli_smb2_getatr(cli,
-                                       fname,
-                                       pattr,
-                                       size,
-                                       write_time);
+               struct stat_ex sbuf = {
+                       .st_ex_nlink = 0,
+               };
+               uint32_t attr;
+
+               status = cli_smb2_qpathinfo_basic(cli, fname, &sbuf, &attr);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               if (pattr != NULL) {
+                       *pattr = attr;
+               }
+               if (size != NULL) {
+                       *size = sbuf.st_ex_size;
+               }
+               if (write_time != NULL) {
+                       *write_time = sbuf.st_ex_mtime.tv_sec;
+               }
+               return NT_STATUS_OK;
        }
 
        frame = talloc_stackframe();