diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-11-29 02:55:35 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-11-29 02:55:35 +0100 |
commit | 8f0af3b0013156b8aa3bae802af5e33c3a440915 (patch) | |
tree | 289ef5095c4046e2eb511a1e71fa51f30a9a9a03 /libbb/appletlib.c | |
parent | 714e2b7e6ab9cef6cb853c52b6c128d390964a25 (diff) | |
download | busybox-w32-8f0af3b0013156b8aa3bae802af5e33c3a440915.tar.gz busybox-w32-8f0af3b0013156b8aa3bae802af5e33c3a440915.tar.bz2 busybox-w32-8f0af3b0013156b8aa3bae802af5e33c3a440915.zip |
if only one applet is enabled, make "busybox applet [params]" work as expected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index c417a270d..c65180c5e 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -227,7 +227,7 @@ bool re_execed; | |||
227 | 227 | ||
228 | IF_FEATURE_SUID(static uid_t ruid;) /* real uid */ | 228 | IF_FEATURE_SUID(static uid_t ruid;) /* real uid */ |
229 | 229 | ||
230 | #if ENABLE_FEATURE_SUID_CONFIG | 230 | # if ENABLE_FEATURE_SUID_CONFIG |
231 | 231 | ||
232 | /* applets[] is const, so we have to define this "override" structure */ | 232 | /* applets[] is const, so we have to define this "override" structure */ |
233 | static struct BB_suid_config { | 233 | static struct BB_suid_config { |
@@ -498,15 +498,15 @@ static void parse_config_file(void) | |||
498 | sct_head = sct; | 498 | sct_head = sct; |
499 | } | 499 | } |
500 | } | 500 | } |
501 | #else | 501 | # else |
502 | static inline void parse_config_file(void) | 502 | static inline void parse_config_file(void) |
503 | { | 503 | { |
504 | IF_FEATURE_SUID(ruid = getuid();) | 504 | IF_FEATURE_SUID(ruid = getuid();) |
505 | } | 505 | } |
506 | #endif /* FEATURE_SUID_CONFIG */ | 506 | # endif /* FEATURE_SUID_CONFIG */ |
507 | 507 | ||
508 | 508 | ||
509 | #if ENABLE_FEATURE_SUID | 509 | # if ENABLE_FEATURE_SUID |
510 | static void check_suid(int applet_no) | 510 | static void check_suid(int applet_no) |
511 | { | 511 | { |
512 | gid_t rgid; /* real gid */ | 512 | gid_t rgid; /* real gid */ |
@@ -515,7 +515,7 @@ static void check_suid(int applet_no) | |||
515 | return; /* run by root - no need to check more */ | 515 | return; /* run by root - no need to check more */ |
516 | rgid = getgid(); | 516 | rgid = getgid(); |
517 | 517 | ||
518 | #if ENABLE_FEATURE_SUID_CONFIG | 518 | # if ENABLE_FEATURE_SUID_CONFIG |
519 | if (suid_cfg_readable) { | 519 | if (suid_cfg_readable) { |
520 | uid_t uid; | 520 | uid_t uid; |
521 | struct BB_suid_config *sct; | 521 | struct BB_suid_config *sct; |
@@ -558,7 +558,7 @@ static void check_suid(int applet_no) | |||
558 | bb_perror_msg_and_die("setresuid"); | 558 | bb_perror_msg_and_die("setresuid"); |
559 | return; | 559 | return; |
560 | } | 560 | } |
561 | #if !ENABLE_FEATURE_SUID_CONFIG_QUIET | 561 | # if !ENABLE_FEATURE_SUID_CONFIG_QUIET |
562 | { | 562 | { |
563 | static bool onetime = 0; | 563 | static bool onetime = 0; |
564 | 564 | ||
@@ -567,9 +567,9 @@ static void check_suid(int applet_no) | |||
567 | fprintf(stderr, "Using fallback suid method\n"); | 567 | fprintf(stderr, "Using fallback suid method\n"); |
568 | } | 568 | } |
569 | } | 569 | } |
570 | #endif | 570 | # endif |
571 | check_need_suid: | 571 | check_need_suid: |
572 | #endif | 572 | # endif |
573 | if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) { | 573 | if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) { |
574 | /* Real uid is not 0. If euid isn't 0 too, suid bit | 574 | /* Real uid is not 0. If euid isn't 0 too, suid bit |
575 | * is most probably not set on our executable */ | 575 | * is most probably not set on our executable */ |
@@ -580,25 +580,24 @@ static void check_suid(int applet_no) | |||
580 | xsetuid(ruid); | 580 | xsetuid(ruid); |
581 | } | 581 | } |
582 | } | 582 | } |
583 | #else | 583 | # else |
584 | #define check_suid(x) ((void)0) | 584 | # define check_suid(x) ((void)0) |
585 | #endif /* FEATURE_SUID */ | 585 | # endif /* FEATURE_SUID */ |
586 | 586 | ||
587 | 587 | ||
588 | #if ENABLE_FEATURE_INSTALLER | 588 | # if ENABLE_FEATURE_INSTALLER |
589 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; | 589 | static const char usr_bin [] ALIGN1 = "/usr/bin/"; |
590 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; | 590 | static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; |
591 | static const char *const install_dir[] = { | 591 | static const char *const install_dir[] = { |
592 | &usr_bin [8], /* "/" */ | 592 | &usr_bin [8], /* "/" */ |
593 | &usr_bin [4], /* "/bin/" */ | 593 | &usr_bin [4], /* "/bin/" */ |
594 | &usr_sbin[4] /* "/sbin/" */ | 594 | &usr_sbin[4] /* "/sbin/" */ |
595 | # if !ENABLE_INSTALL_NO_USR | 595 | # if !ENABLE_INSTALL_NO_USR |
596 | ,usr_bin | 596 | ,usr_bin |
597 | ,usr_sbin | 597 | ,usr_sbin |
598 | # endif | 598 | # endif |
599 | }; | 599 | }; |
600 | 600 | ||
601 | |||
602 | /* create (sym)links for each applet */ | 601 | /* create (sym)links for each applet */ |
603 | static void install_links(const char *busybox, int use_symbolic_links, | 602 | static void install_links(const char *busybox, int use_symbolic_links, |
604 | char *custom_install_dir) | 603 | char *custom_install_dir) |
@@ -628,9 +627,9 @@ static void install_links(const char *busybox, int use_symbolic_links, | |||
628 | free(fpc); | 627 | free(fpc); |
629 | } | 628 | } |
630 | } | 629 | } |
631 | #else | 630 | # else |
632 | # define install_links(x,y,z) ((void)0) | 631 | # define install_links(x,y,z) ((void)0) |
633 | #endif | 632 | # endif |
634 | 633 | ||
635 | /* If we were called as "busybox..." */ | 634 | /* If we were called as "busybox..." */ |
636 | static int busybox_main(char **argv) | 635 | static int busybox_main(char **argv) |
@@ -695,10 +694,10 @@ static int busybox_main(char **argv) | |||
695 | const char *a = applet_names; | 694 | const char *a = applet_names; |
696 | dup2(1, 2); | 695 | dup2(1, 2); |
697 | while (*a) { | 696 | while (*a) { |
698 | #if ENABLE_FEATURE_INSTALLER | 697 | # if ENABLE_FEATURE_INSTALLER |
699 | if (argv[1][6]) /* --list-path? */ | 698 | if (argv[1][6]) /* --list-path? */ |
700 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 699 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
701 | #endif | 700 | # endif |
702 | full_write2_str(a); | 701 | full_write2_str(a); |
703 | full_write2_str("\n"); | 702 | full_write2_str("\n"); |
704 | i++; | 703 | i++; |
@@ -771,7 +770,7 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv) | |||
771 | int applet = find_applet_by_name(name); | 770 | int applet = find_applet_by_name(name); |
772 | if (applet >= 0) | 771 | if (applet >= 0) |
773 | run_applet_no_and_exit(applet, argv); | 772 | run_applet_no_and_exit(applet, argv); |
774 | if (!strncmp(name, "busybox", 7)) | 773 | if (strncmp(name, "busybox", 7) == 0) |
775 | exit(busybox_main(argv)); | 774 | exit(busybox_main(argv)); |
776 | } | 775 | } |
777 | 776 | ||
@@ -803,14 +802,6 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
803 | mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256); | 802 | mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256); |
804 | #endif | 803 | #endif |
805 | 804 | ||
806 | #if defined(SINGLE_APPLET_MAIN) | ||
807 | /* Only one applet is selected by the user! */ | ||
808 | /* applet_names in this case is just "applet\0\0" */ | ||
809 | lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); | ||
810 | return SINGLE_APPLET_MAIN(argc, argv); | ||
811 | #else | ||
812 | lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); | ||
813 | |||
814 | #if !BB_MMU | 805 | #if !BB_MMU |
815 | /* NOMMU re-exec trick sets high-order bit in first byte of name */ | 806 | /* NOMMU re-exec trick sets high-order bit in first byte of name */ |
816 | if (argv[0][0] & 0x80) { | 807 | if (argv[0][0] & 0x80) { |
@@ -818,6 +809,19 @@ int main(int argc UNUSED_PARAM, char **argv) | |||
818 | argv[0][0] &= 0x7f; | 809 | argv[0][0] &= 0x7f; |
819 | } | 810 | } |
820 | #endif | 811 | #endif |
812 | |||
813 | #if defined(SINGLE_APPLET_MAIN) | ||
814 | /* Only one applet is selected in .config */ | ||
815 | if (strncmp(argv[0], "busybox", 7) == 0) { | ||
816 | /* "busybox <applet> <params>" should still work as expected */ | ||
817 | argv++; | ||
818 | } | ||
819 | /* applet_names in this case is just "applet\0\0" */ | ||
820 | lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv)); | ||
821 | return SINGLE_APPLET_MAIN(argc, argv); | ||
822 | #else | ||
823 | lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); | ||
824 | |||
821 | applet_name = argv[0]; | 825 | applet_name = argv[0]; |
822 | if (applet_name[0] == '-') | 826 | if (applet_name[0] == '-') |
823 | applet_name++; | 827 | applet_name++; |