Use absolute domain in detection of A/AAAA records

Python dns resolver append configured domain to queries which may lead
to false positive answer.

Exmaple: resolving "ipa.example.com" may return records for
"ipa.example.com.example.com" if domain is configured as "example.com"

https://fedorahosted.org/freeipa/ticket/5421

Reviewed-By: Petr Spacek <pspacek@redhat.com>
This commit is contained in:
Martin Basti 2015-11-04 16:09:21 +01:00
parent 0f52eddd1d
commit 800c702324
2 changed files with 5 additions and 6 deletions

View File

@ -4189,16 +4189,12 @@ class dns_resolve(Command):
takes_args = ( takes_args = (
Str('hostname', Str('hostname',
label=_('Hostname'), label=_('Hostname (FQDN)'),
), ),
) )
def execute(self, *args, **options): def execute(self, *args, **options):
query=args[0] query=args[0]
if query.find(api.env.domain) == -1 and query.find('.') == -1:
query = '%s.%s.' % (query, api.env.domain)
if query[-1] != '.':
query = query + '.'
if not is_host_resolvable(query): if not is_host_resolvable(query):
raise errors.NotFound( raise errors.NotFound(

View File

@ -49,6 +49,7 @@ from ipapython import ipavalidate
from ipapython import config from ipapython import config
from ipaplatform.paths import paths from ipaplatform.paths import paths
from ipapython.dn import DN from ipapython.dn import DN
from ipapython.dnsutil import DNSName
SHARE_DIR = paths.USR_SHARE_IPA_DIR SHARE_DIR = paths.USR_SHARE_IPA_DIR
PLUGINS_SHARE_DIR = paths.IPA_PLUGINS PLUGINS_SHARE_DIR = paths.IPA_PLUGINS
@ -911,9 +912,11 @@ def bind_port_responder(port, socket_type=socket.SOCK_STREAM, socket_timeout=Non
raise last_socket_error # pylint: disable=E0702 raise last_socket_error # pylint: disable=E0702
def is_host_resolvable(fqdn): def is_host_resolvable(fqdn):
if not isinstance(fqdn, DNSName):
fqdn = DNSName(fqdn)
for rdtype in (rdatatype.A, rdatatype.AAAA): for rdtype in (rdatatype.A, rdatatype.AAAA):
try: try:
resolver.query(fqdn, rdtype) resolver.query(fqdn.make_absolute(), rdtype)
except DNSException: except DNSException:
continue continue
else: else: