import textwrap
import pwd
import copy
+import glob
# Third party modules
import six
from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.3.1'
+__version__ = '0.4.1'
LOG = logging.getLogger(__name__)
self.exclude_dirs = []
self.passwd_home_dirs = []
+ self.unnecessary_dirs = []
description = textwrap.dedent('''\
This scripts detects unnecessary home directories - without an
self.read_exclude_dirs()
self.read_passwd_homes()
+ self.check_homes()
# -------------------------------------------------------------------------
def read_exclude_dirs(self):
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__":