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 */
static struct BB_suid_config {
sct_head = sct;
}
}
-#else
+# else
static inline void parse_config_file(void)
{
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)
{
gid_t rgid; /* real gid */
return; /* run by root - no need to check more */
rgid = getgid();
-#if ENABLE_FEATURE_SUID_CONFIG
+# if ENABLE_FEATURE_SUID_CONFIG
if (suid_cfg_readable) {
uid_t uid;
struct BB_suid_config *sct;
bb_perror_msg_and_die("setresuid");
return;
}
-#if !ENABLE_FEATURE_SUID_CONFIG_QUIET
+# if !ENABLE_FEATURE_SUID_CONFIG_QUIET
{
static bool onetime = 0;
fprintf(stderr, "Using fallback suid method\n");
}
}
-#endif
+# endif
check_need_suid:
-#endif
+# endif
if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) {
/* Real uid is not 0. If euid isn't 0 too, suid bit
* is most probably not set on our executable */
xsetuid(ruid);
}
}
-#else
-#define check_suid(x) ((void)0)
-#endif /* FEATURE_SUID */
+# else
+# define check_suid(x) ((void)0)
+# endif /* FEATURE_SUID */
-#if ENABLE_FEATURE_INSTALLER
+# if ENABLE_FEATURE_INSTALLER
static const char usr_bin [] ALIGN1 = "/usr/bin/";
static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
static const char *const install_dir[] = {
&usr_bin [8], /* "/" */
&usr_bin [4], /* "/bin/" */
&usr_sbin[4] /* "/sbin/" */
-# if !ENABLE_INSTALL_NO_USR
+# if !ENABLE_INSTALL_NO_USR
,usr_bin
,usr_sbin
-# endif
+# endif
};
-
/* create (sym)links for each applet */
static void install_links(const char *busybox, int use_symbolic_links,
char *custom_install_dir)
free(fpc);
}
}
-#else
-# define install_links(x,y,z) ((void)0)
-#endif
+# else
+# define install_links(x,y,z) ((void)0)
+# endif
/* If we were called as "busybox..." */
static int busybox_main(char **argv)
const char *a = applet_names;
dup2(1, 2);
while (*a) {
-#if ENABLE_FEATURE_INSTALLER
+# if ENABLE_FEATURE_INSTALLER
if (argv[1][6]) /* --list-path? */
full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
-#endif
+# endif
full_write2_str(a);
full_write2_str("\n");
i++;
int applet = find_applet_by_name(name);
if (applet >= 0)
run_applet_no_and_exit(applet, argv);
- if (!strncmp(name, "busybox", 7))
+ if (strncmp(name, "busybox", 7) == 0)
exit(busybox_main(argv));
}
mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256);
#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
/* NOMMU re-exec trick sets high-order bit in first byte of name */
if (argv[0][0] & 0x80) {
argv[0][0] &= 0x7f;
}
#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];
if (applet_name[0] == '-')
applet_name++;