Module: Process::UID
- Defined in:
- process.c
Overview
The Process::UID
module contains a collection of module functions which can be used to portably get, set, and switch the current process's real, effective, and saved user IDs.
Class Method Summary collapse
-
.Process::UID.change_privilege(integer) ⇒ Fixnum
Change the current process's real and effective user ID to that specified by integer.
-
.eid ⇒ Object
Returns the effective user ID for this process.
-
.grant_privilege ⇒ Object
Set the effective user ID, and if possible, the saved user ID of the process to the given integer.
-
.Process::UID.re_exchange ⇒ Fixnum
Exchange real and effective user IDs and return the new effective user ID.
-
.Process::UID.re_exchangeable? ⇒ Boolean
Returns
true
if the real and effective user IDs of a process may be exchanged on the current platform. -
.rid ⇒ Object
Returns the (real) user ID of this process.
-
.Process::UID.sid_available? ⇒ Boolean
Returns
true
if the current platform has saved user ID functionality. -
.switch ⇒ Object
Switch the effective and real user IDs of the current process.
Class Method Details
.Process::UID.change_privilege(integer) ⇒ Fixnum
Change the current process's real and effective user ID to that specified by integer. Returns the new user ID. Not available on all platforms.
[Process.uid, Process.euid] #=> [0, 0]
Process::UID.change_privilege(31) #=> 31
[Process.uid, Process.euid] #=> [31, 31]
|
# File 'process.c'
static VALUE
p_uid_change_privilege(VALUE obj, VALUE id)
{
rb_uid_t uid;
check_uid_switch();
uid = NUM2UIDT(id);
if (geteuid() == 0) { /* root-user */
#if defined(HAVE_SETRESUID)
if (setresuid(uid, uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#elif defined(HAVE_SETUID)
if (setuid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
if (getuid() == uid) {
if (SAVED_USER_ID == uid) {
if (setreuid(-1, uid) < 0) rb_sys_fail(0);
}
|
.euid ⇒ Fixnum .Process::UID.eid ⇒ Fixnum .Process::Sys.geteuid ⇒ Fixnum
Returns the effective user ID for this process.
Process.euid #=> 501
|
# File 'process.c'
static VALUE
proc_geteuid(VALUE obj)
{
rb_uid_t euid = geteuid();
return UIDT2NUM(euid);
}
|
.Process::UID.grant_privilege(integer) ⇒ Fixnum .Process::UID.eid=(integer) ⇒ Fixnum
Set the effective user ID, and if possible, the saved user ID of the process to the given integer. Returns the new effective user ID. Not available on all platforms.
[Process.uid, Process.euid] #=> [0, 0]
Process::UID.grant_privilege(31) #=> 31
[Process.uid, Process.euid] #=> [0, 31]
|
# File 'process.c'
static VALUE
p_uid_grant_privilege(VALUE obj, VALUE id)
{
rb_seteuid_core(NUM2UIDT(id));
return id;
}
|
.Process::UID.re_exchange ⇒ Fixnum
Exchange real and effective user IDs and return the new effective user ID. Not available on all platforms.
[Process.uid, Process.euid] #=> [0, 31]
Process::UID.re_exchange #=> 0
[Process.uid, Process.euid] #=> [31, 0]
|
# File 'process.c'
static VALUE
p_uid_exchange(VALUE obj)
{
rb_uid_t uid, euid;
check_uid_switch();
uid = getuid();
euid = geteuid();
#if defined(HAVE_SETRESUID)
if (setresuid(euid, uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
if (setreuid(euid,uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#else
rb_notimplement();
#endif
return UIDT2NUM(uid);
}
|
.Process::UID.re_exchangeable? ⇒ Boolean
Returns true
if the real and effective user IDs of a process may be exchanged on the current platform.
|
# File 'process.c'
static VALUE
p_uid_exchangeable(void)
{
#if defined(HAVE_SETRESUID)
return Qtrue;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
return Qtrue;
#else
return Qfalse;
#endif
}
|
.uid ⇒ Fixnum .Process::UID.rid ⇒ Fixnum .Process::Sys.getuid ⇒ Fixnum
Returns the (real) user ID of this process.
Process.uid #=> 501
|
# File 'process.c'
static VALUE
proc_getuid(VALUE obj)
{
rb_uid_t uid = getuid();
return UIDT2NUM(uid);
}
|
.Process::UID.sid_available? ⇒ Boolean
Returns true
if the current platform has saved user ID functionality.
|
# File 'process.c'
static VALUE
p_uid_have_saved_id(void)
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
#else
return Qfalse;
#endif
}
|
.Process::UID.switch ⇒ Fixnum .Process::UID.switch { ... } ⇒ Object
Switch the effective and real user IDs of the current process. If a block is given, the user IDs will be switched back after the block is executed. Returns the new effective user ID if called without a block, and the return value of the block if one is given.
|
# File 'process.c'
static VALUE
p_uid_switch(VALUE obj)
{
rb_uid_t uid, euid;
check_uid_switch();
uid = getuid();
euid = geteuid();
if (uid != euid) {
proc_seteuid(obj, UIDT2NUM(uid));
if (rb_block_given_p()) {
under_uid_switch = 1;
return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, SAVED_USER_ID);
}
|