Some more fixes ; )

I would suggest changing the PerlSetVar variables
to actual apache configuration directives which would change this :

my @auth_modules=$r->dir_config->get("AuthModules");

I don't have an immediate patch for this but have done it before.
If you would like me to work on this code no prob, otherwise check
the eagle book for some samples if unfamiliar.

Also,

THIS :

my $handler = \&{"$am\::handler"};
if ($handler->($r) == OK) {
  $r->warn("$am return OK");
return OK;

TO :

## 'or next' can be changed
my $handler = $am->can('handler') or next;
if ($handler->($r) == OK) {
  $r->warn("$am return OK");
  return OK;
}

And I would consider changing this :

$module  =~ s[::][/]g;

to be more portable.  I am working on another class for runtime management
of classes that should address this but won't be on CPAN for a few days.

> ---------
>
> package Apache::AuthMulti;
>
> # Stathy G. Touloumis
> # Marcel M. Weber
> # Darren Chamberlain
> #
> # Version 0.1.0 / 2002.02.13 / Marcel M. Weber
>
> use     strict;
> use     Apache::Constants qw(:common);
>
> sub handler {
>          my $r = shift;
>          my($res, $sent_pw) = $r->get_basic_auth_pw;
>          return $res if $res != OK;
>
>          my @auth_modules=$r->dir_config->get("AuthModules");
>
>          for my $am (@auth_modules)
>          {
>          load($am);
>          if ($@){
>                  $r->log_reason("Error loading module '$am':$@");
>                  next;
>          }
>
>          my $handler = \&{"$am\::handler"};
>          if ($handler->($r) == OK) {
>                  $r->warn("$am return OK");
>                  return OK;
>          }
>
>          $r->log_reason("$am not OK");
>          }
>
>          $r->note_basic_auth_failure;
>          $r->log_reason("none of the handlers could authenticate this
> user");
>          return AUTH_REQUIRED;
> }
>
> sub load {
>      my $module=@_[0];
>      $module  =~ s[::][/]g;
>      $module .= '.pm';
>
>      eval { require $module; };
>
>      return $@ ? 1 : 0;
> }
>
> 1;
> __END__
>
>
> -------------------
>
> In the httpd.conf you have to put something like this:
>
> <Location /test>
>     AuthName Test
>     AuthType Basic
>    # These are AuthenSmb specific
>     PerlSetVar myPDC SAMBA
>     PerlSetVar myDOMAIN ARBEITSGRUPPE
>   # With PerlAddVar you pass an array
>     PerlAddVar AuthModules Apache::AuthSybase
>     PerlAddVar AuthModules Apache::AuthenSmb
>     PerlAuthenHandler Apache::AuthMulti
>     require valid-user
> </Location>
>
> -----------------------
>
> Works perfect...
>
> Why not submitting this somewhere? I think this could be usefull for
> quite a lot of people. I think this is cool, as you do not have to worry
> wether the module returns DECLINED or AUTH_REQUIRED.
>
> Marcel
>
>
> Am Mittwoch den, 13. Februar 2002, um 15:02, schrieb darren chamberlain:
>
> > Quoting Marcel Weber <[EMAIL PROTECTED]> [12 Feb-02 16:15]:
> >> I don't get the point why it did not work the other way round,
> >> but now everything is just fine now :
> >
> > Make it a little more generic:
> >
> > package Apache::MultiAuthen;
> >
> > use strict;
> > use Apache::Constants qw(:common);
> >
> > sub handler {
> >     my $r = shift;
> >     my($res, $sent_pw) = $r->get_basic_auth_pw;
> >     return $res if $res != OK;
> >
> >     # Tweak this; unsure about dir_config returning an array
> >     my @auth_modules = $r->dir_config("AuthModules");
> >
> >     for my $am (@auth_modules) {
> >         load($am);
> >
> >         if ($@) {
> >             $r->log("Error loading module '$am': $@");
> >             next;
> >         }
> >
> >         my $handler = \&{"$am\::handler"};
> >         if ($handler->($r) == OK) {
> >             $r->log_reason("$am return OK");
> >             return OK
> >         }
> >
> >         $r->log_reason("$am not OK");
> >     }
> >
> >     $r->note_basic_auth_failure;
> >     return AUTH_REQUIRED;
> > }
> >
> > sub load {
> >     my $module = @_;
> >     $module  =~ s[::][/]g;
> >     $module .= '.pm';
> >
> >     eval { require $module; };
> >
> >     return $@ ? 1 : 0;
> > }
> >
> > 1;
> >
> > __END__
> >
> > (darren)
> >
> > --
> > Never attribute to malice that which is adequately explained by
> > incompetence.
> >     -- Napolean Bonaparte
> >
> >
> -------------------
>
> PGP / GPG Key:        http://www.ncpro.com/GPG/mmweber-at-ncpro-com.asc
>

Reply via email to