[Adduser-devel] Bug#355708: adduser: symlinks in /etc/skel sometimes break adduser

Colin Watson cjwatson at debian.org
Tue Mar 7 14:26:31 UTC 2006

Package: adduser
Version: 3.80
Severity: normal
Tags: patch

The presence of symlinks in /etc/skel sometimes breaks adduser as

  Adding user `test'...
  Adding new group `test' (1000).
  Adding new user `test' (1000) with group `test'.
  Creating home directory `/home/test'.
  Copying files from `/etc/skel'
  symlink: Bad file descriptor
  Cleaning up.
  Removing directory `/home/test'
  Removing user `test'.
  Removing group `test'.
  groupdel: group test does not exist
  adduser: `groupdel test` returned error code 6.  Aborting.

Unfortunately the only environment in which I've been able to reproduce
this reliably is in the Ubuntu live CD installer, which isn't something
I can expect you to be able to randomly test. :-( I don't know why it
shows up in this environment but not in others. However, on looking at
the code, the cause is clear: copy_to_dir() looks at $! after calling
symlink() without checking symlink()'s return code first, and in the
event that symlink() succeeds $! is essentially random.

Here's a patch (against 3.80 since that's what we have in Ubuntu, but
the surrounding code doesn't seem to have changed between that and
3.85). Changelog entry: "Only check $! after calling symlink() if
symlink() fails.":

diff -Nru /tmp/WwKkNgpSc2/adduser-3.80/adduser /tmp/eVp2gJwz5F/adduser-3.80ubuntu1/adduser
--- /tmp/WwKkNgpSc2/adduser-3.80/adduser	2005-11-18 17:15:59.000000000 +0000
+++ /tmp/eVp2gJwz5F/adduser-3.80ubuntu1/adduser	2006-03-07 11:38:39.000000000 +0000
@@ -680,8 +680,7 @@
 	my $error="";
-	symlink("$target", "$todir/$file");
-	$error="$!";
+	symlink("$target", "$todir/$file") or $error="$!";
 	if( "$error" ne "" ) {


Colin Watson                                       [cjwatson at debian.org]

More information about the Adduser-devel mailing list