From 0ed8b49fafb73f9ebe1188af194f522ccf848f6c Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Tue, 20 Sep 2016 06:45:03 +0300 Subject: [PATCH] cliquota: factor out fs quota parsing This code will be reused by SMB2 code. Signed-off-by: Uri Simchoni Reviewed-by: Jeremy Allison --- source3/libsmb/cliquota.c | 51 ++++++++++++++++++++++++++------------- source3/libsmb/proto.h | 3 +++ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/source3/libsmb/cliquota.c b/source3/libsmb/cliquota.c index ff7e6e6c89a..cec378f8418 100644 --- a/source3/libsmb/cliquota.c +++ b/source3/libsmb/cliquota.c @@ -168,6 +168,39 @@ NTSTATUS parse_user_quota_list(const uint8_t *curdata, return status; } +NTSTATUS parse_fs_quota_buffer(const uint8_t *rdata, + unsigned int rdata_count, + SMB_NTQUOTA_STRUCT *pqt) +{ + SMB_NTQUOTA_STRUCT qt; + + ZERO_STRUCT(qt); + + if (rdata_count < 48) { + /* minimum length is not enforced by SMB2 client. + */ + DEBUG(1, ("small returned fs quota buffer\n")); + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + /* unknown_1 24 NULL bytes in pdata*/ + + /* the soft quotas 8 bytes (uint64_t)*/ + qt.softlim = BVAL(rdata, 24); + + /* the hard quotas 8 bytes (uint64_t)*/ + qt.hardlim = BVAL(rdata, 32); + + /* quota_flags 2 bytes **/ + qt.qflags = SVAL(rdata, 40); + + qt.qtype = SMB_USER_FS_QUOTA_TYPE; + + *pqt = qt; + + return NT_STATUS_OK; +} + NTSTATUS cli_get_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_STRUCT *pqt) { @@ -376,11 +409,8 @@ NTSTATUS cli_get_fs_quota_info(struct cli_state *cli, int quota_fnum, uint8_t param[2]; uint8_t *rdata=NULL; uint32_t rdata_count=0; - SMB_NTQUOTA_STRUCT qt; NTSTATUS status; - ZERO_STRUCT(qt); - if (!cli||!pqt) { smb_panic("cli_get_fs_quota_info() called with NULL Pointer!"); } @@ -406,20 +436,7 @@ NTSTATUS cli_get_fs_quota_info(struct cli_state *cli, int quota_fnum, return status; } - /* unknown_1 24 NULL bytes in pdata*/ - - /* the soft quotas 8 bytes (uint64_t)*/ - qt.softlim = BVAL(rdata,24); - - /* the hard quotas 8 bytes (uint64_t)*/ - qt.hardlim = BVAL(rdata,32); - - /* quota_flags 2 bytes **/ - qt.qflags = SVAL(rdata,40); - - qt.qtype = SMB_USER_FS_QUOTA_TYPE; - - *pqt = qt; + status = parse_fs_quota_buffer(rdata, rdata_count, pqt); TALLOC_FREE(rdata); return status; diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 85cf44a557a..eaa9c8e42df 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -770,6 +770,9 @@ NTSTATUS parse_user_quota_list(const uint8_t *curdata, uint32_t curdata_size, TALLOC_CTX *mem_ctx, SMB_NTQUOTA_LIST **pqt_list); +NTSTATUS parse_fs_quota_buffer(const uint8_t *rdata, + unsigned int rdata_count, + SMB_NTQUOTA_STRUCT *pqt); NTSTATUS cli_get_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_STRUCT *pqt); NTSTATUS cli_set_user_quota(struct cli_state *cli, int quota_fnum,