pb->string = malloc(INITIAL_CAPACITY);
pb->len = 0;
pb->capacity = INITIAL_CAPACITY;
- pb->error = (pb->string != NULL) ? pr_enomem() : 0;
-}
-
-static void
-fail(struct path_builder *pb, int error)
-{
- free(pb->string);
- pb->error = error;
+ pb->error = (pb->string != NULL) ? 0 : pr_enomem();
}
static void
total_len = pb->len + addend_len;
if (total_len > pb->capacity) {
if (total_len > MAX_CAPACITY) {
- fail(pb, pr_val_err("Path too long: %zu > %u characters.",
- total_len, MAX_CAPACITY));
+ free(pb->string);
+ pb->error = pr_val_err("Path too long: %zu > %u characters.",
+ total_len, MAX_CAPACITY);
return;
}
pb->capacity = total_len;
pb->string = realloc(pb->string, pb->capacity);
if (pb->string == NULL) {
- fail(pb, pr_enomem());
+ pb->error = pr_enomem();
return;
}
}
for (i = 0; i < mft->fileList.list.count; i++) {
fah = mft->fileList.list.array[i];
- /* TODO (aaaa) where's the file validation? */
error = uri_create_mft(mft_uri, &fah->file, &uri);
if (error)
goto fail;
ctx.notification = notification;
ctx.expected_serial = deltas->serial;
- error = relax_ng_parse(uri, xml_read_delta, &ctx);
+ error = relax_ng_parse(uri_get_local(uri), xml_read_delta, &ctx);
pop: fnstack_pop();
pr_val_debug("}");
{
int error;
- error = relax_ng_parse(notification->uri, xml_read_notification,
- notification);
+ error = relax_ng_parse(uri_get_local(notification->uri),
+ xml_read_notification, notification);
if (error)
return error;
if (error)
goto pop;
- error = relax_ng_parse(uri, xml_read_snapshot, notification);
+ error = relax_ng_parse(uri_get_local(uri), xml_read_snapshot,
+ notification);
pop: fnstack_pop();
pr_val_debug("}");
return 0;
}
+static bool
+is_valid_mft_file_chara(uint8_t chara)
+{
+ return ('a' <= chara && chara <= 'z')
+ || ('A' <= chara && chara <= 'Z')
+ || ('0' <= chara && chara <= '9')
+ || (chara == '-')
+ || (chara == '_');
+}
+
+/* RFC 6486bis, section 4.2.2 */
+static int
+validate_mft_file(IA5String_t *ia5)
+{
+ size_t dot;
+ size_t i;
+
+ if (ia5->size < 5)
+ return pr_val_err("File name is too short (%zu < 5).", ia5->size);
+ dot = ia5->size - 4;
+ if (ia5->buf[dot] != '.')
+ return pr_val_err("File name seems to lack a three-letter extension.");
+
+ for (i = 0; i < ia5->size; i++) {
+ if (i != dot && !is_valid_mft_file_chara(ia5->buf[i])) {
+ return pr_val_err("File name contains illegal character #%u",
+ ia5->buf[i]);
+ }
+ }
+
+ /*
+ * Actual extension doesn't matter; if there's no handler,
+ * we'll naturally ignore the file.
+ */
+ return 0;
+}
+
static int
create_neighbor(char const *prefix, IA5String_t *suffix, char **result)
{
char *global;
int error;
+ error = validate_mft_file(file);
+ if (error)
+ return error;
+
error = create_neighbor(uri_get_global(mft), file, &global);
if (error)
return error;
* parsed using @cb (will receive @arg as argument).
*/
int
-relax_ng_parse(struct rpki_uri *uri, xml_read_cb cb, void *arg)
+relax_ng_parse(char const *path, xml_read_cb cb, void *arg)
{
xmlTextReaderPtr reader;
xmlRelaxNGValidCtxtPtr rngvalidctx;
int read;
int error;
- reader = xmlNewTextReaderFilename(uri_get_local(uri));
- if (reader == NULL) {
- return pr_val_err("Couldn't get XML '%s' file.",
- uri_get_local(uri));
- }
+ reader = xmlNewTextReaderFilename(path);
+ if (reader == NULL)
+ return pr_val_err("Couldn't get XML '%s' file.", path);
error = xmlTextReaderRelaxNGSetSchema(reader, schema);
if (error) {
#include <libxml/xmlreader.h>
#include <string.h>
-#include "types/uri.h"
/*
* Schema obtained from RFC 8182, converted using the tool rnc2rng
void relax_ng_cleanup(void);
typedef int (*xml_read_cb)(xmlTextReaderPtr, void *);
-int relax_ng_parse(struct rpki_uri *, xml_read_cb cb, void *);
+int relax_ng_parse(char const *, xml_read_cb cb, void *);
int xml_parse_long(xmlTextReaderPtr, char const *, unsigned long *);
check_PROGRAMS += line_file.test
check_PROGRAMS += pdu_handler.test
check_PROGRAMS += rrdp_objects.test
-check_PROGRAMS += rsync.test
check_PROGRAMS += serial.test
check_PROGRAMS += tal.test
check_PROGRAMS += thread_pool.test
rrdp_objects_test_SOURCES = rrdp_objects_test.c
rrdp_objects_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} ${XML2_LIBS}
-rsync_test_SOURCES = rsync_test.c
-rsync_test_LDADD = ${MY_LDADD}
-
serial_test_SOURCES = types/serial_test.c
serial_test_LDADD = ${MY_LDADD}
#include "impersonator.c"
#include "log.c"
#include "rrdp/notification.c"
+#include "rrdp/types.c"
+#include "types/uri.c"
+#include "data_structure/path_builder.c"
#define END 0xFFFF
+int
+relax_ng_parse(char const *path, xml_read_cb cb, void *arg)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+long
+file_get_modification_time(char const *luri)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+int
+http_get(struct rpki_uri *uri, long ims)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+int
+xml_parse_long(xmlTextReaderPtr reader, char const *attr, unsigned long *result)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+int
+hash_validate_file(char const *algorithm, struct rpki_uri *uri,
+ unsigned char const *expected, size_t expected_len)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+int
+create_dir_recursive(char const *path)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+int
+base64_decode(BIO *in, unsigned char *out, bool has_nl, size_t out_len,
+ size_t *out_written)
+{
+ pr_crit("Not supposed to be called.");
+}
+
static void
add_serials(struct rrdp_notification_deltas *deltas, ...)
{
{
struct rrdp_notification_deltas deltas;
- deltas_head_init(&deltas);
+ rrdp_notification_deltas_init(&deltas);
ck_assert_int_eq(0, deltas_head_sort(&deltas, 0));
ck_assert_int_eq(0, deltas_head_sort(&deltas, 1));
ck_assert_int_eq(0, deltas_head_sort(&deltas, 2));
ck_assert_int_eq(-EINVAL, deltas_head_sort(&deltas, 4));
ck_assert_int_eq(-EINVAL, deltas_head_sort(&deltas, 2));
- deltas_head_cleanup(&deltas, NULL);
- deltas_head_init(&deltas);
+ rrdp_notification_deltas_cleanup(&deltas, NULL);
+ rrdp_notification_deltas_init(&deltas);
add_serials(&deltas, 3, 0, 1, 2, END);
ck_assert_int_eq(0, deltas_head_sort(&deltas, 3));
validate_serials(&deltas, 0, 1, 2, 3, END);
- deltas_head_cleanup(&deltas, NULL);
- deltas_head_init(&deltas);
+ rrdp_notification_deltas_cleanup(&deltas, NULL);
+ rrdp_notification_deltas_init(&deltas);
add_serials(&deltas, 4, 3, 2, 1, 0, END);
ck_assert_int_eq(0, deltas_head_sort(&deltas, 4));
ck_assert_int_eq(-EINVAL, deltas_head_sort(&deltas, 5));
ck_assert_int_eq(-EINVAL, deltas_head_sort(&deltas, 3));
- deltas_head_cleanup(&deltas, NULL);
+ rrdp_notification_deltas_cleanup(&deltas, NULL);
}
END_TEST
+++ /dev/null
-#include <check.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include "common.c"
-#include "log.c"
-#include "impersonator.c"
-#include "str_token.c"
-#include "types/uri.c"
-#include "rsync/rsync.c"
-
-
-struct validation *
-state_retrieve(void)
-{
- return NULL;
-}
-
-static void
-assert_descendant(bool expected, char *ancestor, char *descendant)
-{
- struct rpki_uri *ancestor_uri;
- struct rpki_uri *descendant_uri;
-
- ck_assert_int_eq(0, uri_create_rsync(&ancestor_uri, ancestor));
- ck_assert_int_eq(0, uri_create_rsync(&descendant_uri, descendant));
-
- ck_assert_int_eq(is_descendant(ancestor_uri, descendant_uri), expected);
-
- uri_refput(ancestor_uri);
- uri_refput(descendant_uri);
-}
-
-START_TEST(rsync_test_prefix_equals)
-{
- char *ancestor;
-
- ancestor = "rsync://a/b/c";
- assert_descendant(true, ancestor, "rsync://a/b/c");
- assert_descendant(false, ancestor, "rsync://a/b/");
- assert_descendant(true, ancestor, "rsync://a/b/c/c");
- assert_descendant(false, ancestor, "rsync://a/b/cc");
- assert_descendant(false, ancestor, "rsync://a/b/cc/");
-
- ancestor = "rsync://a/b/c/";
- assert_descendant(true, ancestor, "rsync://a/b/c");
- assert_descendant(false, ancestor, "rsync://a/b/");
- assert_descendant(true, ancestor, "rsync://a/b/c/c");
- assert_descendant(false, ancestor, "rsync://a/b/cc");
- assert_descendant(false, ancestor, "rsync://a/b/cc/");
-}
-END_TEST
-
-static void
-__mark_as_downloaded(char *uri_str, struct uri_list *visited_uris)
-{
- struct rpki_uri *uri;
- ck_assert_int_eq(0, uri_create_rsync(&uri, uri_str));
- ck_assert_int_eq(mark_as_downloaded(uri, visited_uris), 0);
- uri_refput(uri);
-}
-
-static void
-assert_downloaded(char *uri_str, struct uri_list *visited_uris, bool expected)
-{
- struct rpki_uri *uri;
- ck_assert_int_eq(0, uri_create_rsync(&uri, uri_str));
- ck_assert_int_eq(is_already_downloaded(uri, visited_uris), expected);
- uri_refput(uri);
-}
-
-START_TEST(rsync_test_list)
-{
- struct uri_list *visited_uris;
-
- ck_assert_int_eq(rsync_create(&visited_uris), 0);
-
- __mark_as_downloaded("rsync://example.foo/repository/", visited_uris);
- __mark_as_downloaded("rsync://example.foo/member_repository/",
- visited_uris);
- __mark_as_downloaded("rsync://example.foz/repository/", visited_uris);
- __mark_as_downloaded("rsync://example.boo/repo/", visited_uris);
- __mark_as_downloaded("rsync://example.potato/rpki/", visited_uris);
-
- assert_downloaded("rsync://example.foo/repository/", visited_uris,
- true);
- assert_downloaded("rsync://example.foo/repository/abc/cdfg",
- visited_uris, true);
- assert_downloaded("rsync://example.foo/member_repository/bca",
- visited_uris, true);
- assert_downloaded("rsync://example.boo/repository/", visited_uris,
- false);
- assert_downloaded("rsync://example.potato/repository/", visited_uris,
- false);
- assert_downloaded("rsync://example.potato/rpki/abc/", visited_uris,
- true);
-
- rsync_destroy(visited_uris);
-}
-END_TEST
-
-static void
-test_root_strategy(char *test, char *expected)
-{
- struct rpki_uri *src;
- struct rpki_uri *dst;
-
- ck_assert_int_eq(0, uri_create_rsync(&src, test));
- ck_assert_int_eq(handle_root_strategy(src, &dst), 0);
- ck_assert_str_eq(uri_get_global(dst), expected);
-
- uri_refput(src);
- uri_refput(dst);
-}
-
-START_TEST(rsync_test_get_prefix)
-{
- test_root_strategy("rsync://www.example1.com/test/foo/",
- "rsync://www.example1.com/test");
- test_root_strategy("rsync://www.example1.com/test/foo/bar",
- "rsync://www.example1.com/test");
- test_root_strategy("rsync://www.example1.com/test/",
- "rsync://www.example1.com/test");
- test_root_strategy("rsync://www.example1.com/test",
- "rsync://www.example1.com/test");
- test_root_strategy("rsync://www.example1.com",
- "rsync://www.example1.com");
- test_root_strategy("rsync://w", "rsync://w");
- test_root_strategy("rsync://", "rsync://");
-}
-END_TEST
-
-Suite *rsync_load_suite(void)
-{
- Suite *suite;
- TCase *prefix_equals, *uri_list, *test_get_prefix;
-
- prefix_equals = tcase_create("PrefixEquals");
- tcase_add_test(prefix_equals, rsync_test_prefix_equals);
-
- uri_list = tcase_create("uriList");
- tcase_add_test(uri_list, rsync_test_list);
-
- test_get_prefix = tcase_create("test_get_prefix");
- tcase_add_test(test_get_prefix, rsync_test_get_prefix);
-
- suite = suite_create("rsync_test()");
- suite_add_tcase(suite, prefix_equals);
- suite_add_tcase(suite, uri_list);
- suite_add_tcase(suite, test_get_prefix);
-
- return suite;
-}
-
-int main(void)
-{
- Suite *suite;
- SRunner *runner;
- int tests_failed;
-
- suite = rsync_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;
-}
#include "impersonator.c"
#include "line_file.c"
#include "log.c"
-#include "state.h"
-#include "str_token.c"
-#include "random.c"
#include "types/uri.c"
+#include "types/uri_list.c"
+#include "data_structure/path_builder.c"
#include "crypto/base64.c"
-#include "rsync/rsync.c"
-#include "thread/thread_pool.c"
/* Impersonate functions that won't be utilized by tests */
int
-validation_prepare(struct validation **out, struct tal *tal,
- struct validation_handler *validation_handler)
+http_get(struct rpki_uri *uri, long ims)
{
- return 0;
+ pr_crit("Not supposed to be called.");
}
int
-certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
+rsync_download_files(struct rpki_uri *uri, bool is_file)
{
- return -EINVAL;
+ pr_crit("Not supposed to be called.");
}
-enum pubkey_state
-validation_pubkey_state(struct validation *state)
+int
+rrdp_update(struct rpki_uri *uri)
{
- return PKS_INVALID;
+ pr_crit("Not supposed to be called.");
}
-void
-validation_destroy(struct validation *state)
+int
+validation_prepare(struct tal *tal,
+ struct validation_handler *validation_handler)
{
- /* Nothing to destroy */
+ pr_crit("Not supposed to be called.");
}
int
-process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
- process_file_cb cb, void *arg)
+certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
+{
+ pr_crit("Not supposed to be called.");
+}
+
+enum pubkey_state
+validation_pubkey_state(struct validation *state)
{
- return 0;
+ pr_crit("Not supposed to be called.");
}
void
-close_thread(pthread_t thread, char const *what)
+validation_destroy(struct validation *state)
{
- /* Nothing to close */
+ pr_crit("Not supposed to be called.");
}
int
-autocomplete_local_rsync(char const *uri, char const *uri_prefix, char const *workspace,
- char **result)
+process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
+ process_file_cb cb, void *arg)
{
- /* These tests focus on global URIs, so set a dummy value */
- *result = strdup("dummy");
- if (*result == NULL)
- return -ENOMEM;
- return 0;
+ pr_crit("Not supposed to be called.");
}
void
fnstack_init(void)
{
- /* Empty */
+ pr_crit("Not supposed to be called.");
}
void
fnstack_cleanup(void)
{
- /* Empty */
+ pr_crit("Not supposed to be called.");
}
void
fnstack_pop(void)
{
- /* Empty */
+ pr_crit("Not supposed to be called.");
}
void
fnstack_push(char const *file)
{
- /* Empty */
-}
-
-struct validation *
-state_retrieve(void)
-{
- return NULL;
-}
-
-void
-db_rrdp_reset_visited_tals(void)
-{
- /* Empty */
+ pr_crit("Not supposed to be called.");
}
void
-db_rrdp_rem_nonvisited_tals(void)
+thread_pool_wait(struct thread_pool *pool)
{
- /* Empty */
+ pr_crit("Not supposed to be called.");
}
START_TEST(tal_load_normal)
ck_assert_int_eq(tal_load("tal/lacnic.tal", &tal), 0);
- ck_assert_uint_eq(tal->uris.count, 3);
- ck_assert_str_eq(tal->uris.array[0]->global,
+ ck_assert_uint_eq(tal->ta.len, 3);
+ ck_assert_str_eq(uri_get_global(tal->ta.array[0]),
"rsync://repository.lacnic.net/rpki/lacnic/rta-lacnic-rpki.cer");
- ck_assert_str_eq(tal->uris.array[1]->global, "https://potato");
- ck_assert_str_eq(tal->uris.array[2]->global, "rsync://potato");
+ ck_assert_str_eq(uri_get_global(tal->ta.array[1]), "https://potato");
+ ck_assert_str_eq(uri_get_global(tal->ta.array[2]), "rsync://potato");
ck_assert_uint_eq(ARRAY_LEN(decoded), tal->spki_len);
for (i = 0; i < ARRAY_LEN(decoded); i++)
}
END_TEST
-START_TEST(tal_order_http_first)
-{
- struct tal *tal;
-
- ck_assert_int_eq(tal_load("tal/lacnic.tal", &tal), 0);
-
- config_set_http_priority(60);
- config_set_rsync_priority(50);
- ck_assert_int_eq(tal_order_uris(tal), 0);
-
- ck_assert_str_eq(tal->uris.array[0]->global, "https://potato");
- ck_assert_str_eq(tal->uris.array[1]->global,
- "rsync://repository.lacnic.net/rpki/lacnic/rta-lacnic-rpki.cer");
- ck_assert_str_eq(tal->uris.array[2]->global, "rsync://potato");
-
- tal_destroy(tal);
-}
-END_TEST
-
-START_TEST(tal_order_http_last)
-{
- struct tal *tal;
-
- ck_assert_int_eq(tal_load("tal/lacnic.tal", &tal), 0);
-
- config_set_http_priority(50);
- config_set_rsync_priority(60);
- ck_assert_int_eq(tal_order_uris(tal), 0);
-
- ck_assert_str_eq(tal->uris.array[0]->global,
- "rsync://repository.lacnic.net/rpki/lacnic/rta-lacnic-rpki.cer");
- ck_assert_str_eq(tal->uris.array[1]->global, "rsync://potato");
- ck_assert_str_eq(tal->uris.array[2]->global, "https://potato");
-
- tal_destroy(tal);
-}
-END_TEST
-
Suite *tal_load_suite(void)
{
Suite *suite;
- TCase *core, *order;
+ TCase *core;
core = tcase_create("Core");
tcase_add_test(core, tal_load_normal);
- order = tcase_create("Order");
- tcase_add_test(order, tal_order_http_first);
- tcase_add_test(order, tal_order_http_last);
-
suite = suite_create("tal_load()");
suite_add_tcase(suite, core);
- suite_add_tcase(suite, order);
return suite;
}
#include "log.c"
#include "impersonator.c"
#include "types/uri.c"
+#include "data_structure/path_builder.c"
#define BUFFER_LEN 128
static uint8_t buffer[BUFFER_LEN];