Thank you for taking a look. I have attached a new patch that is diffed against current.
Tom On Wed, Feb 17, 2016 at 3:56 PM, Rob Landley <[email protected]> wrote: > On Wed, Feb 17, 2016 at 4:59 PM, Tom Cherry <[email protected]> wrote: >> Ping - Can this be looked at? >> >> Thank you >> Tom >> >> On Mon, Feb 8, 2016 at 3:57 PM, Tom Cherry <[email protected]> wrote: >>> >>> Apologies for the previous email mangling the patch. This one should >>> be correct... > > It went on my todo list because #including selinux.h directly is > ordinarily frowned upon (there's a lib/lsm.h wrapping that and smack > into a common interface), but this is a toys/android command so it > only builds on android anyway, so... > > $ git am attachment.bin > Applying: Add support for getprop -Z > error: patch failed: toys/android/getprop.c:21 > error: toys/android/getprop.c: patch does not apply > Patch failed at 0001 Add support for getprop -Z > When you have resolved this problem run "git am --resolved". > > Hmmm... [dig dig...] > > The whitespace damage is that the "previous" file version it expects > to apply to ends with "#else", which went away in the first cleanup > (commit 5b493dc48db0 in April of last year). > > There have been three commits to this command since the original > submission, could you rediff against current please? > > Rob
From d50dd3a6a02b00f1c7713800939a09e377277e92 Mon Sep 17 00:00:00 2001 From: Tom Cherry <[email protected]> Date: Wed, 17 Feb 2016 16:27:08 -0800 Subject: [PATCH] Add support for getprop -Z Add support for a -Z option to getprop that will either print the SELabel of a given property if one is provided or print all properties that have been set along with their SELabel. Also, correct a memory leak when freeing TT.nv. --- toys/android/getprop.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/toys/android/getprop.c b/toys/android/getprop.c index 09bb0f0..cce53a6 100644 --- a/toys/android/getprop.c +++ b/toys/android/getprop.c @@ -2,7 +2,7 @@ * * Copyright 2015 The Android Open Source Project -USE_GETPROP(NEWTOY(getprop, ">2", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_GETPROP(NEWTOY(getprop, ">2Z", TOYFLAG_USR|TOYFLAG_SBIN)) config GETPROP bool "getprop" @@ -19,30 +19,83 @@ config GETPROP #include <cutils/properties.h> +#include <selinux/android.h> +#include <selinux/label.h> +#include <selinux/selinux.h> + GLOBALS( size_t size; char **nv; // name/value pairs: even=name, odd=value + struct selabel_handle *handle; ) +static char *get_property_context(char *property) +{ + char *context = NULL; + + if (selabel_lookup(TT.handle, &context, property, 1)) { + perror_exit("unable to lookup label for \"%s\"", property); + } + return context; +} + static void add_property(char *name, char *value, void *unused) { if (!(TT.size&31)) TT.nv = xrealloc(TT.nv, (TT.size+32)*2*sizeof(char *)); TT.nv[2*TT.size] = xstrdup(name); - TT.nv[1+2*TT.size++] = xstrdup(value); + if (toys.optflags & FLAG_Z) { + TT.nv[1+2*TT.size++] = get_property_context(name); + } else { + TT.nv[1+2*TT.size++] = xstrdup(value); + } +} + +// Needed to supress extraneous "Loaded property_contexts from" message +int selinux_log_callback(int type, const char *fmt, ...) { + va_list ap; + + if (type == SELINUX_INFO) return 0; + va_start(ap, fmt); + verror_msg(fmt, 0, ap); + va_end(ap); + return 0; } void getprop_main(void) { + if (toys.optflags & FLAG_Z) { + union selinux_callback cb; + + cb.func_log = selinux_log_callback; + selinux_set_callback(SELINUX_CB_LOG, cb); + TT.handle = selinux_android_prop_context_handle(); + if (!TT.handle) error_exit("unable to get selinux property context handle"); + } + if (*toys.optargs) { - property_get(*toys.optargs, toybuf, toys.optargs[1] ? toys.optargs[1] : ""); - puts(toybuf); + if (toys.optflags & FLAG_Z) { + char *context = get_property_context(*toys.optargs); + + puts(context); + if (CFG_TOYBOX_FREE) free(context); + } else { + property_get(*toys.optargs, toybuf, toys.optargs[1] ? toys.optargs[1] : ""); + puts(toybuf); + } } else { size_t i; if (property_list((void *)add_property, 0)) error_exit("property_list"); qsort(TT.nv, TT.size, 2*sizeof(char *), qstrcmp); for (i = 0; i<TT.size; i++) printf("[%s]: [%s]\n", TT.nv[i*2],TT.nv[1+i*2]); - if (CFG_TOYBOX_FREE) free(TT.nv); + if (CFG_TOYBOX_FREE) { + for (i = 0; i<TT.size; i++) { + free(TT.nv[i*2]); + free(TT.nv[1+i*2]); + } + free(TT.nv); + } } + if (CFG_TOYBOX_FREE && (toys.optflags & FLAG_Z)) selabel_close(TT.handle); } -- 2.7.0.rc3.207.g0ac5344
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
