Exemple #1
0
static ib_status_t modbinradix_init(ib_engine_t *ib,
                                    ib_module_t *m,
                                    void        *cbdata)
{
    IB_FTRACE_INIT();
    ib_status_t rc;

    /* Register as a matcher provider. */
    rc = ib_provider_register(ib,
                              IB_PROVIDER_TYPE_MATCHER,
                              MODULE_NAME_STR,
                              NULL,
                              &modbinradix_matcher_iface,
                              modbinradix_provider_instance_init);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     MODULE_NAME_STR ": Error registering ac matcher provider: "
                     "%s", ib_status_to_string(rc));
        IB_FTRACE_RET_STATUS(IB_OK);
    }

    ib_log_debug(ib, "AC Status: compiled=\"%d.%d %s\" BinRadix Matcher"
                        " registered", AC_MAJOR, AC_MINOR,
                        IB_XSTRINGIFY(AC_DATE));

    IB_FTRACE_RET_STATUS(IB_OK);
}
Exemple #2
0
static ib_status_t modpcre_init(ib_engine_t *ib,
                                ib_module_t *m,
                                void        *cbdata)
{
    IB_FTRACE_INIT();
    ib_status_t rc;

    /* Register as a matcher provider. */
    rc = ib_provider_register(ib,
                              IB_PROVIDER_TYPE_MATCHER,
                              MODULE_NAME_STR,
                              NULL,
                              &modpcre_matcher_iface,
                              NULL);
    if (rc != IB_OK) {
        ib_log_error(ib,
                     MODULE_NAME_STR
                     ": Error registering pcre matcher provider: "
                     "%s", ib_status_to_string(rc));
        IB_FTRACE_RET_STATUS(IB_OK);
    }

    ib_log_debug(ib,"PCRE Status: compiled=\"%d.%d %s\" loaded=\"%s\"",
        PCRE_MAJOR, PCRE_MINOR, IB_XSTRINGIFY(PCRE_DATE), pcre_version());

    /* Register operators. */
    ib_operator_register(ib,
                         "pcre",
                         (IB_OP_FLAG_PHASE | IB_OP_FLAG_CAPTURE),
                         pcre_operator_create,
                         NULL,
                         pcre_operator_destroy,
                         NULL,
                         pcre_operator_execute,
                         NULL);

    /* An alias of pcre. The same callbacks are registered. */
    ib_operator_register(ib,
                         "rx",
                         (IB_OP_FLAG_PHASE | IB_OP_FLAG_CAPTURE),
                         pcre_operator_create,
                         NULL,
                         pcre_operator_destroy,
                         NULL,
                         pcre_operator_execute,
                         NULL);

    /* Register a pcre operator that uses pcre_dfa_exec to match streams. */
    ib_operator_register(ib,
                         "dfa",
                         (IB_OP_FLAG_PHASE | IB_OP_FLAG_STREAM),
                         dfa_operator_create,
                         NULL,
                         dfa_operator_destroy,
                         NULL,
                         dfa_operator_execute,
                         NULL);

    IB_FTRACE_RET_STATUS(IB_OK);
}
Exemple #3
0
/**
 * Initializes and configures the ironbee engine.
 */
