]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Don't considering home dirs outside /home
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 12:59:26 +0000 (13:59 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 12:59:26 +0000 (13:59 +0100)
etc/mk-home.ini.default
pp_lib/mk_home_app.py

index 23d9e054c0b6390e20b2c3a5be20c0a79c9fbb31..3c3fbe96e956350b1d10e0a685ddfdab1fb3b7da 100644 (file)
@@ -11,6 +11,7 @@ bind_dn = cn=admin
 
 [mk-home]
 initial_uid = 999999999
-chroot_homedir = '/mnt/nfs'
+chroot_homedir = /mnt/nfs
+home_root = /home
 
 # vim: filetype=dosini
index dab2979f0635a7c4c86727d91df3e37d6b45412e..05f4c626867cead89d7fc8e95e202f84a1463c6e 100644 (file)
@@ -39,7 +39,7 @@ from .merge import merge_structure
 
 from .ldap_app import PpLdapAppError, PpLdapApplication
 
-__version__ = '0.3.3'
+__version__ = '0.3.4'
 LOG = logging.getLogger(__name__)
 
 
@@ -57,14 +57,18 @@ class PpMkHomeApp(PpLdapApplication):
 
     default_initial_uid = 999999999
     default_chroot_homedir = os.sep + os.path.join('mnt', 'nfs')
+    default_home_root = os.sep + 'home'
 
     # -------------------------------------------------------------------------
     def __init__(self, appname=None, version=__version__):
 
         self.initial_uid = self.default_initial_uid
         self.chroot_homedir = self.default_chroot_homedir
+        self.home_root_abs = default_chroot_homedir
+        self.home_root_rel = os.path.relpath(self.home_root_abs, os.sep)
         self.simulate = False
         self.user_entries = []
+        self.home_root_real = os.path.join(self.chroot_homedir, self.home_root)
 
         description = textwrap.dedent('''\
             Home Directory and UIDNumber generation - this script will search for
@@ -156,6 +160,19 @@ class PpMkHomeApp(PpLdapApplication):
                     raise PpMkHomeError(msg)
                 self.chroot_homedir = v
 
+            if 'home_root' in section:
+                v = section['home_root']
+                if not os.path.isabs(v):
+                    msg = (
+                        "The root path of the home directories must be an "
+                        "absolute pathname (found [{s}]/home_root "
+                        "=> {v!r} in configuration.").format(s=section_name, v=v)
+                    raise PpMkHomeError(msg)
+                self.home_root_abs = v
+
+        self.home_root_rel = os.path.relpath(self.home_root_abs, os.sep)
+        self.home_root_real = os.path.join(self.chroot_homedir, self.home_root)
+
     # -------------------------------------------------------------------------
     def pre_run(self):
         """
@@ -216,6 +233,7 @@ class PpMkHomeApp(PpLdapApplication):
     def check_home_dirs(self):
 
         LOG.info("Checking home directories ...")
+        upper_dir = os.pardir + os.sep
 
         i = 0
         for entry in self.user_entries:
@@ -233,6 +251,16 @@ class PpMkHomeApp(PpLdapApplication):
 
             home = entry['homeDirectory'][0]
             LOG.debug("Checking home directory {!r} ...".format(home))
+            if not os.path.isabs(home):
+                LOG.warn("Home directory {h!r} of user {u!r} is not absolute.".format(
+                    h=home, u=dn))
+                continue
+            home_relative = os.path.relpath(home, self.home_root_abs)
+            if home_relative.startswith(upper_dir):
+                if self.verbose:
+                    LOG.warn("Home directory {h!r} outside {r!r} is not considered.".format(
+                        h=home, r=self.home_root_abs))
+                continue
 
             chroot_dir = os.path.join(
                 self.chroot_homedir, os.path.relpath(home, os.sep))