diff options
author | Olivier Blin <oblin@mandriva.org> | 2004-07-13 06:55:29 +0000 |
---|---|---|
committer | Olivier Blin <oblin@mandriva.org> | 2004-07-13 06:55:29 +0000 |
commit | 7972cf7b6f8ff0a38c16e693b56d08fd10e8effd (patch) | |
tree | 889dbb24b6c9bcb8b9561f6643b23c8858b43992 /mdk-stage1 | |
parent | 7db84e1cffc7e8de8a9ff20fa6d03631daa7bbef (diff) | |
download | drakx-7972cf7b6f8ff0a38c16e693b56d08fd10e8effd.tar drakx-7972cf7b6f8ff0a38c16e693b56d08fd10e8effd.tar.gz drakx-7972cf7b6f8ff0a38c16e693b56d08fd10e8effd.tar.bz2 drakx-7972cf7b6f8ff0a38c16e693b56d08fd10e8effd.tar.xz drakx-7972cf7b6f8ff0a38c16e693b56d08fd10e8effd.zip |
fix segfault when hostname resolves as weird name without any dot (for
example 24.159.64.20 resolves as TN-JACKSN-NR1) and abort domain name
guess in this case
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/network.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index e3764205f..f1f5c1bf5 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -348,6 +348,16 @@ char * guess_netmask(char * ip_addr) } +char * guess_domain_from_hostname(char *hostname) { + char *domain = strchr(strdup(hostname), '.'); + if (!domain || domain[1] == '\0') { + log_message("unable to guess domain from hostname: %s", hostname); + return NULL; + } + return domain + 1; /* skip '.' */ +} + + static void static_ip_callback(char ** strings) { struct in_addr addr; @@ -481,24 +491,31 @@ static enum return_type configure_network(struct interface_info * intf) if (dnshostname) { if (intf->boot_proto == BOOTPROTO_STATIC) hostname = strdup(dnshostname); - domain = strchr(strdup(dnshostname), '.') + 1; - log_message("got hostname and domain from dns entry, %s and %s", dnshostname, domain); - return RETURN_OK; - } - - log_message("reverse name lookup on self failed"); + domain = guess_domain_from_hostname(dnshostname); + if (domain) { + log_message("got hostname and domain from dns entry, %s and %s", dnshostname, domain); + return RETURN_OK; + } + } else + log_message("reverse name lookup on self failed"); if (domain) return RETURN_OK; + dnshostname = NULL; if (dns_server.s_addr != 0) { wait_message("Trying to resolve dns..."); dnshostname = mygethostbyaddr(inet_ntoa(dns_server)); remove_wait_message(); - } + if (dnshostname) { + log_message("got DNS fullname, %s", dnshostname); + domain = guess_domain_from_hostname(dnshostname); + } else + log_message("reverse name lookup on DNS failed"); + } else + log_message("no DNS, unable to guess domain"); - if (dnshostname) { - domain = strchr(strdup(dnshostname), '.') + 1; + if (domain) { log_message("got domain from DNS fullname, %s", domain); } else { enum return_type results; @@ -507,8 +524,6 @@ static enum return_type configure_network(struct interface_info * intf) static char ** answers = NULL; char * boulet; - log_message("reverse name lookup on DNS failed"); - results = ask_from_entries_auto("I could not guess hostname and domain name; please fill in this information. " "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for " "domain name, for a machine called `mybox.mynetwork.com' on the Internet.", |