From 28e92c5325cea83d4fb15225754b277d997c629f Mon Sep 17 00:00:00 2001 From: Stephen Smalley Date: Mon, 20 Jun 2016 16:28:45 -0400 Subject: [PATCH] libsepol: rewrite sepol_string_to_security_class to use hashtab_search Signed-off-by: Stephen Smalley --- libsepol/src/services.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 665fcaa5..d2b80b49 100644 --- a/libsepol/src/services.c +++ b/libsepol/src/services.c @@ -1152,22 +1152,16 @@ int hidden sepol_compute_av(sepol_security_id_t ssid, int hidden sepol_string_to_security_class(const char *class_name, sepol_security_class_t *tclass) { - char *class = NULL; - sepol_security_class_t id; + class_datum_t *tclass_datum; - for (id = 1; id <= policydb->p_classes.nprim; id++) { - class = policydb->p_class_val_to_name[id - 1]; - if (class == NULL) { - ERR(NULL, "could not convert %s to class id", class_name); - return STATUS_ERR; - } - if ((strcmp(class, class_name)) == 0) { - *tclass = id; - return STATUS_SUCCESS; - } + tclass_datum = hashtab_search(policydb->p_classes.table, + (hashtab_key_t) class_name); + if (!tclass_datum) { + ERR(NULL, "unrecognized class %s", class_name); + return STATUS_ERR; } - ERR(NULL, "unrecognized class %s", class_name); - return -EINVAL; + *tclass = tclass_datum->s.value; + return STATUS_SUCCESS; } /*