URL: https://github.com/freeipa/freeipa/pull/681 Author: alex-zel Title: #681: Fix ipadiscovery Action: opened
PR body: """ Sort SRV records for LDAP/KRB based on priority. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/681/head:pr681 git checkout pr681
From 3ac30ca118685134dd38b07e4b55ecbb4c880a3a Mon Sep 17 00:00:00 2001 From: Alex Zeleznikov <a...@iucc.ac.il> Date: Sun, 2 Apr 2017 11:53:11 +0300 Subject: [PATCH 1/2] ipadiscovery sort SRV record by priority Sort SRV records for LDAP/KRB based on priority. --- ipaclient/install/ipadiscovery.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ipaclient/install/ipadiscovery.py b/ipaclient/install/ipadiscovery.py index 46e05c9..c6fc240 100644 --- a/ipaclient/install/ipadiscovery.py +++ b/ipaclient/install/ipadiscovery.py @@ -492,7 +492,16 @@ def ipadns_search_srv(self, domain, srv_record_name, default_port, root_logger.debug("Search DNS for SRV record of %s", qname) try: - answers = resolver.query(qname, rdatatype.SRV) + answers = [] + dns_answers = resolver.query(qname, rdatatype.SRV) + for answer in dns_answers: + if not len(answers): + answers.append(answer) + else: + i = 0 + while i < len(answers) and answer.priority > answers[i].priority: + i += 1 + answers.insert(i, answer) except DNSException as e: root_logger.debug("DNS record not found: %s", e.__class__.__name__) answers = [] @@ -521,7 +530,16 @@ def ipadnssearchkrbrealm(self, domain=None): root_logger.debug("Search DNS for TXT record of %s", qname) try: - answers = resolver.query(qname, rdatatype.TXT) + answers = [] + dns_answers = resolver.query(qname, rdatatype.SRV) + for answer in dns_answers: + if not len(answers): + answers.append(answer) + else: + i = 0 + while i < len(answers) and answer.priority > answers[i].priority: + i += 1 + answers.insert(i, answer) except DNSException as e: root_logger.debug("DNS record not found: %s", e.__class__.__name__) answers = [] From 993c99868f3e033122bfe6fc95f53c701243d3f0 Mon Sep 17 00:00:00 2001 From: Alex Zel <alex88...@gmail.com> Date: Sun, 2 Apr 2017 12:04:11 +0300 Subject: [PATCH 2/2] fix indentation --- ipaclient/install/ipadiscovery.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ipaclient/install/ipadiscovery.py b/ipaclient/install/ipadiscovery.py index c6fc240..4f18398 100644 --- a/ipaclient/install/ipadiscovery.py +++ b/ipaclient/install/ipadiscovery.py @@ -493,15 +493,15 @@ def ipadns_search_srv(self, domain, srv_record_name, default_port, try: answers = [] - dns_answers = resolver.query(qname, rdatatype.SRV) - for answer in dns_answers: - if not len(answers): - answers.append(answer) - else: - i = 0 - while i < len(answers) and answer.priority > answers[i].priority: - i += 1 - answers.insert(i, answer) + dns_answers = resolver.query(qname, rdatatype.SRV) + for answer in dns_answers: + if not len(answers): + answers.append(answer) + else: + i = 0 + while i < len(answers) and answer.priority > answers[i].priority: + i += 1 + answers.insert(i, answer) except DNSException as e: root_logger.debug("DNS record not found: %s", e.__class__.__name__) answers = [] @@ -531,15 +531,15 @@ def ipadnssearchkrbrealm(self, domain=None): try: answers = [] - dns_answers = resolver.query(qname, rdatatype.SRV) - for answer in dns_answers: - if not len(answers): - answers.append(answer) - else: - i = 0 - while i < len(answers) and answer.priority > answers[i].priority: - i += 1 - answers.insert(i, answer) + dns_answers = resolver.query(qname, rdatatype.SRV) + for answer in dns_answers: + if not len(answers): + answers.append(answer) + else: + i = 0 + while i < len(answers) and answer.priority > answers[i].priority: + i += 1 + answers.insert(i, answer) except DNSException as e: root_logger.debug("DNS record not found: %s", e.__class__.__name__) answers = []
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code