diff options
Diffstat (limited to 'src/journal-remote')
-rw-r--r-- | src/journal-remote/journal-gatewayd.c | 53 | ||||
-rw-r--r-- | src/journal-remote/journal-remote-main.c | 39 | ||||
-rw-r--r-- | src/journal-remote/journal-remote.c | 3 | ||||
-rw-r--r-- | src/journal-remote/journal-upload-journal.c | 2 | ||||
-rw-r--r-- | src/journal-remote/journal-upload.c | 3 | ||||
-rw-r--r-- | src/journal-remote/microhttpd-util.c | 13 | ||||
-rw-r--r-- | src/journal-remote/microhttpd-util.h | 1 |
7 files changed, 53 insertions, 61 deletions
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index 4185af63e1..af45fa549a 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -461,7 +461,7 @@ static int request_handler_entries( struct MHD_Connection *connection, void *connection_cls) { - struct MHD_Response *response; + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL; RequestMeta *m = connection_cls; int r; @@ -503,11 +503,7 @@ static int request_handler_entries( return respond_oom(connection); MHD_add_response_header(response, "Content-Type", mime_types[m->mode]); - - r = MHD_queue_response(connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - - return r; + return MHD_queue_response(connection, MHD_HTTP_OK, response); } static int output_field(FILE *f, OutputMode m, const char *d, size_t l) { @@ -619,7 +615,7 @@ static int request_handler_fields( const char *field, void *connection_cls) { - struct MHD_Response *response; + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL; RequestMeta *m = connection_cls; int r; @@ -642,11 +638,7 @@ static int request_handler_fields( return respond_oom(connection); MHD_add_response_header(response, "Content-Type", mime_types[m->mode == OUTPUT_JSON ? OUTPUT_JSON : OUTPUT_SHORT]); - - r = MHD_queue_response(connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - - return r; + return MHD_queue_response(connection, MHD_HTTP_OK, response); } static int request_handler_redirect( @@ -654,8 +646,7 @@ static int request_handler_redirect( const char *target) { char *page; - struct MHD_Response *response; - int ret; + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL; assert(connection); assert(target); @@ -671,11 +662,7 @@ static int request_handler_redirect( MHD_add_response_header(response, "Content-Type", "text/html"); MHD_add_response_header(response, "Location", target); - - ret = MHD_queue_response(connection, MHD_HTTP_MOVED_PERMANENTLY, response); - MHD_destroy_response(response); - - return ret; + return MHD_queue_response(connection, MHD_HTTP_MOVED_PERMANENTLY, response); } static int request_handler_file( @@ -683,8 +670,7 @@ static int request_handler_file( const char *path, const char *mime_type) { - struct MHD_Response *response; - int ret; + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL; _cleanup_close_ int fd = -1; struct stat st; @@ -702,15 +688,10 @@ static int request_handler_file( response = MHD_create_response_from_fd_at_offset64(st.st_size, fd, 0); if (!response) return respond_oom(connection); - - fd = -1; + TAKE_FD(fd); MHD_add_response_header(response, "Content-Type", mime_type); - - ret = MHD_queue_response(connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - - return ret; + return MHD_queue_response(connection, MHD_HTTP_OK, response); } static int get_virtualization(char **v) { @@ -747,14 +728,13 @@ static int request_handler_machine( struct MHD_Connection *connection, void *connection_cls) { - struct MHD_Response *response; + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL; RequestMeta *m = connection_cls; int r; _cleanup_free_ char* hostname = NULL, *os_name = NULL; uint64_t cutoff_from = 0, cutoff_to = 0, usage = 0; - char *json; sd_id128_t mid, bid; - _cleanup_free_ char *v = NULL; + _cleanup_free_ char *v = NULL, *json = NULL; assert(connection); assert(m); @@ -803,21 +783,16 @@ static int request_handler_machine( usage, cutoff_from, cutoff_to); - if (r < 0) return respond_oom(connection); response = MHD_create_response_from_buffer(strlen(json), json, MHD_RESPMEM_MUST_FREE); - if (!response) { - free(json); + if (!response) return respond_oom(connection); - } + TAKE_PTR(json); MHD_add_response_header(response, "Content-Type", "application/json"); - r = MHD_queue_response(connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - - return r; + return MHD_queue_response(connection, MHD_HTTP_OK, response); } static int request_handler( diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index e1748cb46b..802c3ea608 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -221,16 +221,17 @@ static int process_http_upload( journal_remote_server_global->seal); if (r == -EAGAIN) break; - else if (r < 0) { - log_warning("Failed to process data for connection %p", connection); - if (r == -E2BIG) - return mhd_respondf(connection, - r, MHD_HTTP_PAYLOAD_TOO_LARGE, - "Entry is too large, maximum is " STRINGIFY(DATA_SIZE_MAX) " bytes."); + if (r < 0) { + if (r == -ENOBUFS) + log_warning_errno(r, "Entry is above the maximum of %u, aborting connection %p.", + DATA_SIZE_MAX, connection); + else if (r == -E2BIG) + log_warning_errno(r, "Entry with more fields than the maximum of %u, aborting connection %p.", + ENTRY_FIELD_COUNT_MAX, connection); else - return mhd_respondf(connection, - r, MHD_HTTP_UNPROCESSABLE_ENTITY, - "Processing failed: %m."); + log_warning_errno(r, "Failed to process data, aborting connection %p: %m", + connection); + return MHD_NO; } } @@ -264,6 +265,7 @@ static int request_handler( const char *header; int r, code, fd; _cleanup_free_ char *hostname = NULL; + size_t len; assert(connection); assert(connection_cls); @@ -283,12 +285,27 @@ static int request_handler( if (!streq(url, "/upload")) return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found."); - header = MHD_lookup_connection_value(connection, - MHD_HEADER_KIND, "Content-Type"); + header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Content-Type"); if (!header || !streq(header, "application/vnd.fdo.journal")) return mhd_respond(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE, "Content-Type: application/vnd.fdo.journal is required."); + header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Content-Length"); + if (!header) + return mhd_respond(connection, MHD_HTTP_LENGTH_REQUIRED, + "Content-Length header is required."); + r = safe_atozu(header, &len); + if (r < 0) + return mhd_respondf(connection, r, MHD_HTTP_LENGTH_REQUIRED, + "Content-Length: %s cannot be parsed: %m", header); + + if (len > ENTRY_SIZE_MAX) + /* When serialized, an entry of maximum size might be slightly larger, + * so this does not correspond exactly to the limit in journald. Oh well. + */ + return mhd_respondf(connection, 0, MHD_HTTP_PAYLOAD_TOO_LARGE, + "Payload larger than maximum size of %u bytes", ENTRY_SIZE_MAX); + { const union MHD_ConnectionInfo *ci; diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 3c0916c438..1da32c5f85 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -407,6 +407,9 @@ int journal_remote_handle_raw_source( log_debug("%zu active sources remaining", s->active); return 0; } else if (r == -E2BIG) { + log_notice("Entry with too many fields, skipped"); + return 1; + } else if (r == -ENOBUFS) { log_notice("Entry too big, skipped"); return 1; } else if (r == -EAGAIN) { diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index be39f7c047..7d7e7384bf 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -235,7 +235,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { assert_not_reached("WTF?"); } -static inline void check_update_watchdog(Uploader *u) { +static void check_update_watchdog(Uploader *u) { usec_t after; usec_t elapsed_time; diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 1e08fcc554..ef3556f825 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -9,6 +9,7 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "conf-parser.h" #include "daemon-util.h" #include "def.h" @@ -236,7 +237,7 @@ int start_upload(Uploader *u, easy_setopt(curl, CURLOPT_VERBOSE, 1L, LOG_WARNING, ); easy_setopt(curl, CURLOPT_USERAGENT, - "systemd-journal-upload " PACKAGE_STRING, + "systemd-journal-upload " GIT_VERSION, LOG_WARNING, ); if (arg_key || startswith(u->url, "https://")) { diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index adf40b5abd..5f5691995d 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -32,21 +32,16 @@ static int mhd_respond_internal(struct MHD_Connection *connection, const char *buffer, size_t size, enum MHD_ResponseMemoryMode mode) { - struct MHD_Response *response; - int r; - assert(connection); - response = MHD_create_response_from_buffer(size, (char*) buffer, mode); + _cleanup_(MHD_destroy_responsep) struct MHD_Response *response + = MHD_create_response_from_buffer(size, (char*) buffer, mode); if (!response) return MHD_NO; log_debug("Queueing response %u: %s", code, buffer); MHD_add_response_header(response, "Content-Type", "text/plain"); - r = MHD_queue_response(connection, code, response); - MHD_destroy_response(response); - - return r; + return MHD_queue_response(connection, code, response); } int mhd_respond(struct MHD_Connection *connection, @@ -249,7 +244,7 @@ static int get_auth_dn(gnutls_x509_crt_t client_cert, char **buf) { return 0; } -static inline void gnutls_x509_crt_deinitp(gnutls_x509_crt_t *p) { +static void gnutls_x509_crt_deinitp(gnutls_x509_crt_t *p) { gnutls_x509_crt_deinit(*p); } diff --git a/src/journal-remote/microhttpd-util.h b/src/journal-remote/microhttpd-util.h index 364cd0f7cf..ba51d847e4 100644 --- a/src/journal-remote/microhttpd-util.h +++ b/src/journal-remote/microhttpd-util.h @@ -75,3 +75,4 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn int setup_gnutls_logger(char **categories); DEFINE_TRIVIAL_CLEANUP_FUNC(struct MHD_Daemon*, MHD_stop_daemon); +DEFINE_TRIVIAL_CLEANUP_FUNC(struct MHD_Response*, MHD_destroy_response); |