aboutsummaryrefslogtreecommitdiff
path: root/coreutils/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/test.c')
-rw-r--r--coreutils/test.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 874285704..96462d3a2 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -426,8 +426,7 @@ struct test_statics {
426 /* set only by check_operator(), either to bogus struct 426 /* set only by check_operator(), either to bogus struct
427 * or points to matching operator_t struct. Never NULL. */ 427 * or points to matching operator_t struct. Never NULL. */
428 const struct operator_t *last_operator; 428 const struct operator_t *last_operator;
429 gid_t *group_array; 429 struct cached_groupinfo groupinfo;
430 int ngroups;
431#if BASH_TEST2 430#if BASH_TEST2
432 bool bash_test2; 431 bool bash_test2;
433#endif 432#endif
@@ -440,8 +439,7 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
440#define S (*test_ptr_to_statics) 439#define S (*test_ptr_to_statics)
441#define args (S.args ) 440#define args (S.args )
442#define last_operator (S.last_operator) 441#define last_operator (S.last_operator)
443#define group_array (S.group_array ) 442#define groupinfo (S.groupinfo )
444#define ngroups (S.ngroups )
445#define bash_test2 (S.bash_test2 ) 443#define bash_test2 (S.bash_test2 )
446#define leaving (S.leaving ) 444#define leaving (S.leaving )
447 445
@@ -449,7 +447,7 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
449 XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \ 447 XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \
450} while (0) 448} while (0)
451#define DEINIT_S() do { \ 449#define DEINIT_S() do { \
452 free(group_array); \ 450 free(groupinfo.supplementary_array); \
453 free(test_ptr_to_statics); \ 451 free(test_ptr_to_statics); \
454} while (0) 452} while (0)
455 453
@@ -644,7 +642,7 @@ static int is_a_group_member(gid_t gid)
644 if (gid == getgid() || gid == getegid()) 642 if (gid == getgid() || gid == getegid())
645 return 1; 643 return 1;
646 644
647 return is_in_supplementary_groups(&ngroups, &group_array, gid); 645 return is_in_supplementary_groups(&groupinfo, gid);
648} 646}
649 647
650/* 648/*
@@ -654,8 +652,20 @@ static int is_a_group_member(gid_t gid)
654 */ 652 */
655static int test_st_mode(struct stat *st, int mode) 653static int test_st_mode(struct stat *st, int mode)
656{ 654{
657 unsigned int euid = geteuid(); 655 enum { ANY_IX = S_IXUSR | S_IXGRP | S_IXOTH };
658 656 unsigned euid;
657
658//TODO if (mode == X_OK) {
659// /* Do we already know with no extra syscalls? */
660// if (!S_ISREG(st->st_mode))
661// return 0; /* not a regular file */
662// if ((st->st_mode & ANY_IX) == 0)
663// return 0; /* no one can execute */
664// if ((st->st_mode & ANY_IX) == ANY_IX)
665// return 1; /* anyone can execute */
666// }
667
668 euid = geteuid();
659 if (euid == 0) { 669 if (euid == 0) {
660 /* Root can read or write any file. */ 670 /* Root can read or write any file. */
661 if (mode != X_OK) 671 if (mode != X_OK)