Subject: | Bug in HTTP::DAV when used with NTLM authentication? |
Linux, Perl 5.6.0 HTTP::DAV does not work with NTLM.
Hi,
I was trying to pull some information from Exchange 2000 (Contact List),
which offers a WebDAV interface. I was happy to discover your WebDAV
Perl module, but it did not work for me. Upon investigating I discovered
Exchange uses NTLM authentication, and HTTP::DAV does not seem
to work with that.
Am I using it incorrectly?
I found a piece if sample code that "use Authen::NTLM;" that did connect,
but was not WebDAV aware. When I include your DAV code, with "use HTTP::DAV;"
and make no other changes, the previously working code stops working.
This (test.pl) has been borrowed from someone's code I found on google.
This code works, until you uncomment out any of the "use HTTP::DAV*"
lines, then it fails.
NTLM requires the connection be kept open during the handshaking sequence,
and therefore needs the keep_alive.
I think other Microsoft server products also offer webdav interfaces,
but I can not remember which ones right now. I would assume they also
use Microsoft's authentication method, NTLM. Exchange does not offer
the client any other authentication methods.
My Exchange server is not visible from the Internet, so I am not sure
how you can reproduce this. I can/will investigate if Apache can be
configured to require NTLM authentication.
test.pl = NTML only code
mod.txt = modules installed
dav.pl = does not work, it gives this error
Show quoted text
unix> perl dav.pl
The keep_alive option must be enabled for NTLM authentication to work. NTLM authentication aborted.
Couldn't open http://my.exchange.server.com/exchange/user1/: Unauthorized.
#!/usr/bin/perl
# Snippet of code found on google. I lost the author name.
use LWP::UserAgent;
use Authen::NTLM;
use HTTP::Request::Common;
# If any of these lines are uncommented, code will start failing.
#use HTTP::DAV;
#use HTTP::DAV::Resource;
#use HTTP::DAV::Comms;
# Things learned, it is the two files DAV::Resources and DAV::Comms that break it.
# It is nothing those two files include
my $url = 'http://my.exchange.server.com/exchange/user1';
my $user = 'DOMAINNAME\user1'; # The auth module splits this on the '\'
my $pass = 'user1';
my $ua = new LWP::UserAgent(keep_alive=>1);
$ua->credentials('my.exchange.server.com:80', '', $user, $pass);
$request = GET $url;
$response = $ua->request($request);
if ($response->is_success) {print "It worked!->" . $response->code . "\n"}
else {print "It didn't work!->" . $response->code . "\n"}