[Ovirt-devel] [PATCH server] verify hostname is not on the loopback entry in /etc/hosts
Joey Boggs
jboggs at redhat.com
Thu Apr 2 15:44:55 UTC 2009
Trying to get this working on a test file but running into: tundefined
method `init' for Augeas:Class (NoMethodError)
I've built augeas from source and still run into the same problem.
Tried latest available in F10 (0.3.6-1.fc10)
Then upgraded to:
augeas-0.0.5 built from source
ruby-augeas-0.2.0-2.fc11.x86_64 from rawhide
augeas-libs-0.4.2-1.fc11.x86_64 from rawhide
#!/usr/bin/ruby
require 'augeas'
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 Lutterkort wrote:
> 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.close
>>
>
> This 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
>
>
>
More information about the ovirt-devel
mailing list