Description: ubuntu: 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)
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/942850
Author: Serge Hallyn <serge.hallyn@canonical.com>
Forwarded: yes

Index: lxc-0.8.0~rc1/templates/lxc-ubuntu.in
===================================================================
--- lxc-0.8.0~rc1.orig/templates/lxc-ubuntu.in	2012-04-23 23:09:44.447940356 -0500
+++ lxc-0.8.0~rc1/templates/lxc-ubuntu.in	2012-04-23 23:09:46.179940328 -0500
@@ -546,10 +546,9 @@
     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 @@
 	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
 
 
