From 9a53e71de8182b1b7c97962f5d43f47b466328c3 Mon Sep 17 00:00:00 2001 From: Thomas Woerner <twoerner@redhat.com> Date: Fri, 7 Jun 2019 17:25:12 +0200 Subject: [PATCH] ipaclient_test: Use validate_hostname with constants.MAXHOSTNAMELEN Run validate_hostname to check for valid host name if constants.MAXHOSTNAMELEN is defined. The call has not been used in older FreeIPA versions. --- roles/ipaclient/library/ipaclient_test.py | 8 ++++++++ roles/ipaclient/module_utils/ansible_ipa_client.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/roles/ipaclient/library/ipaclient_test.py b/roles/ipaclient/library/ipaclient_test.py index c75f5f5c..bc4d4efc 100644 --- a/roles/ipaclient/library/ipaclient_test.py +++ b/roles/ipaclient/library/ipaclient_test.py @@ -529,6 +529,14 @@ def main(): "Invalid hostname, '{}' must not be used.".format(hostname), rval=CLIENT_INSTALL_ERROR) + if hasattr(constants, "MAXHOSTNAMELEN"): + try: + validate_hostname(hostname, maxlen=constants.MAXHOSTNAMELEN) + except ValueError as e: + raise ScriptError( + 'invalid hostname: {}'.format(e), + rval=CLIENT_INSTALL_ERROR) + if hasattr(tasks, "is_nosssd_supported"): # --no-sssd is not supported any more for rhel-based distros if not tasks.is_nosssd_supported() and not options.sssd: diff --git a/roles/ipaclient/module_utils/ansible_ipa_client.py b/roles/ipaclient/module_utils/ansible_ipa_client.py index 0008fc31..9a956f6a 100644 --- a/roles/ipaclient/module_utils/ansible_ipa_client.py +++ b/roles/ipaclient/module_utils/ansible_ipa_client.py @@ -81,6 +81,7 @@ if NUM_VERSION >= 40400: except ImportError: from ipaclient import ipadiscovery from ipalib import api, errors, x509 + from ipalib import constants try: from ipalib.install import sysrestore except ImportError: @@ -97,7 +98,8 @@ if NUM_VERSION >= 40400: from ipapython import certdb, ipautil from ipapython.admintool import ScriptError from ipapython.ipautil import CheckedIPAddress - from ipalib.util import validate_domain_name, normalize_hostname + from ipalib.util import validate_domain_name, normalize_hostname, \ + validate_hostname from ipaplatform import services from ipaplatform.paths import paths from ipaplatform.tasks import tasks -- GitLab