Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/remote.c b/remote.c
index 404e1e0a0d..5824b08eb5 100644
--- a/remote.c
+++ b/remote.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "config.h"
#include "remote.h"
+#include "urlmatch.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"
@@ -617,6 +618,50 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push)
return NULL;
}
+static void validate_remote_url(struct remote *remote)
+{
+ int i;
+ const char *value;
+ struct strbuf redacted = STRBUF_INIT;
+ int warn_not_die;
+
+ if (git_config_get_string_tmp("fetch.credentialsinurl", &value))
+ return;
+
+ if (!strcmp("warn", value))
+ warn_not_die = 1;
+ else if (!strcmp("die", value))
+ warn_not_die = 0;
+ else if (!strcmp("allow", value))
+ return;
+ else
+ die(_("unrecognized value fetch.credentialsInURL: '%s'"), value);
+
+ for (i = 0; i < remote->url_nr; i++) {
+ struct url_info url_info = { 0 };
+
+ if (!url_normalize(remote->url[i], &url_info) ||
+ !url_info.passwd_off)
+ goto loop_cleanup;
+
+ strbuf_reset(&redacted);
+ strbuf_add(&redacted, url_info.url, url_info.passwd_off);
+ strbuf_addstr(&redacted, "<redacted>");
+ strbuf_addstr(&redacted,
+ url_info.url + url_info.passwd_off + url_info.passwd_len);
+
+ if (warn_not_die)
+ warning(_("URL '%s' uses plaintext credentials"), redacted.buf);
+ else
+ die(_("URL '%s' uses plaintext credentials"), redacted.buf);
+
+loop_cleanup:
+ free(url_info.url);
+ }
+
+ strbuf_release(&redacted);
+}
+
static struct remote *
remotes_remote_get_1(struct remote_state *remote_state, const char *name,
const char *(*get_default)(struct remote_state *,
@@ -642,6 +687,9 @@ remotes_remote_get_1(struct remote_state *remote_state, const char *name,
add_url_alias(remote_state, ret, name);
if (!valid_remote(ret))
return NULL;
+
+ validate_remote_url(ret);
+
return ret;
}