Commit Graph

254 Commits

Author SHA1 Message Date
Tim Kientzle
3a2a859dd4 A minor refinement to "pax" output: Remove suid/sgid/sticky bits
from mode before using mode for extended attributes entry, copy
mtime/atime/ctime to extended attributes entry so it's a little more
clear that it corresponds to the like-named regular entry.

MFC after: 14 days
2005-06-01 15:44:23 +00:00
Tim Kientzle
b33c1067f8 Start to address the race issue between restoring a file's contents
and restoring the metadata.  In particular, the metadata-restore
functions now all accept a file descriptor and a pathname.  If the
file descriptor is set and the platform supports the appropriate
syscall, restore the metadata through the file descriptor.  Otherwise,
restore it through the pathname.  This is complicated by varying
syscall support (FreeBSD has an fchmod(2) but no fchflags(2), for
example) and because non-file entries don't have an fd to use in
restoring attributes (for example, mknod(2) doesn't return a file
handle).

MFC after: 14 days
2005-05-21 19:45:56 +00:00
Tim Kientzle
21805f33bf Correct return values in myopen() and myclose() in Example code.
Bug: docs/79318
Thanks to: Derek Tattersall
MFC after: 7 days
2005-05-21 19:38:19 +00:00
Tim Kientzle
0e35a97bf9 archive_entry_set_link is supposed to update whichever link field
(symlink or hardlink) is already set.  Instead, it was always setting
the hardlink field.  In particular, this caused GNU tar format long
symlinks to be interpreted as hardlinks.

Thanks to: Brooks Davis
MFC after: 7 days
2005-05-08 19:10:41 +00:00
Tim Kientzle
8d8311c95f Fix broken ACL configuration on FreeBSD 4 and Linux.
Thanks to: Greg Lewis, Juergen Lock, Jaakko Heinonen for reporting and testing
2005-04-23 17:56:34 +00:00
Tim Kientzle
256543d9b1 Certain filenames between 245 and 255 characters long would cause an
internal error if pax extended attributes were being generated.  Being
< 255 characters, the first-pass path editing (to generate a
ustar-compatible name for the main entry) wouldn't occur, and the
second-pass path editing (to generate a ustar name for the pax
attributes entry) assumed the input was already < 245 chars.

The core problem here was using an abbreviated algorithm for the
second pass that relied on the first pass having already run.  The
rewritten code is much simpler: It just uses the full path-shortening
algorithm for building both ustar pathnames.  This way, the second
ustar pathname will always be short enough.

Thanks to: Mark Cammidge
Related to: bin/74385
2005-04-23 17:46:51 +00:00
Tim Kientzle
48a54ddbd0 Portability enhancement: MS Windows won't restore metadata if the file
is still open, so close the file as soon as we've written the
file contents, before we attempt to restore metadata.

Thanks to:  Kees Zeelenberg
2005-04-17 22:49:00 +00:00
Tim Kientzle
fec57dbcd5 Update "make distfile" to use newest automake/autoconf from ports.
Thanks to: Juergen Lock
2005-04-17 17:51:05 +00:00
Tim Kientzle
81a4ac6ddb A number of improvements to ZIP support.
* Handles entries with compressed size >2GB (signed/unsigned cleanup)
  * Handles entries with compressed size >4GB ("ZIP64" extension)
  * Handles Unix extensions (ctime, atime, mtime, mode, uid, etc)
  * Format-specific "skip data" override allows ZIP reader to skip
    entries without decompressing them, which makes "tar -t"
    a lot faster.
  * Handles "length-at-end" entries generated by, e.g., "zip -r - foo"

Many thanks to: Dan Nelson, who contributed the code and test files for
   the first three items above and suggested the fourth.
2005-04-06 04:19:30 +00:00
Tim Kientzle
fa37cdf60b Clean up the support for extracting very long pathnames. 2005-03-29 05:24:08 +00:00
Tim Kientzle
236d2801ad Support extracting entries with pathnames longer than PATH_MAX. In
testing, I've archived and restored dir trees with ~1MB pathnames.
Most formats, of course, have much smaller limits.
2005-03-13 02:53:42 +00:00
Tim Kientzle
516788f9a0 When rejecting rediculously large pax attributes (such as pathnames
over 1MB), issue a warning instead of forcing an internal assertion
failure.
2005-03-13 02:35:52 +00:00
Tim Kientzle
569ed75cbc Correctly pass low-level I/O errors back up to the caller when
reading cpio format.
2005-03-13 01:52:35 +00:00
Tim Kientzle
20b8c58920 Better error messages on read and file-open errors. 2005-03-13 01:51:16 +00:00
Tim Kientzle
ceecd8dc63 Include detailed error message from zlib after a decompression error. 2005-03-13 01:48:33 +00:00
Tim Kientzle
666cdfecc9 If the output is not a regular file, it's okay to add it to the archive.
In particular, /dev/st0 can be added to an archive being written to /dev/st0.

Thanks to: Jaakko Heinonen
2005-03-13 01:47:31 +00:00
Tim Kientzle
84875e4d6f Use correct byte order when parsing the size of the gzip "Extra data" field.
In particular, this correctly allows bsdtar (and pkg_add) to skip
package signatures.

Thanks to: Theo Schlossnagle
2005-03-02 05:34:05 +00:00
Tim Kientzle
59ded882e9 Fix a misplaced .El 2005-02-23 06:58:09 +00:00
Tim Kientzle
39cbd83837 Don't return NULL if there's no error message;
return a generic text message instead.
(Someday, I'll track down all the places that
are generating errors but not recording messages. ;-/

Thanks to: Jaakko Heinonen
2005-02-23 06:57:04 +00:00
Ruslan Ermilov
36a142c455 Expand contractions. 2005-02-13 23:45:54 +00:00
Tim Kientzle
bceab447de Fix a buffer overflow in the "none" decompression handler that
occurred with large read-ahead requests.  This only affected
formats that incorrectly make large requests (ZIP did this until
recently) or with block sizes over 32k.
2005-02-13 23:29:54 +00:00
Ruslan Ermilov
0227791b40 Expand *n't contractions. 2005-02-13 22:25:33 +00:00
Tim Kientzle
a090347fe4 Oops. I missed a 0 => '\0' correction.
Thanks to: Ruslan
2005-02-12 23:33:31 +00:00
Tim Kientzle
9aedc8fa6f Clear the error message buffer on entry to major routines.
This avoids having error messages get concatenated over multiple calls.
2005-02-12 23:11:29 +00:00
Tim Kientzle
c56f8b32c1 Update the format descriptions to include ISO9660 and ZIP support.
Also remove some unnecessary blank lines from archive_read.3.
2005-02-12 23:09:44 +00:00
Tim Kientzle
0a4b2ab59c Performance optimization, code clarification, and bug workaround.
When reading the bodies of Zip archive entries, request a minimum of 1
byte, rather than a minimum of the full entry size.  This is faster
(since it does not force the decompression layer to combine reads) and
works around a bug in the "none" decompression handler (which I'm
testing a separate fix for now).  I've also renamed "bytes_read" to
"bytes_avail" in several places to more accurately reflect that the
value returned from (a->compression_read_ahead) is the number of bytes
available, not necessarily the number of bytes requested.
2005-02-12 23:00:31 +00:00
Tim Kientzle
e3485a974c Fill in some more Rockridge details in ISO9660 support: Ignore PD
(padding) entries, extract inode value from PX entry, recognize SP and
ST (start/end of SUSP extensions).

I don't enforce SP yet, as I've seen CDROMs which use Rockridge
extensions but don't have the SP record (which is officially
required).

The ISO9660 support is now mature enough to extract FreeBSD
distribution CDROMs created with mkisofs.
2005-02-12 22:48:38 +00:00
Tim Kientzle
4c5d0dae20 Flush input when reading from pipe to avoid "broken pipe" warnings.
For example, when using 'gunzip | tar' to decompress.
Also, fix some style issues (write null character as '\0').

Thanks to: Jaakko Heinonen
2005-02-12 22:44:50 +00:00
Tim Kientzle
094855db71 This should (finally) fix the 64-bit build. <sigh> 2005-01-26 03:28:37 +00:00
Tim Kientzle
1019b76f79 Fix some signed/unsigned mismatches.
Reported by: tinderbox
Pointy hat: me
2005-01-25 16:55:28 +00:00
Tim Kientzle
5958ff08bd Basic support for ZIP archives.
Only supports "deflate" and "none" compression for now.

