diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-06 19:24:06 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-06 19:25:07 +0200 |
| commit | bb5525613ec109aa30d2cb1db84e18aa0b084576 (patch) | |
| tree | 7a2689181130996ba91fef597289cbfde89d6e19 /coreutils | |
| parent | 222802e83362eabd4c631897ff7db5e85955d7c5 (diff) | |
| download | busybox-w32-bb5525613ec109aa30d2cb1db84e18aa0b084576.tar.gz busybox-w32-bb5525613ec109aa30d2cb1db84e18aa0b084576.tar.bz2 busybox-w32-bb5525613ec109aa30d2cb1db84e18aa0b084576.zip | |
test: Invert return value of test_eaccess and rename it to test_st_mode
From dash:
From: herbert <herbert@gondor.apana.org.au>
Date: Wed, 2 Mar 2005 22:14:54 +1100
Invert return value of test_eaccess and rename it to test_st_mode.
function old new delta
nexpr 800 766 -34
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/test.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index 7df7d0fc8..c02c92745 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
| @@ -665,34 +665,29 @@ static int is_a_group_member(gid_t gid) | |||
| 665 | return 0; | 665 | return 0; |
| 666 | } | 666 | } |
| 667 | 667 | ||
| 668 | 668 | /* | |
| 669 | /* Do the same thing access(2) does, but use the effective uid and gid, | 669 | * Similar to what access(2) does, but uses the effective uid and gid. |
| 670 | and don't make the mistake of telling root that any file is | 670 | * Doesn't make the mistake of telling root that any file is executable. |
| 671 | executable. */ | 671 | * Returns non-zero if the file is accessible. |
| 672 | static int test_eaccess(struct stat *st, int mode) | 672 | */ |
| 673 | static int test_st_mode(struct stat *st, int mode) | ||
| 673 | { | 674 | { |
| 674 | unsigned int euid = geteuid(); | 675 | unsigned int euid = geteuid(); |
| 675 | 676 | ||
| 676 | if (euid == 0) { | 677 | if (euid == 0) { |
| 677 | /* Root can read or write any file. */ | 678 | /* Root can read or write any file. */ |
| 678 | if (mode != X_OK) | 679 | if (mode != X_OK) |
| 679 | return 0; | 680 | return 1; |
| 680 | 681 | ||
| 681 | /* Root can execute any file that has any one of the execute | 682 | /* Root can execute any file that has any one of the execute |
| 682 | * bits set. */ | 683 | * bits set. */ |
| 683 | if (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) | 684 | mode = S_IXUSR | S_IXGRP | S_IXOTH; |
| 684 | return 0; | 685 | } else if (st->st_uid == euid) /* owner */ |
| 685 | } | ||
| 686 | |||
| 687 | if (st->st_uid == euid) /* owner */ | ||
| 688 | mode <<= 6; | 686 | mode <<= 6; |
| 689 | else if (is_a_group_member(st->st_gid)) | 687 | else if (is_a_group_member(st->st_gid)) |
| 690 | mode <<= 3; | 688 | mode <<= 3; |
| 691 | 689 | ||
| 692 | if (st->st_mode & mode) | 690 | return st->st_mode & mode; |
| 693 | return 0; | ||
| 694 | |||
| 695 | return -1; | ||
| 696 | } | 691 | } |
| 697 | 692 | ||
| 698 | 693 | ||
| @@ -722,7 +717,7 @@ static int filstat(char *nm, enum token mode) | |||
| 722 | i = W_OK; | 717 | i = W_OK; |
| 723 | if (mode == FILEX) | 718 | if (mode == FILEX) |
| 724 | i = X_OK; | 719 | i = X_OK; |
| 725 | return test_eaccess(&s, i) == 0; | 720 | return test_st_mode(&s, i); |
| 726 | } | 721 | } |
| 727 | if (is_file_type(mode)) { | 722 | if (is_file_type(mode)) { |
| 728 | if (mode == FILREG) | 723 | if (mode == FILREG) |
