cliquota: support getting fs quota by SMB2
authorUri Simchoni <uri@samba.org>
Tue, 20 Sep 2016 03:46:28 +0000 (06:46 +0300)
committerJeremy Allison <jra@samba.org>
Tue, 4 Oct 2016 00:00:23 +0000 (02:00 +0200)
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/cliquota.c

index 3f5629c130e8846f678638604ce61bf855e00127..1be93812df9991905185e48e255b32e6551dc339 100644 (file)
@@ -2506,6 +2506,59 @@ cleanup:
        return status;
 }
 
+/***************************************************************
+ Wrapper that allows SMB2 to get file system quota.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_get_fs_quota_info(struct cli_state *cli,
+                                   int quota_fnum,
+                                   SMB_NTQUOTA_STRUCT *pqt)
+{
+       NTSTATUS status;
+       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 cleanup;
+       }
+
+       if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto cleanup;
+       }
+
+       status = map_fnum_to_smb2_handle(cli, quota_fnum, &ph);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto cleanup;
+       }
+
+       status = smb2cli_query_info(
+           cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
+           2,                               /* in_info_type */
+           SMB_FS_QUOTA_INFORMATION - 1000, /* 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 cleanup;
+       }
+
+       status = parse_fs_quota_buffer(outbuf.data, outbuf.length, pqt);
+
+cleanup:
+       TALLOC_FREE(frame);
+       return status;
+}
+
 struct cli_smb2_read_state {
        struct tevent_context *ev;
        struct cli_state *cli;
index b39bfed3a74d64cceb4ee757e8a3d3354f19d1d8..7fd97ec0934579f244718c1c23db28344bb2cd6a 100644 (file)
@@ -157,6 +157,9 @@ NTSTATUS cli_smb2_list_user_quota_step(struct cli_state *cli,
                                       int quota_fnum,
                                       SMB_NTQUOTA_LIST **pqt_list,
                                       bool first);
+NTSTATUS cli_smb2_get_fs_quota_info(struct cli_state *cli,
+                                   int quota_fnum,
+                                   SMB_NTQUOTA_STRUCT *pqt);
 struct tevent_req *cli_smb2_read_send(TALLOC_CTX *mem_ctx,
                                struct tevent_context *ev,
                                struct cli_state *cli,
index cec378f84189ccfd48ba8d9f0c0d93d614c3ee76..9a80eef336c8c14e05b3faf55ec55f0547b7605f 100644 (file)
@@ -415,6 +415,10 @@ NTSTATUS cli_get_fs_quota_info(struct cli_state *cli, int quota_fnum,
                smb_panic("cli_get_fs_quota_info() called with NULL Pointer!");
        }
 
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               return cli_smb2_get_fs_quota_info(cli, quota_fnum, pqt);
+       }
+
        SSVAL(setup + 0, 0, TRANSACT2_QFSINFO);
 
        SSVAL(param,0,SMB_FS_QUOTA_INFORMATION);