journal-remote: refuse to specify --trust option when gnutls is disabled
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 24 Mar 2022 07:58:59 +0000 (16:58 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Apr 2022 17:13:02 +0000 (19:13 +0200)
and check_permission() should not be called in that case.

Replaces #22847.

(cherry picked from commit f7adeaeb897f6d24c50250e2d5fdc9797964b81e)
(cherry picked from commit bba396d78ce4752b7446c014b5dfe9a521c870e0)

src/journal-remote/journal-remote-main.c
src/journal-remote/microhttpd-util.c

index b46b4fc08ecd0b53e1888ea2c12b90c31eaf0490..4e2e29ef7c54a0db897836d920b6a22c77738b91 100644 (file)
@@ -46,7 +46,11 @@ static const char* arg_output = NULL;
 static char *arg_key = NULL;
 static char *arg_cert = NULL;
 static char *arg_trust = NULL;
+#if HAVE_GNUTLS
 static bool arg_trust_all = false;
+#else
+static bool arg_trust_all = true;
+#endif
 
 STATIC_DESTRUCTOR_REGISTER(arg_gnutls_log, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_key, freep);
@@ -932,6 +936,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_TRUST:
+#if HAVE_GNUTLS
                         if (arg_trust || arg_trust_all)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "Confusing trusted CA configuration");
@@ -939,16 +944,14 @@ static int parse_argv(int argc, char *argv[]) {
                         if (streq(optarg, "all"))
                                 arg_trust_all = true;
                         else {
-#if HAVE_GNUTLS
                                 arg_trust = strdup(optarg);
                                 if (!arg_trust)
                                         return log_oom();
+                        }
 #else
-                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                       "Option --trust is not available.");
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Option --trust is not available.");
 #endif
-                        }
-
                         break;
 
                 case 'o':
index e6a82544912ddc3d941339857ac8685dbcd4d881..7c59d90ef4c6a84b28d416f4b449451c8ae89cc1 100644 (file)
@@ -300,7 +300,7 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn
 
 #else
 int check_permissions(struct MHD_Connection *connection, int *code, char **hostname) {
-        return -EPERM;
+        assert_not_reached();
 }
 
 int setup_gnutls_logger(char **categories) {