From patchwork Mon Jun 20 20:35:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Smalley X-Patchwork-Id: 9188767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A80660756 for ; Mon, 20 Jun 2016 20:35:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3812727D13 for ; Mon, 20 Jun 2016 20:35:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D0D527D4D; Mon, 20 Jun 2016 20:35:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA72727D13 for ; Mon, 20 Jun 2016 20:35:52 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.26,500,1459814400"; d="scan'208";a="14834829" IronPort-PHdr: =?us-ascii?q?9a23=3Ayrm8/BFUYqprY5tEZzIdPp1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ75osuwAkXT6L1XgUPTWs2DsrQf27uQ4v2rADZfqb+681k8M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJP?= =?us-ascii?q?K/jvHcaK1oLsh7H0qsCYOl8XzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRu?= =?us-ascii?q?JN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IbL/+N5gcYfQYSW5+cjN92Mq+rhTH?= =?us-ascii?q?TA2S9lMAQ24WlVxOGAGD4xbkDbnrtS6vjfZwwCmXO4XNSLkwXTmzp/NwRATAlD?= =?us-ascii?q?YMNzl/9nrezMN3kvQI81qauxVjztuMM8muP/1kc/aYJ4sX?= X-IPAS-Result: =?us-ascii?q?A2FPBADNUmhX/wHyM5BdGwEBAYMggUQPtj+GISSHM0wBAQE?= =?us-ascii?q?BAQECAmIngjGCIgIkExQgCwMDCQIXKQgIAwEtFR8LBRgEiA/BXiWPBhEBaIUPB?= =?us-ascii?q?YgSkGSOKgKJWoVEAkiPL1SCCByBaFKJE4E1AQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 20 Jun 2016 20:35:51 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u5KKZpdc003764; Mon, 20 Jun 2016 16:35:51 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u5KKYajd096546 for ; Mon, 20 Jun 2016 16:34:36 -0400 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto [192.168.25.131]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u5KKYaRI003634; Mon, 20 Jun 2016 16:34:36 -0400 From: Stephen Smalley To: selinux@tycho.nsa.gov Subject: [PATCH] libsepol: rewrite sepol_string_to_security_class to use hashtab_search Date: Mon, 20 Jun 2016 16:35:46 -0400 Message-Id: <1466454946-5713-1-git-send-email-sds@tycho.nsa.gov> X-Mailer: git-send-email 2.5.5 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: Stephen Smalley MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Stephen Smalley --- libsepol/src/services.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 665fcaa..d2b80b4 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; - - 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; - } + class_datum_t *tclass_datum; + + 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; } /*