From: Alberto Leiva Popper Date: Fri, 10 Nov 2023 00:01:44 +0000 (-0600) Subject: Patch FIXME: Delete existing RPP before expanding snapshot X-Git-Tag: 1.6.0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba1f08cf779fe269d91efc0912a6ee587fd74675;p=thirdparty%2FFORT-validator.git Patch FIXME: Delete existing RPP before expanding snapshot --- diff --git a/src/rrdp.c b/src/rrdp.c index 44f95528..d9103678 100644 --- a/src/rrdp.c +++ b/src/rrdp.c @@ -761,6 +761,15 @@ parse_notification(struct rpki_uri *uri, struct update_notification *result) return error; } +static void +delete_rpp(struct rpki_uri *notif) +{ + char *path = uri_get_rrdp_workspace(notif); + pr_val_debug("Snapshot: Deleting cached RPP '%s'.", path); + file_rm_rf(path); + free(path); +} + static int xml_read_snapshot(xmlTextReaderPtr reader, void *arg) { @@ -812,6 +821,8 @@ handle_snapshot(struct update_notification *notif) struct rpki_uri *uri; int error; + delete_rpp(notif->uri); + uri = notif->snapshot.uri; pr_val_debug("Processing snapshot '%s'.", uri_val_get_printable(uri)); diff --git a/src/types/uri.c b/src/types/uri.c index 6eecbf9b..f6ba998c 100644 --- a/src/types/uri.c +++ b/src/types/uri.c @@ -246,7 +246,7 @@ path_is_dotdots(struct path_parser *parser) { return parser->len == 2 && parser->token[0] == '.' - && parser->token[1] == '.' ; + && parser->token[1] == '.'; } static int @@ -307,6 +307,21 @@ append_guri(struct path_builder *pb, char const *guri, char const *gprefix, return 0; } +static int +get_rrdp_workspace(struct path_builder *pb, struct rpki_uri *notif) +{ + int error; + + error = pb_init_cache(pb, "rrdp"); + if (error) + return error; + + error = append_guri(pb, notif->global, "https://", ENOTHTTPS, true); + if (error) + pb_cleanup(pb); + return error; +} + /* * Maps "rsync://a.b.c/d/e.cer" into "/rsync/a.b.c/d/e.cer". */ @@ -340,15 +355,14 @@ map_caged(struct rpki_uri *uri, struct rpki_uri *notif) struct path_builder pb; int error; - error = pb_init_cache(&pb, "rrdp"); - if (error) - return error; - error = append_guri(&pb, notif->global, "https://", ENOTHTTPS, true); + error = get_rrdp_workspace(&pb, notif); if (error) return error; error = append_guri(&pb, uri->global, "rsync://", ENOTRSYNC, true); - if (error) + if (error) { + pb_cleanup(&pb); return error; + } uri->local = pb.string; return 0; @@ -569,6 +583,13 @@ uri_op_get_printable(struct rpki_uri *uri) return uri_get_printable(uri, format); } +char * +uri_get_rrdp_workspace(struct rpki_uri *notif) +{ + struct path_builder pb; + return (get_rrdp_workspace(&pb, notif) == 0) ? pb.string : NULL; +} + DEFINE_ARRAY_LIST_FUNCTIONS(uri_list, struct rpki_uri *, static) void diff --git a/src/types/uri.h b/src/types/uri.h index 493fb018..a026a66e 100644 --- a/src/types/uri.h +++ b/src/types/uri.h @@ -48,6 +48,8 @@ bool uri_is_https(struct rpki_uri *); char const *uri_val_get_printable(struct rpki_uri *); char const *uri_op_get_printable(struct rpki_uri *); +char *uri_get_rrdp_workspace(struct rpki_uri *); + /* Plural */ DEFINE_ARRAY_LIST_STRUCT(uri_list, struct rpki_uri *);