summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2001-04-17 09:42:07 +0000
committerDoug Barton <dougb@FreeBSD.org>2001-04-17 09:42:07 +0000
commit90c39a68308b728f96d32c8ac8e83b23e3719f4d (patch)
tree7e91e37b818b30601f647544277e35e56f4f9d57
parentc4e62c5c4a2057491ba24168f433072e87b2eb6c (diff)
downloadpw-darwin-90c39a68308b728f96d32c8ac8e83b23e3719f4d.tar.gz
pw-darwin-90c39a68308b728f96d32c8ac8e83b23e3719f4d.tar.zst
pw-darwin-90c39a68308b728f96d32c8ac8e83b23e3719f4d.zip
By popular demand, have adduser preserve comments at the top of the
group file. Because of the way the group sorting works while printing out the new file it's not possible at this time to restore comments in other locations, but at least they won't just disappear altogether.
-rw-r--r--adduser/adduser.perl12
1 files changed, 10 insertions, 2 deletions
diff --git a/adduser/adduser.perl b/adduser/adduser.perl
index 3ce7b2a..f453207 100644
--- a/adduser/adduser.perl
+++ b/adduser/adduser.perl
@@ -70,6 +70,7 @@ sub variables {
$groupname =''; # $groupname{groupname} = gid
$groupmembers = ''; # $groupmembers{gid} = members of group/kommalist
$gid = ''; # $gid{gid} = groupname; gid form group db
+ @group_comments; # Comments in the group file
# shell
$shell = ''; # $shell{`basename sh`} = sh
@@ -265,9 +266,13 @@ sub group_read {
while(<G>) {
chop;
push(@group_backup, $_);
- # ignore comments
+ # Ignore empty lines
next if /^\s*$/;
- next if /^\s*#/;
+ # Save comments to restore later
+ if (/^\s*\#/) {
+ push(@group_comments, $_);
+ next;
+ }
($g_groupname, $pw, $g_gid, $memb) = (split(/:/, $_))[0..3];
@@ -566,6 +571,9 @@ sub new_users_group_update {
# new login group is already in name space
rename($group, "$group.bak");
#warn "$group_login $groupname{$group_login} $groupmembers{$groupname{$group_login}}\n";
+
+ # Restore comments from the top of the group file
+ @a = @group_comments;
foreach $e (sort {$a <=> $b} (keys %gid)) {
push(@a, "$gid{$e}:*:$e:$groupmembers{$e}");
}