Skip to content

Commit

Permalink
http-push: enable "proactive auth"
Browse files Browse the repository at this point in the history
Before commit 986bbc0, git was proactive about asking for
http passwords. It assumed that if you had a username in
your URL, you would also want a password, and asked for it
before making any http requests.

However, this could interfere with the use of .netrc (see
986bbc0 for details). And it was also unnecessary, since
the http fetching code had learned to recognize an HTTP 401
and prompt the user then. Furthermore, the proactive prompt
could interfere with the usage of .netrc (see 986bbc0 for
details).

Unfortunately, the http push-over-DAV code never learned to
recognize HTTP 401, and so was broken by this change. This
patch does a quick fix of re-enabling the "proactive auth"
strategy only for http-push, leaving the dumb http fetch and
smart-http as-is.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 14, 2011
1 parent 0521710 commit a4ddbc3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion http-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, const char **argv)

git_config(git_default_config, NULL);

http_init(NULL, url);
http_init(NULL, url, 0);
walker = get_http_walker(url);
walker->get_tree = get_tree;
walker->get_history = get_history;
Expand Down
2 changes: 1 addition & 1 deletion http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ int main(int argc, char **argv)

memset(remote_dir_exists, -1, 256);

http_init(NULL, repo->url);
http_init(NULL, repo->url, 1);

#ifdef USE_CURL_MULTI
is_running_queue = 0;
Expand Down
8 changes: 7 additions & 1 deletion http.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static int curl_ftp_no_epsv;
static const char *curl_http_proxy;
static const char *curl_cookie_file;
static char *user_name, *user_pass, *description;
static int http_proactive_auth;
static const char *user_agent;

#if LIBCURL_VERSION_NUM >= 0x071700
Expand Down Expand Up @@ -279,6 +280,9 @@ static CURL *get_curl_handle(void)
curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
#endif

if (http_proactive_auth)
init_curl_http_auth(result);

if (ssl_cert != NULL)
curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
if (has_cert_password())
Expand Down Expand Up @@ -367,7 +371,7 @@ static void set_from_env(const char **var, const char *envname)
*var = val;
}

void http_init(struct remote *remote, const char *url)
void http_init(struct remote *remote, const char *url, int proactive_auth)
{
char *low_speed_limit;
char *low_speed_time;
Expand All @@ -378,6 +382,8 @@ void http_init(struct remote *remote, const char *url)

curl_global_init(CURL_GLOBAL_ALL);

http_proactive_auth = proactive_auth;

if (remote && remote->http_proxy)
curl_http_proxy = xstrdup(remote->http_proxy);

Expand Down
3 changes: 2 additions & 1 deletion http.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ extern void add_fill_function(void *data, int (*fill)(void *));
extern void step_active_slots(void);
#endif

extern void http_init(struct remote *remote, const char *url);
extern void http_init(struct remote *remote, const char *url,
int proactive_auth);
extern void http_cleanup(void);

extern int data_received;
Expand Down
2 changes: 1 addition & 1 deletion remote-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int main(int argc, const char **argv)

url = strbuf_detach(&buf, NULL);

http_init(remote, url);
http_init(remote, url, 0);

do {
if (strbuf_getline(&buf, stdin, '\n') == EOF) {
Expand Down
2 changes: 1 addition & 1 deletion t/t5540-http-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
"$ROOT_PATH"/test_repo_clone master

test_expect_failure 'push to password-protected repository (user in URL)' '
test_expect_success 'push to password-protected repository (user in URL)' '
test_commit pw-user &&
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
git rev-parse --verify HEAD >expect &&
Expand Down

0 comments on commit a4ddbc3

Please sign in to comment.