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
|
|
|
|
#
|
|
|
|
# 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; version 2 only
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
"""
|
2009-06-16 09:51:44 -05:00
|
|
|
Groups of users
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
from ipalib import api
|
2009-08-27 08:51:48 -05:00
|
|
|
from ipalib import Int, Str
|
|
|
|
from ipalib.plugins.baseldap import *
|
2009-12-09 10:09:53 -06:00
|
|
|
from ipalib import _, ngettext
|
2009-05-11 08:49:07 -05:00
|
|
|
|
2009-05-12 11:40:14 -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
|
|
|
|
object_name = 'group'
|
|
|
|
object_name_plural = 'groups'
|
|
|
|
object_class = ['ipausergroup']
|
|
|
|
object_class_config = 'ipagroupobjectclasses'
|
2009-10-21 09:12:11 -05:00
|
|
|
default_attributes = [
|
|
|
|
'cn', 'description', 'gidnumber', 'member', 'memberof'
|
|
|
|
]
|
2009-08-27 08:51:48 -05:00
|
|
|
uuid_attribute = 'ipauniqueid'
|
|
|
|
attribute_names = {
|
|
|
|
'cn': 'name',
|
|
|
|
'gidnumber': 'group id',
|
|
|
|
'member user': 'member users',
|
|
|
|
'member group': 'member groups',
|
|
|
|
'memberof group': 'member of groups',
|
|
|
|
'memberof netgroup': 'member of netgroups',
|
|
|
|
'memberof rolegroup': 'member of rolegroup',
|
|
|
|
'memberof taskgroup': 'member of taskgroup',
|
|
|
|
}
|
|
|
|
attribute_members = {
|
|
|
|
'member': ['user', 'group'],
|
|
|
|
'memberof': ['group', 'netgroup', 'rolegroup', 'taskgroup'],
|
|
|
|
}
|
|
|
|
|
2010-02-08 06:03:28 -06:00
|
|
|
label = _('User Groups')
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
takes_params = (
|
|
|
|
Str('cn',
|
|
|
|
cli_name='name',
|
2009-12-09 10:09:53 -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',
|
2009-12-09 10:09:53 -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',
|
2009-12-09 10:09:53 -06:00
|
|
|
label='GID',
|
2009-05-11 08:49:07 -05:00
|
|
|
doc='GID (use this option to set it manually)',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(group)
|
2009-05-11 08:49:07 -05:00
|
|
|
|
|
|
|
|
2009-08-27 08:51:48 -05:00
|
|
|
class group_add(LDAPCreate):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
Create 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 + (
|
2009-05-11 08:49:07 -05:00
|
|
|
Flag('posix',
|
|
|
|
cli_name='posix',
|
|
|
|
doc='create as posix group?',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2009-12-10 09:39:24 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
2009-08-27 08:51:48 -05:00
|
|
|
if options['posix'] or 'gidnumber' in options:
|
2009-10-08 05:55:14 -05:00
|
|
|
entry_attrs['objectclass'].append('posixgroup')
|
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):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
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):
|
|
|
|
config = ldap.get_ipa_config()[1]
|
|
|
|
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:
|
|
|
|
raise errors.DefaultGroup()
|
|
|
|
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):
|
|
|
|
try:
|
|
|
|
api.Command['pwpolicy_del'](group=keys[-1])
|
|
|
|
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):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
Modify 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',
|
|
|
|
doc='change to posix group',
|
|
|
|
),
|
|
|
|
)
|
2009-08-27 08:51:48 -05:00
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
if options['posix'] or 'gidnumber' in options:
|
|
|
|
(dn, old_entry_attrs) = ldap.get_entry(dn, ['objectclass'])
|
|
|
|
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']
|
|
|
|
return dn
|
2009-05-11 08:49:07 -05:00
|
|
|
|
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):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
Search for groups.
|
|
|
|
"""
|
2009-05-12 11:40:14 -05:00
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = ngettext(
|
|
|
|
'%(count)d group matched', '%(count)d groups matched', 0
|
|
|
|
)
|
|
|
|
|
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):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
|
|
|
Display group.
|
|
|
|
"""
|
2009-05-12 11:40:14 -05:00
|
|
|
|
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):
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
2009-05-12 11:40:14 -05:00
|
|
|
Add members to group.
|
2009-05-11 08:49:07 -05:00
|
|
|
"""
|
2009-05-12 11:40:14 -05:00
|
|
|
|
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):
|
2009-05-12 11:40:14 -05:00
|
|
|
"""
|
|
|
|
Remove members from group.
|
|
|
|
"""
|
|
|
|
|
2009-07-09 12:02:44 -05:00
|
|
|
api.register(group_remove_member)
|