Re: Upgrading a mod_perl application from Apache 2.2 to Apache 2.4

2018-12-06 Thread William A Rowe Jr
On Thu, Dec 6, 2018 at 3:34 PM Andrew Green  wrote:

> Hi William,
>
> But you are better off looking at;
>
> http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_get_server_version_
>
> which returns nothing except exactly what you are asking.
>
>
> I did try this (and it worked fine) — but I kept seeing the following
> error pop up in the logs:
>
> *ap_get_server_version() is deprecated since httpd/2.3.0 try using
> ap_get_server_(description|banner)() instead*
>
> So I switched to banner.  I’ll see about switching again to description.
>

Ahhh, ok, just be aware the get_server_description call doesn't exist in
2.2, you need
to perform a little eval() magic to guard against that expected failure.


Re: Upgrading a mod_perl application from Apache 2.2 to Apache 2.4

2018-12-06 Thread Andrew Green
Hi William,

> But you are better off looking at;
> http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_get_server_version_
>  
> 
> 
> which returns nothing except exactly what you are asking.

I did try this (and it worked fine) — but I kept seeing the following error pop 
up in the logs:

ap_get_server_version() is deprecated since httpd/2.3.0 try using 
ap_get_server_(description|banner)() instead

So I switched to banner.  I’ll see about switching again to description.

Cheers,
Andrew.

-- 
Andrew Green
Article Seven Limited
http://www.article7.co.uk/ 

Article Seven Limited is a registered company in England and Wales.  Registered 
number: 5703656. Registered office: 10 Hamilton Road, Sidcup, Kent, DA15 7HB.






Re: Upgrading a mod_perl application from Apache 2.2 to Apache 2.4

2018-12-06 Thread William A Rowe Jr
On Thu, Dec 6, 2018 at 9:25 AM Andrew Green  wrote:

> Hi all,
>
> Huge thanks to everyone for your replies on this.  I’ve now been able to
> work through everything, and I thought I’d post a quick update with some
> additional notes in case there’s anyone else in the same boat searching the
> archives in the future!
>
> 1. I was able to use the following as a way of determining which version
> of Apache is in use at runtime:
>
> my $server_version = Apache2::ServerUtil::get_server_banner();
> my $is_old_apache = ($server_version =~ /Apache\/2\.2/) ? 1 : 0;
>

Just a little warning, the server_banner is controlled by the admin, and
may not include
the entire Apache/2.2 token. The server_description fleshed this out beyond
the control
of the admin, but isn't meant for transmission;

/**
 * Get the server banner in a form suitable for sending over the
 * network, with the level of information controlled by the
 * ServerTokens directive.
 * @return The server banner
 */
AP_DECLARE(const char *) ap_get_server_banner(void);

/**
 * Get the server description in a form suitable for local displays,
 * status reports, or logging.  This includes the detailed server
 * version and information about some modules.  It is not affected
 * by the ServerTokens directive.
 * @return The server description
 */
AP_DECLARE(const char *) ap_get_server_description(void);

But you are better off looking at;
http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_get_server_version_

which returns nothing except exactly what you are asking.


Re: Upgrading a mod_perl application from Apache 2.2 to Apache 2.4

2018-12-06 Thread Andrew Green
Hi all,

Huge thanks to everyone for your replies on this.  I’ve now been able to work 
through everything, and I thought I’d post a quick update with some additional 
notes in case there’s anyone else in the same boat searching the archives in 
the future!


1. I was able to use the following as a way of determining which version of 
Apache is in use at runtime:

my $server_version = Apache2::ServerUtil::get_server_banner();
my $is_old_apache = ($server_version =~ /Apache\/2\.2/) ? 1 : 0;


2. My app sets up authen and authz handlers dynamically, from a trans handler. 
André was right, this was by far the biggest pain point!

My before code looked like this:

$r->push_handlers(PerlMapToStorageHandler => sub {
   $r->add_config(['Require valid-user']);
   $r->add_config(['AuthType cookie']);
});

$r->set_handlers(PerlAuthenHandler => [MyApp::Authen]);
$r->set_handlers(PerlAuthzHandler => [MyApp::Authz]);

As far as I can tell, I have to pre-declare the new Authz provider in my server 
config:

PerlAddAuthzProvider myapp MyApp::Authz

I didn’t find a way of doing that bit dynamically at runtime.

But I can still conditionally trigger the provider for individual requests from 
my trans handler, like this:

$r->push_handlers(PerlMapToStorageHandler => sub {
   $r->add_config(['Require myapp']);
});

$r->set_handlers(PerlAuthenHandler => [MyApp::Authen]);


3. Combining #1 and #2 meant I’m able to have the same trans handler run under 
both Apache 2.2 and 2.4.  I was also able to get my authz handler to run under 
both by:

a. Having the call to Apache2::Compat -compile happen in the server startup.pl, 
and not in my module.

b. Wrapping the return value like this:

sub authz_granted {

   my $self = shift;

   # So this compiles under old Apache
   no strict 'subs';

   if ($self->is_old_apache) {
  return Apache2::Const::OK;
   } else {
  return Apache2::Const::AUTHZ_GRANTED;
   }

}


Thanks again to you all for your help.

Cheers,
Andrew.

-- 
Andrew Green
Article Seven Limited
http://www.article7.co.uk/ 

Article Seven Limited is a registered company in England and Wales.  Registered 
number: 5703656. Registered office: 10 Hamilton Road, Sidcup, Kent, DA15 7HB.