diff options
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 34 |
1 files changed, 31 insertions, 3 deletions
@@ -2215,8 +2215,22 @@ proc_setuid(VALUE obj, VALUE id) * */ -static int SAVED_USER_ID; +static int SAVED_USER_ID = -1; +#ifdef BROKEN_SETREUID +int +setreuid(rb_uid_t ruid, rb_uid_t euid) +{ + if (ruid != -1 && ruid != getuid()) { + if (euid == -1) euid = geteuid(); + if (setuid(ruid) < 0) return -1; + } + if (euid != -1 && euid != geteuid()) { + if (seteuid(euid) < 0) return -1; + } + return 0; +} +#endif /* * call-seq: @@ -2551,7 +2565,7 @@ proc_setgid(VALUE obj, VALUE id) #elif defined HAVE_SETREGID if (setregid(gid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETRGID - if (setrgid((GIDTYPE)gid) < 0) rb_sys_fail(0); + if (setrgid(gid) < 0) rb_sys_fail(0); #elif defined HAVE_SETGID { if (getegid() == gid) { @@ -2807,8 +2821,22 @@ proc_daemon(int argc, VALUE *argv) * */ -static int SAVED_GROUP_ID; +static int SAVED_GROUP_ID = -1; +#ifdef BROKEN_SETREGID +int +setregid(rb_gid_t rgid, rb_gid_t egid) +{ + if (rgid != -1 && rgid != getgid()) { + if (egid == -1) egid = getegid(); + if (setgid(rgid) < 0) return -1; + } + if (egid != -1 && egid != getegid()) { + if (setegid(egid) < 0) return -1; + } + return 0; +} +#endif /* * call-seq: |