Skip to content
Commits on Source (2)
......@@ -23,6 +23,9 @@ debhelper (11.1.4) UNRELEASED; urgency=medium
* d/control: Bump (Build-)Dependency on dpkg to ensure that
dpkg provides DEB_RULES_REQUIRES_ROOT and DEB_GAIN_ROOT_CMD
as a part of its Rules-Requires-Root support.
* Dh_Lib.pm: Rely on DEB_RULRES_REQUIRES_ROOT instead of the
field to determine whether or not tools may "root-only"
actions (such as chown'ing).
-- Niels Thykier <niels@thykier.net> Sun, 21 Jan 2018 08:18:20 +0000
......
......@@ -66,7 +66,7 @@ exit 0 if $< == 0;
if ($requirements eq 'legacy-root') {
error("You must run this as root (or use fakeroot).");
} else {
my $env = $ENV{DEB_GAIN_ROOT_CMD} // $ENV{DPKG_GAIN_ROOT_CMD};
my $env = $ENV{DEB_GAIN_ROOT_CMD};
error("Package needs targetted root but builder has not provided a gain-root command via \${DEB_GAIN_ROOT_CMD}")
if not $env;
}
......
......@@ -22,9 +22,6 @@ use constant {
'DH_BUILTIN_VERSION' => \'<DH_LIB_VERSION>', #'# Hi emacs.
# Default Package-Type / extension (must be aligned with dpkg)
'DEFAULT_PACKAGE_TYPE' => 'deb',
# Kill-switch for R³ (for backports)
'DH_ENABLE_RRR_SUPPORT' => 1,
};
use constant {
......@@ -1363,7 +1360,7 @@ sub is_cross_compiling {
# As a side effect, populates %package_arches and %package_types
# with the types of all packages (not only those returned).
my (%package_types, %package_arches, %package_multiarches, %packages_by_type,
%package_sections, $sourcepackage, %rrr, %package_cross_type);
%package_sections, $sourcepackage, %package_cross_type);
# Returns source package name
sub sourcepackage {
......@@ -1406,11 +1403,6 @@ sub getpackages {
if (/^Source:\s*(.*)/i) {
$sourcepackage = $1;
next;
} elsif (/^Rules-Requires-Root:\s*(.*)/i) {
for my $keyword (split(' ', $1)) {
$rrr{$keyword} = 1;
}
next;
} elsif (/^Section:\s(.*)$/i) {
$source_section = $1;
next;
......@@ -1419,7 +1411,6 @@ sub getpackages {
last if (!$_ or eof); # end of stanza.
}
error("could not find Source: line in control file.") if not defined($sourcepackage);
$rrr{'binary-targets'} = 1 if not %rrr;
while (<$fd>) {
chomp;
......@@ -1512,32 +1503,36 @@ sub getpackages {
# - Takes an optional keyword; if passed, this will return true if the keyword is listed in R^3 (Rules-Requires-Root)
# - If the optional keyword is omitted or not present in R^3 and R^3 is not 'binary-targets', then returns false
# - Returns true otherwise (i.e. keyword is in R^3 or R^3 is 'binary-targets')
sub should_use_root {
my ($keyword) = @_;
return 1 if not DH_ENABLE_RRR_SUPPORT;
getpackages() if not %rrr;
return 0 if exists($rrr{'no'});
return 1 if exists($rrr{'binary-targets'});
return 0 if not defined($keyword);
return 1 if exists($rrr{$keyword});
return 0;
{
my %rrr;
sub should_use_root {
my ($keyword) = @_;
my $rrr_env = $ENV{'DEB_RULES_REQUIRES_ROOT'} // 'binary-targets';
$rrr_env =~ s/^\s++//;
$rrr_env =~ s/\s++$//;
return 0 if $rrr_env eq 'no';
return 1 if $rrr_env eq 'binary-targets';
return 0 if not defined($keyword);
%rrr = map { $_ => 1 } split(' ', $rrr_env) if not %rrr;
return 1 if exists($rrr{$keyword});
return 0;
}
}
# Returns the "gain root command" as a list suitable for passing as a part of the command to "doit()"
sub gain_root_cmd {
my $raw_cmd = $ENV{DEB_GAIN_ROOT_CMD} // $ENV{DPKG_GAIN_ROOT_CMD};
my $raw_cmd = $ENV{DEB_GAIN_ROOT_CMD};
return if not defined($raw_cmd) or $raw_cmd =~ m/^\s*+$/;
return split(' ', $raw_cmd);
}
sub root_requirements {
return 'legacy-root' if not DH_ENABLE_RRR_SUPPORT;
getpackages() if not %rrr;
return 'none' if exists($rrr{'no'});
return 'legacy-root' if exists($rrr{'binary-targets'});
my $rrr_env = $ENV{'DEB_RULES_REQUIRES_ROOT'} // 'binary-targets';
$rrr_env =~ s/^\s++//;
$rrr_env =~ s/\s++$//;
return 'none' if $rrr_env eq 'no';
return 'legacy-root' if $rrr_env eq 'binary-targets';
return 'targeted-promotion';
}
......
......@@ -26,6 +26,8 @@ $ENV{PATH} = "$ROOT_DIR:$ENV{PATH}" if $ENV{PATH} !~ m{\Q$ROOT_DIR\E/?:};
$ENV{PERL5LIB} = join(':', "${ROOT_DIR}/lib", (grep { defined } $ENV{PERL5LIB}))
if not $ENV{PERL5LIB} or $ENV{PERL5LIB} !~ m{\Q$ROOT_DIR\E(?:/lib)?/?:};
$ENV{DH_AUTOSCRIPTDIR} = "$ROOT_DIR/autoscripts";
# Nothing in the tests requires root.
$ENV{DEB_RULES_REQUIRES_ROOT} = 'no';
# Drop DEB_BUILD_PROFILES and DEB_BUILD_OPTIONS so they don't interfere
delete($ENV{DEB_BUILD_PROFILES});
......@@ -87,7 +89,7 @@ sub run_dh_tool {
sub uid_0_test_is_ok {
return $ROOT_OK if defined($ROOT_OK);
my $ok = 0;
if (Debian::Debhelper::Dh_Lib::DH_ENABLE_RRR_SUPPORT or $< == 0) {
if ($< == 0) {
$ok = 1;
} else {
system('fakeroot true 2>/dev/null');
......
......@@ -252,6 +252,7 @@ $ENV{DEB_BUILD_OPTIONS} = "parallel=5";
$tmp = write_debian_rules(<<'EOF');
#!/usr/bin/make -f
export DEB_RULES_REQUIRES_ROOT:=no
override_dh_auto_build:
$(MAKE)
%:
......
......@@ -22,9 +22,7 @@ if (uid_0_test_is_ok()) {
plan skip_all => 'fakeroot required';
}
my $NEEDS_ROOT = { 'needs_root' => 1 };
my $NEEDS_ROOT_NODOC_PROFILE = {
'needs_root' => 1,
my $NODOC_PROFILE = {
'env' => {
'DEB_BUILD_PROFILES' => 'nodoc',
},
......@@ -33,14 +31,14 @@ my $NEEDS_ROOT_NODOC_PROFILE = {
my $doc = "debian/docfile";
each_compat_subtest {
ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pbar', $doc));
ok(run_dh_tool('dh_installdocs', '-pbar', $doc));
ok(-e "debian/bar/usr/share/doc/bar/docfile");
remove_tree(qw(debian/foo debian/bar debian/baz));
};
each_compat_subtest {
#regression in debhelper 9.20160702 (#830309)
ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pbaz', '--link-doc=foo', $doc));
ok(run_dh_tool('dh_installdocs', '-pbaz', '--link-doc=foo', $doc));
ok(-l "debian/baz/usr/share/doc/baz");
ok(readlink("debian/baz/usr/share/doc/baz") eq 'foo');
......@@ -49,7 +47,7 @@ each_compat_subtest {
};
each_compat_subtest {
ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pfoo', '--link-doc=bar', $doc));
ok(run_dh_tool('dh_installdocs', '-pfoo', '--link-doc=bar', $doc));
ok(-l "debian/foo/usr/share/doc/foo");
ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
......@@ -61,7 +59,7 @@ each_compat_subtest {
each_compat_subtest {
# docs are ignored, but copyright file is still there
ok(run_dh_tool($NEEDS_ROOT_NODOC_PROFILE, 'dh_installdocs', $doc));
ok(run_dh_tool($NODOC_PROFILE, 'dh_installdocs', $doc));
for my $pkg (qw(foo bar baz)) {
ok(! -e "debian/$pkg/usr/share/doc/$pkg/docfile");
ok(-e "debian/$pkg/usr/share/doc/$pkg/copyright");
......@@ -71,7 +69,7 @@ each_compat_subtest {
each_compat_subtest {
# docs are ignored, but symlinked doc dir is still there
ok(run_dh_tool($NEEDS_ROOT_NODOC_PROFILE, 'dh_installdocs', '-pfoo', '--link-doc=bar', $doc));
ok(run_dh_tool($NODOC_PROFILE, 'dh_installdocs', '-pfoo', '--link-doc=bar', $doc));
ok(-l "debian/foo/usr/share/doc/foo");
ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
ok(! -e "debian/foo/usr/share/doc/bar/docfile");
......
......@@ -22,7 +22,7 @@ if (uid_0_test_is_ok()) {
each_compat_up_to_and_incl_subtest(10, sub {
make_path(qw(debian/foo debian/bar debian/baz));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit'));
ok(run_dh_tool('dh_installinit'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
ok(run_dh_tool('dh_clean'));
......@@ -32,14 +32,14 @@ each_compat_up_to_and_incl_subtest(10, sub {
each_compat_from_and_above_subtest(11, sub {
make_path(qw(debian/foo debian/bar debian/baz));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit'));
ok(run_dh_tool('dh_installinit'));
ok(! -e "debian/foo/lib/systemd/system/foo.service");
ok(!find_script('foo', 'postinst'));
ok(run_dh_tool('dh_clean'));
make_path(qw(debian/foo/lib/systemd/system/ debian/bar debian/baz));
install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit'));
ok(run_dh_tool('dh_installinit'));
ok(!find_script('foo', 'postinst'));
ok(run_dh_tool('dh_clean'));
});
......
......@@ -55,7 +55,7 @@ sub unit_is_started {
# Units are installed and enabled
each_compat_subtest {
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
ok(run_dh_tool( 'dh_installsystemd'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
unit_is_enabled('foo', 'foo', 1);
......@@ -66,7 +66,7 @@ each_compat_subtest {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
ok(run_dh_tool('dh_installsystemd'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
unit_is_enabled('foo', 'foo', 1);
......@@ -77,7 +77,7 @@ each_compat_subtest {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-start'));
ok(run_dh_tool('dh_installsystemd', '--no-start'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
unit_is_enabled('foo', 'foo', 1);
......@@ -88,8 +88,8 @@ each_compat_subtest {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-start', 'debian/foo.service'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '-p', 'foo', 'foo2.service'));
ok(run_dh_tool('dh_installsystemd', '--no-start', 'debian/foo.service'));
ok(run_dh_tool('dh_installsystemd', '-p', 'foo', 'foo2.service'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
unit_is_enabled('foo', 'foo', 1);
......@@ -100,8 +100,8 @@ each_compat_subtest {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-enable', 'debian/foo.service'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '-p', 'foo', 'foo2.service'));
ok(run_dh_tool('dh_installsystemd', '--no-enable', 'debian/foo.service'));
ok(run_dh_tool('dh_installsystemd', '-p', 'foo', 'foo2.service'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(find_script('foo', 'postinst'));
unit_is_enabled('foo', 'foo', 0, 1); # Disabled units are still masked on removal
......@@ -111,7 +111,7 @@ each_compat_subtest {
ok(run_dh_tool('dh_clean'));
make_path('debian/foo/lib/systemd/system/');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-restart-after-upgrade'));
ok(run_dh_tool('dh_installsystemd', '--no-restart-after-upgrade'));
my @foo_postinst = find_script('foo', 'postinst');
ok(@foo_postinst);
my $matches = @foo_postinst ? grep { m{deb-systemd-invoke start .*foo.service} } `cat @foo_postinst` : -1;
......@@ -121,7 +121,7 @@ each_compat_subtest {
# Quoting #764730
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
ok(run_dh_tool('dh_installsystemd'));
unit_is_enabled('foo', 'foo\x2dfuse', 1);
unit_is_started('foo', 'foo\x2dfuse', 1);
ok(run_dh_tool('dh_clean'));
......@@ -129,12 +129,12 @@ each_compat_subtest {
# --name flag #870768
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--name=foo'));
ok(run_dh_tool('dh_installsystemd', '--name=foo'));
unit_is_enabled('foo', 'foo', 1);
unit_is_started('foo', 'foo', 1);
unit_is_enabled('foo', 'foo2', 0);
unit_is_started('foo', 'foo2', 0);
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--name=foo2'));
ok(run_dh_tool('dh_installsystemd', '--name=foo2'));
unit_is_enabled('foo', 'foo', 1);
unit_is_started('foo', 'foo', 1);
unit_is_enabled('foo', 'foo2', 1);
......
......@@ -25,8 +25,8 @@ if (uid_0_test_is_ok()) {
each_compat_from_and_above_subtest(11, sub {
make_path('debian/foo/usr/lib/tmpfiles.d');
create_empty_file('debian/foo/usr/lib/tmpfiles.d/foo.conf');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
ok(run_dh_tool('dh_installinit'));
ok(run_dh_tool('dh_installsystemd'));
ok(-e "debian/foo/etc/init.d/foo");
ok(-e "debian/foo/lib/systemd/system/foo.service");
my @postinst = find_script('foo', 'postinst');
......
......@@ -51,8 +51,8 @@ sub unit_is_started {
# Units are installed and enabled
each_compat_up_to_and_incl_subtest(10, sub {
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start'));
ok(run_dh_tool('dh_systemd_enable'));
ok(run_dh_tool('dh_systemd_start'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(-e "debian/foo.postinst.debhelper");
unit_is_enabled('foo', 'foo', 1);
......@@ -63,8 +63,8 @@ each_compat_up_to_and_incl_subtest(10, sub {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start'));
ok(run_dh_tool('dh_systemd_enable'));
ok(run_dh_tool('dh_systemd_start'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(-e "debian/foo.postinst.debhelper");
unit_is_enabled('foo', 'foo', 1);
......@@ -75,8 +75,8 @@ each_compat_up_to_and_incl_subtest(10, sub {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-start'));
ok(run_dh_tool('dh_systemd_enable'));
ok(run_dh_tool('dh_systemd_start', '--no-start'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(-e "debian/foo.postinst.debhelper");
unit_is_enabled('foo', 'foo', 1);
......@@ -87,9 +87,9 @@ each_compat_up_to_and_incl_subtest(10, sub {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-start', 'debian/foo.service'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '-p', 'foo', 'foo2.service'));
ok(run_dh_tool('dh_systemd_enable'));
ok(run_dh_tool('dh_systemd_start', '--no-start', 'debian/foo.service'));
ok(run_dh_tool('dh_systemd_start', '-p', 'foo', 'foo2.service'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(-e "debian/foo.postinst.debhelper");
unit_is_enabled('foo', 'foo', 1);
......@@ -100,9 +100,9 @@ each_compat_up_to_and_incl_subtest(10, sub {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable', '--no-enable', 'debian/foo.service'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable', '-p', 'foo', 'foo2.service'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start'));
ok(run_dh_tool('dh_systemd_enable', '--no-enable', 'debian/foo.service'));
ok(run_dh_tool('dh_systemd_enable', '-p', 'foo', 'foo2.service'));
ok(run_dh_tool('dh_systemd_start'));
ok(-e "debian/foo/lib/systemd/system/foo.service");
ok(-e "debian/foo.postinst.debhelper");
unit_is_enabled('foo', 'foo', 0, 1); # Disabled units are still masked on removal
......@@ -113,7 +113,7 @@ each_compat_up_to_and_incl_subtest(10, sub {
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-restart-after-upgrade'));
ok(run_dh_tool('dh_systemd_start', '--no-restart-after-upgrade'));
my $matches = grep { m{deb-systemd-invoke start .*foo.service} } `cat debian/foo.postinst.debhelper`;
ok($matches == 1);
ok(run_dh_tool('dh_clean'));
......@@ -121,8 +121,8 @@ each_compat_up_to_and_incl_subtest(10, sub {
# Quoting #764730
make_path('debian/foo/lib/systemd/system/');
install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service');
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start'));
ok(run_dh_tool('dh_systemd_enable'));
ok(run_dh_tool('dh_systemd_start'));
unit_is_enabled('foo', 'foo\x2dfuse', 1);
unit_is_started('foo', 'foo\x2dfuse', 1);
ok(run_dh_tool('dh_clean'));
......
......@@ -29,7 +29,7 @@ mv_conffile /etc/2 /etc/3 1.0-1
EOF
close($fd) or die("close($file): $!\n");
run_dh_tool( { 'needs_root' => 1 }, 'dh_installdeb');
run_dh_tool('dh_installdeb');
for my $script (@scripts) {
my @output=`cat debian/debhelper.$script.debhelper`;
......@@ -50,7 +50,7 @@ ${contents}
EOF
close($fd) or die("close($file): $!\n");
my $res = run_dh_tool( { 'needs_root' => 1, 'quiet' => 1 }, 'dh_installdeb');
my $res = run_dh_tool( { 'quiet' => 1 }, 'dh_installdeb');
remove_tree('debian/debhelper', 'debian/tmp', 'debian/.debhelper');
rm_files(@scripts);
......