merge revision(s) 39349,39374: [Backport #7886]

* file.c (rb_group_member): get rid of NGROUPS dependency.
	  [Bug #7886] [ruby-core:52537]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2013-03-04 16:04:53 +00:00
parent bec0f1a6ce
commit dab8d82d21
3 changed files with 42 additions and 24 deletions

View file

@ -1,3 +1,8 @@
Tue Mar 5 01:03:16 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* file.c (rb_group_member): get rid of NGROUPS dependency.
[Bug #7886] [ruby-core:52537]
Tue Mar 5 00:16:56 2013 Eric Hodel <drbrain@segment7.net>
* ext/openssl/ossl.c (class OpenSSL): Use only inner parenthesis in

51
file.c
View file

@ -1013,39 +1013,52 @@ rb_file_lstat(VALUE obj)
#endif
}
/* Linux allow 65536 groups and it is maximum value as far as we know. */
#define RUBY_GROUP_MAX 65536
static int
rb_group_member(GETGROUPS_T gid)
{
int rv = FALSE;
#ifndef _WIN32
if (getgid() == gid || getegid() == gid)
return TRUE;
# ifdef HAVE_GETGROUPS
# ifndef NGROUPS
# ifdef NGROUPS_MAX
# define NGROUPS NGROUPS_MAX
#ifdef _WIN32
return FALSE;
#else
# define NGROUPS 32
# endif
# endif
{
int rv = FALSE;
int groups = 16;
VALUE v = 0;
GETGROUPS_T *gary;
int anum;
gary = xmalloc(NGROUPS * sizeof(GETGROUPS_T));
anum = getgroups(NGROUPS, gary);
if (getgid() == gid || getegid() == gid)
return TRUE;
/*
* On Mac OS X (Mountain Lion), NGROUPS is 16. But libc and kernel
* accept more larger value.
* So we don't trunk NGROUPS anymore.
*/
while (groups <= RUBY_GROUP_MAX) {
gary = ALLOCV_N(GETGROUPS_T, v, groups);
anum = getgroups(groups, gary);
if (anum != groups)
break;
groups *= 2;
if (v) {
ALLOCV_END(v);
v = 0;
}
}
while (--anum >= 0) {
if (gary[anum] == gid) {
rv = TRUE;
break;
}
}
xfree(gary);
}
# endif
#endif
if (v)
ALLOCV_END(v);
return rv;
#endif
}
#ifndef S_IXUGO

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2013-03-05"
#define RUBY_PATCHLEVEL 17
#define RUBY_PATCHLEVEL 18
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 3