render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
43fe83
From 4e04f5df15242cceaba6c60992cfb2347afee457 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <4e04f5df15242cceaba6c60992cfb2347afee457.1377873638.git.jdenemar@redhat.com>
43fe83
From: Dan Walsh <dwalsh@redhat.com>
43fe83
Date: Tue, 13 Aug 2013 15:20:39 +0100
43fe83
Subject: [PATCH] util: add virGetUserDirectoryByUID
43fe83
43fe83
For https://bugzilla.redhat.com/show_bug.cgi?id=988491
43fe83
43fe83
This function is needed for virt-login-shell.  Also modify virGirUserDirectory
43fe83
to use the new function, to simplify the code.
43fe83
43fe83
Signed-off-by: Eric Blake <eblake@redhat.com>
43fe83
(cherry picked from commit fbd7682706d52445fbc0f6fa1c4b7965256e733f)
43fe83
---
43fe83
 src/libvirt_private.syms |  1 +
43fe83
 src/util/virutil.c       | 22 ++++++++++++++++++----
43fe83
 src/util/virutil.h       |  1 +
43fe83
 3 files changed, 20 insertions(+), 4 deletions(-)
43fe83
43fe83
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
43fe83
index 9cfb84c..faa67ad 100644
43fe83
--- a/src/libvirt_private.syms
43fe83
+++ b/src/libvirt_private.syms
43fe83
@@ -2047,6 +2047,7 @@ virGetUnprivSGIOSysfsPath;
43fe83
 virGetUserCacheDirectory;
43fe83
 virGetUserConfigDirectory;
43fe83
 virGetUserDirectory;
43fe83
+virGetUserDirectoryByUID;
43fe83
 virGetUserID;
43fe83
 virGetUserName;
43fe83
 virGetUserRuntimeDirectory;
43fe83
diff --git a/src/util/virutil.c b/src/util/virutil.c
43fe83
index adcdb3c..3abcd53 100644
43fe83
--- a/src/util/virutil.c
43fe83
+++ b/src/util/virutil.c
43fe83
@@ -647,6 +647,14 @@ cleanup:
43fe83
     return result;
43fe83
 }
43fe83
 
43fe83
+
43fe83
+char *
43fe83
+virGetUserDirectory(void)
43fe83
+{
43fe83
+    return virGetUserDirectoryByUID(geteuid());
43fe83
+}
43fe83
+
43fe83
+
43fe83
 #ifdef HAVE_GETPWUID_R
43fe83
 /* Look up fields from the user database for the given user.  On
43fe83
  * error, set errno, report the error, and return -1.  */
43fe83
@@ -750,13 +758,16 @@ static char *virGetGroupEnt(gid_t gid)
43fe83
     return ret;
43fe83
 }
43fe83
 
43fe83
-char *virGetUserDirectory(void)
43fe83
+
43fe83
+char *
43fe83
+virGetUserDirectoryByUID(uid_t uid)
43fe83
 {
43fe83
     char *ret;
43fe83
-    virGetUserEnt(geteuid(), NULL, NULL, &ret;;
43fe83
+    virGetUserEnt(uid, NULL, NULL, &ret;;
43fe83
     return ret;
43fe83
 }
43fe83
 
43fe83
+
43fe83
 static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir)
43fe83
 {
43fe83
     const char *path = getenv(xdgenvname);
43fe83
@@ -1092,8 +1103,11 @@ virGetWin32DirectoryRoot(char **path)
43fe83
 
43fe83
 
43fe83
 char *
43fe83
-virGetUserDirectory(void)
43fe83
+virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
43fe83
 {
43fe83
+    /* Since Windows lacks setuid binaries, and since we already fake
43fe83
+     * geteuid(), we can safely assume that this is only called when
43fe83
+     * querying about the current user */
43fe83
     const char *dir;
43fe83
     char *ret;
43fe83
 
43fe83
@@ -1177,7 +1191,7 @@ virGetUserRuntimeDirectory(void)
43fe83
 
43fe83
 # else /* !HAVE_GETPWUID_R && !WIN32 */
43fe83
 char *
43fe83
-virGetUserDirectory(void)
43fe83
+virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
43fe83
 {
43fe83
     virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
                    "%s", _("virGetUserDirectory is not available"));
43fe83
diff --git a/src/util/virutil.h b/src/util/virutil.h
43fe83
index 526c610..4b06992 100644
43fe83
--- a/src/util/virutil.h
43fe83
+++ b/src/util/virutil.h
43fe83
@@ -111,6 +111,7 @@ static inline int getgid (void) { return 0; }
43fe83
 char *virGetHostname(void);
43fe83
 
43fe83
 char *virGetUserDirectory(void);
43fe83
+char *virGetUserDirectoryByUID(uid_t uid);
43fe83
 char *virGetUserConfigDirectory(void);
43fe83
 char *virGetUserCacheDirectory(void);
43fe83
 char *virGetUserRuntimeDirectory(void);
43fe83
-- 
43fe83
1.8.3.2
43fe83