SELinux Archive on lore.kernel.org
 help / Atom feed
* [PATCH 1/1] python/semanage: do not show "None" levels when using a non-MLS policy
@ 2018-12-09 15:37 Nicolas Iooss
  2018-12-12 14:14 ` Petr Lautrbach
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Iooss @ 2018-12-09 15:37 UTC (permalink / raw)
  To: selinux

When MLS is disabled, "semanage export" shows records such as:

    login -a -s sysadm_u -r 'None' me

Prevent "semanage export" from displaying None or empty strings in level
and categories arguments by checking them in all customized() methods.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 python/semanage/seobject.py | 44 +++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 12 deletions(-)

diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index b8c43efe0101..efec0a553f43 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -747,7 +747,10 @@ class loginRecords(semanageRecords):
         l = []
         ddict = self.get_all(True)
         for k in sorted(ddict.keys()):
-            l.append("-a -s %s -r '%s' %s" % (ddict[k][0], ddict[k][1], k))
+            if ddict[k][1]:
+                l.append("-a -s %s -r '%s' %s" % (ddict[k][0], ddict[k][1], k))
+            else:
+                l.append("-a -s %s %s" % (ddict[k][0], k))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -1014,7 +1017,10 @@ class seluserRecords(semanageRecords):
         l = []
         ddict = self.get_all(True)
         for k in sorted(ddict.keys()):
-            l.append("-a -L %s -r %s -R '%s' %s" % (ddict[k][1], ddict[k][2], ddict[k][3], k))
+            if ddict[k][1] or ddict[k][2]:
+                l.append("-a -L %s -r %s -R '%s' %s" % (ddict[k][1], ddict[k][2], ddict[k][3], k))
+            else:
+                l.append("-a -R '%s' %s" % (ddict[k][3], k))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -1292,10 +1298,11 @@ class portRecords(semanageRecords):
         l = []
         ddict = self.get_all(True)
         for k in sorted(ddict.keys()):
-            if k[0] == k[1]:
-                l.append("-a -t %s -r '%s' -p %s %s" % (ddict[k][0], ddict[k][1], k[2], k[0]))
+            port = k[0] if k[0] == k[1] else "%s-%s" % (k[0], k[1])
+            if ddict[k][1]:
+                l.append("-a -t %s -r '%s' -p %s %s" % (ddict[k][0], ddict[k][1], k[2], port))
             else:
-                l.append("-a -t %s -r '%s' -p %s %s-%s" % (ddict[k][0], ddict[k][1], k[2], k[0], k[1]))
+                l.append("-a -t %s -p %s %s" % (ddict[k][0], k[2], port))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -1549,10 +1556,11 @@ class ibpkeyRecords(semanageRecords):
         ddict = self.get_all(True)
 
         for k in sorted(ddict.keys()):
-            if k[0] == k[1]:
-                l.append("-a -t %s -r '%s' -x %s %s" % (ddict[k][0], ddict[k][1], k[2], k[0]))
+            port = k[0] if k[0] == k[1] else "%s-%s" % (k[0], k[1])
+            if ddict[k][1]:
+                l.append("-a -t %s -r '%s' -x %s %s" % (ddict[k][0], ddict[k][1], k[2], port))
             else:
-                l.append("-a -t %s -r '%s' -x %s %s-%s" % (ddict[k][0], ddict[k][1], k[2], k[0], k[1]))
+                l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], port))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -1793,7 +1801,10 @@ class ibendportRecords(semanageRecords):
         ddict = self.get_all(True)
 
         for k in sorted(ddict.keys()):
-            l.append("-a -t %s -r '%s' -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
+            if ddict[k][1]:
+                l.append("-a -t %s -r '%s' -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
+            else:
+                l.append("-a -t %s -z %s %s" % (ddict[k][0], k[1], k[0]))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -2033,7 +2044,10 @@ class nodeRecords(semanageRecords):
         l = []
         ddict = self.get_all(True)
         for k in sorted(ddict.keys()):
-            l.append("-a -M %s -p %s -t %s -r '%s' %s" % (k[1], k[2], ddict[k][2], ddict[k][3], k[0]))
+            if ddict[k][3]:
+                l.append("-a -M %s -p %s -t %s -r '%s' %s" % (k[1], k[2], ddict[k][2], ddict[k][3], k[0]))
+            else:
+                l.append("-a -M %s -p %s -t %s %s" % (k[1], k[2], ddict[k][2], k[0]))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -2227,7 +2241,10 @@ class interfaceRecords(semanageRecords):
         l = []
         ddict = self.get_all(True)
         for k in sorted(ddict.keys()):
-            l.append("-a -t %s -r '%s' %s" % (ddict[k][2], ddict[k][3], k))
+            if ddict[k][3]:
+                l.append("-a -t %s -r '%s' %s" % (ddict[k][2], ddict[k][3], k))
+            else:
+                l.append("-a -t %s %s" % (ddict[k][2], k))
         return l
 
     def list(self, heading=1, locallist=0):
@@ -2609,7 +2626,10 @@ class fcontextRecords(semanageRecords):
         fcon_dict = self.get_all(True)
         for k in sorted(fcon_dict.keys()):
             if fcon_dict[k]:
-                l.append("-a -f %s -t %s -r '%s' '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], fcon_dict[k][3], k[0]))
+                if fcon_dict[k][3]:
+                    l.append("-a -f %s -t %s -r '%s' '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], fcon_dict[k][3], k[0]))
+                else:
+                    l.append("-a -f %s -t %s '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], k[0]))
 
         if len(self.equiv):
             for target in self.equiv.keys():
-- 
2.19.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] python/semanage: do not show "None" levels when using a non-MLS policy
  2018-12-09 15:37 [PATCH 1/1] python/semanage: do not show "None" levels when using a non-MLS policy Nicolas Iooss
@ 2018-12-12 14:14 ` Petr Lautrbach
  2018-12-15  9:41   ` Nicolas Iooss
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Lautrbach @ 2018-12-12 14:14 UTC (permalink / raw)
  To: selinux; +Cc: Nicolas Iooss

Nicolas Iooss <nicolas.iooss@m4x.org> writes:

> When MLS is disabled, "semanage export" shows records such as:
>
>     login -a -s sysadm_u -r 'None' me
>
> Prevent "semanage export" from displaying None or empty strings in level
> and categories arguments by checking them in all customized() methods.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Acked-by: Petr Lautrbach <plautrba@redhat.com>

> ---
>  python/semanage/seobject.py | 44 +++++++++++++++++++++++++++----------
>  1 file changed, 32 insertions(+), 12 deletions(-)
>
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index b8c43efe0101..efec0a553f43 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -747,7 +747,10 @@ class loginRecords(semanageRecords):
>          l = []
>          ddict = self.get_all(True)
>          for k in sorted(ddict.keys()):
> -            l.append("-a -s %s -r '%s' %s" % (ddict[k][0], ddict[k][1], k))
> +            if ddict[k][1]:
> +                l.append("-a -s %s -r '%s' %s" % (ddict[k][0], ddict[k][1], k))
> +            else:
> +                l.append("-a -s %s %s" % (ddict[k][0], k))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -1014,7 +1017,10 @@ class seluserRecords(semanageRecords):
>          l = []
>          ddict = self.get_all(True)
>          for k in sorted(ddict.keys()):
> -            l.append("-a -L %s -r %s -R '%s' %s" % (ddict[k][1], ddict[k][2], ddict[k][3], k))
> +            if ddict[k][1] or ddict[k][2]:
> +                l.append("-a -L %s -r %s -R '%s' %s" % (ddict[k][1], ddict[k][2], ddict[k][3], k))
> +            else:
> +                l.append("-a -R '%s' %s" % (ddict[k][3], k))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -1292,10 +1298,11 @@ class portRecords(semanageRecords):
>          l = []
>          ddict = self.get_all(True)
>          for k in sorted(ddict.keys()):
> -            if k[0] == k[1]:
> -                l.append("-a -t %s -r '%s' -p %s %s" % (ddict[k][0], ddict[k][1], k[2], k[0]))
> +            port = k[0] if k[0] == k[1] else "%s-%s" % (k[0], k[1])
> +            if ddict[k][1]:
> +                l.append("-a -t %s -r '%s' -p %s %s" % (ddict[k][0], ddict[k][1], k[2], port))
>              else:
> -                l.append("-a -t %s -r '%s' -p %s %s-%s" % (ddict[k][0], ddict[k][1], k[2], k[0], k[1]))
> +                l.append("-a -t %s -p %s %s" % (ddict[k][0], k[2], port))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -1549,10 +1556,11 @@ class ibpkeyRecords(semanageRecords):
>          ddict = self.get_all(True)
>  
>          for k in sorted(ddict.keys()):
> -            if k[0] == k[1]:
> -                l.append("-a -t %s -r '%s' -x %s %s" % (ddict[k][0], ddict[k][1], k[2], k[0]))
> +            port = k[0] if k[0] == k[1] else "%s-%s" % (k[0], k[1])
> +            if ddict[k][1]:
> +                l.append("-a -t %s -r '%s' -x %s %s" % (ddict[k][0], ddict[k][1], k[2], port))
>              else:
> -                l.append("-a -t %s -r '%s' -x %s %s-%s" % (ddict[k][0], ddict[k][1], k[2], k[0], k[1]))
> +                l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], port))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -1793,7 +1801,10 @@ class ibendportRecords(semanageRecords):
>          ddict = self.get_all(True)
>  
>          for k in sorted(ddict.keys()):
> -            l.append("-a -t %s -r '%s' -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
> +            if ddict[k][1]:
> +                l.append("-a -t %s -r '%s' -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
> +            else:
> +                l.append("-a -t %s -z %s %s" % (ddict[k][0], k[1], k[0]))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -2033,7 +2044,10 @@ class nodeRecords(semanageRecords):
>          l = []
>          ddict = self.get_all(True)
>          for k in sorted(ddict.keys()):
> -            l.append("-a -M %s -p %s -t %s -r '%s' %s" % (k[1], k[2], ddict[k][2], ddict[k][3], k[0]))
> +            if ddict[k][3]:
> +                l.append("-a -M %s -p %s -t %s -r '%s' %s" % (k[1], k[2], ddict[k][2], ddict[k][3], k[0]))
> +            else:
> +                l.append("-a -M %s -p %s -t %s %s" % (k[1], k[2], ddict[k][2], k[0]))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -2227,7 +2241,10 @@ class interfaceRecords(semanageRecords):
>          l = []
>          ddict = self.get_all(True)
>          for k in sorted(ddict.keys()):
> -            l.append("-a -t %s -r '%s' %s" % (ddict[k][2], ddict[k][3], k))
> +            if ddict[k][3]:
> +                l.append("-a -t %s -r '%s' %s" % (ddict[k][2], ddict[k][3], k))
> +            else:
> +                l.append("-a -t %s %s" % (ddict[k][2], k))
>          return l
>  
>      def list(self, heading=1, locallist=0):
> @@ -2609,7 +2626,10 @@ class fcontextRecords(semanageRecords):
>          fcon_dict = self.get_all(True)
>          for k in sorted(fcon_dict.keys()):
>              if fcon_dict[k]:
> -                l.append("-a -f %s -t %s -r '%s' '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], fcon_dict[k][3], k[0]))
> +                if fcon_dict[k][3]:
> +                    l.append("-a -f %s -t %s -r '%s' '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], fcon_dict[k][3], k[0]))
> +                else:
> +                    l.append("-a -f %s -t %s '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], k[0]))
>  
>          if len(self.equiv):
>              for target in self.equiv.keys():

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] python/semanage: do not show "None" levels when using a non-MLS policy
  2018-12-12 14:14 ` Petr Lautrbach
@ 2018-12-15  9:41   ` Nicolas Iooss
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Iooss @ 2018-12-15  9:41 UTC (permalink / raw)
  To: Petr Lautrbach; +Cc: selinux

On Wed, Dec 12, 2018 at 3:14 PM Petr Lautrbach <plautrba@redhat.com> wrote:
> Nicolas Iooss <nicolas.iooss@m4x.org> writes:
>
> > When MLS is disabled, "semanage export" shows records such as:
> >
> >     login -a -s sysadm_u -r 'None' me
> >
> > Prevent "semanage export" from displaying None or empty strings in level
> > and categories arguments by checking them in all customized() methods.
> >
> > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>
> Acked-by: Petr Lautrbach <plautrba@redhat.com>

Thanks, I have merged my patch.
Nicolas


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-09 15:37 [PATCH 1/1] python/semanage: do not show "None" levels when using a non-MLS policy Nicolas Iooss
2018-12-12 14:14 ` Petr Lautrbach
2018-12-15  9:41   ` Nicolas Iooss

SELinux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux/0 selinux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux selinux/ https://lore.kernel.org/selinux \
		selinux@vger.kernel.org selinux@archiver.kernel.org
	public-inbox-index selinux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox