Skip to content
Commits on Source (4)
...@@ -86,9 +86,13 @@ try: ...@@ -86,9 +86,13 @@ try:
from ipalib.config import Env from ipalib.config import Env
from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT
try:
from ipalib.kinit import kinit_password, kinit_keytab
except ImportError:
try: try:
from ipalib.install.kinit import kinit_password, kinit_keytab from ipalib.install.kinit import kinit_password, kinit_keytab
except ImportError: except ImportError:
# pre 4.5.0
from ipapython.ipautil import kinit_password, kinit_keytab from ipapython.ipautil import kinit_password, kinit_keytab
from ipapython.ipautil import run from ipapython.ipautil import run
from ipapython.ipautil import template_str from ipapython.ipautil import template_str
......
...@@ -152,8 +152,10 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None): ...@@ -152,8 +152,10 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None):
if not searchdomains or not isinstance(searchdomains, list): if not searchdomains or not isinstance(searchdomains, list):
raise AssertionError("searchdomains must be of type list") raise AssertionError("searchdomains must be of type list")
changed = False
if fstore is not None and not fstore.has_file(paths.RESOLV_CONF): if fstore is not None and not fstore.has_file(paths.RESOLV_CONF):
fstore.backup_file(paths.RESOLV_CONF) fstore.backup_file(paths.RESOLV_CONF)
changed = True
resolve1_enabled = detect_resolve1_resolv_conf() resolve1_enabled = detect_resolve1_resolv_conf()
if "NetworkManager" not in services.knownservices: if "NetworkManager" not in services.knownservices:
...@@ -192,6 +194,7 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None): ...@@ -192,6 +194,7 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None):
sdrd_service = services.service("systemd-resolved.service") sdrd_service = services.service("systemd-resolved.service")
if sdrd_service.is_enabled(): if sdrd_service.is_enabled():
sdrd_service.reload_or_restart() sdrd_service.reload_or_restart()
changed = True
# Then configure NetworkManager or resolve.conf # Then configure NetworkManager or resolve.conf
if nm_service.is_enabled(): if nm_service.is_enabled():
...@@ -217,6 +220,7 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None): ...@@ -217,6 +220,7 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None):
outf.write(cfg) outf.write(cfg)
# reload NetworkManager # reload NetworkManager
nm_service.reload_or_restart() nm_service.reload_or_restart()
changed = True
# Configure resolv.conf if NetworkManager and systemd-resoled are not # Configure resolv.conf if NetworkManager and systemd-resoled are not
# enabled # enabled
...@@ -231,6 +235,9 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None): ...@@ -231,6 +235,9 @@ def configure_dns_resolver(nameservers, searchdomains, fstore=None):
cfg.append("nameserver %s" % nameserver) cfg.append("nameserver %s" % nameserver)
with open(paths.RESOLV_CONF, 'w') as outf: with open(paths.RESOLV_CONF, 'w') as outf:
outf.write('\n'.join(cfg)) outf.write('\n'.join(cfg))
changed = True
return changed
def unconfigure_dns_resolver(fstore=None): def unconfigure_dns_resolver(fstore=None):
...@@ -239,8 +246,11 @@ def unconfigure_dns_resolver(fstore=None): ...@@ -239,8 +246,11 @@ def unconfigure_dns_resolver(fstore=None):
:param fstore: optional file store for resolv.conf restore :param fstore: optional file store for resolv.conf restore
""" """
changed = False
if fstore is not None and fstore.has_file(paths.RESOLV_CONF): if fstore is not None and fstore.has_file(paths.RESOLV_CONF):
fstore.restore_file(paths.RESOLV_CONF) fstore.restore_file(paths.RESOLV_CONF)
changed = True
if os.path.isfile(NETWORK_MANAGER_IPA_CONF): if os.path.isfile(NETWORK_MANAGER_IPA_CONF):
os.unlink(NETWORK_MANAGER_IPA_CONF) os.unlink(NETWORK_MANAGER_IPA_CONF)
...@@ -252,6 +262,7 @@ def unconfigure_dns_resolver(fstore=None): ...@@ -252,6 +262,7 @@ def unconfigure_dns_resolver(fstore=None):
nm_service = services.knownservices['NetworkManager'] nm_service = services.knownservices['NetworkManager']
if nm_service.is_enabled(): if nm_service.is_enabled():
nm_service.reload_or_restart() nm_service.reload_or_restart()
changed = True
if os.path.isfile(SYSTEMD_RESOLVED_IPA_CONF): if os.path.isfile(SYSTEMD_RESOLVED_IPA_CONF):
os.unlink(SYSTEMD_RESOLVED_IPA_CONF) os.unlink(SYSTEMD_RESOLVED_IPA_CONF)
...@@ -261,6 +272,9 @@ def unconfigure_dns_resolver(fstore=None): ...@@ -261,6 +272,9 @@ def unconfigure_dns_resolver(fstore=None):
sdrd_service = services.service("systemd-resolved.service") sdrd_service = services.service("systemd-resolved.service")
if sdrd_service.is_enabled(): if sdrd_service.is_enabled():
sdrd_service.reload_or_restart() sdrd_service.reload_or_restart()
changed = True
return changed
def main(): def main():
...@@ -308,11 +322,12 @@ def main(): ...@@ -308,11 +322,12 @@ def main():
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE) fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
if state == "present": if state == "present":
configure_dns_resolver(nameservers, searchdomains, fstore) changed = configure_dns_resolver(nameservers,
searchdomains, fstore)
else: else:
unconfigure_dns_resolver(fstore) changed = unconfigure_dns_resolver(fstore)
module.exit_json(changed=True) module.exit_json(changed=changed)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -88,9 +88,13 @@ try: ...@@ -88,9 +88,13 @@ try:
from ipaplatform.paths import paths from ipaplatform.paths import paths
from ipapython.ipautil import run from ipapython.ipautil import run
from ipalib.constants import DEFAULT_CONFIG from ipalib.constants import DEFAULT_CONFIG
try:
from ipalib.kinit import kinit_password, kinit_keytab
except ImportError:
try: try:
from ipalib.install.kinit import kinit_password, kinit_keytab from ipalib.install.kinit import kinit_password, kinit_keytab
except ImportError: except ImportError:
# pre 4.5.0
from ipapython.ipautil import kinit_password, kinit_keytab from ipapython.ipautil import kinit_password, kinit_keytab
except ImportError as _err: except ImportError as _err:
MODULE_IMPORT_ERROR = str(_err) MODULE_IMPORT_ERROR = str(_err)
......
...@@ -172,9 +172,13 @@ try: ...@@ -172,9 +172,13 @@ try:
from ipapython.ipautil import CalledProcessError, write_tmp_file, \ from ipapython.ipautil import CalledProcessError, write_tmp_file, \
ipa_generate_password ipa_generate_password
from ipapython.dn import DN from ipapython.dn import DN
try:
from ipalib.kinit import kinit_password, kinit_keytab
except ImportError:
try: try:
from ipalib.install.kinit import kinit_keytab, kinit_password from ipalib.install.kinit import kinit_keytab, kinit_password
except ImportError: except ImportError:
# pre 4.5.0
from ipapython.ipautil import kinit_keytab, kinit_password from ipapython.ipautil import kinit_keytab, kinit_password
from ipapython.ipa_log_manager import standard_logging_setup from ipapython.ipa_log_manager import standard_logging_setup
from gssapi.exceptions import GSSError from gssapi.exceptions import GSSError
......
...@@ -104,6 +104,9 @@ try: ...@@ -104,6 +104,9 @@ try:
from ipaclient.install.ipachangeconf import IPAChangeConf from ipaclient.install.ipachangeconf import IPAChangeConf
from ipalib.install import certstore, sysrestore from ipalib.install import certstore, sysrestore
from ipapython.ipautil import ipa_generate_password from ipapython.ipautil import ipa_generate_password
try:
from ipalib.kinit import kinit_keytab
except ImportError:
from ipalib.install.kinit import kinit_keytab from ipalib.install.kinit import kinit_keytab
from ipapython import ipaldap, ipautil, kernel_keyring from ipapython import ipaldap, ipautil, kernel_keyring
from ipapython.certdb import IPA_CA_TRUST_FLAGS, \ from ipapython.certdb import IPA_CA_TRUST_FLAGS, \
......
...@@ -76,9 +76,13 @@ try: ...@@ -76,9 +76,13 @@ try:
from ipaplatform.paths import paths from ipaplatform.paths import paths
from ipapython.ipautil import run from ipapython.ipautil import run
from ipalib.constants import DEFAULT_CONFIG from ipalib.constants import DEFAULT_CONFIG
try:
from ipalib.kinit import kinit_password
except ImportError:
try: try:
from ipalib.install.kinit import kinit_password from ipalib.install.kinit import kinit_password
except ImportError: except ImportError:
# pre 4.5.0
from ipapython.ipautil import kinit_password from ipapython.ipautil import kinit_password
except ImportError as _err: except ImportError as _err:
MODULE_IMPORT_ERROR = str(_err) MODULE_IMPORT_ERROR = str(_err)
......