1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virnetsocket: fix getsockopt on FreeBSD

aa0f099 introduced a strict error checking for getsockopt and it
revealed that getting a peer credential of a socket on FreeBSD
didn't work. Libvirtd hits the error:
  error : virNetSocketGetUNIXIdentity:1198 : Failed to get valid
  client socket identity groups

SOL_SOCKET (0xffff) was used as a level of getsockopt for
LOCAL_PEERCRED, however, it was wrong. 0 is correct as well as
Mac OS X.

So for LOCAL_PEERCRED our options are SOL_LOCAL (if defined) or
0 on Mac OS X and FreeBSD. According to the fact, the patch
simplifies the code by removing ifdef __APPLE__.

I tested the patch on FreeBSD 8.4, 9.2 and 10.0-BETA1.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
This commit is contained in:
Ryota Ozaki 2013-10-25 00:48:25 +09:00 committed by Doug Goldstein
parent 9fa3a8ab6f
commit 8079b0e0f4

View File

@ -1152,19 +1152,18 @@ cleanup:
/* VIR_SOL_PEERCRED - the value needed to let getsockopt() work with /* VIR_SOL_PEERCRED - the value needed to let getsockopt() work with
* LOCAL_PEERCRED * LOCAL_PEERCRED
*/ */
# ifdef __APPLE__
/* Mac OS X 10.8 provides SOL_LOCAL for LOCAL_PEERCRED */
# ifdef SOL_LOCAL # ifdef SOL_LOCAL
# define VIR_SOL_PEERCRED SOL_LOCAL # define VIR_SOL_PEERCRED SOL_LOCAL
# else # else
/* Prior to Mac OS X 10.7, SOL_LOCAL was not defined and users were /* FreeBSD and Mac OS X prior to 10.7, SOL_LOCAL is not defined and
* expected to supply 0 as the second value for getsockopt() when using * users are expected to supply 0 as the second value for getsockopt()
* LOCAL_PEERCRED * when using LOCAL_PEERCRED. NB SOL_SOCKET cannot be used instead
* of SOL_LOCAL
*/ */
# define VIR_SOL_PEERCRED 0 # define VIR_SOL_PEERCRED 0
# endif # endif
# else
# define VIR_SOL_PEERCRED SOL_SOCKET
# endif
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
uid_t *uid, uid_t *uid,