chiark / gitweb /
adt-virt-schroot: better handling of root-users/groups (#667001)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Jun 2012 23:39:17 +0000 (00:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Jun 2012 23:39:19 +0000 (00:39 +0100)
Thanks to Colin Watson.

debian/changelog
virt-subproc/adt-virt-schroot

index 8f0daba228723ddcef007b5b7bc267a49915b7e2..77e902fbe2bf4a41f6313b301004232fd92a9007 100644 (file)
@@ -7,6 +7,8 @@ autopkgtest (2.0.2) unstable; urgency=low
   * Fix parsing of "@" dependencies.  Colin Watson.  Closes: #667022.
   * Fix NameError re "f" in restriction parsing.
     Martin Pitt.  Closes: #647882.
+  * Improve handling of schroot root-users and root-groups.
+    Colin Watson.  Closes: #667001.
 
   Packaging fixes:
   * Add Recommends against pbuilder, whose dependency resolver adt-run
index 451f254f20b212efe17049b1ab4fd2a69cd0b368..40384b9ff55a546756e1c22a6d603184352a1960 100755 (executable)
@@ -37,6 +37,24 @@ sys.path.insert(1, our_base)
 import VirtSubproc as vsp
 capabilities = []
 
+def pw_uid(exp_name):
+       try:
+               return pwd.getpwnam(exp_name).pw_uid
+       except KeyError:
+               return None
+
+def gr_gid(exp_name):
+       try:
+               return grp.getgrnam(exp_name).gr_gid
+       except KeyError:
+               return None
+
+def match(exp_names, ids, extract_id):
+       for exp_name in [n for n in exp_names.split(',') if n]:
+               if extract_id(exp_name) in ids:
+                       return True
+       return False
+
 def parse_args():
        global schroot, debuglevel
 
@@ -66,15 +84,8 @@ def parse_args():
        if regexp.search('snapshot',cfg['type']):
                capabilities.append('revert')
 
-       if [True
-               for exp_name in cfg['root-users'].split(',')
-               for got_uid in [os.getuid()]
-               if got_uid == pwd.getpwnam(exp_name).pw_uid
-       ] or [True
-               for exp_name in cfg['root-groups'].split(',')
-               for got_gid in [os.getgid()] + os.getgroups()
-               if got_gid == grp.getgrnam(exp_name).gr_gid
-       ]:
+       if (match(cfg['root-users'], [os.getuid()], pw_uid) or
+           match(cfg['root-groups'], [os.getgid()] + os.getgroups(), gr_gid)):
                capabilities.append('root-on-testbed')
 
 def hook_open():