[PATCH] 2nd attempt at deluser/delgroup size reduction and improvements

Tito farmatito at tiscali.it
Sun Nov 7 09:25:03 UTC 2010


On Sunday 07 November 2010 03:07:47 you wrote:
> On Sun, Nov 7, 2010 at 12:06 AM, Tito <farmatito at tiscali.it> wrote:

Hi,
i was thinking all the time about deluser that's why
i couldn't see the problem you're talking about.

> 
> I am saying that "delgroup foo" (delgroup, not deluser)
> should not check whether *user named foo* exists;
> but should check that deleting group foo doesn't
> leave users with "deleted" GIDs.
 
> Example:
> 
> /etc/passwd
> haldaemon:x:68:490:HAL daemon:/:/sbin/nologin
> foo:x:496:1234::/:/sbin/nologin
> 
> /etc/group
> foo:490:
> 
> What "standard" delgroup foo will do? I suspect it will
> complain that haldaemon user's primary GID is 490
> and therefore group foo can't be deleted.

adduser prova
Adding user `prova' ...
Adding new group `prova' (1006) ...
Adding new user `prova' (1004) with group `prova' ...
adduser prova2 --ingroup prova
Adding user `prova2' ...
Adding new user `prova2' (1005) with group `prova' ...

Test case 1: Removing user prova:

deluser prova
Removing user `prova' ...
Warning: group `prova' has no more members.
userdel: Cannot remove group prova which is a primary group for another user.
Done.
grep prova /etc/group
prova:x:1006:

Test case 2: Removing user prova2: 

deluser prova2
Removing user `prova2' ...
Warning: group `prova' has no more members.
Done.
grep prova /etc/group
prova:x:1006:

Test case 3: Removing group prova:

delgroup prova
/usr/sbin/delgroup: `prova' still has `prova' as their primary group!

Test case 4: Removing group prova after removal of user prova:

deluser prova
Removing user `prova' ...
Warning: group `prova' has no more members.
userdel: Cannot remove group prova which is a primary group for another user.
Done.
delgroup prova
/usr/sbin/delgroup: `prova2' still has `prova' as their primary group!

Test case 5 : Removing non empty group

addgroup root prova
Adding user `root' to group `prova' ...
Adding user root to group prova
Done.
grep prova /etc/group
prova:x:1006:root
delgroup prova
Removing group `prova' ...
Done.



> If you remove haldaemon line from /etc/passwd,
> delgroup foo will succeed despite the fact that _user_ foo exists.
> Because in this example, _user_ foo and _group_ foo
> are completely unrelated.
> 
> Our version gets this wrong, I think.

In some cases of course it does. To fix this
will be rather expensive in size:

if (doing_deluser) {
	get gid
	delete_user
        walk through passwd file
	if users with same gid
		complain and do nothing to group file
	else
		if username == groupname // is UserPrivateGroup
			delete_group
	else
		do_nothing to group file
}

if (doing_delgroup) {
	get_gid
	// NO - check if group is empty 
        walk through passwd file
	if users with same gid
		complain and do nothing to group file
} 

So combining the two

case argc2
	if (deluser) { 
		setup deluser
		gid = get_gid
	} else {
do_delgroup:
	/* delgroup */
		setup delgroup
		if (no_gid)
			gid = get_gid
		// NO - check if group is empty 
        	walk through passwd file
		if users with same gid > 0
			complain and do nothing to group file
		else if (doing_delgroup after deluser /* needs a flag ? */) {
			if username != groupname // not UserPrivateGroup
				do_nothing to group file
		}
	}

	do_deletions_loop

	if (deluser ) {
			set_a_flag
			goto do_delgroup
	}

> My machine has no native deluser/delgroup.
> Can you test this example on your side?
> 

Tested and added a few more cases see above.
So by looking at the untested pseudocode it should
not be difficult to get it right. But I think 
the "walk through passwd file" will be expensive
maybe you have a good idea that can do the trick.
Will try to code it this evening.


Ciao,
Tito  


More information about the busybox mailing list