]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: Don't try to fchown files opened as non-root
authorJiri Denemark <jdenemar@redhat.com>
Fri, 8 Jul 2011 12:11:01 +0000 (14:11 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 8 Jul 2011 14:43:55 +0000 (16:43 +0200)
commit2f4d2496a88055a8343b3efca618522da8715d92
treed625fac53bd3020acc09bfeb63a2f5ee27513136
parent724819a10a92a8709f9276521a0cf27016b5c7b2
util: Don't try to fchown files opened as non-root

When virFileOpenAs is called with VIR_FILE_OPEN_AS_UID flag and uid/gid
different from root/root while libvirtd is running as root, we fork a
new child, change its effective UID/GID to uid/gid and run
virFileOpenAsNoFork. It doesn't make any sense to fchown() the opened
file in this case since we already know that uid/gid can access the file
when open succeeds and one of the following situations may happen:

- the file is already owned by uid/gid and we skip fchown even before
  this patch
- the file is owned by uid but not gid because it was created in a
  directory with SETGID set, in which case it is desirable not to change
  the group
- the file may be owned by a completely different user and/or group
  because it was created on a root-squashed or even all-squashed NFS
  filesystem, in which case fchown would most likely fail anyway
src/util/util.c