Commit Graph

291 Commits

Author SHA1 Message Date
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
Tim Kientzle
e791a7a913 When writing "pax" format, readers are supposed to ignore fields
in the regular ustar header that are overridden by the pax
extended attributes.  As a result, it makes perfect sense to
use numeric extensions in the regular ustar header so that readers
that don't understand pax extensions but do understand some other
extensions can still get useful information out of it.

This is especially important for filesizes, as the failure to
read a file size correctly can get the reader out of sync.

This commit introduces a "non-strict" option into the internal
function to format a ustar header.  In non-strict mode, the formatter
will use longer octal values (overwriting terminators) or binary
("base-256") values as needed to ensure that large file sizes,
negative mtimes, etc, have the correct values stored in the regular
ustar header.
2004-07-26 02:54:42 +00:00
Tim Kientzle
e5cdebc19e Allow "posix" as a synonym for "pax". (The gtar folks chose "posix",
which is really, really dumb and just going to cause confusion among
people who understand that "ustar" is also a POSIX standard tar format.)
2004-07-25 23:10:38 +00:00
Tim Kientzle
3dd77a04e5 We were forcing a pax extension header for files >= 1G. Set that
cutoff to >= 8G, as it should be.
2004-07-25 18:50:24 +00:00
Tim Kientzle
f5589ef9f4 Minor style nits. 2004-07-24 22:30:35 +00:00
Tim Kientzle
e6787adf79 Rework the feature-detection logic in archive_platform.h so that
it will work cleanly with autoconf.
2004-07-24 20:47:11 +00:00
Tim Kientzle
c02f123ff1 Define the PACKAGE_NAME and PACKAGE_VERSION macros. 2004-07-24 20:45:04 +00:00
Tim Kientzle
c91b82e3e5 Suppress a minor compiler warning if the platform doesn't support hi-res
timestamps.
2004-07-24 20:43:22 +00:00
Tim Kientzle
c48a83413a Add some functions to query basic facts about the library:
archive_version: Returns a text string, e.g., "libarchive 1.00.000"
   archive_api_version: Returns the SHLIB major version
   archive_api_feature: Returns a feature number useful for answering
     questions such as "Is this recent enough to do XXX?"

The last two also have macros defined in archive.h, so you can compare
the compile-time and run-time environments.  (In particular, you can
compare ARCHIVE_API_VERSION to archive_api_version() to detect library
version mismatches.)

With these in hand, it will soon be time to turn on the
shared-library version of libarchive...  stay tuned.
2004-07-24 20:08:26 +00:00
Tim Kientzle
73c891fe79 Use "linux" instead of "LINUX" to control Linux-specific code.
Thanks to: David O'Brien for pointing this out.

Also, add in a few additional portability tweaks and make a few
more things conditional on features (HAVE_XXXX macros) rather
than platform.
2004-07-24 17:50:05 +00:00
Tim Kientzle
45e13f191f Fix the handling of signed values when parsing base-256 header values.
In particular, this means we can now correctly read gtar archives that
contain timestamps prior to the start of the Epoch.

Also, make the code in this area more portable.  ANSI C99 headers are
not yet ubiquitous (for example, FreeBSD 4 still lacks them), so be
prepared for systems that don't have the INT64_MAX, INT64_MIN, and
UINT64_MAX macros.  This version still requires int64_t and uint64_t be
defined (which can be done in archive_platform.h if necessary), but
doesn't require them to be exactly 64 bits.
2004-07-24 17:46:45 +00:00
Tim Kientzle
6a1d1828e7 Style: rename 'mkdirpath' so it's clearer exactly what it does.
(To be precise, it creates the parent dir of the provided path.)
2004-07-15 03:13:27 +00:00
Tim Kientzle
47aa50e155 Update the README notes to include the current list of supported
formats and remove some outdated comments about library limitations.
2004-07-12 01:54:37 +00:00
Tim Kientzle
320adc42ea Correct a brain-o in extract_dir: mkdirpath() and mkdir(2) are
not interchangable.
2004-07-10 18:10:20 +00:00
Tim Kientzle
cbf4203db5 I think this is my fourth complete rewrite of the dir-creation
code. <whew!> This version handles all of the following edge cases:
  * Restoring explicit dirs with 000 permissions (star fails this test)
  * Restore of implicit or explicit dirs when umask=777
    (gtar and star both fail this test)
  * Restoring dir paths containing "." and ".." components
