Skip to contentSkip to conversation

gui: fix "file type" selection in fcontextPage

PATCH Superseded Vit Mojzis 3 participants 4 messages Feb 16, 2021 – Feb 24, 2021 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 gui: fix "file type" selection in fcontextPage

A change in seobject.py file_type_str_to_option made the "file type" list not compatible with items in this ComboBox.
See: 317743bbe2a235a5c68f1066b4153e0726a3118f

Avoid this in the future by populating the ComboBox using keys from file_type_str_to_option.

This change disables translations on the file types, but those cause other issues (adding file context fails the same way as with 'socket file' since the translated strings differ form file_type_str_to_option.keys, 'properties' of a file context entry shows no file type for the same reason).

Fixes:
Traceback (most recent call last):
File "/usr/share/system-config-selinux/system-config-selinux.py", line 136, in add
self.tabs[self.notebook.get_current_page()].addDialog()
File "/usr/share/system-config-selinux/semanagePage.py", line 143, in addDialog
if self.add() is False:
File "/usr/share/system-config-selinux/fcontextPage.py", line 195, in add
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
KeyError: 'socket file'

---
 gui/fcontextPage.py          |  7 +++++++
 gui/system-config-selinux.ui | 26 --------------------------
 2 files changed, 7 insertions(+), 26 deletions(-)
gui/fcontextPage.py +7 -0
index 370bbee4..d26aa1b4 100644
@@ -102,6 +102,13 @@ class fcontextPage(semanagePage):
         self.load()
         self.fcontextEntry = xml.get_object("fcontextEntry")
         self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
+        # Populate file type combo_box
+        liststore = self.fcontextFileTypeCombo.get_model()
+        for ftype in seobject.file_type_str_to_option.keys():
+            iter = liststore.append()
+            liststore.set_value(iter, 0, ftype)
+        iter = liststore.get_iter_first()
+        self.fcontextFileTypeCombo.set_active_iter(iter)
         self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
         self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")
 
gui/system-config-selinux.ui +0 -26
index 7cc1cc53..e7b84a64 100644
@@ -401,32 +401,6 @@ Level</property>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
     </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">all files</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">regular file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">directory</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">character device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">block device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">socket file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">symbolic link</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">named pipe</col>
-      </row>
-    </data>
   </object>
   <object class="GtkDialog" id="fcontextDialog">
     <property name="can_focus">False</property>
Signature · 1 line
2.29.2
#1 lore raw
Quoted 14 lines · Vit Mojzis

A change in seobject.py file_type_str_to_option made the "file type" list not compatible with items in this ComboBox.
See: 317743bbe2a235a5c68f1066b4153e0726a3118f

Avoid this in the future by populating the ComboBox using keys from file_type_str_to_option.

This change disables translations on the file types, but those cause other issues (adding file context fails the same way as with 'socket file' since the translated strings differ form file_type_str_to_option.keys, 'properties' of a file context entry shows no file type for the same reason).

Quoted 9 lines

Fixes:
Traceback (most recent call last):
File "/usr/share/system-config-selinux/system-config-selinux.py", line 136, in add
self.tabs[self.notebook.get_current_page()].addDialog()
File "/usr/share/system-config-selinux/semanagePage.py", line 143, in addDialog
if self.add() is False:
File "/usr/share/system-config-selinux/fcontextPage.py", line 195, in add
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
KeyError: 'socket file'

Your patch misses the Signed-off-by tag.

Quoted 63 lines
---
 gui/fcontextPage.py          |  7 +++++++
 gui/system-config-selinux.ui | 26 --------------------------
 2 files changed, 7 insertions(+), 26 deletions(-)
gui/fcontextPage.py +7 -0
index 370bbee4..d26aa1b4 100644
@@ -102,6 +102,13 @@ class fcontextPage(semanagePage):
         self.load()
         self.fcontextEntry = xml.get_object("fcontextEntry")
         self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
+        # Populate file type combo_box
+        liststore = self.fcontextFileTypeCombo.get_model()
+        for ftype in seobject.file_type_str_to_option.keys():
+            iter = liststore.append()
+            liststore.set_value(iter, 0, ftype)
+        iter = liststore.get_iter_first()
+        self.fcontextFileTypeCombo.set_active_iter(iter)
         self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
         self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")
 
gui/system-config-selinux.ui +0 -27
index 7cc1cc53..e7b84a64 100644
@@ -401,32 +401,6 @@ Level</property>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
     </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">all files</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">regular file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">directory</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">character device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">block device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">socket file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">symbolic link</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">named pipe</col>
-      </row>
-    </data>
   </object>
   <object class="GtkDialog" id="fcontextDialog">
     <property name="can_focus">False</property>
--

2.29.2

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
author
#2 lore raw

PATCH v2 1/1 gui: fix "file type" selection in fcontextPage

