PATCH: add -DAPACHE24 support to Apache::Test - necessary for Auth with Apache 2.4

2014-03-17 Thread Michael Schout
Hi.

I have submitted this issue a while back to rt.cpan.org, but I have not
gotten any response.

I am the maintainer of Apache::AuthCookie.

As most of us probably already know, Apache 2.4 has a very different
authentication API from previous Apache versions.  As a result, in order
to release a version of Apache::AuthCookie that passes tests on Apache
2.4 and previous versions, it is necessary to have conditional config
sections that are only enabled for Apache 2.4 or later.

Currently Apache::Test defines APACHE2 if running under apache 2.0 or
later.  The attached patch also defines APACHE24 if running under apache
2 with a minor version = 4.

I shipped a patch for AuthCookie to the debian folks that works under
Apache 2.4, but I also need this patch in Apache::Test in order to make
it so that the test suite will work on all Apache versions (2.4 as well
as 2.2 and earlier)

Example in AuthCookie t/conf/extra.conf.in:

IfDefine APACHE24
  # Apache 2.4+ Auth API
  PerlAddAuthzProvider user My::Auth-authz
/IfDefine
...
IfDefine APACHE2
  ...
  IfDefine !APACHE24
# Pre Apache 2.4 Auth API.
PerlAuthzHandler 
  /IfDefine
/IfDefine

Hopefully this makes it clear why this is needed, and why I'd like to
see this in Apache::Test before mod_perl for apache 2.4 is finalized.

Regards,
Michael Schout

diff --git a/Apache-Test/lib/Apache/TestServer.pm 
b/Apache-Test/lib/Apache/TestServer.pm
index 254aec6..a3bc3ab 100644
--- a/Apache-Test/lib/Apache/TestServer.pm
+++ b/Apache-Test/lib/Apache/TestServer.pm
@@ -85,6 +85,15 @@ sub post_config {
 $self-{rev} = 0; # unknown
 }
 
+($self-{revminor}) = $self-{version} =~ m|/\d\.(\d)|;
+
+if ($self-{revminor}) {
+debug Matched Apache revminor $self-{version} $self-{revminor};
+}
+else {
+$self-{revminor} = 0;
+}
+
 $self;
 }
 
@@ -126,7 +135,14 @@ sub pid_file {
 
 sub dversion {
 my $self = shift;
--D APACHE$self-{rev};
+
+my $dv = -D APACHE$self-{rev};
+
+if ($self-{rev} == 2 and $self-{revminor} = 4) {
+$dv .=  -D APACHE24;
+}
+
+return $dv;
 }
 
 sub config_defines {


Re: PATCH: add -DAPACHE24 support to Apache::Test - necessary for Auth with Apache 2.4

2014-03-17 Thread André Warnier
Not an answer to your question, but many thanks for that module, for keeping it 
up-to-date, and for pointing out the differences in Apache 2.4.
I used Apache::Cookie as a base to create my own module which does just about every 
authentication under the sun (for a particular back-end), and it was very valuable.

It looks like I'll have my work cut out to adapt to Apache 2.4 though.

Incidentally, where can I find a description of the new Apache 2.4 API ?

Michael Schout wrote:

Hi.

I have submitted this issue a while back to rt.cpan.org, but I have not
gotten any response.

I am the maintainer of Apache::AuthCookie.

As most of us probably already know, Apache 2.4 has a very different
authentication API from previous Apache versions.  As a result, in order
to release a version of Apache::AuthCookie that passes tests on Apache
2.4 and previous versions, it is necessary to have conditional config
sections that are only enabled for Apache 2.4 or later.

Currently Apache::Test defines APACHE2 if running under apache 2.0 or
later.  The attached patch also defines APACHE24 if running under apache
2 with a minor version = 4.

I shipped a patch for AuthCookie to the debian folks that works under
Apache 2.4, but I also need this patch in Apache::Test in order to make
it so that the test suite will work on all Apache versions (2.4 as well
as 2.2 and earlier)

Example in AuthCookie t/conf/extra.conf.in:

IfDefine APACHE24
  # Apache 2.4+ Auth API
  PerlAddAuthzProvider user My::Auth-authz
/IfDefine
...
IfDefine APACHE2
  ...
  IfDefine !APACHE24
# Pre Apache 2.4 Auth API.
PerlAuthzHandler 
  /IfDefine
/IfDefine

Hopefully this makes it clear why this is needed, and why I'd like to
see this in Apache::Test before mod_perl for apache 2.4 is finalized.

Regards,
Michael Schout





Re: PATCH: add -DAPACHE24 support to Apache::Test - necessary for Auth with Apache 2.4

2014-03-17 Thread Michael Schout
On 3/17/14, 1:58 PM, André Warnier wrote:
 Not an answer to your question, but many thanks for that module, for
 keeping it up-to-date, and for pointing out the differences in Apache 2.4.

Thanks!

 Incidentally, where can I find a description of the new Apache 2.4 API ?

I'm not sure there is really a place that it is documented extensively
anywhere in one place.

I figured it out from reading these pages:

http://httpd.apache.org/docs/current/developer/new_api_2_4.html
https://httpd.apache.org/docs/trunk/upgrading.html
https://httpd.apache.org/docs/trunk/howto/auth.html
https://httpd.apache.org/docs/trunk/mod/mod_auth_basic.html#authbasicprovider

as well as reading source code for the various apache modules in httpd
2.4 source (e.g.: mod_auth_basic.c, mod_authz_user.c etc) and the
mod_perl patch for apache 2.4 to figure out how the new directives have
been implemented in mod_perl.

Basically it comes down to needing to do the following for Apache 2.4:

declare your Authz handler with something like:

 PerlAddAuthzProvider user Sample::Apache2::AuthCookieHandler-authz_handler

Assuming you want to send Forbidden response if Authz fails (which is
what previous versions did):

 Location /docs
   AuthzSendForbiddenOnFailure On
 /Location

And REMOVE any PerlAuthzHandler entries you have configured (this is
what the PerlAddAuthzProvider does instead).

Also Require defaults to satisfy Any now, so if you had:

Require user foo
Require user bar

You have to wrap that in RequireAll now.

Feel free to look at the httpd24 branch of AuthCookie on github to see
how I implemented it.

Regards,
Michael Schout