Also, add a few clarifications to the archive_read.3 manpage as
requested by William Dean DeVries.
2005-01-25 06:07:28 +00:00
Philippe Charnier
440e84f59e spell "file system" correctly
Approved by:	ru
2005-01-24 19:58:05 +00:00
Tim Kientzle
ab4999c061 Set the format code and name correctly for:
* ISO9660 CDROM images
  * ISO9660 images with Rockridge extensions
2005-01-23 03:02:14 +00:00
Ruslan Ermilov
49aa339e39 Fixed xrefs. 2005-01-21 20:50:39 +00:00
Tim Kientzle
e01b596372 Support 'CE' records in Rockridge extensions
(specifies that record is extended elsewhere on
the disk).
2005-01-20 04:16:55 +00:00
Tim Kientzle
c47a0d494c Implement a custom print formatter (archive_string_vsprintf)
for libarchive error messages.  Mostly, this
avoids a portability headache related to
copying va_list arguments (some FreeBSD 5
platforms require va_copy; FreeBSD 4 doesn't
support va_copy at all).  It also dramatically reduces the
size of libarchive for embedded applications:
a minimal "untar" program using libarchive can now be
under 64k statically linked (as opposed to ~100k
using library *printf() functions).

MFC after: 14 days
2005-01-16 22:13:51 +00:00
Ruslan Ermilov
c2c7551561 Removed empty line. 2005-01-15 12:45:24 +00:00
Tim Kientzle
972d9bed42 Bring some file descriptions in line with reality.
Also, add some hints to help people understand which
functions are most appropriate for typical uses.
2005-01-12 05:56:49 +00:00
Ruslan Ermilov
2d82ac3110 Scheduled mdoc(7) sweep. 2005-01-11 20:50:51 +00:00
Tim Kientzle
f731478646 libarchive does much more than just tar ;-) 2005-01-10 05:11:15 +00:00
Tim Kientzle
d576b4c796 Recognize and parse symlinks in ISO9660 CDROM images with Rockridge extensions. 2005-01-08 19:56:07 +00:00
Tim Kientzle
09cad9b550 Documentation improvements. In particular,
expand and clarify the description of the client
callback functions and how they should handle errors.

Thanks to: Antony Dovgal
2005-01-08 19:51:04 +00:00
Tim Kientzle
67afe2c071 Correctly document the order of arguments
to archive_read_open and archive_write_open.

Thanks to: Antony Dovgal
2005-01-08 18:32:49 +00:00
Tim Kientzle
49f9f01a7f Clear the error buffer on entry
to archive_read_next_header so the
next error doesn't just get appended.

MFC after: 7 days
2005-01-08 18:28:11 +00:00
Tim Kientzle
8544432b98 First cut at RockRidge support.
Large thanks to the easy-to-read and well-documented
sys/isofs/cd9660 source code, which provided many of the
details I needed for this exercise.
2005-01-03 05:51:33 +00:00
Tim Kientzle
483e82b86c Next round of work on ISO9660 support:
* Reference-count the directory data so that
    we don't leak memory.
  * Correctly step through the directory records
    (skipping unrecognized extensions)
  * Use better defaults for file modes
  * Sort directory entries by offset of the end of the file
    rather than the beginning of the file.  This fixes a
    lot of "out-of-order" problems with zero-length files,
    in particular.
  * Style fixes, remove some debug code, add some error messages.
2005-01-03 01:24:13 +00:00
Tim Kientzle
9e5ae80dce Enable ISO9660 support in "read_support_format_all".
In particular, bsdtar should now recognize ISO9660 images.
2005-01-02 05:22:21 +00:00
Tim Kientzle
5d9e84da87 First cut support for extracting from ISO9660 disk images.
This seems to be able to extract a TOC and extract files from
the couple of ISO images I've tested it with.

Treat this as experimental proof-of-concept code for the
moment.  There are still a bunch of debug messages (there
are a few oddities in ISO9660 that I haven't yet figured
out how to handle), a lot of bugs to be addressed (this
code leaks memory very badly), and a lot of missing features (no
Rockridge support, in particular).  I'd appreciate
feedback from anyone who understands ISO9660 format
better than I do. ;-)

