Project

General

Profile

Feature #5610 ยป 0001-allow-strings-as-input-user-group-id.patch

nobu (Nobuyoshi Nakada), 03/28/2012 11:53 AM

View differences:

configure.in
1420 1420
	      setitimer setruid seteuid setreuid setresuid socketpair\
1421 1421
	      setrgid setegid setregid setresgid issetugid pause lchown lchmod\
1422 1422
	      getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
1423
	      getpriority getrlimit setrlimit sysconf close getgrnam_r\
1423
	      getpriority getrlimit setrlimit sysconf close getpwnam_r getgrnam_r\
1424 1424
	      dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
1425 1425
	      setsid telldir seekdir fchmod cosh sinh tanh log2 round\
1426 1426
	      setuid setgid daemon select_large_fdset setenv unsetenv\
process.c
67 67
#include <sys/times.h>
68 68
#endif
69 69

  
70
#ifdef HAVE_PWD_H
71
#include <pwd.h>
72
#endif
70 73
#ifdef HAVE_GRP_H
71 74
#include <grp.h>
72 75
#endif
......
3974 3977
 *  <code>Process::UID</code>, and <code>Process::GID</code> modules.
3975 3978
 */
3976 3979

  
3980
#if 1
3981
#define p_uid_from_name p_uid_from_name
3982
#define p_gid_from_name p_gid_from_name
3983
#endif
3984

  
3985
#if defined(HAVE_PWD_H)
3986
# ifdef HAVE_GETPWNAM_R
3987
#   define PREPARE_GETPWNAM \
3988
    size_t getpw_buf_len = sysconf(_SC_GETPW_R_SIZE_MAX); \
3989
    char *getpw_buf = ALLOCA_N(char, (getpw_buf_len < 0 ? (getpw_buf_len = 4096) : getpw_buf_len));
3990
#   define OBJ2UID(id) obj2uid((id), getpw_buf, getpw_buf_len)
3991
# else
3992
#   define PREPARE_GETPWNAM	/* do nothing */
3993
#   define OBJ2UID(id) obj2uid((id))
3994
# endif
3995

  
3996
static rb_uid_t
3997
obj2uid(VALUE id
3998
# ifdef HAVE_GETPWNAM_R
3999
	, char *getpw_buf, size_t getpw_buf_len
4000
# endif
4001
    )
4002
{
4003
    rb_uid_t uid;
4004
    VALUE tmp;
4005

  
4006
    if (FIXNUM_P(id) || NIL_P(tmp = rb_check_string_type(id))) {
4007
	uid = NUM2UIDT(id);
4008
    }
4009
    else {
4010
	const char *usrname = StringValueCStr(id);
4011
	struct passwd *pwptr;
4012
#ifdef HAVE_GETPWNAM_R
4013
	struct passwd pwbuf;
4014
	if (getpwnam_r(usrname, &pwbuf, getpw_buf, getpw_buf_len, &pwptr))
4015
	    rb_sys_fail("getpwnam_r");
4016
#else
4017
	pwptr = getpwnam(usrname);
4018
#endif
4019
	if (!pwptr) {
4020
#ifndef HAVE_GETPWNAM_R
4021
	    endpwent();
4022
#endif
4023
	    rb_raise(rb_eArgError, "can't find user for %s", usrname);
4024
	}
4025
	uid = pwptr->pw_uid;
4026
#ifndef HAVE_GETPWNAM_R
4027
	endpwent();
4028
#endif
4029
    }
4030
    return uid;
4031
}
4032

  
4033
# ifdef p_uid_from_name
4034
static VALUE
4035
p_uid_from_name(VALUE self, VALUE id)
4036
{
4037
    PREPARE_GETPWNAM
4038
    return UIDT2NUM(OBJ2UID(id));
4039
}
4040
# endif
4041
#else
4042
# define PREPARE_GETPWNAM	/* do nothing */
4043
# define OBJ2UID(id) NUM2UIDT(id)
4044
# ifdef p_uid_from_name
4045
#   undef p_uid_from_name
4046
#   define p_uid_from_name rb_f_notimplement
4047
# endif
4048
#endif
4049

  
4050
#if defined(HAVE_GRP_H)
4051
# ifdef HAVE_GETGRNAM_R
4052
#   define PREPARE_GETGRNAM \
4053
    size_t getgr_buf_len = sysconf(_SC_GETGR_R_SIZE_MAX); \
4054
    char *getgr_buf = ALLOCA_N(char, (getgr_buf_len < 0 ? (getgr_buf_len = 4096) : getgr_buf_len));
4055
#   define OBJ2GID(id) obj2gid((id), getgr_buf, getgr_buf_len)
4056
# else
4057
#   define PREPARE_GETGRNAM	/* do nothing */
4058
#   define OBJ2GID(id) obj2gid((id))
4059
# endif
4060

  
4061
static rb_gid_t
4062
obj2gid(VALUE id
4063
# ifdef HAVE_GETGRNAM_R
4064
	, char *getgr_buf, size_t getgr_buf_len
4065
# endif
4066
    )
4067
{
4068
    rb_gid_t gid;
4069
    VALUE tmp;
4070

  
4071
    if (FIXNUM_P(id) || NIL_P(tmp = rb_check_string_type(id))) {
4072
	gid = NUM2GIDT(id);
4073
    }
4074
    else {
4075
	const char *grpname = StringValueCStr(id);
4076
	struct group *grptr;
4077
#ifdef HAVE_GETGRNAM_R
4078
	struct group grbuf;
4079
	if (getgrnam_r(grpname, &grbuf, getgr_buf, getgr_buf_len, &grptr))
4080
	    rb_sys_fail("getgrnam_r");
4081
#else
4082
	grptr = getgrnam(grpname);
4083
#endif
4084
	if (!grptr) {
4085
#ifndef HAVE_GETGRNAM_R
4086
	    endgrent();
4087
#endif
4088
	    rb_raise(rb_eArgError, "can't find group for %s", grpname);
4089
	}
4090
	gid = grptr->gr_gid;
4091
#ifndef HAVE_GETGRNAM_R
4092
	endgrent();
4093
#endif
4094
    }
4095
    return gid;
4096
}
4097

  
4098
# ifdef p_gid_from_name
4099
static VALUE
4100
p_gid_from_name(VALUE self, VALUE id)
4101
{
4102
    PREPARE_GETGRNAM;
4103
    return GIDT2NUM(OBJ2GID(id));
4104
}
4105
# endif
4106
#else
4107
# define PREPARE_GETGRNAM	/* do nothing */
4108
# define OBJ2GID(id) NUM2GIDT(id)
4109
# ifdef p_gid_from_name
4110
#   undef p_gid_from_name
4111
#   define p_gid_from_name rb_f_notimplement
4112
# endif
4113
#endif
3977 4114

  
3978 4115
#if defined HAVE_SETUID
3979 4116
/*
3980 4117
 *  call-seq:
3981
 *     Process::Sys.setuid(integer)   -> nil
4118
 *     Process::Sys.setuid(user)   -> nil
3982 4119
 *
3983
 *  Set the user ID of the current process to _integer_. Not
4120
 *  Set the user ID of the current process to _user_. Not
3984 4121
 *  available on all platforms.
3985 4122
 *
3986 4123
 */
......
3988 4125
static VALUE
3989 4126
p_sys_setuid(VALUE obj, VALUE id)
3990 4127
{
4128
    PREPARE_GETPWNAM;
3991 4129
    check_uid_switch();
3992
    if (setuid(NUM2UIDT(id)) != 0) rb_sys_fail(0);
4130
    if (setuid(OBJ2UID(id)) != 0) rb_sys_fail(0);
3993 4131
    return Qnil;
3994 4132
}
3995 4133
#else
......
4000 4138
#if defined HAVE_SETRUID
4001 4139
/*
4002 4140
 *  call-seq:
4003
 *     Process::Sys.setruid(integer)   -> nil
4141
 *     Process::Sys.setruid(user)   -> nil
4004 4142
 *
4005
 *  Set the real user ID of the calling process to _integer_.
4143
 *  Set the real user ID of the calling process to _user_.
4006 4144
 *  Not available on all platforms.
4007 4145
 *
4008 4146
 */
