httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Farber <alexander.far...@gmail.com>
Subject Re: How to access client socket from a protocol handler
Date Sat, 23 Oct 2010 22:00:01 GMT
Thank you, but -

On Sat, Oct 23, 2010 at 10:01 PM, Ben Noordhuis <info@bnoordhuis.nl> wrote:
> Alexander, take a look at mod_echo.c (included in the source tarball).
> It's a great example of how a protocol handler should work and it just
> might convince you to use bucket brigades after all. :)
>
> You need to check if your handler is enabled for the current vhost. If
> it's not, return DECLINED. If it is, look up the client socket and go
> from there.
>

I've created a module using bb (the source code at the bottom)
and it suffers from the same problem (hijacks the port 80 too).
Could it be that "SetHandler" is a wrong directive for protocol handler?

LoadModule socket_policy_module modules/mod_socket_policy.so
Listen 843
<VirtualHost _default_:843>
        SetHandler socket_policy
</VirtualHost>

Also, I do not know, how to check that the
"handler is enabled for the current vhost".

for (p = conn->base_server; p != NULL; p = p->next)
        /* and then? */

Regards
Alex

#include <httpd.h>
#include <http_protocol.h>
#include <http_connection.h>
#include <http_config.h>
#include <http_log.h>

#define POLICY "<?xml version=\"1.0\"?>\n" \
               "<!DOCTYPE cross-domain-policy SYSTEM\n" \
               "\"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n" \
               "<cross-domain-policy>\n" \
               "<allow-access-from domain=\"*\" to-ports=\"8080\"/>\n" \
               "</cross-domain-policy>\0"

static int socket_policy_handler(conn_rec *conn) {
        apr_bucket_brigade *bb;
        apr_bucket *b;
        apr_status_t rv;

        bb = apr_brigade_create(conn->pool, conn->bucket_alloc);

        b = apr_bucket_immortal_create(POLICY, sizeof(POLICY),
bb->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(bb, b);

        b = apr_bucket_flush_create(conn->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(bb, b);

        b = apr_bucket_eos_create(bb->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(bb, b);

        rv = ap_pass_brigade(conn->output_filters, bb);
        if (rv != APR_SUCCESS) {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0,
conn->base_server, "output error");
                return DECLINED;
        }

        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, conn->base_server,
            "served socket policy to %s", conn->remote_ip);
        return OK;
}

static void register_hooks(apr_pool_t *pool) {
        ap_hook_process_connection(socket_policy_handler, NULL, NULL,
APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA socket_policy_module = {
        STANDARD20_MODULE_STUFF,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        register_hooks
};

Mime
View raw message