From 6bb6f5b85f7b8a43696e8d8e2f9ee75d6e285995 Mon Sep 17 00:00:00 2001
From: William Orr <will@worrbase.com>
Date: Sun, 27 Feb 2011 22:58:12 -0500
Subject: [PATCH] Added Parrot_get_effective_user_id()
Wrote test for get_effective_user_id
Made test for get_effective_uid *nix only
---
include/parrot/platform_interface.h | 3 +++
src/dynpmc/os.pmc | 15 +++++++++++++++
src/platform/generic/uid.c | 16 ++++++++++++++++
src/platform/win32/uid.c | 17 +++++++++++++++++
t/dynpmc/os.t | 18 +++++++++++++++++-
5 files changed, 68 insertions(+), 1 deletions(-)
diff --git a/include/parrot/platform_interface.h b/include/parrot/platform_interface.h
index 1db1c2a..f0ca061 100644
a
|
b
|
|
392 | 392 | PARROT_EXPORT |
393 | 393 | UINTVAL Parrot_get_user_id(void); |
394 | 394 | |
| 395 | PARROT_EXPORT |
| 396 | UINTVAL Parrot_get_effective_user_id(void); |
| 397 | |
395 | 398 | /* |
396 | 399 | * system memory |
397 | 400 | */ |
diff --git a/src/dynpmc/os.pmc b/src/dynpmc/os.pmc
index 9dfa78b..f9c627c 100644
a
|
b
|
|
343 | 343 | |
344 | 344 | /* |
345 | 345 | |
| 346 | =item C<get_effective_user_id()> |
| 347 | |
| 348 | Returns the ID numver of the effective user. This is also platform dependent. |
| 349 | |
| 350 | =cut |
| 351 | |
| 352 | */ |
| 353 | |
| 354 | METHOD get_effective_user_id() { |
| 355 | const UINTVAL euid = Parrot_get_effective_user_id(); |
| 356 | RETURN(INTVAL euid); |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | |
346 | 361 | =item C<can_execute(STRING *filename)> |
347 | 362 | |
348 | 363 | =item C<can_read(STRING *filename)> |
diff --git a/src/platform/generic/uid.c b/src/platform/generic/uid.c
index a8c11c0..1a471b2 100644
a
|
b
|
|
44 | 44 | |
45 | 45 | /* |
46 | 46 | |
| 47 | =item C<UINTVAK Parrot_get_effective_user_id(void)> |
| 48 | |
| 49 | Get effective user id |
| 50 | |
| 51 | =cut |
| 52 | |
| 53 | */ |
| 54 | |
| 55 | UINTVAL |
| 56 | Parrot_get_effective_user_id(void) |
| 57 | { |
| 58 | return (UINTVAL)geteuid(); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | |
47 | 63 | =back |
48 | 64 | |
49 | 65 | =cut |
diff --git a/src/platform/win32/uid.c b/src/platform/win32/uid.c
index 52734b0..469ee45 100644
a
|
b
|
|
45 | 45 | |
46 | 46 | /* |
47 | 47 | |
| 48 | =item C<UINTVAK Parrot_get_effective_user_id(void)> |
| 49 | |
| 50 | Get effective user id |
| 51 | |
| 52 | =cut |
| 53 | |
| 54 | */ |
| 55 | |
| 56 | UINTVAL |
| 57 | Parrot_get_effective_user_id(void) |
| 58 | { |
| 59 | /* TODO */ |
| 60 | return (UINTVAL)0; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | |
48 | 65 | =back |
49 | 66 | |
50 | 67 | =cut |
diff --git a/t/dynpmc/os.t b/t/dynpmc/os.t
index ec70e6c..8582185 100644
a
|
b
|
|
5 | 5 | use warnings; |
6 | 6 | use lib qw( . lib ../lib ../../lib ); |
7 | 7 | use Test::More; |
8 | | use Parrot::Test tests => 34; |
| 8 | use Parrot::Test tests => 35; |
9 | 9 | use Parrot::Config; |
10 | 10 | use Cwd; |
11 | 11 | use File::Spec; |
… |
… |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | use English '$UID'; |
| 646 | use English '$EUID'; |
646 | 647 | |
647 | 648 | # Test chroot |
648 | 649 | SKIP: { |
… |
… |
|
688 | 689 | CODE |
689 | 690 | |
690 | 691 | SKIP: { |
| 692 | skip 'no effective user ids on Win32', 1 if ($MSWin32 || $cygwin); |
| 693 | pir_output_is( <<'CODE', $EUID, 'Test get_effective_user_id' ); |
| 694 | .sub main :main |
| 695 | $P0 = loadlib 'os' |
| 696 | $P1 = new ['OS'] |
| 697 | |
| 698 | $I0 = $P1."get_effective_user_id"() |
| 699 | print $I0 |
| 700 | |
| 701 | end |
| 702 | .end |
| 703 | CODE |
| 704 | } |
| 705 | |
| 706 | SKIP: { |
691 | 707 | skip 'no file modes on Win32', 3 if ($MSWin32 || $cygwin); |
692 | 708 | |
693 | 709 | open my $fa, ">", "test_f_a"; |