Bug 979

Summary: "delgroup" doesnt delete a user from a secondary group
Product: Busybox Reporter: Joao Cardoso <joao.fs.cardoso>
Component: OtherAssignee: unassigned
Status: RESOLVED WORKSFORME    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.15.x   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description Joao Cardoso 2010-01-26 19:26:22 UTC
Hi,

"delgroup" doesnt delete a user from a group, it complains that the group is the users primary group, which is not true:

# busybox --help
BusyBox v1.15.3 (2010-01-25 21:36:24 WET) multi-call binary

# ls /lib/libuClibc-0.9.30.1.so
/lib/libuClibc-0.9.30.1.so

# cat /etc/passwd
root:x:0:0:root:/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:100:sync:/bin:/bin/sync
at:x:5:8:Linux User,,,:/home/at:/bin/sh
ftp:x:7:7:Linux User,,,:/home/ftp:/bin/sh
mail:x:8:8:mail:/var/spool/mail:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
operator:x:37:37:Operator:/var:/bin/sh
nobody:x:99:99:nobody:/home:/bin/sh
sshd:x:103:99:Operator:/var:/bin/sh
default:x:1000:1000:Default non-root user:/home/default:/bin/sh
dummy:x:1001:100:Test case:/mnt/users/Test case:/bin/sh

# cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
ftp:x:7:
at:x:8:
wheel:x:10:root
utmp:x:43:
staff:x:50:
haldaemon:x:68:
dbus:x:81:
netdev:x:82:
nobody:x:99:
nogroup:x:99:
users:x:100:
default:x:1000:
testgroup:x:1001:dummy

# id dummy
uid=1001(dummy) gid=100(users) groups=100(users),1001(testgroup)

# delgroup dummy testgroup
delgroup: can't remove primary group of user dummy

# delgroup dummy users
delgroup: can't remove primary group of user dummy

The same happens if the user has its own group, created by default at user creation time:

# adduser xpto
# addgroup xpto testgroup
# id xpto
  uid=1002(xpto) gid=1002(xpto) groups=1002(xpto),1001(testgroup)
# tail -2 /etc/group
  testgroup:x:1001:dummy,xpto
  xpto:x:1002:
# tail -1 /etc/passwd
  xpto:x:1002:1002:Linux User,,,:/home/xpto:/bin/sh
# delgroup xpto xpto
  delgroup: can't remove primary group of user xpto
# delgroup xpto testgroup
  delgroup: can't remove primary group of user xpto

relevant (?) busybox configuration:

# grep GROUP .config
CONFIG_FEATURE_FIND_GROUP=y
CONFIG_ADDGROUP=y
# CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS is not set
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_DELGROUP=y
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y

cross compiled with arm-linux-gcc (GCC) 4.3.3

Thanks for busybox!
Joao
Comment 1 Denys Vlasenko 2010-12-31 01:58:58 UTC
Current git has it fixed:

# ./busybox | head -1
BusyBox v1.19.0.git (2010-12-30 23:21:08 CET) multi-call binary.

# grep dummy /etc/passwd /etc/group
/etc/passwd:dummy:x:1011:100:Test case:/mnt/users/Test case:/bin/sh
/etc/group:testgroup:x:1001:dummy

# id dummy
uid=1011(dummy) gid=100(users) groups=100(users),1001(testgroup)

# ./busybox delgroup dummy testgroup

# grep dummy /etc/passwd /etc/group
/etc/passwd:dummy:x:1011:100:Test case:/mnt/users/Test case:/bin/sh

I think 1.18.x also has it fixed. If not, please reopen the bug.