Have you imported them?


use Apache::Const compile ->qw(Apache::HTTP_FORBIDDEN);

All the available Apache:: constants are listed here:

http://perl.apache.org/docs/2.0/api/Apache/Const.html




Hi!


I have included the bare minimum of the code from the module, (Apache::AuthenNTLM). It is still acting as if I have not imported the modules, but I have changed "require" to "use", moved the "use" statements into various places of the module to see if they would catch it, and nothing doing... I am at the end of my wits. If someone would have a minute to see if they can see why the Constants within the "sub handler" would not be found, (though they are imported), that would be a great thanks and help :) I am running apache 2.0.46 and mod_perl 1.99_09, perl 5.6.1 on a Debian machine.

Thanks in advance,
speeves
cws

package Apache::AuthenNTLM ;

use strict ;
use vars qw{$cache $VERSION %msgflags1 %msgflags2 %msgflags3 %invflags1 %invflags2 %invflags3 $debug} ;
use warnings ;
no warnings 'redefine';


$VERSION = 0.24 ;

$debug = 0 ;

$cache = undef ;

use MIME::Base64 () ;
use Authen::Smb 0.95 ;
use Socket ;

############################################
# here is where we start the new code....
############################################
use mod_perl ;

# use Apache::Constants qw(:common);
# setting the constants to help identify which version of mod_perl
# is installed
use constant MP2 => ($mod_perl::VERSION >= 1.99);

# test for the version of mod_perl, and use the appropriate libraries
BEGIN {
if (MP2) {
require Apache::Const;
require Apache::Access;
require Apache::Connection;
require Apache::Log;
require Apache::RequestRec;
require Apache::RequestUtil;
apache::Const->import(-compile => 'HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
} else {
require Apache::Constants;
Apache::Constants->import('HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
}
}
##################### end modperl code ######################




sub handler : method # ($$)
   {
   my ($class, $r) = @_ ;
   my $type ;
   my $nonce = '' ;
   my $self ;
   my $conn = $r -> connection ;
   my $connhdr =  $r -> header_in ('Connection') ;

   my $fh = select (STDERR) ;
   $| = 1 ;
   select ($fh) ;

my ($addr, $port) = sockaddr_in ($conn -> remote_addr) ;


print STDERR "[$$] AuthenNTLM: Start NTLM Authen handler pid = $$, connection = $$conn conn_http_hdr = $connhdr main = " . ($r -> main) . " cuser = " . $conn -> user .
' remote_ip = ' . $conn -> remote_ip . " remote_port = " . unpack('n', $port) . ' remote_host = <' . $conn -> remote_host . "> version = $VERSION\n" if ($debug) ;


# we cannot attach our object to the connection record. Since in
# Apache 1.3 there is only one connection at a time per process
# we can cache our object and check if the connection has changed.
# The check is done by slightly changing the remote_host member, which
# persists as long as the connection does
# This has to be reworked to work with Apache 2.0
if (ref ($cache) ne $class || $$conn != $cache -> {connectionid} || $conn -> remote_host ne $cache->{remote_host})
{
$conn -> remote_host ($conn -> remote_host . ' ') ;
$self = {connectionid => $$conn, remote_host => $conn -> remote_host} ;
bless $self, $class ;
$cache = $self ;
print STDERR "[$$] AuthenNTLM: Setup new object\n" if ($debug) ;
}
else
{
$self = $cache ;
print STDERR "[$$] AuthenNTLM: Object exists user = $self->{userdomain}\\$self->{username}\n" if ($debug) ;


   if ($self -> {ok})
           {
           $conn -> user($self->{mappedusername}) ;

# we accept the user because we are on the same connection
$type = $self -> get_msg ($r);
my $content_len = $r -> header_in('content-length') ;
my $method = $r -> method ;
print STDERR "[$$] AuthenNTLM: Same connection pid = $$, connection = $$conn cuser = " .
$conn -> user . ' ip = ' . $conn -> remote_ip . ' method = ' . $method . ' Content-Length = ' .
$content_len . ' type = ' . $type . "\n" if ($debug) ;



# IE (5.5, 6.0, probably others) can send a type 1 message
# after authenticating on the same connection. This is a
# problem for POST messages, because IE also sends a
# "Content-length: 0" with no POST data.
if ($method eq 'GET' || $method eq 'HEAD' || $method eq 'OPTION' || $method eq 'DELETE' ||
$content_len > 0 || $type == 3)
{
print STDERR "[$$] AuthenNTLM: OK because same connection\n" if ($debug) ;
return MP2 ? Apache::OK : Apache::Constants::OK ;
}


           }
       }

$self -> get_config ($r) ;

$type = $self -> get_msg ($r) if (!$type) ;

if (!$type)
{
$self -> {lock} = undef ; # reset lock in case anything has gone wrong
if (!$self->{ntlmauthoritative})
{ # see if we have any header
my $auth_line = $r -> header_in ($r->proxyreq ? 'Proxy-Authorization' : 'Authorization') ;
if ($auth_line)
{
MP2 ? $r->log_error('Bad/Missing NTLM Authorization Header for ' . $r->uri . '; DECLINEing because we are not authoritative' ) : $r->log_reason('Bad/Missing NTLM Authorization Header for ' . $r->uri . '; DECLINEing because we are not authoritative' ) ;
return MP2 ? Apache::DECLINED : Apache::Constants::DECLINED ;
}
}


MP2 ? $r->log_error('Bad/Missing NTLM/Basic Authorization Header for ' . $r->uri) : $r->log_reason('Bad/Missing NTLM/Basic Authorization Header for ' . $r->uri) ;

my $hdr = $r -> err_headers_out ;
$hdr -> add ($r->proxyreq ? 'Proxy-Authenticate' : 'WWW-Authenticate', 'NTLM') if ($self -> {authntlm}) ;
$hdr -> add ($r->proxyreq ? 'Proxy-Authenticate' : 'WWW-Authenticate', 'Basic realm="' . $self -> {authname} . '"') if ($self -> {authbasic}) ;
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED ;
}


if ($type == 1)
{
my $log = $r->log;
my $nonce = $self -> get_nonce ($r) ;
$log->notice("Nonce value set to $nonce.");
if (!$nonce)
{
$self -> {lock} = undef ; # reset lock in case anything has gone wrong
MP2 ? $r->log_error("Cannot get nonce") : $r->log_reason("Cannot get nonce") if (!defined ($nonce)) ;
return $self->{ntlmauthoritative} ? (defined($nonce)) ? (MP2 ? Apache::HTTP_FORBIDDEN : Apache::Constants::HTTP_FORBIDDEN) : (MP2 ? Apache::HTTP_INTERNAL_SERVER_ERROR : Apache::Constants::HTTP_INTERNAL_SERVER_ERROR) : (MP2 ? Apache::DECLINED : Apache::Constants::DECLINED) ;
# return $self->{ntlmauthoritative}?(defined($nonce)?Apache::HTTP_FORBIDDEN:Apache::HTTP_INTERNAL_SERVER_ERROR):Apache::DECLINED ;
}


$self -> set_msg2 ($r, $nonce) ;
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED ;
}
elsif ($type == 3)
{
if ( !$self->verify_user( $r ) )
{
if ( $self->{ntlmauthoritative} )
{
my $hdr = $r -> err_headers_out ;
$hdr -> add ($r->proxyreq ? 'Proxy-Authenticate' : 'WWW-Authenticate', 'NTLM') if ($self -> {authntlm}) ;
$hdr -> add ($r->proxyreq ? 'Proxy-Authenticate' : 'WWW-Authenticate', 'Basic realm="' . $self -> {authname} . '"') if ($self -> {authbasic}) ;
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED ;
}
else
{
return MP2 ? Apache::DECLINED : Apache::Constants::DECLINED ;
}
}
}
elsif ($type == -1)
{
my $nonce = $self -> get_nonce ($r) ;
if (!$nonce)
{
$self -> {lock} = undef ; # reset lock in case anything has gone wrong
MP2 ? $r->log_error("Cannot get nonce for " . $r->uri) : $r->log_reason("Cannot get nonce for " . $r->uri) ;
return MP2 ? Apache::HTTP_INTERNAL_SERVER_ERROR : Apache::Constants::HTTP_INTERNAL_SERVER_ERROR ;
}


if (!$self -> verify_user ($r))
{
if ($self -> {basicauthoritative})
{
my $hdr = $r -> err_headers_out ;
$hdr -> add ($r->proxyreq ? 'Proxy-Authenticate' :'WWW-Authenticate', 'Basic realm="' . $self -> {authname} . '"') if ($self -> {authbasic}) ;
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED ;
}
else
{
return MP2 ? Apache::DECLINED : Apache::Constants::DECLINED ;
}
}
}
else
{
$self -> {lock} = undef ; # reset lock in case anything has gone wrong
MP2 ? $r->log_error("Bad NTLM Authorization Header type $type for " . $r->uri) : $r->log_reason("Bad NTLM Authorization Header type $type for " . $r->uri) ;
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED ;
}


   $self -> {lock} = undef ; # reset lock in case anything has gone wrong
   $conn -> user($self -> {mappedusername} = $self -> map_user ($r)) ;

$self->{ok} = 1 ;

print STDERR "[$$] AuthenNTLM: OK pid = $$, connection = $$conn cuser = " . $conn -> user .
' ip = ' . $conn -> remote_ip . "\n" if ($debug) ;


   return MP2 ? Apache::OK : Apache::Constants::OK ;
   }


[Thu Jul 17 11:51:30 2003] [error] failed to resolve handler `Apache::AuthenNTLM'
[Thu Jul 17 11:51:30 2003] [error] [client 127.0.0.1] Bareword "Apache::DECLINED" not allowed while "strict su
bs" in use at /usr/local/lib/perl/5.6.1/Apache/AuthenNTLM.pm line 141.
Bareword "Apache::HTTP_UNAUTHORIZED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apach
e/AuthenNTLM.pm line 150.
Bareword "Apache::HTTP_FORBIDDEN" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apache/A
uthenNTLM.pm line 162.
Bareword "Apache::HTTP_UNAUTHORIZED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apach
e/AuthenNTLM.pm line 167.
Bareword "Apache::HTTP_INTERNAL_SERVER_ERROR" not allowed while "strict subs" in use at /usr/local/lib/perl/5.
6.1/Apache/AuthenNTLM.pm line 162.
Bareword "Apache::DECLINED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apache/AuthenN
TLM.pm line 162.
Bareword "Apache::HTTP_UNAUTHORIZED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apach
e/AuthenNTLM.pm line 178.
Bareword "Apache::DECLINED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apache/AuthenN
TLM.pm line 182.
Bareword "Apache::HTTP_INTERNAL_SERVER_ERROR" not allowed while "strict subs" in use at /usr/local/lib/perl/5.
6.1/Apache/AuthenNTLM.pm line 193.
Bareword "Apache::HTTP_UNAUTHORIZED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apach
e/AuthenNTLM.pm line 202.
Bareword "Apache::DECLINED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apache/AuthenN
TLM.pm line 206.
Bareword "Apache::HTTP_UNAUTHORIZED" not allowed while "strict subs" in use at /usr/local/lib/perl/5.6.1/Apach
e/AuthenNTLM.pm line 214.
Compilation failed in require at (eval 4) line 3.





Reply via email to