diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c index 21fae89fd0..95d9c3dd83 100644 --- a/src/basic/hostname-util.c +++ b/src/basic/hostname-util.c @@ -105,7 +105,7 @@ bool hostname_is_valid(const char *s, bool relax) { return true; } -char* hostname_cleanup(char *s, bool lowercase) { +char* hostname_cleanup(char *s) { char *p, *d; bool dot; @@ -119,7 +119,7 @@ char* hostname_cleanup(char *s, bool lowercase) { *(d++) = '.'; dot = true; } else if (hostname_valid_char(*p)) { - *(d++) = lowercase ? tolower(*p) : *p; + *(d++) = *p; dot = false; } @@ -185,7 +185,7 @@ int read_hostname_config(const char *path, char **hostname) { truncate_nl(l); if (l[0] != '\0' && l[0] != '#') { /* found line with value */ - name = hostname_cleanup(l, false); + name = hostname_cleanup(l); name = strdup(name); if (!name) return -ENOMEM; diff --git a/src/basic/hostname-util.h b/src/basic/hostname-util.h index ecae3a267c..6f2b5b66ff 100644 --- a/src/basic/hostname-util.h +++ b/src/basic/hostname-util.h @@ -30,7 +30,7 @@ bool hostname_is_set(void); char* gethostname_malloc(void); bool hostname_is_valid(const char *s, bool relax) _pure_; -char* hostname_cleanup(char *s, bool lowercase); +char* hostname_cleanup(char *s); bool is_localhost(const char *hostname); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index df98212da8..01a3d38746 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -392,7 +392,7 @@ static int prompt_hostname(void) { } /* Get rid of the trailing dot that we allow, but don't want to see */ - arg_hostname = hostname_cleanup(h, false); + arg_hostname = hostname_cleanup(h); h = NULL; break; } @@ -786,7 +786,7 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; } - hostname_cleanup(optarg, false); + hostname_cleanup(optarg); if (free_and_strdup(&arg_hostname, optarg) < 0) return log_oom(); diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index d194e9b629..dcbad99ae9 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -273,13 +273,13 @@ static int set_hostname(sd_bus *bus, char **args, unsigned n) { if (arg_static && hostname_is_valid(hostname, true)) { p = ""; /* maybe get rid of trailing dot */ - hostname = hostname_cleanup(hostname, false); + hostname = hostname_cleanup(hostname); } else { p = h = strdup(hostname); if (!p) return log_oom(); - hostname_cleanup(hostname, false); + hostname_cleanup(hostname); } r = set_simple_string(bus, "SetPrettyHostname", p); diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index 9a09f401e0..1eb07a1681 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -797,7 +797,7 @@ static int request_handler_machine( "\"cutoff_to_realtime\" : \"%"PRIu64"\" }\n", SD_ID128_FORMAT_VAL(mid), SD_ID128_FORMAT_VAL(bid), - hostname_cleanup(hostname, false), + hostname_cleanup(hostname), os_name ? os_name : "Linux", v ? v : "bare", usage, diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 073cc77711..d2c0a03ccb 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1527,7 +1527,7 @@ static int setup_keys(void) { hn = gethostname_malloc(); if (hn) { - hostname_cleanup(hn, false); + hostname_cleanup(hn); fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine)); } else fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine)); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 9a19109b9f..6678b2c77a 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -845,7 +845,7 @@ int config_parse_hostname(const char *unit, return 0; } - *hostname = hostname_cleanup(hn, false); + *hostname = hostname_cleanup(hn); return 0; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 65b9a5071b..cf77cfd220 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -4005,7 +4005,7 @@ static int determine_names(void) { if (!arg_machine) return log_oom(); - hostname_cleanup(arg_machine, false); + hostname_cleanup(arg_machine); if (!machine_name_is_valid(arg_machine)) { log_error("Failed to determine machine name automatically, please use -M."); return -EINVAL; diff --git a/src/test/test-hostname-util.c b/src/test/test-hostname-util.c index 2357ab5758..08be3f7bf2 100644 --- a/src/test/test-hostname-util.c +++ b/src/test/test-hostname-util.c @@ -65,37 +65,37 @@ static void test_hostname_cleanup(void) { char *s; s = strdupa("foobar"); - assert_se(streq(hostname_cleanup(s, false), "foobar")); + assert_se(streq(hostname_cleanup(s), "foobar")); s = strdupa("foobar.com"); - assert_se(streq(hostname_cleanup(s, false), "foobar.com")); + assert_se(streq(hostname_cleanup(s), "foobar.com")); s = strdupa("foobar.com."); - assert_se(streq(hostname_cleanup(s, false), "foobar.com")); + assert_se(streq(hostname_cleanup(s), "foobar.com")); s = strdupa("fooBAR"); - assert_se(streq(hostname_cleanup(s, false), "fooBAR")); + assert_se(streq(hostname_cleanup(s), "fooBAR")); s = strdupa("fooBAR.com"); - assert_se(streq(hostname_cleanup(s, false), "fooBAR.com")); + assert_se(streq(hostname_cleanup(s), "fooBAR.com")); s = strdupa("fooBAR."); - assert_se(streq(hostname_cleanup(s, false), "fooBAR")); + assert_se(streq(hostname_cleanup(s), "fooBAR")); s = strdupa("fooBAR.com."); - assert_se(streq(hostname_cleanup(s, false), "fooBAR.com")); + assert_se(streq(hostname_cleanup(s), "fooBAR.com")); s = strdupa("fööbar"); - assert_se(streq(hostname_cleanup(s, false), "fbar")); + assert_se(streq(hostname_cleanup(s), "fbar")); s = strdupa(""); - assert_se(isempty(hostname_cleanup(s, false))); + assert_se(isempty(hostname_cleanup(s))); s = strdupa("."); - assert_se(isempty(hostname_cleanup(s, false))); + assert_se(isempty(hostname_cleanup(s))); s = strdupa(".."); - assert_se(isempty(hostname_cleanup(s, false))); + assert_se(isempty(hostname_cleanup(s))); s = strdupa("foobar."); - assert_se(streq(hostname_cleanup(s, false), "foobar")); + assert_se(streq(hostname_cleanup(s), "foobar")); s = strdupa(".foobar"); - assert_se(streq(hostname_cleanup(s, false), "foobar")); + assert_se(streq(hostname_cleanup(s), "foobar")); s = strdupa("foo..bar"); - assert_se(streq(hostname_cleanup(s, false), "foo.bar")); + assert_se(streq(hostname_cleanup(s), "foo.bar")); s = strdupa("foo.bar.."); - assert_se(streq(hostname_cleanup(s, false), "foo.bar")); + assert_se(streq(hostname_cleanup(s), "foo.bar")); s = strdupa("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - assert_se(streq(hostname_cleanup(s, false), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); + assert_se(streq(hostname_cleanup(s), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); } static void test_read_hostname_config(void) {