deluser fails to remove home because of Examples link

Bug #34299 reported by Danilo Piazzalunga
18
Affects Status Importance Assigned to Milestone
adduser (Ubuntu)
Fix Released
Medium
Matthias Klose

Bug Description

deluser --remove-home or --remove-all-files fails to completely remove home directories when they contain a symlink. As the ~/Examples symlink is created by default, the above two options are "broken" in a default configuration.

$ sudo adduser test
[...]
$ sudo deluser --remove-home test # same with --remove-all-files
Looking for files to backup/remove...
Removing files...
Removing user `test'...
done.
$ find /home/test
/home/test
/home/test/Examples

Related branches

Matt Zimmerman (mdz)
Changed in adduser:
assignee: nobody → doko
Matthias Klose (doko)
Changed in adduser:
status: Unconfirmed → Confirmed
Revision history for this message
Matthias Klose (doko) wrote :

fixed in 3.80ubuntu2

Changed in adduser:
status: Confirmed → Fix Released
Revision history for this message
Jim Cheetham (jim.cheetham) wrote :

This bug needs to be re-opened, as the previous fix did not account for the --remove-all-files usage.

deluser --remove-all-files fails to remove the Examples symlink in the more recent version of adduser in Hardy, adduser 3.105ubuntu1.
deluser --remove-home is OK.

root@tno:~# adduser worik
Adding user `worik' ...
Adding new group `worik' (1001) ...
Adding new user `worik' (1001) with group `worik' ...
Creating home directory `/home/worik' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for worik
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [y/N] y
root@tno:~# ls -la /home/worik
total 20
drwxr-xr-x 2 worik worik 4096 2008-06-25 20:24 .
drwxr-xr-x 5 root root 4096 2008-06-25 20:24 ..
-rw-r--r-- 1 worik worik 220 2008-06-25 20:24 .bash_logout
-rw-r--r-- 1 worik worik 2940 2008-06-25 20:24 .bashrc
lrwxrwxrwx 1 worik worik 26 2008-06-25 20:24 Examples -> /usr/share/example-content
-rw-r--r-- 1 worik worik 586 2008-06-25 20:24 .profile

Now to delete the user :-
root@tno:~# deluser --remove-all-files worik
Looking for files to backup/remove ...
Removing files ...
Removing user `worik' ...
Warning: Removing group `worik', since no other user is part of it.
Done.
root@tno:~# ls -la /home/worik
total 8
drwxr-xr-x 2 1001 1001 4096 2008-06-25 20:26 .
drwxr-xr-x 5 root root 4096 2008-06-25 20:24 ..
lrwxrwxrwx 1 1001 1001 26 2008-06-25 20:24 Examples -> /usr/share/example-content

The problem seems to be that deluser believes ~/Examples is a directory, and tries to rmdir() it unstead of unlink()ing.

That implies that find_match() is having problems. home_match() assigns a filename to @files on both -f and -l filetest conditions, which means that the Examples symlink ends up in both @files and @dirs -- the dual categorisation is harmless, because by the time rmdir() is called, it has already been unlink()ed. But the different test structure of find_match() won't allow dual categorisation.

Changing find_match() to test for -l before -d , and pushing -l results into @files, fixes the problem. I hope it doesn't introduce others, but that seems unlikely ...

Patch attached.

Revision history for this message
Jim Cheetham (jim.cheetham) wrote :

Changing bug status to In Progress as the previous fix did not account for all use cases.

Changed in adduser:
status: Fix Released → In Progress
Revision history for this message
Jim Cheetham (jim.cheetham) wrote :

Sorry, my comment was slightly inaccurate, although the fix & patch are still valid ...

> home_match() assigns a filename to @files on both -f and -l filetest conditions, which means that the Examples symlink ends up in both @files and @dirs

That should have been

> home_match() assigns a symlinked directory to @files on the -l filetest condition, and to @dirs on the -d filetest condition, which means that the Examples symlink ends up in both @files and @dirs

Revision history for this message
Nigel Babu (nigelbabu) wrote :

On a karmic system which I just tested, a new user does not have a sym link to Examples. Closing the bug as fixed. Please reopen if it isn't.

Changed in adduser (Ubuntu):
status: In Progress → Fix Released
Revision history for this message
Jim Cheetham (jim.cheetham) wrote :

Sorry, the lack of an "Examples" symlink in current distro versions isn't sufficient to fix the fault. The bug is still present on 10.04, for example ... although to trigger it you now have to create your own symlink rather than one being created by default for you.

Changed in adduser (Ubuntu):
status: Fix Released → Incomplete
status: Incomplete → Confirmed
Revision history for this message
Nigel Babu (nigelbabu) wrote :

Thank you for your quick response, please forward the patch upstream to Debian so they can take a look at it. Thank you for looking into this.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package adduser - 3.112+nmu1ubuntu3

---------------
adduser (3.112+nmu1ubuntu3) natty; urgency=low

  * deluser: Remove symlinks to directories with rm, not rmdir (Jim Cheetham).
    LP: #34299.
 -- Matthias Klose <email address hidden> Thu, 06 Jan 2011 21:48:21 +0100

Changed in adduser (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.