cURL / Mailing Lists / curl-library / Single Mail

curl-library

Libcurl code gives authentication error with NTLM

From: Karandeep Malik <karandeepmalik_at_gmail.com>
Date: Thu, 10 Apr 2008 12:48:03 +0530

Hi,
When I use libcurl to connect to my server through proxy, I get a 407 Proxy
Auth error, for NTLM

.* About to connect() to laportimo.net.com port 8003
* Trying 146.122.190.185... * connected
* Connected to laportimo.net.com (146.122.190.185) port 8003
* Proxy auth using NTLM with user 'plm\malik'
> POST http://laportimo.net.com:8009/tc/RestServices/Core-2006-03-Session
/login HTTP/1.1
Proxy-Authorization: NTLM TlRMTVNTUAABAAAAAgIAAAAAAAAgAAAAAAAAACAAAAA=
Host: laportimo.net.com:8009
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive
Log-Correlation-ID: localhost.42754.testHello.01.Anonymous.00001
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
< HTTP/1.0 407 Proxy Authentication Required
< Server: squid/2.6.STABLE10
< Date: Thu, 10 Apr 2008 06:49:44 GMT
< Content-Type: text/html
< Content-Length: 1530
< Expires: Thu, 10 Apr 2008 06:49:44 GMT
< X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0
< Proxy-Authenticate: NTLM
TlRMTVNTUAACAAAAAAAAADgAAAACAgACcp6QphzK4xUAAAAAAAAAA
AAAAAA4AAAABQEoCgAAAA8=
< X-Cache: MISS from laportimo.net.com
< X-Cache-Lookup: NONE from laportimo.net.com:8003
< Via: 1.0 laportimo.net.com:8003 (squid/2.6.STABLE10)
* HTTP/1.0 proxy connection set to keep alive!
< Proxy-Connection: keep-alive
* Ignoring the response-body
* Connection #0 to host laportimo.net.com left intact
* Issue another request to this URL: 'http://laportimo.net.com:8009/tc/Re
stServices/Core-2006-03-Session/login'
* Re-using existing connection! (#0) with host laportimo.net.com
* Connected to laportimo.net.com (146.122.190.185) port 8003
* Proxy auth using NTLM with user 'asm\malik'
> POST http://laportimo.net.com:8009/tc/RestServices/Core-2006-03-Session
/login HTTP/1.1
Proxy-Authorization: NTLM
TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAAAMAAwBAAAAABQAFAE
MAAAAAAAAASAAAAAAAAAB4AAAAAYIAAHBsbW1hbGlrAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAA
Host: laportimo.net.com:8009
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive
Log-Correlation-ID: localhost.42754.testHello.01.Anonymous.00001
Content-Length: 171
Content-Type: application/x-www-form-urlencoded

<ns0:LoginInput xmlns:ns0="http://cookbook.com/Schemas/Core/2006-03/Session"
s
essionDiscriminator="CPP-UTest" password="malik" group="" role=""
username="karandeep"/>< HTTP/1.0 407 Proxy Authentication Required
< Server: squid/2.6.STABLE10
< Date: Thu, 10 Apr 2008 06:49:44 GMT
< Content-Type: text/html
< Content-Length: 1530
< Expires: Thu, 10 Apr 2008 06:49:44 GMT
< X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0
* Authentication problem. Ignoring this.
< Proxy-Authenticate: NTLM
< X-Cache: MISS from laportimo.net.com
< X-Cache-Lookup: NONE from laportimo.net.com:8003
< Via: 1.0 laportimo.net.com:8003 (squid/2.6.STABLE10)
< Proxy-Connection: close

The code I wrote for the same was :-

curl_easy_setopt( m_CurlHandle, CURLOPT_URL, url.c_str() );

curl_easy_setopt( m_CurlHandle, CURLOPT_POST, 1 );

// Usefull for debugging!

curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);

curl_easy_setopt( m_CurlHandle, CURLOPT_VERBOSE, 1 );

curl_easy_setopt( m_CurlHandle, CURLOPT_POSTFIELDS, args.c_str() );

curl_easy_setopt( m_CurlHandle, CURLOPT_ERRORBUFFER, &errorBuffer);

curl_easy_setopt( m_CurlHandle, CURLOPT_WRITEFUNCTION, stdStringWriter );

curl_easy_setopt( m_CurlHandle, CURLOPT_WRITEDATA, (void *)&responseString
);

curl_easy_setopt( m_CurlHandle, CURLOPT_HEADERFUNCTION, stdStringWriter );

curl_easy_setopt( m_CurlHandle, CURLOPT_WRITEHEADER, (void *)&header );

curl_easy_setopt( m_CurlHandle, CURLOPT_HTTPHEADER, requestHeaders );

string sOption =
m_sessionManager->getOption(Connection::OPT_SERVER_TIMEOUT);

curl_easy_setopt( m_CurlHandle, CURLOPT_TIMEOUT, atol(sOption.c_str()) );

bool verify = m_sessionManager->getOption( Connection::OPT_RESERVED_CURL) ==
"true";

curl_easy_setopt( m_CurlHandle, CURLOPT_SSL_VERIFYPEER, false);

if( getOption(Connection::OPT_USE_COMPRESSION) == "true" )

curl_easy_setopt(m_CurlHandle, CURLOPT_ENCODING, "gzip");

string proxy = m_sessionManager->getOption(Connection::HTTP_PROXY_HOST);

curl_easy_setopt(m_CurlHandle, CURLOPT_PROXY, proxy.c_str());

curl_easy_setopt(m_CurlHandle,CURLOPT_PROXYAUTH,CURLAUTH_NTLM);

curl_easy_setopt(m_CurlHandle, CURLOPT_PROXYUSERPWD, user.c_str() );
When I reconfigure my squid proxy and use CURL_AUTH_BASIC, the code ran
fine, i.e. the input variables/data was correct.

I earlier thought that this could be a result of bad proxy settings. But
when I use curl .exe it goes fine and allows me to connect to the same.
what could be the problem. Any clues ??
Received on 2008-04-10