Commit Graph

123 Commits

Author SHA1 Message Date
Tim Kientzle
b77cfdd61e Ignore file flag bits that we don't support. In particular, this
corrects a segfault seen when archiving files from NTFS (which sets
bits in st_flags that are not documented in <sys/stat.h>.)

Thanks to: Doug Rabson
2004-06-19 04:19:27 +00:00
Tim Kientzle
9ad66a1eed Always restore permissions for regular files, even if the
file already exists on disk.

Pointed out by: www/resin3 port (whose distfile contains the same file
  twice with different permissions and relies on the permissions associated
  with the second instance)
Thanks again to: Kris Kennaway
2004-06-17 03:09:06 +00:00
Tim Kientzle
7e37ae50db Be a little more careful about creating directories:
* Restore directories with 0700 permissions initially,
   then use the fixup pass to correct the permissions
 * Trim trailing "/" and "/." in mkdirpath()

Suggested by: Garrett Wollman
2004-06-15 07:12:04 +00:00
Tim Kientzle
071a23c2d6 Correct some spelling errors. 2004-06-08 00:23:27 +00:00
Tim Kientzle
ce7fa714ab Linux (at least Debian) requires sys/types.h to get off_t. 2004-06-07 18:42:50 +00:00
Tim Kientzle
33e546958b History: A few very, very old tar programs used the filename to
distinguish files from dirs (trailing '/' indicated a dir).  Since
POSIX.1-1987, this convention is no longer necessary.  However, there
are current tar programs that pretend to write POSIX-compliant
archives, yet store directories as "regular files", relying on this
old filename convention to save them.  <sigh> So, move the check for
this old convention so it applies to all tar archives, not just those
identified as "old."

Pointed out by: Broken distfile for audio/faad port
2004-06-07 06:34:51 +00:00
Tim Kientzle
7d9005ce33 Tar bidder should just return a zero bid ("not me!") if
it sees a truncated input the first time it gets called.
(In particular, files shorter than 512 bytes cannot be tar archives.)
This allows the top-level archive_read_next_header code to
generate a proper error message for unrecognized file types.

