use Fcntl qw(:flock);
use Getopt::Std;
-my $FREESIDE_CONF = "/usr/local/etc/freeside";
+my $FREESIDE_CONF = "%%%FREESIDE_CONF%%%";
getopts("s:g:n");
my $user = shift or die &usage;
# close MAPSECRETS;
#}
- open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
+ #insert new entry before a wildcard...
+ open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets")
and flock(MAPSECRETS,LOCK_EX)
or die "can't open $FREESIDE_CONF/mapsecrets: $!";
- print MAPSECRETS "$user $opt_s\n";
+ open(NEW,">$FREESIDE_CONF/mapsecrets.new")
+ or die "can't open $FREESIDE_CONF/mapsecrets.new: $!";
+ while(<MAPSECRETS>) {
+ if ( /^\*\s/ ) {
+ print NEW "$user $opt_s\n";
+ }
+ print NEW $_;
+ }
close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
+ close NEW or die "can't close $FREESIDE_CONF/mapsecrets.new: $!";
+ rename("$FREESIDE_CONF/mapsecrets.new", "$FREESIDE_CONF/mapsecrets")
+ or die "can't move mapsecrets.new into place: $!";
}
=head1 NOTE
-No explicit htpasswd options are available in 1.7 - passwordsa are now
+No explicit htpasswd options are available in 1.7 - passwords are now
maintained automatically.
=head1 SEE ALSO