Package: aptitude
Version: 0.4.1-1.1
Severity: important
Tags: patch

When invoked with sudo (and probably su -) ~/.aptitude/config
of the invoking user ends up being owned by root. The patch below
resolves this problem by using getpwuid(getuid()) to determine
the prevaling home directory (of root) rather than using $HOME
(of the invoking user).

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17-1-686
Locale: LANG=ja_JP.utf8, LC_CTYPE=ja_JP.utf8 (charmap=UTF-8) (ignored: LC_ALL 
set to ja_JP.utf8)

Versions of packages aptitude depends on:
ii  apt [libapt-pkg-libc6.3-6-3.1 0.6.44.2   Advanced front-end for dpkg
ii  libc6                         2.3.6-15   GNU C Library: Shared libraries
ii  libgcc1                       1:4.1.1-7  GCC support library
ii  libncursesw5                  5.5-2      Shared libraries for terminal hand
ii  libsigc++-2.0-0c2a            2.0.16-3   type-safe Signal Framework for C++
ii  libstdc++6                    4.1.1-7    The GNU Standard C++ Library v3

Versions of packages aptitude recommends:
pn  aptitude-doc-en | aptitude-do <none>     (no description available)

-- no debconf information

--- aptitude-0.4.1.orig/src/generic/apt/apt.cc
+++ aptitude-0.4.1/src/generic/apt/apt.cc
@@ -50,6 +50,8 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <sys/types.h>
+#include <pwd.h>
 
 using namespace std;
 
@@ -108,6 +110,21 @@
     }
 }
 
+/* In the case where sudo (and probably su without the - argument) is in
+ * use, getenv("HOME") will be the home directory of the calling user and
+ * /.aptitude/config will end up being in that user's home directory owned
+ * by root. So use getpwuid(), instead. */
+static const char *gethome()
+{
+  struct passwd *pw;
+
+  pw = getpwuid(getuid());
+  if (!pw)
+    return NULL;
+
+  return pw->pw_dir;
+}
+
 void apt_preinit()
 {
   signal(SIGPIPE, SIG_IGN);
@@ -121,7 +138,7 @@
   pkgInitSystem(*_config, _system);
 
   // Allow a user-specific customization file.
-  const char *HOME = getenv("HOME");
+  const char *HOME = gethome();
 
   string cfgloc;
 
@@ -159,7 +176,7 @@
 {
   string cfgloc;
 
-  const char *HOME = getenv("HOME");
+  const char *HOME = gethome();
   if(HOME != NULL && *HOME != '\0')
     {
       string tmp(HOME);


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to