SELinux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] libsemanage: Add support for DCCP and SCTP protocols
@ 2019-10-08 12:22 Vit Mojzis
  2019-10-08 12:22 ` [PATCH 2/2] python/semanage: " Vit Mojzis
  0 siblings, 1 reply; 4+ messages in thread
From: Vit Mojzis @ 2019-10-08 12:22 UTC (permalink / raw)
  To: selinux

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 <vmojzis@redhat.com>
---
 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);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols
  2019-10-08 12:22 [PATCH 1/2] libsemanage: Add support for DCCP and SCTP protocols Vit Mojzis
@ 2019-10-08 12:22 ` " Vit Mojzis
  2019-10-09 14:39   ` Stephen Smalley
  0 siblings, 1 reply; 4+ messages in thread
From: Vit Mojzis @ 2019-10-08 12:22 UTC (permalink / raw)
  To: selinux

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 <vmojzis@redhat.com>
---
 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"))
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols
  2019-10-08 12:22 ` [PATCH 2/2] python/semanage: " Vit Mojzis
@ 2019-10-09 14:39   ` Stephen Smalley
  2019-10-10 19:57     ` Stephen Smalley
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Smalley @ 2019-10-09 14:39 UTC (permalink / raw)
  To: Vit Mojzis, selinux

On 10/8/19 8:22 AM, Vit Mojzis wrote:
> 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 <vmojzis@redhat.com>

For both patches,

Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

> ---
>   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"))
>   
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols
  2019-10-09 14:39   ` Stephen Smalley
@ 2019-10-10 19:57     ` Stephen Smalley
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Smalley @ 2019-10-10 19:57 UTC (permalink / raw)
  To: Vit Mojzis, selinux

On 10/9/19 10:39 AM, Stephen Smalley wrote:
> On 10/8/19 8:22 AM, Vit Mojzis wrote:
>> 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 <vmojzis@redhat.com>
> 
> For both patches,
> 
> Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

Thanks, applied.

> 
>> ---
>>   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"))
>>
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-08 12:22 [PATCH 1/2] libsemanage: Add support for DCCP and SCTP protocols Vit Mojzis
2019-10-08 12:22 ` [PATCH 2/2] python/semanage: " Vit Mojzis
2019-10-09 14:39   ` Stephen Smalley
2019-10-10 19:57     ` Stephen Smalley

SELinux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux/0 selinux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux selinux/ https://lore.kernel.org/selinux \
		selinux@vger.kernel.org
	public-inbox-index selinux

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git