mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
util: add virGetUserDirectoryByUID
This function is needed for virt-login-shell. Also modify virGirUserDirectory to use the new function, to simplify the code. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
02033b633a
commit
fbd7682706
@ -2044,6 +2044,7 @@ virGetUnprivSGIOSysfsPath;
|
||||
virGetUserCacheDirectory;
|
||||
virGetUserConfigDirectory;
|
||||
virGetUserDirectory;
|
||||
virGetUserDirectoryByUID;
|
||||
virGetUserID;
|
||||
virGetUserName;
|
||||
virGetUserRuntimeDirectory;
|
||||
|
@ -647,6 +647,14 @@ 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. */
|
||||
@ -750,13 +758,16 @@ static char *virGetGroupEnt(gid_t gid)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *virGetUserDirectory(void)
|
||||
|
||||
char *
|
||||
virGetUserDirectoryByUID(uid_t uid)
|
||||
{
|
||||
char *ret;
|
||||
virGetUserEnt(geteuid(), NULL, NULL, &ret);
|
||||
virGetUserEnt(uid, NULL, NULL, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir)
|
||||
{
|
||||
const char *path = getenv(xdgenvname);
|
||||
@ -1092,8 +1103,11 @@ virGetWin32DirectoryRoot(char **path)
|
||||
|
||||
|
||||
char *
|
||||
virGetUserDirectory(void)
|
||||
virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* Since Windows lacks setuid binaries, 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;
|
||||
|
||||
@ -1177,7 +1191,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"));
|
||||
|
@ -111,6 +111,7 @@ static inline int getgid (void) { return 0; }
|
||||
char *virGetHostname(void);
|
||||
|
||||
char *virGetUserDirectory(void);
|
||||
char *virGetUserDirectoryByUID(uid_t uid);
|
||||
char *virGetUserConfigDirectory(void);
|
||||
char *virGetUserCacheDirectory(void);
|
||||
char *virGetUserRuntimeDirectory(void);
|
||||
|
Loading…
Reference in New Issue
Block a user