Suggested by: Robert Watson
2005-01-02 05:21:15 +00:00
Tim Kientzle
0d5a38b993 Rewrite the code that hacks a short names to use in
the regular ustar entry.  The old code sometimes created
a too-long name that overflowed the ustar fields and triggered
an internal assertion failure.  This version should be more
robust.

Thanks to: Michal Listos
Fixes: bin/74385
MFC after: 15 days
2004-12-29 23:26:18 +00:00
Garrett Wollman
0fbc5ec63e Correct speling erors. 2004-12-22 17:31:28 +00:00
Tim Kientzle
3276f95241 Include wchar.h to improve our chances of finding
WCHAR_MAX.  This might fix a portability problem on HP_UX.

Thanks to: Susan Kim
2004-12-22 06:40:28 +00:00
Tim Kientzle
4ab219dbb9 Portability nit: Some platforms require stdio.h before bzlib.h.
Thanks to: Kurt J. Lidl
2004-12-22 06:30:14 +00:00
Tim Kientzle
74199b0709 Add __archive_strappend_int to format a decimal
number into a variable-length archive_string.
2004-12-22 06:12:40 +00:00
Tim Kientzle
b8b499afc7 Don't truncate major/minor numbers written to the legacy
ustar fields.  Later, we're going to permit numeric extensions
for these fields, so we can support large values here.  In particular,
this allows GNU tar to correctly extract such entries even
though it doesn't support the pax extended attributes.

Note: r1.18 and r1.17.2.1 of this file allowed similar treatment
of the uid/gid fields.

Thanks to: Ben Mesander
2004-12-22 02:35:37 +00:00
Tim Kientzle
4256fc3386 Tune the bidding for tar archives. This
improves the recognition of hardlink entries
with/without bodies (which is implemented through
a look-ahead that uses the bid function).

MFC after: 7 days
2004-12-22 00:49:16 +00:00
Tim Kientzle
3b4eb33882 Be more careful about assembling/disassembling
device numbers.  In particular, this should fix
a bug where archiving a device node with a very
large minor number would sometimes overflow and
corrupt the major number.

Thanks to: Ben Mesander
MFC after: 7 days
2004-12-11 07:11:42 +00:00
Tim Kientzle
7e07597cfc When determining whether filename is too long for a
regular 'ustar' entry, use narrow-character version,
not wide-character version, as the ustar entry always
uses the narrow-character filename.

Thanks to: Michal Listos
Inspired by, but doesn't fix: bin/74385
2004-11-28 17:57:11 +00:00
Tim Kientzle
00fc1d5801 Correct the spelling of "archive_write_pax_header"
in an error message.

Thanks to: Michal Listos
Inspired by, but doesn't fix: bin/74385
2004-11-28 17:49:39 +00:00
Tim Kientzle
890e938dc3 Since I'm not using the public API for writing
the the pax attributes, I shouldn't try using the public
API for finishing out the attribute entry, either.

This also removes some old dubious state manipulations.
2004-11-15 01:46:33 +00:00
Tim Kientzle
5c79ebdbd7 Pax extended headers were always failing
because the code was using the external API
(archive_write_data) and assuming internal
error-return conventions.  Use the internal
API for writing data.

Thanks to: Joe Marcus Clarke
2004-11-15 01:24:39 +00:00
Tim Kientzle
445ac9fc5b Ooops. ssize_t != int. <sigh>
Thanks to: Oliver Lehmann and Peter Wemm
2004-11-06 05:25:53 +00:00
Tim Kientzle
b772d06c77 Makefile tweaks:
* Update Version
  * Add a missing MLINK
  * Fix 'distfile' target so it works from a clean checkout
2004-11-05 05:38:15 +00:00
Tim Kientzle
88507deac2 Remove the unused archive_string_sprintf() utility function. 2004-11-05 05:32:04 +00:00
Tim Kientzle
48cbe7223a Revert 1.24: Brain glitch. <sigh> 2004-11-05 05:29:36 +00:00
Tim Kientzle
3ede53f3e1 Clean up the error handling in the
write path.  In particular, this should
solve some problems people have seen with
bsdtar not exiting on various write errors.
2004-11-05 05:26:30 +00:00
Tim Kientzle
9fb9f10286 archive.h gets built in ${.OBJDIR} 2004-11-05 05:23:18 +00:00
Tim Kientzle
3702bc7eb3 Update a comment. 2004-11-05 05:16:40 +00:00
Tim Kientzle
6b31624278 Allow tar format to read and accept an empty (or non-existent)
file.  In particular, this allows bsdtar to append (-r) to
an empty file.

