virSetUIDGIDWithCaps: Don't drop CAP_SETPCAP right away
virSetUIDGIDWithCaps: Don't drop CAP_SETPCAP right away

There are few cases where we execute a virCommand with all caps
cleared (virCommandClearCaps()). For instance
dnsmasqCapsRefreshInternal() does just that. This means, that
after fork() and before exec() the virSetUIDGIDWithCaps() is
called. But since the caller did not want to change anything,
just drop capabilities, these are the values of arguments:

  virSetUIDGIDWithCaps (uid=-1, gid=-1, groups=0x0, ngroups=0,
                        capBits=0, clearExistingCaps=true)

This means that indeed all capabilities will be dropped,
including CAP_SETPCAP. But this capability controls whether
capabilities can be set, IOW whether capng_apply() succeeds.

There are two calls of capng_apply() in the function. The
CAP_SETPCAP is dropped after the first call and thus the other
call (capng_apply(CAPNG_SELECT_BOUNDS);) fails.

The solution is to keep the capability for as long as needed
(just like CAP_SETGID and CAP_SETUID) and drop it only at the
very end (just like CAP_SETGID and CAP_SETUID).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1949388
Signed-off-by: Michal Privoznik <83d82aaba2eed257f4814b0c239c260c4caaadf0@redhat.com>
Reviewed-by: Martin Kletzander <e82f23e74d43760279ebcc505dac4ae70d5627d0@redhat.com>

crobinso/libvirt,zippy2/libvirt,libvirt/libvirt,jfehlig/libvirt,nertpinx/libvirt,olafhering/libvirt,olafhering/libvirt,jfehlig/libvirt,jfehlig/libvirt,zippy2/libvirt,libvirt/libvirt,zippy2/libvirt,libvirt/libvirt,nertpinx/libvirt,jfehlig/libvirt,libvirt/libvirt,crobinso/libvirt,olafhering/libvirt,olafhering/libvirt,zippy2/libvirt,crobinso/libvirt,nertpinx/libvirt,nertpinx/libvirt,crobinso/libvirt,nertpinx/libvirt