introduce and use setfscreatecon_or_die
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 12 Mar 2007 18:22:55 +0000 (18:22 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 12 Mar 2007 18:22:55 +0000 (18:22 -0000)
(patch by Yuichi Nakamura <ynakam@hitachisoft.jp>)
runcon: *yet another* fix for vda's brainfart :(

coreutils/install.c
coreutils/libcoreutils/getopt_mk_fifo_nod.c
coreutils/mkdir.c
include/libbb.h
libbb/copy_file.c
libbb/selinux_common.c
selinux/runcon.c

index 1f65407b12b809e80b49d89654a83c5ae1b7f99b..a58a23b6e35906ef5c141a29a5e20012dabb1beb 100644 (file)
@@ -110,9 +110,7 @@ int install_main(int argc, char **argv)
        }
        if (flags & OPT_SET_SECURITY_CONTEXT) {
                selinux_or_die();
-               if (setfscreatecon(scontext) < 0) {
-                       bb_error_msg_and_die("setfscreatecon(%s)", scontext); // perror?
-               }
+               setfscreatecon_or_die(scontext);
                use_default_selinux_context = 0;
                copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
        }
index 2e0c2743949e7a6190f74fe07e58035b917fd787..32fa9bedea30d56d0893e7b47d4005e2507d4261 100644 (file)
@@ -43,10 +43,7 @@ mode_t getopt_mk_fifo_nod(int argc, char **argv)
 #if ENABLE_SELINUX
        if (opt & 2) {
                selinux_or_die();
-               if (setfscreatecon(scontext)) {
-                       bb_error_msg_and_die("cannot set default file creation context "
-                                             "to %s", scontext);
-               }
+               setfscreatecon_or_die(scontext);
        }
 #endif
 
index 93ded1dd5742009140ac8dfbaafc4da276ea589c..690e4ab4094f2184d28e18063ad6e6334945d625 100644 (file)
@@ -62,10 +62,7 @@ int mkdir_main(int argc, char **argv)
 #if ENABLE_SELINUX
        if (opt & 4) {
                selinux_or_die();
-               if (setfscreatecon(scontext)) {
-                       bb_error_msg_and_die("cannot set default file creation context "
-                                             "to %s", scontext);
-               }
+               setfscreatecon_or_die(scontext);
        }
 #endif
 
index 69652b6664c27647e5a3899d935d5033422051a5..401fce4cf5b5e1dc67e8f999ee5419d8fde5265a 100644 (file)
@@ -601,6 +601,7 @@ extern void renew_current_security_context(void);
 extern void set_current_security_context(security_context_t sid);
 extern context_t set_security_context_component(security_context_t cur_context,
                                                char *user, char *role, char *type, char *range);
+extern void setfscreatecon_or_die(security_context_t scontext);
 #endif
 extern void selinux_or_die(void);
 extern int restricted_shell(const char *shell);
index 6391824aab7a78ed533e1da7f2c99b3ae58221a4..07564afd03fbcab395e7129df2defe7fd268cf1b 100644 (file)
@@ -74,7 +74,7 @@ int copy_file(const char *source, const char *dest, int flags)
                        }
                } else {
                        if (errno == ENOTSUP || errno == ENODATA) {
-                               setfscreatecon(NULL);
+                               setfscreatecon_or_die(NULL);
                        } else {
                                bb_perror_msg("cannot lgetfilecon %s", source);
                                return -1;
index 70d63a4659f607ed2e5021fa826647c1fc0b1a11..d506f0636ba230100d1cc3084ee8305f8fbdb7d6 100644 (file)
@@ -28,3 +28,13 @@ error:
        context_free(con);
        return NULL;
 }
+
+void setfscreatecon_or_die(security_context_t scontext)
+{
+       if (setfscreatecon(scontext) < 0) {
+               /* Can be NULL. All known printf implementations
+                * display "(null)", "<null>" etc */
+               bb_perror_msg_and_die("cannot set default "
+                               "file creation context to %s", scontext);
+       }
+}
index 24e436febdccbbff5e9c3bb74e15dbcfbfa90c2a..8888ccc7b33219a537f4e6669569f6bf1c1f9957 100644 (file)
@@ -132,6 +132,6 @@ int runcon_main(int argc, char *argv[])
 
        execvp(argv[0], argv);
 
-       bb_perror_msg_and_die("cannot execute '%s'", command);
+       bb_perror_msg_and_die("cannot execute '%s'", argv[0]);
        return 1;
 }