Fix bad searching of reverse DNS zone

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

--

Pavel^3 Vomacka

From ff1e9d9930146ae998bec34e739d0cd8a1fdaa55 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Mon, 6 Jun 2016 18:56:03 +0200
Subject: [PATCH] Fix bad searching of reverse DNS zone

https://fedorahosted.org/freeipa/ticket/5796
---
 install/ui/src/freeipa/dns.js | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/install/ui/src/freeipa/dns.js b/install/ui/src/freeipa/dns.js
index 8bfc23a1ac7fdd47c917091126f6298e323f1dcf..3d384184aa0f4349ae5fdce2673b0803baa3777a 100644
--- a/install/ui/src/freeipa/dns.js
+++ b/install/ui/src/freeipa/dns.js
@@ -2263,28 +2263,27 @@ IPA.dns.ptr_redirection_dialog = function(spec) {
     //2nd step: find target zone
     that.find_zone = function(data) {
         var zones = data.result.result;
-        var target_zone = null;
+        var target_zone = {
+            index: 100,
+            target_zone: ''
+        };
 
         for (var i=0; i<zones.length; i++) {
 
             var zone_name = rpc.extract_objects(zones[i].idnsname)[0];
-            if (that.reverse_address.indexOf(zone_name) > -1) {
-                var msg = text.get('@i18n:objects.dnsrecord.ptr_redir_zone');
-                msg = msg.replace('${zone}', zone_name);
-                that.append_status(msg);
+            var index = that.reverse_address.indexOf(zone_name);
 
-                if (!target_zone ||
-                    (target_zone && zone_name.length > target_zone.length)) {
-
-                    target_zone = zone_name;
-                }
-
-                break;
+            if (index > -1 && target_zone.index > index) {
+                target_zone.target_zone = zone_name;
             }
         }
 
-        if (target_zone) {
-            that.zone = target_zone;
+        if (target_zone.target_zone !== '') {
+
+            that.zone = target_zone.target_zone;
+            var msg = text.get('@i18n:objects.dnsrecord.ptr_redir_zone');
+            msg = msg.replace('${zone}', that.zone);
+            that.append_status(msg);
             that.check_record();
         } else {
             that.append_status(text.get('@i18n:objects.dnsrecord.ptr_redir_zone_err'));
-- 
2.5.5

-- 
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

Reply via email to