c40e03
From b428a334105a28f55b784d284e865b3c42f1f96d Mon Sep 17 00:00:00 2001
c40e03
From: Jeremy Allison <jra@samba.org>
c40e03
Date: Tue, 14 Nov 2017 13:52:03 -0800
c40e03
Subject: [PATCH] s3: libsmb: smbc_statvfs is missing the supporting SMB2
c40e03
 calls.
c40e03
c40e03
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13138
c40e03
c40e03
Signed-off-by: Jeremy Allison <jra@samba.org>
c40e03
Reviewed-by: Andreas Schneider <asn@samba.org>
c40e03
(cherry picked from commit eefc7a27155b70d027b1193187dd435267d863ea)
c40e03
---
c40e03
 source3/libsmb/cli_smb2_fnum.c | 97 ++++++++++++++++++++++++++++++++++++++++++
c40e03
 source3/libsmb/cli_smb2_fnum.h |  6 +++
c40e03
 source3/libsmb/clifsinfo.c     |  9 ++++
c40e03
 3 files changed, 112 insertions(+)
c40e03
c40e03
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
c40e03
index a478c41f068..89cb1f479d5 100644
c40e03
--- a/source3/libsmb/cli_smb2_fnum.c
c40e03
+++ b/source3/libsmb/cli_smb2_fnum.c
c40e03
@@ -1992,6 +1992,103 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli, const char *path,
c40e03
 	return status;
c40e03
 }
c40e03
 
