pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/rpm2pkg Update "rpm2pkg" to version 3.0. Chan...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d0e0942309c2
branches:  trunk
changeset: 576502:d0e0942309c2
user:      tron <tron%pkgsrc.org@localhost>
date:      Sun Jun 13 13:08:51 2010 +0000

description:
Update "rpm2pkg" to version 3.0. Changes since version 2.3:
- Don't use the original "rpm" libraries. All we need to do is to identify
  a file as an RPM file and afterwards find the BZip2 or GZip compressed
  section at the end of the file.
- Use C99's "stdbool.h" instead of home-grown defines.

diffstat:

 pkgtools/rpm2pkg/Makefile        |   12 +-
 pkgtools/rpm2pkg/files/rpm2pkg.c |  191 +++++++++++++++++++++++++-------------
 2 files changed, 131 insertions(+), 72 deletions(-)

diffs (truncated from 523 to 300 lines):

diff -r 41f73aef4d0d -r d0e0942309c2 pkgtools/rpm2pkg/Makefile
--- a/pkgtools/rpm2pkg/Makefile Sun Jun 13 08:56:04 2010 +0000
+++ b/pkgtools/rpm2pkg/Makefile Sun Jun 13 13:08:51 2010 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.43 2009/06/14 22:44:34 joerg Exp $
+# $NetBSD: Makefile,v 1.44 2010/06/13 13:08:51 tron Exp $
 
-DISTNAME=      rpm2pkg-2.3
+DISTNAME=      rpm2pkg-3.0
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
@@ -14,11 +14,12 @@
 
 PKG_DESTDIR_SUPPORT=   user-destdir
 
+USE_LANGUAGES= c99
 WRKSRC=                ${WRKDIR}
 
 CPPFLAGS+=     ${BUILDLINK_CPPFLAGS.bzip2} ${BUILDLINK_CPPFLAGS.rpm} \
                ${BUILDLINK_CPPFLAGS.zlib}
-LIBS+=         -lrpm -lintl -lz -lbz2
+LIBS+=         -lintl -lz -lbz2
 
 .include "../../mk/compiler.mk"
 
@@ -26,6 +27,10 @@
 CFLAGS+=       -Wall -Wshadow -Wsign-compare -Wunused-value
 .endif
 
+.if ${OPSYS} == "NetBSD" && defined(USE_SSP) && (${USE_SSP} != "no")
+CFLAGS+=       -fstack-protector -Wstack-protector --param ssp-buffer-size=1
+.endif
+
 INSTALLATION_DIRS=     ${PKGMANDIR}/man8 sbin
 
 do-build:
@@ -39,7 +44,6 @@
 .include "../../archivers/bzip2/buildlink3.mk"
 .include "../../devel/gettext-lib/buildlink3.mk"
 .include "../../devel/zlib/buildlink3.mk"
-.include "../../misc/rpm/buildlink3.mk"
 .include "../../mk/bdb.buildlink3.mk"
 
 .include "../../mk/bsd.pkg.mk"
diff -r 41f73aef4d0d -r d0e0942309c2 pkgtools/rpm2pkg/files/rpm2pkg.c
--- a/pkgtools/rpm2pkg/files/rpm2pkg.c  Sun Jun 13 08:56:04 2010 +0000
+++ b/pkgtools/rpm2pkg/files/rpm2pkg.c  Sun Jun 13 13:08:51 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpm2pkg.c,v 1.8 2009/06/14 22:44:34 joerg Exp $        */
+/*     $NetBSD: rpm2pkg.c,v 1.9 2010/06/13 13:08:52 tron Exp $ */
 
 /*-
  * Copyright (c) 2004-2009 The NetBSD Foundation, Inc.
@@ -34,15 +34,28 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <bzlib.h>
-#include <rpmlib.h>
 #include <zlib.h>
 
+/*
+ * Lead of an RPM archive as described here:
+ * http://www.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html
+ */
+static const unsigned char RPMMagic[] = { 0xed, 0xab, 0xee, 0xdb };
+
+#define        RPM_LEAD_SIZE   96
+
+/* Magic bytes for "bzip2" and "gzip" compressed files. */
+static const unsigned char BZipMagic[] = { 'B', 'Z', 'h' };
+static const unsigned char GZipMagic[] = { 0x1f, 0x8b, 0x08 };
+
+/* Structure of a cpio(1) archive. */
 #define C_IRUSR                        0000400
 #define C_IWUSR                        0000200
 #define C_IXUSR                        0000100
@@ -60,7 +73,7 @@
 #define C_ISCHR                        0020000
 #define C_ISLNK                        0120000
  
-char CPIOMagic[] = {'0','7','0','7','0','1'};
+static const unsigned char CPIOMagic[] = {'0','7','0','7','0','1'};
 
 #define CPIO_END_MARKER                "TRAILER!!!"
 #define CPIO_FIELD_LENGTH      8
@@ -73,9 +86,6 @@
 
 #define CP_IFMT                        0170000
 
-#define        TRUE    1
-#define        FALSE   0
-
 typedef struct ModeMapStruct {
        unsigned long   mm_CPIOMode;
        mode_t          mm_SysMode;
@@ -124,7 +134,7 @@
        off_t   fh_Pos;
 } FileHandle;
 
-static int
+static bool
 InitBuffer(void **Buffer, size_t *BufferSizePtr)
 {
        if (*Buffer == NULL) {
@@ -134,11 +144,11 @@
                while ((*Buffer = malloc(BufferSize)) == NULL) {
                        BufferSize >>= 1;
                        if (BufferSize == 0)
-                               return FALSE;
+                               return false;
                }
                *BufferSizePtr = BufferSize;
        }
-       return TRUE;
+       return true;
 }
 
 static void
