From: Urabe Shyouhei Date: 2007-01-07T00:57:34+09:00 Subject: [ruby-dev:30099] Re: [ ruby-Bugs-5822 ] Ruby's 'etc' module cannot handle the UID of OS X 'nobody' properly This is a multi-part message in MIME format. --------------040305070505040000070108 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit 卜部です。太古のメールに返信する上に-devに振ってしまって恐縮ですが、 Yukihiro Matsumoto wrote: > Thank you guys. I fixed it on the CVS. Would somebody check the fix? > > matz. > これが1.8.5から漏れてたので直そうと思って修正を確認してたのですが、思う に現状では今度はuid_tがsignedだったときにうまくいかないんじゃないですかね? あと、あきらかにgidにも同じ問題があるのでそれもなおした方がいいと思います。 --------------040305070505040000070108 Content-Type: text/x-patch; name="etc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="etc.patch" HTTP/1.1 200 OK Date: Sat, 06 Jan 2007 14:59:03 GMT Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 PHP/4.3.10-18 mod_ruby/1.2.4 Ruby/1.8.2(2005-04-11) mod_ssl/2.0.54 OpenSSL/0.9.7e mod_perl/1.999.21 Perl/v5.8.4 Content-Length: 1909 Connection: close Content-Type: text/plain Index: ext/etc/extconf.rb =================================================================== --- ext/etc/extconf.rb (revision 11497) +++ ext/etc/extconf.rb (working copy) @@ -36,5 +36,7 @@ if a or b or c end end - $defs.push("-DPW_#{t.chomp('_t').upcase}2VAL=#{f}") + t = t.chomp('_t').upcase + $defs.push("-DPW_#{t}2VAL=#{f}") + $defs.push("-DPW_VAL2#{t}=#{f.sub(/([A-Z]+)2(NUM)/, '\22\1')}") end create_makefile("etc") Index: ext/etc/etc.c =================================================================== --- ext/etc/etc.c (revision 11497) +++ ext/etc/etc.c (working copy) @@ -126,14 +126,5 @@ etc_getpwuid(int argc, VALUE *argv, VALU rb_secure(4); if (rb_scan_args(argc, argv, "01", &id) == 1) { -#if HAVE_LONG_LONG && HAVE_TYPE_UID_T - if (sizeof(uid_t) > sizeof(int)) { - uid = NUM2ULL(id); - } - else { - uid = NUM2UINT(id); - } -#else - uid = NUM2UINT(id); -#endif + uid = PW_VAL2UID(id); } else { @@ -327,12 +318,18 @@ setup_group(struct group *grp) */ static VALUE -etc_getgrgid(VALUE obj, VALUE id) +etc_getgrgid(int argc, VALUE *argv, VALUE obj) { #ifdef HAVE_GETGRENT - int gid; + VALUE id; + gid_t gid; struct group *grp; rb_secure(4); - gid = NUM2INT(id); + if (rb_scan_args(argc, argv, "01", &id) == 1) { + gid = PW_VAL2GID(id); + } + else { + gid = getgid(); + } grp = getgrgid(gid); if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid); @@ -506,5 +503,5 @@ Init_etc(void) rb_define_module_function(mEtc, "passwd", etc_passwd, 0); - rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, 1); + rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1); rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1); rb_define_module_function(mEtc, "group", etc_group, 0); --------------040305070505040000070108--