From 3499bcae59bee70562b741a2ccabffc6cf14f555 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Sun, 28 Nov 2010 21:50:59 -0800 Subject: [PATCH] Clear rules from kernel. --- src/smack.h | 13 +++++++++++-- src/smack_rules.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/smack.h b/src/smack.h index 4ec8002..099dabb 100644 --- a/src/smack.h +++ b/src/smack.h @@ -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 diff --git a/src/smack_rules.c b/src/smack_rules.c index 6aabc88..ff18a41 100644 --- a/src/smack_rules.c +++ b/src/smack_rules.c @@ -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) -- 2.7.4