]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc-ubuntu.in: fix up the logic adding group for bound users
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 31 Jul 2012 14:03:30 +0000 (16:03 +0200)
committerDaniel Lezcano <daniel.lezcano@free.fr>
Tue, 31 Jul 2012 14:03:30 +0000 (16:03 +0200)
 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 <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
templates/lxc-ubuntu.in

index 1fd74d731fe18dde8f8b6931b2fb2eee4af0113f..b1fb956db7d90f5cd1333ceacea2794a92016e3c 100644 (file)
@@ -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