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

Bug#1544: usergroups in adduser



Ian Murdock writes ("Bug#1544: usergroups in adduser"):
> Package: adduser
> Version: 1.94-1
>
> Users added when using usergroups should have home directories with
> mode 2775, and all skeletal files should be g+w.  This is how it is
> currently created:
>
> $ ls -la /mnt/home/imurdock
> total 4
> drwxr-xr-x   2 imurdock imurdock     1024 Oct  3 23:14 .
> drwxrwsr-x   3 root     staff        1024 Oct  3 23:14 ..
> -rw-r--r--   1 imurdock imurdock      133 Oct  3 23:14 .bash_profile
> -rw-r--r--   1 imurdock imurdock      114 Oct  3 23:14 .bashrc

This is because it uses the umask (presumably your root umask is 022 -
mine is 002).

Here is yet another version of my patch to adduser.

This one incorporates all of my previous changes, and fixes a few
other problems too:
 * honour --home when creating non-system users
 * create home directory with setgid bit when using usergroups.
 * copy permissions of dotfiles from /etc/skel, but modified so that
   the group permissions are the same as the user permissions
   (usergroups) or as the other permissions (not user- groups).
 * run /usr/local/sbin/adduser.local if it exists.
 * don't break the dotfiles permissions while doing the umask
   modification.

Ian.

--- /usr/sbin/adduser	Mon Jul 10 02:10:53 1995
+++ /usr/local/sbin/adduser	Wed Oct  4 21:50:45 1995
@@ -602,7 +602,11 @@
     ## add the new user to the passwd file
     ##
     print "Updating password file... " if ($verbose);
-    $home_dir = $config{"home"} . "/" . $new_name;
+    if ($special_home) {
+	$home_dir = $special_home;
+    } else {
+	$home_dir = $config{"home"} . "/" . $new_name;
+    }
     &add_user_to_file($new_name,
 		      $new_uid,
 		      $new_gid,
@@ -651,6 +655,7 @@
 	}
 	mkdir ($home_dir, $dir_mode);
 	chown ($new_uid, $new_gid, $home_dir);
+        chmod ($dir_mode, $home_dir);
 	print "done.\n" if ($verbose);

 	##
@@ -666,19 +671,25 @@
 	## change umask lines in appropriate skel files
 	## if we're using usergroups.
 	##
+        local (@statreturn);
 	if ($config{"usergroups"} eq "yes") {
 	    foreach $file (".login", ".profile", ".bash_profile") {
 		$this_file = $home_dir . "/" . $file;
 		if (-f $this_file) {
 		    open (FILE, "$this_file") || die "open: $!";
-		    open (NEWFILE, ">$file.new") || die "open: $!";
+		    open (NEWFILE, ">$this_file.new") || die "open: $!";
 		    while ($line = <FILE>) {
 			$line =~ s/umask 0([267])\1/umask 00$1/;
-			print NEWFILE $line;
+			print(NEWFILE $line) || die "write: $!";
 		    }
+
+                    (@statreturn= stat(FILE)) || die "fstat: $!";
+                    $filemode= $statreturn[2];
+                    chmod($statreturn[2],"$this_file.new") || die "chmod: $!";
+
 		    close FILE;
-		    close NEWFILE;
-		    rename ("$file.new", "$file") || die "rename: $!";
+		    close(NEWFILE) || die "close: $!";
+		    rename ("$this_file.new", "$this_file") || die "rename: $!";
 		}
 	    }
 	}
@@ -719,6 +730,11 @@
     }
     print "done.\n";
     &clean_up();
+    if (-f "/usr/local/sbin/adduser.local") {
+        exec("/usr/local/sbin/adduser.local",
+             $new_name, $new_uid, $new_gid, $home_dir);
+        die "exec adduser.local: $!";
+    }
     exit 0;
 }

@@ -867,11 +883,21 @@
     open (NEWFILE, ">$dir/$file") || die "open: $!";

     while (<FILE>) {
-	print NEWFILE;
+	print(NEWFILE) || die "print: $!";
     }

+    local (@statreturn,$filemode);
+    (@statreturn= stat(FILE)) || die "fstat: $!";
+    $filemode= $statreturn[2];
+    if ($config{"usergroups"} eq "yes") {
+        $filemode= ($filemode & 0707) | (($filemode & 0700)>>3);
+    } else {
+        $filemode= ($filemode & 0707) | (($filemode & 0007)<<3);
+    }
+    chmod($filemode,"$dir/$file") || die "chmod: $!";
+
     close FILE;
-    close NEWFILE;
+    close(NEWFILE) || die "close: $!";

     return 1;
 }
@@ -1246,7 +1272,3 @@
     print STDERR "  --debug         Display plenty of debugging information.\n";
     print STDERR "Global configuration is in the file '/etc/adduser.conf'\n";
 }
-
-
-
-


Reply to: