Created
October 25, 2011 19:41
-
-
Save bsdf/1313986 to your computer and use it in GitHub Desktop.
dpkg-patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7c6218a76d97394df3efa1c869940670ee3a2706 Mon Sep 17 00:00:00 2001 | |
From: BEN ENGLISCH <[email protected]> | |
Date: Tue, 25 Oct 2011 13:38:54 -0500 | |
Subject: [PATCH] macports patches | |
--- | |
dselect/Makefile.in | 2 +- | |
dselect/dselect.h | 2 +- | |
dselect/main.cc | 2 +- | |
lib/dpkg.h | 2 +- | |
lib/tarfn.c | 40 ++++++++++++++++++++- | |
scripts/Makefile.am | 2 +- | |
scripts/Makefile.in | 2 +- | |
src/archives.c | 15 +++++++- | |
src/help.c | 3 +- | |
src/remove.c | 26 +++++++++++++- | |
utils/start-stop-daemon.c | 83 +++++++++++++++++++++++++++++++++++++++++++- | |
11 files changed, 164 insertions(+), 15 deletions(-) | |
diff --git a/dselect/Makefile.in b/dselect/Makefile.in | |
index 7521fb1..45b3288 100644 | |
--- a/dselect/Makefile.in | |
+++ b/dselect/Makefile.in | |
@@ -640,7 +640,7 @@ uninstall-am: uninstall-binPROGRAMS | |
curkeys.$(OBJEXT): curkeys.h | |
curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl | |
- cursesfile=`echo '#include <ncursesw/curses.h>' | \ | |
+ cursesfile=`echo '#include <curses.h>' | \ | |
$(CC) -E - | grep 'curses.h' | head -n 1 | \ | |
sed -e 's/^[^"]*"//; s/".*$$//'`; \ | |
if [ "$$cursesfile" = "" ]; then \ | |
diff --git a/dselect/dselect.h b/dselect/dselect.h | |
index cf5f553..abc3c9a 100644 | |
--- a/dselect/dselect.h | |
+++ b/dselect/dselect.h | |
@@ -28,7 +28,7 @@ | |
#include <signal.h> | |
#undef ERR | |
-#include <ncursesw/curses.h> | |
+#include <curses.h> | |
struct helpmenuentry { | |
char key; | |
diff --git a/dselect/main.cc b/dselect/main.cc | |
index ac277e9..99702cf 100644 | |
--- a/dselect/main.cc | |
+++ b/dselect/main.cc | |
@@ -37,7 +37,7 @@ extern "C" { | |
#include <ctype.h> | |
#include <assert.h> | |
-#include <ncursesw/term.h> | |
+#include <term.h> | |
extern "C" { | |
#include <dpkg.h> | |
diff --git a/lib/dpkg.h b/lib/dpkg.h | |
index ba6066c..89a66ba 100644 | |
--- a/lib/dpkg.h | |
+++ b/lib/dpkg.h | |
@@ -147,7 +147,7 @@ | |
#define DPKG "dpkg" | |
#define DEBSIGVERIFY "/usr/bin/debsig-verify" | |
-#define TAR "tar" | |
+#define TAR "gnutar" | |
#define GZIP "gzip" | |
#define BZIP2 "bzip2" | |
#define LZMA "lzma" | |
diff --git a/lib/tarfn.c b/lib/tarfn.c | |
index 2aa8b91..8c86083 100644 | |
--- a/lib/tarfn.c | |
+++ b/lib/tarfn.c | |
@@ -18,6 +18,9 @@ | |
#include "strnlen.h" | |
+static const char ustarMagic[] = { 'u', 's', 't', 'a', 'r', '\0', '0', '0', '\0' }; | |
+static const char gnutarMagic[] = { 'u', 's', 't', 'a', 'r', ' ', ' ', '\0' }; | |
+ | |
struct TarHeader { | |
char Name[100]; | |
char Mode[8]; | |
@@ -28,11 +31,12 @@ struct TarHeader { | |
char Checksum[8]; | |
char LinkFlag; | |
char LinkName[100]; | |
- char MagicNumber[8]; | |
+ char MagicNumber[8]; /* POSIX: "ustar\000", GNU: "ustar \0" (blank blank null) */ | |
char UserName[32]; | |
char GroupName[32]; | |
char MajorDevice[8]; | |
char MinorDevice[8]; | |
+ char Prefix[155]; /* POSIX ustar header */ | |
}; | |
typedef struct TarHeader TarHeader; | |
@@ -78,6 +82,10 @@ DecodeTarHeader(char * block, TarInfo * d) | |
struct passwd * passwd = NULL; | |
struct group * group = NULL; | |
unsigned int i; | |
+ char *prefix, *name, *file; | |
+ size_t prefixLen; | |
+ size_t nameLen; | |
+ size_t fileLen; | |
long sum; | |
long checksum; | |
@@ -86,7 +94,35 @@ DecodeTarHeader(char * block, TarInfo * d) | |
if ( *h->GroupName ) | |
group = getgrnam(h->GroupName); | |
- d->Name = StoC(h->Name, sizeof(h->Name)); | |
+ /* | |
+ * Is this a ustar archive entry? | |
+ * Is Prefix in use? | |
+ */ | |
+ if ((memcmp(h->MagicNumber, ustarMagic, sizeof(h->MagicNumber)) == 0) && h->Prefix[0]) { | |
+ prefixLen = strnlen(h->Prefix, sizeof(h->Prefix)); | |
+ | |
+ prefix = StoC(h->Prefix, prefixLen); | |
+ if (h->Prefix[prefixLen - 1] != '/') { | |
+ prefixLen++; /* Space for '/' */ | |
+ /* The rest of the code doesn't care if malloc fails, so we won't either */ | |
+ prefix = realloc(prefix, prefixLen + 1); /* prefix + \0 */ | |
+ prefix[prefixLen - 1] = '/'; | |
+ prefix[prefixLen] = '\0'; | |
+ } | |
+ | |
+ nameLen = strnlen(h->Name, sizeof(h->Name)); | |
+ name = StoC(h->Name, nameLen); | |
+ | |
+ file = realloc(prefix, prefixLen + nameLen + 1); /* prefix + name + \0 */ | |
+ strcat(file, name); | |
+ | |
+ free(name); | |
+ | |
+ d->Name = file; | |
+ } 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/scripts/Makefile.am b/scripts/Makefile.am | |
index fa5a75e..158b487 100644 | |
--- a/scripts/Makefile.am | |
+++ b/scripts/Makefile.am | |
@@ -123,7 +123,7 @@ nobase_dist_perllib_DATA = \ | |
Dpkg/Source/Patch.pm \ | |
Dpkg.pm | |
-do_perl_subst = sed -e "s:^\#![:space:]*/usr/bin/perl:\#!$(PERL):" \ | |
+do_perl_subst = sed -e "s:^\#![[:space:]]*/usr/bin/perl:\#!$(PERL):" \ | |
-e "s:\$$dpkglibdir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$dpkglibdir=\"$(pkglibdir)\":" \ | |
-e "s:\$$pkgdatadir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$pkgdatadir=\"$(pkgdatadir)\":" \ | |
-e "s:\$$admindir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$admindir=\"$(admindir)\":" \ | |
diff --git a/scripts/Makefile.in b/scripts/Makefile.in | |
index 0607c70..12bc0db 100644 | |
--- a/scripts/Makefile.in | |
+++ b/scripts/Makefile.in | |
@@ -330,7 +330,7 @@ nobase_dist_perllib_DATA = \ | |
Dpkg/Source/Patch.pm \ | |
Dpkg.pm | |
-do_perl_subst = sed -e "s:^\#![:space:]*/usr/bin/perl:\#!$(PERL):" \ | |
+do_perl_subst = sed -e "s:^\#![[:space:]]*/usr/bin/perl:\#!$(PERL):" \ | |
-e "s:\$$dpkglibdir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$dpkglibdir=\"$(pkglibdir)\":" \ | |
-e "s:\$$pkgdatadir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$pkgdatadir=\"$(pkgdatadir)\":" \ | |
-e "s:\$$admindir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$admindir=\"$(admindir)\":" \ | |
diff --git a/src/archives.c b/src/archives.c | |
index 70f630a..5f91662 100644 | |
--- a/src/archives.c | |
+++ b/src/archives.c | |
@@ -373,6 +373,7 @@ int tarobject(struct TarInfo *ti) { | |
static struct varbuf conffderefn, hardlinkfn, symlinkfn; | |
static int fd; | |
const char *usename; | |
+ char *s = NULL; | |
struct conffile *conff; | |
struct tarcontext *tc= (struct tarcontext*)ti->UserData; | |
@@ -423,7 +424,15 @@ int tarobject(struct TarInfo *ti) { | |
} | |
} | |
- usename= namenodetouse(nifd->namenode,tc->pkg)->name + 1; /* Skip the leading `/' */ | |
+ usename= namenodetouse(nifd->namenode,tc->pkg)->name; /* Skip the leading `/' */ | |
+ if (*usename == '.' && *usename + 1 == '/') { | |
+ usename += 1; /* Skip the leading `.' */ | |
+ } else if (*usename != '/') { | |
+ s = malloc(strlen(usename) + 2); /* 1 for NULL, one for `/' we're going to add */ | |
+ strcpy(s + 1, usename); | |
+ *s = '/'; | |
+ usename = s; | |
+ } | |
if (nifd->namenode->flags & fnnf_new_conff) { | |
/* If it's a conffile we have to extract it next to the installed | |
@@ -436,6 +445,10 @@ int tarobject(struct TarInfo *ti) { | |
setupfnamevbs(usename); | |
+ if (s != NULL) { | |
+ free(s); | |
+ } | |
+ | |
statr= lstat(fnamevb.buf,&stab); | |
if (statr) { | |
/* The lstat failed. */ | |
diff --git a/src/help.c b/src/help.c | |
index 686addb..f0c8782 100644 | |
--- a/src/help.c | |
+++ b/src/help.c | |
@@ -77,12 +77,11 @@ struct filenamenode *namenodetouse(struct filenamenode *namenode, struct pkginfo | |
void checkpath(void) { | |
/* Verify that some programs can be found in the PATH. */ | |
- static const char *const checklist[]= { "ldconfig", | |
+ static const char *const checklist[]= { | |
#if WITH_START_STOP_DAEMON | |
"start-stop-daemon", | |
#endif | |
"install-info", | |
- "update-rc.d", | |
NULL | |
}; | |
diff --git a/src/remove.c b/src/remove.c | |
index 1e92d62..28050cb 100644 | |
--- a/src/remove.c | |
+++ b/src/remove.c | |
@@ -266,7 +266,18 @@ static void removal_bulk_remove_files( | |
push_leftover(&leftover,namenode); | |
continue; | |
} | |
- if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf); | |
+ if (errno != ENOTDIR) { | |
+ /* XXX Hack: | |
+ * dpkg includes /. in the packing list. | |
+ * rmdir("/.") will return EINVAL. dpkg will | |
+ * only attempt to remove /. when uninstalling | |
+ * the last package on the system, which is why | |
+ * Debian has never run into this issue. */ | |
+ if (errno == EINVAL && strcmp(fnvb.buf, "/.") == 0) | |
+ continue; | |
+ else | |
+ ohshite(_("cannot remove `%.250s'"),fnvb.buf); | |
+ } | |
debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf); | |
{ | |
/* | |
@@ -383,7 +394,18 @@ static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) { | |
push_leftover(&leftover,namenode); | |
continue; | |
} | |
- if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf); | |
+ if (errno != ENOTDIR) { | |
+ /* XXX Hack: | |
+ * dpkg includes /. in the packing list. | |
+ * rmdir("/.") will return EINVAL. dpkg will | |
+ * only attempt to remove /. when uninstalling | |
+ * the last package on the system, which is why | |
+ * Debian has never run into this issue. */ | |
+ if (errno == EINVAL && strcmp(fnvb.buf, "/.") == 0) | |
+ continue; | |
+ else | |
+ ohshite(_("cannot remove `%.250s'"),fnvb.buf); | |
+ } | |
push_leftover(&leftover,namenode); | |
continue; | |
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c | |
index 72ad518..3913862 100644 | |
--- a/utils/start-stop-daemon.c | |
+++ b/utils/start-stop-daemon.c | |
@@ -38,6 +38,8 @@ | |
# define OSFreeBSD | |
#elif defined(__NetBSD__) | |
# define OSNetBSD | |
+#elif defined(__APPLE__) | |
+# define OSDarwin | |
#else | |
# error Unknown architecture - cannot build start-stop-daemon | |
#endif | |
@@ -49,7 +51,8 @@ | |
#include <ps.h> | |
#endif | |
-#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD) | |
+#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin) | |
+#include <sys/time.h> | |
#include <sys/param.h> | |
#include <sys/proc.h> | |
#include <sys/stat.h> | |
@@ -804,7 +807,7 @@ check(pid_t pid) | |
#if defined(OSLinux) || defined(OShpux) | |
if (execname && !pid_is_exec(pid, &exec_stat)) | |
return; | |
-#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) | |
+#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin) | |
/* Let's try this to see if it works */ | |
if (execname && !pid_is_cmd(pid, execname)) | |
return; | |
@@ -882,6 +885,7 @@ do_procinit(void) | |
} | |
#endif /* OSHURD */ | |
+#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD) | |
#ifdef HAVE_KVM_H | |
static int | |
pid_is_cmd(pid_t pid, const char *name) | |
@@ -974,8 +978,83 @@ do_procinit(void) | |
{ | |
/* Nothing to do */ | |
} | |
+#endif | |
#endif /* OSOpenBSD */ | |
+#if defined(OSDarwin) | |
+#include <sys/sysctl.h> | |
+int | |
+pid_is_user(pid_t pid, uid_t uid) | |
+{ | |
+ int mib[4]; | |
+ size_t size; | |
+ struct kinfo_proc ki; | |
+ | |
+ size = sizeof(ki); | |
+ mib[0] = CTL_KERN; | |
+ mib[1] = KERN_PROC; | |
+ mib[2] = KERN_PROC_PID; | |
+ mib[3] = pid; | |
+ if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0) | |
+ errx(1, "%s", "Failure calling sysctl"); | |
+ return (uid == ki.kp_eproc.e_pcred.p_ruid); | |
+} | |
+ | |
+static int | |
+pid_is_cmd(pid_t pid, const char *name) | |
+{ | |
+ int mib[4]; | |
+ size_t size; | |
+ struct kinfo_proc ki; | |
+ | |
+ size = sizeof(ki); | |
+ mib[0] = CTL_KERN; | |
+ mib[1] = KERN_PROC; | |
+ mib[2] = KERN_PROC_PID; | |
+ mib[3] = pid; | |
+ if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0) | |
+ errx(1, "%s", "Failure calling sysctl"); | |
+ return (!strncmp(name, ki.kp_proc.p_comm, MAXCOMLEN)); | |
+} | |
+ | |
+static void | |
+do_procinit(void) | |
+{ | |
+ int mib[3]; | |
+ size_t size; | |
+ int nprocs, ret, i; | |
+ struct kinfo_proc *procs = NULL, *newprocs; | |
+ | |
+ mib[0] = CTL_KERN; | |
+ mib[1] = KERN_PROC; | |
+ mib[2] = KERN_PROC_ALL; | |
+ ret = sysctl(mib, 3, NULL, &size, NULL, 0); | |
+ /* Allocate enough memory for entire process table */ | |
+ do { | |
+ size += size / 10; | |
+ newprocs = realloc(procs, size); | |
+ if (newprocs == NULL) { | |
+ if (procs) | |
+ free(procs); | |
+ errx(1, "%s", "Could not reallocate memory"); | |
+ } | |
+ procs = newprocs; | |
+ ret = sysctl(mib, 3, procs, &size, NULL, 0); | |
+ } while (ret >= 0 && errno == ENOMEM); | |
+ | |
+ if (ret < 0) | |
+ errx(1, "%s", "Failure calling sysctl"); | |
+ | |
+ /* Verify size of proc structure */ | |
+ if (size % sizeof(struct kinfo_proc) != 0) | |
+ errx(1, "%s", "proc size mismatch, userland out of sync with kernel"); | |
+ nprocs = size / sizeof(struct kinfo_proc); | |
+ for (i = 0; i < nprocs; i++) { | |
+ check(procs[i].kp_proc.p_pid); | |
+ } | |
+} | |
+#endif /* OSDarwin */ | |
+ | |
#if defined(OShpux) | |
static int | |
pid_is_user(pid_t pid, uid_t uid) | |
-- | |
1.7.7 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment