]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: sync TrustedCertificateFile= parsing with journal-upload
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 19 Jun 2023 15:12:38 +0000 (17:12 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 19 Jun 2023 21:42:00 +0000 (23:42 +0200)
So we can use TrustedCertificateFile=- to disable certificate checking
for both utilities.

src/journal-remote/journal-remote-main.c
src/journal-remote/journal-remote.c
src/journal-remote/journal-upload.c
src/shared/parse-helpers.c
src/shared/parse-helpers.h

index 2755f5581218999b335e23801b18aa8a6809b011..346c56cf97d43f51f3fba263e1c740aba11796cf 100644 (file)
@@ -16,6 +16,7 @@
 #include "main-func.h"
 #include "memory-util.h"
 #include "parse-argument.h"
+#include "parse-helpers.h"
 #include "pretty-print.h"
 #include "process-util.h"
 #include "rlimit-util.h"
@@ -736,7 +737,7 @@ static int parse_config(void) {
                 { "Remote",  "SplitMode",              config_parse_write_split_mode, 0, &arg_split_mode  },
                 { "Remote",  "ServerKeyFile",          config_parse_path,             0, &arg_key         },
                 { "Remote",  "ServerCertificateFile",  config_parse_path,             0, &arg_cert        },
-                { "Remote",  "TrustedCertificateFile", config_parse_path,             0, &arg_trust       },
+                { "Remote",  "TrustedCertificateFile", config_parse_path_or_ignore,   0, &arg_trust       },
                 { "Remote",  "MaxUse",                 config_parse_iec_uint64,       0, &arg_max_use     },
                 { "Remote",  "MaxFileSize",            config_parse_iec_uint64,       0, &arg_max_size    },
                 { "Remote",  "MaxFiles",               config_parse_uint64,           0, &arg_n_max_files },
@@ -910,17 +911,13 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_TRUST:
 #if HAVE_GNUTLS
-                        if (arg_trust || arg_trust_all)
+                        if (arg_trust)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                       "Confusing trusted CA configuration");
+                                                       "Cannot use --trust more than once");
 
-                        if (streq(optarg, "all"))
-                                arg_trust_all = true;
-                        else {
-                                arg_trust = strdup(optarg);
-                                if (!arg_trust)
-                                        return log_oom();
-                        }
+                        arg_trust = strdup(optarg);
+                        if (!arg_trust)
+                                return log_oom();
 #else
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                "Option --trust is not available.");
@@ -1025,6 +1022,11 @@ static int parse_argv(int argc, char *argv[]) {
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "For SplitMode=host, output must be a directory.");
 
+        if (STRPTR_IN_SET(arg_trust, "-", "all")) {
+                arg_trust_all = true;
+                arg_trust = mfree(arg_trust);
+        }
+
         log_debug("Full config: SplitMode=%s Key=%s Cert=%s Trust=%s",
                   journal_write_split_mode_to_string(arg_split_mode),
                   strna(arg_key),
index 93f2dff59145384da2a6dd612898ff100868b541..5b845a520ffe391131c17ace2f3754844da72c59 100644 (file)
@@ -20,6 +20,7 @@
 #include "macro.h"
 #include "managed-journal-file.h"
 #include "parse-util.h"
+#include "parse-helpers.h"
 #include "process-util.h"
 #include "socket-util.h"
 #include "stdio-util.h"
index fac90d22a21b1944fe18b3824ca4eebb7dd8238e..cb3420f70ffe33a6f4b1305200cf153ba3103220 100644 (file)
@@ -518,45 +518,6 @@ static int perform_upload(Uploader *u) {
         return update_cursor_state(u);
 }
 
-static int config_parse_path_or_ignore(
-                const char *unit,
-                const char *filename,
-                unsigned line,
-                const char *section,
-                unsigned section_line,
-                const char *lvalue,
-                int ltype,
-                const char *rvalue,
-                void *data,
-                void *userdata) {
-
-        _cleanup_free_ char *n = NULL;
-        bool fatal = ltype;
-        char **s = ASSERT_PTR(data);
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue))
-                goto finalize;
-
-        n = strdup(rvalue);
-        if (!n)
-                return log_oom();
-
-        if (streq(n, "-"))
-                goto finalize;
-
-        r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE | (fatal ? PATH_CHECK_FATAL : 0), unit, filename, line, lvalue);
-        if (r < 0)
-                return fatal ? -ENOEXEC : 0;
-
-finalize:
-        return free_and_replace(*s, n);
-}
-
 static int parse_config(void) {
         const ConfigTableItem items[] = {
                 { "Upload",  "URL",                    config_parse_string,         CONFIG_PARSE_STRING_SAFE, &arg_url                  },
index e09797bbf1c3fad8f1cde2b3da18902a1eeebf0f..f48baf7146e71f91a9de0b723fc46e37feb22435 100644 (file)
@@ -196,3 +196,42 @@ int parse_socket_bind_item(
         *port_min = mn;
         return 0;
 }
+
+int config_parse_path_or_ignore(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        _cleanup_free_ char *n = NULL;
+        bool fatal = ltype;
+        char **s = ASSERT_PTR(data);
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue))
+                goto finalize;
+
+        n = strdup(rvalue);
+        if (!n)
+                return log_oom();
+
+        if (streq(n, "-"))
+                goto finalize;
+
+        r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE | (fatal ? PATH_CHECK_FATAL : 0), unit, filename, line, lvalue);
+        if (r < 0)
+                return fatal ? -ENOEXEC : 0;
+
+finalize:
+        return free_and_replace(*s, n);
+}
index 49da2815fb221125addbe5e5cf470fe00dd7429e..38a47e85c339e8f03f4ad8dc2722a25bf4950afc 100644 (file)
@@ -23,3 +23,15 @@ int parse_socket_bind_item(
         int *ip_protocol,
         uint16_t *nr_ports,
         uint16_t *port_min);
+
+int config_parse_path_or_ignore(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata);