s3-libsmb: Support getting fs attributes via SMB2
authorUri Simchoni <uri@samba.org>
Tue, 20 Sep 2016 11:32:06 +0000 (14:32 +0300)
committerJeremy Allison <jra@samba.org>
Tue, 4 Oct 2016 00:00:23 +0000 (02:00 +0200)
Add a wrapper function arounf GET_INFO to obtain
file system attributes, and plumb it in.

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clifsinfo.c

index ac7209014626ecb38833e3b9bfd5df03d84bbf0c..a998d6fedecac53f8e02d507ab46efd7b60c220f 100644 (file)
@@ -1755,6 +1755,83 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli, const char *path,
        return status;
 }
 
+/***************************************************************
+ Wrapper that allows SMB2 to query file system attributes.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
+{
+       NTSTATUS status;
+       uint16_t fnum = 0xffff;
+       DATA_BLOB outbuf = data_blob_null;
+       struct smb2_hnd *ph = 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;
+       }
+
+       if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+
+       /* First open the top level directory. */
+       status =
+           cli_smb2_create_fnum(cli, "", 0,               /* create_flags */
+                                FILE_READ_ATTRIBUTES,     /* desired_access */
+                                FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
+                                FILE_SHARE_READ | FILE_SHARE_WRITE |
+                                    FILE_SHARE_DELETE, /* share_access */
+                                FILE_OPEN,             /* create_disposition */
+                                FILE_DIRECTORY_FILE,   /* create_options */
+                                &fnum,
+                                NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = map_fnum_to_smb2_handle(cli, fnum, &ph);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = smb2cli_query_info(cli->conn, cli->timeout, cli->smb2.session,
+                                   cli->smb2.tcon, 2, /* in_info_type */
+                                   5,                 /* in_file_info_class */
+                                   0xFFFF, /* in_max_output_length */
+                                   NULL,   /* in_input_buffer */
+                                   0,      /* in_additional_info */
+                                   0,      /* in_flags */
+                                   ph->fid_persistent, ph->fid_volatile, frame,
+                                   &outbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       if (outbuf.length < 12) {
+               status = NT_STATUS_INVALID_NETWORK_RESPONSE;
+               goto fail;
+       }
+
+       *fs_attr = IVAL(outbuf.data, 0);
+
+fail:
+
+       if (fnum != 0xffff) {
+               cli_smb2_close_fnum(cli, fnum);
+       }
+
+       TALLOC_FREE(frame);
+       return status;
+}
+
 /***************************************************************
  Wrapper that allows SMB2 to query a security descriptor.
  Synchronous only.
index 0436c68da8bd24b87cc633d25d3931396fb16c74..2df54a30b407a5dedcb7ecf89b5fa41e9c0e8a67 100644 (file)
@@ -121,6 +121,7 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli,
                        uint64_t *bsize,
                        uint64_t *total,
                        uint64_t *avail);
+NTSTATUS cli_smb2_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr);
 NTSTATUS cli_smb2_query_security_descriptor(struct cli_state *cli,
                        uint16_t fnum,
                        uint32_t sec_info,
index ddc9efd61b3743c358a2079523d4e8a7823f0c33..31a2c0222b2d89dd8e446d7c13c8d2af3b85ea4b 100644 (file)
@@ -337,6 +337,10 @@ NTSTATUS cli_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
        struct tevent_req *req;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               return cli_smb2_get_fs_attr_info(cli, fs_attr);
+       }
+
        if (smbXcli_conn_has_async_calls(cli->conn)) {
                return NT_STATUS_INVALID_PARAMETER;
        }