mirror of
https://github.com/sheumann/hush.git
synced 2024-08-26 12:29:04 +00:00
if only one applet is enabled, make "busybox applet [params]" work as expected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
714e2b7e6a
commit
8f0af3b001
@ -227,7 +227,7 @@ bool re_execed;
|
|||||||
|
|
||||||
IF_FEATURE_SUID(static uid_t ruid;) /* real uid */
|
IF_FEATURE_SUID(static uid_t ruid;) /* real uid */
|
||||||
|
|
||||||
#if ENABLE_FEATURE_SUID_CONFIG
|
# if ENABLE_FEATURE_SUID_CONFIG
|
||||||
|
|
||||||
/* applets[] is const, so we have to define this "override" structure */
|
/* applets[] is const, so we have to define this "override" structure */
|
||||||
static struct BB_suid_config {
|
static struct BB_suid_config {
|
||||||
@ -498,15 +498,15 @@ static void parse_config_file(void)
|
|||||||
sct_head = sct;
|
sct_head = sct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
static inline void parse_config_file(void)
|
static inline void parse_config_file(void)
|
||||||
{
|
{
|
||||||
IF_FEATURE_SUID(ruid = getuid();)
|
IF_FEATURE_SUID(ruid = getuid();)
|
||||||
}
|
}
|
||||||
#endif /* FEATURE_SUID_CONFIG */
|
# endif /* FEATURE_SUID_CONFIG */
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_SUID
|
# if ENABLE_FEATURE_SUID
|
||||||
static void check_suid(int applet_no)
|
static void check_suid(int applet_no)
|
||||||
{
|
{
|
||||||
gid_t rgid; /* real gid */
|
gid_t rgid; /* real gid */
|
||||||
@ -515,7 +515,7 @@ static void check_suid(int applet_no)
|
|||||||
return; /* run by root - no need to check more */
|
return; /* run by root - no need to check more */
|
||||||
rgid = getgid();
|
rgid = getgid();
|
||||||
|
|
||||||
#if ENABLE_FEATURE_SUID_CONFIG
|
# if ENABLE_FEATURE_SUID_CONFIG
|
||||||
if (suid_cfg_readable) {
|
if (suid_cfg_readable) {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
struct BB_suid_config *sct;
|
struct BB_suid_config *sct;
|
||||||
@ -558,7 +558,7 @@ static void check_suid(int applet_no)
|
|||||||
bb_perror_msg_and_die("setresuid");
|
bb_perror_msg_and_die("setresuid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if !ENABLE_FEATURE_SUID_CONFIG_QUIET
|
# if !ENABLE_FEATURE_SUID_CONFIG_QUIET
|
||||||
{
|
{
|
||||||
static bool onetime = 0;
|
static bool onetime = 0;
|
||||||
|
|
||||||
@ -567,9 +567,9 @@ static void check_suid(int applet_no)
|
|||||||
fprintf(stderr, "Using fallback suid method\n");
|
fprintf(stderr, "Using fallback suid method\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
# endif
|
||||||
check_need_suid:
|
check_need_suid:
|
||||||
#endif
|
# endif
|
||||||
if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) {
|
if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) {
|
||||||
/* Real uid is not 0. If euid isn't 0 too, suid bit
|
/* Real uid is not 0. If euid isn't 0 too, suid bit
|
||||||
* is most probably not set on our executable */
|
* is most probably not set on our executable */
|
||||||
@ -580,25 +580,24 @@ static void check_suid(int applet_no)
|
|||||||
xsetuid(ruid);
|
xsetuid(ruid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
#define check_suid(x) ((void)0)
|
# define check_suid(x) ((void)0)
|
||||||
#endif /* FEATURE_SUID */
|
# endif /* FEATURE_SUID */
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_INSTALLER
|
# if ENABLE_FEATURE_INSTALLER
|
||||||
static const char usr_bin [] ALIGN1 = "/usr/bin/";
|
static const char usr_bin [] ALIGN1 = "/usr/bin/";
|
||||||
static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
|
static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
|
||||||
static const char *const install_dir[] = {
|
static const char *const install_dir[] = {
|
||||||
&usr_bin [8], /* "/" */
|
&usr_bin [8], /* "/" */
|
||||||
&usr_bin [4], /* "/bin/" */
|
&usr_bin [4], /* "/bin/" */
|
||||||
&usr_sbin[4] /* "/sbin/" */
|
&usr_sbin[4] /* "/sbin/" */
|
||||||
# if !ENABLE_INSTALL_NO_USR
|
# if !ENABLE_INSTALL_NO_USR
|
||||||
,usr_bin
|
,usr_bin
|
||||||
,usr_sbin
|
,usr_sbin
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* create (sym)links for each applet */
|
/* create (sym)links for each applet */
|
||||||
static void install_links(const char *busybox, int use_symbolic_links,
|
static void install_links(const char *busybox, int use_symbolic_links,
|
||||||
char *custom_install_dir)
|
char *custom_install_dir)
|
||||||
@ -628,9 +627,9 @@ static void install_links(const char *busybox, int use_symbolic_links,
|
|||||||
free(fpc);
|
free(fpc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
# define install_links(x,y,z) ((void)0)
|
# define install_links(x,y,z) ((void)0)
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
/* If we were called as "busybox..." */
|
/* If we were called as "busybox..." */
|
||||||
static int busybox_main(char **argv)
|
static int busybox_main(char **argv)
|
||||||
@ -695,10 +694,10 @@ static int busybox_main(char **argv)
|
|||||||
const char *a = applet_names;
|
const char *a = applet_names;
|
||||||
dup2(1, 2);
|
dup2(1, 2);
|
||||||
while (*a) {
|
while (*a) {
|
||||||
#if ENABLE_FEATURE_INSTALLER
|
# if ENABLE_FEATURE_INSTALLER
|
||||||
if (argv[1][6]) /* --list-path? */
|
if (argv[1][6]) /* --list-path? */
|
||||||
full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
|
full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
|
||||||
#endif
|
# endif
|
||||||
full_write2_str(a);
|
full_write2_str(a);
|
||||||
full_write2_str("\n");
|
full_write2_str("\n");
|
||||||
i++;
|
i++;
|
||||||
@ -771,7 +770,7 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
|
|||||||
int applet = find_applet_by_name(name);
|
int applet = find_applet_by_name(name);
|
||||||
if (applet >= 0)
|
if (applet >= 0)
|
||||||
run_applet_no_and_exit(applet, argv);
|
run_applet_no_and_exit(applet, argv);
|
||||||
if (!strncmp(name, "busybox", 7))
|
if (strncmp(name, "busybox", 7) == 0)
|
||||||
exit(busybox_main(argv));
|
exit(busybox_main(argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,14 +802,6 @@ int main(int argc UNUSED_PARAM, char **argv)
|
|||||||
mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256);
|
mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SINGLE_APPLET_MAIN)
|
|
||||||
/* Only one applet is selected by the user! */
|
|
||||||
/* applet_names in this case is just "applet\0\0" */
|
|
||||||
lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv));
|
|
||||||
return SINGLE_APPLET_MAIN(argc, argv);
|
|
||||||
#else
|
|
||||||
lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
|
|
||||||
|
|
||||||
#if !BB_MMU
|
#if !BB_MMU
|
||||||
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
||||||
if (argv[0][0] & 0x80) {
|
if (argv[0][0] & 0x80) {
|
||||||
@ -818,6 +809,19 @@ int main(int argc UNUSED_PARAM, char **argv)
|
|||||||
argv[0][0] &= 0x7f;
|
argv[0][0] &= 0x7f;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SINGLE_APPLET_MAIN)
|
||||||
|
/* Only one applet is selected in .config */
|
||||||
|
if (strncmp(argv[0], "busybox", 7) == 0) {
|
||||||
|
/* "busybox <applet> <params>" should still work as expected */
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
/* applet_names in this case is just "applet\0\0" */
|
||||||
|
lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv));
|
||||||
|
return SINGLE_APPLET_MAIN(argc, argv);
|
||||||
|
#else
|
||||||
|
lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
|
||||||
|
|
||||||
applet_name = argv[0];
|
applet_name = argv[0];
|
||||||
if (applet_name[0] == '-')
|
if (applet_name[0] == '-')
|
||||||
applet_name++;
|
applet_name++;
|
||||||
|
Loading…
Reference in New Issue
Block a user