From: Frank Brehm Date: Tue, 21 Mar 2017 16:24:37 +0000 (+0100) Subject: Collecting all unnecessary home dirs. X-Git-Tag: 0.1.2~234 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=5b3ad6e7be525c2475391f046bd0cac185b73ca2;p=pixelpark%2Fadmin-tools.git Collecting all unnecessary home dirs. --- diff --git a/pp_lib/test_home_app.py b/pp_lib/test_home_app.py index 830faa0..b22c2e0 100644 --- a/pp_lib/test_home_app.py +++ b/pp_lib/test_home_app.py @@ -18,6 +18,7 @@ import traceback import textwrap import pwd import copy +import glob # Third party modules import six @@ -31,7 +32,7 @@ from .common import pp, terminal_can_colors, to_bytes, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.3.1' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) @@ -81,6 +82,7 @@ class PpTestHomeApp(PpConfigApplication): self.exclude_dirs = [] self.passwd_home_dirs = [] + self.unnecessary_dirs = [] description = textwrap.dedent('''\ This scripts detects unnecessary home directories - without an @@ -151,6 +153,7 @@ class PpTestHomeApp(PpConfigApplication): self.read_exclude_dirs() self.read_passwd_homes() + self.check_homes() # ------------------------------------------------------------------------- def read_exclude_dirs(self): @@ -244,6 +247,30 @@ class PpTestHomeApp(PpConfigApplication): if self.verbose > 2: LOG.debug("Home directories in passwd:\n{}".format(pp(self.passwd_home_dirs))) + # ------------------------------------------------------------------------- + def check_homes(self): + + LOG.info("Checking for unnecessary home directories ...") + + glob_pattern = os.path.join(self.home_root_real, '*') + all_home_entries = glob.glob(glob_pattern) + + for path in all_home_entries: + if not os.path.isdir(path): + continue + home_rel = os.sep + os.path.relpath(path, self.chroot_homedir) + if self.verbose > 2: + LOG.debug("Checking {p!r} ({h!r}) ...".format( + p=path, h=home_rel)) + if home_rel in self.passwd_home_dirs: + continue + if home_rel in self.exclude_dirs: + continue + LOG.debug("Marking {!r} as unnecessary.".format(home_rel)) + self.unnecessary_dirs.append(home_rel) + + self.unnecessary_dirs.sort(key=str.lower) + # ============================================================================= if __name__ == "__main__":