Просмотр исходного кода

Merge remote-tracking branch 'mvo/debian/sid' into debian/sid

Michael Vogt лет назад: 12
Родитель
Сommit
f99a02461e

+ 17 - 0
apt-pkg/contrib/fileutl.cc

@@ -1827,3 +1827,20 @@ std::vector<std::string> Glob(std::string const &pattern, int flags)
    return result;
    return result;
 }
 }
 									/*}}}*/
 									/*}}}*/
+
+std::string GetTempDir()
+{
+   const char *tmpdir = getenv("TMPDIR");
+
+#ifdef P_tmpdir
+   if (!tmpdir)
+      tmpdir = P_tmpdir;
+#endif
+
+   // check that tmpdir is set and exists
+   struct stat st;
+   if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
+      tmpdir = "/tmp";
+
+   return string(tmpdir);
+}

+ 2 - 0
apt-pkg/contrib/fileutl.h

@@ -165,6 +165,8 @@ bool DirectoryExists(std::string const &Path) __attrib_const;
 bool CreateDirectory(std::string const &Parent, std::string const &Path);
 bool CreateDirectory(std::string const &Parent, std::string const &Path);
 time_t GetModificationTime(std::string const &Path);
 time_t GetModificationTime(std::string const &Path);
 
 
+std::string GetTempDir();
+
 /** \brief Ensure the existence of the given Path
 /** \brief Ensure the existence of the given Path
  *
  *
  *  \param Parent directory of the Path directory - a trailing
  *  \param Parent directory of the Path directory - a trailing

+ 2 - 13
apt-pkg/contrib/gpgv.cc

@@ -22,20 +22,9 @@
 									/*}}}*/
 									/*}}}*/
 static char * GenerateTemporaryFileTemplate(const char *basename)	/*{{{*/
 static char * GenerateTemporaryFileTemplate(const char *basename)	/*{{{*/
 {
 {
-   const char *tmpdir = getenv("TMPDIR");
-
-#ifdef P_tmpdir
-   if (!tmpdir)
-      tmpdir = P_tmpdir;
-#endif
-
-   // check that tmpdir is set and exists
-   struct stat st;
-   if (!tmpdir || stat(tmpdir, &st) != 0)
-      tmpdir = "/tmp";
-
    std::string out;
    std::string out;
-   strprintf(out,  "%s/%s.XXXXXX", tmpdir, basename);
+   std::string tmpdir = GetTempDir();
+   strprintf(out,  "%s/%s.XXXXXX", tmpdir.c_str(), basename);
    return strdup(out.c_str());
    return strdup(out.c_str());
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 1 - 1
apt-pkg/deb/dpkgpm.cc

@@ -1186,7 +1186,7 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
    StartPtyMagic();
    StartPtyMagic();
 
 
    // Tell the progress that its starting and fork dpkg 
    // Tell the progress that its starting and fork dpkg 
-   d->progress->Start();
+   d->progress->Start(d->master);
 
 
    // this loop is runs once per dpkg operation
    // this loop is runs once per dpkg operation
    vector<Item>::const_iterator I = List.begin();
    vector<Item>::const_iterator I = List.begin();

+ 42 - 17
apt-pkg/install-progress.cc

@@ -9,6 +9,7 @@
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #include <sstream>
 #include <sstream>
 #include <fcntl.h>
 #include <fcntl.h>
+#include <algorithm>
 #include <stdio.h>
 #include <stdio.h>
 
 
 namespace APT {
 namespace APT {
@@ -222,17 +223,47 @@ bool PackageManagerProgressDeb822Fd::StatusChanged(std::string PackageName,
    return true;
    return true;
 }
 }
 
 
+
+PackageManagerFancy::PackageManagerFancy()
+   : child_pty(-1)
+{
+   // setup terminal size
+   old_SIGWINCH = signal(SIGWINCH, PackageManagerFancy::staticSIGWINCH);
+   instances.push_back(this);
+}
+std::vector<PackageManagerFancy*> PackageManagerFancy::instances;
+
+PackageManagerFancy::~PackageManagerFancy()
+{
+   instances.erase(find(instances.begin(), instances.end(), this));
+   signal(SIGWINCH, old_SIGWINCH);
+}
+
+void PackageManagerFancy::staticSIGWINCH(int signum)
+{
+   std::vector<PackageManagerFancy *>::const_iterator I;
+   for(I = instances.begin(); I != instances.end(); I++)
+      (*I)->HandleSIGWINCH(signum);
+}
+
 int PackageManagerFancy::GetNumberTerminalRows()
 int PackageManagerFancy::GetNumberTerminalRows()
 {
 {
    struct winsize win;
    struct winsize win;
+   // FIXME: get from "child_pty" instead?
    if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
    if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
       return -1;
       return -1;
+
+   if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
+      std::cerr << "GetNumberTerminalRows: " << win.ws_row << std::endl;
    
    
    return win.ws_row;
    return win.ws_row;
 }
 }
 
 
 void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
 void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
 {
 {
+     if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
+        std::cerr << "SetupTerminalScrollArea: " << nr_rows << std::endl;
+
      // scroll down a bit to avoid visual glitch when the screen
      // scroll down a bit to avoid visual glitch when the screen
      // area shrinks by one row
      // area shrinks by one row
      std::cout << "\n";
      std::cout << "\n";
@@ -241,30 +272,22 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
      std::cout << "\033[s";
      std::cout << "\033[s";
          
          
      // set scroll region (this will place the cursor in the top left)
      // set scroll region (this will place the cursor in the top left)
-     std::cout << "\033[1;" << nr_rows - 1 << "r";
+     std::cout << "\033[0;" << nr_rows - 1 << "r";
             
             
      // restore cursor but ensure its inside the scrolling area
      // restore cursor but ensure its inside the scrolling area
      std::cout << "\033[u";
      std::cout << "\033[u";
      static const char *move_cursor_up = "\033[1A";
      static const char *move_cursor_up = "\033[1A";
      std::cout << move_cursor_up;
      std::cout << move_cursor_up;
 
 
-     // setup env for (hopefully!) ncurses
-     string s;
-     strprintf(s, "%i", nr_rows);
-     setenv("LINES", s.c_str(), 1);
-
+     // ensure its flushed
      std::flush(std::cout);
      std::flush(std::cout);
-}
 
 
-PackageManagerFancy::PackageManagerFancy()
-{
-   // setup terminal size
-   old_SIGWINCH = signal(SIGWINCH, HandleSIGWINCH);
-}
-
-PackageManagerFancy::~PackageManagerFancy()
-{
-   signal(SIGWINCH, old_SIGWINCH);
+     // setup tty size to ensure xterm/linux console are working properly too
+     // see bug #731738
+     struct winsize win;
+     ioctl(child_pty, TIOCGWINSZ, (char *)&win);
+     win.ws_row = nr_rows - 1;
+     ioctl(child_pty, TIOCSWINSZ, (char *)&win);
 }
 }
 
 
 void PackageManagerFancy::HandleSIGWINCH(int)
 void PackageManagerFancy::HandleSIGWINCH(int)
@@ -273,8 +296,9 @@ void PackageManagerFancy::HandleSIGWINCH(int)
    SetupTerminalScrollArea(nr_terminal_rows);
    SetupTerminalScrollArea(nr_terminal_rows);
 }
 }
 
 
-void PackageManagerFancy::Start()
+void PackageManagerFancy::Start(int a_child_pty)
 {
 {
+   child_pty = a_child_pty;
    int nr_terminal_rows = GetNumberTerminalRows();
    int nr_terminal_rows = GetNumberTerminalRows();
    if (nr_terminal_rows > 0)
    if (nr_terminal_rows > 0)
       SetupTerminalScrollArea(nr_terminal_rows);
       SetupTerminalScrollArea(nr_terminal_rows);
@@ -291,6 +315,7 @@ void PackageManagerFancy::Stop()
       static const char* clear_screen_below_cursor = "\033[J";
       static const char* clear_screen_below_cursor = "\033[J";
       std::cout << clear_screen_below_cursor;
       std::cout << clear_screen_below_cursor;
    }
    }
+   child_pty = -1;
 }
 }
 
 
 bool PackageManagerFancy::StatusChanged(std::string PackageName, 
 bool PackageManagerFancy::StatusChanged(std::string PackageName, 

+ 12 - 5
apt-pkg/install-progress.h

@@ -4,6 +4,7 @@
 #include <string>
 #include <string>
 #include <unistd.h>
 #include <unistd.h>
 #include <signal.h>
 #include <signal.h>
+#include <vector>
 
 
 namespace APT {
 namespace APT {
 namespace Progress {
 namespace Progress {
@@ -28,7 +29,7 @@ namespace Progress {
     virtual ~PackageManager() {};
     virtual ~PackageManager() {};
 
 
     /* Global Start/Stop */
     /* Global Start/Stop */
-    virtual void Start() {};
+    virtual void Start(int child_pty=-1) {};
     virtual void Stop() {};
     virtual void Stop() {};
 
 
     /* When dpkg is invoked (may happen multiple times for each 
     /* When dpkg is invoked (may happen multiple times for each 
@@ -116,16 +117,22 @@ namespace Progress {
 
 
  class PackageManagerFancy : public PackageManager
  class PackageManagerFancy : public PackageManager
  {
  {
+ private:
+    static void staticSIGWINCH(int);
+    static std::vector<PackageManagerFancy*> instances;
+
  protected:
  protected:
-    static void SetupTerminalScrollArea(int nr_rows);
-    static int GetNumberTerminalRows();
-    static void HandleSIGWINCH(int);
+    void SetupTerminalScrollArea(int nr_rows);
+    void HandleSIGWINCH(int);
+
+    int GetNumberTerminalRows();
     sighandler_t old_SIGWINCH;
     sighandler_t old_SIGWINCH;
+    int child_pty;
 
 
  public:
  public:
     PackageManagerFancy();
     PackageManagerFancy();
     ~PackageManagerFancy();
     ~PackageManagerFancy();
-    virtual void Start();
+    virtual void Start(int child_pty=-1);
     virtual void Stop();
     virtual void Stop();
     virtual bool StatusChanged(std::string PackageName, 
     virtual bool StatusChanged(std::string PackageName, 
                                unsigned int StepsDone,
                                unsigned int StepsDone,

+ 4 - 0
apt-pkg/policy.cc

@@ -405,6 +405,10 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
    PreferenceSection Tags;
    PreferenceSection Tags;
    while (TF.Step(Tags) == true)
    while (TF.Step(Tags) == true)
    {
    {
+      // can happen when there are only comments in a record
+      if (Tags.Count() == 0)
+         continue;
+
       string Name = Tags.FindS("Package");
       string Name = Tags.FindS("Package");
       if (Name.empty() == true)
       if (Name.empty() == true)
 	 return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
 	 return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());

+ 9 - 2
apt-pkg/tagfile.cc

@@ -259,7 +259,12 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
    TagCount = 0;
    TagCount = 0;
    while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
    while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
    {
    {
-       TrimRecord(true,End);
+      TrimRecord(true,End);
+
+      // this can happen when TrimRecord trims away the entire Record
+      // (e.g. because it just contains comments)
+      if(Stop == End)
+         return true;
 
 
       // Start a new index and add it to the hash
       // Start a new index and add it to the hash
       if (isspace(Stop[0]) == 0)
       if (isspace(Stop[0]) == 0)
@@ -273,7 +278,9 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
       if (Stop == 0)
       if (Stop == 0)
 	 return false;
 	 return false;
 
 
-      for (; Stop+1 < End && Stop[1] == '\r'; Stop++);
+      for (; Stop+1 < End && Stop[1] == '\r'; Stop++)
+         /* nothing */
+         ;
 
 
       // Double newline marks the end of the record
       // Double newline marks the end of the record
       if (Stop+1 < End && Stop[1] == '\n')
       if (Stop+1 < End && Stop[1] == '\n')

+ 3 - 8
cmdline/apt-extracttemplates.cc

@@ -47,8 +47,6 @@
 
 
 using namespace std;
 using namespace std;
 
 
-#define TMPDIR		"/tmp"
-
 pkgCache *DebFile::Cache = 0;
 pkgCache *DebFile::Cache = 0;
 
 
 // DebFile::DebFile - Construct the DebFile object			/*{{{*/
 // DebFile::DebFile - Construct the DebFile object			/*{{{*/
@@ -253,14 +251,11 @@ string WriteFile(const char *package, const char *prefix, const char *data)
 {
 {
 	char fn[512];
 	char fn[512];
 	static int i;
 	static int i;
-	const char *tempdir = NULL;
-
-        tempdir = getenv("TMPDIR");
-        if (tempdir == NULL)
-             tempdir = TMPDIR;
 
 
+        std::string tempdir = GetTempDir();
 	snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
 	snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
-                 _config->Find("APT::ExtractTemplates::TempDir", tempdir).c_str(),
+                 _config->Find("APT::ExtractTemplates::TempDir", 
+                               tempdir.c_str()).c_str(),
                  package, prefix, getpid(), i++);
                  package, prefix, getpid(), i++);
 	FileFd f;
 	FileFd f;
 	if (data == NULL)
 	if (data == NULL)

+ 4 - 6
cmdline/apt-get.cc

@@ -1536,14 +1536,12 @@ bool DoChangelog(CommandLine &CmdL)
    bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
    bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
 
 
    char tmpname[100];
    char tmpname[100];
-   char* tmpdir = NULL;
+   const char* tmpdir = NULL;
    if (downOnly == false)
    if (downOnly == false)
    {
    {
-      const char* const tmpDir = getenv("TMPDIR");
-      if (tmpDir != NULL && *tmpDir != '\0')
-	 snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir);
-      else
-	 strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname));
+      std::string systemTemp = GetTempDir();
+      snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", 
+               systemTemp.c_str());
       tmpdir = mkdtemp(tmpname);
       tmpdir = mkdtemp(tmpname);
       if (tmpdir == NULL)
       if (tmpdir == NULL)
 	 return _error->Errno("mkdtemp", "mkdtemp failed");
 	 return _error->Errno("mkdtemp", "mkdtemp failed");

+ 13 - 6
cmdline/apt-key.in

@@ -25,6 +25,9 @@ GPG_CMD="$GPG_CMD --no-auto-check-trustdb --trust-model always"
 
 
 GPG="$GPG_CMD"
 GPG="$GPG_CMD"
 
 
+APT_DIR="/"
+eval $(apt-config shell APT_DIR Dir)
+
 MASTER_KEYRING='&keyring-master-filename;'
 MASTER_KEYRING='&keyring-master-filename;'
 eval $(apt-config shell MASTER_KEYRING APT::Key::MasterKeyring)
 eval $(apt-config shell MASTER_KEYRING APT::Key::MasterKeyring)
 ARCHIVE_KEYRING='&keyring-filename;'
 ARCHIVE_KEYRING='&keyring-filename;'
@@ -33,7 +36,7 @@ REMOVED_KEYS='&keyring-removed-filename;'
 eval $(apt-config shell REMOVED_KEYS APT::Key::RemovedKeys)
 eval $(apt-config shell REMOVED_KEYS APT::Key::RemovedKeys)
 ARCHIVE_KEYRING_URI='&keyring-uri;'
 ARCHIVE_KEYRING_URI='&keyring-uri;'
 eval $(apt-config shell ARCHIVE_KEYRING_URI APT::Key::ArchiveKeyringURI)
 eval $(apt-config shell ARCHIVE_KEYRING_URI APT::Key::ArchiveKeyringURI)
-TMP_KEYRING=/var/lib/apt/keyrings/maybe-import-keyring.gpg
+TMP_KEYRING=${APT_DIR}/var/lib/apt/keyrings/maybe-import-keyring.gpg
 
 
 requires_root() {
 requires_root() {
 	if [ "$(id -u)" -ne 0 ]; then
 	if [ "$(id -u)" -ne 0 ]; then
@@ -107,7 +110,11 @@ add_keys_with_verify_against_master_keyring() {
 # (otherwise it does not make sense from a security POV)
 # (otherwise it does not make sense from a security POV)
 net_update() {
 net_update() {
     # Disabled for now as code is insecure (LP: #1013639 (and 857472, 1013128))
     # Disabled for now as code is insecure (LP: #1013639 (and 857472, 1013128))
-    exit 1
+    APT_KEY_NET_UPDATE_ENABLED=""
+    eval $(apt-config shell APT_KEY_NET_UPDATE_ENABLED APT::Key::Net-Update-Enabled)
+    if [ -z "$APT_KEY_NET_UPDATE_ENABLED" ]; then
+        exit 1
+    fi
 
 
     if [ -z "$ARCHIVE_KEYRING_URI" ]; then
     if [ -z "$ARCHIVE_KEYRING_URI" ]; then
 	echo >&2 "ERROR: Your distribution is not supported in net-update as no uri for the archive-keyring is set"
 	echo >&2 "ERROR: Your distribution is not supported in net-update as no uri for the archive-keyring is set"
@@ -120,15 +127,15 @@ net_update() {
 	echo >&2 "ERROR: an installed wget is required for a network-based update"
 	echo >&2 "ERROR: an installed wget is required for a network-based update"
 	exit 1
 	exit 1
     fi
     fi
-    if [ ! -d /var/lib/apt/keyrings ]; then
-	mkdir -p /var/lib/apt/keyrings
+    if [ ! -d ${APT_DIR}/var/lib/apt/keyrings ]; then
+	mkdir -p ${APT_DIR}/var/lib/apt/keyrings
     fi
     fi
-    keyring=/var/lib/apt/keyrings/$(basename $ARCHIVE_KEYRING)
+    keyring=${APT_DIR}/var/lib/apt/keyrings/$(basename $ARCHIVE_KEYRING_URI)
     old_mtime=0
     old_mtime=0
     if [ -e $keyring ]; then
     if [ -e $keyring ]; then
 	old_mtime=$(stat -c %Y $keyring)
 	old_mtime=$(stat -c %Y $keyring)
     fi
     fi
-    (cd  /var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
+    (cd  ${APT_DIR}/var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
     if [ ! -e $keyring ]; then
     if [ ! -e $keyring ]; then
 	return
 	return
     fi
     fi

+ 14 - 3
debian/tests/run-tests

@@ -2,6 +2,17 @@
 
 
 set -e
 set -e
 
 
-make
-make test
-test/integration/run-tests
+# auto-package-test is very unhappy if stuff it writen to stderr
+exec 2> apt-stderr.log
+
+# we need the buildin webserver for the tests
+if [ ! -e environment.mak ]; then
+    ./configure
+fi
+make -C test/interactive-helper/
+
+# run against the installed apt
+APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR=$(pwd)/build/bin \
+APT_INTEGRATION_TESTS_METHODS_DIR=/usr/lib/apt/methods \
+APT_INTEGRATION_TESTS_BUILD_DIR=/usr/bin \
+./test/integration/run-tests

BIN
test/integration/exploid-keyring-with-dupe-keys.pub


BIN
test/integration/exploid-keyring-with-dupe-subkeys.pub


+ 13 - 4
test/integration/framework

@@ -102,6 +102,9 @@ aptget() { runapt apt-get $*; }
 aptftparchive() { runapt apt-ftparchive $*; }
 aptftparchive() { runapt apt-ftparchive $*; }
 aptkey() { runapt apt-key $*; }
 aptkey() { runapt apt-key $*; }
 aptmark() { runapt apt-mark $*; }
 aptmark() { runapt apt-mark $*; }
+aptwebserver() {
+  LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver $*;
+}
 dpkg() {
 dpkg() {
 	$(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
 	$(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
 }
 }
@@ -154,8 +157,14 @@ setupenvironment() {
 	TMPWORKINGDIRECTORY=$(mktemp -d)
 	TMPWORKINGDIRECTORY=$(mktemp -d)
 	TESTDIRECTORY=$(readlink -f $(dirname $0))
 	TESTDIRECTORY=$(readlink -f $(dirname $0))
 	msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
 	msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
-	BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin"
+
+        # allow overriding the default BUILDDIR location
+	BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
+        METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
+        APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
 	test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
 	test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
+        # -----
+
 	addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
 	addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
 	cd $TMPWORKINGDIRECTORY
 	cd $TMPWORKINGDIRECTORY
 	mkdir rootdir aptarchive keys
 	mkdir rootdir aptarchive keys
@@ -181,7 +190,7 @@ setupenvironment() {
 	echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
 	echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
 	echo "Debug::NoLocking \"true\";" >> aptconfig.conf
 	echo "Debug::NoLocking \"true\";" >> aptconfig.conf
 	echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
 	echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
-	echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
+	echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
 	echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
 	echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
 	echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
 	echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
 	echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
 	echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
@@ -822,9 +831,9 @@ changetowebserver() {
 		shift
 		shift
 	fi
 	fi
 	local LOG='/dev/null'
 	local LOG='/dev/null'
-	if test -x ${BUILDDIRECTORY}/aptwebserver; then
+	if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
 		cd aptarchive
 		cd aptarchive
-		LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
+		aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
 		local PID="$(cat aptwebserver.pid)"
 		local PID="$(cat aptwebserver.pid)"
 		if [ -z "$PID" ]; then
 		if [ -z "$PID" ]; then
 			msgdie 'Could not fork aptwebserver successfully'
 			msgdie 'Could not fork aptwebserver successfully'

BIN
test/integration/keyrings/test-archive-keyring.pub


BIN
test/integration/keyrings/test-archive-keyring.sec


BIN
test/integration/keyrings/test-master-keyring.pub


BIN
test/integration/keyrings/test-master-keyring.sec


+ 26 - 97
test/integration/test-apt-key-net-update

@@ -6,109 +6,38 @@ TESTDIR=$(readlink -f $(dirname $0))
 
 
 setupenvironment
 setupenvironment
 configarchitecture "i386"
 configarchitecture "i386"
+changetowebserver
 
 
-# mock
-requires_root() {
-    return 0
-}
+# setup env
+mkdir -p var/lib/apt/keyrings
+mkdir -p usr/share/keyrings
 
 
-# extract net_update() and import it
-func=$( sed -n -e '/^add_keys_with_verify_against_master_keyring/,/^}/p' ${BUILDDIRECTORY}/apt-key )
-eval "$func"
+# install the fake master keyring
+install -m0644 keys/test-master-keyring.pub usr/share/keyrings
+echo "APT::Key::MasterKeyring \"${TMPWORKINGDIRECTORY}/usr/share/keyrings/test-master-keyring.pub\";" >> ./aptconfig.conf
 
 
-mkdir -p ./etc/apt
-TRUSTEDFILE=./etc/apt/trusted.gpg
-mkdir -p ./var/lib/apt/keyrings
-TMP_KEYRING=./var/lib/apt/keyrings/maybe-import-keyring.gpg
-GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring"
+# setup archive-keyring 
+mkdir -p aptarchive/ubuntu/project
+install -m0644 keys/test-archive-keyring.pub aptarchive/ubuntu/project/
+echo 'APT::Key::ArchiveKeyringURI "http://localhost:8080/ubuntu/project/test-archive-keyring.pub";' >> ./aptconfig.conf
+echo 'APT::Key::Net-Update-Enabled "1";' >> ./aptconfig.conf
 
 
-# FIXME: instead of copying this use apt-key and the buildin apt webserver
-#        to do a real test
+# test against the "real" webserver
+testequal 'Checking for new archive signing keys now
+gpg: key F68C85A3: public key "Test Automatic Archive Signing Key <ftpmaster@example.com>" imported
+gpg: Total number processed: 1
+gpg:               imported: 1  (RSA: 1)' aptkey --fakeroot net-update
 
 
-# COPYIED from apt-key.in --------------
 
 
-# gpg needs a trustdb to function, but it can't be invalid (not even empty)
-# so we create a temporary directory to store our fresh readable trustdb in
-TRUSTDBDIR="$(mktemp -d)"
-CURRENTTRAP="${CURRENTTRAP} rm -rf '${TRUSTDBDIR}';"
-trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
-chmod 700 "$TRUSTDBDIR"
-# We also don't use a secret keyring, of course, but gpg panics and
-# implodes if there isn't one available - and writeable for imports
-SECRETKEYRING="${TRUSTDBDIR}/secring.gpg"
-touch $SECRETKEYRING
-GPG_CMD="$GPG_CMD --secret-keyring $SECRETKEYRING"
-GPG_CMD="$GPG_CMD --trustdb-name ${TRUSTDBDIR}/trustdb.gpg"
-#----------------------------------------- END COPY
+# now try a different one
+# setup archive-keyring 
+mkdir -p aptarchive/ubuntu/project
+install -m0644 keys/marvinparanoid.pub aptarchive/ubuntu/project/
+echo 'APT::Key::ArchiveKeyringURI "http://localhost:8080/ubuntu/project/marvinparanoid.pub";' >> ./aptconfig.conf
+echo 'APT::Key::Net-Update-Enabled "1";' >> ./aptconfig.conf
 
 
-GPG="$GPG_CMD --keyring $TRUSTEDFILE"
-MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg
+# test against the "real" webserver
+testequal "Checking for new archive signing keys now
+Key 'E8525D47528144E2' not added. It is not signed with a master key" aptkey --fakeroot net-update
 
 
-msgtest "add_keys_with_verify_against_master_keyring"
-if [ ! -e $MASTER_KEYRING ]; then
-    echo -n "No $MASTER_KEYRING found"
-    msgskip 
-    exit 0
-fi
-
-# test bad keyring and ensure its not added (LP: #857472)
-ADD_KEYRING=./keys/exploid-keyring-with-dupe-keys.pub
-if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
-    msgfail
-else
-    msgpass
-fi
-
-# ensure the keyring is still empty
-gpg_out=$($GPG --list-keys)
-msgtest "Test if keyring is empty"
-if [ -n "" ]; then
-    msgfail
-else
-    msgpass
-fi
-
-
-# test another possible attack vector using subkeys (LP: #1013128)
-msgtest "add_keys_with_verify_against_master_keyring with subkey attack"
-ADD_KEYRING=./keys/exploid-keyring-with-dupe-subkeys.pub
-if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
-    msgfail
-else
-    msgpass
-fi
-
-# ensure the keyring is still empty
-gpg_out=$($GPG --list-keys)
-msgtest "Test if keyring is empty"
-if [ -n "" ]; then
-    msgfail
-else
-    msgpass
-fi
-
-
-# test good keyring and ensure we get no errors
-ADD_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg
-if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
-    msgpass
-else
-    msgfail
-fi
-
-testequal './etc/apt/trusted.gpg
----------------------
-pub   1024D/437D05B5 2004-09-12
-uid                  Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
-sub   2048g/79164387 2004-09-12
-
-pub   1024D/FBB75451 2004-12-30
-uid                  Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
-
-pub   4096R/C0B21F32 2012-05-11
-uid                  Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>
-
-pub   4096R/EFE21092 2012-05-11
-uid                  Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>
-' $GPG --list-keys
 
 

+ 18 - 0
test/integration/test-bug-728500-tempdir

@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+buildsimplenativepackage 'coolstuff' 'all' '1.0' 'unstable'
+
+setupaptarchive
+changetowebserver
+
+msgtest 'Test with incorect TMPDIR'
+export TMPDIR=/does-not-exists
+aptget update && msgpass || msgfail
+unset TMPDIR

+ 32 - 0
test/integration/test-bug-732746-preferences

@@ -0,0 +1,32 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+insertinstalledpackage 'bar' 'i386' '1.0'
+
+cat > rootdir/etc/apt/preferences << EOF
+# random test comment header
+
+# commented out by puppy^Wpuppet
+#Package: foo
+#Pin: origin "ftp.debian.org"
+#Pin: 800
+
+Package: bar
+Pin: version 1.0
+Pin-Priority: 700
+
+#Package: bar
+#Pin: version 1.0
+#Pin: 800
+EOF
+
+testequal "Reading package lists...
+Building dependency tree..." aptget check
+
+msgtest "Ensure policy is applied"
+aptcache policy bar|grep -q "*** 1.0 700" && msgpass || msgfail

+ 13 - 0
test/libapt/fileutl_test.cc

@@ -38,5 +38,18 @@ int main(int argc,char *argv[])
       return 1;
       return 1;
    }
    }
 
 
+   // GetTempDir()
+   unsetenv("TMPDIR");
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "", 1);
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "/not-there-no-really-not", 1);
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "/usr", 1);
+   equals(GetTempDir(), "/usr");
+
    return 0;
    return 0;
 }
 }