Hi Daniel,
On Mon, Oct 7, 2013 at 6:51 PM, Daniel P. Berrange <berrange(a)redhat.com> wrote:
On Mon, Oct 07, 2013 at 10:33:44AM +0200, Michal Privoznik wrote:
> On 05.10.2013 07:56, Ryota Ozaki wrote:
> > This fixes the following error:
> > error : virGetUserEnt:703 : Failed to find user record for uid
'32654'
> >
> > '32654' (it's random and varies) comes from getsockopt with
> > LOCAL_PEERCRED option. getsockopt returns w/o error but seems
> > to not set any value to the buffer for uid.
> >
> > For Mac OS X, LOCAL_PEERCRED has to be used with SOL_LOCAL level.
> > With SOL_LOCAL, getsockopt returns a correct uid.
> >
> > Note that SOL_LOCAL can be found in
> > /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/un.h.
> >
> > Signed-off-by: Ryota Ozaki <ozaki.ryota(a)gmail.com>
> > ---
> > src/rpc/virnetsocket.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
> > index 152c5fc..a6ef07a 100644
> > --- a/src/rpc/virnetsocket.c
> > +++ b/src/rpc/virnetsocket.c
> > @@ -1159,7 +1159,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
> > socklen_t cr_len = sizeof(cr);
> > virObjectLock(sock);
> >
> > +#if defined(__APPLE__)
> > + if (getsockopt(sock->fd, SOL_LOCAL, LOCAL_PEERCRED, &cr,
&cr_len) < 0) {
> > +#else
> > if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr,
&cr_len) < 0) {
> > +#endif
> > virReportSystemError(errno, "%s",
> > _("Failed to get client socket
identity"));
> > virObjectUnlock(sock);
> >
>
> Indentation off. Fixed and pushed. You can use 'make syntax-check' to
> catch these problems. Although, you need cppi installed.
>
> ACK
IIUC, this error was present on BSD too, so I think probably we should
not have the conditional here, but just use SOL_LOCAL for everything
(this code block is already conditionalized)
It seems that there is not SOL_LOCAL on FreeBSD (9.2) and
LOCAL_PEERCRED works with SOL_SOCKET.
If we want to have only one getsockopt, we may be able to
use 0 for the level (*). I confirmed it works on both Mac OS X
(because SOL_LOCAL == 0) and FreeBSD (I don't know why).
(*)
http://doxygen.postgresql.org/getpeereid_8c_source.html
Thanks,
ozaki-r