Pointed out by: numerous ports that expect tar to extract non-tar files ;-(
Thanks to: Kris Kennaway
2004-06-07 04:32:10 +00:00
Tim Kientzle
16847cbdc4 Pointy hat: We can't avoid a chown() call without checking both UID
and GID.  Suppress a premature attempt at optimization.
2004-06-05 06:08:40 +00:00
Tim Kientzle
25354e55bf YAPHtM: Yet Another Pointy Hat to Me.
After calculating new dir permissions that allow creating files,
don't be stupid and use the original permissions.  <sigh>
2004-06-05 05:34:45 +00:00
Tim Kientzle
2474b73276 Recognize when we've accidentally created "foo/."
and don't complain about it.
2004-06-05 05:30:41 +00:00
Tim Kientzle
2b68caa0f2 Correctly reset archive_read_data state everytime a header is read. 2004-06-04 23:25:20 +00:00
Tim Kientzle
7a4f3ab2c4 Correct the layering violation in read_body_to_string. The previous
version called the higher-level archive_read_data and
archive_read_data_skip functions, which screwed up state management of
those functions.  This bit of mis-design has existed for a long time,
but became a serious issue with the recent changes to the
archive_read_data APIs, which added more internal state to the
high-level archive_read_data function.  Most common symptom was a
failure to correctly read 'L' entries (long filename) from GNU-style
archives, causing the message ": Can't open: No such file or
directory" with an empty filename.

Pointed out by:  Numerous port build failures
Thanks to: Kris Kennaway
2004-06-04 23:24:21 +00:00
Tim Kientzle
456db9b6db When we go to read the next tar header, if we get zero bytes, accept
that as end-of-archive.  Otherwise, a short read at this point
generates an error.  This accomodates broken tar writers (such as the
one apparently in use at AT&T Labs) that don't even write a single
end-of-archive block.

Note that both star and pdtar behave this way as well.
In contrast, gtar doesn't complain in either case, and as a
result, will generate no warning for a lot of trashed archives.

Pointed out by: shells/ksh93 port  (Thanks to Kris Kennaway)
2004-06-04 10:27:23 +00:00
Tim Kientzle
1a74b99db7 Be more careful about the initial read (used for "tasting" the compression):
* Check for and return input errors
  * Treat empty file (zero-length read) as a fatal error
2004-06-04 01:36:10 +00:00
Tim Kientzle
a8659f8468 Refactor the extraction code somewhat. In particular,
push extract data down into archive_read_extract.c and out
of the library-global archive_private.h; push dir-specific
mode/time fixup down into dir restore function; now that the
fixup list is file-local, I can use somewhat more natural
naming.

Oh, yeah, update a bunch of comments to match current reality.
2004-06-03 23:29:47 +00:00
Tim Kientzle
94dffc977c Add MLINKS for new API functions. 2004-06-02 08:16:21 +00:00
Tim Kientzle
e250dd4fad Refactor read_data:
* New read_data_block is both sparse-file aware and uses zero-copy semantics
 * Push read_data_block down into specific formats (opens door to
   various encoded entry bodies, such as zip or gtar -S)
 * Reimplement read_data, read_data_skip, read_data_into_fd in terms
   of new read_data_block.
 * Update documentation
It's unfortunate that I couldn't just call the new interface
archive_read_data, but didn't want to upset the API that much.
2004-06-02 08:14:43 +00:00
Tim Kientzle
14a60ae9a2 Connect libarchive decompress support to the build.
Also, add it to archive_read_support_compression_all()
so that typical clients get it pulled in by default.
2004-05-27 23:57:45 +00:00
Tim Kientzle
30230b4fd0 'gnutar' is now handled by the 'tar' reader, so
there's no need to enable support for it separately
from 'tar.'  (The call to enable gnutar support is
now just an alias for the tar support, left in to
avoid API breakage.)
2004-05-27 21:27:42 +00:00
Tim Kientzle
da725414f3 Previously, restoring an archive with hardlinked files that had
certain flags set (e.g., schg or uappend) would fail because the flags
were restored before the hardlink was created.

To address this, I've generalized the existing machinery for deferring
directory timestamp/mode restoration and used it to defer the
restoration of highly-restrictive flags to the end of the extraction,
after any links have been created.

Pointed out by: Pawel Jakub Dawidek (pjd@)
2004-05-27 05:02:35 +00:00
Tim Kientzle
2023cfd41b Document support for reading .Z compressed archives.
Correct a few other minor nits.
2004-05-27 04:21:52 +00:00
Tim Kientzle
5d425e1c12 GC some no-longer-used constants. 2004-05-27 04:01:58 +00:00
Tim Kientzle
ddf99967cc Add prototypes for .Z compression support. 2004-05-27 04:00:25 +00:00
Tim Kientzle
72271236bb Add read-only support for .Z compressed archives. 2004-05-27 03:58:55 +00:00
Tim Kientzle
b3fd17797d Correct parsing of Solaris default ACLs. 2004-05-21 09:01:13 +00:00
Tim Kientzle
5aedc78012 Nits fixed.
Pointed out by: Daniel Harris
2004-05-20 06:22:42 +00:00
Tim Kientzle
9e9662ef5b More research, more shuffling and clarification. 2004-05-20 04:12:47 +00:00
Tim Kientzle
22a2730797 When combining ustar prefix and name fields, check before adding a '/'
character, as some tar implementations incorrectly include a '/' with
the prefix.

Thanks to: Divacky Roman for the UnixWare 7 tarfile that
demonstrated this issue.
2004-05-19 17:09:24 +00:00
Tim Kientzle
ecad688385 I've recently been looking at the Seventh Edition source
code available at tuhs.org, and found out that my chronology
is a bit off.  In particular, Seventh Edition already used
the "linkflag" and "linkname" fields.  Also, it appears that
there was no tar in Sixth Edition, contrary to what an earlier
tar.1 manpage claimed.

A few mdoc fixes also crept in here.
2004-05-19 06:38:38 +00:00
Tim Kientzle
44c46f7978 Refine the heuristic used to determine whether or not to obey
the size field for a hardlink entry.  Specifically, ensure that
we do obey the size field for archives that we know are pax interchange
format archives, as required by POSIX.

Also, clarify the comment explaining why this is necessary and explain
the (very unusual) conditions under which it might fail.
2004-05-19 06:35:47 +00:00
Tim Kientzle
6c1a87e738 Be smarter about hardlink sizes: some tar programs write
a non-zero size but no body, some write a non-zero size and include
a body.  To distinguish these cases, look for a valid tar header immediately
following a hardlink header with non-zero size.
2004-05-18 18:16:30 +00:00
Tim Kientzle
f62681112e Clarify an error message. 2004-05-18 00:13:06 +00:00
Olivier Houchard
c1b2de5af0 Use WARNS?=3 for these in the arm case for now, due to toolchain issues. 2004-05-14 13:31:21 +00:00
Tim Kientzle
f9bc91709e Update raw byte count statistic correctly. 2004-05-13 06:38:30 +00:00
Tim Kientzle
4809584dd6 Add MLINK for newly-added archive_read_extract_set_progress_callback(3). 2004-05-13 06:04:21 +00:00
Tim Kientzle
199984b3b2 Add hook for a client-provided progress callback to be invoked
during lengthy extract operations.
2004-05-13 06:01:14 +00:00
Tim Kientzle
71125f3eb4 Consistify: #define gets 1 tab character afterwards
Pointed out by: Simon Nielsen
2004-05-03 01:40:34 +00:00
Tim Kientzle
037a17e70b Include appropriate flag header on Linux. 2004-05-02 00:38:38 +00:00
Tim Kientzle
183392ce20 Create missing directories when extracting hardlinks and symlinks. 2004-04-30 01:31:20 +00:00
Tim Kientzle
9e62b060b7 Implement ARCHIVE_EXTRACT_UNLINK for regular files. This supports the
-U flag to bsdtar.  Essentially, this option breaks existing hard
links.  According to SUSv2, tar is supposed to overwrite existing
files on extract by default which, in particular, preserves
existing hard links.  Note that this is yet another bug in gtar; it
appears to always break existing links.  (Maybe gtar's -U is broken?)

I'm unsure about how to handle this for other file types; the current
code always unlinks first unless the NO_OVERWRITE flag is specified.
I've commented this issue liberally and will come back to it later.
2004-04-29 05:19:42 +00:00
Tim Kientzle
887bcd3995 Add statistics: track offset in compressed and uncompressed archive,
provide an interface for the client to query this information.
2004-04-28 04:41:27 +00:00
Tim Kientzle
775471a93a Correct spelling of "shell archive" to match /usr/share/misc/magic. 2004-04-28 04:36:57 +00:00
Tim Kientzle
a07768e948 Add the libarchive-formats.5 manpage. This summarizes the various
archive formats supported by libarchive, with some information about
the relative strengths and weaknesses of each format and notes about
issues with libarchive's support for those formats.

This page should make it unnecessary to list all of the libarchive
formats in the manpage of each program that uses libarchive.
Such programs can simply refer to libarchive-formats(5).
2004-04-28 04:34:07 +00:00
Tim Kientzle
7bcc31e94f Add read support for four more common cpio variants:
* little-endian old-style binary cpio archives
 * big-endian old-style binary cpio archives
 * SVR4 portable archives without CRC
 * SVR4 portable archives with CRC

Note that I don't yet verify the CRC for the last one, and I'm
not quite certain I'm correctly parsing device numbers.
2004-04-28 03:44:08 +00:00
Tim Kientzle
61fac2242c Update file flag handling.
The new fflags support in archive_entry supports Linux and FreeBSD
file flags and is a bit more gracious about unrecognized flag names
than strtofflags(3).  This involves some minor API breakage.

The default tar format ("restricted pax") now enables pax extensions
when archiving files that have flags.  In particular, copying dir
heirarchies with 'bsdtar cf - -C src . | bsdtar xpf - -C dest' now
preserves file flags.  (Note the "p" on extract!)

While I'm here, fill in some additional explanation in the
archive_entry.3 manpage, fill in some missing MLINKS, mark some
overlooked internal functions 'static', and make a few minor style
fixes.
2004-04-26 23:37:54 +00:00
Tim Kientzle
a020f1405f Make clone more aggressive about copying strings to the new entry.
The original might have pointers to user-specified strings;
copying the string (instead of just the pointer) protects against
the client re-using their own buffers.

I'm trying hard to avoid dumping all of the 'set' string functions
in favor of slower, but more predictable 'copy' semantics.
2004-04-23 17:15:48 +00:00
Tim Kientzle
4db0943252 Set the 'dump' flag for shardump format.
Credit Juergen Lock.
Pointy hat to me for deleting this somewhere along the way.
2004-04-23 17:13:40 +00:00
Tim Kientzle
9214908dca Correct spelling of == so that file flags are correctly restored.
Credit to Juergen Lock.
2004-04-23 16:27:37 +00:00
Tim Kientzle
0f7d2bd380 More portability improvements, thanks to Juergen Lock.
High-resolution mtime/ctime/atime is not POSIX-standard, so hide
set/get of high-resolution time fields behind easily-mutable macros.
That makes it easier to change how those fields are accessed.
2004-04-21 05:13:42 +00:00
Tim Kientzle
c968be6d98 Yucky bug: Don't emit 'mkdir' commands for regular files in shar archives.
While I'm here, add some logic to avoid "mkdir ."

Reported by: Juergen Lock
2004-04-20 20:21:36 +00:00
Tim Kientzle
9e21a48274 In GNU tar archives, read ctime from ctime field, not atime field.
Credit: Juergen Lock
2004-04-20 20:09:06 +00:00
Tim Kientzle
9b26f9ec8e Eliminate some redundant calls to archive_entry_hardlink. 2004-04-20 20:07:30 +00:00
Tim Kientzle
45804124ae Optimize ustar header formatting. 2004-04-19 20:16:07 +00:00
Tim Kientzle
32ace24809 Only enable the ACL restore logic on FreeBSD versions >= 5.0.
Earlier versions of FreeBSD don't support ACLs.

Note that the ACL support code in archive_entry is standalone code and
unaffected by this.  (In particular, it should be possible to
manipulate archives containing ACLs even if the ACLs cannot be
restored on the current system.)
2004-04-16 01:20:58 +00:00
Tim Kientzle
d911e48507 * Plug a buffer overrun in ACL parsing. (archive_entry.c)
* Re-use a single buffer for shar output formatting rather
   than hammering the heap. (archive_write_set_format_shar.c)
 * Fix a handful of minor memory leaks and clean up some of the
   memory-management code.
2004-04-13 23:45:37 +00:00
Tim Kientzle
aee47dd7c8 More work on ACLs: fix error in archive_entry's ACL parsing code,
try to set ACLs even if fflag restore fails, first cut at reading
  Solaris tar ACLs

Code improvement: merge gnu tar read support into main tar reader;
  this eliminates a lot of duplicate code and generalizes the tar
  reader to handle formats with GNU-like extensions.

Style: Makefile cleanup, eliminate 'dmalloc' references, remove 'tartype'
  from archive_entry (this makes archive_entry more format-agnostic)

Thanks to: David Magda for providing Solaris tar test files
2004-04-12 01:16:16 +00:00
Tim Kientzle
935c15d24f Linux still uses 32-bit off_t by default. Ask for 64-bit off_t on
Linux.
2004-04-07 17:47:06 +00:00
Tim Kientzle
08766bdf18 Fix some issues with ACL handling:
* ACL storage is no longer erased before a group of entries are added.
  * ACL text creation no longer tries to skip over non-existent text.
  * UTF8 encoder no longer blows up on invalid wide characters.
  * Fixed ACL state management for default ACLs.
Also, publicize function for obtaining text-format ACL in various
formats.  The interface is now extensible through a "flags" argument
that allows you to select a variant format.
2004-04-06 23:16:50 +00:00
Tim Kientzle
71b44796d9 Overhauled ACL support. This makes us compatible
with 'star' ACL handling, though there's still a
bit more work needed in this area.

Added 'write_open_fd' and 'read_open_fd' to simplify, e.g.,
tar's u and r modes.  Eliminated old 'write_open_file_position'
as a bad idea.  (It required closing/reopening files to
do updates, which led to unpleasant implications.)

Various other minor fixes, API tweaks, etc.
2004-04-05 21:12:29 +00:00
Tim Kientzle
b1e9afabe1 mdoc fixes 2004-03-23 03:14:01 +00:00
Tim Kientzle
999103b3db Just use autoconf-compatible feature macros; don't try to be clever. 2004-03-22 05:17:23 +00:00
Tim Kientzle
e5b478f765 Bug: Standard C still requires declarations to precede statements. <sigh>
Portability: Eliminate an accidental __unused, accomodate
  systems with non-POSIX strerror_r
2004-03-20 22:35:33 +00:00
Tim Kientzle
44a3d34206 Many fixes:
* Disabled shared-library building, as some API breakage is
  still likely.  (I didn't realize it was turned on by default.)  If
  you have an existing /usr/lib/libarchive.so.2, I recommend deleting it.
* Pax interchange format now correctly stores and reads UTF8
  for extended attributes.  In particular, pax format can portably
  handle arbitrarily long pathnames containing arbitrary characters.
* Library compiles cleanly at -O2, -O3, and WARNS=6 on all
  FreeBSD-CURRENT platforms.
* Minor portability improvements inspired by Juergen Lock
  and Greg Lewis.  (Less reliance on stdint.h, isolating of
  various portability-challenged constructs.)
* archive_entry transparently converts multi-byte <-> wide character
  strings, allowing clients and format handlers to deal with either
  one, as appropriate.
* Support for reading 'L' and 'K' entries in standard tar archives
  for star compatibility.
* Recognize (but don't yet handle) ACL entries from Solaris tar.
* Pushed format-specific data for format readers down into
  format-specific storage and out of library-global storage.  This
  should make it easier to maintain individual formats without mucking
  with the core library management.
* Documentation updates to track the above changes.
* Updates to tar.5 to correct a few mistakes and add some additional
  information about GNU tar and Solaris tar formats.

Notes:
* The basic 'tar' reader is getting more general; there's not much
  point in keeping the 'gnutar' reader separate.  Merging the two
  would lose a bunch of duplicate code.
* The libc ACL support is looking increasingly inadequate for my needs
  here.  I might need to assemble some fairly significant code for
  parsing and building ACLs. <sigh>
2004-03-19 22:37:06 +00:00
Tim Kientzle
df3c1316b0 Many fixes.
Portability: Thanks to Juergen Lock, libarchive now compiles cleanly
on Linux.  Along the way, I cleaned up a lot of error return codes and
reorganized some code to simplify conditional compilation of certain
sections.

Bug fixes:
  * pax format now actually stores filenames that are 101-154
    characters long.
  * pax format now allows newline characters in extended attributes
    (this fixes a long-standing bug in ACL handling)
  * mtime/atime are now restored for directories
  * directory list is now sorted prior to fix-up to permit
    correct restore of non-writable dir heirarchies
2004-03-09 19:50:41 +00:00
Tim Kientzle
cf5704e17b Recognize hardlinks when reading cpio files.
This doesn't yet address the issue of selective restore
of hardlinked files.  With cpio format, it's possible to correctly
restore any linked file; the API doesn't yet fully support this.
(There's no way for the library to inform a client whether or not
there's a file body associated with this entry.  The assumption
right now is that "hardlink" entries have no file body.)
2004-03-07 00:57:43 +00:00
Tim Kientzle
a1f17de172 Minor API tweak: The format-specific write_header function now sets
the size in the archive_entry object to zero if that format doesn't
store a body for that file type.  This allows the client to determine
whether or not it should feed the file body to the archive.  In
particular, cpio stores the file body for hardlinks, tar and shar
don't.  With this change, bsdtar now correctly archives hardlinks in all
supported formats.

While I'm here, make shar output be more aggressive about creating directories.
Before this, commands such as:
    bsdtar -cv -F shar  some/explicit/path/to/a/file
wouldn't create the directory.  Some simple logic to remember the last
directory creation helps reduce unnecessary mkdirs here.

At this point, I think the only flaw in libarchive's cpio support is
the failure to recognize hardlinks when reading.
2004-03-06 05:44:13 +00:00
Tim Kientzle
0af600eb12 Remove last evidence of a long-dead function. 2004-03-06 01:06:49 +00:00
Tim Kientzle
bca59216f7 Add ARCHIVE_EXTRACT_UNLINK option to permit clients to
control how archive_extract handles pre-existing files.
(Not implemented yet, but documented.)
2004-03-06 01:05:32 +00:00
Tim Kientzle
7ed4040910 Correctly read symlinks from cpio files.
While I'm here, fix a bug in reading filenames from
cpio files.  (Copy should count the length of the name,
not the number of bytes available for input.)
2004-03-06 00:59:08 +00:00
Tim Kientzle
4090bd1140 Correctly read SCHILY.nlink from pax-format archives.
In particular, -tv output for pax-format archives now
lists everything that ls -l does.
2004-03-05 00:09:53 +00:00
Tim Kientzle
c56e5beb9c sys/types.h must be included before sys/acl.h,
as clearly documented in the acl manpage.

Thanks to bde for catching this blunder.
2004-02-12 20:35:59 +00:00
Tim Kientzle
06d2a666e4 libarchive itself is now completely clean at WARNS=10 on all architectures.
Unfortunately, the stock zlib.h is not:
  line 885: 'err' parameter shadows global 'err' definition from <err.h>

Back the WARNS level down to 3 to accomodate borked zlib.h.
2004-02-12 04:11:40 +00:00
Tim Kientzle
2710e4d1ef Initial import of libarchive.
What it is:
   A library for reading and writing various streaming archive
   formats, especially tar and cpio.  Being a library, it should
   be easy to incorporate into pkg_* tools, sysinstall, and any
   other place that needs to read or write such archives.

Features:
  * Full automatic detection of both compression and archive format.
  * Extensible internal architecture to make it easy to add new formats.
  * Support for "pax interchange format," a new POSIX-standard tar format
    that eliminates essentially all of the restrictions of historic formats.
  * BSD license

Thanks to: jkh for pushing me to start this work, gordon for
  encouraging me to commit it, bde for answering endless style
  questions, and many others for feedback and encouragement.

Status: Pretty good overall, though there are still a few rough edges and
  the library could always use more testing.  Feedback eagerly solicited.
2004-02-09 23:22:54 +00:00