From 7faeef7cd9dc8ba13009c43f00e1faebbf63e1cb Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Mon, 8 Sep 2014 19:05:58 -0400
Subject: [PATCH] Ticket 47893 - Admin Server should use Sys::Hostname instead
 Net::Domain

Bug Description: hostfqdn function does not always return the correct fqdn.
                 Sometimes it incrrectly adds ".com" when it should not.

Fix Description: Use Sys::Hostname/hostname() which does return the correct
                 fqdn.

https://fedorahosted.org/389/ticket/47893

Reviewed by: ?
---
 admserv/newinst/src/ConfigDSDialogs.pm      | 12 ++++++------
 admserv/newinst/src/register-ds-admin.pl.in |  4 ++--
 admserv/newinst/src/register_param.map.in   |  4 ++--
 admserv/newinst/src/register_server.pl.in   |  6 ++++--
 admserv/newinst/src/setup-ds-admin.pl.in    |  6 +++---
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/admserv/newinst/src/ConfigDSDialogs.pm b/admserv/newinst/src/ConfigDSDialogs.pm
index 3501870..f168825 100644
--- a/admserv/newinst/src/ConfigDSDialogs.pm
+++ b/admserv/newinst/src/ConfigDSDialogs.pm
@@ -20,7 +20,7 @@ package ConfigDSDialogs;
 
 use strict;
 
-use Net::Domain qw(hostfqdn);
+use Sys::Hostname;
 use DialogManager;
 use Setup;
 use Dialog;
