]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Patch FIXME: Delete existing RPP before expanding snapshot
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 10 Nov 2023 00:01:44 +0000 (18:01 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 10 Nov 2023 00:12:04 +0000 (18:12 -0600)
src/rrdp.c
src/types/uri.c
src/types/uri.h

index 44f9552845e67a81404d86063370f7aceb6dd4c9..d91036787034f40d185649e9bd084acb43d19483 100644 (file)
@@ -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));
index 6eecbf9b2af3a2c7c734ae7f10c5870ac6ba8f06..f6ba998c44416cc8ad1b681c7b72d8549b6db5b8 100644 (file)
@@ -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 "<local-repository>/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
index 493fb01885ae09782036ed3eb814fd13a365da35..a026a66ef57701fdcf4905368bee9f1e3e7bd341 100644 (file)
@@ -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 *);