提交 5e09aea7 编写于 作者: J Jiri Denemark

Replace all remaining setgid/setuid calls with virSetUIDGID

Two additional places need initgroups call to properly work in an
environment where the UID is allowed to open/create stuff through its
supplementary groups.
上级 4dd9c161
......@@ -535,20 +535,9 @@ static int virStorageBuildSetUIDHook(void *data) {
if (tmp->skip)
return 0;
if ((vol->target.perms.gid != -1)
&& (setgid(vol->target.perms.gid) != 0)) {
virReportSystemError(errno,
_("Cannot set gid to %u before creating %s"),
vol->target.perms.gid, vol->target.path);
return -1;
}
if ((vol->target.perms.uid != -1)
&& (setuid(vol->target.perms.uid) != 0)) {
virReportSystemError(errno,
_("Cannot set uid to %u before creating %s"),
vol->target.perms.uid, vol->target.path);
if (virSetUIDGID(vol->target.perms.uid, vol->target.perms.gid) < 0)
return -1;
}
return 0;
}
......
......@@ -1476,18 +1476,8 @@ parenterror:
/* set desired uid/gid, then attempt to create the file */
if ((gid != 0) && (setgid(gid) != 0)) {
if (virSetUIDGID(uid, gid) < 0) {
ret = -errno;
virReportSystemError(errno,
_("cannot set gid %u creating '%s'"),
(unsigned int) gid, path);
goto childerror;
}
if ((uid != 0) && (setuid(uid) != 0)) {
ret = -errno;
virReportSystemError(errno,
_("cannot set uid %u creating '%s'"),
(unsigned int) uid, path);
goto childerror;
}
if ((fd = open(path, openflags, mode)) < 0) {
......@@ -1595,16 +1585,8 @@ parenterror:
/* set desired uid/gid, then attempt to create the directory */
if ((gid != 0) && (setgid(gid) != 0)) {
ret = -errno;
virReportSystemError(errno, _("cannot set gid %u creating '%s'"),
(unsigned int) gid, path);
goto childerror;
}
if ((uid != 0) && (setuid(uid) != 0)) {
if (virSetUIDGID(uid, gid) < 0) {
ret = -errno;
virReportSystemError(errno, _("cannot set uid %u creating '%s'"),
(unsigned int) uid, path);
goto childerror;
}
if (mkdir(path, mode) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册