[#7978] Patch for Unix socket peer credentials — "James F. Hranicky" <jfh@...>

This patch adds support for getting the uid and gid of the peer

27 messages 2006/06/09
[#8004] Re: Patch for Unix socket peer credentials — Tanaka Akira <akr@...17n.org> 2006/06/16

In article <200606091528.30171.jfh@cise.ufl.edu>,

[#8005] Re: Patch for Unix socket peer credentials — "James F. Hranicky" <jfh@...> 2006/06/16

On Friday 16 June 2006 11:51, Tanaka Akira wrote:

[#8010] Re: Patch for Unix socket peer credentials — Tanaka Akira <akr@...17n.org> 2006/06/17

In article <200606161327.35948.jfh@cise.ufl.edu>,

[#8191] Re: Patch for Unix socket peer credentials — "James F. Hranicky" <jfh@...> 2006/07/10

On Saturday 17 June 2006 06:27, Tanaka Akira wrote:

[#8193] Re: Patch for Unix socket peer credentials — Tanaka Akira <akr@...> 2006/07/11

In article <200607101352.16804.jfh@cise.ufl.edu>,

[#8212] Re: Patch for Unix socket peer credentials — "James F. Hranicky" <jfh@...> 2006/07/13

On Tuesday 11 July 2006 00:10, Tanaka Akira wrote:

[#8217] Re: Patch for Unix socket peer credentials — nobu@... 2006/07/14

Hi,

[#8257] Re: Patch for Unix socket peer credentials — "James F. Hranicky" <jfh@...> 2006/07/18

On Thursday 13 July 2006 22:48, nobu@ruby-lang.org wrote:

[#8258] Re: Patch for Unix socket peer credentials — Eric Hodel <drbrain@...7.net> 2006/07/18

On Jul 18, 2006, at 12:27 PM, James F. Hranicky wrote:

[#8073] 1.8.5p1 build failure on Solaris 10 — "Daniel Berger" <Daniel.Berger@...>

Solaris 10

23 messages 2006/06/27
[#8074] Re: 1.8.5p1 build failure on Solaris 10 — Yukihiro Matsumoto <matz@...> 2006/06/28

Hi,

[#8078] Re: 1.8.5p1 build failure on Solaris 10 — "Daniel Berger" <Daniel.Berger@...> 2006/06/28

Yukihiro Matsumoto wrote:

[#8079] Re: 1.8.5p1 build failure on Solaris 10 — ts <decoux@...> 2006/06/28

>>>>> "D" == Daniel Berger <Daniel.Berger@qwest.com> writes:

[#8096] Re: 1.8.5p1 build failure on Solaris 10 — ville.mattila@... 2006/06/29

ts <decoux@moulon.inra.fr> wrote on 28.06.2006 17:37:00:

Re: Patch for Unix socket peer credentials

From: Sam Roberts <sroberts@...>
Date: 2006-06-09 21:25:55 UTC
List: ruby-core #7980
On Sat, Jun 10, 2006 at 04:28:36AM +0900, James F. Hranicky wrote:
> This patch adds support for getting the uid and gid of the peer
> socket connected to a Unix domain socket.
> 
> The patch is really just a suggestion, as you can't necessarily get the
> same kinds of information across platforms. Unless I'm mistaken this is
> what you can get for the following platforms:
> 
> 	FreeBSD, OSX (getpeereid)   : euid, egid
> 	Linux        (getsockopt)   : pid, uid, gid
> 	Solaris 10   (getpeerucred) : uid, euid, gid, egid, pid and more
> 
> The patch adds checks to extconf.rb for the getpeereid and getpeerucred
> functions and a check for the SO_PEERCRED macro. If none of these are
> found calls to the peer_uid and peer_gid method raise an error. 
> 
> Questions and comments welcome, and I'm open to suggestions for
> changes/improvements.

I tried to do this on OS X recently using DGRAM AF_LOCAL sockets based
on the examples from Stevens, and failed, possibly due to an error on my
part, or maybe because the only way to do it is with getpeereid() on a
connected stream-oriented socket?

So, this is serendipitous, and very useful. Will try the patch
this weekend.

A bits of feedback:

- Maybe instead of #peer_uid, and #peer_gid, have just #peer_id =>
  [uid,gid], seems more convenient to me to get them both in one shot,
  matches (some of) the underlying system calls more closely, and also
  rids you of the duplicate code adn documentation (btw, thanks for
  including docs!).

- Maybe instead of raising an error if not supported (which means you
  have to call it to find that out), just don't define the method at
  all?  Kindof like socket options, you can do Socket.constants.include?
  to see if a sockopt is supported before even attempting to use it, it
  might be nice to do (Socket/UNIXSocket).methods.include? :peer_id to
  see if #peer_id is supported.

- I think the methods should be lower down in the hierarchy, or at least
  duplicated in Socket, if I create an AF_LOCAL connection-oriented
  socket with Socket.new, I should be able to get the peer ID, too, I
  think.

- I am using DGRAM unix domain sockets... it sure would be nice to have
  a way to determine the peer's credentials for received messages, any
  thoughts on that? Even non-ruby thoughts... do you know if it works
  on the Linux and OS X, and how to make it work?

Please and Thank You,
Sam


In This Thread