mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-07 05:03:00 -05:00
ZM_OPT_USE_AUTH shipped as 0, so a new install accepted every request as the default user with System=Edit. That includes requests a browser sends on behalf of any web page a user on the same network opens, so a server that is never exposed to the internet could still be driven from it. Default it to 1. zm_create.sql (generated from ConfigData) gives new installs authentication on. Existing installs keep their value: zmupdate.pl -f loads Value from the database and writes it back, and only DefaultValue changes. zm_update-1.39.41.sql also sets DefaultValue to 1 for the row, so that an upgrade run without -f doesn't leave Value = DefaultValue = 0, which the C++ config loader would skip in favour of its compiled-in default (on) while the web UI read off. Update the option help and the user guide (getting started, FAQ, system options) to say authentication is on for new installs and kept on upgrade. tests/perl/test_auth_default.pl checks the default, the stored value and that no update script sets the row's Value; tests/zm_config.cpp now expects the compiled-in default (opt_use_auth) to be on.
66 lines
2.3 KiB
Perl
66 lines
2.3 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# ZM_OPT_USE_AUTH is on by default, so a new install starts with
|
|
# authentication. An existing install must keep the value it has: zmupdate.pl
|
|
# -f loads Value from the database and writes it back, and only DefaultValue
|
|
# takes the new default. The update script also records the new DefaultValue,
|
|
# because the C++ config loader reads only rows whose Value differs from
|
|
# DefaultValue: an upgrade that left Value = DefaultValue = 0 would make the
|
|
# daemons use their compiled-in default (on) while the web UI read off.
|
|
#
|
|
# Run as: perl tests/perl/test_auth_default.pl
|
|
#
|
|
# ConfigData has no database dependency, so this runs without a configured
|
|
# ZoneMinder. The upgrade itself is exercised against a database in the
|
|
# holodeck lab (see the PR).
|
|
use strict;
|
|
use warnings;
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/../../build/scripts/ZoneMinder/lib";
|
|
|
|
use ZoneMinder::ConfigData qw(:data);
|
|
|
|
my $failures = 0;
|
|
my $passes = 0;
|
|
|
|
sub ok {
|
|
my ($name, $cond, $detail) = @_;
|
|
if ($cond) {
|
|
$passes++;
|
|
print "ok - $name\n";
|
|
} else {
|
|
$failures++;
|
|
print "FAIL - $name\n";
|
|
print " $detail\n" if defined $detail;
|
|
}
|
|
}
|
|
|
|
my $option = $options_hash{ZM_OPT_USE_AUTH};
|
|
ok('ZM_OPT_USE_AUTH exists', defined $option);
|
|
ok('ZM_OPT_USE_AUTH defaults to on', $option && $option->{default} eq '1',
|
|
'default is '.($option ? "'$option->{default}'" : 'undef'));
|
|
ok('a new install stores it as on',
|
|
$option && dbValue($option->{type}{db_type}, $option->{value}) eq '1');
|
|
|
|
# Every update script that touches this row must only change DefaultValue.
|
|
my $dir = "$FindBin::Bin/../../db";
|
|
opendir(my $dh, $dir) or die "Can't open $dir: $!";
|
|
my @updates = sort grep { /^zm_update-[\d.]+\.sql$/ } readdir($dh);
|
|
closedir($dh);
|
|
my $records_default = 0;
|
|
foreach my $file (@updates) {
|
|
open(my $fh, '<', "$dir/$file") or die "Can't open $file: $!";
|
|
my $sql = do { local $/; <$fh> };
|
|
close($fh);
|
|
$sql =~ s/^--.*$//mg;
|
|
foreach my $stmt (grep { /ZM_OPT_USE_AUTH/ } split(/;/, $sql)) {
|
|
ok("$file does not set the Value of ZM_OPT_USE_AUTH", $stmt !~ /(?<!Default)`?Value`?\s*=/i, $stmt)
|
|
if $stmt =~ /^\s*UPDATE/i;
|
|
$records_default = 1 if $stmt =~ /SET\s+`?DefaultValue`?\s*=\s*'1'/i;
|
|
}
|
|
}
|
|
ok('an update script records the new DefaultValue', $records_default);
|
|
|
|
print "\n$passes passed, $failures failed\n";
|
|
exit($failures ? 1 : 0);
|