Beispiel #1
0
/**
 * @brief Create the PCRE operator.
 * @param[in] ib The IronBee engine (unused)
 * @param[in] ctx The current IronBee context (unused)
 * @param[in,out] pool The memory pool into which @c op_inst->data
 *                will be allocated.
 * @param[in] The regular expression to be built.
 * @param[out] op_inst The operator instance that will be populated by
 *             parsing @a pattern.
 * @returns IB_OK on success or IB_EALLOC on any other type of error.
 */
static ib_status_t pcre_operator_create(ib_engine_t *ib,
                                        ib_context_t *ctx,
                                        const ib_rule_t *rule,
                                        ib_mpool_t *pool,
                                        const char *pattern,
                                        ib_operator_inst_t *op_inst)
{
    IB_FTRACE_INIT();
    const char* errptr;
    int erroffset;
    pcre_rule_data_t *rule_data = NULL;
    ib_status_t rc;

    if (pattern == NULL) {
        ib_log_error(ib, "No pattern for %s operator", op_inst->op->name);
        IB_FTRACE_RET_STATUS(IB_EINVAL);
    }
    rc = pcre_compile_internal(ib,
                               pool,
                               &rule_data,
                               pattern,
                               &errptr,
                               &erroffset);

    if (rc==IB_OK) {
        op_inst->data = rule_data;
    }

    IB_FTRACE_RET_STATUS(rc);
}
Beispiel #2
0
/**
 * @param[in] mpr Provider object. This is unused.
 * @param[in] pool The memory pool to allocate memory out of.
 * @param[out] pcpatt When the pattern is successfully compiled
 *             a modpcre_cpatt_t* is stored in *pcpatt.
 * @param[in] patt The uncompiled pattern to match.
 * @param[out] errptr Pointer to an error message describing the failure.
 * @param[out] errorffset The location of the failure, if this fails.
 * @returns IronBee status. IB_EINVAL if the pattern is invalid,
 *          IB_EALLOC if memory allocation fails or IB_OK.
 */
static ib_status_t modpcre_compile(ib_provider_t *mpr,
                                   ib_mpool_t *pool,
                                   void *pcpatt,
                                   const char *patt,
                                   const char **errptr,
                                   int *erroffset)
{
    IB_FTRACE_INIT();

    ib_status_t rc;

    rc = pcre_compile_internal(mpr->ib,
                               pool,
                               (modpcre_cpatt_t **)pcpatt,
                               patt,
                               errptr,
                               erroffset);

    IB_FTRACE_RET_STATUS(rc);

}
Beispiel #3
0
/**
 * Create the PCRE operator.
 *
 * @param[in] ctx Current context.
 * @param[in] parameters Unparsed string with the parameters to
 *                       initialize the operator instance.
 * @param[out] instance_data Instance data.
 * @param[in] cbdata Callback data.
 *
 * @returns IB_OK on success or IB_EALLOC on any other type of error.
 */
static
ib_status_t dfa_operator_create(
    ib_context_t *ctx,
    const char   *parameters,
    void         *instance_data,
    void         *cbdata
)
{
    assert(ctx           != NULL);
    assert(parameters    != NULL);
    assert(instance_data != NULL);

    ib_engine_t *ib = ib_context_get_engine(ctx);
    ib_mpool_t *pool = ib_context_get_mpool(ctx);
    assert(ib != NULL);
    assert(pool != NULL);

    modpcre_cpat_data_t *cpdata;
    modpcre_operator_data_t *operator_data;
    ib_module_t *module;
    modpcre_cfg_t *config;
    ib_status_t rc;
    const char *errptr;
    int erroffset;

    /* Get my module object */
    rc = ib_engine_module_get(ib, MODULE_NAME_STR, &module);
    if (rc != IB_OK) {
        ib_log_error(ib, "Failed to get pcre module object: %s",
                     ib_status_to_string(rc));
        return rc;
    }

    /* Get the context configuration */
    rc = ib_context_module_config(ctx, module, &config);
    if (rc != IB_OK) {
        ib_log_error(ib, "Failed to get pcre module configuration: %s",
                     ib_status_to_string(rc));
        return rc;
    }

    rc = pcre_compile_internal(ib,
                               pool,
                               config,
                               true,
                               &cpdata,
                               parameters,
                               &errptr,
                               &erroffset);

    if (rc != IB_OK) {
        ib_log_error(ib, "Failed to parse DFA operator pattern \"%s\":%s",
                     parameters, ib_status_to_string(rc));
        return rc;
    }

    /* Allocate a rule data object, populate it */
    operator_data = ib_mpool_alloc(pool, sizeof(*operator_data));
    if (operator_data == NULL) {
        return IB_EALLOC;
    }
    operator_data->cpdata = cpdata;
    rc = dfa_id_set(pool, operator_data);
    if (rc != IB_OK) {
        ib_log_error(ib, "Error creating ID for DFA: %s",
                     ib_status_to_string(rc));
        return rc;
    }
    ib_log_debug(ib, "Compiled DFA id=\"%s\" operator pattern \"%s\" @ %p",
                 operator_data->id, parameters, (void *)cpdata->cpatt);

    *(modpcre_operator_data_t **)instance_data = operator_data;
    return IB_OK;
}
Beispiel #4
0
/**
 * Create the PCRE operator.
 *
 * @param[in] ctx Current context.
 * @param[in] parameters Unparsed string with the parameters to
 *                       initialize the operator instance.
 * @param[out] instance_data Instance data.
 * @param[in] cbdata Callback data.
 *
 * @returns IB_OK on success or IB_EALLOC on any other type of error.
 */
static
ib_status_t pcre_operator_create(
    ib_context_t *ctx,
    const char   *parameters,
    void         *instance_data,
    void         *cbdata
)
{
    assert(ctx           != NULL);
    assert(parameters    != NULL);
    assert(instance_data != NULL);

    ib_engine_t *ib = ib_context_get_engine(ctx);
    ib_mpool_t *pool = ib_context_get_mpool(ctx);
    assert(ib != NULL);
    assert(pool != NULL);

    modpcre_cpat_data_t *cpdata = NULL;
    modpcre_operator_data_t *operator_data = NULL;
    ib_module_t *module;
    modpcre_cfg_t *config;
    ib_status_t rc;
    const char *errptr;
    int erroffset;

    if (parameters == NULL) {
        ib_log_error(ib, "No pattern for operator");
        return IB_EINVAL;
    }

    /* Get my module object */
    rc = ib_engine_module_get(ib, MODULE_NAME_STR, &module);
    if (rc != IB_OK) {
        ib_log_error(ib, "Failed to get pcre module object: %s",
                     ib_status_to_string(rc));
        return rc;
    }

    /* Get the context configuration */
    rc = ib_context_module_config(ctx, module, &config);
    if (rc != IB_OK) {
        ib_log_error(ib, "Failed to get pcre module configuration: %s",
                     ib_status_to_string(rc));
        return rc;
    }

    /* Compile the pattern.  Note that the rule data is an alias for
     * the compiled pattern type */
    rc = pcre_compile_internal(ib,
                               pool,
                               config,
                               false,
                               &cpdata,
                               parameters,
                               &errptr,
                               &erroffset);
    if (rc != IB_OK) {
        return rc;
    }

    /* Allocate a rule data object, populate it */
    operator_data = ib_mpool_alloc(pool, sizeof(*operator_data));
    if (operator_data == NULL) {
        return IB_EALLOC;
    }
    operator_data->cpdata = cpdata;
    operator_data->id = NULL;           /* Not needed for rx rules */

    /* Rule data is an alias for the compiled pattern data */
    *(modpcre_operator_data_t **)instance_data = operator_data;

    return rc;
}