Thanks to: Ryan Sommers

While I'm here, straighten out a misleading comment about GNU-compatible
sparse file handling.
2004-10-27 05:15:23 +00:00
Tim Kientzle
d4ddb4f67f Revert 1.18: It broke Athlon64 builds, which
probably means it also requires a .so version
bump.  Defer it until I finish some related
work on cleaning up error returns throughout
the library.

Thanks to: Conrad J. Sabatier
2004-10-18 05:31:01 +00:00
Tim Kientzle
ccd736423f Use STDERR_FILENO instead of 2, as POSIX intended.
Thanks to: Alfred Perlstein
2004-10-18 04:34:30 +00:00
Tim Kientzle
227b756897 Correctly report write errors from the lowest-level
output routines back to the compression layer.
2004-10-17 23:47:30 +00:00
Tim Kientzle
5255e61f1a Refine the error-checking and reporting in the
"compress" format decompression code.  In particular,
distinguish between EOF and fatal data errors.
2004-10-17 23:40:10 +00:00
Tim Kientzle
cc11275dd4 Correct the return type of archive_write_data
to match the documentation.

MFC after: 30 days
2004-10-17 23:37:09 +00:00
Tim Kientzle
49f89e883c Don't rely on stdio here. 2004-10-17 23:35:16 +00:00
David E. O'Brien
731239920f Build as a shared lib again.
Discussed with:	kientzle
2004-10-11 22:04:05 +00:00
Tim Kientzle
d6970563b6 Fix two ugly errors:
1. The correct cutoff for large uid/gid handling is 1<<18, not 1<<20.
2. Limit the uid/gid in the 'x' extension header (where numeric extensions
are not permitted) to 1<<18, but use the correct value in the regular
header (where numeric extensions are permitted).
Thanks to: Dan Nelson
MFC after: 3 days
2004-09-17 04:39:07 +00:00
Tim Kientzle
8a95c5cb6e Some old tar archives rely on "regular-file-plus-trailing-slash" to
denote a directory.  Unfortunately, in the presence of GNU or POSIX
extensions, this code was checking the truncated filename stored in the
regular header rather than the full filename stored in the extended
attribute.  As a result, long filenames with '/' in just the right
position would trigger this check and be erroneously marked as
directories.  Move the check so it only considers the full filename.
Note: the check can't simply be disabled for archives that contain
these extensions because there are some very broken archivers out
there.

Thanks to: Will Froning
MFC after: 3 days
2004-09-04 21:49:42 +00:00
Tim Kientzle
00ccc351f8 Per Ruslan, bsd.lib.mk already has support for dynamically-generated
.h files.  This simplifies the Makefile here a bit and makes it behave
better in a couple of situations.  While I'm here, clean up some comments
and try to improve the organization a bit.

Thanks to: Ruslan Ermilov (The Marvelous Makefile Guru)
2004-09-01 05:06:42 +00:00
Tim Kientzle
db9e0127da Cache uid-from-uname and gid-from-gname lookups during extraction.
This should provide a big performance boost for folks using NIS or LDAP.

MFC after: 3 days
Thanks to: Jun Kuriyama (for reminding me that this was still on my TODO list)
2004-08-27 03:40:48 +00:00
Tim Kientzle
2522fe6764 Don't edit permissions of pre-existing directories during extract.
This closes a security hole.  Otherwise, libarchive will happily
extract into directories to which it lacks write permissions by
resetting the permissions during the extract.

Thanks to: Kris Kennaway
2004-08-26 03:53:43 +00:00
Tim Kientzle
c85db499ac It is not legal to re-use a va_list variable. This caused
a crash on amd64, in particular.

