[#8136] Confused exception handling in Continuation Context — "Robert Dober" <robert.dober@...>

Hi all

13 messages 2006/07/06

[#8248] One-Click Installer: MinGW? or VC2005? — "Curt Hibbs" <ml.chibbs@...>

I just posted this to ruby-talk. But I would also like to discuss this

33 messages 2006/07/18
[#8264] Re: One-Click Installer: MinGW? or VC2005? — Charlie Savage <cfis@...> 2006/07/19

From my experience using both tool chains on Windows (for the ruby-prof

[#8266] Re: One-Click Installer: MinGW? or VC2005? — "Curt Hibbs" <ml.chibbs@...> 2006/07/19

Tim, I'm going to top reply since your post was so long. I'm interested in

[#8267] Re: One-Click Installer: MinGW? or VC2005? — Charlie Savage <cfis@...> 2006/07/19

> Tim, I'm going to top reply since your post was so long. I'm interested in

[#8271] my sandboxing extension!! — why the lucky stiff <ruby-core@...>

I have (what feels like) very exciting news. I finally sat down to code up my

17 messages 2006/07/19

[#8430] Re: doc patch: weakref. — "Berger, Daniel" <Daniel.Berger@...>

> -----Original Message-----

19 messages 2006/07/28
[#8434] Re: doc patch: weakref. — Yukihiro Matsumoto <matz@...> 2006/07/29

Hi,

[#8436] Re: doc patch: weakref. — Daniel Berger <djberg96@...> 2006/07/29

Yukihiro Matsumoto wrote:

[#8437] Re: doc patch: weakref. — Mauricio Fernandez <mfp@...> 2006/07/29

On Sat, Jul 29, 2006 at 07:37:24PM +0900, Daniel Berger wrote:

[#8441] Inconsistency in scoping during module_eval? — "Charles O Nutter" <headius@...>

I have the following code:

18 messages 2006/07/30
[#8442] Re: Inconsistency in scoping during module_eval? — nobu@... 2006/07/30

Hi,

[#8443] Re: Inconsistency in scoping during module_eval? — "Charles O Nutter" <headius@...> 2006/07/30

Why does this:

[#8445] Re: Inconsistency in scoping during module_eval? — Yukihiro Matsumoto <matz@...> 2006/07/30

Hi,

[#8454] Re: Inconsistency in scoping during module_eval? — "Charles O Nutter" <headius@...> 2006/07/31

So to clarify...

Re: Patch for Unix socket peer credentials

From: Tanaka Akira <akr@...>
Date: 2006-07-22 06:54:19 UTC
List: ruby-core #8355
In article <200607191340.25414.jfh@cise.ufl.edu>,
  "James F. Hranicky" <jfh@cise.ufl.edu> writes:

> Are negative values allowed on Linux? AFAICT, if the credentials aren't 
> available on Linux, say when I check a TCPServer socket's credentials
> after accepting a connection from another host, the system call returns
> 0 but sets the uid & gid to -1:

An example of negative UID is on NFS: "nobody" is -2.  [RFC 1094]

> +if have_macro("SO_PEERCRED", "sys/socket.h")
> +  $defs <<  "-DHAVE_SO_PEERCRED "
> +end

Uselessly complex.
Just use #if defined(SO_PEERCRED) in socket.c.

> +/*
> + * Document-method: peer_cred
> + * call-seq: socket.peer_cred => hash
> + *      hash[:uid]  => ruid || euid
> + *      hash[:gid]  => rgid || egid 
> + *      hash[:ruid] => ruid
> + *      hash[:euid] => euid
> + *      hash[:rgid] => rgid
> + *      hash[:egid] => egid
> + * }

unmatched closing curly brace?

>  static VALUE
> +bsock_peer_cred(sock)
> +    VALUE sock;
> +{
> +    char buf[1024];
> +    socklen_t len = sizeof buf;

It seems that buf is not used.

> +#if defined(HAVE_GETPEERUCRED)
> +    ucred_t *creds;
> +#elif defined(HAVE_SO_PEERCRED)
> +    struct ucred creds;
> +#elif defined(HAVE_GETPEEREID)
> +    int euid, egid;
> +#else
> +    rb_raise(rb_eSocket, "peer_cred not implemented on this platform");

There is rb_notimplement().
See other usages of rb_notimplement().

> +    kuid = rb_str_intern(rb_str_new2("uid"));
> +    kgid = rb_str_intern(rb_str_new2("gid"));
> +    kruid = rb_str_intern(rb_str_new2("ruid"));
> +    krgid = rb_str_intern(rb_str_new2("rgid"));
> +    keuid = rb_str_intern(rb_str_new2("euid"));
> +    kegid = rb_str_intern(rb_str_new2("egid"));

rb_str_new2 and rb_str_intern is too complex here.
Use ID2SYM(rb_intern("uid")), etc.

> +    ahash = rb_hash_new();
> +
> +    rb_hash_aset(ahash, kuid, Qnil);
> +    rb_hash_aset(ahash, kgid, Qnil);
> +    rb_hash_aset(ahash, kruid, Qnil);
> +    rb_hash_aset(ahash, krgid, Qnil);
> +    rb_hash_aset(ahash, keuid, Qnil);
> +    rb_hash_aset(ahash, kegid, Qnil);

I think the hash entries which OS doesn't provides are useless.

% ./ruby -v -rsocket -e '
File.unlink("/tmp/s") rescue nil
serv = UNIXServer.new("/tmp/s")
sock = UNIXSocket.new("/tmp/s")
s = serv.accept
p s.peer_cred
'
ruby 1.8.5 (2006-07-21) [i686-linux]
{:egid=>1000, :rgid=>nil, :uid=>1000, :gid=>1000, :euid=>1000, :ruid=>nil}

I think :rgid=>nil and :ruid=>nil should be removed as follows.

{:egid=>1000, :uid=>1000, :gid=>1000, :euid=>1000}

> +#if defined(HAVE_GETPEERUCRED)
> +    if ((creds = malloc(ucred_size())) == NULL)
> +        rb_sys_fail("malloc");

Why memory allocation?

> +    if (getpeerucred(fileno(fptr->f), &creds) < 0)
> +        rb_sys_fail("getpeerucred(2)");

It seems getpeerucred allocates memory.
http://docs.sun.com/app/docs/doc/816-5168/6mbb3hrcl?l=ja&a=view

> +    rb_hash_aset(ahash, kuid, INT2FIX(creds.uid));
> +    rb_hash_aset(ahash, kgid, INT2FIX(creds.gid));
> +    rb_hash_aset(ahash, keuid, INT2FIX(creds.uid));
> +    rb_hash_aset(ahash, kegid, INT2FIX(creds.gid));

I'd like to replace kuid by ID2SYM(rb_intern("uid")), to
avoid variables and unused variable initialization.

> +    if ((hashval = rb_hash_aref(ahash, kuid)) == Qnil) 
> +        rb_raise(rb_eSocket, "Invalid credentials: uid is nil");
> +
> +    if ((hashval = rb_hash_aref(ahash, kgid)) == Qnil)
> +        rb_raise(rb_eSocket, "Invalid credentials: gid is nil");

It seems a defensive programming.

> +    rb_define_method(rb_cBasicSocket, "peer_cred", bsock_peer_cred, 0);

Of course, the last possible problem is the method name.
I'm not sure that matz accept peer_cred.
-- 
Tanaka Akira

In This Thread