2009-02-18 15:45:49 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@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
|
|
|
Joining an IPA domain
|
2009-02-18 15:45:49 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
from ipalib import api, util
|
2009-10-23 08:35:32 -05:00
|
|
|
from ipalib import Command, Str
|
2009-04-23 07:51:59 -05:00
|
|
|
from ipalib import errors
|
2009-02-18 15:45:49 -06:00
|
|
|
import krbV
|
2010-03-05 15:11:21 -06:00
|
|
|
from ipalib import _
|
2009-02-18 15:45:49 -06:00
|
|
|
|
|
|
|
def get_realm():
|
2009-10-23 08:35:32 -05:00
|
|
|
"""
|
|
|
|
Returns the default kerberos realm configured for this server.
|
|
|
|
"""
|
2009-02-18 15:45:49 -06:00
|
|
|
krbctx = krbV.default_context()
|
|
|
|
|
2009-04-22 13:36:29 -05:00
|
|
|
return unicode(krbctx.default_realm)
|
2009-02-18 15:45:49 -06:00
|
|
|
|
|
|
|
def validate_host(ugettext, cn):
|
|
|
|
"""
|
|
|
|
Require at least one dot in the hostname (to support localhost.localdomain)
|
|
|
|
"""
|
|
|
|
dots = len(cn.split('.'))
|
|
|
|
if dots < 2:
|
|
|
|
return 'Fully-qualified hostname required'
|
|
|
|
return None
|
|
|
|
|
|
|
|
class join(Command):
|
|
|
|
"""Join an IPA domain"""
|
|
|
|
|
|
|
|
takes_args = (
|
|
|
|
Str('cn',
|
|
|
|
validate_host,
|
|
|
|
cli_name='hostname',
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_("The hostname to register as"),
|
2009-04-22 13:36:29 -05:00
|
|
|
create_default=lambda **kw: unicode(util.get_fqdn()),
|
|
|
|
autofill=True,
|
2009-02-18 15:45:49 -06:00
|
|
|
#normalizer=lamda value: value.lower(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
takes_options= (
|
|
|
|
Str('realm',
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_("The IPA realm"),
|
2009-04-22 13:36:29 -05:00
|
|
|
create_default=lambda **kw: get_realm(),
|
|
|
|
autofill=True,
|
2009-02-18 15:45:49 -06:00
|
|
|
),
|
2009-09-14 16:04:08 -05:00
|
|
|
Str('nshardwareplatform?',
|
|
|
|
cli_name='platform',
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Hardware platform of the host (e.g. Lenovo T61)'),
|
2009-09-14 16:04:08 -05:00
|
|
|
),
|
|
|
|
Str('nsosversion?',
|
|
|
|
cli_name='os',
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Operating System and version of the host (e.g. Fedora 9)'),
|
2009-09-14 16:04:08 -05:00
|
|
|
),
|
2009-02-18 15:45:49 -06:00
|
|
|
)
|
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
has_output = tuple()
|
|
|
|
use_output_validation = False
|
|
|
|
|
2009-02-18 15:45:49 -06:00
|
|
|
def execute(self, hostname, **kw):
|
|
|
|
"""
|
|
|
|
Execute the machine join operation.
|
|
|
|
|
|
|
|
Returns the entry as it will be created in LDAP.
|
|
|
|
|
|
|
|
:param hostname: The name of the host joined
|
|
|
|
:param kw: Keyword arguments for the other attributes.
|
|
|
|
"""
|
|
|
|
assert 'cn' not in kw
|
2009-09-14 16:04:08 -05:00
|
|
|
ldap = self.api.Backend.ldap2
|
2009-02-18 15:45:49 -06:00
|
|
|
|
2009-09-14 16:04:08 -05:00
|
|
|
host = None
|
2009-02-18 15:45:49 -06:00
|
|
|
try:
|
2009-09-14 16:04:08 -05:00
|
|
|
# First see if the host exists
|
|
|
|
kw = {'fqdn': hostname, 'all': True}
|
2009-12-16 15:04:53 -06:00
|
|
|
attrs_list = api.Command['host_show'](**kw)['result']
|
|
|
|
dn = attrs_list['dn']
|
2009-09-14 16:04:08 -05:00
|
|
|
|
|
|
|
# If no principal name is set yet we need to try to add
|
|
|
|
# one.
|
|
|
|
if 'krbprincipalname' not in attrs_list:
|
|
|
|
service = "host/%s@%s" % (hostname, api.env.realm)
|
2009-12-16 15:04:53 -06:00
|
|
|
api.Command['host_mod'](hostname, krbprincipalname=service)
|
2009-09-14 16:04:08 -05:00
|
|
|
|
|
|
|
# It exists, can we write the password attributes?
|
|
|
|
allowed = ldap.can_write(dn, 'krblastpwdchange')
|
|
|
|
if not allowed:
|
|
|
|
raise errors.ACIError(info="Insufficient 'write' privilege to the 'krbLastPwdChange' attribute of entry '%s'." % dn)
|
|
|
|
|
|
|
|
kw = {'fqdn': hostname, 'all': True}
|
2009-12-16 15:04:53 -06:00
|
|
|
attrs_list = api.Command['host_show'](**kw)['result']
|
|
|
|
dn = attrs_list['dn']
|
2009-04-23 07:51:59 -05:00
|
|
|
except errors.NotFound:
|
2009-12-16 15:04:53 -06:00
|
|
|
attrs_list = api.Command['host_add'](hostname)['result']
|
|
|
|
dn = attrs_list['dn']
|
2009-02-18 15:45:49 -06:00
|
|
|
|
2010-04-05 15:27:46 -05:00
|
|
|
config = api.Command['config_show']()['result']
|
|
|
|
attrs_list['ipacertificatesubjectbase'] = config['ipacertificatesubjectbase']
|
|
|
|
|
2009-09-14 16:04:08 -05:00
|
|
|
return (dn, attrs_list)
|
2009-02-18 15:45:49 -06:00
|
|
|
|
|
|
|
api.register(join)
|