2009-05-11 08:49:07 -05:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009 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.
|
2009-05-11 08:49:07 -05: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 import api
|
|
|
|
from ipalib import Int, Str
|
|
|
|
from ipalib.plugins.baseldap import *
|
2013-01-08 03:10:35 -06:00
|
|
|
from ipalib.plugins import baseldap
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib import _, ngettext
|
2012-06-20 08:08:33 -05:00
|
|
|
if api.env.in_server and api.env.context in ['lite', 'server']:
|
|
|
|
try:
|
|
|
|
import ipaserver.dcerpc
|
|
|
|
_dcerpc_bindings_installed = True
|
2012-09-20 06:02:15 -05:00
|
|
|
except ImportError:
|
2012-06-20 08:08:33 -05:00
|
|
|
_dcerpc_bindings_installed = False
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
__doc__ = _("""
|
2009-06-16 09:51:44 -05:00
|
|
|
Groups of users
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-10-01 12:33:33 -05:00
|
|
|
Manage groups of users. By default, new groups are POSIX groups. You
|
2011-03-04 10:08:54 -06:00
|
|
|
can add the --nonposix option to the group-add command to mark a new group
|
2011-11-16 17:42:40 -06:00
|
|
|
as non-POSIX. You can use the --posix argument with the group-mod command
|
|
|
|
to convert a non-POSIX group into a POSIX group. POSIX groups cannot be
|
2010-08-24 22:40:32 -05:00
|
|
|
converted to non-POSIX groups.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
Every group must have a description.
|
|
|
|
|
2011-03-04 10:08:54 -06:00
|
|
|
POSIX groups must have a Group ID (GID) number. Changing a GID is
|
|
|
|
supported but can have an impact on your file permissions. It is not necessary
|
2010-08-24 22:40:32 -05:00
|
|
|
to supply a GID when creating a group. IPA will generate one automatically
|
|
|
|
if it is not provided.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
|
|
|
Add a new group:
|
|
|
|
ipa group-add --desc='local administrators' localadmins
|
|
|
|
|
2010-10-01 12:33:33 -05:00
|
|
|
Add a new non-POSIX group:
|
|
|
|
ipa group-add --nonposix --desc='remote administrators' remoteadmins
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Convert a non-POSIX group to posix:
|
2010-10-01 12:33:33 -05:00
|
|
|
ipa group-mod --posix remoteadmins
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new POSIX group with a specific Group ID number:
|
2010-10-01 12:33:33 -05:00
|
|
|
ipa group-add --gid=500 --desc='unix admins' unixadmins
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new POSIX group and let IPA assign a Group ID number:
|
2010-10-01 12:33:33 -05:00
|
|
|
ipa group-add --desc='printer admins' printeradmins
|
2010-08-24 22:40:32 -05:00
|
|
|
|
2010-06-02 13:08:50 -05:00
|
|
|
Remove a group:
|
|
|
|
ipa group-del unixadmins
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
To add the "remoteadmins" group to the "localadmins" group:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa group-add-member --groups=remoteadmins localadmins
|
|
|
|
|
2013-02-22 07:48:50 -06:00
|
|
|
Add multiple users to the "localadmins" group:
|
|
|
|
ipa group-add-member --users=test1 --users=test2 localadmins
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Remove a user from the "localadmins" group:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa group-remove-member --users=test2 localadmins
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Display information about a named group.
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa group-show localadmins
|
2012-09-20 06:31:01 -05:00
|
|
|
|
|
|
|
External group membership is designed to allow users from trusted domains
|
|
|
|
to be mapped to local POSIX groups in order to actually use IPA resources.
|
|
|
|
External members should be added to groups that specifically created as
|
|
|
|
external and non-POSIX. Such group later should be included into one of POSIX
|
|
|
|
groups.
|
|
|
|
|
2012-10-31 14:52:12 -05:00
|
|
|
An external group member is currently a Security Identifier (SID) as defined by
|
|
|
|
the trusted domain. When adding external group members, it is possible to
|
|
|
|
specify them in either SID, or DOM\\name, or name@domain format. IPA will attempt
|
|
|
|
to resolve passed name to SID with the use of Global Catalog of the trusted domain.
|
2012-09-20 06:31:01 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-10-31 14:52:12 -05:00
|
|
|
1. Create group for the trusted domain admins' mapping and their local POSIX group:
|
2012-09-20 06:31:01 -05:00
|
|
|
|
|
|
|
ipa group-add --desc='<ad.domain> admins external map' ad_admins_external --external
|
|
|
|
ipa group-add --desc='<ad.domain> admins' ad_admins
|
|
|
|
|
2012-10-31 14:52:12 -05:00
|
|
|
2. Add security identifier of Domain Admins of the <ad.domain> to the ad_admins_external
|
|
|
|
group:
|
2012-09-20 06:31:01 -05:00
|
|
|
|
2012-10-31 14:52:12 -05:00
|
|
|
ipa group-add-member ad_admins_external --external 'AD\\Domain Admins'
|
2012-09-20 06:31:01 -05:00
|
|
|
|
2012-10-31 14:52:12 -05:00
|
|
|
3. Allow members of ad_admins_external group to be associated with ad_admins POSIX group:
|
2012-09-20 06:31:01 -05:00
|
|
|
|
|
|
|
ipa group-add-member ad_admins --groups ad_admins_external
|
2012-10-31 14:52:12 -05:00
|
|
|
|
|
|
|
4. List members of external members of ad_admins_external group to see their SIDs:
|
|
|
|
|
|
|
|
ipa group-show ad_admins_external
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2009-05-12 11:40:14 -05:00
|
|
|
|
2012-10-09 04:03:00 -05:00
|
|
|
PROTECTED_GROUPS = (u'admins', u'trust admins', u'default smb group')
|
2012-05-23 04:44:53 -05:00
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group(LDAPObject):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
Group object.
|
|
|
|
"""
|
2009-08-27 08:51:48 -05:00
|
|
|
container_dn = api.env.container_group
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('group')
|
|
|
|
object_name_plural = _('groups')
|
2009-08-27 08:51:48 -05:00
|
|
|
object_class = ['ipausergroup']
|
|
|
|
object_class_config = 'ipagroupobjectclasses'
|
2012-06-20 08:08:33 -05:00
|
|
|
possible_objectclasses = ['posixGroup', 'mepManagedEntry', 'ipaExternalGroup']
|
2014-01-09 07:43:37 -06:00
|
|
|
permission_filter_objectclasses = ['ipausergroup']
|
2010-07-12 13:17:33 -05:00
|
|
|
search_attributes_config = 'ipagroupsearchfields'
|
2009-10-21 09:12:11 -05:00
|
|
|
default_attributes = [
|
2010-10-04 16:45:40 -05:00
|
|
|
'cn', 'description', 'gidnumber', 'member', 'memberof',
|
2012-06-20 08:08:33 -05:00
|
|
|
'memberindirect', 'memberofindirect', 'ipaexternalmember',
|
2009-10-21 09:12:11 -05:00
|
|
|
]
|
2009-08-27 08:51:48 -05:00
|
|
|
uuid_attribute = 'ipauniqueid'
|
|
|
|
attribute_members = {
|
|
|
|
'member': ['user', 'group'],
|
2011-05-31 16:52:35 -05:00
|
|
|
'memberof': ['group', 'netgroup', 'role', 'hbacrule', 'sudorule'],
|
2011-06-24 14:18:35 -05:00
|
|
|
'memberindirect': ['user', 'group'],
|
2011-05-31 16:52:35 -05:00
|
|
|
'memberofindirect': ['group', 'netgroup', 'role', 'hbacrule',
|
|
|
|
'sudorule'],
|
2009-08-27 08:51:48 -05:00
|
|
|
}
|
2012-02-29 12:31:20 -06:00
|
|
|
rdn_is_primary_key = True
|
2014-03-26 09:17:34 -05:00
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Groups': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'anonymous',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'businesscategory', 'cn', 'description', 'gidnumber',
|
|
|
|
'ipaexternalmember', 'ipauniqueid', 'mepmanagedby', 'o',
|
|
|
|
'objectclass', 'ou', 'owner', 'seealso',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'System: Read Group Membership': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'all',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'member', 'memberof', 'memberuid',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2009-08-27 08:51:48 -05:00
|
|
|
|
2010-02-08 06:03:28 -06:00
|
|
|
label = _('User Groups')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('User Group')
|
2010-02-08 06:03:28 -06:00
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
takes_params = (
|
|
|
|
Str('cn',
|
2010-11-10 16:30:01 -06:00
|
|
|
pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?$',
|
2010-07-27 15:35:23 -05:00
|
|
|
pattern_errmsg='may only include letters, numbers, _, -, . and $',
|
2010-11-10 16:30:01 -06:00
|
|
|
maxlength=255,
|
2010-12-02 15:29:26 -06:00
|
|
|
cli_name='group_name',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Group name'),
|
2009-08-27 08:51:48 -05:00
|
|
|
primary_key=True,
|
|
|
|
normalizer=lambda value: value.lower(),
|
|
|
|
),
|
|
|
|
Str('description',
|
|
|
|
cli_name='desc',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Description'),
|
|
|
|
doc=_('Group description'),
|
2009-08-27 08:51:48 -05:00
|
|
|
),
|
2009-05-11 08:49:07 -05:00
|
|
|
Int('gidnumber?',
|
|
|
|
cli_name='gid',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('GID'),
|
|
|
|
doc=_('GID (use this option to set it manually)'),
|
2012-02-23 03:25:22 -06:00
|
|
|
minvalue=1,
|
2009-05-11 08:49:07 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2012-09-24 08:57:13 -05:00
|
|
|
ipaexternalmember_param = Str('ipaexternalmember*',
|
|
|
|
cli_name='external',
|
|
|
|
label=_('External member'),
|
2013-02-14 11:01:16 -06:00
|
|
|
doc=_('Members of a trusted domain in DOM\\name or name@domain form'),
|
2012-09-24 08:57:13 -05:00
|
|
|
csv=True,
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_add(LDAPCreate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Create a new group.')
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
msg_summary = _('Added group "%(value)s"')
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
takes_options = LDAPCreate.takes_options + (
|
2010-10-01 12:33:33 -05:00
|
|
|
Flag('nonposix',
|
|
|
|
cli_name='nonposix',
|
2011-03-04 10:08:54 -06:00
|
|
|
doc=_('Create as a non-POSIX group'),
|
2010-10-01 12:33:33 -05:00
|
|
|
default=False,
|
2009-05-11 08:49:07 -05:00
|
|
|
),
|
2012-06-20 08:08:33 -05:00
|
|
|
Flag('external',
|
|
|
|
cli_name='external',
|
|
|
|
doc=_('Allow adding external non-IPA members from trusted domains'),
|
|
|
|
default=False,
|
|
|
|
),
|
2009-05-11 08:49:07 -05:00
|
|
|
)
|
|
|
|
|
2009-12-10 09:39:24 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
2012-06-20 08:08:33 -05:00
|
|
|
# As both 'external' and 'nonposix' options have default= set for
|
|
|
|
# them, they will always be present in options dict, thus we can
|
|
|
|
# safely reference the values
|
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-20 08:08:33 -05:00
|
|
|
if options['external']:
|
|
|
|
entry_attrs['objectclass'].append('ipaexternalgroup')
|
|
|
|
if 'gidnumber' in options:
|
|
|
|
raise errors.RequirementError(name='gid')
|
|
|
|
elif not options['nonposix']:
|
2009-10-08 05:55:14 -05:00
|
|
|
entry_attrs['objectclass'].append('posixgroup')
|
2010-06-25 15:14:46 -05:00
|
|
|
if not 'gidnumber' in options:
|
2013-01-08 03:10:35 -06:00
|
|
|
entry_attrs['gidnumber'] = baseldap.DNA_MAGIC
|
2009-08-27 08:51:48 -05:00
|
|
|
return dn
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2009-06-16 09:51:44 -05:00
|
|
|
api.register(group_add)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_del(LDAPDelete):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Delete group.')
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
msg_summary = _('Deleted group "%(value)s"')
|
|
|
|
|
2009-08-27 08:51:48 -05: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)
|
2013-10-31 11:54:21 -05:00
|
|
|
config = ldap.get_ipa_config()
|
2009-08-27 08:51:48 -05:00
|
|
|
def_primary_group = config.get('ipadefaultprimarygroup', '')
|
|
|
|
def_primary_group_dn = group_dn = self.obj.get_dn(def_primary_group)
|
|
|
|
if dn == def_primary_group_dn:
|
2011-01-25 11:46:26 -06:00
|
|
|
raise errors.DefaultGroupError()
|
2010-10-08 21:44:48 -05:00
|
|
|
group_attrs = self.obj.methods.show(
|
|
|
|
self.obj.get_primary_key_from_dn(dn), all=True
|
|
|
|
)['result']
|
2012-09-25 07:14:57 -05:00
|
|
|
if keys[0] in PROTECTED_GROUPS:
|
2012-05-23 04:44:53 -05:00
|
|
|
raise errors.ProtectedEntryError(label=_(u'group'), key=keys[0],
|
|
|
|
reason=_(u'privileged group'))
|
2010-08-09 15:40:51 -05:00
|
|
|
if 'mepmanagedby' in group_attrs:
|
|
|
|
raise errors.ManagedGroupError()
|
2009-08-27 08:51:48 -05:00
|
|
|
return dn
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2010-01-28 16:19:30 -06:00
|
|
|
def post_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)
|
2010-01-28 16:19:30 -06:00
|
|
|
try:
|
2010-05-14 14:58:34 -05:00
|
|
|
api.Command['pwpolicy_del'](keys[-1])
|
2010-01-28 16:19:30 -06:00
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2009-06-16 09:51:44 -05:00
|
|
|
api.register(group_del)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_mod(LDAPUpdate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify a group.')
|
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = _('Modified group "%(value)s"')
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
takes_options = LDAPUpdate.takes_options + (
|
2009-05-11 08:49:07 -05:00
|
|
|
Flag('posix',
|
|
|
|
cli_name='posix',
|
2010-10-01 12:33:33 -05:00
|
|
|
doc=_('change to a POSIX group'),
|
2009-05-11 08:49:07 -05:00
|
|
|
),
|
2012-06-20 08:08:33 -05:00
|
|
|
Flag('external',
|
|
|
|
cli_name='external',
|
|
|
|
doc=_('change to support external non-IPA members from trusted domains'),
|
|
|
|
default=False,
|
|
|
|
),
|
2009-05-11 08:49:07 -05:00
|
|
|
)
|
2009-08-27 08:51:48 -05:00
|
|
|
|
|
|
|
def pre_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)
|
2012-09-25 07:14:57 -05:00
|
|
|
|
|
|
|
is_protected_group = keys[-1] in PROTECTED_GROUPS
|
|
|
|
|
2013-02-11 03:19:53 -06:00
|
|
|
if 'rename' in options or 'cn' in entry_attrs:
|
2012-09-25 07:14:57 -05:00
|
|
|
if is_protected_group:
|
|
|
|
raise errors.ProtectedEntryError(label=u'group', key=keys[-1],
|
|
|
|
reason=u'Cannot be renamed')
|
|
|
|
|
2012-06-20 08:08:33 -05:00
|
|
|
if ('posix' in options and options['posix']) or 'gidnumber' in options:
|
2013-10-31 11:54:21 -05:00
|
|
|
old_entry_attrs = ldap.get_entry(dn, ['objectclass'])
|
|
|
|
dn = old_entry_attrs.dn
|
2012-06-20 08:08:33 -05:00
|
|
|
if 'ipaexternalgroup' in old_entry_attrs['objectclass']:
|
|
|
|
raise errors.ExternalGroupViolation()
|
2009-08-27 08:51:48 -05:00
|
|
|
if 'posixgroup' in old_entry_attrs['objectclass']:
|
|
|
|
if options['posix']:
|
2009-05-21 07:37:04 -05:00
|
|
|
raise errors.AlreadyPosixGroup()
|
2009-05-11 08:49:07 -05:00
|
|
|
else:
|
2009-08-27 08:51:48 -05:00
|
|
|
old_entry_attrs['objectclass'].append('posixgroup')
|
|
|
|
entry_attrs['objectclass'] = old_entry_attrs['objectclass']
|
2010-06-25 15:14:46 -05:00
|
|
|
if not 'gidnumber' in options:
|
2013-01-08 03:10:35 -06:00
|
|
|
entry_attrs['gidnumber'] = baseldap.DNA_MAGIC
|
2012-09-25 07:14:57 -05:00
|
|
|
|
2012-06-20 08:08:33 -05:00
|
|
|
if options['external']:
|
2012-09-25 07:14:57 -05:00
|
|
|
if is_protected_group:
|
|
|
|
raise errors.ProtectedEntryError(label=u'group', key=keys[-1],
|
|
|
|
reason=u'Cannot support external non-IPA members')
|
2013-10-31 11:54:21 -05:00
|
|
|
old_entry_attrs = ldap.get_entry(dn, ['objectclass'])
|
|
|
|
dn = old_entry_attrs.dn
|
2012-06-20 08:08:33 -05:00
|
|
|
if 'posixgroup' in old_entry_attrs['objectclass']:
|
|
|
|
raise errors.PosixGroupViolation()
|
|
|
|
if 'ipaexternalgroup' in old_entry_attrs['objectclass']:
|
|
|
|
raise errors.AlreadyExternalGroup()
|
|
|
|
else:
|
|
|
|
old_entry_attrs['objectclass'].append('ipaexternalgroup')
|
|
|
|
entry_attrs['objectclass'] = old_entry_attrs['objectclass']
|
2012-09-25 07:14:57 -05:00
|
|
|
|
2011-11-28 11:31:45 -06:00
|
|
|
# Can't check for this in a validator because we lack context
|
|
|
|
if 'gidnumber' in options and options['gidnumber'] is None:
|
|
|
|
raise errors.RequirementError(name='gid')
|
2009-08-27 08:51:48 -05:00
|
|
|
return dn
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2011-11-28 11:31:45 -06:00
|
|
|
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
|
|
|
|
# Check again for GID requirement in case someone tried to clear it
|
|
|
|
# using --setattr.
|
2012-04-19 07:06:32 -05:00
|
|
|
if call_func.func_name == 'update_entry':
|
|
|
|
if isinstance(exc, errors.ObjectclassViolation):
|
|
|
|
if 'gidNumber' in exc.message and 'posixGroup' in exc.message:
|
|
|
|
raise errors.RequirementError(name='gid')
|
2011-11-28 11:31:45 -06:00
|
|
|
raise exc
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group_mod)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_find(LDAPSearch):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Search for groups.')
|
|
|
|
|
2011-01-04 14:15:54 -06:00
|
|
|
member_attributes = ['member', 'memberof']
|
2010-12-02 18:24:11 -06:00
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = ngettext(
|
|
|
|
'%(count)d group matched', '%(count)d groups matched', 0
|
|
|
|
)
|
|
|
|
|
2010-09-21 12:03:40 -05:00
|
|
|
takes_options = LDAPSearch.takes_options + (
|
|
|
|
Flag('private',
|
|
|
|
cli_name='private',
|
|
|
|
doc=_('search for private groups'),
|
|
|
|
),
|
2013-03-11 06:37:29 -05:00
|
|
|
Flag('posix',
|
|
|
|
cli_name='posix',
|
|
|
|
doc=_('search for POSIX groups'),
|
|
|
|
),
|
|
|
|
Flag('external',
|
|
|
|
cli_name='external',
|
|
|
|
doc=_('search for groups with support of external non-IPA members from trusted domains'),
|
|
|
|
),
|
|
|
|
Flag('nonposix',
|
|
|
|
cli_name='nonposix',
|
|
|
|
doc=_('search for non-POSIX groups'),
|
|
|
|
),
|
2010-09-21 12:03:40 -05:00
|
|
|
)
|
|
|
|
|
2010-11-23 08:02:54 -06:00
|
|
|
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **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(base_dn, DN)
|
2013-03-11 06:37:29 -05:00
|
|
|
|
|
|
|
# filter groups by pseudo type
|
|
|
|
filters = []
|
|
|
|
if options['posix']:
|
|
|
|
search_kw = {'objectclass': ['posixGroup']}
|
|
|
|
filters.append(ldap.make_filter(search_kw, rules=ldap.MATCH_ALL))
|
|
|
|
if options['external']:
|
|
|
|
search_kw = {'objectclass': ['ipaExternalGroup']}
|
|
|
|
filters.append(ldap.make_filter(search_kw, rules=ldap.MATCH_ALL))
|
|
|
|
if options['nonposix']:
|
|
|
|
search_kw = {'objectclass': ['posixGroup' , 'ipaExternalGroup']}
|
|
|
|
filters.append(ldap.make_filter(search_kw, rules=ldap.MATCH_NONE))
|
|
|
|
|
2010-09-21 12:03:40 -05:00
|
|
|
# if looking for private groups, we need to create a new search filter,
|
|
|
|
# because private groups have different object classes
|
|
|
|
if options['private']:
|
|
|
|
# filter based on options, oflt
|
|
|
|
search_kw = self.args_options_2_entry(**options)
|
|
|
|
search_kw['objectclass'] = ['posixGroup', 'mepManagedEntry']
|
|
|
|
oflt = ldap.make_filter(search_kw, rules=ldap.MATCH_ALL)
|
|
|
|
|
|
|
|
# filter based on 'criteria' argument
|
|
|
|
search_kw = {}
|
2013-10-31 11:54:21 -05:00
|
|
|
config = ldap.get_ipa_config()
|
2010-09-21 12:03:40 -05:00
|
|
|
attrs = config.get(self.obj.search_attributes_config, [])
|
|
|
|
if len(attrs) == 1 and isinstance(attrs[0], basestring):
|
|
|
|
search_attrs = attrs[0].split(',')
|
|
|
|
for a in search_attrs:
|
|
|
|
search_kw[a] = args[-1]
|
|
|
|
cflt = ldap.make_filter(search_kw, exact=False)
|
|
|
|
|
|
|
|
filter = ldap.combine_filters((oflt, cflt), rules=ldap.MATCH_ALL)
|
2013-03-11 06:37:29 -05:00
|
|
|
elif filters:
|
|
|
|
filters.append(filter)
|
|
|
|
filter = ldap.combine_filters(filters, rules=ldap.MATCH_ALL)
|
2010-11-23 08:02:54 -06:00
|
|
|
return (filter, base_dn, scope)
|
2010-09-21 12:03:40 -05:00
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group_find)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_show(LDAPRetrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Display information about a named group.')
|
2012-09-24 08:57:13 -05:00
|
|
|
has_output_params = LDAPRetrieve.has_output_params + (ipaexternalmember_param,)
|
2014-01-16 12:31:37 -06:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
if ('ipaexternalmember' in entry_attrs and
|
|
|
|
len(entry_attrs['ipaexternalmember']) > 0 and
|
|
|
|
'trust_resolve' in self.Command and
|
|
|
|
not options.get('raw', False)):
|
|
|
|
sids = entry_attrs['ipaexternalmember']
|
|
|
|
result = self.Command.trust_resolve(sids=sids)
|
|
|
|
for entry in result['result']:
|
|
|
|
try:
|
|
|
|
idx = sids.index(entry['sid'][0])
|
|
|
|
sids[idx] = entry['name'][0]
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return dn
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group_show)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_add_member(LDAPAddMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add members to a group.')
|
2009-05-12 11:40:14 -05:00
|
|
|
|
2012-09-24 08:57:13 -05:00
|
|
|
takes_options = (ipaexternalmember_param,)
|
2012-06-20 08:08:33 -05:00
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, 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)
|
2012-06-20 08:08:33 -05:00
|
|
|
result = (completed, dn)
|
|
|
|
if 'ipaexternalmember' in options:
|
|
|
|
if not _dcerpc_bindings_installed:
|
2012-09-20 06:02:15 -05:00
|
|
|
raise errors.NotFound(reason=_('Cannot perform external member validation without '
|
|
|
|
'Samba 4 support installed. Make sure you have installed '
|
|
|
|
'server-trust-ad sub-package of IPA on the server'))
|
2012-06-20 08:08:33 -05:00
|
|
|
domain_validator = ipaserver.dcerpc.DomainValidator(self.api)
|
|
|
|
if not domain_validator.is_configured():
|
2012-09-20 06:02:15 -05:00
|
|
|
raise errors.NotFound(reason=_('Cannot perform join operation without own domain configured. '
|
|
|
|
'Make sure you have run ipa-adtrust-install on the IPA server first'))
|
2012-06-20 08:08:33 -05:00
|
|
|
sids = []
|
|
|
|
failed_sids = []
|
|
|
|
for sid in options['ipaexternalmember']:
|
|
|
|
if domain_validator.is_trusted_sid_valid(sid):
|
|
|
|
sids.append(sid)
|
|
|
|
else:
|
2013-01-18 10:28:39 -06:00
|
|
|
try:
|
|
|
|
actual_sid = domain_validator.get_trusted_domain_object_sid(sid)
|
|
|
|
except errors.PublicError, e:
|
2013-01-24 04:51:58 -06:00
|
|
|
failed_sids.append((sid, e.strerror))
|
2012-10-31 14:52:12 -05:00
|
|
|
else:
|
2013-01-18 10:28:39 -06:00
|
|
|
sids.append(actual_sid)
|
2012-06-20 08:08:33 -05:00
|
|
|
restore = []
|
|
|
|
if 'member' in failed and 'group' in failed['member']:
|
|
|
|
restore = failed['member']['group']
|
|
|
|
failed['member']['group'] = list((id,id) for id in sids)
|
|
|
|
result = add_external_post_callback('member', 'group', 'ipaexternalmember',
|
|
|
|
ldap, completed, failed, dn, entry_attrs,
|
|
|
|
keys, options, external_callback_normalize=False)
|
2013-02-21 09:56:03 -06:00
|
|
|
failed['member']['group'] += restore + failed_sids
|
2012-06-20 08:08:33 -05:00
|
|
|
return result
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group_add_member)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_remove_member(LDAPRemoveMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Remove members from a group.')
|
2009-05-12 11:40:14 -05:00
|
|
|
|
2012-09-24 08:57:13 -05:00
|
|
|
takes_options = (ipaexternalmember_param,)
|
2012-06-20 08:08:33 -05:00
|
|
|
|
2012-05-23 04:44:53 -05:00
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *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-09-25 07:14:57 -05:00
|
|
|
if keys[0] in PROTECTED_GROUPS:
|
|
|
|
protected_group_name = keys[0]
|
2012-05-23 04:44:53 -05:00
|
|
|
result = api.Command.group_show(protected_group_name)
|
|
|
|
users_left = set(result['result'].get('member_user', []))
|
|
|
|
users_deleted = set(options['user'])
|
|
|
|
if users_left.issubset(users_deleted):
|
|
|
|
raise errors.LastMemberError(key=sorted(users_deleted)[0],
|
|
|
|
label=_(u'group'), container=protected_group_name)
|
|
|
|
return dn
|
|
|
|
|
2012-06-20 08:08:33 -05:00
|
|
|
def post_callback(self, ldap, completed, failed, 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)
|
2012-06-20 08:08:33 -05:00
|
|
|
result = (completed, dn)
|
|
|
|
if 'ipaexternalmember' in options:
|
2013-02-21 09:56:03 -06:00
|
|
|
if not _dcerpc_bindings_installed:
|
|
|
|
raise errors.NotFound(reason=_('Cannot perform external member validation without '
|
|
|
|
'Samba 4 support installed. Make sure you have installed '
|
|
|
|
'server-trust-ad sub-package of IPA on the server'))
|
|
|
|
domain_validator = ipaserver.dcerpc.DomainValidator(self.api)
|
|
|
|
if not domain_validator.is_configured():
|
|
|
|
raise errors.NotFound(reason=_('Cannot perform join operation without own domain configured. '
|
|
|
|
'Make sure you have run ipa-adtrust-install on the IPA server first'))
|
|
|
|
sids = []
|
|
|
|
failed_sids = []
|
|
|
|
for sid in options['ipaexternalmember']:
|
|
|
|
if domain_validator.is_trusted_sid_valid(sid):
|
|
|
|
sids.append(sid)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
actual_sid = domain_validator.get_trusted_domain_object_sid(sid)
|
|
|
|
except errors.PublicError, e:
|
|
|
|
failed_sids.append((sid, unicode(e)))
|
|
|
|
else:
|
|
|
|
sids.append(actual_sid)
|
|
|
|
restore = []
|
2012-06-20 08:08:33 -05:00
|
|
|
if 'member' in failed and 'group' in failed['member']:
|
|
|
|
restore = failed['member']['group']
|
|
|
|
failed['member']['group'] = list((id,id) for id in sids)
|
|
|
|
result = remove_external_post_callback('member', 'group', 'ipaexternalmember',
|
|
|
|
ldap, completed, failed, dn, entry_attrs,
|
|
|
|
keys, options)
|
2013-02-21 09:56:03 -06:00
|
|
|
failed['member']['group'] += restore + failed_sids
|
2012-06-20 08:08:33 -05:00
|
|
|
return result
|
|
|
|
|
2009-07-09 12:02:44 -05:00
|
|
|
api.register(group_remove_member)
|
2010-08-09 15:40:51 -05:00
|
|
|
|
|
|
|
|
2010-11-29 16:09:35 -06:00
|
|
|
class group_detach(LDAPQuery):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Detach a managed group from a user.')
|
|
|
|
|
2010-08-09 15:40:51 -05:00
|
|
|
has_output = output.standard_value
|
|
|
|
msg_summary = _('Detached group "%(value)s" from user "%(value)s"')
|
|
|
|
|
|
|
|
def execute(self, *keys, **options):
|
|
|
|
"""
|
|
|
|
This requires updating both the user and the group. We first need to
|
|
|
|
verify that both the user and group can be updated, then we go
|
|
|
|
about our work. We don't want a situation where only the user or
|
|
|
|
group can be modified and we're left in a bad state.
|
|
|
|
"""
|
|
|
|
ldap = self.obj.backend
|
|
|
|
|
|
|
|
group_dn = self.obj.get_dn(*keys, **options)
|
|
|
|
user_dn = self.api.Object['user'].get_dn(*keys)
|
|
|
|
|
2011-02-02 08:29:38 -06:00
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
user_attrs = ldap.get_entry(user_dn)
|
2011-02-02 08:29:38 -06:00
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
2010-11-01 11:05:53 -05:00
|
|
|
is_managed = self.obj.has_objectclass(user_attrs['objectclass'], 'mepmanagedentry')
|
2010-08-09 15:40:51 -05:00
|
|
|
if (not ldap.can_write(user_dn, "objectclass") or
|
2010-11-01 11:05:53 -05:00
|
|
|
not (ldap.can_write(user_dn, "mepManagedEntry")) and is_managed):
|
2010-08-09 15:40:51 -05:00
|
|
|
raise errors.ACIError(info=_('not allowed to modify user entries'))
|
|
|
|
|
2013-10-31 11:54:21 -05:00
|
|
|
group_attrs = ldap.get_entry(group_dn)
|
2010-11-01 11:05:53 -05:00
|
|
|
is_managed = self.obj.has_objectclass(group_attrs['objectclass'], 'mepmanagedby')
|
2010-08-09 15:40:51 -05:00
|
|
|
if (not ldap.can_write(group_dn, "objectclass") or
|
2010-11-01 11:05:53 -05:00
|
|
|
not (ldap.can_write(group_dn, "mepManagedBy")) and is_managed):
|
2010-08-09 15:40:51 -05:00
|
|
|
raise errors.ACIError(info=_('not allowed to modify group entries'))
|
|
|
|
|
|
|
|
objectclasses = user_attrs['objectclass']
|
|
|
|
try:
|
|
|
|
i = objectclasses.index('mepOriginEntry')
|
2010-11-01 11:05:53 -05:00
|
|
|
del objectclasses[i]
|
2013-10-31 11:54:21 -05:00
|
|
|
user_attrs['mepManagedEntry'] = None
|
|
|
|
ldap.update_entry(user_attrs)
|
2010-08-09 15:40:51 -05:00
|
|
|
except ValueError:
|
2010-11-01 11:05:53 -05:00
|
|
|
# Somehow the user isn't managed, let it pass for now. We'll
|
|
|
|
# let the group throw "Not managed".
|
|
|
|
pass
|
2010-08-09 15:40:51 -05:00
|
|
|
|
2013-10-31 11:54:21 -05:00
|
|
|
group_attrs = ldap.get_entry(group_dn)
|
2010-08-09 15:40:51 -05:00
|
|
|
objectclasses = group_attrs['objectclass']
|
|
|
|
try:
|
|
|
|
i = objectclasses.index('mepManagedEntry')
|
|
|
|
except ValueError:
|
|
|
|
# this should never happen
|
2010-11-01 11:05:53 -05:00
|
|
|
raise errors.NotFound(reason=_('Not a managed group'))
|
2010-08-09 15:40:51 -05:00
|
|
|
del objectclasses[i]
|
2010-11-01 11:05:53 -05:00
|
|
|
|
|
|
|
# Make sure the resulting group has the default group objectclasses
|
2013-10-31 11:54:21 -05:00
|
|
|
config = ldap.get_ipa_config()
|
2010-11-01 11:05:53 -05:00
|
|
|
def_objectclass = config.get(
|
|
|
|
self.obj.object_class_config, objectclasses
|
|
|
|
)
|
|
|
|
objectclasses = list(set(def_objectclass + objectclasses))
|
|
|
|
|
2013-10-31 11:54:21 -05:00
|
|
|
group_attrs['mepManagedBy'] = None
|
|
|
|
ldap.update_entry(group_attrs)
|
2010-08-09 15:40:51 -05:00
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=True,
|
2014-03-27 08:04:00 -05:00
|
|
|
value=pkey_to_value(keys[0], options),
|
2010-08-09 15:40:51 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
api.register(group_detach)
|