mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +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;
|
||||
int ngroups;
|
||||
bool dynamicOwnership;
|
||||
char *baselabel;
|
||||
};
|
||||
|
||||
void
|
||||
virSecurityDACSetUser(virSecurityManagerPtr mgr,
|
||||
uid_t user)
|
||||
/* returns -1 on error, 0 on success */
|
||||
int
|
||||
virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
|
||||
uid_t user,
|
||||
gid_t group)
|
||||
{
|
||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
||||
priv->user = user;
|
||||
}
|
||||
|
||||
void
|
||||
virSecurityDACSetGroup(virSecurityManagerPtr mgr,
|
||||
gid_t group)
|
||||
{
|
||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
||||
priv->group = group;
|
||||
|
||||
if (virAsprintf(&priv->baselabel, "%u:%u",
|
||||
(unsigned int) user,
|
||||
(unsigned int) group) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -217,6 +220,7 @@ virSecurityDACClose(virSecurityManagerPtr mgr)
|
||||
{
|
||||
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
|
||||
VIR_FREE(priv->groups);
|
||||
VIR_FREE(priv->baselabel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,9 @@
|
||||
|
||||
extern virSecurityDriver virSecurityDriverDAC;
|
||||
|
||||
void virSecurityDACSetUser(virSecurityManagerPtr mgr,
|
||||
uid_t user);
|
||||
void virSecurityDACSetGroup(virSecurityManagerPtr mgr,
|
||||
gid_t group);
|
||||
int virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
|
||||
uid_t user,
|
||||
gid_t group);
|
||||
|
||||
void virSecurityDACSetDynamicOwnership(virSecurityManagerPtr mgr,
|
||||
bool dynamic);
|
||||
|
@ -146,8 +146,10 @@ virSecurityManagerPtr virSecurityManagerNewDAC(const char *virtDriver,
|
||||
if (!mgr)
|
||||
return NULL;
|
||||
|
||||
virSecurityDACSetUser(mgr, user);
|
||||
virSecurityDACSetGroup(mgr, group);
|
||||
if (virSecurityDACSetUserAndGroup(mgr, user, group) < 0) {
|
||||
virSecurityManagerDispose(mgr);
|
||||
return NULL;
|
||||
}
|
||||
virSecurityDACSetDynamicOwnership(mgr, dynamicOwnership);
|
||||
|
||||
return mgr;
|
||||
|
Loading…
Reference in New Issue
Block a user