/* TODO is it safe to call it here or should this call be moved in
* front of the clone() as otherwise there might be a risk for a
* deadlock */
- if ((ngroups = virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cmd),
- &groups)) < 0)
- goto cleanup;
+ ngroups = virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cmd),
+ &groups);
ret = 0;
cleanup:
virSecurityDACPreFork(virSecurityManager *mgr)
{
virSecurityDACData *priv = virSecurityManagerGetPrivateData(mgr);
- int ngroups;
g_clear_pointer(&priv->groups, g_free);
- priv->ngroups = 0;
- if ((ngroups = virGetGroupList(priv->user, priv->group,
- &priv->groups)) < 0)
- return -1;
- priv->ngroups = ngroups;
+ priv->ngroups = virGetGroupList(priv->user, priv->group, &priv->groups);
return 0;
}
childerr = null;
}
- if ((ngroups = virGetGroupList(cmd->uid, cmd->gid, &groups)) < 0)
- goto cleanup;
+ ngroups = virGetGroupList(cmd->uid, cmd->gid, &groups);
pid = virFork();
return access(path, mode);
ngroups = virGetGroupList(uid, gid, &groups);
- if (ngroups < 0)
- return -1;
pid = virFork();
* NFS servers. */
ngroups = virGetGroupList(uid, gid, &groups);
- if (ngroups < 0)
- return -errno;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) < 0) {
ret = -errno;
gid = getegid();
ngroups = virGetGroupList(uid, gid, &groups);
- if (ngroups < 0)
- return -errno;
pid = virFork();
gid = getegid();
ngroups = virGetGroupList(uid, gid, &groups);
- if (ngroups < 0)
- return -errno;
pid = virFork();
* storing a malloc'd result into @list. If uid is -1 or doesn't exist in the
* system database querying of the supplementary groups is skipped.
*
- * Returns the size of the list on success, or -1 on failure with error
- * reported and errno set. May not be called between fork and exec.
+ * Returns the size of the list. Doesn't have an error path.
+ * May not be called between fork and exec.
* */
int
-virGetGroupList(uid_t uid, gid_t gid, gid_t **list)
+virGetGroupList(uid_t uid,
+ gid_t gid,
+ gid_t **list)
{
int ret = 0;
- char *user = NULL;
+ g_autofree char *user = NULL;
gid_t primary;
*list = NULL;
for (i = 0; i < ret; i++) {
if ((*list)[i] == gid)
- goto cleanup;
+ return ret;
}
VIR_APPEND_ELEMENT(*list, i, gid);
- ret = i;
+ return i;
}
- cleanup:
- VIR_FREE(user);
return ret;
}
goto cleanup;
}
- if ((ngroups = virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cmd),
- &groups)) < 0)
- goto cleanup;
+ ngroups = virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cmd),
+ &groups);
/* Now, fork and try to exec a nonexistent binary. */
pid = virFork();
if (!(conf = virConfReadFile(login_shell_path, 0)))
goto cleanup;
- if ((ngroups = virGetGroupList(uid, gid, &groups)) < 0)
- goto cleanup;
+ ngroups = virGetGroupList(uid, gid, &groups);
if (virLoginShellAllowedUser(conf, name, groups, ngroups) < 0)
goto cleanup;