[gnome-continuous-yocto/gnomeostree-3.28-rocko: 4324/8267] useradd_base: keep group if it still has users



commit 6805ae0f2aa77b2719f382140c3ad562e767d21b
Author: Ioan-Adrian Ratiu <adrian ratiu ni com>
Date:   Mon Jan 23 20:09:23 2017 +0200

    useradd_base: keep group if it still has users
    
    perform_groupdel() tries to delete a group irrespective if other
    users have it as their primary group, thus the call to groupdel will
    fail with the following error error:
    
    groupdel: cannot remove the primary group of user '<user>'
    
    Add a check to perform_groupdel() to determine if there are other
    users and keep the group, printing a warning. This is called right
    after a user is deleted to delete it's group. If the last user is
    deleted, only then the group is also deleted.
    
    (From OE-Core rev: bba1f02cb6d80279c6fed34bb18f010aa921fc1e)
    
    Signed-off-by: Ioan-Adrian Ratiu <adrian ratiu ni com>
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 meta/classes/useradd_base.bbclass |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/meta/classes/useradd_base.bbclass b/meta/classes/useradd_base.bbclass
index ba87edc..551c82c 100644
--- a/meta/classes/useradd_base.bbclass
+++ b/meta/classes/useradd_base.bbclass
@@ -69,11 +69,21 @@ perform_groupdel () {
        bbnote "${PN}: Performing groupdel with [$opts]"
        local groupname=`echo "$opts" | awk '{ print $NF }'`
        local group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
+
        if test "x$group_exists" != "x"; then
-               eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupdel \$opts\" || true
-               group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
-               if test "x$group_exists" != "x"; then
-                       bbfatal "${PN}: groupdel command did not succeed."
+               local awk_input='BEGIN {FS=":"}; $1=="'$groupname'" { print $3 }'
+               local groupid=`echo "$awk_input" | awk -f- $rootdir/etc/group`
+               local awk_check_users='BEGIN {FS=":"}; $4=="'$groupid'" {print $1}'
+               local other_users=`echo "$awk_check_users" | awk -f- $rootdir/etc/passwd`
+
+               if test "x$other_users" = "x"; then
+                       eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupdel \$opts\" || true
+                       group_exists="`grep "^$groupname:" $rootdir/etc/group || true`"
+                       if test "x$group_exists" != "x"; then
+                               bbfatal "${PN}: groupdel command did not succeed."
+                       fi
+               else
+                       bbnote "${PN}: '$groupname' is primary group for users '$other_users', not removing 
it"
                fi
        else
                bbnote "${PN}: group $groupname doesn't exist, not removing it"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]