X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=applets%2Fapplets.c;h=bd8cfec5da2356ace2e14c4b57be656cb9f47dc7;hb=eea561871b45a2335ab6a09f14dad627ffcdc1cd;hp=aea116add254897338d32ae204b699528d00eeda;hpb=e15d7573a1263fb364d1678c3a46be47a8b5e5ea;p=oweals%2Fbusybox.git diff --git a/applets/applets.c b/applets/applets.c index aea116add..bd8cfec5d 100644 --- a/applets/applets.c +++ b/applets/applets.c @@ -14,8 +14,6 @@ #include "busybox.h" #include -#include -#include #include #include @@ -43,7 +41,6 @@ const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1); #ifdef CONFIG_FEATURE_SUID_CONFIG -#include #include #include "pwd_.h" #include "grp_.h" @@ -99,7 +96,7 @@ static char *get_trimmed_slice(char *s, char *e) /* Next, advance past all leading space and return a ptr to the * first non-space char; possibly the terminating nul. */ - return (char *) bb_skip_whitespace(s); + return skip_whitespace(s); } @@ -240,7 +237,7 @@ static void parse_config_file(void) /* Get the specified mode. */ - e = (char *) bb_skip_whitespace(e+1); + e = skip_whitespace(e+1); for (i=0 ; i < 3 ; i++) { const char *q; @@ -253,7 +250,7 @@ static void parse_config_file(void) /* Now get the the user/group info. */ - s = (char *) bb_skip_whitespace(e); + s = skip_whitespace(e); /* Note: We require whitespace between the mode and the * user/group info. */ @@ -346,22 +343,15 @@ static void check_suid (struct BB_applet *applet) bb_error_msg_and_die ("You have no permission to run this applet!"); if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */ - if (setegid (sct->m_gid)) - bb_error_msg_and_die - ("BusyBox binary has insufficient rights to set proper GID for applet!"); - } else - setgid (rgid); /* no sgid -> drop */ - - if (sct->m_mode & S_ISUID) { - if (seteuid (sct->m_uid)) - bb_error_msg_and_die - ("BusyBox binary has insufficient rights to set proper UID for applet!"); - } else - setuid (ruid); /* no suid -> drop */ + xsetgid(sct->m_gid); + } else xsetgid(rgid); /* no sgid -> drop */ + + if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid); + else xsetuid(ruid); /* no suid -> drop */ } else { /* default: drop all privileges */ - setgid (rgid); - setuid (ruid); + xsetgid(rgid); + xsetuid(ruid); } return; } else { @@ -377,11 +367,10 @@ static void check_suid (struct BB_applet *applet) #endif if (applet->need_suid == _BB_SUID_ALWAYS) { - if (geteuid () != 0) - bb_error_msg_and_die ("This applet requires root privileges!"); + if (geteuid()) bb_error_msg_and_die("Applet requires root privileges!"); } else if (applet->need_suid == _BB_SUID_NEVER) { - setgid (rgid); /* drop all privileges */ - setuid (ruid); + xsetgid(rgid); /* drop all privileges */ + xsetuid(ruid); } } #else @@ -422,14 +411,14 @@ static const char *unpack_usage_messages(void) case -1: /* error */ exit(1); case 0: /* child */ - bb_full_write(input[1], packed_usage, sizeof(packed_usage)); + full_write(input[1], packed_usage, sizeof(packed_usage)); exit(0); } /* parent */ close(input[1]); buf = xmalloc(SIZEOF_usage_messages); - bb_full_read(output[0], buf, SIZEOF_usage_messages); + full_read(output[0], buf, SIZEOF_usage_messages); return buf; } @@ -457,33 +446,32 @@ void bb_show_usage (void) exit (bb_default_error_retval); } -static int applet_name_compare (const void *x, const void *y) +static int applet_name_compare(const void *name, const void *vapplet) { - const char *name = x; - const struct BB_applet *applet = y; + const struct BB_applet *applet = vapplet; - return strcmp (name, applet->name); + return strcmp(name, applet->name); } extern const size_t NUM_APPLETS; -struct BB_applet *find_applet_by_name (const char *name) +struct BB_applet *find_applet_by_name(const char *name) { - return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet), + return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), applet_name_compare); } -void run_applet_by_name (const char *name, int argc, char **argv) +void run_applet_by_name(const char *name, int argc, char **argv) { - if(ENABLE_FEATURE_SUID_CONFIG) parse_config_file (); + if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file(); - if(!strncmp(name, "busybox", 7)) busybox_main(argc, argv); + if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv); /* Do a binary search to find the applet entry given the name. */ applet_using = find_applet_by_name(name); - if(applet_using) { + if (applet_using) { bb_applet_name = applet_using->name; - if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage (); - if(ENABLE_FEATURE_SUID) check_suid (applet_using); - exit ((*(applet_using->main)) (argc, argv)); + if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage(); + if(ENABLE_FEATURE_SUID) check_suid(applet_using); + exit((*(applet_using->main))(argc, argv)); } }