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:
Giuseppe Scrivano 2013-10-18 14:13:19 +02:00 committed by Eric Blake
parent 1bc12e1c46
commit 4387132f31
3 changed files with 21 additions and 16 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;