This version initially creates all dirs with permission 700 (ignoring
umask), then does a post-extract "fixup" pass to set the correct
permissions (which may or may not depend on umask, depending on the
restore flags and whether it's an explicit or implicit dir).
Permissions are restored depth-first so that permissions within
non-writable dirs can be correctly restored. (The depth-sorting does
correctly account for dirs with ".." components.)
2004-07-08 05:24:48 +00:00
Tim Kientzle
2859e75d07 Minor wordsmithing; remove a controversial colon. 2004-07-05 19:44:35 +00:00
Tim Kientzle
f586f10d0d Add convenience functions to retrieve the atime fields directly,
without having to first pull the stat structure.
2004-07-05 18:11:44 +00:00
Tim Kientzle
7228b0c18b ru@'s ambitious sweep through the manpages is mostly a good thing,
but some colons are supposed to be followed by uppercase letters.
2004-07-05 18:08:32 +00:00
Ruslan Ermilov
51f98e585b Fix the NAME section making whatis(1) happy in particular. 2004-07-05 17:12:53 +00:00
Ruslan Ermilov
284fcee0c0 Fixed cross-references in SEE ALSO.
Emininated double space and hard sentence breaks.
2004-07-04 21:15:37 +00:00
Tim Kientzle
98183bf412 Yet another pointy hat: When restoring file flags, it's okay to use the
shared stat buffer, but don't try to access it through an uninitialized
pointer.
2004-07-04 18:28:56 +00:00
Ruslan Ermilov
1a0a934547 Mechanically kill hard sentence breaks. 2004-07-02 23:52:20 +00:00
Tim Kientzle
5708f1dd7c In case symlinks happen to already be sitting around, be sure to use
chmod() and not lchmod() whenever we know we didn't extract a symlink.
2004-06-30 04:54:07 +00:00
Tim Kientzle
88c3541690 Some implicit dirs were not having the umask correctly
applied to their permissions.  Just calculate the
default dir mode once and use it consistently, rather than
trying to remember to calculate it everywhere it's needed.
2004-06-28 14:12:09 +00:00
Tim Kientzle
b3f695b45c Refuse to extract an entry from an archive on top of the archive being read.
(This is the converse of the "don't add an archive to itself".)
2004-06-27 23:36:39 +00:00
Tim Kientzle
b5f1f87711 More cleanup work on permissions restore:
* Rename some variables/functions/etc to try to make things clearer.
  * Add separate flags to control fflag/acl restore
  * Collect metadata restore into a single function for clarity
  * Propagate errors in metadata restore back out to the client
  * Fix some places where errors were being returned when they
    shouldn't and vice-versa
  * Modes are now always restored; ARCHIVE_EXTRACT_PERM just controls
    whether or not umask is obeyed.
  * Restore suid/sgid bits only if user/group matches archive
  * Cache the last stat results to try to reduce the number of stat calls
2004-06-27 23:27:28 +00:00
Tim Kientzle
4660ecd1dc Add two new convenience functions to query the uid/gid from an
archive_entry.

Update the Makefile MLINKS and manpage to bring it up-to-date with
the current status of archive_entry.  At least the manpage actually
lists all of the functions now, even if it doesn't really yet explain
them all.
2004-06-27 23:16:42 +00:00
Tim Kientzle
527b6597a0 Clean up some consistent confusion between "dev" and "rdev."
Mostly, these were being used correctly even though a lot of
variables and function names were mis-named.

In the process, I found and fixed a couple of latent bugs and
added a guard against adding an archive to itself.
2004-06-27 18:38:13 +00:00
Tim Kientzle
406b66ef06 More tweaks to implicit directory creation. Even such abominations as
a/././b/../b/../c/./../d/e/f now work correctly.  And yes, a/b and a/c
both get created in this example; if you want, you can create an
entire dir heirarchy from a tar archive with only one entry.

More tweaks to umask support: umasks are now obeyed for all objects,
not just directories; the umask used is now the one in effect at the
corresponding call to archive_read_extract(), so clients that want to
tinker with umask during extract should get the expected behavior.
2004-06-27 16:44:51 +00:00
Tim Kientzle
30d140332e * The mode for implicitly-created dirs is now 0777 modified by the
umask in effect when the archive is closed
* Correct a typo that broke implicit dir creation for non-directories.

Thanks to: Garret A Wollman for pointing out my umask oversight
2004-06-27 05:59:15 +00:00
Tim Kientzle
6efb916277 Unify mkdirpath (used to automatically create missing parent dirs) and
read_extract_dir (which creates directories in the archive).  This
brings a number of advantages:
 * FINALLY fix the problems creating dirs ending in "/."  <sigh>
 * Missing parent dirs now get created securely, just like explicit dirs.
   (Created 0700 initially, then edited to 0755 at end of extraction.)
 * Eliminate some duplicate code and some weird special cases.

While I'm cleaning, inline the regular-file creation code as well.
2004-06-27 03:19:01 +00:00
Tim Kientzle
1393f9061e Read gtar-style sparse archives.
This change also pointed out one API deficiency: the
archive_read_data_into_XXX functions were originally defined to return
the total bytes read.  This is, of course, ambiguous when dealing with
non-contiguous files.  Change it to just return a status value.
2004-06-27 01:15:31 +00:00
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