summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-10-29 17:01:07 +0100
committerMartin Kosek <mkosek@redhat.com>2014-01-07 09:56:41 +0100
commit4a64a1f18bd51c65bf34a13fd7541e1d6b4b75fd (patch)
tree8cc1db4e9b3e1b77f25b36ad5c58a1b37d94fea7 /ipalib/plugins
parentd7f5d58d352f31df144de15976bd06c5aa822210 (diff)
downloadfreeipa-4a64a1f18bd51c65bf34a13fd7541e1d6b4b75fd.tar.gz
freeipa-4a64a1f18bd51c65bf34a13fd7541e1d6b4b75fd.tar.xz
freeipa-4a64a1f18bd51c65bf34a13fd7541e1d6b4b75fd.zip
Allow anonymous and all permissions
Disallow adding permissions with non-default bindtype to privileges Ticket: https://fedorahosted.org/freeipa/ticket/4032 Design: http://www.freeipa.org/page/V3/Anonymous_and_All_permissions
Diffstat (limited to 'ipalib/plugins')
-rw-r--r--ipalib/plugins/permission.py9
-rw-r--r--ipalib/plugins/privilege.py33
2 files changed, 40 insertions, 2 deletions
diff --git a/ipalib/plugins/permission.py b/ipalib/plugins/permission.py
index fef640c37..204574697 100644
--- a/ipalib/plugins/permission.py
+++ b/ipalib/plugins/permission.py
@@ -180,7 +180,7 @@ class permission(baseldap.LDAPObject):
label=_('Bind rule type'),
doc=_('Bind rule type'),
autofill=True,
- values=(u'permission',),
+ values=(u'permission', u'all', u'anonymous'),
default=u'permission',
),
DNOrURL(
@@ -775,6 +775,13 @@ class permission_mod(baseldap.LDAPUpdate):
self.obj.reject_system(old_entry)
self.obj.upgrade_permission(old_entry)
+ # Check setting bindtype for an assigned permission
+ if options.get('ipapermbindruletype') and old_entry.get('member'):
+ raise errors.ValidationError(
+ name='ipapermbindruletype',
+ error=_('cannot set bindtype for a permission that is '
+ 'assigned to a privilege'))
+
# Since `entry` only contains the attributes we are currently changing,
# it cannot be used directly to generate an ACI.
# First we need to copy the original data into it.
diff --git a/ipalib/plugins/privilege.py b/ipalib/plugins/privilege.py
index 694e1184f..678eb2416 100644
--- a/ipalib/plugins/privilege.py
+++ b/ipalib/plugins/privilege.py
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ipalib.plugins.baseldap import *
-from ipalib import api, _, ngettext
+from ipalib import api, _, ngettext, errors
from ipalib.plugable import Registry
__doc__ = _("""
@@ -152,6 +152,37 @@ class privilege_add_permission(LDAPAddReverseMember):
),
)
+ def pre_callback(self, ldap, dn, *keys, **options):
+ if options.get('permission'):
+ # We can only add permissions with bind rule type set to
+ # "permission" (or old-style permissions)
+ ldapfilter = ldap.combine_filters(rules='&', filters=[
+ '(objectClass=ipaPermissionV2)',
+ '(!(ipaPermBindRuleType=permission))',
+ ldap.make_filter_from_attr('cn', options['permission'],
+ rules='|'),
+ ])
+ try:
+ entries, truncated = ldap.find_entries(
+ filter=ldapfilter,
+ attrs_list=['cn', 'ipapermbindruletype'],
+ base_dn=DN(self.api.env.container_permission,
+ self.api.env.basedn),
+ size_limit=1)
+ except errors.NotFound:
+ pass
+ else:
+ entry = entries[0]
+ message = _('cannot add permission "%(perm)s" with bindtype '
+ '"%(bindtype)s" to a privilege')
+ raise errors.ValidationError(
+ name='permission',
+ error=message % {
+ 'perm': entry.single_value['cn'],
+ 'bindtype': entry.single_value.get(
+ 'ipapermbindruletype', 'permission')})
+ return dn
+
@register()
class privilege_remove_permission(LDAPRemoveReverseMember):