summaryrefslogtreecommitdiffstats
path: root/adduser
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
commit45a2cd95a357dec3d1fb614593c239432e36ca57 (patch)
treee7789979ce1856877f658e1a7821d7b37c8fb840 /adduser
parent0f0d85d94eb7e17bf801f4e512eecd4f357396fc (diff)
downloadpw-darwin-45a2cd95a357dec3d1fb614593c239432e36ca57.tar.gz
pw-darwin-45a2cd95a357dec3d1fb614593c239432e36ca57.tar.zst
pw-darwin-45a2cd95a357dec3d1fb614593c239432e36ca57.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.
Diffstat (limited to 'adduser')
-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}");
}