diff options
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/Android.mk | 23 | ||||
-rw-r--r-- | toolbox/df.c | 16 | ||||
-rw-r--r-- | toolbox/id.c | 7 | ||||
-rw-r--r-- | toolbox/ls.c | 12 | ||||
-rw-r--r-- | toolbox/setsebool.c | 39 |
5 files changed, 62 insertions, 35 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk index dbbce06..086ba0d 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -57,7 +57,11 @@ TOOLS := \ touch \ lsof \ du \ - md5 \ + md5 + +ifeq ($(HAVE_SELINUX),true) + +TOOLS += \ getenforce \ setenforce \ chcon \ @@ -67,6 +71,9 @@ TOOLS := \ setsebool \ load_policy +endif + + ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) TOOLS += r endif @@ -83,13 +90,17 @@ LOCAL_SRC_FILES := \ cp/cp.c cp/utils.c \ grep/grep.c grep/fastgrep.c grep/file.c grep/queue.c grep/util.c +LOCAL_SHARED_LIBRARIES := libcutils libc libusbhost + LOCAL_C_INCLUDES := bionic/libc/bionic -LOCAL_SHARED_LIBRARIES := \ - libcutils \ - libc \ - libusbhost \ - libselinux +ifeq ($(HAVE_SELINUX),true) + +LOCAL_CFLAGS += -DHAVE_SELINUX +LOCAL_SHARED_LIBRARIES += libselinux +LOCAL_C_INCLUDES += external/libselinux/include + +endif LOCAL_MODULE := toolbox diff --git a/toolbox/df.c b/toolbox/df.c index 9cd0743..63940a1 100644 --- a/toolbox/df.c +++ b/toolbox/df.c @@ -9,22 +9,16 @@ static int ok = EXIT_SUCCESS; static void printsize(long long n) { char unit = 'K'; - long long t; - - n *= 10; - - if (n > 1024*1024*10) { + n /= 1024; + if (n > 1024) { n /= 1024; unit = 'M'; } - - if (n > 1024*1024*10) { + if (n > 1024) { n /= 1024; unit = 'G'; } - - t = (n + 512) / 1024; - printf("%4lld.%1lld%c", t/10, t%10, unit); + printf("%4lld%c", n, unit); } static void df(char *s, int always) { @@ -47,7 +41,7 @@ static void df(char *s, int always) { } int df_main(int argc, char *argv[]) { - printf("Filesystem Size Used Free Blksize\n"); + printf("Filesystem Size Used Free Blksize\n"); if (argc == 1) { char s[2000]; FILE *f = fopen("/proc/mounts", "r"); diff --git a/toolbox/id.c b/toolbox/id.c index 8ec79c1..bc79288 100644 --- a/toolbox/id.c +++ b/toolbox/id.c @@ -4,7 +4,10 @@ #include <sys/types.h> #include <pwd.h> #include <grp.h> + +#ifdef HAVE_SELINUX #include <selinux/selinux.h> +#endif static void print_uid(uid_t uid) { @@ -31,7 +34,9 @@ int id_main(int argc, char **argv) { gid_t list[64]; int n, max; +#ifdef HAVE_SELINUX char *secctx; +#endif max = getgroups(64, list); if (max < 0) max = 0; @@ -48,10 +53,12 @@ int id_main(int argc, char **argv) print_gid(list[n]); } } +#ifdef HAVE_SELINUX if (getcon(&secctx) == 0) { printf(" context=%s", secctx); free(secctx); } +#endif printf("\n"); return 0; } diff --git a/toolbox/ls.c b/toolbox/ls.c index e530521..a4db99c 100644 --- a/toolbox/ls.c +++ b/toolbox/ls.c @@ -5,7 +5,9 @@ #include <dirent.h> #include <errno.h> +#ifdef HAVE_SELINUX #include <selinux/selinux.h> +#endif #include <sys/stat.h> #include <unistd.h> @@ -258,7 +260,11 @@ static int listfile_maclabel(const char *path, int flags) return -1; } +#ifdef HAVE_SELINUX lgetfilecon(path, &maclabel); +#else + maclabel = strdup("-"); +#endif if (!maclabel) { return -1; } @@ -270,12 +276,12 @@ static int listfile_maclabel(const char *path, int flags) switch(s.st_mode & S_IFMT) { case S_IFLNK: { char linkto[256]; - ssize_t len; + int len; len = readlink(path, linkto, sizeof(linkto)); if(len < 0) return -1; - if((size_t)len > sizeof(linkto)-1) { + if(len > sizeof(linkto)-1) { linkto[sizeof(linkto)-4] = '.'; linkto[sizeof(linkto)-3] = '.'; linkto[sizeof(linkto)-2] = '.'; @@ -301,7 +307,7 @@ static int listfile_maclabel(const char *path, int flags) static int listfile(const char *dirname, const char *filename, int flags) { - if ((flags & (LIST_LONG | LIST_SIZE | LIST_CLASSIFY | LIST_MACLABEL)) == 0) { + if ((flags & LIST_LONG | LIST_SIZE | LIST_CLASSIFY | LIST_MACLABEL) == 0) { printf("%s\n", filename); return 0; } diff --git a/toolbox/setsebool.c b/toolbox/setsebool.c index f79a612..4a3d87d 100644 --- a/toolbox/setsebool.c +++ b/toolbox/setsebool.c @@ -9,26 +9,35 @@ #include <errno.h> static int do_setsebool(int nargs, char **args) { - const char *name = args[1]; - const char *value = args[2]; - SELboolean b; + SELboolean *b = alloca(nargs * sizeof(SELboolean)); + char *v; + int i; if (is_selinux_enabled() <= 0) return 0; - b.name = name; - if (!strcmp(value, "1") || !strcasecmp(value, "true") || !strcasecmp(value, "on")) - b.value = 1; - else if (!strcmp(value, "0") || !strcasecmp(value, "false") || !strcasecmp(value, "off")) - b.value = 0; - else { - fprintf(stderr, "setsebool: invalid value %s\n", value); - return -1; + for (i = 1; i < nargs; i++) { + char *name = args[i]; + v = strchr(name, '='); + if (!v) { + fprintf(stderr, "setsebool: argument %s had no =\n", name); + return -1; + } + *v++ = 0; + b[i-1].name = name; + if (!strcmp(v, "1") || !strcasecmp(v, "true") || !strcasecmp(v, "on")) + b[i-1].value = 1; + else if (!strcmp(v, "0") || !strcasecmp(v, "false") || !strcasecmp(v, "off")) + b[i-1].value = 0; + else { + fprintf(stderr, "setsebool: invalid value %s\n", v); + return -1; + } } - if (security_set_boolean_list(1, &b, 0) < 0) + if (security_set_boolean_list(nargs - 1, b, 0) < 0) { - fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno)); + fprintf(stderr, "setsebool: unable to set booleans: %s", strerror(errno)); return -1; } @@ -37,8 +46,8 @@ static int do_setsebool(int nargs, char **args) { int setsebool_main(int argc, char **argv) { - if (argc != 3) { - fprintf(stderr, "Usage: %s name value\n", argv[0]); + if (argc < 2) { + fprintf(stderr, "Usage: %s name=value...\n", argv[0]); exit(1); } |