[PATCH 8/8] busybox -- SELinux option support for coreutils: ver3

Bernhard Fischer rep.dot.nop at gmail.com
Thu Mar 8 13:46:35 UTC 2007


On Tue, Feb 27, 2007 at 02:40:38AM +0900, KaiGai Kohei wrote:
>I'm sorry, it was overlooked.
>The attached patch replace the above if-conditions by a single logical
>operation as you suggested.

would this block:
+       if (user && context_user_set(con, user))
+               bb_error_msg_and_die("failed to set new user '%s'", user);
+       if (type && context_type_set(con, type))
+               bb_error_msg_and_die("failed to set new type '%s'", type);
+       if (range && context_range_set(con, range))
+               bb_error_msg_and_die("failed to set new range '%s'", range);
+       if (role && context_role_set(con, role))
+               bb_error_msg_and_die("failed to set new role '%s'", role);

benefit from
const char const fmt[] = "failed to set new %s '%s'";
if (user && context_user_set(con, user))
        bb_error_msg_and_die(fmt, "user", user);
if (type && context_type_set(con, type))
        bb_error_msg_and_die(fmt, "type", type);
if (range && context_range_set(con, range))
        bb_error_msg_and_die(fmt, "range", range);
if (role && context_role_set(con, role))
        bb_error_msg_and_die(fmt, "role", role);

Can you reuse parts of chcon in runcon -- runcon_compute_new_context
comes to mind.

Reusing option_mask32 smaller than private opts?

+       opts = getopt32(argc, argv, "r:t:u:l:ch", &role, &type, &user,
&range);
+
+       if (!(opts & OPTS_CONTEXT_COMPONENT)) {
+               if (optind >= argc)
+                       bb_error_msg_and_die("must specify -c, -t, -u, -l, -r, or context");

Can you do this via opt_complementally="-1"; /* need at least one
non-option parm */
+               context = argv[optind++];
+       }


+       if (security_check_context(context_str(con)))
+               bb_error_msg_and_die("'%s' is not a valid context",
+                                    context_str(con));
+
+       if (setexeccon(context_str(con)))
+               bb_error_msg_and_die("unable to set up security context '%s'",
+                                    context_str(con));
+

perhaps some return a meaningful perror so you'd want
bb_perror_msg_and_die() ?



More information about the busybox mailing list