package OneUnified::AuthNTLM;

# Copyright 2007 One Unified, All Rights Reserved
# Created by Ray Burkholder, ray@oneunified.net

use Apache2::AuthenNTLM;

@ISA = ( 'Apache2::AuthenNTLM' );

sub handler : method {
  my ( $self, $r ) = @_;

#  print STDERR "[$$] OU NTLM handler bgn: " . $r -> headers_in -> {'Connection'} . " \n";
#  my $s = Apache2::AuthenNTLM::handler($self, $r);  
  my $s = $self->SUPER::handler($r);  
#   print STDERR "[$$] OU NTLM vuser ud: " . $self->{userdomain} . "\n" if defined $self->{userdomain};
#   print STDERR "[$$] OU NTLM vuser un: " . $self->{username} . "\n" if defined  $self->{username};
#  print STDERR "[$$] OU NTLM handler end: $s \n";
  return $s;
  }

sub map_user($$) {
  my ( $self, $r ) = @_;

#   my $s = $self->{userdomain} . "\\" . $self->{username};
  my $s = Apache2::AuthenNTLM::map_user($self, $r);
#  print STDERR "[$$] OU NTLM mapuser: $s\n";
  return $s;
  }

sub get_config($$) {
  my ( $self, $r ) = @_;
#  print STDERR "[$$] OU NTLM getconfig\n";
  return Apache2::AuthenNTLM::get_config($self, $r);
  }

sub get_nonce($$) {
  my ( $self, $r ) = @_;
#  print STDERR "[$$] OU NTLM getnonce\n";
  return Apache2::AuthenNTLM::get_nonce($self, $r);
  }

sub verify_user($$) {
  my ( $self, $r ) = @_;

#   print STDERR "[$$] OU NTLM vuser ba: " . $self->{basic} . "\n" if defined $self->{basic};
   print STDERR "[$$] OU NTLM vuser nt: " . $self->{ntlm} . "\n" if defined $self->{ntlm}; #0/1 true/false
   print STDERR "[$$] OU NTLM vuser un: " . $self->{username} . "\n" if defined  $self->{username};
#   print STDERR "[$$] OU NTLM vuser ps: " . $self->{password} . "\n" if defined  $self->{password};
#   print STDERR "[$$] OU NTLM vuser hs: " . $self->{usernthash} . "\n" if defined $self->{usernthash};
   print STDERR "[$$] OU NTLM vuser ud: " . $self->{userdomain} . "\n" if defined $self->{userdomain};
   print STDERR "[$$] OU NTLM vuser un: " . $self->{username} . "\n" if defined  $self->{username};

  $r->pnotes( 'basic'      => $self->{basic}      ) if defined $self->{basic};
  $r->pnotes( 'ntlm'       => $self->{ntlm}       ) if defined $self->{ntlm};
  $r->pnotes( 'username'   => $self->{username}   ) if defined $self->{username};
  $r->pnotes( 'userdomain' => $self->{userdomain} ) if defined $self->{userdomain};

  return 1;
  }


1;