A change in seobject.py file_type_str_to_option made the "file type" list not compatible with items in this ComboBox.
See: 317743bbe2a235a5c68f1066b4153e0726a3118f

Avoid this in the future by populating the ComboBox using keys from file_type_str_to_option.

This change disables translations on the file types, but those cause other issues (adding file context fails the same way as with 'socket file' since the translated strings differ form file_type_str_to_option.keys, 'properties' of a file context entry shows no file type for the same reason).

Fixes:
Traceback (most recent call last):
File "/usr/share/system-config-selinux/system-config-selinux.py", line 136, in add
self.tabs[self.notebook.get_current_page()].addDialog()
File "/usr/share/system-config-selinux/semanagePage.py", line 143, in addDialog
if self.add() is False:
File "/usr/share/system-config-selinux/fcontextPage.py", line 195, in add
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
KeyError: 'socket file'

---
Add missing "Signed-off-by".

 gui/fcontextPage.py          |  7 +++++++
 gui/system-config-selinux.ui | 26 --------------------------
 2 files changed, 7 insertions(+), 26 deletions(-)
gui/fcontextPage.py +7 -0
index 370bbee4..d26aa1b4 100644
@@ -102,6 +102,13 @@ class fcontextPage(semanagePage):
         self.load()
         self.fcontextEntry = xml.get_object("fcontextEntry")
         self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
+        # Populate file type combo_box
+        liststore = self.fcontextFileTypeCombo.get_model()
+        for ftype in seobject.file_type_str_to_option.keys():
+            iter = liststore.append()
+            liststore.set_value(iter, 0, ftype)
+        iter = liststore.get_iter_first()
+        self.fcontextFileTypeCombo.set_active_iter(iter)
         self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
         self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")
 
gui/system-config-selinux.ui +0 -26
index 7cc1cc53..e7b84a64 100644
@@ -401,32 +401,6 @@ Level</property>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
     </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">all files</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">regular file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">directory</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">character device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">block device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">socket file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">symbolic link</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">named pipe</col>
-      </row>
-    </data>
   </object>
   <object class="GtkDialog" id="fcontextDialog">
     <property name="can_focus">False</property>
Signature · 1 line
2.29.2
Acked-by on v2 1/1
#3 lore raw
Quoted 23 lines · Vit Mojzis

A change in seobject.py file_type_str_to_option made the "file type" list not compatible with items in this ComboBox.
See: 317743bbe2a235a5c68f1066b4153e0726a3118f

Avoid this in the future by populating the ComboBox using keys from file_type_str_to_option.

This change disables translations on the file types, but those cause other issues (adding file context fails the same way as with 'socket file' since the translated strings differ form file_type_str_to_option.keys, 'properties' of a file context entry shows no file type for the same reason).

Fixes:
Traceback (most recent call last):
File "/usr/share/system-config-selinux/system-config-selinux.py", line 136, in add
self.tabs[self.notebook.get_current_page()].addDialog()
File "/usr/share/system-config-selinux/semanagePage.py", line 143, in addDialog
if self.add() is False:
File "/usr/share/system-config-selinux/fcontextPage.py", line 195, in add
(rc, out) = getstatusoutput("semanage fcontext -a -t %s -r %s -f '%s' '%s'" % (type, mls, seobject.file_type_str_to_option[ftype], fspec))
KeyError: 'socket file'

Quoted 1 line

And merged. Thanks!

Quoted 64 lines

---
Add missing "Signed-off-by".

 gui/fcontextPage.py          |  7 +++++++
 gui/system-config-selinux.ui | 26 --------------------------
 2 files changed, 7 insertions(+), 26 deletions(-)
gui/fcontextPage.py +7 -0
index 370bbee4..d26aa1b4 100644
@@ -102,6 +102,13 @@ class fcontextPage(semanagePage):
         self.load()
         self.fcontextEntry = xml.get_object("fcontextEntry")
         self.fcontextFileTypeCombo = xml.get_object("fcontextFileTypeCombo")
+        # Populate file type combo_box
+        liststore = self.fcontextFileTypeCombo.get_model()
+        for ftype in seobject.file_type_str_to_option.keys():
+            iter = liststore.append()
+            liststore.set_value(iter, 0, ftype)
+        iter = liststore.get_iter_first()
+        self.fcontextFileTypeCombo.set_active_iter(iter)
         self.fcontextTypeEntry = xml.get_object("fcontextTypeEntry")
         self.fcontextMLSEntry = xml.get_object("fcontextMLSEntry")
 
gui/system-config-selinux.ui +0 -26
index 7cc1cc53..e7b84a64 100644
@@ -401,32 +401,6 @@ Level</property>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
     </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">all files</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">regular file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">directory</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">character device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">block device</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">socket file</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">symbolic link</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">named pipe</col>
-      </row>
-    </data>
   </object>
   <object class="GtkDialog" id="fcontextDialog">
     <property name="can_focus">False</property>
Signature · 1 line
2.29.2