Exemple #1
0
ib_status_t tsib_manager_engine_create(void)
{
    return module_data.manager == NULL
           ? IB_EALLOC
           : ib_manager_engine_create(module_data.manager, IB_MANAGER_ENGINE_NAME_DEFAULT, module_data.config_file);
}
Exemple #2
0
/**
 * IronBee initialization function.  Sets up engine and logging,
 * and reads IronBee config.
 *
 * @param[in]  cf     Configuration rec
 * @return     NGX_OK or error
 */
static ngx_int_t ironbee_init(ngx_conf_t *cf)
{
    ironbee_proc_t *proc;
    ib_status_t rc;
    module_data_t *mod_data = &module_data;
    char *buf;

    /* We still use the global-log hack to initialise */
    ngx_regex_malloc_init(cf->pool);

    ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "ironbee_init %d", getpid());

    proc = ngx_http_conf_get_module_main_conf(cf, ngx_ironbee_module);
    if (proc->log_level == NGX_CONF_UNSET_UINT) {
        proc->log_level = IB_LOG_NOTICE;
    }
    if (proc->max_engines == NGX_CONF_UNSET_UINT) {
        proc->max_engines = IB_MANAGER_DEFAULT_MAX_ENGINES;
    }
    if (proc->use_ngxib_logger == NGX_CONF_UNSET) {
        proc->use_ngxib_logger =1;
    }

    /* initialise fields in mod_data */
    mod_data->ib_log_active = proc->use_ngxib_logger;
    mod_data->log = cf->log;
    mod_data->log_level = proc->log_level;

    rc = ib_initialize();
    if (rc != IB_OK) {
        cleanup_return IB2NG(rc);
    }

    /* Create the IronBee engine manager */
    rc = ib_manager_create(&(mod_data->manager),  /* Engine Manager */
                           ngxib_server(),        /* Server object */
                           proc->max_engines);    /* Max engines */
    if (rc != IB_OK) {
        cleanup_return IB2NG(rc);
    }

    rc = ib_manager_register_module_fn(
        mod_data->manager,
        ngxib_module,
        mod_data);
    if (rc != IB_OK) {
        cleanup_return IB2NG(rc);
    }

    /* Null manager here would be a bug, as per RNS-CR-143 comments */
    assert(mod_data->manager != NULL);

    /* FIXME - use the temp pool operation for this */
    buf = strndup((char*)proc->config_file.data, proc->config_file.len);

    /* Create the initial engine */
    rc = ib_manager_engine_create(mod_data->manager, buf);
    if (rc != IB_OK) {
        free(buf);
        cleanup_return IB2NG(rc);
    }
    free(buf);

    cleanup_return rc == IB_OK ? NGX_OK : IB2NG(rc);
}
Exemple #3
0
/**
 * Initialize IronBee for ATS.
 *
 * Performs IB initializations for the ATS plugin.
 *
 * @param[in] mod_data Global module data
 *
 * @returns status
 */
static int ironbee_init(module_data_t *mod_data)
{
    /* grab from httpd module's post-config */
    ib_status_t rc;
    int rv;

    /* Create the channel. This is destroyed when the manager is destroyed. */
    rc = ib_engine_manager_control_channel_create(
        &(mod_data->manager_ctl),
        ib_manager_mm(mod_data->manager),
        mod_data->manager);
    if (rc != IB_OK) {
        TSError("[ironbee] Error creating IronBee control channel: %s",
            ib_status_to_string(rc));
        return rc;
    }

    /* Register the control commands (enable, disable, etc).
     * Failure is not fatal. */
    rc = ib_engine_manager_control_manager_ctrl_register(mod_data->manager_ctl);
    if (rc != IB_OK) {
        TSError("[ironbee] Failed to register ctrl commands to ctrl channel.");
    }

    /* Register the diagnostic commands (version and valgrind).
     * Failure is not fatal.
     * The valgrind command does nothing when not compiled w/ valgrind. */
    rc = ib_engine_manager_control_manager_diag_register(mod_data->manager_ctl);
    if (rc != IB_OK) {
        TSError("[ironbee] Failed to register diag commands to ctrl channel.");
    }

    /* Start the channel. This is stopped when it is destroyed. */
    rc = ib_engine_manager_control_channel_start(mod_data->manager_ctl);
    if (rc != IB_OK) {
        TSError("[ironbee] Error starting IronBee control channel: %s",
            ib_status_to_string(rc));
        /* Note: this is not a fatal error. */
    }
    /* If we started the channel, schedule it for periodic execution. */
    else {
        TSCont cont = TSContCreate(manager_ctl, TSMutexCreate());
        TSContDataSet(cont, mod_data);
        TSContScheduleEvery(
           cont,                          /* Manager control continuation. */
           CONTROL_CHANNEL_POLL_INTERVAL, /* Millisecons. */
           TS_THREAD_POOL_TASK            /* Task thread pool. */
        );
    }

    rc = ib_manager_engine_preconfig_fn_add(
        mod_data->manager,
        engine_preconfig_fn,
        mod_data);
    if (rc != IB_OK) {
        TSError("[ironbee] Error registering server preconfig function: %s",
                ib_status_to_string(rc));
        return rc;
    }

    rc = ib_manager_engine_postconfig_fn_add(
        mod_data->manager,
        engine_postconfig_fn,
        mod_data);
    if (rc != IB_OK) {
        TSError("[ironbee] Error registering server postconfig function: %s",
                ib_status_to_string(rc));
        return rc;
    }

    /* Create the initial engine */
    TSDebug("ironbee", "Creating initial IronBee engine");
    rc = ib_manager_engine_create(mod_data->manager, IB_MANAGER_ENGINE_NAME_DEFAULT, mod_data->config_file);
    if (rc != IB_OK) {
        TSError("[ironbee] Error creating initial IronBee engine: %s",
                ib_status_to_string(rc));
        return rc;
    }

    /* Register our at exit function */
    rv = atexit(ibexit);
    if (rv != 0) {
        TSError("[ironbee] Error registering IronBee exit handler: %s", strerror(rv));
        return IB_EOTHER;
    }

    TSDebug("ironbee", "IronBee Ready");
    return rc;
}
Exemple #4
0
ib_status_t tsib_manager_engine_create(void)
{
    return module_data.manager == NULL
           ? IB_EALLOC
           : ib_manager_engine_create(module_data.manager, module_data.config_file);
}