......
4010 4148
static VALUE
4011 4149
p_sys_setruid(VALUE obj, VALUE id)
4012 4150
{
4151
    PREPARE_GETPWNAM;
4013 4152
    check_uid_switch();
4014
    if (setruid(NUM2UIDT(id)) != 0) rb_sys_fail(0);
4153
    if (setruid(OBJ2UID(id)) != 0) rb_sys_fail(0);
4015 4154
    return Qnil;
4016 4155
}
4017 4156
#else
......
4022 4161
#if defined HAVE_SETEUID
4023 4162
/*
4024 4163
 *  call-seq:
4025
 *     Process::Sys.seteuid(integer)   -> nil
4164
 *     Process::Sys.seteuid(user)   -> nil
4026 4165
 *
4027 4166
 *  Set the effective user ID of the calling process to
4028
 *  _integer_.  Not available on all platforms.
4167
 *  _user_.  Not available on all platforms.
4029 4168
 *
4030 4169
 */
4031 4170

  
4032 4171
static VALUE
4033 4172
p_sys_seteuid(VALUE obj, VALUE id)
4034 4173
{
4174
    PREPARE_GETPWNAM;
4035 4175
    check_uid_switch();
4036
    if (seteuid(NUM2UIDT(id)) != 0) rb_sys_fail(0);
4176
    if (seteuid(OBJ2UID(id)) != 0) rb_sys_fail(0);
4037 4177
    return Qnil;
4038 4178
}
4039 4179
#else
......
4046 4186
 *  call-seq:
4047 4187
 *     Process::Sys.setreuid(rid, eid)   -> nil
4048 4188
 *
4049
 *  Sets the (integer) real and/or effective user IDs of the current
4189
 *  Sets the (user) real and/or effective user IDs of the current
4050 4190
 *  process to _rid_ and _eid_, respectively. A value of
4051 4191
 *  <code>-1</code> for either means to leave that ID unchanged. Not
4052 4192
 *  available on all platforms.
......
4056 4196
static VALUE
4057 4197
p_sys_setreuid(VALUE obj, VALUE rid, VALUE eid)
4058 4198
{
4199
    PREPARE_GETPWNAM;
4059 4200
    check_uid_switch();
4060
    if (setreuid(NUM2UIDT(rid),NUM2UIDT(eid)) != 0) rb_sys_fail(0);
4201
    if (setreuid(OBJ2UID(rid), OBJ2UID(eid)) != 0) rb_sys_fail(0);
4061 4202
    return Qnil;
4062 4203
}
4063 4204
#else
......
4070 4211
 *  call-seq:
4071 4212
 *     Process::Sys.setresuid(rid, eid, sid)   -> nil
4072 4213
 *
4073
 *  Sets the (integer) real, effective, and saved user IDs of the
4214
 *  Sets the (user) real, effective, and saved user IDs of the
4074 4215
 *  current process to _rid_, _eid_, and _sid_ respectively. A
4075 4216
 *  value of <code>-1</code> for any value means to
4076 4217
 *  leave that ID unchanged. Not available on all platforms.
......
4080 4221
static VALUE
4081 4222
p_sys_setresuid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
4082 4223
{
4224
    PREPARE_GETPWNAM;
4083 4225
    check_uid_switch();
4084
    if (setresuid(NUM2UIDT(rid),NUM2UIDT(eid),NUM2UIDT(sid)) != 0) rb_sys_fail(0);
4226
    if (setresuid(OBJ2UID(rid), OBJ2UID(eid), OBJ2UID(sid)) != 0) rb_sys_fail(0);
4085 4227
    return Qnil;
4086 4228
}
4087 4229
#else
......
4111 4253
#if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRUID) || defined(HAVE_SETUID)
4112 4254
/*
4113 4255
 *  call-seq:
4114
 *     Process.uid= integer   -> numeric
4256
 *     Process.uid= user   -> numeric
4115 4257
 *
4116
 *  Sets the (integer) user ID for this process. Not available on all
4258
 *  Sets the (user) user ID for this process. Not available on all
4117 4259
 *  platforms.
4118 4260
 */
