Dave Greco wrote:
> I am having some serious problems with a custom AuthenHandler. Basically,
> it looks up users/passwords/groups in a database. The problem is whenever I
> encounter a bad password/username, I want the dialog box to reappear asking
> for them. Instead, the 401 error page is being displayed. Below is the
> config and most of the code:
>
> <Location /php/show.gleim.com>
> Options Indexes ExecCGI
> PerlAuthenHandler Apache::AuthDir
> AuthType Basic
> AuthName "show.gleim.com"
> require valid-user
> </Location>
>
> package Apache::AuthDir;
>
> use Apache::Constants qw(:common);
>
> use DBI;
> $dbh = DBI->connect('DBI:mysql:SGC');
>
> sub handler {
>
> $req = shift;
>
>
> return OK unless $req->is_initial_req;
>
How about redirecting the error back to the original URI, that may work
$req->custom_response(AUTH_REQUIRED,"/php/show.gleim.com");
>
> my( $res, $passwd ) = $req->get_basic_auth_pw();
> return $res if $res != OK;
>
> my $user = $req->connection->user;
> my $uri = $req->uri;
> my $subr = $req->lookup_uri($uri);
> my $filename = $subr->filename;
>
> # Matches /php/show.gleim.com/(oranges/)
> $uri =~ /^\/php\/show.gleim.com\/(.*)$/;
> $dir = $1;
>
> #$req->server->log_error("$dir - $user - $passwd");
>
> # check user and password
> if ( ! checkPassword($user, $passwd) ) {
> $req->note_basic_auth_failure;
> return AUTH_REQUIRED;
> }
>
> if (-d $filename) {
> # Remove any trailing /
> $dir =~ s/\/$//;
>
> # check user and directory
> if (! checkDirectory($user, $dir) ) {
> #$req->server->log_error("$user tried to access $dir but
> couldnt");
> return FORBIDDEN;
> }
> }
>
> if (-f $filename) {
> if (! checkFile($user, $file) ) {
> #$req->server->log_error("$user tried to access $file but
> couldnt");
> return FORBIDDEN;
> }
> }
>
> # Else they are OK
> $req->connection->auth_type('Basic');
> $req->connection->user($user);
> return OK;
> }
>
> ____________________________________
> Dave Greco
> [EMAIL PROTECTED]
> Network Administrator
> Gleim Publications, Inc.
> (800) 87-GLEIM x312
> http://www.gleim.com
> ____________________________________