ArcCheck.pm revision 1.6
1# ex:ts=8 sw=4: 2# $OpenBSD: ArcCheck.pm,v 1.6 2007/05/02 15:05:29 espie Exp $ 3# 4# Copyright (c) 2005-2006 Marc Espie <espie@openbsd.org> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 18# Supplementary code to handle archives in the package context. 19# Contrarily to GNU-tar, we do not change the archive format, but by 20# convention, the names LongName\d+ and LongLink\d correspond to names 21# too long to fit. The actual names reside in the PLIST, but the archive 22# is still a valid archive. 23# 24 25package OpenBSD::Ustar::Object; 26 27# match archive header name against PackingElement item 28sub check_name 29{ 30 my ($self, $item) = @_; 31 return 1 if $self->{name} eq $item->{name}; 32 if ($self->{name} =~ m/^LongName\d+$/) { 33 $self->{name} = $item->{name}; 34 return 1; 35 } 36 return 0; 37} 38 39# match archive header link name against actual link names 40sub check_linkname 41{ 42 my ($self, $linkname) = @_; 43 my $c = $self->{linkname}; 44 if ($self->isHardLink && defined $self->{cwd}) { 45 $c = $self->{cwd}.'/'.$c; 46 } 47 return 1 if $c eq $linkname; 48 if ($self->{linkname} =~ m/^Long(?:Link|Name)\d+$/) { 49 $self->{linkname} = $linkname; 50 if ($self->isHardLink && defined $self->{cwd}) { 51 $self->{linkname} =~ s|^$self->{cwd}/||; 52 } 53 return 1; 54 } 55 return 0; 56} 57 58# copy long items, avoiding duplicate long names. 59sub copy_long 60{ 61 my ($self, $wrarc) = @_; 62 if ($self->{name} =~ m/^LongName(\d+)$/) { 63 $wrarc->{name_index} = $1 + 1; 64 } 65 if (length($self->{name}) > MAXFILENAME+MAXPREFIX+1) { 66 $wrarc->{name_index} = 0 if !defined $wrarc->{name_index}; 67 $entry->{name} = 'LongName'.$wrarc->{name_index}++; 68 } 69 $self->copy($wrarc); 70} 71 72package OpenBSD::Ustar; 73 74# prepare item and introduce long names where needed. 75sub prepare_long 76{ 77 my ($self, $item) = @_; 78 my $filename = $item->{name}; 79 my $entry = $self->prepare($filename); 80 if (!defined $entry->{uname}) { 81 die "No user name for ", $entry->{name}, " (uid ", $entry->{uid}, ")\n"; 82 } 83 if (!defined $entry->{gname}) { 84 die "No group name for ", $entry->{name}, " (gid ", $entry->{gid}. "\n"; 85 } 86 my ($prefix, $name) = split_name($entry->{name}); 87 if (length($name) > MAXFILENAME || length($prefix) > MAXPREFIX) { 88 $self->{name_index} = 0 if !defined $self->{name_index}; 89 $entry->{name} = 'LongName'.$self->{name_index}++; 90 } 91 if (length($entry->{linkname}) > MAXLINKNAME) { 92 $self->{linkname_index} = 0 if !defined $self->{linkname_index}; 93 $entry->{linkname} = 'LongLink'.$self->{linkname_index}++; 94 } 95 return $entry; 96} 97 981; 99