]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Global: Further #49 cleanup
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 24 Jun 2021 17:44:55 +0000 (12:44 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 24 Jun 2021 19:05:32 +0000 (14:05 -0500)
src/http/http.c
src/http/http.h
src/log.c
src/main.c
src/object/tal.c
src/rrdp/rrdp_parser.c
src/rsync/rsync.c
test/Makefile.am
test/http_test.c [deleted file]
test/impersonator.c

index 793d9826244e1fb5a7cd5148f1216411f18f152c..b8bd79dde766e89e75557f7829b3b6d5916e9a37 100644 (file)
@@ -141,7 +141,7 @@ curl_err_string(struct http_handler *handler, CURLcode res)
  */
 static int
 http_fetch(struct http_handler *handler, char const *uri, long *response_code,
-    long *cond_met, bool log_operation, FILE *file, bool is_ta)
+    long *cond_met, bool log_operation, FILE *file)
 {
        CURLcode res, res2;
        long unmet = 0;
@@ -150,6 +150,7 @@ http_fetch(struct http_handler *handler, char const *uri, long *response_code,
        setopt_str(handler->curl, CURLOPT_URL, uri);
        setopt_writedata(handler->curl, file);
 
+       pr_val_debug("HTTP GET: %s", uri);
        res = curl_easy_perform(handler->curl);
 
        res2 = curl_easy_getinfo(handler->curl, CURLINFO_RESPONSE_CODE,
@@ -205,17 +206,15 @@ http_fetch(struct http_handler *handler, char const *uri, long *response_code,
                return 0;
        }
 
-       if (*response_code >= HTTP_BAD_REQUEST) {
+       if (*response_code >= HTTP_BAD_REQUEST)
                return pr_val_err("Error requesting URL %s (received HTTP code %ld): %s",
                    uri, *response_code, curl_err_string(handler, res));
-       }
 
        pr_val_err("Error requesting URL %s: %s", uri,
            curl_err_string(handler, res));
-       if (log_operation) {
+       if (log_operation)
                pr_op_err("Error requesting URL %s: %s", uri,
                    curl_err_string(handler, res));
-       }
 
        return EREQFAILED;
 }
@@ -228,7 +227,7 @@ http_easy_cleanup(struct http_handler *handler)
 
 static int
 __http_download_file(struct rpki_uri *uri, long *response_code, long ims_value,
-    long *cond_met, bool log_operation, bool is_ta)
+    long *cond_met, bool log_operation)
 {
        char const *tmp_suffix = "_tmp";
        struct http_handler handler;
@@ -280,10 +279,9 @@ __http_download_file(struct rpki_uri *uri, long *response_code, long ims_value,
                            CURL_TIMECOND_IFMODSINCE);
                }
                error = http_fetch(&handler, uri_get_global(uri), response_code,
-                   cond_met, log_operation, out, is_ta);
-               if (error != EREQFAILED) {
+                   cond_met, log_operation, out);
+               if (error != EREQFAILED)
                        break; /* Note: Usually happy path */
-               }
 
                if (retries == config_get_http_retry_count()) {
                        pr_val_warn("Max HTTP retries (%u) reached requesting for '%s', won't retry again.",
@@ -333,12 +331,12 @@ release_tmp:
  * request to the server failed.
  */
 int
-http_download_file(struct rpki_uri *uri, bool log_operation, bool is_ta)
+http_download_file(struct rpki_uri *uri, bool log_operation)
 {
        long response;
        long cond_met;
        return __http_download_file(uri, &response, 0, &cond_met,
-           log_operation, is_ta);
+           log_operation);
 }
 
 /*
@@ -363,7 +361,7 @@ http_download_file_with_ims(struct rpki_uri *uri, long value,
        int error;
 
        error = __http_download_file(uri, &response, value, &cond_met,
-           log_operation, false);
+           log_operation);
        if (error)
                return error;
 
@@ -394,7 +392,7 @@ http_download_file_with_ims(struct rpki_uri *uri, long value,
         */
 
        return __http_download_file(uri, &response, 0, &cond_met,
-           log_operation, false);
+           log_operation);
 
 }
 
