2
# Chroot.pm: chroot library for sbuild
3
# Copyright © 2005 Ryan Murray <rmurray@debian.org>
4
# Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
5
# Copyright © 2008 Simon McVittie <smcv@debian.org>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see
19
# <http://www.gnu.org/licenses/>.
21
#######################################################################
23
package Sbuild::ChrootPlain;
34
use Sbuild::Sysconfig;
41
@ISA = qw(Exporter Sbuild::Chroot);
49
my $chroot_id = shift;
51
my $self = $class->SUPER::new($conf, $chroot_id);
54
# Only run split, because plain makes no guarantee that networking
55
# works inside the chroot.
56
$self->set('Split', 1);
64
$self->set('Priority', 0);
65
$self->set('Location', $self->get('Chroot ID'));
66
$self->set('Session Purged', 0);
68
$self->_setup_options();
81
sub get_command_internal {
85
my $command = $options->{'INTCOMMAND'}; # Command to run
86
my $user = $options->{'USER'}; # User to run command under
87
my $chroot = $options->{'CHROOT'}; # Run in chroot?
88
my $dir; # Directory to use (optional)
89
$dir = $self->get('Defaults')->{'DIR'} if
90
(defined($self->get('Defaults')) &&
91
defined($self->get('Defaults')->{'DIR'}));
92
$dir = $options->{'DIR'} if
93
defined($options->{'DIR'}) && $options->{'DIR'};
95
if (!defined $user || $user eq "") {
96
$user = $self->get_conf('USERNAME');
98
if (!defined $chroot) {
104
if ($chroot != 0) { # Run command inside chroot
105
if (!defined($dir)) {
110
foreach (@$command) {
112
$tmp =~ s/'//g; # Strip any single quotes for security
114
$self->log_warning("Stripped single quote from command for security: $_\n");
117
$shellcommand .= " '$tmp'";
119
$shellcommand = "'$tmp'";
123
@cmdline = ('/usr/sbin/chroot', $self->get('Location'),
124
$self->get_conf('SU'), '-p', "$user", '-s',
125
$Sbuild::Sysconfig::programs{'SHELL'}, '-c',
126
"cd '$dir' && $shellcommand");
127
} else { # Run command outside chroot
128
if ($options->{'CHDIR_CHROOT'}) {
129
my $tmpdir = $self->get('Location');
130
$tmpdir = $tmpdir . $dir if defined($dir);
133
if ($user ne $self->get_conf('USERNAME')) {
134
print main::LOG "Command \"$command\" cannot be run as user $user on the host system\n";
136
$chdir = $dir if defined($dir);
137
push(@cmdline, @$command);
140
$options->{'CHROOT'} = $chroot;
141
$options->{'USER'} = $user;
142
$options->{'COMMAND'} = $command;
143
$options->{'EXPCOMMAND'} = \@cmdline;
144
$options->{'CHDIR'} = $chdir;
145
$options->{'DIR'} = $dir;