diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-08-07 14:18:06 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-08-07 14:18:06 +0000 |
commit | 11c8b909d521fdf96aff3b931e828f9a94646216 (patch) | |
tree | 99a37f75557a487f0961e7d95eeb3638aae23358 | |
parent | c3d7ac66121443cc12be9008b2bb13e9b25ecc9e (diff) |
wrapper around Ustar that replaces long names/links with LongName#/LongLink#.
The archive will unpack correctly with tar, except that those names won't
be preserved.
The wrapper checks names against the packing-list to restore the correct names
on the fly.
Put into a separate file, as it is an extension of Ustar proper, and we're
going to do more archive checking in the future.
Lots of tests by Bernd Ahlers. Comments by Tom Cosgrove.
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 17 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/ArcCheck.pm | 82 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_create | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_merge | 7 |
5 files changed, 98 insertions, 16 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 67bbdca7707..96ea294cc3c 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.24 2005/06/28 20:34:55 espie Exp $ +# $OpenBSD: Makefile,v 1.25 2005/08/07 14:18:04 espie Exp $ .include <bsd.own.mk> @@ -8,6 +8,7 @@ POD2MAN=/usr/bin/pod2man PACKAGES= \ OpenBSD/Add.pm \ + OpenBSD/ArcCheck.pm \ OpenBSD/CollisionReport.pm \ OpenBSD/Delete.pm \ OpenBSD/Error.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 5b86a5efb91..09e82d4171c 100644 --- a/usr.sbin/pkg_add/OpenBSD/Add.pm +++ b/usr.sbin/pkg_add/OpenBSD/Add.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Add.pm,v 1.34 2005/08/05 09:52:08 espie Exp $ +# $OpenBSD: Add.pm,v 1.35 2005/08/07 14:18:05 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -20,6 +20,7 @@ use warnings; package OpenBSD::Add; use OpenBSD::Error; use OpenBSD::PackageInfo; +use OpenBSD::ArcCheck; use File::Copy; sub manpages_index @@ -342,10 +343,11 @@ sub prepare_to_extract my $destdir = $state->{destdir}; my $file=$state->{archive}->next(); + $file->{cwd} = $self->cwd(); if (!defined $file) { Fatal "Error: truncated archive\n"; } - if ($file->{name} ne $self->{name}) { + if (!$file->check_name($self->{name})) { Fatal "Error: archive does not match ", $file->{name}, "!=", $self->{name}, "\n"; } @@ -353,7 +355,7 @@ sub prepare_to_extract unless (defined $self->{symlink} && $file->isSymLink()) { Fatal "Error: bogus symlink ", $self->{name}, "\n"; } - if ($self->{symlink} ne $file->{linkname}) { + if (!$file->check_linkname($self->{symlink})) { Fatal "Error: archive sl does not match ", $file->{linkname}, "!=", $self->{symlink}, "\n"; } @@ -361,18 +363,13 @@ sub prepare_to_extract unless (defined $self->{link} && $file->isHardLink()) { Fatal "Error: bogus hardlink ", $self->{name}, "\n"; } - my $linkname = $file->{linkname}; - if (defined $self->{cwd}) { - $linkname = $self->cwd().'/'.$linkname; - } - if ($self->{link} ne $linkname) { - Fatal "Error: archive hl does not match ", $linkname, "!=", + if (!$file->check_linkname($self->{link})) { + Fatal "Error: archive hl does not match ", $file->{linkname}, "!=", $self->{link}, "!!!\n"; } } $file->{name} = $fullname; - $file->{cwd} = $self->cwd(); $file->{destdir} = $destdir; # faked installation are VERY weird if (defined $self->{symlink} && $state->{do_faked}) { diff --git a/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm new file mode 100644 index 00000000000..8e1702d86be --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm @@ -0,0 +1,82 @@ +# ex:ts=8 sw=4: +# $OpenBSD: ArcCheck.pm,v 1.1 2005/08/07 14:18:05 espie Exp $ +# +# Copyright (c) 2005 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# Supplementary code to handle archives. + +package OpenBSD::Ustar::Object; + +sub check_name +{ + my ($self, $name) = @_; + return 1 if $self->{name} eq $name; + if ($self->{name} =~ m/^LongName\d+$/) { + $self->{name} = $name; + return 1; + } + return 0; +} + +sub check_linkname +{ + my ($self, $linkname) = @_; + my $c = $self->{linkname}; + if ($self->isHardLink() && defined $self->{cwd}) { + $c = $self->{cwd}.'/'.$c; + } + return 1 if $c eq $linkname; + if ($self->{linkname} =~ m/^Long(?:Link|Name)\d+$/) { + $self->{linkname} = $linkname; + if ($self->isHardLink() && defined $self->{cwd}) { + $self->{linkname} =~ s|^$self->{cwd}/||; + } + return 1; + } + return 0; +} + +sub copy_long +{ + my ($self, $wrarc) = @_; + if ($self->{name} =~ m/^LongName(\d+)$/) { + $wrarc->{name_index} = $1 + 1; + } + if (length($self->{name}) > MAXFILENAME+MAXPREFIX+1) { + $wrarc->{name_index} = 0 if !defined $wrarc->{name_index}; + $entry->{name} = 'LongName'.$wrarc->{name_index}++; + } + $self->copy($wrarc); +} + +package OpenBSD::Ustar; + +sub prepare_long +{ + my ($self, $filename) = @_; + my $entry = $self->prepare($filename); + my ($prefix, $name) = split_name($entry->{name}); + if (length($name) > MAXFILENAME || length($prefix) > MAXPREFIX) { + $self->{name_index} = 0 if !defined $self->{name_index}; + $entry->{name} = 'LongName'.$self->{name_index}++; + } + if (length($entry->{linkname}) > MAXLINKNAME) { + $self->{linkname_index} = 0 if !defined $self->{linkname_index}; + $entry->{linkname} = 'LongLink'.$self->{linkname_index}++; + } + return $entry; +} + +1; diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create index 5dd429c982b..8e5520b8d82 100644 --- a/usr.sbin/pkg_add/pkg_create +++ b/usr.sbin/pkg_add/pkg_create @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_create,v 1.35 2005/06/26 11:24:06 espie Exp $ +# $OpenBSD: pkg_create,v 1.36 2005/08/07 14:18:04 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -25,6 +25,7 @@ use OpenBSD::md5; use OpenBSD::Temp; use OpenBSD::Error; use OpenBSD::Ustar; +use OpenBSD::ArcCheck; use Symbol; use File::Basename; @@ -40,7 +41,7 @@ sub archive my ($self, $arc, $base, $verbose) = @_; if (defined $arc) { - my $o = $arc->prepare($self->{name}); + my $o = $arc->prepare_long($self->{name}); $o->write(); } if ($verbose) { diff --git a/usr.sbin/pkg_add/pkg_merge b/usr.sbin/pkg_add/pkg_merge index bd3cab8723b..9b71291b599 100644 --- a/usr.sbin/pkg_add/pkg_merge +++ b/usr.sbin/pkg_add/pkg_merge @@ -20,6 +20,7 @@ use OpenBSD::PackingList; use OpenBSD::Getopt; use OpenBSD::Error; use OpenBSD::Ustar; +use OpenBSD::ArcCheck; use File::Copy; use File::Path; @@ -40,18 +41,18 @@ sub copy_over { my ($self, $wrarc, $prefix, $pkg) = @_; my $e = $pkg->{pkg}->next(); - if ($e->{name} ne $self->{name}) { + if (!$e->check_name($self->{name})) { die "Names don't match: ", $e->{name}, " ", $self->{name}; } $e->{name} = $prefix."/".$e->{name}; - $e->copy($wrarc); + $e->copy_long($wrarc); } sub make_alias { my ($self, $wrarc, $prefix, $pkg, $alias) = @_; my $e = $pkg->{pkg}->next(); - if ($e->{name} ne $self->{name}) { + if (!$e->check_name($self->{name})) { die "Names don't match: ", $e->{name}, " ", $self->{name}; } $e->{name} = $prefix."/".$e->{name}; |