andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame 0139-Ticket-422-389-ds-base-Can-t-call-method-getText.patch

dc8c34
From 9655e2f36b9127068ce25046b8bb512c3c9fa565 Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@redhat.com>
dc8c34
Date: Fri, 21 Dec 2012 10:31:24 -0800
dc8c34
Subject: [PATCH 139/225] Ticket #422 - 389-ds-base - Can't call method
dc8c34
 "getText"
dc8c34
dc8c34
Bug description: If a hostname which has no corresponding IP
dc8c34
address associated is given to the setup-ds-admin.pl or
dc8c34
setup-ds.pl (e.g., bogus.bogus.bogus.com), then DSUtil.pm
dc8c34
complains with "Can't call method "getText" on an undefined
dc8c34
value".
dc8c34
dc8c34
Fix description: Thanks to Rich for his comments.  Following
dc8c34
his suggestions, this patch prepares 2 different return types
dc8c34
in checkHostname depending upon the existence of the resource
dc8c34
object.  If the resource is given, the subroutine returns the
dc8c34
error message.  Otherwise, it returns the array of error message.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/422
dc8c34
(cherry picked from commit d8cdb35018d63757de165c9d47f4734780f41c1b)
dc8c34
(cherry picked from commit 87a069c2318fcc6c8d81446a5eb82a93d9bfc0ca)
dc8c34
---
dc8c34
 ldap/admin/src/scripts/DSCreate.pm.in |  6 ++---
dc8c34
 ldap/admin/src/scripts/DSUtil.pm.in   | 44 +++++++++++++++++++++++------------
dc8c34
 2 files changed, 32 insertions(+), 18 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in
dc8c34
index 0acd74f..30de40e 100644
dc8c34
--- a/ldap/admin/src/scripts/DSCreate.pm.in
dc8c34
+++ b/ldap/admin/src/scripts/DSCreate.pm.in
dc8c34
@@ -150,9 +150,9 @@ sub sanityCheckParams {
dc8c34
         debug(0, "WARNING: The root password is less than 8 characters long.  You should choose a longer one.\n");
dc8c34
     }
dc8c34
 
