aboutsummaryrefslogtreecommitdiff
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
commit555dff94cc9abd872c0a61345825941edc5fabcf (patch)
treee5edf47ece4aa00460be5db7121a4914784047e4
parentf84e29a06ca262c7ab86785292d9c71b4eeff4b6 (diff)
downloadsrc-555dff94cc9abd872c0a61345825941edc5fabcf.tar.gz
src-555dff94cc9abd872c0a61345825941edc5fabcf.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.
Notes
Notes: svn path=/head/; revision=75581
-rw-r--r--usr.sbin/adduser/adduser.perl12
1 files changed, 10 insertions, 2 deletions
diff --git a/usr.sbin/adduser/adduser.perl b/usr.sbin/adduser/adduser.perl
index 3ce7b2aa03fd..f453207b3d15 100644
--- a/usr.sbin/adduser/adduser.perl
+++ b/usr.sbin/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}");
}