[PATCH-v2 2/6] ima: added new template helper lookup_template_desc_by_fmt()

From: Roberto Sassu
Date: Tue Nov 19 2013 - 07:36:18 EST


This patch adds a new helper to search a template descriptor by its format.
Also, the old function lookup_template_desc(), which performs the search
by name, has been renamed to lookup_template_desc_by_name().

Signed-off-by: Roberto Sassu <roberto.sassu@xxxxxxxxx>
---
security/integrity/ima/ima_template.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 33c911a..c849723 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -38,7 +38,7 @@ static struct ima_template_field supported_fields[] = {
};

static struct ima_template_desc *ima_template;
-static struct ima_template_desc *lookup_template_desc(const char *name);
+static struct ima_template_desc *lookup_template_desc_by_name(const char *name);
static struct ima_template_field *lookup_template_field(const char *field_id);

static int __init ima_template_setup(char *str)
@@ -53,7 +53,7 @@ static int __init ima_template_setup(char *str)
* Verify that a template with the supplied name exists.
* If not, use CONFIG_IMA_DEFAULT_TEMPLATE.
*/
- template_desc = lookup_template_desc(str);
+ template_desc = lookup_template_desc_by_name(str);
if (!template_desc) {
pr_err("IMA: template %s not found, using %s\n",
str, CONFIG_IMA_DEFAULT_TEMPLATE);
@@ -117,7 +117,7 @@ static int __init ima_template_fmt_setup(char *str)
}
__setup("ima_template_fmt=", ima_template_fmt_setup);

-static struct ima_template_desc *lookup_template_desc(const char *name)
+static struct ima_template_desc *lookup_template_desc_by_name(const char *name)
{
int i;

@@ -129,6 +129,18 @@ static struct ima_template_desc *lookup_template_desc(const char *name)
return NULL;
}

+static struct ima_template_desc *lookup_template_desc_by_fmt(const char *fmt)
+{
+ struct ima_template_desc *desc;
+
+ list_for_each_entry(desc, &defined_templates[0].list, list) {
+ if (strcmp(desc->fmt, fmt) == 0)
+ return desc;
+ }
+
+ return NULL;
+}
+
static struct ima_template_field *lookup_template_field(const char *field_id)
{
int i;
@@ -232,7 +244,7 @@ struct ima_template_desc *ima_template_desc_current(void)
{
if (!ima_template)
ima_template =
- lookup_template_desc(CONFIG_IMA_DEFAULT_TEMPLATE);
+ lookup_template_desc_by_name(CONFIG_IMA_DEFAULT_TEMPLATE);
return ima_template;
}

--
1.8.1.4

Attachment: smime.p7s
Description: S/MIME cryptographic signature