Blame SOURCES/0001-Make-seinfo-output-predictable.patch

5752ef
From 8ed316d6bfb65e5e9b57f3761ea8490022ab3a05 Mon Sep 17 00:00:00 2001
5752ef
From: Petr Lautrbach <plautrba@redhat.com>
5752ef
Date: Thu, 18 Nov 2021 13:59:08 +0100
5752ef
Subject: [PATCH] Make seinfo output predictable
5752ef
5752ef
There are few places where frozenset is used. Given that frozenset is an unordered
5752ef
collection the output generated from this is unpredictable.
5752ef
5752ef
The following command outputs are fixed using sorted() on frozensets:
5752ef
5752ef
    seinfo --constrain
5752ef
    seinfo --common
5752ef
    seinfo -c -x
5752ef
    seinfo -r -x
5752ef
    seinfo -u -x
5752ef
5752ef
Fixes: https://github.com/SELinuxProject/setools/issues/65
5752ef
5752ef
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
5752ef
---
5752ef
 setools/policyrep/constraint.pxi | 2 +-
5752ef
 setools/policyrep/objclass.pxi   | 4 ++--
5752ef
 setools/policyrep/role.pxi       | 2 +-
5752ef
 setools/policyrep/user.pxi       | 2 +-
5752ef
 4 files changed, 5 insertions(+), 5 deletions(-)
5752ef
5752ef
diff --git a/setools/policyrep/constraint.pxi b/setools/policyrep/constraint.pxi
5752ef
index 01c63d87425b..0b4c5b9bcf6a 100644
5752ef
--- a/setools/policyrep/constraint.pxi
5752ef
+++ b/setools/policyrep/constraint.pxi
5752ef
@@ -72,7 +72,7 @@ cdef class Constraint(BaseConstraint):
5752ef
 
5752ef
     def statement(self):
5752ef
         if len(self.perms) > 1:
5752ef
-            perms = "{{ {0} }}".format(' '.join(self.perms))
5752ef
+            perms = "{{ {0} }}".format(' '.join(sorted(self.perms)))
5752ef
         else:
5752ef
             # convert to list since sets cannot be indexed
5752ef
             perms = list(self.perms)[0]
5752ef
diff --git a/setools/policyrep/objclass.pxi b/setools/policyrep/objclass.pxi
5752ef
index b7ec7b7de5c3..8ed2be5a9bed 100644
5752ef
--- a/setools/policyrep/objclass.pxi
5752ef
+++ b/setools/policyrep/objclass.pxi
5752ef
@@ -75,7 +75,7 @@ cdef class Common(PolicySymbol):
5752ef
         return other in self.perms
5752ef
 
5752ef
     def statement(self):
5752ef
-        return "common {0}\n{{\n\t{1}\n}}".format(self, '\n\t'.join(self.perms))
5752ef
+        return "common {0}\n{{\n\t{1}\n}}".format(self, '\n\t'.join(sorted(self.perms)))
5752ef
 
5752ef
 
5752ef
 cdef class ObjClass(PolicySymbol):
5752ef
@@ -204,7 +204,7 @@ cdef class ObjClass(PolicySymbol):
5752ef
 
5752ef
         # a class that inherits may not have additional permissions
5752ef
         if len(self.perms) > 0:
5752ef
-            stmt += "{{\n\t{0}\n}}".format('\n\t'.join(self.perms))
5752ef
+            stmt += "{{\n\t{0}\n}}".format('\n\t'.join(sorted(self.perms)))
5752ef
 
5752ef
         return stmt
5752ef
 
5752ef
diff --git a/setools/policyrep/role.pxi b/setools/policyrep/role.pxi
5752ef
index 9a0dd39f27d9..3af8a3f72a1f 100644
5752ef
--- a/setools/policyrep/role.pxi
5752ef
+++ b/setools/policyrep/role.pxi
5752ef
@@ -58,7 +58,7 @@ cdef class Role(PolicySymbol):
5752ef
         if count == 1:
5752ef
             stmt += " types {0}".format(types[0])
5752ef
         else:
5752ef
-            stmt += " types {{ {0} }}".format(' '.join(types))
5752ef
+            stmt += " types {{ {0} }}".format(' '.join(sorted(types)))
5752ef
 
5752ef
         stmt += ";"
5752ef
         return stmt
5752ef
diff --git a/setools/policyrep/user.pxi b/setools/policyrep/user.pxi
5752ef
index 9c82aa92eb72..e37af2939820 100644
5752ef
--- a/setools/policyrep/user.pxi
5752ef
+++ b/setools/policyrep/user.pxi
5752ef
@@ -81,7 +81,7 @@ cdef class User(PolicySymbol):
5752ef
         if count == 1:
5752ef
             stmt += roles[0]
5752ef
         else:
5752ef
-            stmt += "{{ {0} }}".format(' '.join(roles))
5752ef
+            stmt += "{{ {0} }}".format(' '.join(sorted(roles)))
5752ef
 
5752ef
         if self._level:
5752ef
             stmt += " level {0.mls_level} range {0.mls_range};".format(self)
5752ef
-- 
5752ef
2.33.1
5752ef