Thanks to: Sean McNeil
2004-08-26 03:33:53 +00:00
Tim Kientzle
57b665990a Eliminate reliance on non-portable <err.h> by implementing a very
simple errx() function.
Improve behavior when bzlib/zlib are missing by detecting and
issuing an error message on attempts to read gzip/bzip2 compressed
archives.
2004-08-14 03:45:45 +00:00
Tim Kientzle
6a0724a89e We don't need <paths.h>, so don't bother including it. 2004-08-14 03:43:35 +00:00
Tim Kientzle
7acae2155e Add archive_entry_set_mtime() 2004-08-08 07:39:19 +00:00
Tim Kientzle
0a36c0e86b Oops. Use "unsigned long" instead of "int" for the intermediate variables
in wide-character conversions, since it's guaranteed to be large enough.
Thanks to: Andrey Chernov
2004-08-08 02:22:48 +00:00
Tim Kientzle
61913b5f21 Use 'int' for certain wide-character conversions instead of wchar_t.
That quiets some compiler warnings on platforms with 16-bit wchar_t.
With this change, libarchive now compiles cleanly on Win32/cygwin.
2004-08-08 01:21:10 +00:00
Tim Kientzle
e33730c3c3 The configure-built Makefile wasn't installing archive.h 2004-08-08 00:48:39 +00:00
Tim Kientzle
e8ec6e32d2 If you don't need a header, don't bother including it. 2004-08-08 00:43:21 +00:00
Tim Kientzle
91ce8f27d8 Split archive_{read,write}_finish into separate "close" (finish the archive
and close it) and "finish" (destroy the object) functions.   For backwards
compat and simplicity, have "finish" invoke "close" transparently if needed.
This allows clients to close the archive and check end-of-operation
statistics before destroying the object.
2004-08-07 19:22:50 +00:00
Tim Kientzle
0cc230af33 Don't forget to count the end-of-file padding as part of the finished
file size.
2004-08-07 19:21:18 +00:00
Tim Kientzle
b2d9ea9fd3 Having implemented read support for it, I now know how to document the
GNU sparse file extension.
2004-08-07 17:24:50 +00:00
Tim Kientzle
659c68935c Correct an mdoc error; add a sentence about tar's ancestors "tp" and "tap." 2004-08-07 17:15:33 +00:00
Tim Kientzle
1e28302160 Fix the calculation of the most negative int64_t value, which
is used on systems that lack C99 headers (such as FreeBSD 4).
2004-08-07 06:38:40 +00:00
Tim Kientzle
bfe891b141 libarchive now has two complete build systems. The usual "Makefile"
is present for FreeBSD.  If you "make distfile" on FreeBSD, you will
soon have a tar.gz file suitable for deploying to other systems
(complete with the expected "configure" script, etc).  This latter
relies (at least for now) on the GNU auto??? tools.  (I like autoconf
okay, but someday I hope to write a custom Makefile.in and dispense
with automake, which is somewhat odious.)

As part of this, I've cleaned up some of the conditional
compilation options, added make-foo to construct archive.h dynamically
(it now contains some version constants), and added some useful
informational files.
2004-08-07 03:09:28 +00:00
Tim Kientzle
501fe26500 Pass the pointy hat, please: Don't blow away the high-order
mode bits when setting permissions from ACL data.
Thanks to: David Gilbert for first reporting this and
    Jimmy Olgeni for noticing that it only occurred on
    ACL-enabled filesystems.
2004-08-07 02:50:05 +00:00
Tim Kientzle
af062c24e6 Beef up the "cannot archive this" error message with the
actual mode that failed, to help track down a bug.
2004-08-07 02:24:20 +00:00
Tim Kientzle
16918868d3 Correct the names and descriptions of the man pages. 2004-08-04 06:19:31 +00:00
Tim Kientzle
da40bbb79e For the "portable" distribution, the configure script will overwrite
"Makefile," so I'm moving all the FreeBSD build machinery to
"Makefile.freebsd", with the default "Makefile" containing a single
include.
2004-08-01 19:30:56 +00:00
Tim Kientzle
b5fda35ca3 C standard does not permit empty initializer list.
Thanks to: Stefan Farfeleder
2004-08-01 19:02:49 +00:00
Tim Kientzle
769756525d Conditionalize the bzip2/gzip compression/decompression
code on the existence of the relevant libraries (actually,
the existence of the include files).

This will allow the library to be easily ported to systems
that don't have these libraries.  (Of course, it also means
that clients using the library on such systems will not be
able to take advantage of the automatic compression format
detection.)
2004-07-30 04:14:47 +00:00