@@ -438,7 +436,7 @@ http_direct_download(char const *remote, char const *dest)
        response_code = 0;
        cond_met = 0;
        error = http_fetch(&handler, remote, &response_code, &cond_met, true,
-           out, false);
+           out);
        http_easy_cleanup(&handler);
        file_close(out);
        if (error)
index 8cb3b0efe873a217bd52e669865de65bddd3833e..717119d90c969e78763982e559ff102d8b5e8b9d 100644 (file)
@@ -9,7 +9,7 @@
 int http_init(void);
 void http_cleanup(void);
 
-int http_download_file(struct rpki_uri *, bool, bool);
+int http_download_file(struct rpki_uri *, bool);
 int http_download_file_with_ims(struct rpki_uri *, long, bool);
 
 int http_direct_download(char const *, char const *);
index 83293e43ff3d0127aee77a7f0e71a48383055bd0..1c54a10de5274834a007ac15f16817dc446075f7 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -204,9 +204,9 @@ log_setup(void)
 
        DBG.stream = stdout;
        INF.stream = stdout;
-       WRN.stream = stdout;
-       ERR.stream = stdout;
-       CRT.stream = stdout;
+       WRN.stream = stderr;
+       ERR.stream = stderr;
+       CRT.stream = stderr;
        UNK.stream = stdout;
 
        openlog("fort", LOG_CONS | LOG_PID, LOG_DAEMON);
@@ -608,6 +608,9 @@ val_crypto_err(const char *format, ...)
 int
 pr_enomem(void)
 {
+       static char const *ENOMEM_MSG = "Out of memory.\n";
+       ssize_t garbage;
+
        /*
         * I'm not using PR_SIMPLE and friends, because those allocate.
         * We want to minimize allocations after a memory allocation failure.
@@ -616,15 +619,21 @@ pr_enomem(void)
        if (LOG_ERR > op_config.level)
                return -ENOMEM;
 
-       if (op_config.syslog_enabled) {
+       if (op_config.fprintf_enabled) {
                lock_mutex();
-               syslog(LOG_ERR | op_config.facility, "Out of memory.");
+               /*
+                * write() is AS-Safe, which implies it doesn't allocate,
+                * unlike printf().
+                */
+               garbage = write(STDERR_FILENO, ENOMEM_MSG, strlen(ENOMEM_MSG));
                unlock_mutex();
+               garbage++;
        }
 
-       if (op_config.fprintf_enabled) {
+       if (op_config.syslog_enabled) {
                lock_mutex();
-               fprintf(stderr, "Out of memory.\n");
+               /* This allocates, but I don't think I have more options. */
+               syslog(LOG_ERR | op_config.facility, "Out of memory.");
                unlock_mutex();
        }
 
index e60d1491090f0d14b9d5673cec18131584435f12..89cda3113c96d5d4c5d17b86b3403b057ce1d49f 100644 (file)
@@ -40,9 +40,6 @@ main(int argc, char **argv)
        if (error)
                goto just_quit;
 
-       /* TODO (issue49) don't forget to improve this. */
-       pr_op_info("Fort 1.5.0.2");
-
        error = thvar_init();
        if (error)
                goto revert_log;
index a708151021e83095f3af876aad18fe6653c37ba2..98d58900fa9dd016a60bfc06145ac7756830a81e 100644 (file)
@@ -541,7 +541,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg)
                                return 0; /* Try some other TAL URI */
                        }
                        error = http_download_file(uri,
-                           reqs_errors_log_uri(uri_get_global(uri)), true);
+                           reqs_errors_log_uri(uri_get_global(uri)));
                }
 
                /* Reminder: there's a positive error: EREQFAILED */
@@ -552,7 +552,6 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg)
                            "TAL URI '%s' could not be downloaded.",
                            uri_val_get_printable(uri));
                }
