Clear rules from kernel.
authorJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Mon, 29 Nov 2010 05:50:59 +0000 (21:50 -0800)
committerJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Mon, 29 Nov 2010 05:50:59 +0000 (21:50 -0800)
src/smack.h
src/smack_rules.c

index 4ec8002..099dabb 100644 (file)
@@ -90,13 +90,22 @@ extern void smack_rule_set_delete(SmackRuleSet handle);
 extern int smack_rule_set_save_to_file(SmackRuleSet handle, const char *path);
 
 /*!
- * Write rules to SmackFS rules file.
+ * Write rules to /smack/load.
+ *
+ * @param handle handle to a rule set
+ * @param path path to the SmackFS load file
+ * @return 0 on success
+ */
+extern int smack_rule_set_save_to_kernel(SmackRuleSet handle, const char *path);
+
+/*!
+ * Clear rules from kernel.
  *
  * @param handle handle to a rules
  * @param path path to the rules file
  * @return 0 on success
  */
-extern int smack_rule_set_save_to_kernel(SmackRuleSet handle, const char *path);
+extern int smack_rule_set_clear_from_kernel(SmackRuleSet handle, const char *path);
 
 /*!
  * Add new rule to a rule set. Updates existing rule if there is already rule
index 6aabc88..ff18a41 100644 (file)
@@ -197,6 +197,36 @@ int smack_rule_set_save_to_kernel(SmackRuleSet handle, const char *path)
        return 0;
 }
 
+int smack_rule_set_clear_from_kernel(SmackRuleSet handle, const char *path)
+{
+       struct smack_subject *s, *stmp;
+       struct smack_object *o, *otmp;
+       FILE *file;
+       char str[6];
+       int err = 0;
+
+       file = fopen(path, "w+");
+       if (!file)
+               return -1;
+
+       HASH_ITER(hh, handle->subjects, s, stmp) {
+               HASH_ITER(hh, s->objects, o, otmp) {
+                       ac_to_kernel_str(0, str);
+
+                       err = fprintf(file, "%-23s %-23s %4s\n",
+                                     s->subject, o->object, str);
+
+                       if (err < 0) {
+                               fclose(file);
+                               return errno;
+                       }
+               }
+       }
+
+       fclose(file);
+       return 0;
+}
+
 int smack_rule_set_add(SmackRuleSet handle, const char *subject,
                       const char *object, const char *access_str,
                       SmackLabelSet labels)