andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 9655e2f36b9127068ce25046b8bb512c3c9fa565 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Fri, 21 Dec 2012 10:31:24 -0800
Subject: [PATCH 139/225] Ticket #422 - 389-ds-base - Can't call method
 "getText"

Bug description: If a hostname which has no corresponding IP
address associated is given to the setup-ds-admin.pl or
setup-ds.pl (e.g., bogus.bogus.bogus.com), then DSUtil.pm
complains with "Can't call method "getText" on an undefined
value".

Fix description: Thanks to Rich for his comments.  Following
his suggestions, this patch prepares 2 different return types
in checkHostname depending upon the existence of the resource
object.  If the resource is given, the subroutine returns the
error message.  Otherwise, it returns the array of error message.

https://fedorahosted.org/389/ticket/422
(cherry picked from commit d8cdb35018d63757de165c9d47f4734780f41c1b)
(cherry picked from commit 87a069c2318fcc6c8d81446a5eb82a93d9bfc0ca)
---
 ldap/admin/src/scripts/DSCreate.pm.in |  6 ++---
 ldap/admin/src/scripts/DSUtil.pm.in   | 44 +++++++++++++++++++++++------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in
index 0acd74f..30de40e 100644
--- a/ldap/admin/src/scripts/DSCreate.pm.in
+++ b/ldap/admin/src/scripts/DSCreate.pm.in
@@ -150,9 +150,9 @@ sub sanityCheckParams {
         debug(0, "WARNING: The root password is less than 8 characters long.  You should choose a longer one.\n");
     }
 
-    my $str = checkHostname($inf->{General}->{FullMachineName});
-    if ($str) {
-        debug(0, $str);
+    if (@errs = checkHostname($inf->{General}->{FullMachineName}, 0)) {
+        debug(1, @errs);
+        return @errs;
     }
 
     return ();
diff --git a/ldap/admin/src/scripts/DSUtil.pm.in b/ldap/admin/src/scripts/DSUtil.pm.in
index cc64a2d..0f72571 100644
--- a/ldap/admin/src/scripts/DSUtil.pm.in
+++ b/ldap/admin/src/scripts/DSUtil.pm.in
@@ -207,7 +207,8 @@ sub isValidGroup {
 # arguments
 # - hostname - the hostname to look for
 # - res - the Resource object to use to construct messages
-# returns - the error message string, or "" upon success
+# returns - the error message string, or "" upon success if $res exists
+#         - the error message array, or () upon success otherwise
 sub checkHostname {
     my $hn = shift;
     my $res = shift;
@@ -217,7 +218,7 @@ sub checkHostname {
         if ($res) {
             return $res->getText('warning_hostname_not_fully_qualified', $hn);
         } else {
-            return "Warning: hostname $hn is not a fully qualified host and domain name\n";
+            return ('warning_hostname_not_fully_qualified', $hn);
         }
     }
 
@@ -229,7 +230,11 @@ sub checkHostname {
         my %hints = (socktype => SOCK_STREAM);
         my ($err, @aires) = getaddrinfo($hn, "ldap", \%hints);
         if ($err) {
-            return $res->getText('warning_no_such_hostname', $hn);
+            if ($res) {
+                return $res->getText('warning_no_such_hostname', $hn);
+            } else {
+                return ('warning_no_such_hostname', $hn);
+            }
         }
         while (my $ai = shift @aires) {
             debug(1, "found for hostname $hn\n");
@@ -256,7 +261,11 @@ sub checkHostname {
         debug(1, "Socket6\n");
         my @aires = getaddrinfo($hn, "ldap", AF_UNSPEC, SOCK_STREAM);
         if (scalar(@aires) < 5) {
-            return $res->getText('warning_no_such_hostname', $hn);
+            if ($res) {
+                return $res->getText('warning_no_such_hostname', $hn);
+            } else {
+                return ('warning_no_such_hostname', $hn);
+            }
         }
         my $ailen = scalar(@aires);
         while ($ailen >= 5) {
@@ -293,7 +302,7 @@ sub checkHostname {
             if ($res) {
                 return $res->getText('warning_no_such_hostname', $hn);
             } else {
-                return "Warning: could not resolve hostname $hn\n";
+                return ('warning_no_such_hostname', $hn);
             }
         }
         debug(1, "found for hostname $hn: name=$name\n");
@@ -313,24 +322,29 @@ sub checkHostname {
     }
 
     if (!$found) {
-        my $retstr = "";
         if ($res) {
+            my $retstr = "";
             $retstr = $res->getText('warning_reverse_resolve', $hn, $hn);
-        } else {
-            $retstr = "Warning: Hostname $hn is valid, but none of the IP addresses\nresolve back to $hn\n";
-        }
-        for my $ii (@hostip) {
-            if ($res) {
+            for my $ii (@hostip) {
                 $retstr .= $res->getText('warning_reverse_resolve_sub', $ii->[1], $ii->[0]);
-            } else {
-                $retstr .= "\taddress $ii->[1] resolves to host $ii->[0]\n";
             }
+            return $retstr;
+        } else {
+            my @reterrs = ();
+            push @reterrs, [ 'warning_reverse_resolve', $hn, $hn ];
+            for my $ii (@hostip) {
+                push @reterrs, [ 'warning_reverse_resolve_sub', $ii->[1], $ii->[0] ];
+            }
+            return @reterrs;
         }
-        return $retstr;
     }
 
     debug(1, "hostname $hn resolves correctly\n");
-    return '';
+    if ($res) {
+        return '';
+    } else {
+        return ();
+    }
 }
 
 # delete the subtree starting from the passed entry
-- 
1.8.1.4