Update objectclasses for groups, by default not posix groups.

This change depends on DS bugs 487574 and 487725. Groups cannot be
promoted properly without these fixed. It will fail with an
Object Class violation because gidNumber isn't set.
This commit is contained in:
Rob Crittenden
2009-02-27 15:04:46 -05:00
parent 1359618e7e
commit be0cac932a
4 changed files with 70 additions and 14 deletions

View File

@@ -145,8 +145,8 @@ ipaMaxUsernameLength: 8
ipaPwdExpAdvNotify: 4 ipaPwdExpAdvNotify: 4
ipaGroupObjectClasses: top ipaGroupObjectClasses: top
ipaGroupObjectClasses: groupofnames ipaGroupObjectClasses: groupofnames
ipaGroupObjectClasses: posixGroup ipaGroupObjectClasses: nestedGroup
ipaGroupObjectClasses: inetUser ipaGroupObjectClasses: ipaUserGroup
ipaUserObjectClasses: top ipaUserObjectClasses: top
ipaUserObjectClasses: person ipaUserObjectClasses: person
ipaUserObjectClasses: organizationalPerson ipaUserObjectClasses: organizationalPerson

View File

@@ -726,6 +726,22 @@ class RequiresRoot(ExecutionError):
errno = 4006 errno = 4006
format = _('This command requires root access') format = _('This command requires root access')
class AlreadyPosixGroup(ExecutionError):
"""
**4007** Raised when a group is already a posix group
For example:
>>> raise AlreadyPosixGroup
Traceback (most recent call last):
...
AlreadyPosixGroup: This is already a posix group
"""
errno = 4007
format = _('This is already a posix group')
class BuiltinError(ExecutionError): class BuiltinError(ExecutionError):
""" """
**4100** Base class for builtin execution errors (*4100 - 4199*). **4100** Base class for builtin execution errors (*4100 - 4199*).

View File

@@ -48,15 +48,18 @@ class group(Object):
takes_params = ( takes_params = (
Str('description', Str('description',
doc='A description of this group', doc='A description of this group',
attribute=True,
), ),
Int('gidnumber?', Int('gidnumber?',
cli_name='gid', cli_name='gid',
doc='The gid to use for this group. If not included one is automatically set.', doc='The gid to use for this group. If not included one is automatically set.',
attribute=True,
), ),
Str('cn', Str('cn',
cli_name='name', cli_name='name',
primary_key=True, primary_key=True,
normalizer=lambda value: value.lower(), normalizer=lambda value: value.lower(),
attribute=True,
), ),
) )
api.register(group) api.register(group)
@@ -64,6 +67,12 @@ api.register(group)
class group_add(crud.Add): class group_add(crud.Add):
'Add a new group.' 'Add a new group.'
takes_options = (
Flag('posix',
doc='Create as a posix group',
attribute=False,
),
)
def execute(self, cn, **kw): def execute(self, cn, **kw):
""" """
@@ -83,16 +92,18 @@ class group_add(crud.Add):
assert 'cn' not in kw assert 'cn' not in kw
assert 'dn' not in kw assert 'dn' not in kw
ldap = self.api.Backend.ldap ldap = self.api.Backend.ldap
kw['cn'] = cn entry = self.args_options_2_entry(cn, **kw)
kw['dn'] = ldap.make_group_dn(cn) entry['dn'] = ldap.make_group_dn(cn)
# Get our configuration # Get our configuration
config = ldap.get_ipa_config() config = ldap.get_ipa_config()
# some required objectclasses # some required objectclasses
kw['objectClass'] = config.get('ipagroupobjectclasses') entry['objectClass'] = config.get('ipagroupobjectclasses')
if kw.get('posix'):
entry['objectClass'].append('posixGroup')
return ldap.create(**kw) return ldap.create(**entry)
def output_for_cli(self, textui, result, *args, **options): def output_for_cli(self, textui, result, *args, **options):
""" """
@@ -122,14 +133,17 @@ class group_del(crud.Del):
# raise ipaerror.gen_exception(ipaerror.CONFIG_REQUIRED_GROUPS) # raise ipaerror.gen_exception(ipaerror.CONFIG_REQUIRED_GROUPS)
ldap = self.api.Backend.ldap ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("cn", cn, "posixGroup") dn = ldap.find_entry_dn("cn", cn, "ipaUserGroup")
self.log.info("IPA: group-del '%s'" % dn) self.log.info("IPA: group-del '%s'" % dn)
# Don't allow the default user group to be removed # Don't allow the default user group to be removed
try:
config=ldap.get_ipa_config() config=ldap.get_ipa_config()
default_group = ldap.find_entry_dn("cn", config.get('ipadefaultprimarygroup'), "posixGroup") default_group = ldap.find_entry_dn("cn", config.get('ipadefaultprimarygroup'), "ipaUserGroup")
if dn == default_group: if dn == default_group:
raise errors.DefaultGroup raise errors.DefaultGroup
except errors2.NotFound:
pass
return ldap.delete(dn) return ldap.delete(dn)
@@ -144,6 +158,12 @@ api.register(group_del)
class group_mod(crud.Mod): class group_mod(crud.Mod):
'Edit an existing group.' 'Edit an existing group.'
takes_options = (
Flag('posix',
doc='Make this group a posix group',
attribute=False,
),
)
def execute(self, cn, **kw): def execute(self, cn, **kw):
""" """
Execute the group-mod operation. Execute the group-mod operation.
@@ -159,7 +179,27 @@ class group_mod(crud.Mod):
assert 'cn' not in kw assert 'cn' not in kw
assert 'dn' not in kw assert 'dn' not in kw
ldap = self.api.Backend.ldap ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("cn", cn, "posixGroup") dn = ldap.find_entry_dn("cn", cn, "ipaUserGroup")
# Are we promoting a non-posix group into a posix one? We just
# need to add the posixGroup objectclass to the list and the
# DNA plugin will handle assigning a new gidNumber for us.
if kw.get('posix'):
groupkw = {'all': True}
oldgroup = api.Command['group_show'](cn, **groupkw)
if oldgroup.get('gidnumber'):
raise errors2.AlreadyPosixGroup
else:
oldgroup['objectclass'].append('posixgroup')
kw['objectclass'] = oldgroup['objectclass']
if kw.has_key('posix'):
del kw['posix']
if isinstance(kw.get('gidnumber',''), int):
# python-ldap wants this as a string
kw['gidnumber'] = str(kw['gidnumber'])
return ldap.update(dn, **kw) return ldap.update(dn, **kw)
def output_for_cli(self, textui, result, cn, **options): def output_for_cli(self, textui, result, cn, **options):
@@ -231,7 +271,7 @@ class group_show(crud.Get):
:param kw: Not used. :param kw: Not used.
""" """
ldap = self.api.Backend.ldap ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("cn", cn, "posixGroup") dn = ldap.find_entry_dn("cn", cn, "ipaUserGroup")
# FIXME: should kw contain the list of attributes to display? # FIXME: should kw contain the list of attributes to display?
if kw.get('all', False): if kw.get('all', False):

View File

@@ -202,7 +202,7 @@ class ldap(CrudBackend):
if attribute == "uid": # User if attribute == "uid": # User
object_type = "posixAccount" object_type = "posixAccount"
elif attribute == "cn": # Group elif attribute == "cn": # Group
object_type = "posixGroup" object_type = "ipaUserGroup"
elif attribute == "krbprincipalname": # Service elif attribute == "krbprincipalname": # Service
object_type = "krbPrincipal" object_type = "krbPrincipal"