summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2009-02-27 06:16:03 +0200
committerGuillem Jover <guillem@debian.org>2009-02-27 07:13:51 +0200
commit22408d0c3dac33a396a451e18f1e8860793928d3 (patch)
treead8931d1fbc0d31037367c004eb70d0fe668d47c /lib
parent4b9da2295656cd63e04a4fcc707a575b1f5cd88b (diff)
downloaddpkg-22408d0c3dac33a396a451e18f1e8860793928d3.tar.gz
libdpkg: Add tar format detection support
Recognize old tar, GNU tar and ustar formats. Abort on ustar with non empty Prefix field, as we don't properly handle the long names yet. Failure for PAX archive is already being handled when acting on the typeflag.
Diffstat (limited to 'lib')
-rw-r--r--lib/tarfn.c16
-rw-r--r--lib/tarfn.h8
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/tarfn.c b/lib/tarfn.c
index bdf0bb0c1..ecb5acb21 100644
--- a/lib/tarfn.c
+++ b/lib/tarfn.c
@@ -18,6 +18,9 @@
#include <dpkg.h>
#include <dpkg-priv.h>
+#define TAR_MAGIC_USTAR "ustar\0" "00"
+#define TAR_MAGIC_GNU "ustar " " \0"
+
struct TarHeader {
char Name[100];
char Mode[8];
@@ -33,6 +36,7 @@ struct TarHeader {
char GroupName[32];
char MajorDevice[8];
char MinorDevice[8];
+ char Prefix[155]; /* Only valid on ustar. */
};
typedef struct TarHeader TarHeader;
@@ -81,12 +85,22 @@ DecodeTarHeader(char * block, TarInfo * d)
long sum;
long checksum;
+ if (memcmp(h->MagicNumber, TAR_MAGIC_GNU, 6) == 0)
+ d->format = tar_format_gnu;
+ else if (memcmp(h->MagicNumber, TAR_MAGIC_USTAR, 6) == 0)
+ d->format = tar_format_ustar;
+ else
+ d->format = tar_format_old;
+
if ( *h->UserName )
passwd = getpwnam(h->UserName);
if ( *h->GroupName )
group = getgrnam(h->GroupName);
- d->Name = StoC(h->Name, sizeof(h->Name));
+ if (d->format == tar_format_ustar && h->Prefix[0] != '\0')
+ abort();
+ else
+ d->Name = StoC(h->Name, sizeof(h->Name));
d->LinkName = StoC(h->LinkName, sizeof(h->LinkName));
d->Mode = (mode_t)OtoL(h->Mode, sizeof(h->Mode));
d->Size = (size_t)OtoL(h->Size, sizeof(h->Size));
diff --git a/lib/tarfn.h b/lib/tarfn.h
index 4bd0e00f4..469d47699 100644
--- a/lib/tarfn.h
+++ b/lib/tarfn.h
@@ -12,6 +12,13 @@
#include <unistd.h>
#include <sys/types.h>
+enum tar_format {
+ tar_format_old,
+ tar_format_gnu,
+ tar_format_ustar,
+ tar_format_pax,
+};
+
enum TarFileType {
NormalFile0 = '\0', /* For compatibility with decades-old bug */
NormalFile1 = '0',
@@ -27,6 +34,7 @@ enum TarFileType {
typedef enum TarFileType TarFileType;
struct TarInfo {
+ enum tar_format format; /* Tar archive format. */
void * UserData; /* User passed this in as argument */
char * Name; /* File name */
mode_t Mode; /* Unix mode, including device bits. */