[PATCH 41/96] policycoreutils: semanage: use define/raise instead of

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


This patch looks good to me. acked.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5D6qgACgkQrlYvE4MpobNDsgCfVhvcuw3m/NFcsFq2+Mif3fP9
pP8Aniij0HlXSZOPFPE1BR5uwgf0GEqg
=bQJs
-----END PGP SIGNATURE-----
>From cdbec28c5645866e6be12b132469a7b0432f6428 Mon Sep 17 00:00:00 2001
From: Eric Paris <eparis@xxxxxxxxxx>
Date: Mon, 18 Jul 2011 12:12:34 -0400
Subject: [PATCH 41/96] policycoreutils: semanage: use define/raise instead of
 lots of conditionals

Right now the validation code has lots of conditionals which check if we
are trying to add and delete or add and modify or something like that.
Instead make a single function which just sets if this operation is
trying to do an action and if it gets called twice will realize this is
invalid and will raise and exception.

Signed-off-by: Eric Paris <eparis@xxxxxxxxxx>
---
 policycoreutils/semanage/semanage |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/policycoreutils/semanage/semanage b/policycoreutils/semanage/semanage
index 99ac3cd..304a641 100644
--- a/policycoreutils/semanage/semanage
+++ b/policycoreutils/semanage/semanage
@@ -40,6 +40,13 @@ except IOError:
 
 if __name__ == '__main__':
 
+	action  = False
+	def set_action(option):
+		global action
+		if action:
+			raise ValueError(_("%s bad option") % option)
+		action = True
+
 	def usage(message = ""):
                text = _("""
 semanage [ -S store ] -i [ input_file | - ]
@@ -169,6 +176,8 @@ Object-specific Options (see above):
                return ret
 
         def process_args(argv):
+		global action
+		action = False
 		serange = ""
 		port = ""
 		proto = ""
@@ -229,17 +238,14 @@ Object-specific Options (see above):
 				
 		for o,a in gopts:
 			if o == "-a" or o == "--add":
-				if modify or delete:
-                                       raise ValueError(_("%s bad option") % o)
+				set_action(o)
 				add = True
 				
 			if o == "-d"  or o == "--delete":
-				if modify or add:
-                                       raise ValueError(_("%s bad option") % o)
+				set_action(o)
 				delete = True
 			if o == "-D"  or o == "--deleteall":
-				if modify:
-                                       raise ValueError(_("%s bad option") % o)
+				set_action(o)
 				deleteall = True
 			if o == "-f"  or o == "--ftype":
 				ftype=a
@@ -257,8 +263,7 @@ Object-specific Options (see above):
 				locallist = True
 
 			if o == "-m"or o == "--modify":
-				if delete or add:
-                                       raise ValueError(_("%s bad option") % o)
+				set_action(o)
 				modify = True
 				
 			if o == "-S" or o == '--store':
-- 
1.7.6

Attachment: 0041-policycoreutils-semanage-use-define-raise-instead-of.patch.sig
Description: PGP signature


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux