2010-12-01 10:23:52 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2010-12-01 10:23:52 -06:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
from ipalib.plugins.baseldap import *
|
|
|
|
from ipalib import api, _, ngettext
|
|
|
|
from ipalib import Flag, Str, StrEnum
|
|
|
|
from ipalib.request import context
|
|
|
|
from ipalib import errors
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
from ipapython.dn import DN, EditableDN
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
__doc__ = _("""
|
2010-12-01 10:23:52 -06:00
|
|
|
Permissions
|
|
|
|
|
2011-02-22 15:24:41 -06:00
|
|
|
A permission enables fine-grained delegation of rights. A permission is
|
|
|
|
a human-readable form of a 389-ds Access Control Rule, or instruction (ACI).
|
|
|
|
A permission grants the right to perform a specific task such as adding a
|
|
|
|
user, modifying a group, etc.
|
2010-12-01 10:23:52 -06:00
|
|
|
|
2011-02-22 15:24:41 -06:00
|
|
|
A permission may not contain other permissions.
|
2010-12-01 10:23:52 -06:00
|
|
|
|
2011-03-04 10:08:54 -06:00
|
|
|
* A permission grants access to read, write, add or delete.
|
2010-12-01 10:23:52 -06:00
|
|
|
* A privilege combines similar permissions (for example all the permissions
|
|
|
|
needed to add a user).
|
|
|
|
* A role grants a set of privileges to users, groups, hosts or hostgroups.
|
|
|
|
|
|
|
|
A permission is made up of a number of different parts:
|
|
|
|
|
|
|
|
1. The name of the permission.
|
2011-01-31 10:01:56 -06:00
|
|
|
2. The target of the permission.
|
2011-03-04 10:08:54 -06:00
|
|
|
3. The rights granted by the permission.
|
2010-12-01 10:23:52 -06:00
|
|
|
|
2011-03-04 10:08:54 -06:00
|
|
|
Rights define what operations are allowed, and may be one or more
|
|
|
|
of the following:
|
2010-12-01 10:23:52 -06:00
|
|
|
1. write - write one or more attributes
|
|
|
|
2. read - read one or more attributes
|
|
|
|
3. add - add a new entry to the tree
|
|
|
|
4. delete - delete an existing entry
|
|
|
|
5. all - all permissions are granted
|
|
|
|
|
2011-01-31 10:01:56 -06:00
|
|
|
Read permission is granted for most attributes by default so the read
|
|
|
|
permission is not expected to be used very often.
|
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
Note the distinction between attributes and entries. The permissions are
|
|
|
|
independent, so being able to add a user does not mean that the user will
|
2011-03-04 10:08:54 -06:00
|
|
|
be editable.
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
There are a number of allowed targets:
|
|
|
|
1. type: a type of object (user, group, etc).
|
2011-01-31 10:01:56 -06:00
|
|
|
2. memberof: a member of a group or hostgroup
|
2010-12-01 10:23:52 -06:00
|
|
|
3. filter: an LDAP filter
|
2011-01-31 10:01:56 -06:00
|
|
|
4. subtree: an LDAP filter specifying part of the LDAP DIT. This is a
|
2011-03-04 10:08:54 -06:00
|
|
|
super-set of the "type" target.
|
2011-01-31 10:01:56 -06:00
|
|
|
5. targetgroup: grant access to modify a specific group (such as granting
|
|
|
|
the rights to manage group membership)
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
|
|
|
Add a permission that grants the creation of users:
|
2011-01-31 10:01:56 -06:00
|
|
|
ipa permission-add --type=user --permissions=add "Add Users"
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
Add a permission that grants the ability to manage group membership:
|
2011-01-31 10:01:56 -06:00
|
|
|
ipa permission-add --attrs=member --permissions=write --type=group "Manage Group Members"
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2010-12-01 10:23:52 -06:00
|
|
|
|
2011-01-21 02:20:01 -06:00
|
|
|
ACI_PREFIX=u"permission"
|
2010-12-01 10:23:52 -06:00
|
|
|
|
2011-02-01 10:57:18 -06:00
|
|
|
output_params = (
|
|
|
|
Str('ipapermissiontype',
|
|
|
|
label=_('Permission Type'),
|
|
|
|
),
|
2012-02-02 14:28:15 -06:00
|
|
|
Str('aci',
|
|
|
|
label=_('ACI'),
|
|
|
|
),
|
2011-02-01 10:57:18 -06:00
|
|
|
)
|
|
|
|
|
2012-04-17 11:42:35 -05:00
|
|
|
def filter_options(options, keys):
|
|
|
|
"""Return a dict that includes entries from `options` that are in `keys`
|
|
|
|
|
|
|
|
example:
|
|
|
|
>>> filtered = filter_options({'a': 1, 'b': 2, 'c': 3}, ['a', 'c'])
|
|
|
|
>>> filtered == {'a': 1, 'c': 3}
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
return dict((k, options[k]) for k in keys if k in options)
|
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
class permission(LDAPObject):
|
|
|
|
"""
|
|
|
|
Permission object.
|
|
|
|
"""
|
|
|
|
container_dn = api.env.container_permission
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('permission')
|
|
|
|
object_name_plural = _('permissions')
|
2011-02-01 10:57:18 -06:00
|
|
|
object_class = ['groupofnames', 'ipapermission']
|
2011-01-31 10:01:56 -06:00
|
|
|
default_attributes = ['cn', 'member', 'memberof',
|
2011-02-01 10:57:18 -06:00
|
|
|
'memberindirect', 'ipapermissiontype',
|
2010-12-01 10:23:52 -06:00
|
|
|
]
|
2012-02-02 14:28:15 -06:00
|
|
|
aci_attributes = ['aci', 'group', 'permissions', 'attrs', 'type',
|
2011-12-06 17:15:41 -06:00
|
|
|
'filter', 'subtree', 'targetgroup', 'memberof',
|
2010-12-01 10:23:52 -06:00
|
|
|
]
|
|
|
|
attribute_members = {
|
|
|
|
'member': ['privilege'],
|
2012-11-15 20:38:26 -06:00
|
|
|
'memberindirect': ['role'],
|
2010-12-01 10:23:52 -06:00
|
|
|
}
|
2012-02-29 12:31:20 -06:00
|
|
|
rdn_is_primary_key = True
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
label = _('Permissions')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('Permission')
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
takes_params = (
|
|
|
|
Str('cn',
|
|
|
|
cli_name='name',
|
|
|
|
label=_('Permission name'),
|
|
|
|
primary_key=True,
|
2012-04-06 03:56:46 -05:00
|
|
|
pattern='^[-_ a-zA-Z0-9]+$',
|
|
|
|
pattern_errmsg="May only contain letters, numbers, -, _, and space",
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
2011-11-21 09:50:27 -06:00
|
|
|
Str('permissions+',
|
2010-12-01 10:23:52 -06:00
|
|
|
cli_name='permissions',
|
|
|
|
label=_('Permissions'),
|
2013-02-14 11:01:16 -06:00
|
|
|
doc=_('Permissions to grant ' \
|
2010-12-01 10:23:52 -06:00
|
|
|
'(read, write, add, delete, all)'),
|
2011-11-21 09:50:27 -06:00
|
|
|
csv=True,
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
2011-11-21 09:50:27 -06:00
|
|
|
Str('attrs*',
|
2010-12-01 10:23:52 -06:00
|
|
|
cli_name='attrs',
|
|
|
|
label=_('Attributes'),
|
2013-02-14 11:01:16 -06:00
|
|
|
doc=_('Attributes to which the permission applies'),
|
2011-11-21 09:50:27 -06:00
|
|
|
csv=True,
|
2010-12-17 15:57:28 -06:00
|
|
|
normalizer=lambda value: value.lower(),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
StrEnum('type?',
|
|
|
|
cli_name='type',
|
|
|
|
label=_('Type'),
|
2010-12-30 08:12:35 -06:00
|
|
|
doc=_('Type of IPA object (user, group, host, hostgroup, service, netgroup, dns)'),
|
2011-01-13 10:32:57 -06:00
|
|
|
values=(u'user', u'group', u'host', u'service', u'hostgroup', u'netgroup', u'dnsrecord',),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
Str('memberof?',
|
|
|
|
cli_name='memberof',
|
|
|
|
label=_('Member of group'), # FIXME: Does this label make sense?
|
|
|
|
doc=_('Target members of a group'),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
Str('filter?',
|
|
|
|
cli_name='filter',
|
|
|
|
label=_('Filter'),
|
|
|
|
doc=_('Legal LDAP filter (e.g. ou=Engineering)'),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
Str('subtree?',
|
|
|
|
cli_name='subtree',
|
|
|
|
label=_('Subtree'),
|
|
|
|
doc=_('Subtree to apply permissions to'),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
Str('targetgroup?',
|
|
|
|
cli_name='targetgroup',
|
|
|
|
label=_('Target group'),
|
|
|
|
doc=_('User group to apply permissions to'),
|
2012-05-16 06:36:35 -05:00
|
|
|
flags=('ask_create'),
|
2010-12-01 10:23:52 -06:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2011-02-01 10:57:18 -06:00
|
|
|
# Don't allow SYSTEM permissions to be modified or removed
|
|
|
|
def check_system(self, ldap, dn, *keys):
|
|
|
|
try:
|
|
|
|
(dn, entry_attrs) = ldap.get_entry(dn, ['ipapermissiontype'])
|
|
|
|
except errors.NotFound:
|
|
|
|
self.handle_not_found(*keys)
|
|
|
|
if 'ipapermissiontype' in entry_attrs:
|
|
|
|
if 'SYSTEM' in entry_attrs['ipapermissiontype']:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2012-06-29 06:24:14 -05:00
|
|
|
def filter_aci_attributes(self, options):
|
|
|
|
"""Return option dictionary that only includes ACI attributes"""
|
|
|
|
return dict((k, v) for k, v in options.items() if
|
|
|
|
k in self.aci_attributes)
|
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
api.register(permission)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_add(LDAPCreate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add a new permission.')
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
msg_summary = _('Added permission "%(value)s"')
|
2012-02-02 14:28:15 -06:00
|
|
|
has_output_params = LDAPCreate.has_output_params + output_params
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-12-01 10:23:52 -06:00
|
|
|
# Test the ACI before going any further
|
2012-06-29 06:24:14 -05:00
|
|
|
opts = self.obj.filter_aci_attributes(options)
|
2010-12-01 10:23:52 -06:00
|
|
|
opts['test'] = True
|
|
|
|
opts['permission'] = keys[-1]
|
2011-01-21 02:20:01 -06:00
|
|
|
opts['aciprefix'] = ACI_PREFIX
|
2012-04-17 11:48:33 -05:00
|
|
|
self.api.Command.aci_add(keys[-1], **opts)
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
# Clear the aci attributes out of the permission entry
|
|
|
|
for o in options:
|
|
|
|
try:
|
2011-01-31 10:01:56 -06:00
|
|
|
if o not in ['objectclass']:
|
2010-12-01 10:23:52 -06:00
|
|
|
del entry_attrs[o]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-12-01 10:23:52 -06:00
|
|
|
# Now actually add the aci.
|
2012-06-29 06:24:14 -05:00
|
|
|
opts = self.obj.filter_aci_attributes(options)
|
2010-12-01 10:23:52 -06:00
|
|
|
opts['test'] = False
|
|
|
|
opts['permission'] = keys[-1]
|
2011-01-21 02:20:01 -06:00
|
|
|
opts['aciprefix'] = ACI_PREFIX
|
2010-12-01 10:23:52 -06:00
|
|
|
try:
|
2011-01-21 02:20:01 -06:00
|
|
|
result = self.api.Command.aci_add(keys[-1], **opts)['result']
|
2010-12-01 10:23:52 -06:00
|
|
|
for attr in self.obj.aci_attributes:
|
|
|
|
if attr in result:
|
|
|
|
entry_attrs[attr] = result[attr]
|
2010-12-17 14:35:24 -06:00
|
|
|
except errors.InvalidSyntax, e:
|
|
|
|
# A syntax error slipped past our attempt at validation, clean up
|
|
|
|
self.api.Command.permission_del(keys[-1])
|
|
|
|
raise e
|
2010-12-01 10:23:52 -06:00
|
|
|
except Exception, e:
|
2010-12-17 14:35:24 -06:00
|
|
|
# Something bad happened, clean up as much as we can and return
|
|
|
|
# that error
|
|
|
|
try:
|
|
|
|
self.api.Command.permission_del(keys[-1])
|
|
|
|
except Exception, ignore:
|
|
|
|
pass
|
|
|
|
try:
|
2011-01-21 02:20:01 -06:00
|
|
|
self.api.Command.aci_del(keys[-1], aciprefix=ACI_PREFIX)
|
2010-12-17 14:35:24 -06:00
|
|
|
except Exception, ignore:
|
|
|
|
pass
|
2010-12-01 10:23:52 -06:00
|
|
|
raise e
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(permission_add)
|
|
|
|
|
2012-06-27 06:10:10 -05:00
|
|
|
class permission_add_noaci(LDAPCreate):
|
|
|
|
__doc__ = _('Add a system permission without an ACI')
|
|
|
|
|
|
|
|
msg_summary = _('Added permission "%(value)s"')
|
|
|
|
has_output_params = LDAPCreate.has_output_params + output_params
|
|
|
|
NO_CLI = True
|
|
|
|
|
|
|
|
takes_options = (
|
|
|
|
StrEnum('permissiontype?',
|
|
|
|
label=_('Permission type'),
|
|
|
|
values=(u'SYSTEM',),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_args(self):
|
|
|
|
# do not validate system permission names
|
|
|
|
yield self.obj.primary_key.clone(pattern=None, pattern_errmsg=None)
|
|
|
|
|
|
|
|
def get_options(self):
|
|
|
|
for option in super(permission_add_noaci, self).get_options():
|
|
|
|
# filter out ACI options
|
|
|
|
if option.name in self.obj.aci_attributes:
|
|
|
|
continue
|
|
|
|
yield option
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2012-06-27 06:10:10 -05:00
|
|
|
permission_type = options.get('permissiontype')
|
|
|
|
if permission_type:
|
|
|
|
entry_attrs['ipapermissiontype'] = [ permission_type ]
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(permission_add_noaci)
|
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
class permission_del(LDAPDelete):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Delete a permission.')
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
msg_summary = _('Deleted permission "%(value)s"')
|
|
|
|
|
2012-06-27 06:10:10 -05:00
|
|
|
takes_options = LDAPDelete.takes_options + (
|
|
|
|
Flag('force',
|
|
|
|
label=_('Force'),
|
|
|
|
flags=['no_option', 'no_output'],
|
|
|
|
doc=_('force delete of SYSTEM permissions'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
def pre_callback(self, ldap, dn, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2012-06-27 06:10:10 -05:00
|
|
|
if not options.get('force') and not self.obj.check_system(ldap, dn, *keys):
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.ACIError(
|
|
|
|
info=_('A SYSTEM permission may not be removed'))
|
2011-01-21 02:20:01 -06:00
|
|
|
# remove permission even when the underlying ACI is missing
|
|
|
|
try:
|
|
|
|
self.api.Command.aci_del(keys[-1], aciprefix=ACI_PREFIX)
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
2010-12-01 10:23:52 -06:00
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(permission_del)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_mod(LDAPUpdate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify a permission.')
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
msg_summary = _('Modified permission "%(value)s"')
|
2011-02-01 10:57:18 -06:00
|
|
|
has_output_params = LDAPUpdate.has_output_params + output_params
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2011-02-01 10:57:18 -06:00
|
|
|
if not self.obj.check_system(ldap, dn, *keys):
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.ACIError(
|
|
|
|
info=_('A SYSTEM permission may not be modified'))
|
2011-02-01 10:57:18 -06:00
|
|
|
|
2011-01-27 05:17:10 -06:00
|
|
|
# check if permission is in LDAP
|
2010-12-10 21:52:44 -06:00
|
|
|
try:
|
2013-02-04 04:48:58 -06:00
|
|
|
(dn, attrs) = ldap.get_entry(dn, attrs_list)
|
2010-12-10 21:52:44 -06:00
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
2011-01-27 05:17:10 -06:00
|
|
|
|
|
|
|
# when renaming permission, check if the target permission does not
|
|
|
|
# exists already. Then, make changes to underlying ACI
|
|
|
|
if 'rename' in options:
|
2012-04-11 02:37:15 -05:00
|
|
|
if options['rename']:
|
|
|
|
try:
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
try:
|
|
|
|
new_dn = EditableDN(dn)
|
|
|
|
new_dn[0]['cn'] # assure the first RDN has cn as it's type
|
|
|
|
except (IndexError, KeyError), e:
|
|
|
|
raise ValueError("expected dn starting with 'cn=' but got '%s'" % dn)
|
|
|
|
new_dn[0].value = options['rename']
|
2013-02-04 04:48:58 -06:00
|
|
|
(new_dn, attrs) = ldap.get_entry(new_dn, attrs_list)
|
2012-04-11 02:37:15 -05:00
|
|
|
raise errors.DuplicateEntry()
|
|
|
|
except errors.NotFound:
|
|
|
|
pass # permission may be renamed, continue
|
|
|
|
else:
|
2012-04-17 11:48:33 -05:00
|
|
|
raise errors.ValidationError(
|
2012-07-04 07:52:47 -05:00
|
|
|
name='rename', error=_('New name can not be empty'))
|
2011-01-27 05:17:10 -06:00
|
|
|
|
2012-06-29 06:24:14 -05:00
|
|
|
opts = self.obj.filter_aci_attributes(options)
|
2010-12-01 10:23:52 -06:00
|
|
|
setattr(context, 'aciupdate', False)
|
|
|
|
# If there are no options left we don't need to do anything to the
|
|
|
|
# underlying ACI.
|
|
|
|
if len(opts) > 0:
|
|
|
|
opts['permission'] = keys[-1]
|
2011-01-21 02:20:01 -06:00
|
|
|
opts['aciprefix'] = ACI_PREFIX
|
2012-04-17 11:48:33 -05:00
|
|
|
self.api.Command.aci_mod(keys[-1], **opts)
|
|
|
|
setattr(context, 'aciupdate', True)
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
# Clear the aci attributes out of the permission entry
|
|
|
|
for o in self.obj.aci_attributes:
|
|
|
|
try:
|
|
|
|
del entry_attrs[o]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
|
2012-04-19 07:06:32 -05:00
|
|
|
if call_func.func_name == 'update_entry':
|
|
|
|
if isinstance(exc, errors.EmptyModlist):
|
|
|
|
aciupdate = getattr(context, 'aciupdate')
|
2012-05-16 06:36:35 -05:00
|
|
|
if aciupdate:
|
2012-04-19 07:06:32 -05:00
|
|
|
return
|
|
|
|
raise exc
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2011-01-21 02:20:01 -06:00
|
|
|
# rename the underlying ACI after the change to permission
|
2011-01-27 05:17:10 -06:00
|
|
|
cn = keys[-1]
|
|
|
|
|
2011-01-21 02:20:01 -06:00
|
|
|
if 'rename' in options:
|
2011-01-27 05:17:10 -06:00
|
|
|
self.api.Command.aci_mod(cn,aciprefix=ACI_PREFIX,
|
2011-01-21 02:20:01 -06:00
|
|
|
permission=options['rename'])
|
|
|
|
|
2011-01-27 05:17:10 -06:00
|
|
|
self.api.Command.aci_rename(cn, aciprefix=ACI_PREFIX,
|
2012-04-17 11:48:33 -05:00
|
|
|
newname=options['rename'])
|
2011-01-27 05:17:10 -06:00
|
|
|
|
|
|
|
cn = options['rename'] # rename finished
|
2011-01-21 02:20:01 -06:00
|
|
|
|
2012-08-22 09:39:01 -05:00
|
|
|
# all common options to permission-mod and show need to be listed here
|
|
|
|
common_options = filter_options(options, ['all', 'raw', 'rights'])
|
2012-04-17 11:48:33 -05:00
|
|
|
result = self.api.Command.permission_show(cn, **common_options)['result']
|
2012-08-22 09:39:01 -05:00
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
for r in result:
|
2011-12-06 17:15:41 -06:00
|
|
|
if not r.startswith('member_'):
|
2010-12-01 10:23:52 -06:00
|
|
|
entry_attrs[r] = result[r]
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(permission_mod)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_find(LDAPSearch):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Search for permissions.')
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
msg_summary = ngettext(
|
2011-02-23 15:47:49 -06:00
|
|
|
'%(count)d permission matched', '%(count)d permissions matched', 0
|
2010-12-01 10:23:52 -06:00
|
|
|
)
|
2011-02-01 10:57:18 -06:00
|
|
|
has_output_params = LDAPSearch.has_output_params + output_params
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
def post_callback(self, ldap, entries, truncated, *args, **options):
|
2012-04-17 11:42:35 -05:00
|
|
|
|
|
|
|
# There is an option/param overlap: "cn" must be passed as "aciname"
|
|
|
|
# to aci-find. Besides that we don't need cn anymore so pop it
|
|
|
|
aciname = options.pop('cn', None)
|
|
|
|
|
2012-05-31 05:39:24 -05:00
|
|
|
pkey_only = options.pop('pkey_only', False)
|
|
|
|
if not pkey_only:
|
|
|
|
for entry in entries:
|
|
|
|
(dn, attrs) = entry
|
|
|
|
try:
|
2012-04-17 11:42:35 -05:00
|
|
|
common_options = filter_options(options, ['all', 'raw'])
|
|
|
|
aci = self.api.Command.aci_show(attrs['cn'][0],
|
|
|
|
aciprefix=ACI_PREFIX, **common_options)['result']
|
2012-05-31 05:39:24 -05:00
|
|
|
|
|
|
|
# copy information from respective ACI to permission entry
|
|
|
|
for attr in self.obj.aci_attributes:
|
|
|
|
if attr in aci:
|
|
|
|
attrs[attr] = aci[attr]
|
|
|
|
except errors.NotFound:
|
|
|
|
self.debug('ACI not found for %s' % attrs['cn'][0])
|
2012-05-23 10:00:24 -05:00
|
|
|
if truncated:
|
|
|
|
# size/time limit met, no need to search acis
|
|
|
|
return truncated
|
|
|
|
|
|
|
|
if 'sizelimit' in options:
|
|
|
|
max_entries = options['sizelimit']
|
|
|
|
else:
|
|
|
|
config = ldap.get_ipa_config()[1]
|
|
|
|
max_entries = config['ipasearchrecordslimit']
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
# Now find all the ACIs that match. Once we find them, add any that
|
|
|
|
# aren't already in the list along with their permission info.
|
2011-01-21 02:20:01 -06:00
|
|
|
|
2012-06-29 06:24:14 -05:00
|
|
|
opts = self.obj.filter_aci_attributes(options)
|
2012-04-17 11:42:35 -05:00
|
|
|
if aciname:
|
|
|
|
opts['aciname'] = aciname
|
2012-04-17 11:48:33 -05:00
|
|
|
opts['aciprefix'] = ACI_PREFIX
|
2012-04-17 11:42:35 -05:00
|
|
|
# permission ACI attribute is needed
|
2012-02-02 14:28:15 -06:00
|
|
|
aciresults = self.api.Command.aci_find(*args, **opts)
|
2010-12-01 10:23:52 -06:00
|
|
|
truncated = truncated or aciresults['truncated']
|
|
|
|
results = aciresults['result']
|
2011-01-21 02:20:01 -06:00
|
|
|
|
2010-12-01 10:23:52 -06:00
|
|
|
for aci in results:
|
|
|
|
found = False
|
|
|
|
if 'permission' in aci:
|
|
|
|
for entry in entries:
|
2010-12-08 12:33:40 -06:00
|
|
|
(dn, attrs) = entry
|
2011-01-21 02:20:01 -06:00
|
|
|
if aci['permission'] == attrs['cn'][0]:
|
2010-12-01 10:23:52 -06:00
|
|
|
found = True
|
|
|
|
break
|
2010-12-17 14:35:24 -06:00
|
|
|
if not found:
|
2012-04-17 11:42:35 -05:00
|
|
|
common_options = filter_options(options, ['all', 'raw'])
|
|
|
|
permission = self.api.Command.permission_show(
|
|
|
|
aci['permission'], **common_options)['result']
|
2012-02-02 14:28:15 -06:00
|
|
|
dn = permission['dn']
|
|
|
|
del permission['dn']
|
2012-05-31 05:39:24 -05:00
|
|
|
if pkey_only:
|
2013-01-31 04:19:13 -06:00
|
|
|
pk = self.obj.primary_key.name
|
|
|
|
new_entry = ldap.make_entry(dn, {pk: permission[pk]})
|
2012-05-31 05:39:24 -05:00
|
|
|
else:
|
2013-01-31 04:19:13 -06:00
|
|
|
new_entry = ldap.make_entry(dn, permission)
|
2012-05-31 05:39:24 -05:00
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
if (dn, permission) not in entries:
|
2012-05-23 10:00:24 -05:00
|
|
|
if len(entries) < max_entries:
|
2012-05-31 05:39:24 -05:00
|
|
|
entries.append(new_entry)
|
2012-05-23 10:00:24 -05:00
|
|
|
else:
|
|
|
|
truncated = True
|
|
|
|
break
|
|
|
|
return truncated
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
api.register(permission_find)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_show(LDAPRetrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Display information about a permission.')
|
|
|
|
|
2011-02-01 10:57:18 -06:00
|
|
|
has_output_params = LDAPRetrieve.has_output_params + output_params
|
2010-12-01 10:23:52 -06:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-12-01 10:23:52 -06:00
|
|
|
try:
|
2012-04-17 11:42:35 -05:00
|
|
|
common_options = filter_options(options, ['all', 'raw'])
|
|
|
|
aci = self.api.Command.aci_show(keys[-1], aciprefix=ACI_PREFIX,
|
|
|
|
**common_options)['result']
|
2010-12-01 10:23:52 -06:00
|
|
|
for attr in self.obj.aci_attributes:
|
|
|
|
if attr in aci:
|
|
|
|
entry_attrs[attr] = aci[attr]
|
|
|
|
except errors.NotFound:
|
2011-01-31 10:01:56 -06:00
|
|
|
self.debug('ACI not found for %s' % entry_attrs['cn'][0])
|
2011-04-20 12:26:20 -05:00
|
|
|
if options.get('rights', False) and options.get('all', False):
|
|
|
|
# The ACI attributes are just broken-out components of aci so
|
|
|
|
# the rights should all match it.
|
|
|
|
for attr in self.obj.aci_attributes:
|
|
|
|
entry_attrs['attributelevelrights'][attr] = entry_attrs['attributelevelrights']['aci']
|
2010-12-01 10:23:52 -06:00
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(permission_show)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_add_member(LDAPAddMember):
|
|
|
|
"""
|
|
|
|
Add members to a permission.
|
|
|
|
"""
|
2011-01-20 14:07:43 -06:00
|
|
|
NO_CLI = True
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
api.register(permission_add_member)
|
|
|
|
|
|
|
|
|
|
|
|
class permission_remove_member(LDAPRemoveMember):
|
|
|
|
"""
|
|
|
|
Remove members from a permission.
|
|
|
|
"""
|
2011-01-20 14:07:43 -06:00
|
|
|
NO_CLI = True
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
api.register(permission_remove_member)
|