From 90c39a68308b728f96d32c8ac8e83b23e3719f4d Mon Sep 17 00:00:00 2001 From: Doug Barton Date: Tue, 17 Apr 2001 09:42:07 +0000 Subject: 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. --- adduser/adduser.perl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'adduser/adduser.perl') 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() { 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}"); } -- cgit v1.2.3-56-ge451