c40e03
+/***************************************************************
c40e03
+ Wrapper that allows SMB2 to query file system sizes.
c40e03
+ Synchronous only.
c40e03
+***************************************************************/
c40e03
+
c40e03
+NTSTATUS cli_smb2_get_fs_full_size_info(struct cli_state *cli,
c40e03
+				uint64_t *total_allocation_units,
c40e03
+				uint64_t *caller_allocation_units,
c40e03
+				uint64_t *actual_allocation_units,
c40e03
+				uint64_t *sectors_per_allocation_unit,
c40e03
+				uint64_t *bytes_per_sector)
c40e03
+{
c40e03
+	NTSTATUS status;
c40e03
+	uint16_t fnum = 0xffff;
c40e03
+	DATA_BLOB outbuf = data_blob_null;
c40e03
+	struct smb2_hnd *ph = NULL;
c40e03
+	TALLOC_CTX *frame = talloc_stackframe();
c40e03
+
c40e03
+	if (smbXcli_conn_has_async_calls(cli->conn)) {
c40e03
+		/*
c40e03
+		 * Can't use sync call while an async call is in flight
c40e03
+		 */
c40e03
+		status = NT_STATUS_INVALID_PARAMETER;
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
c40e03
+		status = NT_STATUS_INVALID_PARAMETER;
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	/* First open the top level directory. */
c40e03
+	status =
c40e03
+	    cli_smb2_create_fnum(cli, "", 0,		   /* create_flags */
c40e03
+				 FILE_READ_ATTRIBUTES,     /* desired_access */
c40e03
+				 FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
c40e03
+				 FILE_SHARE_READ | FILE_SHARE_WRITE |
c40e03
+				     FILE_SHARE_DELETE, /* share_access */
c40e03
+				 FILE_OPEN,		/* create_disposition */
c40e03
+				 FILE_DIRECTORY_FILE,   /* create_options */
c40e03
+				 &fnum,
c40e03
+				 NULL);
c40e03
+
c40e03
+	if (!NT_STATUS_IS_OK(status)) {
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	status = map_fnum_to_smb2_handle(cli, fnum, &ph);
c40e03
+	if (!NT_STATUS_IS_OK(status)) {
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	/* getinfo on the returned handle with info_type SMB2_GETINFO_FS (2),
c40e03
+	   level 7 (SMB_FS_FULL_SIZE_INFORMATION). */
c40e03
+
c40e03
+	status = smb2cli_query_info(cli->conn,
c40e03
+				cli->timeout,
c40e03
+				cli->smb2.session,
c40e03
+				cli->smb2.tcon,
c40e03
+				SMB2_GETINFO_FS, /* in_info_type */
c40e03
+				/* in_file_info_class */
c40e03
+				SMB_FS_FULL_SIZE_INFORMATION - 1000,
c40e03
+				0xFFFF, /* in_max_output_length */
c40e03
+				NULL, /* in_input_buffer */
c40e03
+				0, /* in_additional_info */
c40e03
+				0, /* in_flags */
c40e03
+				ph->fid_persistent,
c40e03
+				ph->fid_volatile,
c40e03
+				frame,
c40e03
+				&outbuf);
c40e03
+	if (!NT_STATUS_IS_OK(status)) {
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	if (outbuf.length < 32) {
c40e03
+		status = NT_STATUS_INVALID_NETWORK_RESPONSE;
c40e03
+		goto fail;
c40e03
+	}
c40e03
+
c40e03
+	*total_allocation_units = BIG_UINT(outbuf.data, 0);
c40e03
+	*caller_allocation_units = BIG_UINT(outbuf.data, 8);
c40e03
+	*actual_allocation_units = BIG_UINT(outbuf.data, 16);
c40e03
+	*sectors_per_allocation_unit = (uint64_t)IVAL(outbuf.data, 24);
c40e03
+	*bytes_per_sector = (uint64_t)IVAL(outbuf.data, 28);
c40e03
+
c40e03
+fail:
c40e03
+
c40e03
+	if (fnum != 0xffff) {
c40e03
+		cli_smb2_close_fnum(cli, fnum);
c40e03
+	}
c40e03
+
c40e03
+	cli->raw_status = status;
c40e03
+
c40e03
+	TALLOC_FREE(frame);
c40e03
+	return status;
c40e03
+}
c40e03
+
c40e03
 /***************************************************************
c40e03
  Wrapper that allows SMB2 to query file system attributes.
c40e03
  Synchronous only.
c40e03
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
c40e03
index 9a709e85d96..c9325b66902 100644
c40e03
--- a/source3/libsmb/cli_smb2_fnum.h
c40e03
+++ b/source3/libsmb/cli_smb2_fnum.h
c40e03
@@ -136,6 +136,12 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli,
c40e03
 			uint64_t *total,
c40e03
 			uint64_t *avail);
c40e03
 NTSTATUS cli_smb2_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr);
c40e03
+NTSTATUS cli_smb2_get_fs_full_size_info(struct cli_state *cli,
c40e03
+			uint64_t *total_allocation_units,
c40e03
+			uint64_t *caller_allocation_units,
c40e03
+			uint64_t *actual_allocation_units,
c40e03
+			uint64_t *sectors_per_allocation_unit,
c40e03
+			uint64_t *bytes_per_sector);
c40e03
 NTSTATUS cli_smb2_query_security_descriptor(struct cli_state *cli,
c40e03
 			uint16_t fnum,
c40e03
 			uint32_t sec_info,
c40e03
diff --git a/source3/libsmb/clifsinfo.c b/source3/libsmb/clifsinfo.c
c40e03
index 119b1216fb2..46236390022 100644
c40e03
--- a/source3/libsmb/clifsinfo.c
c40e03
+++ b/source3/libsmb/clifsinfo.c
c40e03
@@ -439,6 +439,15 @@ NTSTATUS cli_get_fs_full_size_info(struct cli_state *cli,
c40e03
 	uint32_t rdata_count;
c40e03
 	NTSTATUS status;
c40e03
 
c40e03
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
c40e03
+		return cli_smb2_get_fs_full_size_info(cli,
c40e03
+						total_allocation_units,
c40e03
+						caller_allocation_units,
c40e03
+						actual_allocation_units,
c40e03
+						sectors_per_allocation_unit,
c40e03
+						bytes_per_sector);
c40e03
+	}
c40e03
+
c40e03
 	SSVAL(setup, 0, TRANSACT2_QFSINFO);
c40e03
 	SSVAL(param, 0, SMB_FS_FULL_SIZE_INFORMATION);
c40e03
 
c40e03
-- 
c40e03
2.15.0.448.gf294e3d99a-goog
c40e03