summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2010-10-11 10:07:15 -0400
committerRob Crittenden <rcritten@redhat.com>2010-10-18 15:47:16 -0400
commitfe7d97a3d925e07bc4ba81f4859dbe11a223948a (patch)
tree46078652e03ec0a0a2c85cd2e88adb756b045b22 /ipalib
parentdff2ff830073c638582c3708cec422c47994f36a (diff)
downloadfreeipa-fe7d97a3d925e07bc4ba81f4859dbe11a223948a.tar.gz
freeipa-fe7d97a3d925e07bc4ba81f4859dbe11a223948a.tar.xz
freeipa-fe7d97a3d925e07bc4ba81f4859dbe11a223948a.zip
Fix problem testing for mutual exclusivity in hbac plugin.
This should fix the hbac tests.
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugins/hbac.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/ipalib/plugins/hbac.py b/ipalib/plugins/hbac.py
index 00743aedc..55d9d912c 100644
--- a/ipalib/plugins/hbac.py
+++ b/ipalib/plugins/hbac.py
@@ -80,6 +80,18 @@ from ipalib import AccessTime, Password, Str, StrEnum
from ipalib.plugins.baseldap import *
from ipalib import _, ngettext
+def is_all(options, attribute):
+ """
+ See if options[attribute] is lower-case 'all' in a safe way.
+ """
+ if attribute in options and \
+ options[attribute] is not None and \
+ options[attribute].lower() == 'all':
+ return True
+ else:
+ return False
+
+
class hbac(LDAPObject):
"""
HBAC object.
@@ -233,17 +245,13 @@ class hbac_mod(LDAPUpdate):
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
(dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
- if 'usercategory' in options and options['usercategory'].lower() == 'all' and \
- 'memberuser' in entry_attrs:
+ if is_all(options, 'usercategory') and 'memberuser' in entry_attrs:
raise errors.MutuallyExclusiveError(reason="user category cannot be set to 'all' while there are allowed users")
- if 'hostcategory' in options and options['hostcategory'].lower() == 'all' and \
- 'memberhost' in entry_attrs:
+ if is_all(options, 'hostcategory') and 'memberhost' in entry_attrs:
raise errors.MutuallyExclusiveError(reason="host category cannot be set to 'all' while there are allowed hosts")
- if 'sourcehostcategory' in options and options['sourcehostcategory'].lower() == 'all' and \
- 'sourcehost' in entry_attrs:
+ if is_all(options, 'sourcehostcategory') and 'sourcehost' in entry_attrs:
raise errors.MutuallyExclusiveError(reason="sourcehost category cannot be set to 'all' while there are allowed source hosts")
- if 'servicecategory' in options and options['servicecategory'].lower() == 'all' and \
- 'memberservice' in entry_attrs:
+ if is_all(options, 'servicecategory') and 'memberservice' in entry_attrs:
raise errors.MutuallyExclusiveError(reason="service category cannot be set to 'all' while there are allowed services")
return dn