~ubuntu-branches/debian/sid/freeipa/sid

« back to all changes in this revision

Viewing changes to ipalib/plugins/sudocmdgroup.py

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-10-25 02:43:59 UTC
  • Revision ID: package-import@ubuntu.com-20141025024359-to6c607ln0lmzwik
Tags: upstream-4.0.4
ImportĀ upstreamĀ versionĀ 4.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Authors:
 
2
#   Jr Aquino <jr.aquino@citrixonline.com>
 
3
#
 
4
# Copyright (C) 2010  Red Hat
 
5
# see file 'COPYING' for use and warranty information
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
from ipalib import api
 
21
from ipalib import Str
 
22
from ipalib.plugable import Registry
 
23
from ipalib.plugins.baseldap import *
 
24
from ipalib import _, ngettext
 
25
 
 
26
__doc__ = _("""
 
27
Groups of Sudo Commands
 
28
 
 
29
Manage groups of Sudo Commands.
 
30
 
 
31
EXAMPLES:
 
32
 
 
33
 Add a new Sudo Command Group:
 
34
   ipa sudocmdgroup-add --desc='administrators commands' admincmds
 
35
 
 
36
 Remove a Sudo Command Group:
 
37
   ipa sudocmdgroup-del admincmds
 
38
 
 
39
 Manage Sudo Command Group membership, commands:
 
40
   ipa sudocmdgroup-add-member --sudocmds=/usr/bin/less --sudocmds=/usr/bin/vim admincmds
 
41
 
 
42
 Manage Sudo Command Group membership, commands:
 
43
   ipa group-remove-member --sudocmds=/usr/bin/less admincmds
 
44
 
 
45
 Show a Sudo Command Group:
 
46
   ipa group-show localadmins
 
47
""")
 
48
 
 
49
register = Registry()
 
50
 
 
51
topic = ('sudo', _('commands for controlling sudo configuration'))
 
52
 
 
53
@register()
 
54
class sudocmdgroup(LDAPObject):
 
55
    """
 
56
    Sudo Command Group object.
 
57
    """
 
58
    container_dn = api.env.container_sudocmdgroup
 
59
    object_name = _('sudo command group')
 
60
    object_name_plural = _('sudo command groups')
 
61
    object_class = ['ipaobject', 'ipasudocmdgrp']
 
62
    permission_filter_objectclasses = ['ipasudocmdgrp']
 
63
    default_attributes = [
 
64
        'cn', 'description', 'member',
 
65
    ]
 
66
    uuid_attribute = 'ipauniqueid'
 
67
    attribute_members = {
 
68
        'member': ['sudocmd'],
 
69
    }
 
70
    managed_permissions = {
 
71
        'System: Read Sudo Command Groups': {
 
72
            'replaces_global_anonymous_aci': True,
 
73
            'ipapermbindruletype': 'all',
 
74
            'ipapermright': {'read', 'search', 'compare'},
 
75
            'ipapermdefaultattr': {
 
76
                'businesscategory', 'cn', 'description', 'ipauniqueid',
 
77
                'member', 'o', 'objectclass', 'ou', 'owner', 'seealso',
 
78
                'memberuser', 'memberhost',
 
79
            },
 
80
        },
 
81
        'System: Add Sudo Command Group': {
 
82
            'ipapermright': {'add'},
 
83
            'replaces': [
 
84
                '(target = "ldap:///cn=*,cn=sudocmdgroups,cn=sudo,$SUFFIX")(version 3.0;acl "permission:Add Sudo command group";allow (add) groupdn = "ldap:///cn=Add Sudo command group,cn=permissions,cn=pbac,$SUFFIX";)',
 
85
            ],
 
86
            'default_privileges': {'Sudo Administrator'},
 
87
        },
 
88
        'System: Delete Sudo Command Group': {
 
89
            'ipapermright': {'delete'},
 
90
            'replaces': [
 
91
                '(target = "ldap:///cn=*,cn=sudocmdgroups,cn=sudo,$SUFFIX")(version 3.0;acl "permission:Delete Sudo command group";allow (delete) groupdn = "ldap:///cn=Delete Sudo command group,cn=permissions,cn=pbac,$SUFFIX";)',
 
92
            ],
 
93
            'default_privileges': {'Sudo Administrator'},
 
94
        },
 
95
        'System: Modify Sudo Command Group': {
 
96
            'ipapermright': {'write'},
 
97
            'ipapermdefaultattr': {'description'},
 
98
            'default_privileges': {'Sudo Administrator'},
 
99
        },
 
100
        'System: Manage Sudo Command Group Membership': {
 
101
            'ipapermright': {'write'},
 
102
            'ipapermdefaultattr': {'member'},
 
103
            'replaces': [
 
104
                '(targetattr = "member")(target = "ldap:///cn=*,cn=sudocmdgroups,cn=sudo,$SUFFIX")(version 3.0;acl "permission:Manage Sudo command group membership";allow (write) groupdn = "ldap:///cn=Manage Sudo command group membership,cn=permissions,cn=pbac,$SUFFIX";)',
 
105
            ],
 
106
            'default_privileges': {'Sudo Administrator'},
 
107
        },
 
108
    }
 
