提交 7cf53437 编写于 作者: C Cole Robinson

util: virfile: Clarify setuid usage for virFileRemove

Break these checks out into their own function, and clearly document
each one. This shouldn't change behavior
上级 02ae21de
...@@ -2314,6 +2314,32 @@ virFileOpenAs(const char *path, int openflags, mode_t mode, ...@@ -2314,6 +2314,32 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
} }
/* virFileRemoveNeedsSetuid:
* @uid: file uid to check
* @gid: file gid to check
*
* Return true if we should use setuid/setgid before deleting a file
* owned by the passed uid/gid pair. Needed for NFS with root-squash
*/
static bool
virFileRemoveNeedsSetuid(uid_t uid, gid_t gid)
{
/* If running unprivileged, setuid isn't going to work */
if (geteuid() != 0)
return false;
/* uid/gid weren't specified */
if ((uid == (uid_t) -1) && (gid == (gid_t) -1))
return false;
/* already running as proper uid/gid */
if (uid == geteuid() && gid == getegid())
return false;
return true;
}
/* virFileRemove: /* virFileRemove:
* @path: file to unlink or directory to remove * @path: file to unlink or directory to remove
* @uid: uid that was used to create the file (not required) * @uid: uid that was used to create the file (not required)
...@@ -2335,12 +2361,7 @@ virFileRemove(const char *path, ...@@ -2335,12 +2361,7 @@ virFileRemove(const char *path,
gid_t *groups; gid_t *groups;
int ngroups; int ngroups;
/* If not running as root or if a non explicit uid/gid was being used for if (!virFileRemoveNeedsSetuid(uid, gid)) {
* the file/volume or the explicit uid/gid matches, then use unlink directly
*/
if ((geteuid() != 0) ||
((uid == (uid_t) -1) && (gid == (gid_t) -1)) ||
(uid == geteuid() && gid == getegid())) {
if (virFileIsDir(path)) if (virFileIsDir(path))
return rmdir(path); return rmdir(path);
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册