4119 4261

  
......
4121 4263
proc_setuid(VALUE obj, VALUE id)
4122 4264
{
4123 4265
    rb_uid_t uid;
4266
    PREPARE_GETPWNAM;
4124 4267

  
4125 4268
    check_uid_switch();
4126 4269

  
4127
    uid = NUM2UIDT(id);
4270
    uid = OBJ2UID(id);
4128 4271
#if defined(HAVE_SETRESUID)
4129 4272
    if (setresuid(uid, -1, -1) < 0) rb_sys_fail(0);
4130 4273
#elif defined HAVE_SETREUID
......
4177 4320

  
4178 4321
/*
4179 4322
 *  call-seq:
4180
 *     Process::UID.change_privilege(integer)   -> fixnum
4323
 *     Process::UID.change_privilege(user)   -> fixnum
4181 4324
 *
4182 4325
 *  Change the current process's real and effective user ID to that
4183
 *  specified by _integer_. Returns the new user ID. Not
4326
 *  specified by _user_. Returns the new user ID. Not
4184 4327
 *  available on all platforms.
4185 4328
 *
4186 4329
 *     [Process.uid, Process.euid]          #=> [0, 0]
......
4192 4335
p_uid_change_privilege(VALUE obj, VALUE id)
4193 4336
{
4194 4337
    rb_uid_t uid;
4338
    PREPARE_GETPWNAM;
4195 4339

  
4196 4340
    check_uid_switch();
4197 4341

  
4198
    uid = NUM2UIDT(id);
4342
    uid = OBJ2UID(id);
4199 4343

  
4200 4344
    if (geteuid() == 0) { /* root-user */
4201 4345
#if defined(HAVE_SETRESUID)
......
4350 4494
#if defined HAVE_SETGID
4351 4495
/*
4352 4496
 *  call-seq:
4353
 *     Process::Sys.setgid(integer)   -> nil
4497
 *     Process::Sys.setgid(group)   -> nil
4354 4498
 *
4355
 *  Set the group ID of the current process to _integer_. Not
4499
 *  Set the group ID of the current process to _group_. Not
4356 4500
 *  available on all platforms.
4357 4501
 *
4358 4502
 */
......
4360 4504
static VALUE
4361 4505
p_sys_setgid(VALUE obj, VALUE id)
4362 4506
{
4507
    PREPARE_GETGRNAM;
4363 4508
    check_gid_switch();
4364
    if (setgid(NUM2GIDT(id)) != 0) rb_sys_fail(0);
4509
    if (setgid(OBJ2GID(id)) != 0) rb_sys_fail(0);
4365 4510
    return Qnil;
4366 4511
}
4367 4512
#else
......
4372 4517
#if defined HAVE_SETRGID
4373 4518
/*
4374 4519
 *  call-seq:
4375
 *     Process::Sys.setrgid(integer)   -> nil
4520
 *     Process::Sys.setrgid(group)   -> nil
4376 4521
 *
4377
 *  Set the real group ID of the calling process to _integer_.
4522
 *  Set the real group ID of the calling process to _group_.
4378 4523
 *  Not available on all platforms.
4379 4524
 *
4380 4525
 */
......
4382 4527
static VALUE
4383 4528
p_sys_setrgid(VALUE obj, VALUE id)
4384 4529
{
4530
    PREPARE_GETGRNAM;
4385 4531
    check_gid_switch();
4386
    if (setrgid(NUM2GIDT(id)) != 0) rb_sys_fail(0);
4532
    if (setrgid(OBJ2GID(id)) != 0) rb_sys_fail(0);
4387 4533
    return Qnil;
4388 4534
}
4389 4535
#else
......
4394 4540
#if defined HAVE_SETEGID
4395 4541
/*
4396 4542
 *  call-seq:
4397
 *     Process::Sys.setegid(integer)   -> nil
4543
 *     Process::Sys.setegid(group)   -> nil
4398 4544
 *
4399 4545
 *  Set the effective group ID of the calling process to
4400
 *  _integer_.  Not available on all platforms.
4546
 *  _group_.  Not available on all platforms.
4401 4547
 *
4402 4548
 */
4403 4549

  
4404 4550
static VALUE
4405 4551
p_sys_setegid(VALUE obj, VALUE id)
4406 4552
{
4553
    PREPARE_GETGRNAM;
4407 4554
    check_gid_switch();
4408
    if (setegid(NUM2GIDT(id)) != 0) rb_sys_fail(0);
4555
    if (setegid(OBJ2GID(id)) != 0) rb_sys_fail(0);
4409 4556
    return Qnil;
4410 4557
}
4411 4558
#else
......
4418 4565
 *  call-seq:
4419 4566
 *     Process::Sys.setregid(rid, eid)   -> nil
4420 4567
 *
4421
 *  Sets the (integer) real and/or effective group IDs of the current
4568
 *  Sets the (group) real and/or effective group IDs of the current
4422 4569
 *  process to <em>rid</em> and <em>eid</em>, respectively. A value of
4423 4570
 *  <code>-1</code> for either means to leave that ID unchanged. Not
4424 4571
 *  available on all platforms.
......
4428 4575
static VALUE
4429 4576
p_sys_setregid(VALUE obj, VALUE rid, VALUE eid)
4430 4577
{
4578
    PREPARE_GETGRNAM;
4431 4579
    check_gid_switch();
4432
    if (setregid(NUM2GIDT(rid),NUM2GIDT(eid)) != 0) rb_sys_fail(0);
4580
    if (setregid(OBJ2GID(rid), OBJ2GID(eid)) != 0) rb_sys_fail(0);
4433 4581
    return Qnil;
4434 4582
}
4435 4583
#else
......
4441 4589
 *  call-seq:
4442 4590
 *     Process::Sys.setresgid(rid, eid, sid)   -> nil
4443 4591
 *
4444
 *  Sets the (integer) real, effective, and saved user IDs of the
4592
 *  Sets the (group) real, effective, and saved user IDs of the
4445 4593
 *  current process to <em>rid</em>, <em>eid</em>, and <em>sid</em>
4446 4594
 *  respectively. A value of <code>-1</code> for any value means to
4447 4595
 *  leave that ID unchanged. Not available on all platforms.
......
4451 4599
static VALUE
4452 4600
p_sys_setresgid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
4453 4601
{
4602
    PREPARE_GETGRNAM;
4454 4603
    check_gid_switch();
4455
    if (setresgid(NUM2GIDT(rid),NUM2GIDT(eid),NUM2GIDT(sid)) != 0) rb_sys_fail(0);
4604
    if (setresgid(OBJ2GID(rid), OBJ2GID(eid), OBJ2GID(sid)) != 0) rb_sys_fail(0);
4456 4605
    return Qnil;
4457 4606
}
4458 4607
#else
......
4520 4669
proc_setgid(VALUE obj, VALUE id)
4521 4670
{
4522 4671
    rb_gid_t gid;
4672
    PREPARE_GETGRNAM;
4523 4673

  
4524 4674
    check_gid_switch();
4525 4675

  
4526
    gid = NUM2GIDT(id);
4676
    gid = OBJ2GID(id);
4527 4677
#if defined(HAVE_SETRESGID)
4528 4678
    if (setresgid(gid, -1, -1) < 0) rb_sys_fail(0);
4529 4679
#elif defined HAVE_SETREGID
......
4653 4803
{
4654 4804
    int ngroups, i;
4655 4805
    rb_gid_t *groups;
4656
#ifdef HAVE_GETGRNAM_R
4657
    long getgr_buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
4658
    char* getgr_buf;
4659

  
4660
    if (getgr_buf_len < 0)
4661
	getgr_buf_len = 4096;
4662
    getgr_buf = ALLOCA_N(char, getgr_buf_len);
4663
#endif
4806
    PREPARE_GETGRNAM;
4664 4807

  
4665 4808
    Check_Type(ary, T_ARRAY);
4666 4809

  
......
4673 4816
    for (i = 0; i < ngroups; i++) {
4674 4817
	VALUE g = RARRAY_PTR(ary)[i];
4675 4818

  
4676
	if (FIXNUM_P(g)) {
4677
	    groups[i] = NUM2GIDT(g);
4678
	}
4679
	else {
4680
	    VALUE tmp = rb_check_string_type(g);
4681
	    struct group grp;
4682
	    struct group *p;
4683
	    int ret;
4684

  
4685
	    if (NIL_P(tmp)) {
4686
		groups[i] = NUM2GIDT(g);
4687
	    }
4688
	    else {
4689
		const char *grpname = StringValueCStr(tmp);
4690

  
4691
#ifdef HAVE_GETGRNAM_R
4692
		ret = getgrnam_r(grpname, &grp, getgr_buf, getgr_buf_len, &p);
4693
		if (ret)
4694
		    rb_sys_fail("getgrnam_r");
4695
#else
4696
		p = getgrnam(grpname);
4697
#endif
4698
		if (p == NULL) {
4699
		    rb_raise(rb_eArgError,
4700
			     "can't find group for %s", RSTRING_PTR(tmp));
4701
		}
4702
		groups[i] = p->gr_gid;
4703
	    }
4704
	}
4819
	groups[i] = OBJ2GID(g);
4705 4820
    }
4706 4821

  
4707 4822
    if (setgroups(ngroups, groups) == -1) /* ngroups <= maxgroups */
......
4735 4850
static VALUE
4736 4851
proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp)
4737 4852
{
4738
    if (initgroups(StringValuePtr(uname), NUM2GIDT(base_grp)) != 0) {
4853
    PREPARE_GETGRNAM;
4854
    if (initgroups(StringValuePtr(uname), OBJ2GID(base_grp)) != 0) {
4739 4855
	rb_sys_fail(0);
4740 4856
    }
4741 4857
    return proc_getgroups(obj);
......
4907 5023

  
4908 5024
/*
4909 5025
 *  call-seq:
4910
 *     Process::GID.change_privilege(integer)   -> fixnum
5026
 *     Process::GID.change_privilege(group)   -> fixnum
4911 5027
 *
4912 5028
 *  Change the current process's real and effective group ID to that
4913
 *  specified by _integer_. Returns the new group ID. Not
5029
 *  specified by _group_. Returns the new group ID. Not
4914 5030
 *  available on all platforms.
4915 5031
 *
4916 5032
 *     [Process.gid, Process.egid]          #=> [0, 0]
......
4922 5038
p_gid_change_privilege(VALUE obj, VALUE id)
4923 5039
{
4924 5040
    rb_gid_t gid;
5041
    PREPARE_GETGRNAM;
4925 5042

  
4926 5043
    check_gid_switch();
4927 5044

  
4928
    gid = NUM2GIDT(id);
5045
    gid = OBJ2GID(id);
4929 5046

  
4930 5047
    if (geteuid() == 0) { /* root-user */
4931 5048
#if defined(HAVE_SETRESGID)
......
5121 5238
#if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETEUID) || defined(HAVE_SETUID)
5122 5239
/*
5123 5240
 *  call-seq:
5124
 *     Process.euid= integer
5241
 *     Process.euid= user
5125 5242
 *
5126 5243
 *  Sets the effective user ID for this process. Not available on all
5127 5244
 *  platforms.
......
5130 5247
static VALUE
5131 5248
proc_seteuid_m(VALUE mod, VALUE euid)
5132 5249
{
5250
    PREPARE_GETPWNAM;
5133 5251
    check_uid_switch();
5134
    proc_seteuid(NUM2UIDT(euid));
5252
    proc_seteuid(OBJ2UID(euid));
5135 5253
    return euid;
5136 5254
}
5137 5255
#else
......
5180 5298

  
5181 5299
/*
5182 5300
 *  call-seq:
5183
 *     Process::UID.grant_privilege(integer)   -> fixnum
5184
 *     Process::UID.eid= integer               -> fixnum
5301
 *     Process::UID.grant_privilege(user)   -> fixnum
5302
 *     Process::UID.eid= user               -> fixnum
5185 5303
 *
5186 5304
 *  Set the effective user ID, and if possible, the saved user ID of
5187
 *  the process to the given _integer_. Returns the new
5305
 *  the process to the given _user_. Returns the new
5188 5306
 *  effective user ID. Not available on all platforms.
5189 5307
 *
5190 5308
 *     [Process.uid, Process.euid]          #=> [0, 0]
......
5195 5313
static VALUE
5196 5314
p_uid_grant_privilege(VALUE obj, VALUE id)
5197 5315
{
5198
    rb_seteuid_core(NUM2UIDT(id));
5316
    PREPARE_GETPWNAM;
5317
    rb_seteuid_core(OBJ2UID(id));
5199 5318
    return id;
5200 5319
}
5201 5320

  
......
5234 5353
{
5235 5354
#if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID)
5236 5355
    rb_gid_t gid;
5356
    PREPARE_GETGRNAM;
5237 5357
#endif
5238 5358

  
5239 5359
    check_gid_switch();
5240 5360

  
5241 5361
#if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID)
5242
    gid = NUM2GIDT(egid);
5362
    gid = OBJ2GID(egid);
5243 5363
#endif
5244 5364

  
5245 5365
#if defined(HAVE_SETRESGID)
......
5310 5430

  
5311 5431
/*
5312 5432
 *  call-seq:
5313
 *     Process::GID.grant_privilege(integer)    -> fixnum
5314
 *     Process::GID.eid = integer               -> fixnum
5433
 *     Process::GID.grant_privilege(group)    -> fixnum
5434
 *     Process::GID.eid = group               -> fixnum
5315 5435
 *
5316 5436
 *  Set the effective group ID, and if possible, the saved group ID of
5317
 *  the process to the given _integer_. Returns the new
5437
 *  the process to the given _group_. Returns the new
5318 5438
 *  effective group ID. Not available on all platforms.
5319 5439
 *
5320 5440
 *     [Process.gid, Process.egid]          #=> [0, 0]
......
5325 5445
static VALUE
5326 5446
p_gid_grant_privilege(VALUE obj, VALUE id)
5327 5447
{
5328
    rb_setegid_core(NUM2GIDT(id));
5448
    PREPARE_GETGRNAM;
5449
    rb_setegid_core(OBJ2GID(id));
5329 5450
    return id;
5330 5451
}
5331 5452

  
......
6008 6129
    rb_define_module_function(rb_mProcGID, "sid_available?", p_gid_have_saved_id, 0);
6009 6130
    rb_define_module_function(rb_mProcUID, "switch", p_uid_switch, 0);
6010 6131
    rb_define_module_function(rb_mProcGID, "switch", p_gid_switch, 0);
6132
#ifdef p_uid_from_name
6133
    rb_define_module_function(rb_mProcUID, "from_name", p_uid_from_name, 1);
6134
#endif
6135
#ifdef p_gid_from_name
6136
    rb_define_module_function(rb_mProcGID, "from_name", p_gid_from_name, 1);
6137
#endif
6011 6138

  
6012 6139
    rb_mProcID_Syscall = rb_define_module_under(rb_mProcess, "Sys");
6013 6140

  
test/ruby/test_process.rb
1180 1180
  rescue NotImplementedError
1181 1181
  end
1182 1182

  
1183
  def test_seteuid_name
1184
    user = ENV["USER"] or return
1185
    assert_nothing_raised(TypeError) {Process.euid = user}
1186
  rescue NotImplementedError
1187
  end
1188

  
1183 1189
  def test_getegid
1184 1190
    assert_kind_of(Integer, Process.egid)
1185 1191
  end
1186
-