cURL / Mailing Lists / curl-users / Single Mail

curl-users

libcurl ignores remote port when using http digest auth

From: <j.ryska.mail_at_post.cz>
Date: Mon, 13 Mar 2006 09:58:20 +0100 (CET)

Hi,
 here is the problem. I'm using libCurl (7.15.2). When my program uses port different than 80 for connection, then it fail when sending http digest credentials. Here is relevant code:
   curl=curl_easy_init();
   curl_easy_setopt(curl,CURLOPT_VERBOSE);
   curl_easy_setopt(curl,CURLOPT_URL, "http://localhost/private/index.html");
   curl_easy_setopt(curl,CURLOPT_HTTPAUTH,CURLAUTH_DIGEST);
   curl_easy_setopt(curl,CURLOPT_USERPWD,"user:password");
   curl_easy_setopt(curl,CURLOPT_PORT,5020);

   curl_easy_perform(curl);
   curl_easy_cleanup(curl);
Here is output of this program

* About to connect() to localhost port 5020
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 5020
* Server auth using Digest with user 'user'
> GET /private/index.html HTTP/1.1

Host: localhost:5020

Accept: */*

< HTTP/1.1 401 Authorization Required

< Date: Mon, 13 Mar 2006 08:41:34 GMT

< Server: Apache/2.0.55 (Win32)

< WWW-Authenticate: Digest realm="digestTest", nonce="f6dqT9wOBAA=d9aee3a61214ce798382957dd54c99633b88d53e", algorithm=MD5, qop="auth"

< Content-Length: 477

< Content-Type: text/html; charset=iso-8859-1

* Ignoring the response-body
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost/private/index.html'
* About to connect() to localhost port 80
* Trying 127.0.0.1... * Connection refused
* couldn't connect to host
* Closing connection #1
* couldn't connect to server
* Closing connection #0

As you can see second request with digest auth data is trying to connect to port 80 instead of 5020 where apache is running.
After some research i found this code in transfer.c

1931: else {
1932: /* This is an absolute URL, don't allow the custom port number */
1933: data->state.allow_port = FALSE;

This causes that port isn't set for second request: file url.c:

3430: if(data->set.use_port && data->state.allow_port) {
3431: /* if set, we use this and ignore the port possibly given in the URL */
3432: conn->remote_port = (unsigned short)data->set.use_port;

So I commented that line 1933 in transfer.c and for now this works for me.

Cheers
 Jiri Ryska
Received on 2006-03-13