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

« back to all changes in this revision

Viewing changes to ipalib/plugins/pkinit.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
#   Simo Sorce <ssorce@redhat.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, errors
 
21
from ipalib import Int, Str
 
22
from ipalib import Object, Command
 
23
from ipalib import _
 
24
from ipalib.plugable import Registry
 
25
from ipapython.dn import DN
 
26
 
 
27
__doc__ = _("""
 
28
Kerberos pkinit options
 
29
 
 
30
Enable or disable anonymous pkinit using the principal
 
31
WELLKNOWN/ANONYMOUS@REALM. The server must have been installed with
 
32
pkinit support.
 
33
 
 
34
EXAMPLES:
 
35
 
 
36
 Enable anonymous pkinit:
 
37
  ipa pkinit-anonymous enable
 
38
 
 
39
 Disable anonymous pkinit:
 
40
  ipa pkinit-anonymous disable
 
41
 
 
42
For more information on anonymous pkinit see:
 
43
 
 
44
http://k5wiki.kerberos.org/wiki/Projects/Anonymous_pkinit
 
45
""")
 
46
 
 
47
register = Registry()
 
48
 
 
49
@register()
 
50
class pkinit(Object):
 
51
    """
 
52
    PKINIT Options
 
53
    """
 
54
    object_name = _('pkinit')
 
55
 
 
56
    label=_('PKINIT')
 
57
 
 
58
 
 
59
def valid_arg(ugettext, action):
 
60
    """
 
61
    Accepts only Enable/Disable.
 
62
    """
 
63
    a = action.lower()
 
64
    if a != 'enable' and a != 'disable':
 
65
        raise errors.ValidationError(
 
66
            name='action',
 
67
            error=_('Unknown command %s') % action
 
68
        )
 
69
 
 
70
@register()
 
71
class pkinit_anonymous(Command):
 
72
    __doc__ = _('Enable or Disable Anonymous PKINIT.')
 
73
 
 
74
    princ_name = 'WELLKNOWN/ANONYMOUS@%s' % api.env.realm
 
75
    default_dn = DN(('krbprincipalname', princ_name), ('cn', api.env.realm), ('cn', 'kerberos'), api.env.basedn)
 
76
 
 
77
    takes_args = (
 
78
        Str('action', valid_arg),
 
79
    )
 
80
 
 
81
    def execute(self, action, **options):
 
82
        ldap = self.api.Backend.ldap2
 
83
        set_lock = False
 
84
        lock = None
 
85
 
 
86
        entry_attrs = ldap.get_entry(self.default_dn, ['nsaccountlock'])
 
87
 
 
88
        if 'nsaccountlock' in entry_attrs:
 
89
            lock = entry_attrs['nsaccountlock'][0].lower()
 
90
 
 
91
        if action.lower() == 'enable':
 
92
            if lock == 'true':
 
93
                set_lock = True
 
94
                lock = None
 
95
        elif action.lower() == 'disable':
 
96
            if lock != 'true':
 
97
                set_lock = True
 
98
                lock = 'TRUE'
 
99
 
 
100
        if set_lock:
 
101
            entry_attrs['nsaccountlock'] = lock
 
102
            ldap.update_entry(entry_attrs)
 
103
 
 
104
        return dict(result=True)
 
105