From f078aa7fa1f38f0bf1e0a0eabe1da83726472f8f Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Sat, 29 Jan 2011 08:38:26 -0800 Subject: [PATCH] Added function smack_rule_set_list to iterate over rules. --- src/smack.c | 26 +++++++++++++++++++++++++- src/smack.h | 12 ++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/smack.c b/src/smack.c index 4af7282..a3d14ad 100644 --- a/src/smack.c +++ b/src/smack.c @@ -37,10 +37,10 @@ #define ACC_A 16 #define ACC_LEN 4 - struct smack_object { char *object; unsigned ac; + char acstr[ACC_LEN + 1]; UT_hash_handle hh; }; @@ -316,6 +316,29 @@ int smack_rule_set_have_access(SmackRuleSet handle, const char *subject, return ((o->ac & ac) == ac); } +int smack_rule_set_list(SmackRuleSet handle, int index, + const char **subject, const char **object, + const char **access) +{ + struct smack_subject *s, *stmp; + struct smack_object *o, *otmp; + int i = 0; + + HASH_ITER(hh, handle->subjects, s, stmp) { + HASH_ITER(hh, s->objects, o, otmp) { + if (i == index) { + *subject = s->subject; + *object = o->object; + *access = o->acstr; + return 0; + } + i++; + } + } + + return -1; +} + static int update_rule(struct smack_subject **subjects, const char *subject_str, const char *object_str, unsigned ac) @@ -342,6 +365,7 @@ static int update_rule(struct smack_subject **subjects, } o->ac = ac; + ac_to_config_str(ac, o->acstr); return 0; } diff --git a/src/smack.h b/src/smack.h index 1a3542b..22fc8ff 100644 --- a/src/smack.h +++ b/src/smack.h @@ -144,6 +144,18 @@ extern void smack_rule_set_remove_by_object(SmackRuleSet handle, extern int smack_rule_set_have_access(SmackRuleSet handle, const char *subject, const char *object, const char *access); +/*! + * Iterate over rules. + * + * @param index Index of the rule. + * @param subject Subject label of the rule. + * @param object Object label of the rule. + * @param access Access string for the rule. + */ +extern int smack_rule_set_list(SmackRuleSet handle, int index, + const char **subject, const char **object, + const char **access); + #ifdef __cplusplus } #endif -- 2.7.4