12
#include "packfile.h"
13
#include "environment.h"
14
#include "url.h"
15
+#include "urlmatch.h"
16
#include "version.h"
17
18
struct promisor_remote_config {
658
return false;
659
}
660
661
+struct allowed_url {
662
+ char *remote_name;
663
+ char *url_pattern;
664
+ struct url_info pattern_info;
665
+};
666
+
667
+static void allowed_url_free(void *util, const char *str UNUSED)
668
+{
669
+ struct allowed_url *allowed = util;
670
+
671
+ if (!allowed)
672
+ return;
673
+
674
+ /* Depending on prefix, free either remote_name or url_pattern */
675
+ free(allowed->remote_name ? allowed->remote_name : allowed->url_pattern);
676
+ free(allowed->pattern_info.url);
677
+ free(allowed);
678
+}
679
+
680
+static struct allowed_url *valid_accept_url(const char *url)
681
+{
682
+ char *dup, *p;
683
+ struct allowed_url *allowed;
684
+
685
+ if (!url)
686
+ return NULL;
687
+
688
+ dup = xstrdup(url);
689
+ p = strchr(dup, '=');
690
+ if (p) {
691
+ *p = '\0';
692
+ if (!valid_remote_name(dup)) {
693
+ warning(_("invalid remote name '%s' before '=' sign "
694
+ "in '%s' from promisor.acceptFromServerUrl config"),
695
+ dup, url);
696
+ free(dup);
697
+ return NULL;
698
+ }
699
+ p++;
700
+ } else {
701
+ p = dup;
702
+ }
703
+
704
+ if (has_control_char(p)) {
705
+ warning(_("invalid url pattern '%s' "
706
+ "in '%s' from promisor.acceptFromServerUrl config"), p, url);
707
+ free(dup);
708
+ return NULL;
709
+ }
710
+
711
+ allowed = xmalloc(sizeof(*allowed));
712
+ allowed->remote_name = (p == dup) ? NULL : dup;
713
+ allowed->url_pattern = p;
714
+ allowed->pattern_info.url = url_normalize_pattern(p, &allowed->pattern_info);
715
+ if (!allowed->pattern_info.url) {
716
+ warning(_("invalid url pattern '%s' "
717
+ "in '%s' from promisor.acceptFromServerUrl config"), p, url);
718
+ free(dup);
719
+ free(allowed);
720
+ return NULL;
721
+ }
722
+
723
+ return allowed;
724
+}
725
+
726
+static void load_accept_from_server_url(struct repository *repo,
727
+ struct string_list *accept_urls)
728
+{
729
+ const struct string_list *config_urls;
730
+
731
+ if (!repo_config_get_string_multi(repo, "promisor.acceptfromserverurl", &config_urls)) {
732
+ struct string_list_item *item;
733
+
734
+ for_each_string_list_item(item, config_urls) {
735
+ struct allowed_url *allowed = valid_accept_url(item->string);
736
+ if (allowed) {
737
+ struct string_list_item *new;
738
+ new = string_list_append(accept_urls, item->string);
739
+ new->util = allowed;
740
+ }
741
+ }
742
+ }
743
+}
744
+
745
static int should_accept_remote(enum accept_promisor accept,
746
struct promisor_info *advertised,
747
struct string_list *config_info)
986
struct string_list_item *item;
987
bool reload_config = false;
988
enum accept_promisor accept = accept_from_server(repo);
989
+ struct string_list accept_urls = STRING_LIST_INIT_DUP;
990
+
991
+ /* Load and validate the acceptFromServerUrl config */
992
+ load_accept_from_server_url(repo, &accept_urls);
993
994
if (accept == ACCEPT_NONE)
995
return;
1023
}
1024
}
1025
1026
+ string_list_clear_func(&accept_urls, allowed_url_free);
1027
promisor_info_list_clear(&config_info);
1028
string_list_clear(&remote_info, 0);
1029
store_info_free(store_info);