from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.2.1'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
def _run(self):
self.read_exclude_dirs()
+ self.read_passwd_homes()
# -------------------------------------------------------------------------
def read_exclude_dirs(self):
e=token, f=self.exclude_file, l=lnr))
continue
home_relative = os.path.relpath(token, self.home_root_abs)
- if home_relative.startswith(upper_dir):
+ if token == os.sep or home_relative.startswith(upper_dir):
LOG.warn((
"Entry {e!r} in file {f!r}, line {l}, "
"is outside home root {h!r}.").format(
e=token, f=self.exclude_file, l=lnr, h=self.home_root_abs))
continue
- if not token in self.exclude_dirs:
+ if token not in self.exclude_dirs:
self.exclude_dirs.append(token)
self.exclude_dirs.sort(key=str.lower)
+ LOG.debug("Found {} directories to exclude.".format(len(self.exclude_dirs)))
if self.verbose > 2:
LOG.debug("Found directories to exclude:\n{}".format(pp(self.exclude_dirs)))
+ # -------------------------------------------------------------------------
+ def read_passwd_homes(self):
+
+ LOG.info("Reading all home directories from 'getent passwd' ...")
+
+ upper_dir = os.pardir + os.sep
+ entries = pwd.getpwall()
+
+ for entry in entries:
+ home = entry.pw_dir
+ if not home:
+ continue
+ home_relative = os.path.relpath(home, self.home_root_abs)
+ if home == os.sep or home_relative.startswith(upper_dir):
+ if self.verbose > 1:
+ LOG.debug((
+ "Home directory {d!r} of user {u!r} "
+ "is outside home root {h!r}.").format(
+ d=home, u=entry.pw_name, h=self.home_root_abs))
+ continue
+ if home not in self.passwd_home_dirs:
+ self.passwd_home_dirs.append(home)
+
+ self.passwd_home_dirs.sort(key=str.lower)
+
+ LOG.debug("Found {} home directories in passwd.".format(len(self.passwd_home_dirs)))
+ if self.verbose > 2:
+ LOG.debug("Home directories in passwd:\n{}".format(pp(self.passwd_home_dirs)))
+
# =============================================================================
if __name__ == "__main__":