dc8c34
-    my $str = checkHostname($inf->{General}->{FullMachineName});
dc8c34
-    if ($str) {
dc8c34
-        debug(0, $str);
dc8c34
+    if (@errs = checkHostname($inf->{General}->{FullMachineName}, 0)) {
dc8c34
+        debug(1, @errs);
dc8c34
+        return @errs;
dc8c34
     }
dc8c34
 
dc8c34
     return ();
dc8c34
diff --git a/ldap/admin/src/scripts/DSUtil.pm.in b/ldap/admin/src/scripts/DSUtil.pm.in
dc8c34
index cc64a2d..0f72571 100644
dc8c34
--- a/ldap/admin/src/scripts/DSUtil.pm.in
dc8c34
+++ b/ldap/admin/src/scripts/DSUtil.pm.in
dc8c34
@@ -207,7 +207,8 @@ sub isValidGroup {
dc8c34
 # arguments
dc8c34
 # - hostname - the hostname to look for
dc8c34
 # - res - the Resource object to use to construct messages
dc8c34
-# returns - the error message string, or "" upon success
dc8c34
+# returns - the error message string, or "" upon success if $res exists
dc8c34
+#         - the error message array, or () upon success otherwise
dc8c34
 sub checkHostname {
dc8c34
     my $hn = shift;
dc8c34
     my $res = shift;
dc8c34
@@ -217,7 +218,7 @@ sub checkHostname {
dc8c34
         if ($res) {
dc8c34
             return $res->getText('warning_hostname_not_fully_qualified', $hn);
dc8c34
         } else {
dc8c34
-            return "Warning: hostname $hn is not a fully qualified host and domain name\n";
dc8c34
+            return ('warning_hostname_not_fully_qualified', $hn);
dc8c34
         }
dc8c34
     }
dc8c34
 
dc8c34
@@ -229,7 +230,11 @@ sub checkHostname {
dc8c34
         my %hints = (socktype => SOCK_STREAM);
dc8c34
         my ($err, @aires) = getaddrinfo($hn, "ldap", \%hints);
dc8c34
         if ($err) {
dc8c34
-            return $res->getText('warning_no_such_hostname', $hn);
dc8c34
+            if ($res) {
dc8c34
+                return $res->getText('warning_no_such_hostname', $hn);
dc8c34
+            } else {
dc8c34
+                return ('warning_no_such_hostname', $hn);
dc8c34
+            }
dc8c34
         }
dc8c34
         while (my $ai = shift @aires) {
dc8c34
             debug(1, "found for hostname $hn\n");
dc8c34
@@ -256,7 +261,11 @@ sub checkHostname {
dc8c34
         debug(1, "Socket6\n");
dc8c34
         my @aires = getaddrinfo($hn, "ldap", AF_UNSPEC, SOCK_STREAM);
dc8c34
         if (scalar(@aires) < 5) {
dc8c34
-            return $res->getText('warning_no_such_hostname', $hn);
dc8c34
+            if ($res) {
dc8c34
+                return $res->getText('warning_no_such_hostname', $hn);
dc8c34
+            } else {
dc8c34
+                return ('warning_no_such_hostname', $hn);
dc8c34
+            }
dc8c34
         }
dc8c34
         my $ailen = scalar(@aires);
dc8c34
         while ($ailen >= 5) {
dc8c34
@@ -293,7 +302,7 @@ sub checkHostname {
dc8c34
             if ($res) {
dc8c34
                 return $res->getText('warning_no_such_hostname', $hn);
dc8c34
             } else {
dc8c34
-                return "Warning: could not resolve hostname $hn\n";
dc8c34
+                return ('warning_no_such_hostname', $hn);
dc8c34
             }
dc8c34
         }
dc8c34
         debug(1, "found for hostname $hn: name=$name\n");
dc8c34
@@ -313,24 +322,29 @@ sub checkHostname {
dc8c34
     }
dc8c34
 
dc8c34
     if (!$found) {
dc8c34
-        my $retstr = "";
dc8c34
         if ($res) {
dc8c34
+            my $retstr = "";
dc8c34
             $retstr = $res->getText('warning_reverse_resolve', $hn, $hn);
dc8c34
-        } else {
dc8c34
-            $retstr = "Warning: Hostname $hn is valid, but none of the IP addresses\nresolve back to $hn\n";
dc8c34
-        }
dc8c34
-        for my $ii (@hostip) {
dc8c34
-            if ($res) {
dc8c34
+            for my $ii (@hostip) {
dc8c34
                 $retstr .= $res->getText('warning_reverse_resolve_sub', $ii->[1], $ii->[0]);
dc8c34
-            } else {
dc8c34
-                $retstr .= "\taddress $ii->[1] resolves to host $ii->[0]\n";
dc8c34
             }
dc8c34
+            return $retstr;
dc8c34
+        } else {
dc8c34
+            my @reterrs = ();
dc8c34
+            push @reterrs, [ 'warning_reverse_resolve', $hn, $hn ];
dc8c34
+            for my $ii (@hostip) {
dc8c34
+                push @reterrs, [ 'warning_reverse_resolve_sub', $ii->[1], $ii->[0] ];
dc8c34
+            }
dc8c34
+            return @reterrs;
dc8c34
         }
dc8c34
-        return $retstr;
dc8c34
     }
dc8c34
 
dc8c34
     debug(1, "hostname $hn resolves correctly\n");
dc8c34
-    return '';
dc8c34
+    if ($res) {
dc8c34
+        return '';
dc8c34
+    } else {
dc8c34
+        return ();
dc8c34
+    }
dc8c34
 }
dc8c34
 
dc8c34
 # delete the subtree starting from the passed entry
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34