From: Serge Hallyn Date: Tue, 31 Jul 2012 14:03:30 +0000 (+0200) Subject: lxc-ubuntu.in: fix up the logic adding group for bound users X-Git-Tag: lxc-0.8.0~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9db1aba4bc2201d886c159d7821c03a8cf25c389;p=thirdparty%2Flxc.git lxc-ubuntu.in: fix up the logic adding group for bound users 1. 'getent group $user' assumes user's group is named $user. 2. if 'getent group' returns error, just ignore the group in container 3. (misc) while it happens to all work out fine anyway, don't do getent passwd $bindhome if $bindhome isn't defined. (it will successfully return all password entries) Signed-off-by: Serge Hallyn Signed-off-by: Daniel Lezcano --- diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in index 1fd74d731..b1fb956db 100644 --- a/templates/lxc-ubuntu.in +++ b/templates/lxc-ubuntu.in @@ -546,10 +546,9 @@ do_bindhome() echo "$h $rootfs/$h none bind 0 0" >> $path/fstab # Make sure the group exists in container - chroot $rootfs getent group $user || { \ - grp=`getent group $user` - echo "$grp" >> $rootfs/etc/group - } + grp=`echo $pwd | cut -d: -f 4` # group number for $user + grpe=`getent group $grp` || return 0 # if host doesn't define grp, ignore in container + chroot $rootfs getent group "$grpe" || echo "$grpe" >> $rootfs/etc/group } usage() @@ -630,10 +629,12 @@ if [ $debug -eq 1 ]; then set -x fi -pwd=`getent passwd $bindhome` -if [ $? -ne 0 ]; then - echo "Error: no password entry found for $bindhome" - exit 1 +if [ -n "$bindhome" ]; then + pwd=`getent passwd $bindhome` + if [ $? -ne 0 ]; then + echo "Error: no password entry found for $bindhome" + exit 1 + fi fi