On Thu, 2011-02-10 at 13:58 -0500, Rob Crittenden wrote: > Martin Kosek wrote: > > This patch fixes behavior of ipa-dns-install, which does not > > exit when an invalid configuration of /etc/hosts is detected. > > > > https://fedorahosted.org/freeipa/ticket/736 > > I'm not positive but was the address info checking done within the try > to catch any possible exception? > > This code dates back to very early IPA code (say 4 years old or so) when > we were pretty new to python and somethings catching things in a very > broad way. > > Is it possible that running through the addresses could raise an > unhandled exception? > > rob
Rob, thanks for the review. Well, I think the unhandled code should not raise any exception - we are not calling any external function, just going through an array. But to bulletproof it, I have added a check just to be sure that we do it right even when socket.getaddrinfo would return empty result and did not raise an exception. Patch is attached. I moved the exception handling closer to the socket.getaddrinfo to actually be able to easily call sys.exit(). Martin
>From 1b361dbe9469a5896140ce7ce819d4013d93d0cd Mon Sep 17 00:00:00 2001 From: Martin Kosek <mko...@redhat.com> Date: Thu, 10 Feb 2011 14:18:57 +0100 Subject: [PATCH] ipa-dns-install does not exit on error This patch fixes behavior of ipa-dns-install, which does not exit when an invalid configuration of /etc/hosts is detected. https://fedorahosted.org/freeipa/ticket/736 --- install/tools/ipa-dns-install | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-) diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install index 66cdaffd8a18b1ba3771f14cf17e61edc021f1e0..57a9cb36eb86e408e305c9b1e2431e4e54cce621 100755 --- a/install/tools/ipa-dns-install +++ b/install/tools/ipa-dns-install @@ -67,19 +67,24 @@ def resolve_host(host_name): try: addrinfos = socket.getaddrinfo(host_name, None, socket.AF_UNSPEC, socket.SOCK_DGRAM) - for ai in addrinfos: - ip = ai[4][0] - if ip == "127.0.0.1" or ip == "::1": - print "The hostname resolves to the localhost address (127.0.0.1/::1)" - print "Please change your /etc/hosts file so that the hostname" - print "resolves to the ip address of your network interface." - print "" - print "Please fix your /etc/hosts file and restart the setup program" - return None - - ip = addrinfos[0][4][0] except: print "Unable to lookup the IP address of the provided host" + return None + + for ai in addrinfos: + ip = ai[4][0] + if ip == "127.0.0.1" or ip == "::1": + print "The hostname resolves to the localhost address (127.0.0.1/::1)" + print "Please change your /etc/hosts file so that the hostname" + print "resolves to the ip address of your network interface." + print "" + print "Please fix your /etc/hosts file and restart the setup program." + print "" + sys.exit("Aborting installation.") + + if addrinfos: + ip = addrinfos[0][4][0] + return ip def main(): @@ -108,7 +113,7 @@ def main(): # Check bind packages are installed if not bindinstance.check_inst(options.unattended): - sys.exit("Aborting installation") + sys.exit("Aborting installation.") # Initialize the ipalib api cfg = dict( -- 1.7.4
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel