mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: add function for looking up the user shell
Add a virGetUserShell wrapper around virGetUserEnt, that returns the shell field. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
86dd9fac0f
commit
235620463c
@ -2516,6 +2516,7 @@ virGetUserDirectoryByUID;
|
|||||||
virGetUserID;
|
virGetUserID;
|
||||||
virGetUserName;
|
virGetUserName;
|
||||||
virGetUserRuntimeDirectory;
|
virGetUserRuntimeDirectory;
|
||||||
|
virGetUserShell;
|
||||||
virHexToBin;
|
virHexToBin;
|
||||||
virIndexToDiskName;
|
virIndexToDiskName;
|
||||||
virIsCapableFCHost;
|
virIsCapableFCHost;
|
||||||
|
@ -757,7 +757,7 @@ virGetUserDirectory(void)
|
|||||||
/* Look up fields from the user database for the given user. On
|
/* Look up fields from the user database for the given user. On
|
||||||
* error, set errno, report the error, and return -1. */
|
* error, set errno, report the error, and return -1. */
|
||||||
static int
|
static int
|
||||||
virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir)
|
virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell)
|
||||||
{
|
{
|
||||||
char *strbuf;
|
char *strbuf;
|
||||||
struct passwd pwbuf;
|
struct passwd pwbuf;
|
||||||
@ -771,6 +771,8 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir)
|
|||||||
*name = NULL;
|
*name = NULL;
|
||||||
if (dir)
|
if (dir)
|
||||||
*dir = NULL;
|
*dir = NULL;
|
||||||
|
if (shell)
|
||||||
|
*shell = NULL;
|
||||||
|
|
||||||
/* sysconf is a hint; if it fails, fall back to a reasonable size */
|
/* sysconf is a hint; if it fails, fall back to a reasonable size */
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
@ -806,14 +808,21 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (group)
|
if (group)
|
||||||
*group = pw->pw_gid;
|
*group = pw->pw_gid;
|
||||||
if (dir && VIR_STRDUP(*dir, pw->pw_dir) < 0) {
|
if (dir && VIR_STRDUP(*dir, pw->pw_dir) < 0)
|
||||||
if (name)
|
goto cleanup;
|
||||||
VIR_FREE(*name);
|
if (shell && VIR_STRDUP(*shell, pw->pw_shell) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (ret < 0) {
|
||||||
|
if (name)
|
||||||
|
VIR_FREE(*name);
|
||||||
|
if (dir)
|
||||||
|
VIR_FREE(*dir);
|
||||||
|
if (shell)
|
||||||
|
VIR_FREE(*shell);
|
||||||
|
}
|
||||||
VIR_FREE(strbuf);
|
VIR_FREE(strbuf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -873,7 +882,15 @@ char *
|
|||||||
virGetUserDirectoryByUID(uid_t uid)
|
virGetUserDirectoryByUID(uid_t uid)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
virGetUserEnt(uid, NULL, NULL, &ret);
|
virGetUserEnt(uid, NULL, NULL, &ret, NULL);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *virGetUserShell(uid_t uid)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
virGetUserEnt(uid, NULL, NULL, NULL, &ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +940,7 @@ char *virGetUserRuntimeDirectory(void)
|
|||||||
char *virGetUserName(uid_t uid)
|
char *virGetUserName(uid_t uid)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
virGetUserEnt(uid, &ret, NULL, NULL);
|
virGetUserEnt(uid, &ret, NULL, NULL, NULL);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,7 +1126,7 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list)
|
|||||||
if (uid == (uid_t)-1)
|
if (uid == (uid_t)-1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (virGetUserEnt(uid, &user, &primary, NULL) < 0)
|
if (virGetUserEnt(uid, &user, &primary, NULL, NULL) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = mgetgroups(user, primary, list);
|
ret = mgetgroups(user, primary, list);
|
||||||
@ -1283,6 +1300,15 @@ virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
virGetUserShell(uid_t uid ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("virGetUserShell is not available"));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virGetUserConfigDirectory(void)
|
virGetUserConfigDirectory(void)
|
||||||
{
|
{
|
||||||
@ -1329,6 +1355,15 @@ virGetUserDirectoryByUID(uid_t uid ATTRIBUTE_UNUSED)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
virGetUserShell(uid_t uid ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("virGetUserShell is not available"));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virGetUserConfigDirectory(void)
|
virGetUserConfigDirectory(void)
|
||||||
{
|
{
|
||||||
|
@ -139,6 +139,7 @@ char *virGetUserDirectoryByUID(uid_t uid);
|
|||||||
char *virGetUserConfigDirectory(void);
|
char *virGetUserConfigDirectory(void);
|
||||||
char *virGetUserCacheDirectory(void);
|
char *virGetUserCacheDirectory(void);
|
||||||
char *virGetUserRuntimeDirectory(void);
|
char *virGetUserRuntimeDirectory(void);
|
||||||
|
char *virGetUserShell(uid_t uid);
|
||||||
char *virGetUserName(uid_t uid);
|
char *virGetUserName(uid_t uid);
|
||||||
char *virGetGroupName(gid_t gid);
|
char *virGetGroupName(gid_t gid);
|
||||||
int virGetGroupList(uid_t uid, gid_t group, gid_t **groups)
|
int virGetGroupList(uid_t uid, gid_t group, gid_t **groups)
|
||||||
|
Loading…
Reference in New Issue
Block a user