Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 May 2008 20:56:01 +0100
From:      "Steven Hartland" <killing@multiplay.co.uk>
To:        <freebsd-hackers@freebsd.org>
Subject:   Using sendmsg for SCM_CREDS results in EINVAL on PF_INET socket
Message-ID:  <BCBAE9EA84D54762AD983B29B2752492@multiplay.co.uk>

next in thread | raw e-mail | index | archive | help
sendmsg is not documented as ever returning EINVAL but yet when
using the following code to send credentials to a remote host
results in EINVAL from sendmsg.

I suspect that SCM_CREDS is only valid for PF_LOCAL / PF_UNIX
sockets and not PF_INET sockets and hence the code in dbus
is actually invalid.

Can anyone confirm this is the case or not?

[code from dbus-sysdeps-unix.c]
write_credentials_byte (int             server_fd,
                        DBusError      *error)
{
  int bytes_written;
  char buf[1] = { '\0' };
#if defined(HAVE_CMSGCRED) 
  union {
      struct cmsghdr hdr;
      char cred[CMSG_SPACE (sizeof (struct cmsgcred))];
  } cmsg;
  struct iovec iov;
  struct msghdr msg;
  iov.iov_base = buf;
  iov.iov_len = 1;

  memset (&msg, 0, sizeof (msg));
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;

  msg.msg_control = (caddr_t) &cmsg;
  msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred));
  memset (&cmsg, 0, sizeof (cmsg));
  cmsg.hdr.cmsg_len = CMSG_LEN (sizeof (struct cmsgcred));
  cmsg.hdr.cmsg_level = SOL_SOCKET;
  cmsg.hdr.cmsg_type = SCM_CREDS;
#endif

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);

 again:

#if defined(HAVE_CMSGCRED) 
  bytes_written = sendmsg (server_fd, &msg, 0);
#else
  bytes_written = write (server_fd, buf, 1);
#endif

  if (bytes_written < 0 && errno == EINTR)
    goto again;

  if (bytes_written < 0)
    {
      dbus_set_error (error, _dbus_error_from_errno (errno),
                      "Failed to write credentials byte: %s",
                     _dbus_strerror (errno));
      return FALSE;
    }
  else if (bytes_written == 0)
    {
      dbus_set_error (error, DBUS_ERROR_IO_ERROR,
                      "wrote zero bytes writing credentials byte");
      return FALSE;
    }
  else
    {
      _dbus_assert (bytes_written == 1);
      _dbus_verbose ("wrote credentials byte\n");
      return TRUE;
    }
}
[/code from dbus-sysdeps-unix.c]

================================================
This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. 

In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337
or return the E.mail to postmaster@multiplay.co.uk.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BCBAE9EA84D54762AD983B29B2752492>