From patchwork Sun Dec 9 14:23:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Iooss X-Patchwork-Id: 10720061 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 592DC18A7 for ; Sun, 9 Dec 2018 14:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B7472909F for ; Sun, 9 Dec 2018 14:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F4B6296DB; Sun, 9 Dec 2018 14:23:49 +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 D623B294B4 for ; Sun, 9 Dec 2018 14:23:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726212AbeLIOXs (ORCPT ); Sun, 9 Dec 2018 09:23:48 -0500 Received: from mx1.polytechnique.org ([129.104.30.34]:48140 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbeLIOXs (ORCPT ); Sun, 9 Dec 2018 09:23:48 -0500 Received: from localhost.localdomain (89-156-252-9.rev.numericable.fr [89.156.252.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 98A77564670 for ; Sun, 9 Dec 2018 15:23:45 +0100 (CET) From: Nicolas Iooss To: selinux@vger.kernel.org Subject: [PATCH 2/2] python/chcat: fix removing categories on users with Fedora default setup Date: Sun, 9 Dec 2018 15:23:23 +0100 Message-Id: <20181209142323.21149-2-nicolas.iooss@m4x.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181209142323.21149-1-nicolas.iooss@m4x.org> References: <20181209142323.21149-1-nicolas.iooss@m4x.org> MIME-Version: 1.0 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sun Dec 9 15:23:45 2018 +0100 (CET)) X-Org-Mail: nicolas.iooss.2010@polytechnique.org Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using Vagrant with fedora/28-cloud-base image, SELinux logins are configured this way: # semanage login -l Login Name SELinux User MLS/MCS Range Service __default__ unconfined_u s0-s0:c0.c1023 * root unconfined_u s0-s0:c0.c1023 * vagrant unconfined_u s0-s0:c0.c1023 * Using "chcat -l +c42 vagrant" successfully adds the category to user vagrant, but "chcat -l -- -c42 vagrant" fails to remove it. semanage login -l returns: vagrant unconfined_u s0-s0:c0.c1023,c42 * This issue is caused by expandCats(), which refuses to return a list of more than 25 categories. This causes chcat_user_remove() to work with cats=['c0.c1023,c42'] instead of cats=['c0.c102','c42'], which leads to it not been able to remove 'c42' from the list. Fix this issue by splitting the list of categories before calling expandCats(). Signed-off-by: Nicolas Iooss Acked-by: Petr Lautrbach --- python/chcat/chcat | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python/chcat/chcat b/python/chcat/chcat index 73f757258807..5bef0073b7a4 100755 --- a/python/chcat/chcat +++ b/python/chcat/chcat @@ -82,8 +82,7 @@ def chcat_user_add(newcat, users): if len(serange) > 1: top = serange[1].split(":") if len(top) > 1: - cats.append(top[1]) - cats = expandCats(cats) + cats = expandCats(top[1].split(',')) for i in newcat[1:]: if i not in cats: @@ -163,8 +162,7 @@ def chcat_user_remove(newcat, users): if len(serange) > 1: top = serange[1].split(":") if len(top) > 1: - cats.append(top[1]) - cats = expandCats(cats) + cats = expandCats(top[1].split(',')) for i in newcat[1:]: if i in cats: