Module: Process::UID
- Defined in:
- process.c
Class Method Summary collapse
-
.Process::UID.change_privilege(user) ⇒ Integer
Change the current process’s real and effective user ID to that specified by user.
-
.eid ⇒ Object
Returns the effective user ID for the current process.
-
.Process::UID.from_name(name) ⇒ Object
Get the user ID by the name.
-
.grant_privilege(id) ⇒ Object
Set the effective user ID, and if possible, the saved user ID of the process to the given user.
-
.Process::UID.re_exchange ⇒ Integer
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 the current process.
-
.Process::UID.sid_available? ⇒ Boolean
Returns
true
if the current platform has saved user ID functionality. - .switch ⇒ Object
Instance Method Summary collapse
-
#Process::UID.change_privilege(user) ⇒ Integer
private
Change the current process’s real and effective user ID to that specified by user.
-
#eid ⇒ Object
private
Returns the effective user ID for the current process.
-
#Process::UID.from_name(name) ⇒ Object
private
Get the user ID by the name.
-
#grant_privilege(id) ⇒ Object
private
Set the effective user ID, and if possible, the saved user ID of the process to the given user.
-
#Process::UID.re_exchange ⇒ Integer
private
Exchange real and effective user IDs and return the new effective user ID.
-
#Process::UID.re_exchangeable? ⇒ Boolean
private
Returns
true
if the real and effective user IDs of a process may be exchanged on the current platform. -
#rid ⇒ Object
private
Returns the (real) user ID of the current process.
-
#Process::UID.sid_available? ⇒ Boolean
private
Returns
true
if the current platform has saved user ID functionality. - #switch ⇒ Object private
Class Method Details
.Process::UID.change_privilege(user) ⇒ Integer
6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 |
# File 'process.c', line 6432
static VALUE
p_uid_change_privilege(VALUE obj, VALUE id)
{
rb_uid_t uid;
check_uid_switch();
uid = OBJ2UID(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);
}
else {
if (uid == 0) { /* (r,e,s) == (root, root, x) */
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
if (setreuid(0, -1) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
}
}
else {
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
if (getuid() == uid) {
if (SAVED_USER_ID == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
}
else {
if (uid == 0) {
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (setruid(0) < 0) rb_sys_fail(0);
}
else {
if (setruid(0) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
}
}
else {
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
#else
(void)uid;
rb_notimplement();
#endif
}
else { /* unprivileged user */
#if defined(HAVE_SETRESUID)
if (setresuid((getuid() == uid)? (rb_uid_t)-1: uid,
(geteuid() == uid)? (rb_uid_t)-1: uid,
(SAVED_USER_ID == uid)? (rb_uid_t)-1: uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
if (SAVED_USER_ID == uid) {
if (setreuid((getuid() == uid)? (rb_uid_t)-1: uid,
(geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
rb_sys_fail(0);
}
else if (getuid() != uid) {
if (setreuid(uid, (geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else if (/* getuid() == uid && */ geteuid() != uid) {
if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
}
else { /* getuid() == uid && geteuid() == uid */
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
}
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
if (SAVED_USER_ID == uid) {
if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
}
else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
if (getuid() != uid) {
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setruid(uid) < 0) rb_sys_fail(0);
}
}
else if (/* geteuid() != uid && */ getuid() == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setruid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_44BSD_SETUID
if (getuid() == uid) {
/* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
if (setuid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_SETEUID
if (getuid() == uid && SAVED_USER_ID == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_SETUID
if (getuid() == uid && SAVED_USER_ID == uid) {
if (setuid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#else
rb_notimplement();
#endif
}
return id;
}
|
.euid ⇒ Integer .Process::UID.eid ⇒ Integer .Process::Sys.geteuid ⇒ Integer
7314 7315 7316 7317 7318 7319 |
# File 'process.c', line 7314
static VALUE
proc_geteuid(VALUE obj)
{
rb_uid_t euid = geteuid();
return UIDT2NUM(euid);
}
|
.Process::UID.from_name(name) ⇒ Object
6095 6096 6097 6098 6099 |
# File 'process.c', line 6095
static VALUE
p_uid_from_name(VALUE self, VALUE id)
{
return UIDT2NUM(OBJ2UID(id));
}
|
.Process::UID.grant_privilege(user) ⇒ Integer .Process::UID.eid=(user) ⇒ Integer
7419 7420 7421 7422 7423 7424 |
# File 'process.c', line 7419
static VALUE
p_uid_grant_privilege(VALUE obj, VALUE id)
{
rb_seteuid_core(OBJ2UID(id));
return id;
}
|
.Process::UID.re_exchange ⇒ Integer
7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 |
# File 'process.c', line 7593
static VALUE
p_uid_exchange(VALUE obj)
{
rb_uid_t uid;
#if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
rb_uid_t euid;
#endif
check_uid_switch();
uid = getuid();
#if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
euid = geteuid();
#endif
#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.
7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 |
# File 'process.c', line 7568
static VALUE
p_uid_exchangeable(VALUE _)
{
#if defined(HAVE_SETRESUID)
return Qtrue;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
return Qtrue;
#else
return Qfalse;
#endif
}
|
.uid ⇒ Integer .Process::UID.rid ⇒ Integer .Process::Sys.getuid ⇒ Integer
6341 6342 6343 6344 6345 6346 |
# File 'process.c', line 6341
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.
7693 7694 7695 7696 7697 7698 7699 7700 7701 |
# File 'process.c', line 7693
static VALUE
p_uid_have_saved_id(VALUE _)
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
#else
return Qfalse;
#endif
}
|
.switch ⇒ Object
7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 |
# File 'process.c', line 7772
static VALUE
p_uid_switch(VALUE obj)
{
rb_uid_t uid, euid;
check_uid_switch();
uid = getuid();
euid = geteuid();
if (uid == euid) {
rb_syserr_fail(EPERM, 0);
}
p_uid_exchange(obj);
if (rb_block_given_p()) {
under_uid_switch = 1;
return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, obj);
}
else {
return UIDT2NUM(euid);
}
}
|
Instance Method Details
#Process::UID.change_privilege(user) ⇒ Integer (private)
6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 |
# File 'process.c', line 6432
static VALUE
p_uid_change_privilege(VALUE obj, VALUE id)
{
rb_uid_t uid;
check_uid_switch();
uid = OBJ2UID(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);
}
else {
if (uid == 0) { /* (r,e,s) == (root, root, x) */
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
if (setreuid(0, -1) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
}
}
else {
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
if (getuid() == uid) {
if (SAVED_USER_ID == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
}
else {
if (uid == 0) {
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (setruid(0) < 0) rb_sys_fail(0);
}
else {
if (setruid(0) < 0) rb_sys_fail(0);
SAVED_USER_ID = 0;
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
}
}
else {
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
#else
(void)uid;
rb_notimplement();
#endif
}
else { /* unprivileged user */
#if defined(HAVE_SETRESUID)
if (setresuid((getuid() == uid)? (rb_uid_t)-1: uid,
(geteuid() == uid)? (rb_uid_t)-1: uid,
(SAVED_USER_ID == uid)? (rb_uid_t)-1: uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
if (SAVED_USER_ID == uid) {
if (setreuid((getuid() == uid)? (rb_uid_t)-1: uid,
(geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
rb_sys_fail(0);
}
else if (getuid() != uid) {
if (setreuid(uid, (geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else if (/* getuid() == uid && */ geteuid() != uid) {
if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
}
else { /* getuid() == uid && geteuid() == uid */
if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setreuid(uid, -1) < 0) rb_sys_fail(0);
}
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
if (SAVED_USER_ID == uid) {
if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
}
else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
if (getuid() != uid) {
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setruid(uid) < 0) rb_sys_fail(0);
}
}
else if (/* geteuid() != uid && */ getuid() == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
if (setruid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_44BSD_SETUID
if (getuid() == uid) {
/* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
if (setuid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_SETEUID
if (getuid() == uid && SAVED_USER_ID == uid) {
if (seteuid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#elif defined HAVE_SETUID
if (getuid() == uid && SAVED_USER_ID == uid) {
if (setuid(uid) < 0) rb_sys_fail(0);
}
else {
rb_syserr_fail(EPERM, 0);
}
#else
rb_notimplement();
#endif
}
return id;
}
|
#euid ⇒ Integer (private) #Process::UID.eid ⇒ Integer (private) #Process::Sys.geteuid ⇒ Integer (private)
7314 7315 7316 7317 7318 7319 |
# File 'process.c', line 7314
static VALUE
proc_geteuid(VALUE obj)
{
rb_uid_t euid = geteuid();
return UIDT2NUM(euid);
}
|
#Process::UID.from_name(name) ⇒ Object (private)
6095 6096 6097 6098 6099 |
# File 'process.c', line 6095
static VALUE
p_uid_from_name(VALUE self, VALUE id)
{
return UIDT2NUM(OBJ2UID(id));
}
|
#Process::UID.grant_privilege(user) ⇒ Integer (private) #Process::UID.eid=(user) ⇒ Integer (private)
7419 7420 7421 7422 7423 7424 |
# File 'process.c', line 7419
static VALUE
p_uid_grant_privilege(VALUE obj, VALUE id)
{
rb_seteuid_core(OBJ2UID(id));
return id;
}
|
#Process::UID.re_exchange ⇒ Integer (private)
7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 |
# File 'process.c', line 7593
static VALUE
p_uid_exchange(VALUE obj)
{
rb_uid_t uid;
#if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
rb_uid_t euid;
#endif
check_uid_switch();
uid = getuid();
#if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
euid = geteuid();
#endif
#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 (private)
Returns true
if the real and effective user IDs of a process may be exchanged on the current platform.
7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 |
# File 'process.c', line 7568
static VALUE
p_uid_exchangeable(VALUE _)
{
#if defined(HAVE_SETRESUID)
return Qtrue;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
return Qtrue;
#else
return Qfalse;
#endif
}
|
#uid ⇒ Integer (private) #Process::UID.rid ⇒ Integer (private) #Process::Sys.getuid ⇒ Integer (private)
6341 6342 6343 6344 6345 6346 |
# File 'process.c', line 6341
static VALUE
proc_getuid(VALUE obj)
{
rb_uid_t uid = getuid();
return UIDT2NUM(uid);
}
|
#Process::UID.sid_available? ⇒ Boolean (private)
Returns true
if the current platform has saved user ID functionality.
7693 7694 7695 7696 7697 7698 7699 7700 7701 |
# File 'process.c', line 7693
static VALUE
p_uid_have_saved_id(VALUE _)
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
#else
return Qfalse;
#endif
}
|
#switch ⇒ Object (private)
7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 |
# File 'process.c', line 7772
static VALUE
p_uid_switch(VALUE obj)
{
rb_uid_t uid, euid;
check_uid_switch();
uid = getuid();
euid = geteuid();
if (uid == euid) {
rb_syserr_fail(EPERM, 0);
}
p_uid_exchange(obj);
if (rb_block_given_p()) {
under_uid_switch = 1;
return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, obj);
}
else {
return UIDT2NUM(euid);
}
}
|