-
        } else {
                /* Look for local files */
                if (!valid_file_or_dir(uri_get_local(uri), true, false,
index 6b59ad15f2a98bd19ce1cd9f42a6331f102ac5dc..e1c4428c7e5aa9d57d21efb9332b22c9e5a9bc1f 100644 (file)
@@ -104,7 +104,7 @@ download_file(struct rpki_uri *uri, long last_update, bool log_operation)
                error = http_download_file_with_ims(uri, last_update,
                    log_operation);
        else
-               error = http_download_file(uri, log_operation, false);
+               error = http_download_file(uri, log_operation);
 
        /*
         * Since distinct files can be downloaded (notification, snapshot,
index bdc7374a46e68378ac85b1dccd89534e1db586ad..8e5d608022d408ab4fd0324bdf20b99153564b93 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h> /* SIGINT, SIGQUIT, etc */
+#include <syslog.h>
 #include <sys/queue.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
@@ -373,6 +374,7 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
        int fork_fds[2][2];
        pid_t child_pid;
        unsigned int retries;
+       unsigned int i;
        int child_status;
        int error;
 
@@ -383,6 +385,12 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
        if (error)
                return error;
 
+       if (log_val_enabled(LOG_DEBUG)) {
+               pr_val_debug("Executing RSYNC:");
+               for (i = 0; i < args_len + 1; i++)
+                       pr_val_debug("    %s", args[i]);
+       }
+
        retries = 0;
        do {
                child_status = 0;
@@ -586,9 +594,8 @@ rsync_download_files(struct rpki_uri *requested_uri, bool is_ta, bool force)
                error = get_rsync_uri(requested_uri, is_ta, &rsync_uri);
        } else {
                error = check_ancestor_error(requested_uri);
-               if (error) {
+               if (error)
                        return error;
-               }
                error = handle_strict_strategy(requested_uri, &rsync_uri);
        }
 
index c353952721e7bea29af9434d03fac2fa8ec9e39f..acba67a624a42209bae8883a3618637ca9791c4a 100644 (file)
@@ -22,7 +22,6 @@ MY_LDADD = ${CHECK_LIBS}
 check_PROGRAMS  = address.test
 check_PROGRAMS += clients.test
 check_PROGRAMS += db_table.test
-check_PROGRAMS += http.test
 check_PROGRAMS += line_file.test
 check_PROGRAMS += pdu_handler.test
 check_PROGRAMS += rsync.test
@@ -44,9 +43,6 @@ clients_test_LDADD = ${MY_LDADD}
 db_table_test_SOURCES = rtr/db/db_table_test.c
 db_table_test_LDADD = ${MY_LDADD}
 
-http_test_SOURCES = http_test.c
-http_test_LDADD = ${MY_LDADD} ${CURL_LIBS}
-
 line_file_test_SOURCES = line_file_test.c
 line_file_test_LDADD = ${MY_LDADD}
 
diff --git a/test/http_test.c b/test/http_test.c
deleted file mode 100644 (file)
index affe932..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#include <check.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include "common.c"
-#include "file.c"
-#include "impersonator.c"
-#include "log.c"
-#include "uri.c"
-#include "http/http.c"
-
-struct response {
-       unsigned char *content;
-       size_t size;
-};
-
-static void
-init_response(struct response *resp)
-{
-       resp->size = 0;
-       resp->content = malloc(sizeof(char));
-}
-
-static size_t
-write_buf_cb(unsigned char *content, size_t size, size_t nmemb, void *arg)
-{
-       struct response *resp = arg;
-       unsigned char *tmp;
-       size_t read = size * nmemb;
-
-       tmp = realloc(resp->content, resp->size + read + 1);
-       if (tmp == NULL)
-               return -EINVAL;
-
-       resp->content = tmp;
-       memcpy(&resp->content[resp->size], content, read);
-       resp->size += read;
-       resp->content[resp->size] = 0;
-
-       return read;
-}
-
-static int
-local_download(char const *url, long *response_code, struct response *resp)
-{
-       struct http_handler handler;
-       long cond;
-       int error;
-
-       cond = 0;
-       error = http_easy_init(&handler);
-       if (error)
-               return error;
-
-       error = http_fetch(&handler, url, response_code, &cond, false,
-           write_buf_cb, resp);
-       http_easy_cleanup(&handler);
-       return error;
-}
-
-START_TEST(http_fetch_normal)
-{
-       struct response resp;
-       long response_code;
-       char const *url = "https://rrdp.ripe.net/notification.xml";
-
-       init_response(&resp);
-       response_code = 0;
-
-       ck_assert_int_eq(http_init(), 0);
-       ck_assert_int_eq(local_download(url, &response_code, &resp), 0);
-       ck_assert_int_gt(resp.size, 0);
-
-       http_cleanup();
-       free(resp.content);
-       if (response_code == 0)
-               ck_abort_msg("NO response code received");
-       else if (response_code >= HTTP_BAD_REQUEST)
-               ck_abort_msg("Received response code %ld", response_code);
-}
-END_TEST
-
-Suite *http_load_suite(void)
-{
-       Suite *suite;
-       TCase *fetch;
-
-       fetch = tcase_create("Fetch");
-       tcase_add_test(fetch, http_fetch_normal);
-       tcase_set_timeout(fetch, 60);
-
-       suite = suite_create("http_test()");
-       suite_add_tcase(suite, fetch);
-
-       return suite;
-}
-
-int main(void)
-{
-       Suite *suite;
-       SRunner *runner;
-       int tests_failed;
-
-       suite = http_load_suite();
-
-       runner = srunner_create(suite);
-       srunner_run_all(runner, CK_NORMAL);
-       tests_failed = srunner_ntests_failed(runner);
-       srunner_free(runner);
-
-       return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
index 6684e2eb1c1a8ca24b41f317980d0ea2cf88786b..a98039b47eabfe123f13eedfd66d474568baae6a 100644 (file)
@@ -67,12 +67,6 @@ config_get_shuffle_tal_uris(void)
        return false;
 }
 
-unsigned int
-config_get_max_cert_depth(void)
-{
-       return 32;
-}
-
 char const *
 config_get_local_repository(void)
 {
@@ -97,49 +91,12 @@ config_get_rsync_priority(void)
        return rsync_priority;
 }
 
-bool
-config_get_http_enabled(void)
-{
-       return false;
-}
-
 unsigned int
 config_get_http_priority(void)
 {
        return http_priority;
 }
 
-bool
-config_get_work_offline(void)
-{
-       return false;
-}
-
-bool
-config_get_color_output(void)
-{
-       return false;
-}
-
-enum filename_format
-config_get_filename_format(void)
-{
-       return FNF_NAME;
-}
-
-char *
-config_get_rsync_program(void)
-{
-       return "rsync";
-}
-
-struct string_array const *
-config_get_rsync_args(bool is_ta)
-{
-       static const struct string_array array = { 0 };
-       return &array;
-}
-
 char const *
 config_get_slurm(void)
 {
@@ -248,49 +205,12 @@ config_get_val_log_facility(void)
        return (3<<3); /* LOG_DAEMON */
 }
 
-unsigned int
-config_get_asn1_decode_max_stack(void)
-{
-       return 4096;
-}
-
 enum incidence_action
 incidence_get_action(enum incidence_id id)
 {
        return INAC_ERROR;
 }
 
-/* Impersonate HTTP config */
-char const *
-config_get_http_user_agent(void)
-{
-       return "fort-test/0.1";
-}
-
-unsigned int
-config_get_http_connect_timeout(void)
-{
-       return 30;
-}
-
-unsigned int
-config_get_http_transfer_timeout(void)
-{
-       return 0;
-}
-
-unsigned int
-config_get_http_idle_timeout(void)
-{
-       return 15;
-}
-
-char const *
-config_get_http_ca_path(void)
-{
-       return NULL;
-}
-
 void
 config_set_rsync_priority(unsigned int value)
 {