@@ -74,7 +74,7 @@ my $configdsinfo = new Dialog (
             my $url = $self->{manager}->{inf}->{General}->{ConfigDirectoryLdapURL};
             if (!defined($url)) {
                 my $host = $self->{manager}->{inf}->{General}->{FullMachineName} ||
-                    hostfqdn;
+                    hostname();
                 my $port = $self->{manager}->{inf}->{slapd}->{ServerPort} || 389;
                 if (!portAvailable($port)) {
                     $port = getAvailablePort();
@@ -92,7 +92,7 @@ my $configdsinfo = new Dialog (
             my $admindomain = $self->{manager}->{inf}->{General}->{AdminDomain};
             if (!defined($admindomain)) {
                 $admindomain = $self->{manager}->{inf}->{General}->{FullMachineName} ||
-                    hostfqdn;
+                    hostname();
                 $admindomain =~ s/^[^\.]*\.//; # just the domain part
             }
             return $admindomain;
@@ -177,7 +177,7 @@ my $regconfigdsinfo = new Dialog (
             my $url = $self->{manager}->{inf}->{General}->{ConfigDirectoryLdapURL};
             if (!defined($url)) {
                 my $host = $self->{manager}->{inf}->{General}->{FullMachineName} ||
-                    hostfqdn;
+                    hostname();
                 my $port = $self->{manager}->{inf}->{slapd}->{ServerPort} || 389;
                 if (!portAvailable($port)) {
                     $port = getAvailablePort();
@@ -195,7 +195,7 @@ my $regconfigdsinfo = new Dialog (
             my $admindomain = $self->{manager}->{inf}->{General}->{AdminDomain};
             if (!defined($admindomain)) {
                 $admindomain = $self->{manager}->{inf}->{General}->{FullMachineName} ||
-                    hostfqdn;
+                    hostname();
                 $admindomain =~ s/^[^\.]*\.//; # just the domain part
             }
             return $admindomain;
@@ -339,7 +339,7 @@ my $configdsadmindomain = new Dialog (
         my $admindomain = $self->{manager}->{inf}->{General}->{AdminDomain};
         if (!defined($admindomain)) {
             $admindomain = $self->{manager}->{inf}->{General}->{FullMachineName} ||
-                hostfqdn;
+                hostname();
             $admindomain =~ s/^[^\.]*\.//; # just the domain part
         }
         return $admindomain;
diff --git a/admserv/newinst/src/register-ds-admin.pl.in b/admserv/newinst/src/register-ds-admin.pl.in
index 45ca806..2f92411 100644
--- a/admserv/newinst/src/register-ds-admin.pl.in
+++ b/admserv/newinst/src/register-ds-admin.pl.in
@@ -42,7 +42,7 @@ use lib qw(@perlpath@);
 use strict;
 
 use File::Basename;
-use Net::Domain qw(hostfqdn);
+use Sys::Hostname;
 
 # Admin Setup modules
 use AdminUtil;
@@ -220,7 +220,7 @@ my $new_confdsid = "";
 my $new_confdir = "";
 my $adminuid = "";
 my @errs = ();
-my $fqdn = hostfqdn();
+my $fqdn = hostname();
 
 # set defaults
 if ( $#admConfKeys >= 4 ) # admserv.conf, console.conf, httpd.conf, nss.conf
diff --git a/admserv/newinst/src/register_param.map.in b/admserv/newinst/src/register_param.map.in
index cd13c61..1084e94 100644
--- a/admserv/newinst/src/register_param.map.in
+++ b/admserv/newinst/src/register_param.map.in
@@ -36,8 +36,8 @@
 # * The right-hand value can contain variables surrounded by % (e.g., %asid%)
 #   which refers the right-hand value (key) of this map file.
 # 
-fqdn =			`use Net::Domain qw(hostfqdn); $returnvalue = hostfqdn();`
-domain =		`use Net::Domain qw(hostdomain); $returnvalue = hostdomain();`
+fqdn =			`use Sys::Hostname; $returnvalue = hostname();`
+domain =		`use Sys::Hostname; $fqdn = hostname(); $fqdn =~ /(.+?)(?=\.)/; $fqdn =~ s/$1\.//; $returnvalue = $fqdn;`
 brand =			Brand
 normbrand =			NormBrand
 hostname =		`$returnvalue = $mapper->{fqdn}; $returnvalue =~ s/\..*$//;`
diff --git a/admserv/newinst/src/register_server.pl.in b/admserv/newinst/src/register_server.pl.in
index 7ab6cf9..eac6337 100644
--- a/admserv/newinst/src/register_server.pl.in
+++ b/admserv/newinst/src/register_server.pl.in
@@ -37,9 +37,11 @@
 use lib qw(@perlpath@);
 
 use Getopt::Std;
-use Net::Domain qw(hostname hostfqdn);
+use Sys::Hostname;
+
 # PERLDAP modules
 use Mozilla::LDAP::Conn;
+
 # Setup Inf module
 use Inf;
 use DSUtil;
@@ -78,7 +80,7 @@ $confds_fresh = $opt_F;
 $confds_host = $opt_h;
 if ( "" eq $confds_host )
 {
-	$confds_host = hostfqdn();
+	$confds_host = hostname();
 }
 $confds_port = $opt_p;
 if ( "" eq $confds_port )
diff --git a/admserv/newinst/src/setup-ds-admin.pl.in b/admserv/newinst/src/setup-ds-admin.pl.in
index edb0f2d..3436f37 100644
--- a/admserv/newinst/src/setup-ds-admin.pl.in
+++ b/admserv/newinst/src/setup-ds-admin.pl.in
@@ -31,7 +31,7 @@ use DSUpdate;
 use AdminUtil;
 use AdminServer;
 use DSUtil;
-use Net::Domain qw(hostfqdn);
+use Sys::Hostname;
 
 my $res = new Resource("@propertydir@/setup-ds.res",
                        "@propertydir@/setup-ds-admin.res");
@@ -164,7 +164,7 @@ if (!$setup->{silent}) {
 
 # set default values
 if (!defined($setup->{inf}->{General}->{FullMachineName})) {
-    $setup->{inf}->{General}->{FullMachineName} = hostfqdn;
+    $setup->{inf}->{General}->{FullMachineName} = hostname();
 }
 
 if (!defined($setup->{inf}->{slapd}->{ServerPort})) {
@@ -195,7 +195,7 @@ if (!defined($setup->{inf}->{General}->{ConfigDirectoryAdminID})) {
 
 if (!defined($setup->{inf}->{General}->{AdminDomain})) {
     my $admindomain = $setup->{inf}->{General}->{FullMachineName} ||
-        hostfqdn;
+        hostname();
     $admindomain =~ s/^[^\.]*\.//; # just the domain part
     $setup->{inf}->{General}->{AdminDomain} = $admindomain;
 }
-- 
1.9.3

