X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal-remote%2Fjournal-remote.c;h=36c8e00e6b12b951f2697c95852cb349de4b6462;hb=4d8ddba9d71e51356cc9488f906b8fef89c60c23;hp=e127b0b8008cad81adfbc0310b212336f832aecc;hpb=9ff48d0982fcb97923955685fe9fa4e0e67cb238;p=elogind.git diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index e127b0b80..36c8e00e6 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -52,9 +52,9 @@ #define REMOTE_JOURNAL_PATH "/var/log/journal/remote" -#define KEY_FILE CERTIFICATE_ROOT "/private/journal-remote.pem" -#define CERT_FILE CERTIFICATE_ROOT "/certs/journal-remote.pem" -#define TRUST_FILE CERTIFICATE_ROOT "/ca/trusted.pem" +#define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-remote.pem" +#define CERT_FILE CERTIFICATE_ROOT "/certs/journal-remote.pem" +#define TRUST_FILE CERTIFICATE_ROOT "/ca/trusted.pem" static char* arg_url = NULL; static char* arg_getter = NULL; @@ -149,9 +149,11 @@ static int spawn_getter(const char *getter, const char *url) { _cleanup_strv_free_ char **words = NULL; assert(getter); - words = strv_split_quoted(getter); - if (!words) - return log_oom(); + r = strv_split_quoted(&words, getter); + if (r < 0) { + log_error("Failed to split getter option: %s", strerror(-r)); + return r; + } r = strv_extend(&words, url); if (r < 0) { @@ -793,22 +795,21 @@ static int fd_fd(const char *spec) { r = safe_atoi(spec, &fd); if (r < 0) return r; + if (fd < 0) + return -EINVAL; - return -1; + return fd; } - static int remoteserver_init(RemoteServer *s, const char* key, const char* cert, const char* trust) { int r, n, fd; - const char *output_name = NULL; char **file; assert(s); - if ((arg_listen_raw || arg_listen_http) && trust) { log_error("Option --trust makes all non-HTTPS connections untrusted."); return -EINVAL; @@ -869,8 +870,6 @@ static int remoteserver_init(RemoteServer *s, fd, strerror(-r)); return r; } - - output_name = "socket"; } if (arg_url) { @@ -896,8 +895,6 @@ static int remoteserver_init(RemoteServer *s, r = add_source(s, fd, (char*) hostname, false); if (r < 0) return r; - - output_name = arg_url; } if (arg_listen_raw) { @@ -905,27 +902,23 @@ static int remoteserver_init(RemoteServer *s, r = setup_raw_socket(s, arg_listen_raw); if (r < 0) return r; - - output_name = arg_listen_raw; } if (arg_listen_http) { r = setup_microhttpd_socket(s, arg_listen_http, NULL, NULL, NULL); if (r < 0) return r; - - output_name = arg_listen_http; } if (arg_listen_https) { r = setup_microhttpd_socket(s, arg_listen_https, key, cert, trust); if (r < 0) return r; - - output_name = arg_listen_https; } STRV_FOREACH(file, arg_files) { + const char *output_name; + if (streq(*file, "-")) { log_info("Using standard input as source."); @@ -952,9 +945,6 @@ static int remoteserver_init(RemoteServer *s, return -EINVAL; } - if (!!n + !!arg_url + !!arg_listen_raw + !!arg_files) - output_name = "multiple"; - r = init_writer_hashmap(s); if (r < 0) return r; @@ -1134,16 +1124,11 @@ static int parse_config(void) { { "Remote", "ServerCertificateFile", config_parse_path, 0, &arg_cert }, { "Remote", "TrustedCertificateFile", config_parse_path, 0, &arg_trust }, {}}; - int r; - - r = config_parse(NULL, PKGSYSCONFDIR "/journal-remote.conf", NULL, - "Remote\0", - config_item_table_lookup, items, - false, false, NULL); - if (r < 0) - log_error("Failed to parse configuration file: %s", strerror(-r)); - return r; + return config_parse(NULL, PKGSYSCONFDIR "/journal-remote.conf", NULL, + "Remote\0", + config_item_table_lookup, items, + false, false, true, NULL); } static void help(void) { @@ -1159,7 +1144,7 @@ static void help(void) { " --[no-]compress Use XZ-compression in the output journal (default: yes)\n" " --[no-]seal Use Event sealing in the output journal (default: no)\n" " --key=FILENAME Specify key in PEM format (default:\n" - " \"" KEY_FILE "\")\n" + " \"" PRIV_KEY_FILE "\")\n" " --cert=FILENAME Specify certificate in PEM format (default:\n" " \"" CERT_FILE "\")\n" " --trust=FILENAME|all Specify CA certificate or disable checking (default:\n" @@ -1361,7 +1346,7 @@ static int parse_argv(int argc, char *argv[]) { case ARG_GNUTLS_LOG: { #ifdef HAVE_GNUTLS - char *word, *state; + const char *word, *state; size_t size; FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) { @@ -1385,8 +1370,7 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unknown option code."); } if (optind < argc) @@ -1435,10 +1419,10 @@ static int parse_argv(int argc, char *argv[]) { static int load_certificates(char **key, char **cert, char **trust) { int r; - r = read_full_file(arg_key ?: KEY_FILE, key, NULL); + r = read_full_file(arg_key ?: PRIV_KEY_FILE, key, NULL); if (r < 0) { log_error("Failed to read key from file '%s': %s", - arg_key ?: KEY_FILE, strerror(-r)); + arg_key ?: PRIV_KEY_FILE, strerror(-r)); return r; }