Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL Always Returns 401 With NTLM

Tags:

linux

curl

ntlm

I'm working on a library to communicate with Microsoft Exchange using PHP. Everything works fine on my production servers, but I keep getting a 401 Unauthorized on my development machine. I tried using curl from the command line and I get the same results.

Using the following returns "401" on my machine:

curl https://mail.example.com/EWS/Exchange.asmx -w %{http_code} --ntlm -u username:password

The same exact call returns "302" on my production machines, which is what I expect.

My development machine is using curl 7.19.7 and my production machine is using curl 7.18.0.

like image 650
JamesArmes Avatar asked Dec 03 '10 00:12

JamesArmes


1 Answers

This is an old question but if it can eventually help anybody, I figured I'd post an answer.

There's a bug with NTLM and curl on certain recent version of Ubuntu (10.04 and up I believe).

  • Ubuntu: https://bugs.launchpad.net/ubuntu/+source/curl/+bug/675974
  • CentOS: https://bugzilla.redhat.com/show_bug.cgi?id=799557

If you're using the curl module of PHP on ubuntu and your libcurl version is affected by this bug, this could explain why your authentication requests are failing.

If you add the verbose flag to your command (-v), you should see something like this in the response part:

  • gss_init_sec_context() failed: : Credentials cache file '/tmp/krb5cc_1000' not found

If you do see this, you're affected by the bug and you'll have to either downgrade your library or find another machine.

I hope this helps :P

like image 175
Pierre Avatar answered Oct 31 '22 08:10

Pierre