diff mbox series

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

Message ID 20191008122213.9227-2-vmojzis@redhat.com (mailing list archive)
State Accepted
Headers show
Series [1/2] libsemanage: Add support for DCCP and SCTP protocols | expand

Commit Message

Vit Mojzis Oct. 8, 2019, 12:22 p.m. UTC
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(-)

Comments

Stephen Smalley Oct. 9, 2019, 2:39 p.m. UTC | #1
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"))
>   
>
Stephen Smalley Oct. 10, 2019, 7:57 p.m. UTC | #2
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"))
>>
>
diff mbox series

Patch

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