diff options
Diffstat (limited to 'applets')
-rw-r--r-- | applets/applets.c | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/applets/applets.c b/applets/applets.c index 27becfd68..bd8cfec5d 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -343,22 +343,15 @@ static void check_suid (struct BB_applet *applet) | |||
343 | bb_error_msg_and_die ("You have no permission to run this applet!"); | 343 | bb_error_msg_and_die ("You have no permission to run this applet!"); |
344 | 344 | ||
345 | if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */ | 345 | if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */ |
346 | if (setegid (sct->m_gid)) | 346 | xsetgid(sct->m_gid); |
347 | bb_error_msg_and_die | 347 | } else xsetgid(rgid); /* no sgid -> drop */ |
348 | ("BusyBox binary has insufficient rights to set proper GID for applet!"); | 348 | |
349 | } else | 349 | if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid); |
350 | setgid (rgid); /* no sgid -> drop */ | 350 | else xsetuid(ruid); /* no suid -> drop */ |
351 | |||
352 | if (sct->m_mode & S_ISUID) { | ||
353 | if (seteuid (sct->m_uid)) | ||
354 | bb_error_msg_and_die | ||
355 | ("BusyBox binary has insufficient rights to set proper UID for applet!"); | ||
356 | } else | ||
357 | setuid (ruid); /* no suid -> drop */ | ||
358 | } else { | 351 | } else { |
359 | /* default: drop all privileges */ | 352 | /* default: drop all privileges */ |
360 | setgid (rgid); | 353 | xsetgid(rgid); |
361 | setuid (ruid); | 354 | xsetuid(ruid); |
362 | } | 355 | } |
363 | return; | 356 | return; |
364 | } else { | 357 | } else { |
@@ -374,11 +367,10 @@ static void check_suid (struct BB_applet *applet) | |||
374 | #endif | 367 | #endif |
375 | 368 | ||
376 | if (applet->need_suid == _BB_SUID_ALWAYS) { | 369 | if (applet->need_suid == _BB_SUID_ALWAYS) { |
377 | if (geteuid () != 0) | 370 | if (geteuid()) bb_error_msg_and_die("Applet requires root privileges!"); |
378 | bb_error_msg_and_die ("This applet requires root privileges!"); | ||
379 | } else if (applet->need_suid == _BB_SUID_NEVER) { | 371 | } else if (applet->need_suid == _BB_SUID_NEVER) { |
380 | setgid (rgid); /* drop all privileges */ | 372 | xsetgid(rgid); /* drop all privileges */ |
381 | setuid (ruid); | 373 | xsetuid(ruid); |
382 | } | 374 | } |
383 | } | 375 | } |
384 | #else | 376 | #else |
@@ -419,14 +411,14 @@ static const char *unpack_usage_messages(void) | |||
419 | case -1: /* error */ | 411 | case -1: /* error */ |
420 | exit(1); | 412 | exit(1); |
421 | case 0: /* child */ | 413 | case 0: /* child */ |
422 | bb_full_write(input[1], packed_usage, sizeof(packed_usage)); | 414 | full_write(input[1], packed_usage, sizeof(packed_usage)); |
423 | exit(0); | 415 | exit(0); |
424 | } | 416 | } |
425 | /* parent */ | 417 | /* parent */ |
426 | close(input[1]); | 418 | close(input[1]); |
427 | 419 | ||
428 | buf = xmalloc(SIZEOF_usage_messages); | 420 | buf = xmalloc(SIZEOF_usage_messages); |
429 | bb_full_read(output[0], buf, SIZEOF_usage_messages); | 421 | full_read(output[0], buf, SIZEOF_usage_messages); |
430 | return buf; | 422 | return buf; |
431 | } | 423 | } |
432 | 424 | ||
@@ -454,33 +446,32 @@ void bb_show_usage (void) | |||
454 | exit (bb_default_error_retval); | 446 | exit (bb_default_error_retval); |
455 | } | 447 | } |
456 | 448 | ||
457 | static int applet_name_compare (const void *x, const void *y) | 449 | static int applet_name_compare(const void *name, const void *vapplet) |
458 | { | 450 | { |
459 | const char *name = x; | 451 | const struct BB_applet *applet = vapplet; |
460 | const struct BB_applet *applet = y; | ||
461 | 452 | ||
462 | return strcmp (name, applet->name); | 453 | return strcmp(name, applet->name); |
463 | } | 454 | } |
464 | 455 | ||
465 | extern const size_t NUM_APPLETS; | 456 | extern const size_t NUM_APPLETS; |
466 | 457 | ||
467 | struct BB_applet *find_applet_by_name (const char *name) | 458 | struct BB_applet *find_applet_by_name(const char *name) |
468 | { | 459 | { |
469 | return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet), | 460 | return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), |
470 | applet_name_compare); | 461 | applet_name_compare); |
471 | } | 462 | } |
472 | 463 | ||
473 | void run_applet_by_name (const char *name, int argc, char **argv) | 464 | void run_applet_by_name(const char *name, int argc, char **argv) |
474 | { | 465 | { |
475 | if(ENABLE_FEATURE_SUID_CONFIG) parse_config_file (); | 466 | if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file(); |
476 | 467 | ||
477 | if(!strncmp(name, "busybox", 7)) busybox_main(argc, argv); | 468 | if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv); |
478 | /* Do a binary search to find the applet entry given the name. */ | 469 | /* Do a binary search to find the applet entry given the name. */ |
479 | applet_using = find_applet_by_name(name); | 470 | applet_using = find_applet_by_name(name); |
480 | if(applet_using) { | 471 | if (applet_using) { |
481 | bb_applet_name = applet_using->name; | 472 | bb_applet_name = applet_using->name; |
482 | if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage (); | 473 | if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage(); |
483 | if(ENABLE_FEATURE_SUID) check_suid (applet_using); | 474 | if(ENABLE_FEATURE_SUID) check_suid(applet_using); |
484 | exit ((*(applet_using->main)) (argc, argv)); | 475 | exit((*(applet_using->main))(argc, argv)); |
485 | } | 476 | } |
486 | } | 477 | } |