On 09-11-22 17:42 , Devrim Yasar wrote:
> This script supposedly should take * out of *.domain.com, assign it to
> $subdomain variable, and $subdomain should be put to AssignUserId.
>
> However, no matter how hard I try, I can't get this to work. I've been
> working on this for days, and am really desperate. If you think this is
> a lot of work, please charge me consultancy and come get the root passwd.
>
> Any ideas though? Thanks...
>
> |<Perl>
> Use Apache2::ServerRec qw//;
> use Apache2::ServerUtil qw//;
> use Apache2::RequestRec qw//;
> use Apache2::RequestUtil qw//;
> use Apache2::Const qw/OK DECLINED/;
>
> my $s = Apache2::ServerUtil->server;
>
> $s->push_handlers(PerlHeaderParserHandler => sub { my($r) = @_;
From a quick glance at the mpm-itk source-code, it does its magic in at
the headerparsing phase, so your attempt at using that phase to alter
it's behaviour was a good one.
/* set the uid as fast as possible, but not before merging per-dit
config */
ap_hook_header_parser(itk_post_perdir_config, NULL, NULL,
APR_HOOK_REALLY_FIRST);
Unfortunately, it seems to pick APR_HOOK_REALLY_FIRST as precedence,
which makes it run /before/ your code, in the same phase. So, even
though you actually succeed at changing it's run-time configuration, you
do it too late, and it doesn't even look at it.
> if ( $r->hostname =~ m/(.*)\.([^.]+\.\w+)$/ ) {
> my($subdomain,$domain) = ($1,$2);
>
> #
> # THIS WORKS!
> # -----------
> # if requested domain is fio.domain.com <http://fio.domain.com/>,
> # this successfully assigns ServerAdmin [email protected]
> <mailto:[email protected]>
> # so gathering domain parts working
>
> $r->server->server_admin("$subdoma...@$domain");
Yes, as expected, and it uses a published API to do that.
> #
> # THIS DOESN'T!
> # --------------
> # this is supposed to insert this line inside Virtual host
> # --------------
> # <IfModule mpm_itk_module> AssignUserId fio domain</IfModule>
> # --------------
>
> $r->add_config([ "<IfModule mpm_itk_module>",
> "AssignUserId $subdomain $domain",
> "</IfModule>",
> ]);
>
Except for my above explanation, this would work just fine. I would
however caution about using this kind of mechanism to alter run-time
configuration on a per-request basis. This comes at a non-negligable
performance impact, if that's important to your usage scenario.
Ideally, like in the server_admin() case outlined above, mpm-itk
could/should expose an API to allow for changing the userid/domain.
You could try and use PerlMapToStorageHandler as your phase, since it
happens before the PerlHeaderParserHandler phase.
--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
signature.asc
Description: OpenPGP digital signature
