From patchwork Thu Jan 3 12:03:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 10747245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67E3A1880 for ; Thu, 3 Jan 2019 12:03:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 599A026C9B for ; Thu, 3 Jan 2019 12:03:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3572861D; Thu, 3 Jan 2019 12:03: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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDCCA26E69 for ; Thu, 3 Jan 2019 12:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729055AbfACMDs (ORCPT ); Thu, 3 Jan 2019 07:03:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51798 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbfACMDs (ORCPT ); Thu, 3 Jan 2019 07:03:48 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99D01806B3 for ; Thu, 3 Jan 2019 12:03:48 +0000 (UTC) Received: from workstation.brq.redhat.com (unknown [10.43.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5E796013C; Thu, 3 Jan 2019 12:03:47 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2 3/5] python/sepolicy: Add sepolicy.load_store_policy(store) Date: Thu, 3 Jan 2019 13:03:38 +0100 Message-Id: <20190103120340.2695-3-plautrba@redhat.com> In-Reply-To: <20190103120340.2695-1-plautrba@redhat.com> References: <20181220151420.30878-1-plautrba@redhat.com> <20190103120340.2695-1-plautrba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 03 Jan 2019 12:03:48 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP load_store_policy() allows to (re)load SELinux policy based on a store name. It is useful when SELinux is disabled and default policy is not installed; or when a user wants to query or manipulate another policy. Related: https://bugzilla.redhat.com/show_bug.cgi?id=1558861 Signed-off-by: Petr Lautrbach --- python/sepolicy/sepolicy/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py index fbeb731d..b69a6b94 100644 --- a/python/sepolicy/sepolicy/__init__.py +++ b/python/sepolicy/sepolicy/__init__.py @@ -129,6 +129,13 @@ def get_installed_policy(root="/"): pass raise ValueError(_("No SELinux Policy installed")) +def get_store_policy(store, root="/"): + try: + policies = glob.glob("%s%s/policy/policy.*" % (selinux.selinux_path(), store)) + policies.sort() + return policies[-1] + except: + return None def policy(policy_file): global all_domains @@ -156,6 +163,11 @@ def policy(policy_file): except: raise ValueError(_("Failed to read %s policy file") % policy_file) +def load_store_policy(store): + policy_file = get_store_policy(store) + if not policy_file: + return None + policy(policy_file) try: policy_file = get_installed_policy()