lintian: r395 - in trunk: debian frontend lib
Author: djpig
Date: 2004-12-27 05:42:21 +0100 (Mon, 27 Dec 2004)
New Revision: 395
Modified:
trunk/debian/changelog
trunk/frontend/lintian
trunk/lib/Lab.pm
Log:
SECURITY (CAN-2004-1000):
Overhaul lab directory handling. This also fixes the issue
of removing a lab that never was created (Closes: #286681)
Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog 2004-12-27 04:30:04 UTC (rev 394)
+++ trunk/debian/changelog 2004-12-27 04:42:21 UTC (rev 395)
@@ -35,8 +35,13 @@
don't issue no-standards-version-field for them. (If they happen to
have a Standards-Version field anyway, we still check that it's
valid.)
+
+ * lib/Lab.pm, frontend/lintian:
+ SECURITY (CAN-2004-1000):
+ + [FL] Overhaul lab directory handling. This also fixes the issue
+ of removing a lab that never was created (Closes: #286681)
- -- Marc 'HE' Brockschmidt <he@debian.org> Sat, 18 Dec 2004 13:13:11 +0100
+ -- Debian Lintian Maintainers <lintian-maint@debian.org> Mon, 27 Dec 2004 05:40:13 +0100
lintian (1.23.5) unstable; urgency=low
Modified: trunk/frontend/lintian
===================================================================
--- trunk/frontend/lintian 2004-12-27 04:30:04 UTC (rev 394)
+++ trunk/frontend/lintian 2004-12-27 04:42:21 UTC (rev 395)
@@ -73,7 +73,7 @@
my $cwd;
my $cleanup_filename;
my $exit_code;
-my $lab_mode = 'static';
+my $LAB;
my %collection_info;
my %already_scheduled;
@@ -405,19 +405,11 @@
}
if ($LINTIAN_LAB) {
- # LINTIAN_LAB defined => advanced mode (static lab)
- $lab_mode = 'static';
+ $ENV{'LINTIAN_LAB'} = $LINTIAN_LAB;
} else {
- # LINTIAN_LAB not defined => basic mode (temporary lab)
- $lab_mode = 'temporary';
-
- if ($ENV{'TMPDIR'}) {
- $LINTIAN_LAB = "$ENV{'TMPDIR'}/lintian-lab.$$";
- } else {
- $LINTIAN_LAB = "/tmp/lintian-lab.$$";
- }
+ $ENV{'LINTIAN_LAB'} = "";
+ $LINTIAN_LAB = "";
}
-$ENV{'LINTIAN_LAB'} = $LINTIAN_LAB;
if ($LINTIAN_ARCHIVEDIR) {
$ENV{'LINTIAN_ARCHIVEDIR'} = $LINTIAN_ARCHIVEDIR;
@@ -511,14 +503,8 @@
# {{{ Create/Maintain Lab and add any specified Debian Archives (*.debs)
-# sanity check:
-if (($action ne 'setup-lab') and ($lab_mode eq 'static')) {
+$LAB = new Lab( $LINTIAN_LAB, $LINTIAN_DIST );
- # LINTIAN_LAB has to exist in this mode
- fail("lintian lab has not been set up correctly (run lintian --setup-lab)")
- unless Lab::is_lab($LINTIAN_LAB);
-}
-
#######################################
# Process -S option
if ($action eq 'setup-lab') {
@@ -526,16 +512,9 @@
print STDERR "warning: ignoring additional command line arguments\n";
}
- if ($lab_mode eq 'temporary') {
- fail("no laboratory specified (need to define LINTIAN_LAB)");
- }
+ $LAB->setup_static()
+ or fail("There was an error while setting up the static lab.");
- Lab::setup($LINTIAN_LAB, $lab_mode);
-
- # No idea what this is needed here, but it used to be in the code, so I'll
- # leave it untouched for the moment
- Lab::populate_with_dist($LINTIAN_LAB, $LINTIAN_DIST) if $LINTIAN_DIST;
-
exit 0;
#######################################
@@ -545,12 +524,9 @@
print STDERR "warning: ignoring additional command line arguments\n";
}
- if ($lab_mode eq 'temporary') {
- fail("no laboratory specified (need to define LINTIAN_LAB)");
- }
+ $LAB->delete_static()
+ or fail("There was an error while removing the static lab.");
- Lab::delete($LINTIAN_LAB, $lab_mode);
-
exit 0;
#######################################
@@ -560,6 +536,13 @@
fail("bad action $action specified");
}
+# sanity check:
+fail("lintian lab has not been set up correctly (perhaps you forgot to run lintian --setup-lab?)")
+ unless $LAB->is_lab();
+
+#XXX: There has to be a cleaner way to do this
+$LINTIAN_LAB = $LAB->{dir};
+
# }}}
# {{{ Setup the lintian-info pipe
@@ -1008,16 +991,6 @@
}
# }}}
-# {{{ Create temp lab if needed (Why here??)
-if ($lab_mode eq 'temporary') {
- # TODO: register signal handler to remove lab when C-C is pressed
-
- # create lab
- Lab::setup($LINTIAN_LAB, $lab_mode);
- Lab::populate_with_dist($LINTIAN_LAB, $LINTIAN_DIST) if $LINTIAN_DIST;
-}
-# }}}
-
# {{{ process all packages in the archive?
if ($check_everything) {
# make sure package info is available
@@ -1559,7 +1532,10 @@
# Prevent Lab::delete from affecting the exit code.
local $?;
- Lab::delete($LINTIAN_LAB, $lab_mode) if $lab_mode eq 'temporary';
+ $SIG{'INT'} = 'DEFAULT';
+ $SIG{'QUIT'} = 'DEFAULT';
+
+ $LAB->delete() if $LAB;
}
sub interrupted {
Modified: trunk/lib/Lab.pm
===================================================================
--- trunk/lib/Lab.pm 2004-12-27 04:30:04 UTC (rev 394)
+++ trunk/lib/Lab.pm 2004-12-27 04:42:21 UTC (rev 395)
@@ -25,6 +25,8 @@
use Pipeline;
use Util;
+use File::Temp;
+
my $LINTIAN_ROOT = $::LINTIAN_ROOT;
# Can also be more precise later on (only verbose with lab actions) but for
@@ -32,118 +34,190 @@
my $verbose = $::verbose;
my $debug = $::debug;
+sub new {
+ my ( $class, $dir, $dist ) = @_;
+
+ my $self = {};
+ bless $self, $class;
+
+ $self->setup( $dir, $dist );
+ return $self;
+}
+
+
sub is_lab {
- my $labdir = shift;
+ my ( $self ) = @_;
- return -d "$labdir/binary"
- && -d "$labdir/udeb"
- && -d "$labdir/source"
- && -d "$labdir/info";
+ return unless $self->{dir};
+ return -d "$self->{dir}/binary"
+ && -d "$self->{dir}/udeb"
+ && -d "$self->{dir}/source"
+ && -d "$self->{dir}/info";
}
sub setup {
- my $LINTIAN_LAB = shift;
- my $lab_mode = shift;
+ my ( $self, $dir, $dist ) = @_;
- print "N: Setting up lab in $LINTIAN_LAB ...\n" if $verbose;
+ if ( $dir ) {
+ $self->{mode} = 'static';
+ $self->{dir} = $dir;
+ $self->{dist} = $dist;
+ } else {
+ $self->{mode} = 'temporary';
- # create lab directory
- if (not -d "$LINTIAN_LAB" or ($lab_mode eq 'temporary')) {
- # (Note, that the mode 0777 is reduced by the current umask.)
- mkdir($LINTIAN_LAB,0777) or fail("cannot create lab directory $LINTIAN_LAB");
+ $dir = tmpnam();
+
+ $self->setup_force( $dir, $dist );
}
+ return 1;
+}
+
+sub setup_static {
+ my ( $self ) = @_;
+
+ unless ( $self->{mode} eq 'static' and $self->{dir} ) {
+ print STDERR "no laboratory specified (need to define LINTIAN_LAB)";
+ return 0;
+ }
+
+ return $self->setup_force( $self->{dir}, $self->{dist} );
+}
+
+
+sub setup_force {
+ my ( $self, $dir, $dist ) = @_;
+
+ return unless $dir;
+
+ print "N: Setting up lab in $dir ...\n" if $verbose;
+
+ # create lab directory
+ # (Note, that the mode 0777 is reduced by the current umask.)
+ mkdir($dir,0777) or fail("cannot create lab directory $dir");
+
# create base directories
- if (not -d "$LINTIAN_LAB/binary") {
- mkdir("$LINTIAN_LAB/binary",0777) or fail("cannot create lab directory $LINTIAN_LAB/binary");
+ for my $subdir (qw( binary source udeb info )) {
+ my $fulldir = "$dir/$subdir";
+ if (not -d $fulldir) {
+ mkdir($fulldir, 0777)
+ or fail("cannot create lab directory $fulldir");
+ }
}
- if (not -d "$LINTIAN_LAB/source") {
- mkdir("$LINTIAN_LAB/source",0777) or fail("cannot create lab directory $LINTIAN_LAB/source");
+
+ # just create empty files
+ for my $pkgtype (qw( binary source udeb )) {
+ _touch("$dir/info/$pkgtype-packages")
+ or fail("cannot create $pkgtype package list");
}
- if (not -d "$LINTIAN_LAB/udeb") {
- mkdir("$LINTIAN_LAB/udeb",0777) or fail("cannot create lab directory $LINTIAN_LAB/udeb");
- }
- if (not -d "$LINTIAN_LAB/info") {
- mkdir("$LINTIAN_LAB/info",0777) or fail("cannot create lab directory $LINTIAN_LAB/info");
- }
- # just create empty files
- _touch("$LINTIAN_LAB/info/binary-packages")
- or fail("cannot create binary package list");
- _touch("$LINTIAN_LAB/info/source-packages")
- or fail("cannot create source package list");
- _touch("$LINTIAN_LAB/info/udeb-packages")
- or fail("cannot create udeb package list");
+
+ $self->{dir} = $dir;
+ $ENV{'LINTIAN_LAB'} = $dir;
+ $self->populate_with_dist( $dist );
+
+ return 1;
}
sub populate_with_dist {
- my $LINTIAN_LAB = shift;
- my $LINTIAN_DIST = shift;
+ my ( $self, $dist ) = @_;
- print STDERR "spawning list-binpkg, list-udebpkg and list-srcpkg since LINTIAN_DIST=$LINTIAN_DIST\n" if ($debug >= 2);
+ return 0 unless $dist;
+ return 0 unless $self->{dir};
- my $v = $verbose ? '-v' : '';
+ print STDERR "spawning list-binpkg, list-udebpkg and list-srcpkg since LINTIAN_DIST=$dist\n" if ($debug >= 2);
- spawn("$LINTIAN_ROOT/unpack/list-binpkg",
- "$LINTIAN_LAB/info/binary-packages", $v) == 0
- or fail("cannot create binary package list");
- spawn("$LINTIAN_ROOT/unpack/list-srcpkg",
- "$LINTIAN_LAB/info/source-packages", $v) == 0
- or fail("cannot create source package list");
- spawn("$LINTIAN_ROOT/unpack/list-udebpkg",
- "$LINTIAN_LAB/info/udeb-packages", $v) == 0
- or fail("cannot create udeb package list");
+ my $v = $verbose ? '-v' : '';
+
+ spawn("$LINTIAN_ROOT/unpack/list-binpkg",
+ "$self->{dir}/info/binary-packages", $v) == 0
+ or fail("cannot create binary package list");
+ spawn("$LINTIAN_ROOT/unpack/list-srcpkg",
+ "$self->{dir}/info/source-packages", $v) == 0
+ or fail("cannot create source package list");
+ spawn("$LINTIAN_ROOT/unpack/list-udebpkg",
+ "$self->{dir}/info/udeb-packages", $v) == 0
+ or fail("cannot create udeb package list");
+
+ return 1;
}
-# Remove is apparantly some reserved name...
+sub delete_static {
+ my ( $self ) = @_;
+
+ unless ( $self->{mode} eq 'static' and $self->{dir} ) {
+ print STDERR "warning: no laboratory specified (need to define LINTIAN_LAB)";
+ return 0;
+ }
+
+ return $self->delete_force;
+}
+
sub delete {
- my $LINTIAN_LAB = shift;
- my $lab_mode = shift;
+ my ( $self ) = @_;
- $SIG{'INT'} = 'DEFAULT';
- $SIG{'QUIT'} = 'DEFAULT';
+ return 1 unless $self->{mode} eq 'temporary';
- print "N: Removing $LINTIAN_LAB ...\n" if $verbose;
+ return $self->delete_force;
+}
+# Remove is apparantly some reserved name...
+sub delete_force {
+ my ( $self ) = @_;
+
+ return 0 unless $self->{dir};
+
+ print "N: Removing $self->{dir} ...\n" if $verbose;
+
+ # since we will chdir in a moment, make the path of the lab absolute
+ unless ( $self->{dir} =~ m,^/, ) {
+ require Cwd;
+ $self->{dir} = Cwd::getcwd() . "/$self->{dir}";
+ }
+
# chdir to root (otherwise, the shell will complain if we happen
# to sit in the directory we want to delete :)
chdir('/');
# does the lab exist?
- unless (-d "$LINTIAN_LAB") {
+ unless (-d $self->{dir}) {
# no.
- print STDERR "warning: cannot remove lab in directory $LINTIAN_LAB ! (directory does not exist)\n";
- return;
+ print STDERR "warning: cannot remove lab in directory $self->{dir} ! (directory does not exist)\n";
+ return 0;
}
- # sanity check if $LINTIAN_LAB really points to a lab :)
- unless (-d "$LINTIAN_LAB/binary") {
+ # sanity check if $self->{dir} really points to a lab :)
+ unless (-d "$self->{dir}/binary") {
# binary/ subdirectory does not exist--empty directory?
- my @t = <$LINTIAN_LAB/*>;
+ my @t = glob("$self->{dir}/*");
if ($#t+1 <= 2) {
# yes, empty directory--skip it
- return;
+ return 1;
} else {
# non-empty directory that does not look like a lintian lab!
- print STDERR "warning: directory $LINTIAN_LAB does not look like a lab! (please remove it yourself)\n";
- return;
+ print STDERR "warning: directory $self->{dir} does not look like a lab! (please remove it yourself)\n";
+ return 0;
}
}
# looks ok.
if (spawn('rm', '-rf', '--',
- "$LINTIAN_LAB/binary",
- "$LINTIAN_LAB/source",
- "$LINTIAN_LAB/udeb",
- "$LINTIAN_LAB/info") != 0) {
- print STDERR "warning: cannot remove lab directory $LINTIAN_LAB (please remove it yourself)\n";
+ "$self->{dir}/binary",
+ "$self->{dir}/source",
+ "$self->{dir}/udeb",
+ "$self->{dir}/info") != 0) {
+ print STDERR "warning: cannot remove lab directory $self->{dir} (please remove it yourself)\n";
}
# dynamic lab?
- if ($lab_mode eq 'temporary') {
- if (rmdir($LINTIAN_LAB) != 1) {
- print STDERR "warning: cannot remove lab directory $LINTIAN_LAB (please remove it yourself)\n";
+ if ($self->{mode} eq 'temporary') {
+ if (rmdir($self->{dir}) != 1) {
+ print STDERR "warning: cannot remove lab directory $self->{dir} (please remove it yourself)\n";
}
}
+
+ $self->{dir} = "";
+
+ return 1;
}
# create an empty file
Reply to: