Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 3 | * Utility routines. |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 4 | * |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 5 | * Copyright (C) tons of folks. Tracking down who wrote what |
| 6 | * isn't something I'm going to worry about... If you wrote something |
| 7 | * here, please feel free to acknowledge your work. |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 8 | * |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 9 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell |
| 10 | * Permission has been granted to redistribute this code under the GPL. |
| 11 | * |
| 12 | * Licensed under GPLv2 or later, see file License in this tarball for details. |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 15 | /* We are trying to not use printf, this benefits the case when selected |
| 16 | * applets are really simple. Example: |
| 17 | * |
| 18 | * $ ./busybox |
| 19 | * ... |
| 20 | * Currently defined functions: |
| 21 | * basename, false, true |
| 22 | * |
| 23 | * $ size busybox |
| 24 | * text data bss dec hex filename |
| 25 | * 4473 52 72 4597 11f5 busybox |
| 26 | * |
| 27 | * FEATURE_INSTALLER or FEATURE_SUID will still link printf routines in. :( |
| 28 | */ |
| 29 | |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 30 | #include <assert.h> |
| 31 | #include "busybox.h" |
| 32 | |
| 33 | |
| 34 | /* Declare <applet>_main() */ |
| 35 | #define PROTOTYPES |
| 36 | #include "applets.h" |
| 37 | #undef PROTOTYPES |
| 38 | |
| 39 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE |
| 40 | /* Define usage_messages[] */ |
| 41 | static const char usage_messages[] ALIGN1 = "" |
| 42 | #define MAKE_USAGE |
| 43 | #include "usage.h" |
| 44 | #include "applets.h" |
| 45 | ; |
| 46 | #undef MAKE_USAGE |
| 47 | #else |
| 48 | #define usage_messages 0 |
| 49 | #endif /* SHOW_USAGE */ |
| 50 | |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 51 | |
Denis Vlasenko | 32b2a9f | 2008-02-22 22:43:22 +0000 | [diff] [blame] | 52 | /* Include generated applet names, pointers to <applet>_main, etc */ |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 53 | #include "applet_tables.h" |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 54 | /* ...and if applet_tables generator says we have only one applet... */ |
| 55 | #ifdef SINGLE_APPLET_MAIN |
| 56 | #undef ENABLE_FEATURE_INDIVIDUAL |
| 57 | #define ENABLE_FEATURE_INDIVIDUAL 1 |
| 58 | #undef USE_FEATURE_INDIVIDUAL |
| 59 | #define USE_FEATURE_INDIVIDUAL(...) __VA_ARGS__ |
| 60 | #endif |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | #if ENABLE_FEATURE_COMPRESS_USAGE |
| 64 | |
| 65 | #include "usage_compressed.h" |
| 66 | #include "unarchive.h" |
| 67 | |
| 68 | static const char *unpack_usage_messages(void) |
| 69 | { |
| 70 | char *outbuf = NULL; |
| 71 | bunzip_data *bd; |
| 72 | int i; |
| 73 | |
| 74 | i = start_bunzip(&bd, |
| 75 | /* src_fd: */ -1, |
Denis Vlasenko | 5599502 | 2008-05-18 22:28:26 +0000 | [diff] [blame] | 76 | /* inbuf: */ (void *)packed_usage, |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 77 | /* len: */ sizeof(packed_usage)); |
| 78 | /* read_bunzip can longjmp to start_bunzip, and ultimately |
| 79 | * end up here with i != 0 on read data errors! Not trivial */ |
| 80 | if (!i) { |
| 81 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ |
| 82 | outbuf = malloc_or_warn(SIZEOF_usage_messages); |
| 83 | if (outbuf) |
| 84 | read_bunzip(bd, outbuf, SIZEOF_usage_messages); |
| 85 | } |
| 86 | dealloc_bunzip(bd); |
| 87 | return outbuf; |
| 88 | } |
| 89 | #define dealloc_usage_messages(s) free(s) |
| 90 | |
| 91 | #else |
| 92 | |
| 93 | #define unpack_usage_messages() usage_messages |
| 94 | #define dealloc_usage_messages(s) ((void)(s)) |
| 95 | |
| 96 | #endif /* FEATURE_COMPRESS_USAGE */ |
| 97 | |
| 98 | |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 99 | static void full_write2_str(const char *str) |
| 100 | { |
Bernhard Reutner-Fischer | 5e25ddb | 2008-05-19 09:48:17 +0000 | [diff] [blame] | 101 | full_write(STDERR_FILENO, str, strlen(str)); |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 104 | void FAST_FUNC bb_show_usage(void) |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 105 | { |
| 106 | if (ENABLE_SHOW_USAGE) { |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 107 | #ifdef SINGLE_APPLET_STR |
| 108 | /* Imagine that this applet is "true". Dont suck in printf! */ |
| 109 | const char *p; |
| 110 | const char *usage_string = p = unpack_usage_messages(); |
| 111 | |
| 112 | if (*p == '\b') { |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 113 | full_write2_str("\nNo help available.\n\n"); |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 114 | } else { |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 115 | full_write2_str("\nUsage: "SINGLE_APPLET_STR" "); |
| 116 | full_write2_str(p); |
| 117 | full_write2_str("\n\n"); |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 118 | } |
| 119 | dealloc_usage_messages((char*)usage_string); |
| 120 | #else |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 121 | const char *p; |
| 122 | const char *usage_string = p = unpack_usage_messages(); |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 123 | int ap = find_applet_by_name(applet_name); |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 124 | |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 125 | if (ap < 0) /* never happens, paranoia */ |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 126 | xfunc_die(); |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 127 | while (ap) { |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 128 | while (*p++) continue; |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 129 | ap--; |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 130 | } |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 131 | full_write2_str(bb_banner); |
| 132 | full_write2_str(" multi-call binary\n"); |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 133 | if (*p == '\b') |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 134 | full_write2_str("\nNo help available.\n\n"); |
| 135 | else { |
| 136 | full_write2_str("\nUsage: "); |
| 137 | full_write2_str(applet_name); |
| 138 | full_write2_str(" "); |
| 139 | full_write2_str(p); |
| 140 | full_write2_str("\n\n"); |
| 141 | } |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 142 | dealloc_usage_messages((char*)usage_string); |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 143 | #endif |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 144 | } |
| 145 | xfunc_die(); |
| 146 | } |
| 147 | |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 148 | #if NUM_APPLETS > 8 |
Denis Vlasenko | 745cd17 | 2007-11-29 03:31:20 +0000 | [diff] [blame] | 149 | /* NB: any char pointer will work as well, not necessarily applet_names */ |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 150 | static int applet_name_compare(const void *name, const void *v) |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 151 | { |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 152 | int i = (const char *)v - applet_names; |
| 153 | return strcmp(name, APPLET_NAME(i)); |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 154 | } |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 155 | #endif |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 156 | int FAST_FUNC find_applet_by_name(const char *name) |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 157 | { |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 158 | #if NUM_APPLETS > 8 |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 159 | /* Do a binary search to find the applet entry given the name. */ |
Denis Vlasenko | 745cd17 | 2007-11-29 03:31:20 +0000 | [diff] [blame] | 160 | const char *p; |
| 161 | p = bsearch(name, applet_names, ARRAY_SIZE(applet_main), 1, applet_name_compare); |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 162 | if (!p) |
| 163 | return -1; |
| 164 | return p - applet_names; |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 165 | #else |
| 166 | /* A version which does not pull in bsearch */ |
| 167 | int i = 0; |
| 168 | const char *p = applet_names; |
| 169 | while (i < NUM_APPLETS) { |
| 170 | if (strcmp(name, p) == 0) |
| 171 | return i; |
| 172 | p += strlen(p) + 1; |
| 173 | i++; |
| 174 | } |
| 175 | return -1; |
| 176 | #endif |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 180 | void lbb_prepare(const char *applet |
| 181 | USE_FEATURE_INDIVIDUAL(, char **argv)) |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 182 | MAIN_EXTERNALLY_VISIBLE; |
| 183 | void lbb_prepare(const char *applet |
| 184 | USE_FEATURE_INDIVIDUAL(, char **argv)) |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 185 | { |
| 186 | #ifdef __GLIBC__ |
| 187 | (*(int **)&bb_errno) = __errno_location(); |
Denis Vlasenko | 574f2f4 | 2008-02-27 18:41:59 +0000 | [diff] [blame] | 188 | barrier(); |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 189 | #endif |
Denis Vlasenko | 15cb4a4 | 2007-10-11 10:06:26 +0000 | [diff] [blame] | 190 | applet_name = applet; |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 191 | |
| 192 | /* Set locale for everybody except 'init' */ |
| 193 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) |
| 194 | setlocale(LC_ALL, ""); |
| 195 | |
Denis Vlasenko | 82d38da | 2007-10-10 14:38:47 +0000 | [diff] [blame] | 196 | #if ENABLE_FEATURE_INDIVIDUAL |
| 197 | /* Redundant for busybox (run_applet_and_exit covers that case) |
| 198 | * but needed for "individual applet" mode */ |
Denis Vlasenko | d419a9f | 2007-10-08 20:45:42 +0000 | [diff] [blame] | 199 | if (argv[1] && strcmp(argv[1], "--help") == 0) |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 200 | bb_show_usage(); |
Denis Vlasenko | 82d38da | 2007-10-10 14:38:47 +0000 | [diff] [blame] | 201 | #endif |
Denis Vlasenko | ac7d0e3 | 2007-10-08 19:32:12 +0000 | [diff] [blame] | 202 | } |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 203 | |
| 204 | /* The code below can well be in applets/applets.c, as it is used only |
| 205 | * for busybox binary, not "individual" binaries. |
| 206 | * However, keeping it here and linking it into libbusybox.so |
| 207 | * (together with remaining tiny applets/applets.o) |
| 208 | * makes it possible to avoid --whole-archive at link time. |
| 209 | * This makes (shared busybox) + libbusybox smaller. |
| 210 | * (--gc-sections would be even better....) |
| 211 | */ |
| 212 | |
| 213 | const char *applet_name; |
| 214 | #if !BB_MMU |
| 215 | bool re_execed; |
| 216 | #endif |
| 217 | |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 218 | |
Denis Vlasenko | 10f6fb1 | 2008-04-29 00:10:27 +0000 | [diff] [blame] | 219 | /* If not built as a single-applet executable... */ |
| 220 | #if !defined(SINGLE_APPLET_MAIN) |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 221 | |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 222 | USE_FEATURE_SUID(static uid_t ruid;) /* real uid */ |
| 223 | |
| 224 | #if ENABLE_FEATURE_SUID_CONFIG |
| 225 | |
| 226 | /* applets[] is const, so we have to define this "override" structure */ |
| 227 | static struct BB_suid_config { |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 228 | int m_applet; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 229 | uid_t m_uid; |
| 230 | gid_t m_gid; |
| 231 | mode_t m_mode; |
| 232 | struct BB_suid_config *m_next; |
| 233 | } *suid_config; |
| 234 | |
| 235 | static bool suid_cfg_readable; |
| 236 | |
| 237 | /* check if u is member of group g */ |
| 238 | static int ingroup(uid_t u, gid_t g) |
| 239 | { |
| 240 | struct group *grp = getgrgid(g); |
| 241 | |
| 242 | if (grp) { |
| 243 | char **mem; |
| 244 | |
| 245 | for (mem = grp->gr_mem; *mem; mem++) { |
| 246 | struct passwd *pwd = getpwnam(*mem); |
| 247 | |
| 248 | if (pwd && (pwd->pw_uid == u)) |
| 249 | return 1; |
| 250 | } |
| 251 | } |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* This should probably be a libbb routine. In that case, |
| 256 | * I'd probably rename it to something like bb_trimmed_slice. |
| 257 | */ |
| 258 | static char *get_trimmed_slice(char *s, char *e) |
| 259 | { |
| 260 | /* First, consider the value at e to be nul and back up until we |
| 261 | * reach a non-space char. Set the char after that (possibly at |
| 262 | * the original e) to nul. */ |
| 263 | while (e-- > s) { |
| 264 | if (!isspace(*e)) { |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | e[1] = '\0'; |
| 269 | |
| 270 | /* Next, advance past all leading space and return a ptr to the |
| 271 | * first non-space char; possibly the terminating nul. */ |
| 272 | return skip_whitespace(s); |
| 273 | } |
| 274 | |
| 275 | /* Don't depend on the tools to combine strings. */ |
| 276 | static const char config_file[] ALIGN1 = "/etc/busybox.conf"; |
| 277 | |
| 278 | /* We don't supply a value for the nul, so an index adjustment is |
| 279 | * necessary below. Also, we use unsigned short here to save some |
| 280 | * space even though these are really mode_t values. */ |
| 281 | static const unsigned short mode_mask[] ALIGN2 = { |
| 282 | /* SST sst xxx --- */ |
| 283 | S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */ |
| 284 | S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */ |
| 285 | 0, S_IXOTH, S_IXOTH, 0 /* other */ |
| 286 | }; |
| 287 | |
| 288 | #define parse_error(x) do { errmsg = x; goto pe_label; } while (0) |
| 289 | |
| 290 | static void parse_config_file(void) |
| 291 | { |
| 292 | struct BB_suid_config *sct_head; |
| 293 | struct BB_suid_config *sct; |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 294 | int applet_no; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 295 | FILE *f; |
| 296 | const char *errmsg; |
| 297 | char *s; |
| 298 | char *e; |
| 299 | int i; |
| 300 | unsigned lc; |
| 301 | smallint section; |
| 302 | char buffer[256]; |
| 303 | struct stat st; |
| 304 | |
| 305 | assert(!suid_config); /* Should be set to NULL by bss init. */ |
| 306 | |
| 307 | ruid = getuid(); |
| 308 | if (ruid == 0) /* run by root - don't need to even read config file */ |
| 309 | return; |
| 310 | |
| 311 | if ((stat(config_file, &st) != 0) /* No config file? */ |
| 312 | || !S_ISREG(st.st_mode) /* Not a regular file? */ |
| 313 | || (st.st_uid != 0) /* Not owned by root? */ |
| 314 | || (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */ |
| 315 | || !(f = fopen(config_file, "r")) /* Cannot open? */ |
| 316 | ) { |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | suid_cfg_readable = 1; |
| 321 | sct_head = NULL; |
| 322 | section = lc = 0; |
| 323 | |
| 324 | while (1) { |
| 325 | s = buffer; |
| 326 | |
| 327 | if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */ |
Denis Vlasenko | d02db89 | 2008-03-17 09:05:21 +0000 | [diff] [blame] | 328 | // why? |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 329 | if (ferror(f)) { /* Make sure it wasn't a read error. */ |
| 330 | parse_error("reading"); |
| 331 | } |
| 332 | fclose(f); |
| 333 | suid_config = sct_head; /* Success, so set the pointer. */ |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | lc++; /* Got a (partial) line. */ |
| 338 | |
| 339 | /* If a line is too long for our buffer, we consider it an error. |
| 340 | * The following test does mistreat one corner case though. |
| 341 | * If the final line of the file does not end with a newline and |
| 342 | * yet exactly fills the buffer, it will be treated as too long |
| 343 | * even though there isn't really a problem. But it isn't really |
| 344 | * worth adding code to deal with such an unlikely situation, and |
| 345 | * we do err on the side of caution. Besides, the line would be |
| 346 | * too long if it did end with a newline. */ |
| 347 | if (!strchr(s, '\n') && !feof(f)) { |
| 348 | parse_error("line too long"); |
| 349 | } |
| 350 | |
| 351 | /* Trim leading and trailing whitespace, ignoring comments, and |
| 352 | * check if the resulting string is empty. */ |
| 353 | s = get_trimmed_slice(s, strchrnul(s, '#')); |
| 354 | if (!*s) { |
| 355 | continue; |
| 356 | } |
| 357 | |
| 358 | /* Check for a section header. */ |
| 359 | |
| 360 | if (*s == '[') { |
| 361 | /* Unlike the old code, we ignore leading and trailing |
| 362 | * whitespace for the section name. We also require that |
| 363 | * there are no stray characters after the closing bracket. */ |
| 364 | e = strchr(s, ']'); |
| 365 | if (!e /* Missing right bracket? */ |
| 366 | || e[1] /* Trailing characters? */ |
| 367 | || !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */ |
| 368 | ) { |
| 369 | parse_error("section header"); |
| 370 | } |
| 371 | /* Right now we only have one section so just check it. |
| 372 | * If more sections are added in the future, please don't |
| 373 | * resort to cascading ifs with multiple strcasecmp calls. |
| 374 | * That kind of bloated code is all too common. A loop |
| 375 | * and a string table would be a better choice unless the |
| 376 | * number of sections is very small. */ |
| 377 | if (strcasecmp(s, "SUID") == 0) { |
| 378 | section = 1; |
| 379 | continue; |
| 380 | } |
| 381 | section = -1; /* Unknown section so set to skip. */ |
| 382 | continue; |
| 383 | } |
| 384 | |
| 385 | /* Process sections. */ |
| 386 | |
| 387 | if (section == 1) { /* SUID */ |
| 388 | /* Since we trimmed leading and trailing space above, we're |
| 389 | * now looking for strings of the form |
| 390 | * <key>[::space::]*=[::space::]*<value> |
| 391 | * where both key and value could contain inner whitespace. */ |
| 392 | |
| 393 | /* First get the key (an applet name in our case). */ |
| 394 | e = strchr(s, '='); |
| 395 | if (e) { |
| 396 | s = get_trimmed_slice(s, e); |
| 397 | } |
| 398 | if (!e || !*s) { /* Missing '=' or empty key. */ |
| 399 | parse_error("keyword"); |
| 400 | } |
| 401 | |
| 402 | /* Ok, we have an applet name. Process the rhs if this |
| 403 | * applet is currently built in and ignore it otherwise. |
| 404 | * Note: this can hide config file bugs which only pop |
| 405 | * up when the busybox configuration is changed. */ |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 406 | applet_no = find_applet_by_name(s); |
| 407 | if (applet_no >= 0) { |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 408 | /* Note: We currently don't check for duplicates! |
| 409 | * The last config line for each applet will be the |
| 410 | * one used since we insert at the head of the list. |
| 411 | * I suppose this could be considered a feature. */ |
| 412 | sct = xmalloc(sizeof(struct BB_suid_config)); |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 413 | sct->m_applet = applet_no; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 414 | sct->m_mode = 0; |
| 415 | sct->m_next = sct_head; |
| 416 | sct_head = sct; |
| 417 | |
| 418 | /* Get the specified mode. */ |
| 419 | |
| 420 | e = skip_whitespace(e+1); |
| 421 | |
| 422 | for (i = 0; i < 3; i++) { |
| 423 | /* There are 4 chars + 1 nul for each of user/group/other. */ |
| 424 | static const char mode_chars[] ALIGN1 = "Ssx-\0" "Ssx-\0" "Ttx-"; |
| 425 | |
| 426 | const char *q; |
| 427 | q = strchrnul(mode_chars + 5*i, *e++); |
| 428 | if (!*q) { |
| 429 | parse_error("mode"); |
| 430 | } |
| 431 | /* Adjust by -i to account for nul. */ |
| 432 | sct->m_mode |= mode_mask[(q - mode_chars) - i]; |
| 433 | } |
| 434 | |
| 435 | /* Now get the the user/group info. */ |
| 436 | |
| 437 | s = skip_whitespace(e); |
| 438 | |
| 439 | /* Note: we require whitespace between the mode and the |
| 440 | * user/group info. */ |
| 441 | if ((s == e) || !(e = strchr(s, '.'))) { |
| 442 | parse_error("<uid>.<gid>"); |
| 443 | } |
| 444 | *e++ = '\0'; |
| 445 | |
| 446 | /* We can't use get_ug_id here since it would exit() |
| 447 | * if a uid or gid was not found. Oh well... */ |
| 448 | sct->m_uid = bb_strtoul(s, NULL, 10); |
| 449 | if (errno) { |
| 450 | struct passwd *pwd = getpwnam(s); |
| 451 | if (!pwd) { |
| 452 | parse_error("user"); |
| 453 | } |
| 454 | sct->m_uid = pwd->pw_uid; |
| 455 | } |
| 456 | |
| 457 | sct->m_gid = bb_strtoul(e, NULL, 10); |
| 458 | if (errno) { |
| 459 | struct group *grp; |
| 460 | grp = getgrnam(e); |
| 461 | if (!grp) { |
| 462 | parse_error("group"); |
| 463 | } |
| 464 | sct->m_gid = grp->gr_gid; |
| 465 | } |
| 466 | } |
| 467 | continue; |
| 468 | } |
| 469 | |
| 470 | /* Unknown sections are ignored. */ |
| 471 | |
| 472 | /* Encountering configuration lines prior to seeing a |
| 473 | * section header is treated as an error. This is how |
| 474 | * the old code worked, but it may not be desirable. |
| 475 | * We may want to simply ignore such lines in case they |
| 476 | * are used in some future version of busybox. */ |
| 477 | if (!section) { |
| 478 | parse_error("keyword outside section"); |
| 479 | } |
| 480 | |
| 481 | } /* while (1) */ |
| 482 | |
| 483 | pe_label: |
| 484 | fprintf(stderr, "Parse error in %s, line %d: %s\n", |
| 485 | config_file, lc, errmsg); |
| 486 | |
| 487 | fclose(f); |
| 488 | /* Release any allocated memory before returning. */ |
| 489 | while (sct_head) { |
| 490 | sct = sct_head->m_next; |
| 491 | free(sct_head); |
| 492 | sct_head = sct; |
| 493 | } |
| 494 | } |
| 495 | #else |
| 496 | static inline void parse_config_file(void) |
| 497 | { |
| 498 | USE_FEATURE_SUID(ruid = getuid();) |
| 499 | } |
| 500 | #endif /* FEATURE_SUID_CONFIG */ |
| 501 | |
| 502 | |
| 503 | #if ENABLE_FEATURE_SUID |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 504 | static void check_suid(int applet_no) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 505 | { |
| 506 | gid_t rgid; /* real gid */ |
| 507 | |
| 508 | if (ruid == 0) /* set by parse_config_file() */ |
| 509 | return; /* run by root - no need to check more */ |
| 510 | rgid = getgid(); |
| 511 | |
| 512 | #if ENABLE_FEATURE_SUID_CONFIG |
| 513 | if (suid_cfg_readable) { |
| 514 | uid_t uid; |
| 515 | struct BB_suid_config *sct; |
| 516 | mode_t m; |
| 517 | |
| 518 | for (sct = suid_config; sct; sct = sct->m_next) { |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 519 | if (sct->m_applet == applet_no) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 520 | goto found; |
| 521 | } |
Denis Vlasenko | 15ca51e | 2007-10-29 19:25:45 +0000 | [diff] [blame] | 522 | goto check_need_suid; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 523 | found: |
| 524 | m = sct->m_mode; |
| 525 | if (sct->m_uid == ruid) |
| 526 | /* same uid */ |
| 527 | m >>= 6; |
| 528 | else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid)) |
| 529 | /* same group / in group */ |
| 530 | m >>= 3; |
| 531 | |
| 532 | if (!(m & S_IXOTH)) /* is x bit not set ? */ |
| 533 | bb_error_msg_and_die("you have no permission to run this applet!"); |
| 534 | |
| 535 | /* _both_ sgid and group_exec have to be set for setegid */ |
| 536 | if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) |
| 537 | rgid = sct->m_gid; |
| 538 | /* else (no setegid) we will set egid = rgid */ |
| 539 | |
| 540 | /* We set effective AND saved ids. If saved-id is not set |
| 541 | * like we do below, seteiud(0) can still later succeed! */ |
| 542 | if (setresgid(-1, rgid, rgid)) |
| 543 | bb_perror_msg_and_die("setresgid"); |
| 544 | |
| 545 | /* do we have to set effective uid? */ |
| 546 | uid = ruid; |
| 547 | if (sct->m_mode & S_ISUID) |
| 548 | uid = sct->m_uid; |
| 549 | /* else (no seteuid) we will set euid = ruid */ |
| 550 | |
| 551 | if (setresuid(-1, uid, uid)) |
| 552 | bb_perror_msg_and_die("setresuid"); |
| 553 | return; |
| 554 | } |
| 555 | #if !ENABLE_FEATURE_SUID_CONFIG_QUIET |
| 556 | { |
| 557 | static bool onetime = 0; |
| 558 | |
| 559 | if (!onetime) { |
| 560 | onetime = 1; |
| 561 | fprintf(stderr, "Using fallback suid method\n"); |
| 562 | } |
| 563 | } |
| 564 | #endif |
Denis Vlasenko | 15ca51e | 2007-10-29 19:25:45 +0000 | [diff] [blame] | 565 | check_need_suid: |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 566 | #endif |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 567 | if (APPLET_SUID(applet_no) == _BB_SUID_ALWAYS) { |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 568 | /* Real uid is not 0. If euid isn't 0 too, suid bit |
| 569 | * is most probably not set on our executable */ |
| 570 | if (geteuid()) |
Denis Vlasenko | 15ca51e | 2007-10-29 19:25:45 +0000 | [diff] [blame] | 571 | bb_error_msg_and_die("must be suid to work properly"); |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 572 | } else if (APPLET_SUID(applet_no) == _BB_SUID_NEVER) { |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 573 | xsetgid(rgid); /* drop all privileges */ |
| 574 | xsetuid(ruid); |
| 575 | } |
| 576 | } |
| 577 | #else |
| 578 | #define check_suid(x) ((void)0) |
| 579 | #endif /* FEATURE_SUID */ |
| 580 | |
| 581 | |
| 582 | #if ENABLE_FEATURE_INSTALLER |
| 583 | /* create (sym)links for each applet */ |
| 584 | static void install_links(const char *busybox, int use_symbolic_links) |
| 585 | { |
| 586 | /* directory table |
| 587 | * this should be consistent w/ the enum, |
| 588 | * busybox.h::bb_install_loc_t, or else... */ |
| 589 | static const char usr_bin [] ALIGN1 = "/usr/bin"; |
| 590 | static const char usr_sbin[] ALIGN1 = "/usr/sbin"; |
| 591 | static const char *const install_dir[] = { |
| 592 | &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */ |
| 593 | &usr_bin [4], /* "/bin" */ |
| 594 | &usr_sbin[4], /* "/sbin" */ |
| 595 | usr_bin, |
| 596 | usr_sbin |
| 597 | }; |
| 598 | |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 599 | int (*lf)(const char *, const char *); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 600 | char *fpc; |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 601 | unsigned i; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 602 | int rc; |
| 603 | |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 604 | lf = link; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 605 | if (use_symbolic_links) |
| 606 | lf = symlink; |
| 607 | |
Denis Vlasenko | 745cd17 | 2007-11-29 03:31:20 +0000 | [diff] [blame] | 608 | for (i = 0; i < ARRAY_SIZE(applet_main); i++) { |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 609 | fpc = concat_path_file( |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 610 | install_dir[APPLET_INSTALL_LOC(i)], |
| 611 | APPLET_NAME(i)); |
Denis Vlasenko | 745cd17 | 2007-11-29 03:31:20 +0000 | [diff] [blame] | 612 | // debug: bb_error_msg("%slinking %s to busybox", |
| 613 | // use_symbolic_links ? "sym" : "", fpc); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 614 | rc = lf(busybox, fpc); |
| 615 | if (rc != 0 && errno != EEXIST) { |
| 616 | bb_simple_perror_msg(fpc); |
| 617 | } |
| 618 | free(fpc); |
| 619 | } |
| 620 | } |
| 621 | #else |
| 622 | #define install_links(x,y) ((void)0) |
| 623 | #endif /* FEATURE_INSTALLER */ |
| 624 | |
| 625 | /* If we were called as "busybox..." */ |
| 626 | static int busybox_main(char **argv) |
| 627 | { |
| 628 | if (!argv[1]) { |
| 629 | /* Called without arguments */ |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 630 | const char *a; |
Denis Vlasenko | 5599502 | 2008-05-18 22:28:26 +0000 | [diff] [blame] | 631 | unsigned col, output_width; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 632 | help: |
| 633 | output_width = 80; |
| 634 | if (ENABLE_FEATURE_AUTOWIDTH) { |
| 635 | /* Obtain the terminal width */ |
| 636 | get_terminal_width_height(0, &output_width, NULL); |
| 637 | } |
| 638 | /* leading tab and room to wrap */ |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 639 | output_width -= MAX_APPLET_NAME_LEN + 8; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 640 | |
Denis Vlasenko | 21278df | 2008-06-25 12:15:46 +0000 | [diff] [blame] | 641 | dup2(1, 2); |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 642 | full_write2_str(bb_banner); /* reuse const string... */ |
| 643 | full_write2_str(" multi-call binary\n" |
Bernhard Reutner-Fischer | 15ce7f5 | 2008-04-24 10:35:50 +0000 | [diff] [blame] | 644 | "Copyright (C) 1998-2008 Erik Andersen, Rob Landley, Denys Vlasenko\n" |
Denis Vlasenko | fcfb5c0 | 2007-12-24 12:16:24 +0000 | [diff] [blame] | 645 | "and others. Licensed under GPLv2.\n" |
| 646 | "See source distribution for full notice.\n" |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 647 | "\n" |
| 648 | "Usage: busybox [function] [arguments]...\n" |
Denis Vlasenko | fcfb5c0 | 2007-12-24 12:16:24 +0000 | [diff] [blame] | 649 | " or: function [arguments]...\n" |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 650 | "\n" |
| 651 | "\tBusyBox is a multi-call binary that combines many common Unix\n" |
| 652 | "\tutilities into a single executable. Most people will create a\n" |
| 653 | "\tlink to busybox for each function they wish to use and BusyBox\n" |
| 654 | "\twill act like whatever it was invoked as!\n" |
Denis Vlasenko | fcfb5c0 | 2007-12-24 12:16:24 +0000 | [diff] [blame] | 655 | "\n" |
| 656 | "Currently defined functions:\n"); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 657 | col = 0; |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 658 | a = applet_names; |
| 659 | while (*a) { |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 660 | int len; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 661 | if (col > output_width) { |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 662 | full_write2_str(",\n"); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 663 | col = 0; |
| 664 | } |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 665 | full_write2_str(col ? ", " : "\t"); |
| 666 | full_write2_str(a); |
| 667 | len = strlen(a); |
| 668 | col += len + 2; |
| 669 | a += len + 1; |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 670 | } |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 671 | full_write2_str("\n\n"); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { |
| 676 | const char *busybox; |
| 677 | busybox = xmalloc_readlink(bb_busybox_exec_path); |
| 678 | if (!busybox) |
| 679 | busybox = bb_busybox_exec_path; |
| 680 | /* -s makes symlinks */ |
| 681 | install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0); |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | if (strcmp(argv[1], "--help") == 0) { |
| 686 | /* "busybox --help [<applet>]" */ |
| 687 | if (!argv[2]) |
| 688 | goto help; |
| 689 | /* convert to "<applet> --help" */ |
| 690 | argv[0] = argv[2]; |
| 691 | argv[2] = NULL; |
| 692 | } else { |
| 693 | /* "busybox <applet> arg1 arg2 ..." */ |
| 694 | argv++; |
| 695 | } |
| 696 | /* We support "busybox /a/path/to/applet args..." too. Allows for |
| 697 | * "#!/bin/busybox"-style wrappers */ |
| 698 | applet_name = bb_get_last_path_component_nostrip(argv[0]); |
| 699 | run_applet_and_exit(applet_name, argv); |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 700 | |
| 701 | /*bb_error_msg_and_die("applet not found"); - sucks in printf */ |
| 702 | full_write2_str(applet_name); |
| 703 | full_write2_str(": applet not found\n"); |
| 704 | xfunc_die(); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 707 | void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 708 | { |
| 709 | int argc = 1; |
| 710 | |
| 711 | while (argv[argc]) |
| 712 | argc++; |
| 713 | |
| 714 | /* Reinit some shared global data */ |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 715 | xfunc_error_retval = EXIT_FAILURE; |
| 716 | |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 717 | applet_name = APPLET_NAME(applet_no); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 718 | if (argc == 2 && !strcmp(argv[1], "--help")) |
| 719 | bb_show_usage(); |
| 720 | if (ENABLE_FEATURE_SUID) |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 721 | check_suid(applet_no); |
Denis Vlasenko | 745cd17 | 2007-11-29 03:31:20 +0000 | [diff] [blame] | 722 | exit(applet_main[applet_no](argc, argv)); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 725 | void FAST_FUNC run_applet_and_exit(const char *name, char **argv) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 726 | { |
Denis Vlasenko | 1aa7e47 | 2007-11-28 06:49:03 +0000 | [diff] [blame] | 727 | int applet = find_applet_by_name(name); |
| 728 | if (applet >= 0) |
| 729 | run_applet_no_and_exit(applet, argv); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 730 | if (!strncmp(name, "busybox", 7)) |
| 731 | exit(busybox_main(argv)); |
| 732 | } |
| 733 | |
Denis Vlasenko | 10f6fb1 | 2008-04-29 00:10:27 +0000 | [diff] [blame] | 734 | #endif /* !defined(SINGLE_APPLET_MAIN) */ |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 735 | |
| 736 | |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 737 | |
| 738 | #if ENABLE_BUILD_LIBBUSYBOX |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 739 | int lbb_main(char **argv) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 740 | #else |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 741 | int main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 742 | #endif |
| 743 | { |
Denis Vlasenko | 10f6fb1 | 2008-04-29 00:10:27 +0000 | [diff] [blame] | 744 | #if defined(SINGLE_APPLET_MAIN) |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 745 | /* Only one applet is selected by the user! */ |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 746 | /* applet_names in this case is just "applet\0\0" */ |
| 747 | lbb_prepare(applet_names USE_FEATURE_INDIVIDUAL(, argv)); |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 748 | return SINGLE_APPLET_MAIN(argc, argv); |
| 749 | #else |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 750 | lbb_prepare("busybox" USE_FEATURE_INDIVIDUAL(, argv)); |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 751 | |
| 752 | #if !BB_MMU |
| 753 | /* NOMMU re-exec trick sets high-order bit in first byte of name */ |
| 754 | if (argv[0][0] & 0x80) { |
| 755 | re_execed = 1; |
| 756 | argv[0][0] &= 0x7f; |
| 757 | } |
| 758 | #endif |
| 759 | applet_name = argv[0]; |
| 760 | if (applet_name[0] == '-') |
| 761 | applet_name++; |
| 762 | applet_name = bb_basename(applet_name); |
| 763 | |
| 764 | parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ |
| 765 | |
| 766 | run_applet_and_exit(applet_name, argv); |
Denis Vlasenko | 79cedcb | 2008-04-08 21:13:28 +0000 | [diff] [blame] | 767 | |
| 768 | /*bb_error_msg_and_die("applet not found"); - sucks in printf */ |
| 769 | full_write2_str(applet_name); |
| 770 | full_write2_str(": applet not found\n"); |
| 771 | xfunc_die(); |
Denis Vlasenko | 468aea2 | 2008-04-01 14:47:57 +0000 | [diff] [blame] | 772 | #endif |
Denis Vlasenko | 724d196 | 2007-10-10 14:41:07 +0000 | [diff] [blame] | 773 | } |