Browse Source

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
Noriko Hosoi 13 years ago
parent
commit
d8cdb35018
2 changed files with 32 additions and 18 deletions
  1. 3 3
      ldap/admin/src/scripts/DSCreate.pm.in
  2. 29 15
      ldap/admin/src/scripts/DSUtil.pm.in

+ 3 - 3
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 ();

+ 29 - 15
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