Skip to content

WIP/RFC remote-vfs transport. #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ ifdef NO_CURL
REMOTE_CURL_PRIMARY =
REMOTE_CURL_ALIASES =
REMOTE_CURL_NAMES =
REMOTE_VFS =
EXCLUDED_PROGRAMS += git-http-fetch git-http-push
else
ifdef CURLDIR
Expand All @@ -1362,8 +1363,11 @@ endif
REMOTE_CURL_PRIMARY = git-remote-http$X
REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES)
REMOTE_VFS = git-remote-vfs$X
PROGRAM_OBJS += http-fetch.o
PROGRAMS += $(REMOTE_CURL_NAMES)
PROGRAMS += $(REMOTE_VFS)
PROGRAM_OBJS += remote-vfs.o
curl_check := $(shell (echo 070908; $(CURL_CONFIG) --vernum | sed -e '/^70[BC]/s/^/0/') 2>/dev/null | sort -r | sed -ne 2p)
ifeq "$(curl_check)" "070908"
ifndef NO_EXPAT
Expand Down Expand Up @@ -2469,6 +2473,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)

$(REMOTE_VFS): remote-vfs.o http.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)

$(LIB_FILE): $(LIB_OBJS)
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^

Expand Down
30 changes: 30 additions & 0 deletions credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,33 @@ void credential_from_url(struct credential *c, const char *url)
*p-- = '\0';
}
}

void credential_init_min_creds(struct credential *c,
const struct credential *src)
{
credential_clear(c);

/*
* Set flags in a contrived way to:
* () prevent "store" and "erase" calls to credential manager.
* () prevent the config from being scanned.
* () prevent the helpers string-list from being loaded.
*/
c->approved = 1;
c->configured = 1;

// TODO what to do about use_http_path?

#define CP(f) do { \
if (src->f && *src->f) \
c->f = xstrdup(src->f); \
} while (0)

CP(username);
CP(password);
CP(protocol);
CP(host);
CP(path);

#undef CP
}
3 changes: 3 additions & 0 deletions credential.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct credential {
void credential_init(struct credential *);
void credential_clear(struct credential *);

void credential_init_min_creds(struct credential *,
const struct credential *src);

void credential_fill(struct credential *);
void credential_approve(struct credential *);
void credential_reject(struct credential *);
Expand Down
29 changes: 27 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ static void init_curl_http_auth(CURL *result)
credential_fill(&http_auth);

#if LIBCURL_VERSION_NUM >= 0x071301
trace2_printf("u:p %s %s",
http_auth.username, http_auth.password);
curl_easy_setopt(result, CURLOPT_USERNAME, http_auth.username);
curl_easy_setopt(result, CURLOPT_PASSWORD, http_auth.password);
#else
Expand Down Expand Up @@ -1842,7 +1844,7 @@ static void http_opt_request_remainder(CURL *curl, off_t pos)
/* http_request() targets */
#define HTTP_REQUEST_STRBUF 0
#define HTTP_REQUEST_FILE 1

static int http_request(const char *url,
void *result, int target,
const struct http_get_options *options)
Expand Down Expand Up @@ -1977,7 +1979,30 @@ static int http_request_reauth(const char *url,
void *result, int target,
struct http_get_options *options)
{
int ret = http_request(url, result, target, options);
int ret;

if (options->force_vfs_creds) {
credential_init_min_creds(&http_auth, options->force_vfs_creds);

#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
/*
* Turn off CURLAUTH_ANY when talking to the cache-server.
* It causes the initial request to NOT send creds in order
* to force the 401 and negotiate the best scheme and then
* actually send the creds on the retry.
*
* This is problematic when talking to the cache-servers
* because they send a 400 (with a "A valid Basic Auth..."
* message) rather than a 401 and so the automatic retry
* will never happen (and even if we do force a retry, CURL
* still won't send the creds).
*/
http_auth_methods = CURLAUTH_BASIC;
http_auth_methods_restricted = 1;
#endif
}

ret = http_request(url, result, target, options);

if (ret != HTTP_OK && ret != HTTP_REAUTH)
return ret;
Expand Down
5 changes: 5 additions & 0 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ struct http_get_options {
* request has completed.
*/
struct string_list *extra_headers;

/*
* TODO
*/
struct credential *force_vfs_creds;
};

/* Return values for http_get_*() */
Expand Down
Loading