Example #1
0
/**
 * Called to initialize the user agent module (when the module is loaded).
 *
 * Registers a handler for the request_header_finished_event event.
 *
 * @param[in,out] ib IronBee object
 * @param[in] m Module object
 * @param[in] cbdata (unused)
 *
 * @returns Status code
 */
static ib_status_t modua_init(ib_engine_t *ib, ib_module_t *m, void *cbdata)
{
    IB_FTRACE_INIT();
    ib_status_t  rc;
    modua_match_rule_t *failed_rule;
    unsigned int failed_frule_num;

    /* Register the user agent callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_user_agent,
                             NULL);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Register the remote address callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_remoteip,
                             NULL);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Initializations */
    rc = modua_ruleset_init(&failed_rule, &failed_frule_num);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     "User agent rule initialization failed"
                     " on rule %s field rule #%d: %s",
                     failed_rule->label, failed_frule_num, ib_status_to_string(rc));
    }

    /* Get the rules */
    modua_match_ruleset = modua_ruleset_get( );
    if (modua_match_ruleset == NULL) {
        ib_log_error(ib, "Failed to get user agent rule list: %s", ib_status_to_string(rc));
        IB_FTRACE_RET_STATUS(rc);
    }
    ib_log_debug(ib,
                 "Found %d match rules",
                 modua_match_ruleset->num_rules);

    IB_FTRACE_RET_STATUS(IB_OK);
}
Example #2
0
/**
 * Called to initialize the user agent module (when the module is loaded).
 *
 * Registers a handler for the request_header_finished_event event.
 *
 * @param[in,out] ib IronBee object
 * @param[in] m Module object
 * @param[in] cbdata (unused)
 *
 * @returns Status code
 */
static ib_status_t modua_init(ib_engine_t *ib, ib_module_t *m, void *cbdata)
{
    ib_status_t  rc;
    modua_match_rule_t *failed_rule;
    unsigned int failed_frule_num;

    /* Register the user agent callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_user_agent,
                             NULL);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Register the remote address callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_remoteip,
                             NULL);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Initializations */
    rc = modua_ruleset_init(&failed_rule, &failed_frule_num);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     "User agent rule initialization failed"
                     " on rule %s field rule #%d: %s",
                     failed_rule->label, failed_frule_num, ib_status_to_string(rc));
    }

    /* Get the rules */
    modua_match_ruleset = modua_ruleset_get( );
    if (modua_match_ruleset == NULL) {
        ib_log_error(ib, "Failed to get user agent rule list: %s", ib_status_to_string(rc));
        return rc;
    }
    ib_log_debug(ib,
                 "Found %d match rules",
                 modua_match_ruleset->num_rules);

    rc = ib_data_register_indexed(ib_engine_data_config_get(ib), "remote_addr");
    if (rc != IB_OK) {
        ib_log_warning(ib,
                       "User agent failed to register \"remote_addr\" as indexed: %s",
                       ib_status_to_string(rc)
                      );
        /* Continue. */
    }

    rc = ib_data_register_indexed(ib_engine_data_config_get(ib), "UA");
    if (rc != IB_OK) {
        ib_log_warning(ib,
                       "User agent failed to register \"UA\" as indexed: %s",
                       ib_status_to_string(rc)
                      );
        /* Continue. */
    }

    return IB_OK;
}
Example #3
0
/**
 * Called to initialize the user agent module (when the module is loaded).
 *
 * Registers a handler for the request_header_finished_event event.
 *
 * @param[in,out] ib IronBee object
 * @param[in] m Module object
 * @param[in] cbdata (unused)
 *
 * @returns Status code
 */
static ib_status_t modua_init(ib_engine_t *ib, ib_module_t *m, void *cbdata)
{
    ib_status_t  rc;
    modua_match_rule_t *failed_rule;
    unsigned int failed_frule_num;

    /* Register the user agent callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_user_agent,
                             m);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Register the remote address callback */
    rc = ib_hook_tx_register(ib, request_header_finished_event,
                             modua_remoteip,
                             m);
    if (rc != IB_OK) {
        ib_log_error(ib, "Hook register returned %s", ib_status_to_string(rc));
    }

    /* Initializations */
    rc = modua_ruleset_init(&failed_rule, &failed_frule_num);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     "User agent rule initialization failed"
                     " on rule %s field rule #%d: %s",
                     failed_rule->label, failed_frule_num, ib_status_to_string(rc));
    }

    /* Get the rules */
    modua_match_ruleset = modua_ruleset_get( );
    if (modua_match_ruleset == NULL) {
        ib_log_error(ib, "Failed to get user agent rule list: %s", ib_status_to_string(rc));
        return rc;
    }
    ib_log_debug(ib,
                 "Found %d match rules",
                 modua_match_ruleset->num_rules);

    rc = ib_var_source_register(
        NULL,
        ib_engine_var_config_get(ib),
        IB_S2SL("remote_addr"),
        IB_PHASE_NONE, IB_PHASE_NONE
    );
    if (rc != IB_OK && rc != IB_EEXIST) {
        ib_log_warning(ib,
            "User agent failed to register \"remote_addr\": %s",
            ib_status_to_string(rc)
        );
        /* Continue. */
    }

    rc = ib_var_source_register(
        NULL,
        ib_engine_var_config_get(ib),
        IB_S2SL("UA"),
        IB_PHASE_NONE, IB_PHASE_NONE
    );
    if (rc != IB_OK) {
        ib_log_warning(ib,
            "User agent failed to register \"UA\": %s",
            ib_status_to_string(rc)
        );
        /* Continue. */
    }

    rc = ib_hook_context_register(ib, context_close_event,
                                  modua_ctx_close, m);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     "Could not register context close hook: %s",
                     ib_status_to_string(rc));
        return rc;
    }

    return IB_OK;
}