Add runcon(1).
authorElliott Hughes <enh@google.com>
Mon, 23 Mar 2015 17:46:20 +0000 (12:46 -0500)
committerElliott Hughes <enh@google.com>
Mon, 23 Mar 2015 17:46:20 +0000 (12:46 -0500)
toys/pending/runcon.c [new file with mode: 0644]

diff --git a/toys/pending/runcon.c b/toys/pending/runcon.c
new file mode 100644 (file)
index 0000000..bf13442
--- /dev/null
@@ -0,0 +1,29 @@
+/* runcon.c - Run command in specified security context
+ *
+ * Copyright 2015 The Android Open Source Project
+
+USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN))
+
+config RUNCON
+  bool "runcon"
+  depends on TOYBOX_SELINUX
+  default n
+  help
+    usage: runcon CONTEXT COMMAND [ARGS...]
+
+    Run a command in a specified security context.
+*/
+
+#define FOR_runcon
+#include "toys.h"
+
+void runcon_main(void)
+{
+  char *context = *toys.optargs;
+
+  if (setexeccon(context))
+    error_exit("Could not set context to %s: %s", context, strerror(errno));
+
+  toys.optargs++;
+  xexec(toys.optargs);
+}