diff options
Diffstat (limited to 'applets/applets.c')
-rw-r--r-- | applets/applets.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/applets/applets.c b/applets/applets.c index 8acfd95a9..c8e85cdb1 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -49,7 +49,7 @@ static const char usage_messages[] = | |||
49 | const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(struct BB_applet) - 1; | 49 | const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(struct BB_applet) - 1; |
50 | 50 | ||
51 | 51 | ||
52 | static struct BB_applet *current_applet; | 52 | const struct BB_applet *current_applet; |
53 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | 53 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; |
54 | #ifdef BB_NOMMU | 54 | #ifdef BB_NOMMU |
55 | smallint re_execed; | 55 | smallint re_execed; |
@@ -60,14 +60,11 @@ smallint re_execed; | |||
60 | #if ENABLE_FEATURE_SUID_CONFIG | 60 | #if ENABLE_FEATURE_SUID_CONFIG |
61 | 61 | ||
62 | /* applets[] is const, so we have to define this "override" structure */ | 62 | /* applets[] is const, so we have to define this "override" structure */ |
63 | static struct BB_suid_config | 63 | static struct BB_suid_config { |
64 | { | 64 | const struct BB_applet *m_applet; |
65 | struct BB_applet *m_applet; | ||
66 | |||
67 | uid_t m_uid; | 65 | uid_t m_uid; |
68 | gid_t m_gid; | 66 | gid_t m_gid; |
69 | mode_t m_mode; | 67 | mode_t m_mode; |
70 | |||
71 | struct BB_suid_config *m_next; | 68 | struct BB_suid_config *m_next; |
72 | } *suid_config; | 69 | } *suid_config; |
73 | 70 | ||
@@ -133,7 +130,7 @@ static void parse_config_file(void) | |||
133 | { | 130 | { |
134 | struct BB_suid_config *sct_head; | 131 | struct BB_suid_config *sct_head; |
135 | struct BB_suid_config *sct; | 132 | struct BB_suid_config *sct; |
136 | struct BB_applet *applet; | 133 | const struct BB_applet *applet; |
137 | FILE *f; | 134 | FILE *f; |
138 | const char *errmsg; | 135 | const char *errmsg; |
139 | char *s; | 136 | char *s; |
@@ -330,7 +327,7 @@ static void parse_config_file(void) | |||
330 | 327 | ||
331 | 328 | ||
332 | #if ENABLE_FEATURE_SUID | 329 | #if ENABLE_FEATURE_SUID |
333 | static void check_suid(struct BB_applet *applet) | 330 | static void check_suid(const struct BB_applet *applet) |
334 | { | 331 | { |
335 | uid_t ruid = getuid(); /* real [ug]id */ | 332 | uid_t ruid = getuid(); /* real [ug]id */ |
336 | uid_t rgid = getgid(); | 333 | uid_t rgid = getgid(); |
@@ -476,7 +473,7 @@ static int applet_name_compare(const void *name, const void *vapplet) | |||
476 | return strcmp(name, applet->name); | 473 | return strcmp(name, applet->name); |
477 | } | 474 | } |
478 | 475 | ||
479 | struct BB_applet *find_applet_by_name(const char *name) | 476 | const struct BB_applet *find_applet_by_name(const char *name) |
480 | { | 477 | { |
481 | /* Do a binary search to find the applet entry given the name. */ | 478 | /* Do a binary search to find the applet entry given the name. */ |
482 | return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), | 479 | return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), |
@@ -599,17 +596,21 @@ static int busybox_main(int argc, char **argv) | |||
599 | bb_error_msg_and_die("applet not found"); | 596 | bb_error_msg_and_die("applet not found"); |
600 | } | 597 | } |
601 | 598 | ||
599 | void run_current_applet_and_exit(int argc, char **argv) | ||
600 | { | ||
601 | applet_name = current_applet->name; | ||
602 | if (argc == 2 && !strcmp(argv[1], "--help")) | ||
603 | bb_show_usage(); | ||
604 | if (ENABLE_FEATURE_SUID) | ||
605 | check_suid(current_applet); | ||
606 | exit(current_applet->main(argc, argv)); | ||
607 | } | ||
608 | |||
602 | void run_applet_by_name(const char *name, int argc, char **argv) | 609 | void run_applet_by_name(const char *name, int argc, char **argv) |
603 | { | 610 | { |
604 | current_applet = find_applet_by_name(name); | 611 | current_applet = find_applet_by_name(name); |
605 | if (current_applet) { | 612 | if (current_applet) |
606 | applet_name = current_applet->name; | 613 | run_current_applet_and_exit(argc, argv); |
607 | if (argc == 2 && !strcmp(argv[1], "--help")) | ||
608 | bb_show_usage(); | ||
609 | if (ENABLE_FEATURE_SUID) | ||
610 | check_suid(current_applet); | ||
611 | exit(current_applet->main(argc, argv)); | ||
612 | } | ||
613 | if (!strncmp(name, "busybox", 7)) | 614 | if (!strncmp(name, "busybox", 7)) |
614 | exit(busybox_main(argc, argv)); | 615 | exit(busybox_main(argc, argv)); |
615 | } | 616 | } |