Audit tar(1), add DIRFIRST-flag to recurse()
I've been wanting to do this for a while now, as tar(1) used to
be one of messiest and cruftiest tools.
First off, before walking through the audit, I'll talk about
what the DIRFIRST-flag for recurse() does.
It basically calls fn() on the first-level-dir before calling
it's subentries. It's necessary here, because else the order
of the tar-files would've been wrong (it would try to create
dir/file before creating dir/).
Now, to the audit:
1) Update manpage, fix mistake that compression is also available
for compressing. It's only available for extracting.
2) Define the major, minor and makedev macros from glibc by ourselves.
No need to rely on them, as they are common sense.
decomp()
3) Simple refactorization.
putoctal()
4) Add a truncation check for snprintf().
archive()
5) BUGFIX: Add checks to any checkable function, don't blindly call
them, this is harmful and there are 100 ways to exploit that.
6) Use estrlcpy() instead of snprintf() wherever possible, fix
alignment.
7) BUGFIX: Terminate the result-buffer of readlink(), check if
it even succeeded.
8) Fix sizeof()-formatting.
unarchive()
9) BUGFIX: Add checks to any checkable function, don't blindly call
them, this is harmful and there are 100 ways to exploit that.
10) BUGFIX: strtoul can happily return negative numbers. Add checks
for that and also if the full string has been processed.
11) Remove calls to perror(). We have eprintf, use it.
12) BUGFIX: "minor = strtoul(h->mode, 0, 8);". We need h->minor of
course.
13) Fix typo "usupported", remove fprintf-call.
print()
14) Check fread().
xt()
15) Get rid of snprintf-magic. Use estrlcat().
16) BUGFIX: check for ferror() on the tarfile.
usage()
17) Update it. The old usage() was like 1000 years old.
main()
18) Add DIRFIRST-flag to the recursor.
19) Don't print usage() when a mode is re-set. We allow this in
general.
20) Add function checks and fix error messages.
21) Add tarfilename-global for proper error-messages.
2015-03-20 20:03:35 -04:00
|
|
|
.Dd March 21, 2015
|
2015-01-31 08:20:02 -05:00
|
|
|
.Dt TAR 1
|
2015-01-31 14:37:03 -05:00
|
|
|
.Os sbase
|
2015-01-31 08:05:23 -05:00
|
|
|
.Sh NAME
|
|
|
|
.Nm tar
|
|
|
|
.Nd create, list or extract a tape archive
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm
|
|
|
|
.Op Fl C Ar dir
|
2015-02-08 17:16:27 -05:00
|
|
|
.Op Fl j | Fl z
|
|
|
|
.Fl x Op Fl m | Fl t
|
|
|
|
.Op Fl f Ar file
|
2015-01-31 08:05:23 -05:00
|
|
|
.Nm
|
|
|
|
.Op Fl C Ar dir
|
2015-02-09 16:42:56 -05:00
|
|
|
.Op Fl h
|
2015-01-31 08:05:23 -05:00
|
|
|
.Fl c Ar dir
|
2015-02-08 17:16:27 -05:00
|
|
|
.Op Fl f Ar file
|
2015-01-31 08:05:23 -05:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Nm
|
2015-02-08 17:16:27 -05:00
|
|
|
is the standard file archiver.
|
2015-01-31 08:05:23 -05:00
|
|
|
.Sh OPTIONS
|
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Fl c Ar path
|
2015-02-08 17:16:27 -05:00
|
|
|
Create archive from
|
2015-01-31 08:05:23 -05:00
|
|
|
.Ar path .
|
|
|
|
.It Fl C Ar dir
|
|
|
|
Change directory to
|
|
|
|
.Ar dir
|
|
|
|
before beginning.
|
2015-02-08 17:16:27 -05:00
|
|
|
.It Fl f Ar file
|
|
|
|
Set
|
|
|
|
.Ar file
|
|
|
|
as input | output archive instead of stdin | stdout.
|
2015-01-31 08:05:23 -05:00
|
|
|
.It Fl m
|
|
|
|
Do not preserve modification time.
|
|
|
|
.It Fl t
|
2015-02-08 17:16:27 -05:00
|
|
|
List all files in the archive.
|
2015-01-31 08:05:23 -05:00
|
|
|
.It Fl x
|
2015-02-08 17:16:27 -05:00
|
|
|
Extract archive.
|
2015-02-09 16:42:56 -05:00
|
|
|
.It Fl h
|
|
|
|
Always dereference symbolic links while recursively traversing directories.
|
2015-02-08 17:16:27 -05:00
|
|
|
.It Fl j | Fl z
|
Audit tar(1), add DIRFIRST-flag to recurse()
I've been wanting to do this for a while now, as tar(1) used to
be one of messiest and cruftiest tools.
First off, before walking through the audit, I'll talk about
what the DIRFIRST-flag for recurse() does.
It basically calls fn() on the first-level-dir before calling
it's subentries. It's necessary here, because else the order
of the tar-files would've been wrong (it would try to create
dir/file before creating dir/).
Now, to the audit:
1) Update manpage, fix mistake that compression is also available
for compressing. It's only available for extracting.
2) Define the major, minor and makedev macros from glibc by ourselves.
No need to rely on them, as they are common sense.
decomp()
3) Simple refactorization.
putoctal()
4) Add a truncation check for snprintf().
archive()
5) BUGFIX: Add checks to any checkable function, don't blindly call
them, this is harmful and there are 100 ways to exploit that.
6) Use estrlcpy() instead of snprintf() wherever possible, fix
alignment.
7) BUGFIX: Terminate the result-buffer of readlink(), check if
it even succeeded.
8) Fix sizeof()-formatting.
unarchive()
9) BUGFIX: Add checks to any checkable function, don't blindly call
them, this is harmful and there are 100 ways to exploit that.
10) BUGFIX: strtoul can happily return negative numbers. Add checks
for that and also if the full string has been processed.
11) Remove calls to perror(). We have eprintf, use it.
12) BUGFIX: "minor = strtoul(h->mode, 0, 8);". We need h->minor of
course.
13) Fix typo "usupported", remove fprintf-call.
print()
14) Check fread().
xt()
15) Get rid of snprintf-magic. Use estrlcat().
16) BUGFIX: check for ferror() on the tarfile.
usage()
17) Update it. The old usage() was like 1000 years old.
main()
18) Add DIRFIRST-flag to the recursor.
19) Don't print usage() when a mode is re-set. We allow this in
general.
20) Add function checks and fix error messages.
21) Add tarfilename-global for proper error-messages.
2015-03-20 20:03:35 -04:00
|
|
|
Use bzip2 | gzip decompression. The
|
2015-02-08 17:16:27 -05:00
|
|
|
.Xr bzip2 1 |
|
2015-01-31 08:05:23 -05:00
|
|
|
.Xr gzip 1
|
2015-02-08 17:16:27 -05:00
|
|
|
utilities must be installed separately.
|
|
|
|
Using these flags is discouraged in favour of the flexibility
|
|
|
|
and clarity of pipes:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ bzcat archive.tar.bz2 | tar -x
|
|
|
|
$ zcat archive.tar.gz | tar -x
|
|
|
|
.Ed
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ tar -c file ... | bzip2 > archive.tar.bz2
|
|
|
|
$ tar -c file ... | gzip2 > archive.tar.gz
|
|
|
|
.Ed
|
2015-01-31 08:05:23 -05:00
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr ar 1 ,
|
|
|
|
.Xr bzip2 1 ,
|
|
|
|
.Xr gzip 1
|
2015-02-08 17:16:27 -05:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility is compliant with the UStar (Uniform Standard Tape ARchive)
|
|
|
|
format defined in the
|
|
|
|
.St -p1003.1-88
|
|
|
|
specification.
|