From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 5/6] http: use hostname in credential description
Date: Fri, 14 Oct 2011 09:40:39 +0200 [thread overview]
Message-ID: <f3365a7c54c17c2c53e5204578a3406057e62b5f.1318577792.git.git@drmicha.warpmail.net> (raw)
In-Reply-To: <4E9692BF.8040705@drmicha.warpmail.net>
In-Reply-To: <cover.1318577792.git.git@drmicha.warpmail.net>
Until now, a request for an http password looked like:
Username:
Password:
Now it will look like:
Username for 'example.com':
Password for 'example.com':
Picked-from: Jeff King <peff@peff.net>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
http.c | 41 +++++++++++++++++++++++++++++++++--------
t/t5550-http-fetch.sh | 4 ++--
2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/http.c b/http.c
index 89e3cf4..149e116 100644
--- a/http.c
+++ b/http.c
@@ -42,7 +42,7 @@ static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv;
static const char *curl_http_proxy;
static const char *curl_cookie_file;
-static char *user_name, *user_pass;
+static char *user_name, *user_pass, *description;
static const char *user_agent;
#if LIBCURL_VERSION_NUM >= 0x071700
@@ -139,6 +139,25 @@ static void process_curl_messages(void)
}
#endif
+static char *git_getpass_one(const char *what, const char *desc)
+{
+ struct strbuf prompt = STRBUF_INIT;
+ char *r;
+
+ if (desc)
+ strbuf_addf(&prompt, "%s for '%s': ", what, desc);
+ else
+ strbuf_addf(&prompt, "%s: ", what);
+ /* FIXME: for usernames, we should do something less magical that
+ * actually echoes the characters. However, we need to read from
+ * /dev/tty and not stdio, which is not portable (but getpass will do
+ * it for us). http.c uses the same workaround. */
+ r = git_getpass(prompt.buf);
+
+ strbuf_release(&prompt);
+ return xstrdup(r);
+}
+
static int http_options(const char *var, const char *value, void *cb)
{
if (!strcmp("http.sslverify", var)) {
@@ -214,7 +233,7 @@ static void init_curl_http_auth(CURL *result)
if (user_name) {
struct strbuf up = STRBUF_INIT;
if (!user_pass)
- user_pass = xstrdup(git_getpass("Password: "));
+ user_pass = xstrdup(git_getpass_one("Password", description));
strbuf_addf(&up, "%s:%s", user_name, user_pass);
curl_easy_setopt(result, CURLOPT_USERPWD,
strbuf_detach(&up, NULL));
@@ -229,7 +248,7 @@ static int has_cert_password(void)
return 0;
/* Only prompt the user once. */
ssl_cert_password_required = -1;
- ssl_cert_password = git_getpass("Certificate Password: ");
+ ssl_cert_password = git_getpass_one("Certificate Password", description);
if (ssl_cert_password != NULL) {
ssl_cert_password = xstrdup(ssl_cert_password);
return 1;
@@ -307,7 +326,7 @@ static CURL *get_curl_handle(void)
static void http_auth_init(const char *url)
{
- char *at, *colon, *cp, *slash;
+ const char *at, *colon, *cp, *slash, *host;
cp = strstr(url, "://");
if (!cp)
@@ -323,16 +342,22 @@ static void http_auth_init(const char *url)
at = strchr(cp, '@');
colon = strchr(cp, ':');
slash = strchrnul(cp, '/');
- if (!at || slash <= at)
- return; /* No credentials */
- if (!colon || at <= colon) {
+ if (!at || slash <= at) {
+ /* No credentials, but we may have to ask for some later */
+ host = cp;
+ }
+ else if (!colon || at <= colon) {
/* Only username */
user_name = url_decode_mem(cp, at - cp);
user_pass = NULL;
+ host = at + 1;
} else {
user_name = url_decode_mem(cp, colon - cp);
user_pass = url_decode_mem(colon + 1, at - (colon + 1));
+ host = at + 1;
}
+
+ description = url_decode_mem(host, slash - host);
}
static void set_from_env(const char **var, const char *envname)
@@ -828,7 +853,7 @@ static int http_request(const char *url, void *result, int target, int options)
* but that is non-portable. Using git_getpass() can at least be stubbed
* on other platforms with a different implementation if/when necessary.
*/
- user_name = xstrdup(git_getpass("Username: "));
+ user_name = xstrdup(git_getpass_one("Username", description));
init_curl_http_auth(slot->curl);
ret = HTTP_REAUTH;
}
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index ed4db09..d1ab4d0 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -51,8 +51,8 @@ test_expect_success 'setup askpass helpers' '
GIT_ASKPASS="$PWD/askpass" &&
export GIT_ASKPASS &&
>askpass-expect-none &&
- echo "askpass: Password: " >askpass-expect-pass &&
- { echo "askpass: Username: " &&
+ echo "askpass: Password for '\''$HTTPD_DEST'\'': " >askpass-expect-pass &&
+ { echo "askpass: Username for '\''$HTTPD_DEST'\'': " &&
cat askpass-expect-pass
} >askpass-expect-both
'
--
1.7.7.338.g0156b
next prev parent reply other threads:[~2011-10-14 7:41 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-04 10:19 Git ksshaskpass to play nice with https and kwallet Michael J Gruber
2011-10-04 10:50 ` Jeff King
2011-10-04 11:27 ` Michael J Gruber
2011-10-04 11:37 ` Jeff King
2011-10-04 12:12 ` Michael J Gruber
2011-10-04 12:43 ` Jeff King
2011-10-04 18:49 ` Michael J Gruber
2011-10-05 17:55 ` Jeff King
2011-10-05 18:01 ` Jeff King
2011-10-06 6:33 ` Michael J Gruber
2011-10-06 13:15 ` [RFC/PATCH] remote-curl: Obey passed URL Michael J Gruber
2011-10-06 13:25 ` Jeff King
2011-10-06 13:37 ` Jeff King
2011-10-12 20:51 ` Michael J Gruber
2011-10-12 21:43 ` [PATCH] http_init: accept separate URL parameter Jeff King
2011-10-12 21:46 ` Jeff King
2011-10-12 22:38 ` Junio C Hamano
2011-10-12 22:46 ` Jeff King
2011-10-13 7:26 ` Michael J Gruber
2011-10-14 7:40 ` [PATCH 0/6] http-auth-early Michael J Gruber
2011-10-14 7:40 ` [PATCH 1/6] url: decode buffers that are not NUL-terminated Michael J Gruber
2011-10-14 7:40 ` [PATCH 2/6] improve httpd auth tests Michael J Gruber
2011-10-14 7:40 ` [PATCH 3/6] remote-curl: don't retry auth failures with dumb protocol Michael J Gruber
2011-10-14 7:40 ` [PATCH 4/6] http: retry authentication failures for all http requests Michael J Gruber
2011-10-14 7:40 ` Michael J Gruber [this message]
2011-10-14 7:40 ` [PATCH 6/6] http_init: accept separate URL parameter Michael J Gruber
2011-10-14 13:19 ` [PATCH 0/6] http-auth-early Jeff King
2011-10-14 13:24 ` Michael J Gruber
2011-10-14 18:59 ` Junio C Hamano
2011-10-13 2:06 ` [PATCH] http_init: accept separate URL parameter Tay Ray Chuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f3365a7c54c17c2c53e5204578a3406057e62b5f.1318577792.git.git@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).