Skip to content

Commit 3ea099d

Browse files
Sasha KhapyorskyJunio C Hamano
authored andcommitted
http/ftp: optionally ask curl to not use EPSV command
If http.noEPSV config variable is defined and true, or if GIT_CURL_FTP_NO_EPSV environment variable is defined, disable using of EPSV ftp command (PASV will be used instead). This is helpful with some "poor" ftp servers which does not support EPSV mode. Signed-off-by: Sasha Khapyorsky <sashak@voltaire.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 77e565d commit 3ea099d

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ http.lowSpeedLimit, http.lowSpeedTime::
202202
Can be overridden by the 'GIT_HTTP_LOW_SPEED_LIMIT' and
203203
'GIT_HTTP_LOW_SPEED_TIME' environment variables.
204204

205+
http.noEPSV::
206+
A boolean which disables using of EPSV ftp command by curl.
207+
This can helpful with some "poor" ftp servers which doesn't
208+
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
209+
environment variable. Default is false (curl will use EPSV).
210+
205211
i18n.commitEncoding::
206212
Character encoding the commit messages are stored in; git itself
207213
does not care per se, but this information is necessary e.g. when

git-clone.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ clone_dumb_http () {
3131
cd "$2" &&
3232
clone_tmp="$GIT_DIR/clone-tmp" &&
3333
mkdir -p "$clone_tmp" || exit 1
34+
if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
35+
"`git-repo-config --bool http.noEPSV`" = true ]; then
36+
curl_extra_args="${curl_extra_args} --disable-epsv"
37+
fi
3438
http_fetch "$1/info/refs" "$clone_tmp/refs" || {
3539
echo >&2 "Cannot get remote repository information.
3640
Perhaps git-update-server-info needs to be run there?"

git-fetch.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ fetch_main () {
289289
if [ -n "$GIT_SSL_NO_VERIFY" ]; then
290290
curl_extra_args="-k"
291291
fi
292+
if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
293+
"`git-repo-config --bool http.noEPSV`" = true ]; then
294+
noepsv_opt="--disable-epsv"
295+
fi
292296
max_depth=5
293297
depth=0
294298
head="ref: $remote_name"
@@ -300,7 +304,7 @@ fetch_main () {
300304
$u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
301305
print "$u";
302306
' "$head")
303-
head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted")
307+
head=$(curl -nsfL $curl_extra_args $noepsv_opt "$remote/$remote_name_quoted")
304308
depth=$( expr \( $depth + 1 \) )
305309
done
306310
expr "z$head" : "z$_x40\$" >/dev/null ||

git-ls-remote.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ http://* | https://* | ftp://* )
5353
if [ -n "$GIT_SSL_NO_VERIFY" ]; then
5454
curl_extra_args="-k"
5555
fi
56+
if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
57+
"`git-repo-config --bool http.noEPSV`" = true ]; then
58+
curl_extra_args="${curl_extra_args} --disable-epsv"
59+
fi
5660
curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
5761
echo "failed slurping"
5862
;;

http.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ char *ssl_capath = NULL;
2323
char *ssl_cainfo = NULL;
2424
long curl_low_speed_limit = -1;
2525
long curl_low_speed_time = -1;
26+
int curl_ftp_no_epsv = 0;
2627

2728
struct curl_slist *pragma_header;
2829

@@ -155,6 +156,11 @@ static int http_options(const char *var, const char *value)
155156
return 0;
156157
}
157158

159+
if (!strcmp("http.noepsv", var)) {
160+
curl_ftp_no_epsv = git_config_bool(var, value);
161+
return 0;
162+
}
163+
158164
/* Fall back on the default ones */
159165
return git_default_config(var, value);
160166
}
@@ -196,6 +202,9 @@ static CURL* get_curl_handle(void)
196202

197203
curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
198204

205+
if (curl_ftp_no_epsv)
206+
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
207+
199208
return result;
200209
}
201210

@@ -251,6 +260,9 @@ void http_init(void)
251260
max_requests = DEFAULT_MAX_REQUESTS;
252261
#endif
253262

263+
if (getenv("GIT_CURL_FTP_NO_EPSV"))
264+
curl_ftp_no_epsv = 1;
265+
254266
#ifndef NO_CURL_EASY_DUPHANDLE
255267
curl_default = get_curl_handle();
256268
#endif

0 commit comments

Comments
 (0)