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 [EMAIL PROTECTED]

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to