From f64814b215c8669ad912058225eabf5e1d0d40fd Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 13 Dec 2019 10:30:00 +1000 Subject: Install smb2-quota and its manpage Signed-off-by: Ronnie Sahlberg --- Makefile.am | 6 ++ configure.ac | 6 ++ smb2-quota | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ smb2-quota.py | 190 ---------------------------------------------------------- 4 files changed, 202 insertions(+), 190 deletions(-) create mode 100755 smb2-quota delete mode 100755 smb2-quota.py diff --git a/Makefile.am b/Makefile.am index 1af2573..b3e9d9a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,7 @@ RST2MAN = $(have_rst2man) --syntax-highlight=none $< $@ CLEANFILES = bin_PROGRAMS = +bin_SCRIPTS = sbin_PROGRAMS = if CONFIG_CIFSUPCALL @@ -85,6 +86,11 @@ smbinfo_SOURCES = smbinfo.c rst_man_pages += smbinfo.1 endif +if CONFIG_PYTHON_TOOLS +bin_SCRIPTS += smb2-quota +rst_man_pages += smb2-quota.1 +endif + if CONFIG_PLUGIN plugindir = $(pkglibdir) plugin_PROGRAMS = idmapwb.so diff --git a/configure.ac b/configure.ac index cc48563..1b2c9c9 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,11 @@ AC_ARG_ENABLE(smbinfo, enable_smbinfo=$enableval, enable_smbinfo="maybe") +AC_ARG_ENABLE(pythontools, + [AS_HELP_STRING([--enable-pythontools],[Install python utilities @<:@default=yes@@])], + enable_pythontools=$enableval, + enable_pythontools="maybe") + AC_ARG_ENABLE(pam, [AS_HELP_STRING([--enable-pam],[Create cifscreds PAM module @<:@default=yes@:>@])], enable_pam=$enableval, @@ -281,6 +286,7 @@ AM_CONDITIONAL(CONFIG_CIFSCREDS, [test "$enable_cifscreds" != "no"]) AM_CONDITIONAL(CONFIG_CIFSIDMAP, [test "$enable_cifsidmap" != "no"]) AM_CONDITIONAL(CONFIG_CIFSACL, [test "$enable_cifsacl" != "no"]) AM_CONDITIONAL(CONFIG_SMBINFO, [test "$enable_smbinfo" != "no"]) +AM_CONDITIONAL(CONFIG_PYTHON_TOOLS, [test "$enable_pythontools" != "no"]) AM_CONDITIONAL(CONFIG_PAM, [test "$enable_pam" != "no"]) AM_CONDITIONAL(CONFIG_PLUGIN, [test "$enable_cifsidmap" != "no" -o "$enable_cifsacl" != "no"]) diff --git a/smb2-quota b/smb2-quota new file mode 100755 index 0000000..6d0b8a3 --- /dev/null +++ b/smb2-quota @@ -0,0 +1,190 @@ +#!/usr/bin/env python +# coding: utf-8 +# +# smb2-quota 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 'smb2-quota -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(' limit: + return "Above Limit" + elif warn < used < limit: + return "Warning" + else: + return "Ok" + + +class QuotaEntry: + def __init__(self, buf, flag): + sl = struct.unpack_from(' " % sys.argv[0]) - print("Try 'smb2-quota -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(' limit: - return "Above Limit" - elif warn < used < limit: - return "Warning" - else: - return "Ok" - - -class QuotaEntry: - def __init__(self, buf, flag): - sl = struct.unpack_from('