From patchwork Tue Oct 8 12:22:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 11179499 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 391191747 for ; Tue, 8 Oct 2019 12:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 189F4206BB for ; Tue, 8 Oct 2019 12:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730317AbfJHMWU (ORCPT ); Tue, 8 Oct 2019 08:22:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48686 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730316AbfJHMWU (ORCPT ); Tue, 8 Oct 2019 08:22:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D2493082E0F for ; Tue, 8 Oct 2019 12:22:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.12.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1110019C68 for ; Tue, 8 Oct 2019 12:22:19 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH 1/2] libsemanage: Add support for DCCP and SCTP protocols Date: Tue, 8 Oct 2019 14:22:12 +0200 Message-Id: <20191008122213.9227-1-vmojzis@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 08 Oct 2019 12:22:20 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org This is necessary for "semanage port" to be able to handle DCCP and SCTP protocols. Fixes: "port_parse" only handles TCP and UDP protocols Signed-off-by: Vit Mojzis --- libsemanage/include/semanage/port_record.h | 2 ++ libsemanage/src/ports_file.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/libsemanage/include/semanage/port_record.h b/libsemanage/include/semanage/port_record.h index 20ae4bd9..71074800 100644 --- a/libsemanage/include/semanage/port_record.h +++ b/libsemanage/include/semanage/port_record.h @@ -16,6 +16,8 @@ typedef struct semanage_port_key semanage_port_key_t; #define SEMANAGE_PROTO_UDP 0 #define SEMANAGE_PROTO_TCP 1 +#define SEMANAGE_PROTO_DCCP 2 +#define SEMANAGE_PROTO_SCTP 3 /* Key */ extern int semanage_port_compare(const semanage_port_t * port, diff --git a/libsemanage/src/ports_file.c b/libsemanage/src/ports_file.c index 46ee2f00..4738d467 100644 --- a/libsemanage/src/ports_file.c +++ b/libsemanage/src/ports_file.c @@ -84,6 +84,10 @@ static int port_parse(semanage_handle_t * handle, semanage_port_set_proto(port, SEMANAGE_PROTO_TCP); else if (!strcasecmp(str, "udp")) semanage_port_set_proto(port, SEMANAGE_PROTO_UDP); + else if (!strcasecmp(str, "dccp")) + semanage_port_set_proto(port, SEMANAGE_PROTO_DCCP); + else if (!strcasecmp(str, "sctp")) + semanage_port_set_proto(port, SEMANAGE_PROTO_SCTP); else { ERR(handle, "invalid protocol \"%s\" (%s: %u):\n%s", str, info->filename, info->lineno, info->orig_line); From patchwork Tue Oct 8 12:22:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 11179501 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 C904317EE for ; Tue, 8 Oct 2019 12:22:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9ACB206BB for ; Tue, 8 Oct 2019 12:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730316AbfJHMWX (ORCPT ); Tue, 8 Oct 2019 08:22:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39478 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730301AbfJHMWX (ORCPT ); Tue, 8 Oct 2019 08:22:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C60730B2502 for ; Tue, 8 Oct 2019 12:22:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.12.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2E4819C68 for ; Tue, 8 Oct 2019 12:22:22 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols Date: Tue, 8 Oct 2019 14:22:13 +0200 Message-Id: <20191008122213.9227-2-vmojzis@redhat.com> In-Reply-To: <20191008122213.9227-1-vmojzis@redhat.com> References: <20191008122213.9227-1-vmojzis@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 08 Oct 2019 12:22:23 +0000 (UTC) Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Fixes: # semanage port -a -p sctp -t port_t 1234 ValueError: Protocol udp or tcp is required # semanage port -d -p sctp -t port_t 1234 ValueError: Protocol udp or tcp is required Signed-off-by: Vit Mojzis Acked-by: Stephen Smalley --- python/semanage/seobject.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py index f4c29854..dc413ca5 100644 --- a/python/semanage/seobject.py +++ b/python/semanage/seobject.py @@ -1058,13 +1058,15 @@ class portRecords(semanageRecords): pass def __genkey(self, port, proto): - if proto == "tcp": - proto_d = SEMANAGE_PROTO_TCP + protocols = {"tcp": SEMANAGE_PROTO_TCP, + "udp": SEMANAGE_PROTO_UDP, + "sctp": SEMANAGE_PROTO_SCTP, + "dccp": SEMANAGE_PROTO_DCCP} + + if proto in protocols.keys(): + proto_d = protocols[proto] else: - if proto == "udp": - proto_d = SEMANAGE_PROTO_UDP - else: - raise ValueError(_("Protocol udp or tcp is required")) + raise ValueError(_("Protocol has to be one of udp, tcp, dccp or sctp")) if port == "": raise ValueError(_("Port is required"))