109
 
 
110
    label = _('Sudo Command Groups')
 
111
    label_singular = _('Sudo Command Group')
 
112
 
 
113
    takes_params = (
 
114
        Str('cn',
 
115
            cli_name='sudocmdgroup_name',
 
116
            label=_('Sudo Command Group'),
 
117
            primary_key=True,
 
118
            normalizer=lambda value: value.lower(),
 
119
        ),
 
120
        Str('description',
 
121
            cli_name='desc',
 
122
            label=_('Description'),
 
123
            doc=_('Group description'),
 
124
        ),
 
125
        Str('membercmd_sudocmd?',
 
126
            label=_('Commands'),
 
127
            flags=['no_create', 'no_update', 'no_search'],
 
128
        ),
 
129
        Str('membercmd_sudocmdgroup?',
 
130
            label=_('Sudo Command Groups'),
 
131
            flags=['no_create', 'no_update', 'no_search'],
 
132
        ),
 
133
    )
 
134
 
 
135
 
 
136
 
 
137
@register()
 
138
class sudocmdgroup_add(LDAPCreate):
 
139
    __doc__ = _('Create new Sudo Command Group.')
 
140
 
 
141
    msg_summary = _('Added Sudo Command Group "%(value)s"')
 
142
 
 
143
 
 
144
 
 
145
@register()
 
146
class sudocmdgroup_del(LDAPDelete):
 
147
    __doc__ = _('Delete Sudo Command Group.')
 
148
 
 
149
    msg_summary = _('Deleted Sudo Command Group "%(value)s"')
 
150
 
 
151
 
 
152
 
 
153
@register()
 
154
class sudocmdgroup_mod(LDAPUpdate):
 
155
    __doc__ = _('Modify Sudo Command Group.')
 
156
 
 
157
    msg_summary = _('Modified Sudo Command Group "%(value)s"')
 
158
 
 
159
 
 
160
 
 
161
@register()
 
162
class sudocmdgroup_find(LDAPSearch):
 
163
    __doc__ = _('Search for Sudo Command Groups.')
 
164
 
 
165
    msg_summary = ngettext(
 
166
        '%(count)d Sudo Command Group matched',
 
167
        '%(count)d Sudo Command Groups matched', 0
 
168
    )
 
169
 
 
170
 
 
171
 
 
172
@register()
 
173
class sudocmdgroup_show(LDAPRetrieve):
 
174
    __doc__ = _('Display Sudo Command Group.')
 
175
 
 
176
 
 
177
 
 
178
@register()
 
179
class sudocmdgroup_add_member(LDAPAddMember):
 
180
    __doc__ = _('Add members to Sudo Command Group.')
 
181
 
 
182
 
 
183
 
 
184
@register()
 
185
class sudocmdgroup_remove_member(LDAPRemoveMember):
 
186
    __doc__ = _('Remove members from Sudo Command Group.')
 
187