ip link: add VLAN support
[oweals/busybox.git] / selinux / matchpathcon.c
index 4fa95b0efd4ee821704171ccc2f96b62a67e1d4f..9e5728eb3b8c31aa6a2ad79ed63af7b8b01b0cdb 100644 (file)
@@ -3,8 +3,19 @@
  *                  based on libselinux-1.32
  * Port to busybox: KaiGai Kohei <kaigai@kaigai.gr.jp>
  *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-#include "busybox.h"
+
+//usage:#define matchpathcon_trivial_usage
+//usage:       "[-n] [-N] [-f file_contexts_file] [-p prefix] [-V]"
+//usage:#define matchpathcon_full_usage "\n\n"
+//usage:       "       -n      Don't display path"
+//usage:     "\n       -N      Don't use translations"
+//usage:     "\n       -f      Use alternate file_context file"
+//usage:     "\n       -p      Use prefix to speed translations"
+//usage:     "\n       -V      Verify file context on disk matches defaults"
+
+#include "libbb.h"
 
 static int print_matchpathcon(char *path, int noprint)
 {
@@ -17,7 +28,7 @@ static int print_matchpathcon(char *path, int noprint)
        if (!noprint)
                printf("%s\t%s\n", path, buf);
        else
-               printf("%s\n", buf);
+               puts(buf);
 
        freecon(buf);
        return 0;
@@ -29,19 +40,20 @@ static int print_matchpathcon(char *path, int noprint)
 #define OPT_PREFIX      (1<<3)  /* -p */
 #define OPT_VERIFY      (1<<4)  /* -V */
 
-int matchpathcon_main(int argc, char **argv)
+int matchpathcon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int matchpathcon_main(int argc UNUSED_PARAM, char **argv)
 {
        int error = 0;
        unsigned opts;
        char *fcontext, *prefix, *path;
 
-       opt_complementary = "-1:" /* at least one param reqd */
-               "f--p:p--f"; /* mutually exclusive */
-       opts = getopt32(argc, argv, "nNf:p:V", &fcontext, &prefix);
+       opt_complementary = "-1" /* at least one param reqd */
+               ":?:f--p:p--f"; /* mutually exclusive */
+       opts = getopt32(argv, "nNf:p:V", &fcontext, &prefix);
        argv += optind;
 
        if (opts & OPT_NOT_TRANS) {
-               set_matchpathcon_flags(NOTRANS);
+               set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
        }
        if (opts & OPT_FCONTEXT) {
                if (matchpathcon_init(fcontext))
@@ -52,12 +64,12 @@ int matchpathcon_main(int argc, char **argv)
                        bb_perror_msg_and_die("error while processing %s", prefix);
        }
 
-       while((path = *argv++) != NULL) {
+       while ((path = *argv++) != NULL) {
                security_context_t con;
                int rc;
 
                if (!(opts & OPT_VERIFY)) {
-                       error += print_matchpathcon(path, opt & OPT_NOT_PRINT);
+                       error += print_matchpathcon(path, opts & OPT_NOT_PRINT);
                        continue;
                }