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
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
Manage groups of users. By default new groups are not Posix groups.
|
|
|
|
You can mark it as Posix at creation time with the --posix flag and
|
|
|
|
can promose a non-Posix group using the --posix flag in group-mod.
|
|
|
|
Once a group is a Posix group there is no way to undo this.
|
|
|
|
|
|
|
|
Every group must have a description.
|
|
|
|
|
|
|
|
Posix groups must have a group id number (gid). Changing a gid is
|
|
|
|
supported but can have impact on your file permissions.
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
|
|
|
Add a new group:
|
|
|
|
ipa group-add --desc='local administrators' localadmins
|
|
|
|
|
|
|
|
Add a new posix group:
|
|
|
|
ipa group-add --posix --desc='remote administrators' remoteadmins
|
|
|
|
|
|
|
|
Promote a non-posix group to posix:
|
|
|
|
ipa group-mod --posix localadmins
|
|
|
|
|
|
|
|
Create a group with a specific group ID number"
|
|
|
|
ipa group-add --posix --gid=500 --desc='unix admins' unixadmins
|
|
|
|
|
|
|
|
Remove a group:
|
|
|
|
ipa group-del unixadmins
|
|
|
|
|
|
|
|
Manage group membership, nested groups:
|
|
|
|
ipa group-add-member --groups=remoteadmins localadmins
|
|
|
|
|
|
|
|
Manage group membership, users:
|
|
|
|
ipa group-add-member --users=test1,test2 localadmins
|
|
|
|
|
|
|
|
Manage group membership, users:
|
|
|
|
ipa group-remove-member --users=test2 localadmins
|
|
|
|
|
|
|
|
Show a group:
|
|
|
|
ipa group-show localadmins
|
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'
|
2010-07-12 13:17:33 -05:00
|
|
|
search_attributes_config = 'ipagroupsearchfields'
|
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_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',
|
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)'),
|
2009-05-11 08:49:07 -05:00
|
|
|
),
|
2010-02-12 15:34:21 -06:00
|
|
|
Str('member_group?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Member groups'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('member_user?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Member users'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('member?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Failed members'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('user?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Users'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('group?',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Groups'),
|
2010-02-12 15:34:21 -06:00
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
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
|
|
|
|
|
|
|
|
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',
|
2010-02-19 10:08:16 -06:00
|
|
|
doc=_('Create as posix group?'),
|
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):
|
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')
|
2010-06-25 15:14:46 -05:00
|
|
|
if not 'gidnumber' in options:
|
|
|
|
entry_attrs['gidnumber'] = 999
|
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:
|
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):
|
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',
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('change to posix group'),
|
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):
|
|
|
|
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']
|
2010-06-25 15:14:46 -05:00
|
|
|
if not 'gidnumber' in options:
|
|
|
|
entry_attrs['gidnumber'] = 999
|
2009-08-27 08:51:48 -05:00
|
|
|
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)
|