static int ironbee_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptmp,
                             server_rec *s)
{
    ironbee_config_t *modcfg =
        (ironbee_config_t *)ap_get_module_config(s->module_config,
                                                 &ironbee_module);
    ib_cfgparser_t *cp;
    ib_provider_t *lpr;
    void *init = NULL;
    ib_status_t rc;


    /* Init IB library. */
    rc = ib_initialize();
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error initializing ib library");
        return OK;
    }

    ib_util_log_level(4);

    /* Detect first (validation) run vs real config run. */
    apr_pool_userdata_get(&init, "ironbee-init", s->process->pool);
    if (init == NULL) {
        ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
                     MODULE_NAME_FULL " loading.");

        apr_pool_userdata_set((const void *)1, "ironbee-init",
                              apr_pool_cleanup_null, s->process->pool);

        return OK;
    }

    /// @todo Tracefile needs removed
    //ib_trace_init("/tmp/ironbee.trace");
    ib_trace_init(NULL);

    /* Create the engine handle. */
    rc = ib_engine_create(&ironbee, &ibplugin);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error creating engine: %d", rc);
        return OK;
    }

    /* Register the logger. */
    rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER,
                              MODULE_NAME_STR, &lpr,
                              &ironbee_logger_iface,
                              NULL);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error registering log provider: %d", rc);
        return OK;
    }
    ib_provider_data_set(lpr, (void *)s);

    /* Default logger */
    /// @todo Need to add a post set hook in core for this to work correctly
    ib_context_set_string(ib_context_engine(ironbee),
                          IB_PROVIDER_TYPE_LOGGER,
                          MODULE_NAME_STR);
    ib_context_set_num(ib_context_engine(ironbee),
                       IB_PROVIDER_TYPE_LOGGER ".log_level",
                       4);


    rc = ib_engine_init(ironbee);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error initializing engine: %d", rc);
        return OK;
    }

    /* Register module cleanup. */
    apr_pool_cleanup_register(p, (void *)s, ironbee_module_cleanup,
                              apr_pool_cleanup_null);

    /* Register conn/tx init hooks. */
    ib_hook_register(ironbee, conn_opened_event,
                     (ib_void_fn_t)ironbee_conn_init, s);

    /* Configure the engine. */
    if (modcfg->config != NULL) {
        ib_context_t *ctx;

        /* Notify the engine that the config process has started. This
         * will also create a main configuration context.
         */
        ib_state_notify_cfg_started(ironbee);

        /* Get the main configuration context. */
        ctx = ib_context_main(ironbee);

        /* Set some defaults */
        ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, MODULE_NAME_STR);
        ib_context_set_num(ctx, "logger.log_level", 4);

        /* Parse the config file. */
        rc = ib_cfgparser_create(&cp, ironbee);
        if ((rc == IB_OK) && (cp != NULL)) {
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                         IB_PRODUCT_NAME ": Parsing config: %s",
                         modcfg->config);
            ib_cfgparser_parse(cp, modcfg->config);
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                         IB_PRODUCT_NAME ": Destroying config parser");
            ib_cfgparser_destroy(cp);
        }

        /* Notify the engine that the config process has finished. This
         * will also close out the main configuration context.
         */
        ib_state_notify_cfg_finished(ironbee);
    }
    else {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": No config specified with IronBeeConfig directive");
    }

    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
                 MODULE_NAME_FULL " configured.");

    return OK;
}
Exemple #4
0
static int ironbee_init(const char *configfile, const char *logfile)
{
  /* grab from httpd module's post-config */
  ib_status_t rc;
//  ib_provider_t *lpr;
  ib_cfgparser_t *cp;
  ib_context_t *ctx;
  int rv;

  rc = ib_initialize();
  if (rc != IB_OK) {
    return rc;
  }

  ib_util_log_level(9);

  ib_trace_init(TRACEFILE);

  rc = ib_engine_create(&ironbee, &ibplugin);
  if (rc != IB_OK) {
    return rc;
  }

  rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts",
                            NULL, &ironbee_logger_iface, NULL);
  if (rc != IB_OK) {
    return rc;
  }

  ib_context_set_string(ib_context_engine(ironbee),
                        IB_PROVIDER_TYPE_LOGGER, "ironbee-ts");
  ib_context_set_num(ib_context_engine(ironbee),
                     IB_PROVIDER_TYPE_LOGGER ".log_level", 4);

  rc = ib_engine_init(ironbee);
  if (rc != IB_OK) {
    return rc;
  }

  /* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined.
   * It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641).
   */
  rv = TSTextLogObjectCreate(logfile, TS_LOG_MODE_ADD_TIMESTAMP, &ironbee_log);
  if (rv != TS_SUCCESS) {
    return IB_OK + rv;
  }
   
  rc = atexit(ibexit);
  if (rc != 0) {
    return IB_OK + rv;
  }

  ib_hook_register(ironbee, conn_opened_event,
                   (ib_void_fn_t)ironbee_conn_init, NULL);


  ib_state_notify_cfg_started(ironbee);
  ctx = ib_context_main(ironbee);

  ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts");
  ib_context_set_num(ctx, "logger.log_level", 4);

  rc = ib_cfgparser_create(&cp, ironbee);
  if (rc != IB_OK) {
    return rc;
  }
  if (cp != NULL) {  // huh?
    ib_cfgparser_parse(cp, configfile);
    ib_cfgparser_destroy(cp);
  }
  ib_state_notify_cfg_finished(ironbee);


  return IB_OK;
}