summaryrefslogtreecommitdiff
path: root/src/util/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/net.c')
-rw-r--r--src/util/net.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/util/net.c b/src/util/net.c
index ac7befe07..dd8a1ba46 100644
--- a/src/util/net.c
+++ b/src/util/net.c
@@ -19,6 +19,50 @@
#define DEFAULT_PORT_GIT "9418"
#define DEFAULT_PORT_SSH "22"
+bool git_net_hostname_matches_cert(
+ const char *hostname,
+ const char *pattern)
+{
+ for (;;) {
+ char c = git__tolower(*pattern++);
+
+ if (c == '\0')
+ return *hostname ? false : true;
+
+ if (c == '*') {
+ c = *pattern;
+
+ /* '*' at the end matches everything left */
+ if (c == '\0')
+ return true;
+
+ /*
+ * We've found a pattern, so move towards the
+ * next matching char. The '.' is handled
+ * specially because wildcards aren't allowed
+ * to cross subdomains.
+ */
+ while(*hostname) {
+ char h = git__tolower(*hostname);
+
+ if (h == c)
+ return git_net_hostname_matches_cert(hostname++, pattern);
+ else if (h == '.')
+ return git_net_hostname_matches_cert(hostname, pattern);
+
+ hostname++;
+ }
+
+ return false;
+ }
+
+ if (c != git__tolower(*hostname++))
+ return false;
+ }
+
+ return false;
+}
+
bool git_net_str_is_url(const char *str)
{
const char *c;