Joey Boggs
2009-Mar-25 19:21 UTC
[Ovirt-devel] [PATCH server] verify hostname is not on the loopback entry in /etc/hosts
To prevent kerberos errors the fqdn must never be on the loopback entry --- installer/bin/ovirt-installer | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/installer/bin/ovirt-installer b/installer/bin/ovirt-installer index a2aae9f..28b269c 100755 --- a/installer/bin/ovirt-installer +++ b/installer/bin/ovirt-installer @@ -96,6 +96,20 @@ welcome = "This installer will configure the ovirt installation based on a seri of questions. When complete, you will be asked to install oVirt or\n\ do the installation manually. Would you like to continue?" +# verify hostname is not on the loopback line in /etc/hosts to prevent kerberos problems +hostname = `hostname` +hostsfile = File.new("/etc/hosts", "r") +while (line = hostsfile.gets) + if line =~ /127.0.0.1/ && line.include?(hostname.chomp) + if hostname !~ /localhost.localdomain/ + @cli.say("\nHostname must not be on the loopback 127.0.0.1 line in /etc/hosts") + @cli.say("#{line}") + exit(0) + end + end +end +hostsfile.close + if (prompt_yes_no(welcome, :default => "y") == "n") exit(0) end -- 1.6.0.6
David Lutterkort
2009-Apr-01 23:46 UTC
[Ovirt-devel] [PATCH server] verify hostname is not on the loopback entry in /etc/hosts
On Wed, 2009-03-25 at 15:21 -0400, Joey Boggs wrote:> +# verify hostname is not on the loopback line in /etc/hosts to prevent kerberos problems > +hostname = `hostname` > +hostsfile = File.new("/etc/hosts", "r") > +while (line = hostsfile.gets) > + if line =~ /127.0.0.1/ && line.include?(hostname.chomp) > + if hostname !~ /localhost.localdomain/ > + @cli.say("\nHostname must not be on the loopback 127.0.0.1 line in /etc/hosts") > + @cli.say("#{line}") > + exit(0) > + end > + end > +end > +hostsfile.closeThis can produce false positives in a number of ways: (1) it will get confused by comments: # We used to have, but that's wrong # 127.0.0.1 host.exmaple.com 127.0.0.1 localhost.localdomain It also gets confused if hostname is 'host.example.com' and the 127.0.0.1 line has an alias 'myhost.example.com'. Finally, (but that should happen throughout the installer), the installer shouldn't exit with status 0 when there was an error. It would be good to have a convention like status == 0 when installer finished successfully, status == 1 when an error happened, status == 2 when user exited installer (e.g., by answering 'no' to some question) A more robust implementation of the above would be: aug = Augeas::init(nil, nil, 0) hosts = "/files/etc/hosts/*" paths = aug.match("#{hosts}/canonical[../ipaddr = '127.0.0.1']") + aug.match("#{hosts}/alias[../ipaddr = '127.0.0.1']") paths.each do |p| name = aug.get(p) if hostname == name @cli.say("\nHostname must not be on the loopback 127.0.0.1 line in /etc/hosts") if (prompt_yes_no("Should I fix that ?", :default => "n") == "y") aug.rm(p) aug.save end end end David