提交 4387132f 编写于 作者: G Giuseppe Scrivano 提交者: Eric Blake

security: use a single function to set DAC user and group

Merge the functions 'virSecurityDACSetUser' and
'virSecurityDACSetGroup' into 'virSecurityDACSetUserAndGroup'.
Signed-off-by: NGiuseppe Scrivano <gscrivan@redhat.com>
上级 1bc12e1c
......@@ -47,22 +47,25 @@ struct _virSecurityDACData {
gid_t *groups;
int ngroups;
bool dynamicOwnership;
char *baselabel;
};
void
virSecurityDACSetUser(virSecurityManagerPtr mgr,
uid_t user)
{
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
priv->user = user;
}
void
virSecurityDACSetGroup(virSecurityManagerPtr mgr,
/* returns -1 on error, 0 on success */
int
virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
uid_t user,
gid_t group)
{
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
priv->user = user;
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,9 +25,8 @@
extern virSecurityDriver virSecurityDriverDAC;
void virSecurityDACSetUser(virSecurityManagerPtr mgr,
uid_t user);
void virSecurityDACSetGroup(virSecurityManagerPtr mgr,
int virSecurityDACSetUserAndGroup(virSecurityManagerPtr mgr,
uid_t user,
gid_t group);
void virSecurityDACSetDynamicOwnership(virSecurityManagerPtr mgr,
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册