]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add a basic test that the configured fallback hostname is OK
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 May 2020 15:30:02 +0000 (17:30 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 May 2020 15:35:26 +0000 (17:35 +0200)
Ideally, assert_cc() would be used for this, so that it is not possible to even
compile systemd with something like '-Dfallback-hostname=.foo'. But to do a
proper check we need to call hostname_is_valid(), and we cannot depend on being
able to run code (e.g. during cross-compilation). So let's do a very superficial
check in meson, and a proper on in test-util.

meson.build
src/test/test-hostname-util.c

index 28494c9af23ba58b136dc6bf82de9d04662c1702..fea226e2d6f0f794b69d5eb71a25efdea81890c0 100644 (file)
@@ -639,7 +639,14 @@ endforeach
 
 ############################################################
 
-conf.set_quoted('FALLBACK_HOSTNAME', get_option('fallback-hostname'))
+fallback_hostname = get_option('fallback-hostname')
+if fallback_hostname == '' or fallback_hostname[0] == '.' or fallback_hostname[0] == '-'
+        error('Invalid fallback-hostname configuration')
+        # A more extensive test is done in test-hostname-util. Let's catch
+        # the most obvious errors here so we don't fail with an assert later.
+endif
+conf.set_quoted('FALLBACK_HOSTNAME', fallback_hostname)
+
 conf.set10('ENABLE_COMPAT_GATEWAY_HOSTNAME', get_option('compat-gateway-hostname'))
 gateway_hostnames = ['_gateway'] + (conf.get('ENABLE_COMPAT_GATEWAY_HOSTNAME') == 1 ? ['gateway'] : [])
 
index ec34f9cd716b5622199de9b9894dfff1b73c8e2b..fe1b23e1bbbfa9f51f424485ff672d28f395d73d 100644 (file)
@@ -140,6 +140,13 @@ static void test_read_etc_hostname(void) {
         unlink(path);
 }
 
+static void test_fallback_hostname(void) {
+        if (!hostname_is_valid(FALLBACK_HOSTNAME, false)) {
+                log_error("Configured fallback hostname \"%s\" is not valid.", FALLBACK_HOSTNAME);
+                exit(EXIT_FAILURE);
+        }
+}
+
 int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
@@ -148,5 +155,7 @@ int main(int argc, char *argv[]) {
         test_hostname_cleanup();
         test_read_etc_hostname();
 
+        test_fallback_hostname();
+
         return 0;
 }