summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 12:43:04 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 12:43:04 +0000
commit7a01268aebada78b505f9ac4736cb23fa8bf260d (patch)
treeacfd54621f334218918c7c496eeb4230ad0e404c
parente52da919872f8cf71c90a27b470cef724204eece (diff)
* ext/socket/basicsocket.c (bsock_getpeereid): implemented for Solaris
using getpeerucred. * ext/socket/extconf.rb: check ucred.h and getpeerucred. * ext/socket/rubysocket.h: include ucred.h if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--ext/socket/basicsocket.c10
-rw-r--r--ext/socket/extconf.rb3
-rw-r--r--ext/socket/rubysocket.h3
4 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 2cfd0fc..4538e39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Feb 12 12:36:35 2009 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/basicsocket.c (bsock_getpeereid): implemented for Solaris
+ using getpeerucred.
+
+ * ext/socket/extconf.rb: check ucred.h and getpeerucred.
+
+ * ext/socket/rubysocket.h: include ucred.h if available.
+
Thu Feb 12 19:42:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (compile_array_, defined_expr, iseq_compile_each): hide
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index b818ffa..fd74930 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -392,6 +392,16 @@ bsock_getpeereid(VALUE self)
if (getsockopt(fptr->fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1)
rb_sys_fail("getsockopt(SO_PEERCRED)");
return rb_assoc_new(UIDT2NUM(cred.uid), GIDT2NUM(cred.gid));
+#elif defined(HAVE_GETPEERUCRED) /* Solaris */
+ rb_io_t *fptr;
+ ucred_t *uc = NULL;
+ VALUE ret;
+ GetOpenFile(self, fptr);
+ if (getpeerucred(fptr->fd, &uc) == -1)
+ rb_sys_fail("getpeerucred");
+ ret = rb_assoc_new(UIDT2NUM(ucred_geteuid(uc)), GIDT2NUM(ucred_getegid(uc)));
+ ucred_free(uc);
+ return ret;
#else
rb_notimplement();
#endif
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 921a0ee..ae2338d 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -316,6 +316,9 @@ have_type("struct cmsgcred", headers)
have_func("getpeereid")
+have_header("ucred.h", headers)
+have_func("getpeerucred")
+
$distcleanfiles << "constants.h" << "constdefs.*"
if have_func(test_func)
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index ae21f26..d6f09fe 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -79,6 +79,9 @@
#ifdef HAVE_SYS_UCRED_H
#include <sys/ucred.h>
#endif
+#ifdef HAVE_UCRED_H
+#include <ucred.h>
+#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN