Package: autopkgtest Version: 2.0.1 Severity: normal Tags: patch The (largely automatically-generated) configuration for the schroot instance I was trying to run adt-virt-schroot against is as follows:
[precise-i386-sbuild] description=precise-i386-sbuild groups=sbuild,root,admin root-groups=sbuild,root,admin # Uncomment these lines to allow members of these groups to access # the -source chroots directly (useful for automated updates, etc). source-root-users=sbuild,root,admin source-root-groups=sbuild,root,admin type=directory union-type=overlayfs directory=/media/passport/chroot/precise-i386-sbuild personality=linux32 adt-virt-schroot chokes on this with: Traceback (most recent call last): File "/usr/bin/adt-virt-schroot", line 107, in <module> parse_args() File "/usr/bin/adt-virt-schroot", line 72, in parse_args if got_uid == pwd.getpwnam(exp_name).pw_uid KeyError: 'getpwnam(): name not found: ' There are two problems here. Firstly, ''.split(',') returns [''] not [], so you should filter out empty entries. Secondly, adt-virt-schroot should ignore user or group names that don't exist rather than crashing. Patch attached. Thanks, -- Colin Watson [cjwat...@ubuntu.com]
>From 61c3d931fc7f8255df7cfefafe4b7434f3f24977 Mon Sep 17 00:00:00 2001 From: Colin Watson <cjwat...@canonical.com> Date: Tue, 3 Apr 2012 11:06:31 +0100 Subject: [PATCH] Make schroot configuration parsing more robust Ignore empty root-users/root-groups entries, or entries containing non-existent users or groups. --- virt-subproc/adt-virt-schroot | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-) diff --git a/virt-subproc/adt-virt-schroot b/virt-subproc/adt-virt-schroot index 451f254..40384b9 100755 --- a/virt-subproc/adt-virt-schroot +++ b/virt-subproc/adt-virt-schroot @@ -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(): -- 1.7.9.1