Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. package LWP::Authen::Basic;
  2. use strict;
  3. require MIME::Base64;
  4. sub authenticate
  5. {
  6. my($class, $ua, $proxy, $auth_param, $response,
  7. $request, $arg, $size) = @_;
  8. my($user, $pass) = $ua->get_basic_credentials($auth_param->{realm},
  9. $request->url, $proxy);
  10. return $response unless defined $user and defined $pass;
  11. my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization";
  12. my $auth_value = "Basic " . MIME::Base64::encode("$user:$pass", "");
  13. # Need to check this isn't a repeated fail!
  14. my $r = $response;
  15. while ($r) {
  16. my $auth = $r->request->header($auth_header);
  17. if ($auth && $auth eq $auth_value) {
  18. # here we know this failed before
  19. $response->header("Client-Warning" =>
  20. "Credentials for '$user' failed before");
  21. return $response;
  22. }
  23. $r = $r->previous;
  24. }
  25. my $referral = $request->clone;
  26. $referral->header($auth_header => $auth_value);
  27. return $ua->request($referral, $arg, $size, $response);
  28. }
  29. 1;