Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CC96C432C1 for ; Tue, 24 Sep 2019 04:56:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47DAA207FD for ; Tue, 24 Sep 2019 04:56:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390541AbfIXE4R (ORCPT ); Tue, 24 Sep 2019 00:56:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59156 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388254AbfIXE4Q (ORCPT ); Tue, 24 Sep 2019 00:56:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 087B483F45; Tue, 24 Sep 2019 04:56:16 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.76.1.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70F3F60852; Tue, 24 Sep 2019 04:56:14 +0000 (UTC) From: Kenneth D'souza To: linux-cifs@vger.kernel.org, piastryyy@gmail.com, smfrench@gmail.com Cc: lsahlber@redhat.com Subject: [PATCH] smb2quota.py: Userspace helper to display quota information for the Linux SMB client file system (CIFS) Date: Tue, 24 Sep 2019 10:26:11 +0530 Message-Id: <20190924045611.21689-1-kdsouza@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 24 Sep 2019 04:56:16 +0000 (UTC) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Kenneth D'souza Signed-off-by: Ronnie Sahlberg --- smb2quota.py | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100755 smb2quota.py diff --git a/smb2quota.py b/smb2quota.py new file mode 100755 index 0000000..11d98db --- /dev/null +++ b/smb2quota.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# coding: utf-8 +# +# smb2quota is a cmdline tool to display quota information for the +# Linux SMB client file system (CIFS) +# +# Copyright (C) Ronnie Sahlberg (lsahlberg@redhat.com) 2019 +# Copyright (C) Kenneth D'souza (kdsouza@redhat.com) 2019 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +import array +import fcntl +import os +import struct +import sys +import argparse + +CIFS_QUERY_INFO = 0xc018cf07 +BBOLD = '\033[1;30;47m' # Bold black text with white background. +ENDC = '\033[m' # Rest to defaults + + +def usage(): + print("Usage: %s [-h] " % sys.argv[0]) + print("Try 'smb2quota -h' for more information") + sys.exit() + + +class SID: + def __init__(self, buf): + self.sub_authority_count = buf[1] + self.buffer = buf[:8 + self.sub_authority_count * 4] + self.revision = self.buffer[0] + if self.revision != 1: + raise ValueError('SID Revision %d not supported' % self.revision) + self.identifier_authority = 0 + for x in self.buffer[2:8]: + self.identifier_authority = self.identifier_authority * 256 + x + self.sub_authority = [] + for i in range(self.sub_authority_count): + self.sub_authority.append(struct.unpack_from('