mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
security: use a single function to set DAC user and group
Merge the functions 'virSecurityDACSetUser' and 'virSecurityDACSetGroup' into 'virSecurityDACSetUserAndGroup'. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
1bc12e1c46
commit
4387132f31
@ -47,22 +47,25 @@ struct _virSecurityDACData {
|
|||||||
gid_t *groups;
|
gid_t *groups;
|
||||||
int ngroups;
|
int ngroups;
|
||||||
bool dynamicOwnership;
|
bool dynamicOwnership;
|
||||||
|
char *baselabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
/* returns -1 on error, 0 on success */
|
||||||
virSecurityDACSetUser(virSecurityManagerPtr mgr,
|
int
|
||||||
uid_t user)
|
virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
|
||||||
|
uid_t user,
|
||||||
|
gid_t group)
|
||||||
{
|
{
|
||||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
||||||
priv->user = user;
|
priv->user = user;
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
virSecurityDACSetGroup(virSecurityManagerPtr mgr,
|
|
||||||
gid_t group)
|
|
||||||
{
|
|
||||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
|
||||||
priv->group = group;
|
priv->group = group;
|
||||||
|
|
||||||
|
if (virAsprintf(&priv->baselabel, "%u:%u",
|
||||||
|
(unsigned int) user,
|
||||||
|
(unsigned int) group) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -217,6 +220,7 @@ virSecurityDACClose(virSecurityManagerPtr mgr)
|
|||||||
{
|
{
|
||||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
||||||
VIR_FREE(priv->groups);
|
VIR_FREE(priv->groups);
|
||||||
|
VIR_FREE(priv->baselabel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,9 @@
|
|||||||
|
|
||||||
extern virSecurityDriver virSecurityDriverDAC;
|
extern virSecurityDriver virSecurityDriverDAC;
|
||||||
|
|
||||||
void virSecurityDACSetUser(virSecurityManagerPtr mgr,
|
int virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
|
||||||
uid_t user);
|
uid_t user,
|
||||||
void virSecurityDACSetGroup(virSecurityManagerPtr mgr,
|
gid_t group);
|
||||||
gid_t group);
|
|
||||||
|
|
||||||
void virSecurityDACSetDynamicOwnership(virSecurityManagerPtr mgr,
|
void virSecurityDACSetDynamicOwnership(virSecurityManagerPtr mgr,
|
||||||
bool dynamic);
|
bool dynamic);
|
||||||
|
@ -146,8 +146,10 @@ virSecurityManagerPtr virSecurityManagerNewDAC(const char *virtDriver,
|
|||||||
if (!mgr)
|
if (!mgr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
virSecurityDACSetUser(mgr, user);
|
if (virSecurityDACSetUserAndGroup(mgr, user, group) < 0) {
|
||||||
virSecurityDACSetGroup(mgr, group);
|
virSecurityManagerDispose(mgr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
virSecurityDACSetDynamicOwnership(mgr, dynamicOwnership);
|
virSecurityDACSetDynamicOwnership(mgr, dynamicOwnership);
|
||||||
|
|
||||||
return mgr;
|
return mgr;
|
||||||
|
Loading…
Reference in New Issue
Block a user