Reputation: 59
So I am working on trying to make my own apache module. Right now I trying to get it to return a 403 just to test it out, but it seems that apache just ignores the module entirely and returns the default page. Here is the relevant parts of my code:
static int request_hook(request_rec* r){
return HTTP_FORBIDDEN;
}
/* ********************************************
Register module to Apache
******************************************** */
static void register_hooks(apr_pool_t *p)
{
// We want to hook first so we can issue a deny ASAP if needed
ap_hook_log_transaction( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);
}
module AP_MODULE_DECLARE_DATA my_module = {
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server configs */
NULL, /* command apr_table_t */
register_hooks /* register hooks */
};
And my apache configuration file looks like this:
<VirtualHost *:80>
DocumentRoot /var/www/html
SetHandler my_module
</VirtualHost>
It was compiled by doing
sudo apxs -i -a -c my_module.c && sudo service apache2 restart
Upvotes: 0
Views: 211
Reputation: 59
Fixed. The problem was the function:
ap_hook_log_transaction( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);
should have been:
ap_hook_handler( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);
Upvotes: 0