utils: stdin support for smackload
authorJarkko Sakkinen <jarkko.sakkinen@iki.fi>
Sun, 11 Dec 2011 17:02:49 +0000 (19:02 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@iki.fi>
Sun, 11 Dec 2011 17:03:31 +0000 (19:03 +0200)
utils/common.c
utils/common.h
utils/smackload.c

index 76cbad4..bf9d2f7 100644 (file)
@@ -59,16 +59,13 @@ struct cipso {
        struct cipso_mapping *last;
 };
 
-static int apply_rules_file(int fd, int clear);
 static int apply_rules_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
-
 static int apply_cipso_file(const char *path);
 static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
 static struct cipso *cipso_new(const char *path);
 static void cipso_free(struct cipso *cipso);
 static int cipso_apply(struct cipso *cipso);
 
-
 int is_smackfs_mounted(void)
 {
        struct statfs sfs;
@@ -146,7 +143,7 @@ int apply_cipso(const char *path)
        return 0;
 }
 
-static int apply_rules_file(int fd, int clear)
+int apply_rules_file(int fd, int clear)
 {
        struct smack_accesses *rules = NULL;
        int ret = 0;
index 43ebb91..cde6209 100644 (file)
@@ -36,5 +36,6 @@ int clear(void);
 int is_smackfs_mounted(void);
 int apply_rules(const char *path, int clear);
 int apply_cipso(const char *path);
+int apply_rules_file(int fd, int clear);
 
 #endif // COMMON_H
index fad0e0b..5374552 100644 (file)
@@ -19,6 +19,7 @@
  *
  * Authors:
  * Brian McGillion <brian.mcgillion@intel.com>
+ * Jarkko Sakkinen <jarkko.sakkinen@intel.com>
  */
 
 #include "common.h"
@@ -37,6 +38,11 @@ int main(int argc, char **argv)
        int clear = 0;
        int c;
 
+       if (is_smackfs_mounted() != 1) {
+               fprintf(stderr, "SmackFS is not mounted.\n");
+               exit(1);
+       }
+
        while ((c = getopt(argc, argv, "c")) != -1) {
                switch (c) {
                case 'c':
@@ -47,17 +53,16 @@ int main(int argc, char **argv)
                }
        }
 
-       if (optind == argc)
-               usage(argv[0]);
-
-       if (is_smackfs_mounted() != 1) {
-               fprintf(stderr, "SmackFS is not mounted.\n");
-               exit(1);
-       }
-
-       if (apply_rules(argv[optind], clear)) {
-               perror("apply_rules");
-               exit(1);
+       if (optind == argc) {
+               if (apply_rules_file(STDIN_FILENO, clear)) {
+                       perror("apply_rules_file");
+                       exit(1);
+               }
+       } else {
+               if (apply_rules(argv[optind], clear)) {
+                       perror("apply_rules");
+                       exit(1);
+               }
        }
 
        exit(0);