libsemanage: Add support for DCCP and SCTP protocols
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
@@ -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
@@ -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
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
@@ -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
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 requiredSigned-off-by Vit Mojzis <[email protected]>
For both patches,
Quoted 31 lines
--- python/semanage/seobject.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)python/semanage/seobject.py +8
-6@@ -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"))
Stephen Smalley
AppliedRe: [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
Signed-off-by Vit Mojzis <[email protected]>For both patches,
Acked-by Stephen Smalley <[email protected]>
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@@ -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 inprotocols.keys():
+proto_d= protocols[proto]
else:
- if proto == "udp":
-proto_d=SEMANAGE_PROTO_UDP
- else:
- raiseValueError(_("Protocol udp or tcp is required"))+ raiseValueError(_("Protocol has to be one of udp, tcp, dccp or sctp"))
if port == "":
raiseValueError(_("Port is required"))