Skip to contentSkip to conversation

python/semanage: Fix logger class definition

PATCH In review Vit Mojzis 2 participants 4 messages Jul 9, 2018 – Jul 14, 2018 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 python/semanage: Fix logger class definition

Test if audit module is enabled so that logger class is defined correctly.

Fixes:
"semanage fcontext -l" fails with "OSError: Protocol not supported" when booting with audit=0

---
 python/semanage/seobject.py | 2 ++
 1 file changed, 2 insertions(+)
python/semanage/seobject.py +2 -0
index e5c81a7d..29b4afe0 100644
@@ -101,6 +101,8 @@ ftype_to_audit = {"": "any",
 
 try:
     import audit
+    #test if audit module is enabled
+    audit.audit_close(audit.audit_open())
 
     class logger:
 
Signature · 1 line
2.14.3
#1 lore raw
Quoted 18 lines · Vit Mojzis

Test if audit module is enabled so that logger class is defined correctly.

Fixes:
"semanage fcontext -l" fails with "OSError: Protocol not supported" when booting with audit=0

---
 python/semanage/seobject.py | 2 ++
 1 file changed, 2 insertions(+)
python/semanage/seobject.py +0 -0
index e5c81a7d..29b4afe0 100644

python/semanage/seobject.py ftype_to_audit = {"": "any", · line 108

Quoted 8 lines
python/semanage/seobject.py +2 -0
@@ -101,6 +101,8 @@ ftype_to_audit = {"": "any",
 
 try:
     import audit
+    #test if audit module is enabled
+    audit.audit_close(audit.audit_open())
 
     class logger:
 

This looks good to me (Ack). For future reference, I was wondering whether audit.audit_open() returns -1 or raises an exception if it fails to open the audit log, and found the answer in audit's source code (it raises an OSError, as expected [1], so the new code is fine).

While reviewing your patch, I encountered the bare "except:" right after the definition of class logger. The exceptions which cause the use of the fail-over logger class are not explicitly written and this could cause issues, for example when someone tries to interrupt the program with Ctrl-C while the code executes. Would it be possible to replace this "except:" with "except ImportError, OSError:"? (This could be done in another patch).

Thanks,
Nicolas

[1] https://github.com/linux-audit/audit-userspace/blob/v2.8.4/bindings/swig/src/auditswig.i#L27-L33)

author
#2 lore raw

PATCH 1/1 python/semanage: Replace bare except with specific one

The corresponding except clause should only be used for exceptions caused by audit module error or unavailability.

---
 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
index 29b4afe0..78ffb091 100644
@@ -140,7 +140,7 @@ try:
 
             self.log_list = []
             self.log_change_list = []
-except:
+except OSError, ImportError:
     class logger:
 
         def __init__(self):
Signature · 1 line
2.14.3
#3 lore raw

Re: [PATCH] python/semanage: Replace bare except with specific one

Quoted 4 lines · Vit Mojzis

The corresponding except clause should only be used for exceptions caused by audit module error or unavailability.

Thanks. I applied your two patches.

Nicolas