From patchwork Mon Apr 27 15:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 11512451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A636514DD for ; Mon, 27 Apr 2020 15:35:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FA8320661 for ; Mon, 27 Apr 2020 15:35:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AvxiQhFl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbgD0PfR (ORCPT ); Mon, 27 Apr 2020 11:35:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40710 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727006AbgD0PfQ (ORCPT ); Mon, 27 Apr 2020 11:35:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588001715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h76vANqeUMrppq1MyM5+mG2iaU6uXMCAsMD+mc3myrQ=; b=AvxiQhFlSIBfrElssRu0arvy+cM/cTh1fkc7jHQWguoup/HUTi1JAjUXgPcm3yvZFqg7CQ hGHArl0jnGDbkKQoT+v4nrSjtyzU8nNNcIToA3bSQCAWWPEUA/QRkqLeJdb1khsd+cEEfq Xh27Y1yizuouttmKy8F0o1TcG+bwvns= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-z2ShQf5BNJGkgV666zwB_Q-1; Mon, 27 Apr 2020 11:35:11 -0400 X-MC-Unique: z2ShQf5BNJGkgV666zwB_Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5ABAB835B41 for ; Mon, 27 Apr 2020 15:35:10 +0000 (UTC) Received: from workstation.redhat.com (unknown [10.40.193.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EE8160635; Mon, 27 Apr 2020 15:35:08 +0000 (UTC) From: Petr Lautrbach To: selinux@vger.kernel.org Cc: Petr Lautrbach Subject: [PATCH v2] python/semanage: Use ipaddress module instead of IPy Date: Mon, 27 Apr 2020 17:34:39 +0200 Message-Id: <20200427153438.17061-1-plautrba@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org ipaddress python module was added to standard library in Python 3.3 - https://docs.python.org/3/library/ipaddress.html seobject.py was the only consumer of IPy module so this dependency is not needed anymore. Signed-off-by: Petr Lautrbach Acked-by: Nicolas Iooss --- Based on Nicolas input: - improved the check comment - dropped the unnecessary check python/semanage/seobject.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py index f2a139c970bd..6e0b87f2fa3c 100644 --- a/python/semanage/seobject.py +++ b/python/semanage/seobject.py @@ -32,7 +32,7 @@ from semanage import * PROGNAME = "policycoreutils" import sepolicy import setools -from IPy import IP +import ipaddress try: import gettext @@ -1858,15 +1858,12 @@ class nodeRecords(semanageRecords): if addr == "": raise ValueError(_("Node Address is required")) - # verify valid combination + # verify that (addr, mask) is either a IP address (without a mask) or a valid network mask if len(mask) == 0 or mask[0] == "/": - i = IP(addr + mask) - newaddr = i.strNormal(0) - newmask = str(i.netmask()) - if newmask == "0.0.0.0" and i.version() == 6: - newmask = "::" - - protocol = "ipv%d" % i.version() + i = ipaddress.ip_network(addr + mask) + newaddr = str(i.network_address) + newmask = str(i.netmask) + protocol = "ipv%d" % i.version try: newprotocol = self.protocol.index(protocol)