From: John Kelly <jak@isp2dial.com>
To: linux-kernel@vger.kernel.org
Subject: Re: User credentials on a unix datagram socket
Date: Tue, 07 Oct 2008 00:04:42 +0000 [thread overview]
Message-ID: <200810070004.m9704fZB019302@isp2dial.com> (raw)
In-Reply-To: <200810052141.m95LfL2c027165@isp2dial.com>
On Sun, 05 Oct 2008 21:41:22 +0000, John Kelly <jak@isp2dial.com>
wrote:
>The socket(7) man page seems to imply that user credentials cannot be
>sent on a unix datagram socket, unless socketpair() created it.
>> SO_PEERCRED
>> Return the credentials of the foreign process connected to this socket.
>> This is only possible for connected AF_UNIX stream sockets and AF_UNIX
>> stream and datagram socket pairs created using socketpair(2);
>But through trial and error, without reading any kernel source, I
>learned that you can send user credentials on a regular unix datagram
>socket which was not created with socketpair().
>I'm unsure what SO_PEERCRED is intended for; I used SO_PASSCRED in my
>server code, and it works.
Maybe I'm the only one on the planet interested in this subject, but
for posterity ... after browsing net/unix/af_unix.c, I see ...
Using SO_PEERCRED with getsockopt(2) reads an sk_peercred struct. It
seems this data is available in the kernel, without the client sending
credentials as ancillary data. In af_unix.c, unix_stream_connect and
unix_socketpair set this structure, but unix_dgram_connect does not.
So apparently, the socket(7) man page is accurate. However, it could
mislead one towards a wrong conclusion ...
As I learned by trial and error, you CAN get user credentials on a
regular datagram socket by using SO_PASSCRED, you just have to do it
the hard way, with the client explicitly sending his credentials as
ancillary data.
Works for me ....
--
Webmail for Dialup Users
http://www.isp2dial.com/freeaccounts.html
prev parent reply other threads:[~2008-10-07 0:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-05 21:41 John Kelly
2008-10-07 0:04 ` John Kelly [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200810070004.m9704fZB019302@isp2dial.com \
--to=jak@isp2dial.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome