busybox -- SELinux option support for coreutils: ver3
PATCH 2/8 busybox -- SELinux option support for coreutils: ver3
[2/8] busybox-coreutils-02-copy.v3.patch
- cp: -Z,-c option support.
-c option: security context is preserved during file copy.
- mv
In SELinux, it is recommended to preserve security context when file is moved. By this patch, file context is preserved during file move.
- install
When file is copied by install, security context of installed file becomes different from value configured in file_contexts file. By this patch, security context is set according to file_contexts file. -Z option: security context can be set during file copy.
libbb.h +7 -2
@@ -737,7 +737,7 @@uint32_t *crc32_filltable (int endian); -enum {/* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ +enum {/* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depends on them. */ FILEUTILS_PRESERVE_STATUS =1 ,FILEUTILS_DEREFERENCE =2 ,FILEUTILS_RECUR =4 ,
@@ -745,9 +745,14 @@FILEUTILS_INTERACTIVE =0x10 ,FILEUTILS_MAKE_HARDLINK =0x20 ,FILEUTILS_MAKE_SOFTLINK =0x40 , +#if ENABLE_SELINUX +FILEUTILS_PRESERVE_SECURITY_CONTEXT =0x80 , +FILEUTILS_SET_SECURITY_CONTEXT =0x100 +#endif }; -#define FILEUTILS_CP_OPTSTR "pdRfils" +#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c\b") +extern const char *applet_name;extern const char BB_BANNER [];
cp.c +7 -0
@@ -3,6 +3,7 @@* Mini cp implementation for busybox * * Copyright (C) 2000 by Matt Kraai <[email protected]> +* SELinux support by Yuichi Nakamura <[email protected]> * * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. */
@@ -50,6 +51,12 @@if (flags & OPT_H) ... // deref command-line params only */ +#if ENABLE_SELINUX +if (flags &FILEUTILS_PRESERVE_SECURITY_CONTEXT ) { +selinux_or_die (); + } +#endif + flags ^=FILEUTILS_DEREFERENCE ;/* The sense of this flag was reversed. */ if (optind +2 > argc) {
mv.c +7 -2
@@ -3,6 +3,7 @@* Mini mv implementation for busybox * * Copyright (C) 2000 by Matt Kraai <[email protected]> +* SELinux support by Yuichi Nakamura <[email protected]> * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
@@ -44,6 +45,7 @@unsigned long flags;int dest_exists;int status =0 ; +int copy_flag =0 ;#if ENABLE_FEATURE_MV_LONG_OPTIONS applet_long_options = mv_long_options;
@@ -113,8 +115,11 @@ goto RET_1; } } -if ((copy_file (*argv, dest, -FILEUTILS_RECUR |FILEUTILS_PRESERVE_STATUS ) >=0 ) && + copy_flag =FILEUTILS_RECUR |FILEUTILS_PRESERVE_STATUS ; +#if ENABLE_SELINUX + copy_flag |=FILEUTILS_PRESERVE_SECURITY_CONTEXT ; +#endif +if ((copy_file (*argv, dest, copy_flag) >=0 ) && (remove_file (*argv,FILEUTILS_RECUR |FILEUTILS_FORCE ) >=0 )) { goto RET_0; }
install.c +77 -4
116 lines not on this page · raw message
copy_file.c +41 -1
61 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 52 lines · On Sat, 24 Feb 2007 16:01:14 +0100 Denis Vlasenko wrote:
Quoted 13 lines · Yuichi Nakamura
[2/8] busybox-coreutils-02-copy.v3.patch
- cp: -Z,-c option support.
-c option: security context is preserved during file copy.
- mv
In SELinux, it is recommended to preserve security context when file is moved. By this patch, file context is preserved during file move.
- install
When file is copied by install, security context of installed file becomes different from value configured infile_contextsfile. By this patch, security context is set according tofile_contextsfile. -Z option: security context can be set during file copy.Quoted 1 line
Signed-off-by Yuichi Nakamura <[email protected]>FILEUTILS_MAKE_SOFTLINK = 0x40,(quoted diff) +12
-1+#if ENABLE_SELINUX + FILEUTILS_PRESERVE_SECURITY_CONTEXT = 0x80, + FILEUTILS_SET_SECURITY_CONTEXT = 0x100 +#endif }; -#define FILEUTILS_CP_OPTSTR "pdRfils" +#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c\b") + extern const char *applet_name; { "owner", 0, NULL, 'o' }, +#if ENABLE_SELINUX + { "context", 1, NULL, 'Z' }, + { "preserve_context", 0, NULL, '\b'}, + { "preserve-context", 0, NULL, '\b'}, + +#endif { 0, 0, 0, 0 }Hmmm... we typically use high ascii values for this kind of "fake" option chars. Example in
wget.c:static const struct option wget_long_options[] = { ... { "user-agent", required_argument, NULL, 'U' }, { "passive-ftp", no_argument, NULL, 0xff }, { "header", required_argument, NULL, 0xfe }, { 0, 0, 0, 0 } }; applet_long_options = wget_long_options; #endif opt_complementary = "-1" USE_FEATURE_WGET_LONG_OPTIONS(":\xfe::"); opt = getopt32(argc, argv, "cqO:P:Y:U:", ...);
Quoted 5 lines
Notice that in this example we avoid giving "strange" chars to getopt32 *at all*, preventing our applets from having "hidden" options a-la "wget $'-\xff' ftp://kernel.org/".
Can you avoid passing '\b' to getopt32 in install etc?
Fixed. Using "0xff" instead.
Quoted 29 lines
(quoted diff) +2
-0+ bb_error_msg("warning: ignoring --preserve-context. " + "The kernel is not SELinux-enabled.\n" );
bb_error_msgdon't need trailing '\n'.
I already mentioned that in the previous round of review.(quoted diff) +19
-0+#if ENABLE_SELINUX + if ((flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) && is_selinux_enabled() > 0){ + security_context_t con; + if (lgetfilecon (source, &con) >= 0){ + if (setfscreatecon(con) < 0) { + bb_perror_msg ("cannot set setfscreatecon %s", con); + freecon(con); + return -1; + } + }else{ + if( errno == ENOTSUP || errno == ENODATA ) { + setfscreatecon(NULL); + } else { + bb_perror_msg ("cannot lgetfilecon %s", source); + return -1; + } + } + } +#endif
Quoted 1 line
Usage of whitespace is very different from the rest of busybox code here.
Fixed. And I found other bad usage of white space, and fixed.
Quoted 3 lines
--
vda
Attached is revised patch(v4).
--
Yuichi Nakamura
Hitachi Software Engineering Co., Ltd. SELinux Policy Editor: http://seedit.sourceforge.net/
libbb.h +6 -2
@@ -737,7 +737,7 @@uint32_t *crc32_filltable (int endian); -enum {/* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ +enum {/* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depends on them. */ FILEUTILS_PRESERVE_STATUS =1 ,FILEUTILS_DEREFERENCE =2 ,FILEUTILS_RECUR =4 ,
@@ -745,9 +745,13 @@FILEUTILS_INTERACTIVE =0x10 ,FILEUTILS_MAKE_HARDLINK =0x20 ,FILEUTILS_MAKE_SOFTLINK =0x40 , +#if ENABLE_SELINUX +FILEUTILS_PRESERVE_SECURITY_CONTEXT =0x80 , +FILEUTILS_SET_SECURITY_CONTEXT =0x100 +#endif }; -#define FILEUTILS_CP_OPTSTR "pdRfils" +#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c")extern const char *applet_name;extern const char BB_BANNER [];
cp.c +7 -0
@@ -3,6 +3,7 @@* Mini cp implementation for busybox * * Copyright (C) 2000 by Matt Kraai <[email protected]> +* SELinux support by Yuichi Nakamura <[email protected]> * * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. */
@@ -50,6 +51,12 @@if (flags & OPT_H) ... // deref command-line params only */ +#if ENABLE_SELINUX +if (flags &FILEUTILS_PRESERVE_SECURITY_CONTEXT ) { +selinux_or_die (); + } +#endif + flags ^=FILEUTILS_DEREFERENCE ;/* The sense of this flag was reversed. */ if (optind +2 > argc) {
mv.c +7 -2
@@ -3,6 +3,7 @@* Mini mv implementation for busybox * * Copyright (C) 2000 by Matt Kraai <[email protected]> +* SELinux support by Yuichi Nakamura <[email protected]> * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
@@ -44,6 +45,7 @@unsigned long flags;int dest_exists;int status =0 ; +int copy_flag =0 ;#if ENABLE_FEATURE_MV_LONG_OPTIONS applet_long_options = mv_long_options;
@@ -113,8 +115,11 @@ goto RET_1; } } -if ((copy_file (*argv, dest, -FILEUTILS_RECUR |FILEUTILS_PRESERVE_STATUS ) >=0 ) && + copy_flag =FILEUTILS_RECUR |FILEUTILS_PRESERVE_STATUS ; +#if ENABLE_SELINUX + copy_flag |=FILEUTILS_PRESERVE_SECURITY_CONTEXT ; +#endif +if ((copy_file (*argv, dest, copy_flag) >=0 ) && (remove_file (*argv,FILEUTILS_RECUR |FILEUTILS_FORCE ) >=0 )) { goto RET_0; }
install.c +76 -4
115 lines not on this page · raw message
copy_file.c +41 -1
61 lines not on this page · raw message