Skip to contentSkip to conversation

libsemanage: Add support for DCCP and SCTP protocols

PATCH Applied Vit Mojzis 2 participants 4 messages Oct 8, 2019 – Oct 10, 2019 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/2 libsemanage: Add support for DCCP and SCTP protocols

This is necessary for "semanage port" to be able to handle DCCP and SCTP protocols.

Fixes:
"port_parse" only handles TCP and UDP protocols

---
 libsemanage/include/semanage/port_record.h | 2 ++
 libsemanage/src/ports_file.c               | 4 ++++
 2 files changed, 6 insertions(+)
libsemanage/include/semanage/port_record.h +2 -0
index 20ae4bd9..71074800 100644
@@ -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,
libsemanage/src/ports_file.c +4 -0
index 46ee2f00..4738d467 100644
@@ -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);
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 2/2 python/semanage: Add support for DCCP and SCTP protocols

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
---
 python/semanage/seobject.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
python/semanage/seobject.py +8 -6
index f4c29854..dc413ca5 100644
@@ -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"))
 
Signature · 1 line
2.21.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols

Quoted 7 lines · Vit Mojzis

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

For both patches,

Quoted 31 lines
---
  python/semanage/seobject.py | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
python/semanage/seobject.py +8 -6
index f4c29854..dc413ca5 100644
@@ -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"))
 
#3 lore raw

Re: [PATCH 2/2] python/semanage: Add support for DCCP and SCTP protocols

Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Vit Mojzis

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
Quoted 5 lines
Quoted 1 line

For both patches,

Thanks, applied.

Quoted 32 lines
Quoted 31 lines

---
  python/semanage/seobject.py | 14 ++++++++------

  1 file changed, 8 insertions(+), 6 deletions(-)
python/semanage/seobject.py +0 -0
index f4c29854..dc413ca5 100644
@@ -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"))