aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@open.eurogiciel.org>2015-05-11 18:54:15 +0200
committerRob Landley <rob@landley.net>2015-05-31 12:12:34 -0500
commit7c8a2f4adf8502ab2ca921944427e35cde069b6c (patch)
tree5134971077e52e67ea8fb2d83dc9a7be8b88bb13 /toys/lsb
parent2d66e6a23822a500ecf6610411941e99127129c8 (diff)
downloadtoybox-7c8a2f4adf8502ab2ca921944427e35cde069b6c.tar.gz
mknod: Add -Z option
Change-Id: I23174fb7b54d029784e6d7460368128113090079
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/mknod.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/toys/lsb/mknod.c b/toys/lsb/mknod.c
index 35a127d6..0fec5a25 100644
--- a/toys/lsb/mknod.c
+++ b/toys/lsb/mknod.c
@@ -4,7 +4,7 @@
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mknod.html
-USE_MKNOD(NEWTOY(mknod, "<2>4m(mode):", TOYFLAG_BIN|TOYFLAG_UMASK))
+USE_MKNOD(NEWTOY(mknod, "<2>4m(mode):"USE_MKNOD_Z("Z:"), TOYFLAG_BIN|TOYFLAG_UMASK))
config MKNOD
bool "mknod"
@@ -16,12 +16,22 @@ config MKNOD
c or u for character device, p for named pipe (which ignores MAJOR/MINOR).
-m Mode (file permissions) of new device, in octal or u+x format
+
+config MKNOD_Z
+ bool
+ default y
+ depends on MKNOD && !TOYBOX_LSM_NONE
+ help
+ usage: mknod [-Z CONTEXT] ...
+
+ -Z Set security context to created file
*/
#define FOR_mknod
#include "toys.h"
GLOBALS(
+ char *arg_context;
char *m;
)
@@ -40,6 +50,13 @@ void mknod_main(void)
minor = atoi(toys.optargs[3]);
}
- if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor)))
+ if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor))) {
perror_exit("mknod %s failed", toys.optargs[0]);
+ }
+ else if (CFG_MKNOD_Z && (toys.optflags & FLAG_Z)) {
+ if (lsm_set_context(toys.optargs[0], TT.arg_context) < 0) {
+ unlink(toys.optargs[0]);
+ error_msg("'%s': bad -Z '%s'", toys.optargs[0], TT.arg_context);
+ }
+ }
}