libbb: simplify parameter passing in is_in_supplementary_groups()
function old new delta is_in_supplementary_groups 54 52 -2 nexpr 721 718 -3 test_exec 125 119 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-11) Total: -11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
860b3d066f
commit
4c1d645c86
4 changed files with 33 additions and 19 deletions
|
@ -426,8 +426,7 @@ struct test_statics {
|
||||||
/* set only by check_operator(), either to bogus struct
|
/* set only by check_operator(), either to bogus struct
|
||||||
* or points to matching operator_t struct. Never NULL. */
|
* or points to matching operator_t struct. Never NULL. */
|
||||||
const struct operator_t *last_operator;
|
const struct operator_t *last_operator;
|
||||||
gid_t *group_array;
|
struct cached_groupinfo groupinfo;
|
||||||
int ngroups;
|
|
||||||
#if BASH_TEST2
|
#if BASH_TEST2
|
||||||
bool bash_test2;
|
bool bash_test2;
|
||||||
#endif
|
#endif
|
||||||
|
@ -440,8 +439,7 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
|
||||||
#define S (*test_ptr_to_statics)
|
#define S (*test_ptr_to_statics)
|
||||||
#define args (S.args )
|
#define args (S.args )
|
||||||
#define last_operator (S.last_operator)
|
#define last_operator (S.last_operator)
|
||||||
#define group_array (S.group_array )
|
#define groupinfo (S.groupinfo )
|
||||||
#define ngroups (S.ngroups )
|
|
||||||
#define bash_test2 (S.bash_test2 )
|
#define bash_test2 (S.bash_test2 )
|
||||||
#define leaving (S.leaving )
|
#define leaving (S.leaving )
|
||||||
|
|
||||||
|
@ -449,7 +447,7 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
|
||||||
XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \
|
XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define DEINIT_S() do { \
|
#define DEINIT_S() do { \
|
||||||
free(group_array); \
|
free(groupinfo.supplementary_array); \
|
||||||
free(test_ptr_to_statics); \
|
free(test_ptr_to_statics); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -644,7 +642,7 @@ static int is_a_group_member(gid_t gid)
|
||||||
if (gid == getgid() || gid == getegid())
|
if (gid == getgid() || gid == getegid())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return is_in_supplementary_groups(&ngroups, &group_array, gid);
|
return is_in_supplementary_groups(&groupinfo, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -654,8 +652,20 @@ static int is_a_group_member(gid_t gid)
|
||||||
*/
|
*/
|
||||||
static int test_st_mode(struct stat *st, int mode)
|
static int test_st_mode(struct stat *st, int mode)
|
||||||
{
|
{
|
||||||
unsigned int euid = geteuid();
|
enum { ANY_IX = S_IXUSR | S_IXGRP | S_IXOTH };
|
||||||
|
unsigned euid;
|
||||||
|
|
||||||
|
//TODO if (mode == X_OK) {
|
||||||
|
// /* Do we already know with no extra syscalls? */
|
||||||
|
// if (!S_ISREG(st->st_mode))
|
||||||
|
// return 0; /* not a regular file */
|
||||||
|
// if ((st->st_mode & ANY_IX) == 0)
|
||||||
|
// return 0; /* no one can execute */
|
||||||
|
// if ((st->st_mode & ANY_IX) == ANY_IX)
|
||||||
|
// return 1; /* anyone can execute */
|
||||||
|
// }
|
||||||
|
|
||||||
|
euid = geteuid();
|
||||||
if (euid == 0) {
|
if (euid == 0) {
|
||||||
/* Root can read or write any file. */
|
/* Root can read or write any file. */
|
||||||
if (mode != X_OK)
|
if (mode != X_OK)
|
||||||
|
|
|
@ -1203,9 +1203,15 @@ void die_if_bad_username(const char* name) FAST_FUNC;
|
||||||
gid_t *bb_getgroups(int *ngroups, gid_t *group_array) FAST_FUNC;
|
gid_t *bb_getgroups(int *ngroups, gid_t *group_array) FAST_FUNC;
|
||||||
/*
|
/*
|
||||||
* True if GID is in our getgroups() result.
|
* True if GID is in our getgroups() result.
|
||||||
* getgroups() is cached in group_array[], to makse successive calls faster.
|
* getgroups() is cached in supplementary_array[], to make successive calls faster.
|
||||||
*/
|
*/
|
||||||
int FAST_FUNC is_in_supplementary_groups(int *pngroups, gid_t **pgroup_array, gid_t gid);
|
struct cached_groupinfo {
|
||||||
|
//TODO? gid_t egid;
|
||||||
|
int ngroups;
|
||||||
|
gid_t *supplementary_array;
|
||||||
|
};
|
||||||
|
//TODO? int FAST_FUNC get_cached_egid(gid_t *egid);
|
||||||
|
int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid);
|
||||||
|
|
||||||
#if ENABLE_FEATURE_UTMP
|
#if ENABLE_FEATURE_UTMP
|
||||||
void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
|
void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
|
||||||
|
|
|
@ -47,16 +47,16 @@ gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return non-zero if GID is in our supplementary group list. */
|
/* Return non-zero if GID is in our supplementary group list. */
|
||||||
int FAST_FUNC is_in_supplementary_groups(int *pngroups, gid_t **pgroup_array, gid_t gid)
|
int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int ngroups;
|
int ngroups;
|
||||||
gid_t *group_array;
|
gid_t *group_array;
|
||||||
|
|
||||||
if (*pngroups == 0)
|
if (groupinfo->ngroups == 0)
|
||||||
*pgroup_array = bb_getgroups(pngroups, NULL);
|
groupinfo->supplementary_array = bb_getgroups(&groupinfo->ngroups, NULL);
|
||||||
ngroups = *pngroups;
|
ngroups = groupinfo->ngroups;
|
||||||
group_array = *pgroup_array;
|
group_array = groupinfo->supplementary_array;
|
||||||
|
|
||||||
/* Search through the list looking for GID. */
|
/* Search through the list looking for GID. */
|
||||||
for (i = 0; i < ngroups; i++)
|
for (i = 0; i < ngroups; i++)
|
||||||
|
|
|
@ -493,8 +493,7 @@ struct globals_misc {
|
||||||
/* Rarely referenced stuff */
|
/* Rarely referenced stuff */
|
||||||
|
|
||||||
/* Cached supplementary group array (for testing executable'ity of files) */
|
/* Cached supplementary group array (for testing executable'ity of files) */
|
||||||
int ngroups;
|
struct cached_groupinfo groupinfo;
|
||||||
gid_t *group_array;
|
|
||||||
|
|
||||||
#if ENABLE_ASH_RANDOM_SUPPORT
|
#if ENABLE_ASH_RANDOM_SUPPORT
|
||||||
random_t random_gen;
|
random_t random_gen;
|
||||||
|
@ -528,8 +527,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
|
||||||
#define may_have_traps (G_misc.may_have_traps )
|
#define may_have_traps (G_misc.may_have_traps )
|
||||||
#define trap (G_misc.trap )
|
#define trap (G_misc.trap )
|
||||||
#define trap_ptr (G_misc.trap_ptr )
|
#define trap_ptr (G_misc.trap_ptr )
|
||||||
#define ngroups (G_misc.ngroups )
|
#define groupinfo (G_misc.groupinfo )
|
||||||
#define group_array (G_misc.group_array)
|
|
||||||
#define random_gen (G_misc.random_gen )
|
#define random_gen (G_misc.random_gen )
|
||||||
#define backgndpid (G_misc.backgndpid )
|
#define backgndpid (G_misc.backgndpid )
|
||||||
#define INIT_G_misc() do { \
|
#define INIT_G_misc() do { \
|
||||||
|
@ -13821,7 +13819,7 @@ static int test_exec(/*const char *fullname,*/ struct stat *statb)
|
||||||
stmode = S_IXUSR;
|
stmode = S_IXUSR;
|
||||||
else if (statb->st_gid == getegid())
|
else if (statb->st_gid == getegid())
|
||||||
stmode = S_IXGRP;
|
stmode = S_IXGRP;
|
||||||
else if (is_in_supplementary_groups(&ngroups, &group_array, statb->st_gid))
|
else if (is_in_supplementary_groups(&groupinfo, statb->st_gid))
|
||||||
stmode = S_IXGRP;
|
stmode = S_IXGRP;
|
||||||
|
|
||||||
return statb->st_mode & stmode;
|
return statb->st_mode & stmode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue