#include "usage_compressed.h"
-#if ENABLE_ASH_EMBEDDED_SCRIPTS
-# define DEFINE_script_names 1
+#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS
+# define DEFINE_SCRIPT_DATA 1
# include "embedded_scripts.h"
#else
# define NUM_SCRIPTS 0
{
if (ENABLE_SHOW_USAGE) {
#ifdef SINGLE_APPLET_STR
- /* Imagine that this applet is "true". Dont suck in printf! */
+ /* Imagine that this applet is "true". Dont link in printf! */
const char *usage_string = unpack_usage_messages();
if (usage_string) {
if (*usage_string == '\b') {
- full_write2_str("No help available.\n\n");
+ full_write2_str("No help available\n");
} else {
full_write2_str("Usage: "SINGLE_APPLET_STR" ");
full_write2_str(usage_string);
- full_write2_str("\n\n");
+ full_write2_str("\n");
}
if (ENABLE_FEATURE_CLEAN_UP)
dealloc_usage_messages((char*)usage_string);
ap--;
}
full_write2_str(bb_banner);
- full_write2_str(" multi-call binary.\n");
+ full_write2_str(" multi-call binary.\n"); /* common string */
if (*p == '\b')
- full_write2_str("\nNo help available.\n\n");
+ full_write2_str("\nNo help available\n");
else {
full_write2_str("\nUsage: ");
full_write2_str(applet_name);
IF_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef __GLIBC__
- (*(int **)&bb_errno) = __errno_location();
+ (*(int **)not_const_pp(&bb_errno)) = __errno_location();
barrier();
#endif
applet_name = applet;
/* same group / in group */
m >>= 3;
if (!(m & S_IXOTH)) /* is x bit not set? */
- bb_error_msg_and_die("you have no permission to run this applet");
+ bb_simple_error_msg_and_die("you have no permission to run this applet");
/* We set effective AND saved ids. If saved-id is not set
* like we do below, seteuid(0) can still later succeed! */
rgid = sct->m_ugid.gid;
/* else: we will set egid = rgid, thus dropping sgid effect */
if (setresgid(-1, rgid, rgid))
- bb_perror_msg_and_die("setresgid");
+ bb_simple_perror_msg_and_die("setresgid");
/* Are we directed to change uid
* (APPLET = s** USER.GROUP or APPLET = S** USER.GROUP)?
uid = sct->m_ugid.uid;
/* else: we will set euid = ruid, thus dropping suid effect */
if (setresuid(-1, uid, uid))
- bb_perror_msg_and_die("setresuid");
+ bb_simple_perror_msg_and_die("setresuid");
goto ret;
}
if (!onetime) {
onetime = 1;
- bb_error_msg("using fallback suid method");
+ bb_simple_error_msg("using fallback suid method");
}
}
# endif
/* Real uid is not 0. If euid isn't 0 too, suid bit
* is most probably not set on our executable */
if (geteuid())
- bb_error_msg_and_die("must be suid to work properly");
+ bb_simple_error_msg_and_die("must be suid to work properly");
} else if (APPLET_SUID(applet_no) == BB_SUID_DROP) {
/*
* Drop all privileges.
static void run_applet_and_exit(const char *name, char **argv) NORETURN;
+# if NUM_SCRIPTS > 0
+static int find_script_by_name(const char *name)
+{
+ int i;
+ int applet = find_applet_by_name(name);
+
+ if (applet >= 0) {
+ for (i = 0; i < NUM_SCRIPTS; ++i)
+ if (applet_numbers[i] == applet)
+ return i;
+ }
+ return -1;
+}
+
+int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int scripted_main(int argc UNUSED_PARAM, char **argv)
+{
+ int script = find_script_by_name(applet_name);
+ if (script >= 0)
+#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH
+ exit(ash_main(-script - 1, argv));
+#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH
+ exit(hush_main(-script - 1, argv));
+#else
+ return 1;
+#endif
+ return 0;
+}
+
+char* FAST_FUNC
+get_script_content(unsigned n)
+{
+ char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
+ UNPACKED_SCRIPTS_LENGTH);
+ if (t) {
+ while (n != 0) {
+ while (*t++ != '\0')
+ continue;
+ n--;
+ }
+ }
+ return t;
+}
+# endif /* NUM_SCRIPTS > 0 */
+
# if ENABLE_BUSYBOX
# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
/*
"\n"
"Usage: busybox [function [arguments]...]\n"
" or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
+# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
+ " or: busybox --show SCRIPT\n"
+# endif
IF_FEATURE_INSTALLER(
" or: busybox --install [-s] [DIR]\n"
)
/* prevent last comma to be in the very last pos */
output_width--;
a = applet_names;
- {
-# if NUM_SCRIPTS > 0
- int i;
- for (i = 0; i < 2; i++, a = script_names)
-# endif
- while (*a) {
- int len2 = strlen(a) + 2;
- if (col >= (int)output_width - len2) {
- full_write2_str(",\n");
- col = 0;
- }
- if (col == 0) {
- col = 6;
- full_write2_str("\t");
- } else {
- full_write2_str(", ");
- }
- full_write2_str(a);
- col += len2;
- a += len2 - 1;
+ while (*a) {
+ int len2 = strlen(a) + 2;
+ if (col >= (int)output_width - len2) {
+ full_write2_str(",\n");
+ col = 0;
}
+ if (col == 0) {
+ col = 6;
+ full_write2_str("\t");
+ } else {
+ full_write2_str(", ");
+ }
+ full_write2_str(a);
+ col += len2;
+ a += len2 - 1;
}
full_write2_str("\n");
return 0;
}
+# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
+ if (strcmp(argv[1], "--show") == 0) {
+ int n;
+ if (!argv[2])
+ bb_error_msg_and_die(bb_msg_requires_arg, "--show");
+ n = find_script_by_name(argv[2]);
+ if (n < 0)
+ bb_error_msg_and_die("script '%s' not found", argv[2]);
+ full_write1_str(get_script_content(n));
+ return 0;
+ }
+# endif
+
if (is_prefixed_with(argv[1], "--list")) {
unsigned i = 0;
const char *a = applet_names;
}
# endif /* NUM_APPLETS > 0 */
-# if NUM_SCRIPTS > 0
-int FAST_FUNC
-find_script_by_name(const char *name)
-{
- const char *s = script_names;
- int i = 0;
-
- while (*s) {
- if (strcmp(name, s) == 0)
- return i;
- i++;
- while (*s++ != '\0')
- continue;
- }
- return -0x10000; /* make it so that NUM_APPLETS + <error> is still < 0 */
-}
-
-char* FAST_FUNC
-get_script_content(unsigned n)
-{
- char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
- UNPACKED_SCRIPTS_LENGTH);
- if (t) {
- while (n != 0) {
- while (*t++ != '\0')
- continue;
- n--;
- }
- }
- return t;
-}
-# endif /* NUM_SCRIPTS > 0 */
-
-# if ENABLE_BUSYBOX || NUM_APPLETS > 0 || NUM_SCRIPTS > 0
+# if ENABLE_BUSYBOX || NUM_APPLETS > 0
static NORETURN void run_applet_and_exit(const char *name, char **argv)
{
# if ENABLE_BUSYBOX
run_applet_no_and_exit(applet, name, argv);
}
# endif
-# if NUM_SCRIPTS > 0
- {
- int script = find_script_by_name(name);
- if (script >= 0)
- exit(ash_main(-script - 1, argv));
- }
-# endif
/*bb_error_msg_and_die("applet not found"); - links in printf */
full_write2_str(applet_name);