diff options
author | Ron Yorston <rmy@pobox.com> | 2017-07-18 15:58:52 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-07-18 15:58:52 +0100 |
commit | b680f05ad449505e3d914bebd4c8d83bf768c094 (patch) | |
tree | c08ded13d430b0e7e0104f2eb594fad190ce98a3 /libbb/appletlib.c | |
parent | 258200ff81d5a9da54dab35acf36213eff1e399b (diff) | |
parent | 513a2457b65894b10b9fd6aa8753fca59eced08c (diff) | |
download | busybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.tar.gz busybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.tar.bz2 busybox-w32-b680f05ad449505e3d914bebd4c8d83bf768c094.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index a31a73e90..34b73afa5 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -78,6 +78,17 @@ | |||
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | 80 | ||
81 | unsigned FAST_FUNC string_array_len(char **argv) | ||
82 | { | ||
83 | char **start = argv; | ||
84 | |||
85 | while (*argv) | ||
86 | argv++; | ||
87 | |||
88 | return argv - start; | ||
89 | } | ||
90 | |||
91 | |||
81 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE | 92 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE |
82 | static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; | 93 | static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; |
83 | #else | 94 | #else |
@@ -675,8 +686,21 @@ static void check_suid(int applet_no) | |||
675 | if (geteuid()) | 686 | if (geteuid()) |
676 | bb_error_msg_and_die("must be suid to work properly"); | 687 | bb_error_msg_and_die("must be suid to work properly"); |
677 | } else if (APPLET_SUID(applet_no) == BB_SUID_DROP) { | 688 | } else if (APPLET_SUID(applet_no) == BB_SUID_DROP) { |
678 | xsetgid(rgid); /* drop all privileges */ | 689 | /* |
679 | xsetuid(ruid); | 690 | * Drop all privileges. |
691 | * | ||
692 | * Don't check for errors: in normal use, they are impossible, | ||
693 | * and in special cases, exiting is harmful. Example: | ||
694 | * 'unshare --user' when user's shell is also from busybox. | ||
695 | * | ||
696 | * 'unshare --user' creates a new user namespace without any | ||
697 | * uid mappings. Thus, busybox binary is setuid nobody:nogroup | ||
698 | * within the namespace, as that is the only user. However, | ||
699 | * since no uids are mapped, calls to setgid/setuid | ||
700 | * fail (even though they would do nothing). | ||
701 | */ | ||
702 | setgid(rgid); | ||
703 | setuid(ruid); | ||
680 | } | 704 | } |
681 | # if ENABLE_FEATURE_SUID_CONFIG | 705 | # if ENABLE_FEATURE_SUID_CONFIG |
682 | ret: ; | 706 | ret: ; |
@@ -919,16 +943,17 @@ static int busybox_main(char **argv) | |||
919 | # endif | 943 | # endif |
920 | 944 | ||
921 | # if NUM_APPLETS > 0 | 945 | # if NUM_APPLETS > 0 |
922 | void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | 946 | void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) |
923 | { | 947 | { |
924 | int argc = 1; | 948 | int argc = string_array_len(argv); |
925 | |||
926 | while (argv[argc]) | ||
927 | argc++; | ||
928 | 949 | ||
929 | /* Reinit some shared global data */ | 950 | /* Reinit some shared global data */ |
930 | xfunc_error_retval = EXIT_FAILURE; | 951 | xfunc_error_retval = EXIT_FAILURE; |
931 | applet_name = bb_get_last_path_component_nostrip(argv[0]); | 952 | /* |
953 | * We do not use argv[0]: do not want to repeat massaging of | ||
954 | * "-/sbin/halt" -> "halt", for example. | ||
955 | */ | ||
956 | applet_name = name; | ||
932 | 957 | ||
933 | /* Special case. POSIX says "test --help" | 958 | /* Special case. POSIX says "test --help" |
934 | * should be no different from e.g. "test --foo". | 959 | * should be no different from e.g. "test --foo". |
@@ -972,7 +997,7 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv) | |||
972 | { | 997 | { |
973 | int applet = find_applet_by_name(name); | 998 | int applet = find_applet_by_name(name); |
974 | if (applet >= 0) | 999 | if (applet >= 0) |
975 | run_applet_no_and_exit(applet, argv); | 1000 | run_applet_no_and_exit(applet, name, argv); |
976 | } | 1001 | } |
977 | # endif | 1002 | # endif |
978 | 1003 | ||
@@ -1058,7 +1083,11 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
1058 | } | 1083 | } |
1059 | /* applet_names in this case is just "applet\0\0" */ | 1084 | /* applet_names in this case is just "applet\0\0" */ |
1060 | lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); | 1085 | lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); |
1086 | # if ENABLE_BUILD_LIBBUSYBOX | ||
1087 | return SINGLE_APPLET_MAIN(string_array_len(argv), argv); | ||
1088 | # else | ||
1061 | return SINGLE_APPLET_MAIN(argc, argv); | 1089 | return SINGLE_APPLET_MAIN(argc, argv); |
1090 | # endif | ||
1062 | 1091 | ||
1063 | #elif !ENABLE_BUSYBOX && NUM_APPLETS == 0 | 1092 | #elif !ENABLE_BUSYBOX && NUM_APPLETS == 0 |
1064 | 1093 | ||