From 4ab0e57f1073e776b8832f5edc3dca04ef903fef Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 16 Feb 2015 19:26:23 +0100 Subject: smbd/reply: convert free space to 16bit in dskattr handler The deprecated Core Protocol dskattr SMB_COM_QUERY_INFORMATION_DISK command provides free space information in the form of 16-bit words. Until now, this has been handled by passing the dskattr specific small_query boolean through to disk_norm() via the SMB_VFS_DISK_FREE VFS hook. disk_norm(small_query=true) then modifies the block size and free space values such that they fit in the 16-bit field. This change adds the command specific logic to the dskattr handler, so that it can be removed from the SMB_VFS_DISK_FREE()->disk_norm() code path. In doing so, it fixes dskattr request handling against opaque VFS backends that don't call disk_norm(), such as vfs_glusterfs. Signed-off-by: David Disseldorp Reviewed-by: Jeremy Allison --- source3/smbd/reply.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 0b6c102448..b6199bbef2 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1456,15 +1456,34 @@ void reply_setatr(struct smb_request *req) void reply_dskattr(struct smb_request *req) { connection_struct *conn = req->conn; + uint64_t ret; uint64_t dfree,dsize,bsize; START_PROFILE(SMBdskattr); - if (get_dfree_info(conn,".",True,&bsize,&dfree,&dsize) == (uint64_t)-1) { + ret = get_dfree_info(conn, ".", false, &bsize, &dfree, &dsize); + if (ret == (uint64_t)-1) { reply_nterror(req, map_nt_error_from_unix(errno)); END_PROFILE(SMBdskattr); return; } + /* + * Force max to fit in 16 bit fields. + */ + while (dfree > WORDMAX || dsize > WORDMAX || bsize < 512) { + dfree /= 2; + dsize /= 2; + bsize *= 2; + if (bsize > (WORDMAX*512)) { + bsize = (WORDMAX*512); + if (dsize > WORDMAX) + dsize = WORDMAX; + if (dfree > WORDMAX) + dfree = WORDMAX; + break; + } + } + reply_outbuf(req, 5, 0); if (get_Protocol() <= PROTOCOL_LANMAN2) { -- cgit