From be76ec644c949ab14b2e3f3a6ef3f4f9778eb7bf Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 19 Oct 2012 21:40:08 +0200 Subject: [PATCH] Allow use of host names without any dot. * In the case where DNS isn't working we calculate the computer name from the host name. Allow that name to have no dots. https://bugs.freedesktop.org/show_bug.cgi?id=56147 --- library/adconn.c | 15 ++++++++++----- library/adenroll.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/library/adconn.c b/library/adconn.c index 2e99313..afead6a 100644 --- a/library/adconn.c +++ b/library/adconn.c @@ -258,15 +258,20 @@ ensure_computer_name (adcli_result res, /* Use the FQDN minus the last part */ dom = strchr (conn->host_fqdn, '.'); - /* If no dot, or dot is first or last, then fail */ - if (dom == NULL || dom == conn->host_fqdn || dom[1] == '\0') { + /* If dot is first then fail */ + if (dom == conn->host_fqdn) { _adcli_err (conn, "Couldn't determine the computer account name from host name: %s", conn->host_fqdn); return ADCLI_ERR_CONFIG; - } - conn->computer_name = strndup (conn->host_fqdn, dom - conn->host_fqdn); - return_unexpected_if_fail (conn->computer_name != NULL); + } else if (dom == NULL) { + conn->computer_name = strdup (conn->host_fqdn); + return_unexpected_if_fail (conn->computer_name != NULL); + + } else { + conn->computer_name = strndup (conn->host_fqdn, dom - conn->host_fqdn); + return_unexpected_if_fail (conn->computer_name != NULL); + } _adcli_str_up (conn->computer_name); diff --git a/library/adenroll.c b/library/adenroll.c index c64948b..c4098ee 100644 --- a/library/adenroll.c +++ b/library/adenroll.c @@ -123,15 +123,20 @@ ensure_computer_name (adcli_result res, /* Use the FQDN minus the last part */ dom = strchr (enroll->host_fqdn, '.'); - /* If no dot, or dot is first or last, then fail */ - if (dom == NULL || dom == enroll->host_fqdn || dom[1] == '\0') { + /* If dot is first then fail */ + if (dom == enroll->host_fqdn) { _adcli_err (enroll->conn, "Couldn't determine the computer account name from host name: %s", enroll->host_fqdn); return ADCLI_ERR_CONFIG; - } - enroll->computer_name = strndup (enroll->host_fqdn, dom - enroll->host_fqdn); - return_unexpected_if_fail (enroll->computer_name != NULL); + } else if (dom == NULL) { + enroll->computer_name = strdup (enroll->host_fqdn); + return_unexpected_if_fail (enroll->computer_name != NULL); + + } else { + enroll->computer_name = strndup (enroll->host_fqdn, dom - enroll->host_fqdn); + return_unexpected_if_fail (enroll->computer_name != NULL); + } _adcli_str_up (enroll->computer_name); -- 1.7.12.1