mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/option.c (inspect_peercred): new function to show
SO_PEERCRED socket option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5baafac0b7
commit
8f9d6d1863
3 changed files with 45 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Feb 8 23:22:35 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/option.c (inspect_peercred): new function to show
|
||||
SO_PEERCRED socket option.
|
||||
|
||||
Sun Feb 8 22:44:20 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* include/ruby/backward/rubysig.h (rb_thread_blocking_region_begin),
|
||||
|
|
|
@ -221,6 +221,23 @@ inspect_timeval(int level, int optname, VALUE data, VALUE ret)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(SOL_SOCKET) && defined(SO_PEERCRED) /* GNU/Linux */
|
||||
static int
|
||||
inspect_peercred(int level, int optname, VALUE data, VALUE ret)
|
||||
{
|
||||
if (RSTRING_LEN(data) == sizeof(struct ucred)) {
|
||||
struct ucred cred;
|
||||
memcpy(&cred, RSTRING_PTR(data), sizeof(struct ucred));
|
||||
rb_str_catf(ret, " pid=%u uid=%u gid=%u", cred.pid, cred.uid, cred.gid);
|
||||
rb_str_cat2(ret, " (ucred)");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
sockopt_inspect(VALUE self)
|
||||
{
|
||||
|
@ -299,6 +316,9 @@ sockopt_inspect(VALUE self)
|
|||
# if defined(SO_SNDTIMEO) /* POSIX */
|
||||
case SO_SNDTIMEO: if (inspect_timeval(level, optname, data, ret) == -1) goto dump; break;
|
||||
# endif
|
||||
# if defined(SO_PEERCRED) /* GNU/Linux */
|
||||
case SO_PEERCRED: if (inspect_peercred(level, optname, data, ret) == -1) goto dump; break;
|
||||
# endif
|
||||
|
||||
default: goto dump;
|
||||
}
|
||||
|
|
|
@ -296,7 +296,23 @@ class TestUNIXSocket < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_cred_ucred
|
||||
def test_getcred_ucred
|
||||
return if /linux/ !~ RUBY_PLATFORM
|
||||
Dir.mktmpdir {|d|
|
||||
sockpath = "#{d}/sock"
|
||||
serv = Socket.unix_server_socket(sockpath)
|
||||
c = Socket.unix(sockpath)
|
||||
s, = serv.accept
|
||||
cred = s.getsockopt(:SOCKET, :PEERCRED)
|
||||
inspect = cred.inspect
|
||||
assert_match(/ pid=#{$$} /, inspect)
|
||||
assert_match(/ uid=#{Process.uid} /, inspect)
|
||||
assert_match(/ gid=#{Process.gid} /, inspect)
|
||||
assert_match(/ \(ucred\)/, inspect)
|
||||
}
|
||||
end
|
||||
|
||||
def test_sendcred_ucred
|
||||
return if /linux/ !~ RUBY_PLATFORM
|
||||
Dir.mktmpdir {|d|
|
||||
sockpath = "#{d}/sock"
|
||||
|
@ -310,12 +326,12 @@ class TestUNIXSocket < Test::Unit::TestCase
|
|||
assert_equal("a", msg)
|
||||
assert_match(/ pid=#{$$} /, inspect)
|
||||
assert_match(/ uid=#{Process.uid} /, inspect)
|
||||
assert_match(/ gid=#{Process.gid}>/, inspect)
|
||||
assert_match(/ gid=#{Process.gid} /, inspect)
|
||||
assert_match(/ \(ucred\)/, inspect)
|
||||
}
|
||||
end
|
||||
|
||||
def test_cred_sockcred
|
||||
def test_sendcred_sockcred
|
||||
return if /netbsd|freebsd/ !~ RUBY_PLATFORM
|
||||
Dir.mktmpdir {|d|
|
||||
sockpath = "#{d}/sock"
|
||||
|
@ -336,7 +352,7 @@ class TestUNIXSocket < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_cred_cmsgcred
|
||||
def test_sendcred_cmsgcred
|
||||
return if /freebsd/ !~ RUBY_PLATFORM
|
||||
Dir.mktmpdir {|d|
|
||||
sockpath = "#{d}/sock"
|
||||
|
|
Loading…
Reference in a new issue