@@ -155,24 +165,77 @@
        free(fh);
 }
 
+static bool
+IsRPMFile(int fd)
+{
+       char buffer[RPM_LEAD_SIZE];
+
+       if (read(fd, buffer, sizeof(buffer)) != sizeof(buffer))
+               return false;
+
+       return (memcmp(buffer, RPMMagic, sizeof(RPMMagic)) == 0);
+}
+
 static FileHandle *
 Open(int fd)
 {
+       unsigned char   buffer[4096];
+       size_t          bzMatch, gzMatch;
+       int             archive_type;
        off_t           offset;
-       char            Magic[3];
        FileHandle      *fh;
 
-       if ((offset = lseek(fd, 0, SEEK_CUR)) < 0)
-               return NULL;
-       if (read(fd, Magic, sizeof (Magic)) != sizeof (Magic))
-               return NULL;
-       if (lseek(fd, offset, SEEK_SET) != offset)
+       bzMatch = 0;
+       gzMatch = 0;
+       archive_type = 0;
+       offset = 0;
+       do {
+               ssize_t bytes, i;
+
+               bytes = read(fd, buffer, sizeof(buffer));
+               if (bytes <= 0)
+                       return NULL;
+
+               for (i = 0; i < bytes; i++) {
+                       /* Look for bzip2 header. */
+                       if (buffer[i] == BZipMagic[bzMatch]) {
+                               bzMatch++;
+                               if (bzMatch == sizeof(BZipMagic)) {
+                                       archive_type = 1;
+                                       offset = i - bytes -
+                                           sizeof(BZipMagic) + 1;
+                                       break;
+                               }
+                       } else {
+                               bzMatch = 0;
+                       }
+
+                       /* Look for gzip header. */
+                       if (buffer[i] == GZipMagic[gzMatch]) {
+                               gzMatch++;
+                               if (gzMatch == sizeof(GZipMagic)) {
+                                       archive_type = 2;
+                                       offset = i - bytes -
+                                           sizeof(GZipMagic) + 1;
+                                       break;
+                               }
+                       } else {
+                               gzMatch = 0;
+                       }
+
+                       offset++;
+               }
+       } while (archive_type == 0);
+
+       /* Go back to the beginning of the archive. */
+       if (lseek(fd, offset, SEEK_CUR) < RPM_LEAD_SIZE)
                return NULL;
 
        if ((fh = calloc(1, sizeof (FileHandle))) == NULL)
                return NULL;
 
-       if ((Magic[0] == 'B') && (Magic[1] == 'Z') && (Magic[2] == 'h')) {
+       if (archive_type == 1) {
+               /* bzip2 archive */
                int     bzerror;
 
                if ((fd = dup(fd)) < 0) {
@@ -192,6 +255,7 @@
                        return (NULL);
                }
        } else {
+               /* gzip archive */
                if ((fh->fh_GZFile = gzdopen(fd, "r")) == NULL) {
                        free(fh);
                        return (NULL);
@@ -215,7 +279,7 @@
        return (bytes == length);
 }
 
-static int
+static bool
 SkipAndAlign(FileHandle *fh, off_t Skip)
 
 {
@@ -223,20 +287,20 @@
 
        NewPos = (fh->fh_Pos + Skip + 3) & ~3;
        if (fh->fh_Pos == NewPos)
-               return TRUE;
+               return true;
 
        if (fh->fh_GZFile != NULL) {
                if (gzseek(fh->fh_GZFile, NewPos, SEEK_SET) == NewPos) {
                        fh->fh_Pos = NewPos;
-                       return TRUE;
+                       return true;
                }
-               return FALSE;
+               return false;
        } else {
                static void     *Buffer = NULL;
                static size_t   BufferSize = 0;
 
                if (!InitBuffer(&Buffer, &BufferSize))
-                       return FALSE;
+                       return false;
 
                while (fh->fh_Pos < NewPos) {
                        off_t   Length;
@@ -246,11 +310,11 @@
                        Chunk = (Length > (off_t)BufferSize) ?
                            (off_t)BufferSize : Length;
                        if (!Read(fh, Buffer, Chunk))
-                               return FALSE;
+                               return false;
                }
        }
 
-       return TRUE;
+       return true;
 }
 
 static PListEntry *
@@ -413,22 +477,22 @@
        return NULL;
 }
 
-static int
+static bool
 GetCPIOHeader(FileHandle *In, unsigned long *Fields, char **Name)
 {
-       char    Buffer[CPIO_NUM_HEADERS*CPIO_FIELD_LENGTH], *Ptr;
+       char    Buffer[CPIO_NUM_HEADERS * CPIO_FIELD_LENGTH], *Ptr;
        int     Index;
        unsigned long   Value;
 
        *Name = NULL;
 
        if (!Read(In, Buffer, sizeof (CPIOMagic)))
-               return FALSE;
+               return false;
        if (memcmp(Buffer, CPIOMagic, sizeof (CPIOMagic)) != 0)
-               return FALSE;
+               return false;
 
        if (!Read(In, Buffer, sizeof (Buffer)))
-               return FALSE;
+               return false;
 
        Ptr = Buffer;
        Index = sizeof (Buffer);
@@ -442,7 +506,7 @@
                } else if ((*Ptr >= 'a') && (*Ptr <= 'f')) {
                                Value += (unsigned long)(*Ptr++-'a') + 10;
                } else {
-                       return FALSE;



Home | Main Index | Thread Index | Old Index