[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 1/2] Add virGetUserDirectoryByUID to retrieve users homedir based on UID.



On 07/30/2013 01:55 PM, dwalsh redhat com wrote:
> From: Dan Walsh <dwalsh redhat com>

Subject line was a little long; I trimmed it to:

util: add virGetUserDirectoryByUID

> 
> This function is needed for virt-login-shell.  Also modify virGirUserDirectory
> to use the new function, to simplify the code.
> ---
>  src/libvirt_private.syms | 1 +
>  src/util/virutil.c       | 9 +++++++--
>  src/util/virutil.h       | 1 +
>  3 files changed, 9 insertions(+), 2 deletions(-)

Failed to build on mingw; here's what I squashed in, then pushed:

diff --git i/src/util/virutil.c w/src/util/virutil.c
index 99812ca..aef63c7 100644
--- i/src/util/virutil.c
+++ w/src/util/virutil.c
@@ -647,6 +647,11 @@ cleanup:
     return result;
 }

+char *virGetUserDirectory(void)
+{
+    return virGetUserDirectoryByUID(geteuid());
+}
+
 #ifdef HAVE_GETPWUID_R
 /* Look up fields from the user database for the given user.  On
  * error, set errno, report the error, and return -1.  */
@@ -757,11 +762,6 @@ char *virGetUserDirectoryByUID(uid_t uid)
     return ret;
 }

-char *virGetUserDirectory(void)
-{
-    return virGetUserDirectoryByUID(geteuid());
-}
-
 static char *virGetXDGDirectory(const char *xdgenvname, const char
*xdgdefdir)
 {
     const char *path = getenv(xdgenvname);
@@ -1097,8 +1097,11 @@ virGetWin32DirectoryRoot(char **path)


 char *
-virGetUserDirectory(void)
+virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
 {
+    /* Since Windows lacks setuid, and since we already fake
+     * geteuid(), we can safely assume that this is only called when
+     * querying about the current user */
     const char *dir;
     char *ret;

@@ -1182,7 +1185,7 @@ virGetUserRuntimeDirectory(void)

 # else /* !HAVE_GETPWUID_R && !WIN32 */
 char *
-virGetUserDirectory(void)
+virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
 {
     virReportError(VIR_ERR_INTERNAL_ERROR,
                    "%s", _("virGetUserDirectory is not available"));


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]