ib_status_t rules_lua_init(ib_engine_t *ib, ib_module_t *module) { assert(ib != NULL); assert(module != NULL); ib_status_t rc; modlua_rules_cbdata_t *modlua_rules_cbdata = NULL; ib_mm_t mm = ib_engine_mm_main_get(ib); /* Build an initialize callback struct for Lua Rules. */ modlua_rules_cbdata = ib_mm_calloc(mm, 1, sizeof(*modlua_rules_cbdata)); if (modlua_rules_cbdata == NULL) { ib_log_error(ib, "Failed to create Lua Rules callback data."); return IB_EALLOC; } modlua_rules_cbdata->module = module; /* Register driver. */ rc = ib_rule_register_external_driver( ib, "lua", modlua_rule_driver, modlua_rules_cbdata ); if (rc != IB_OK) { ib_log_error(ib, "Failed to register lua rule driver."); return rc; } return IB_OK; }
/** * Create an instance of the @c ee_match_any operator. * * Looks up the automata name and adds the automata to the operator instance. * * @param[in] ctx Current context. * @param[in] parameters Automata name. * @param[out] instance_data Instance data. * @param[in] cbdata Callback data. */ static ib_status_t ee_match_any_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_status_t rc; ia_eudoxus_t* eudoxus; ee_operator_data_t *operator_data; ib_module_t *module; ib_engine_t *ib = ib_context_get_engine(ctx); ib_mpool_t *pool = ib_context_get_mpool(ctx); const ee_config_t *config = ee_get_config(ib); const ib_hash_t *eudoxus_pattern_hash; assert(config != NULL); assert(config->eudoxus_pattern_hash != NULL); /* 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 eudoxus operator module object: %s", 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; } eudoxus_pattern_hash = config->eudoxus_pattern_hash; rc = ib_hash_get(eudoxus_pattern_hash, &eudoxus, parameters); if (rc == IB_ENOENT ) { ib_log_error(ib, MODULE_NAME_STR ": No eudoxus automata named %s found.", parameters); return rc; } else if (rc != IB_OK) { ib_log_error(ib, MODULE_NAME_STR ": Error setting up eudoxus automata operator."); return rc; } operator_data->eudoxus = eudoxus; *(ee_operator_data_t **)instance_data = operator_data; ib_log_debug(ib, "Found compiled eudoxus pattern \"%s\"", parameters); return IB_OK; }
static ib_status_t sqli_op_create( ib_context_t *ctx, ib_mm_t mm, const char *parameters, void *instance_data, void *cbdata ) { ib_engine_t *ib = ib_context_get_engine(ctx); ib_status_t rc; ib_module_t *m = (ib_module_t *)cbdata; const char *set_name; size_t set_name_len; const sqli_module_config_t *cfg = NULL; const sqli_fingerprint_set_t *ps = NULL; if (parameters == NULL) { ib_log_error(ib, "Missing parameter for operator sqli"); return IB_EINVAL; } set_name = parameters; set_name_len = strlen(parameters); if (set_name[0] == '\'') { ++set_name; --set_name_len; } if (set_name[set_name_len-1] == '\'') { --set_name_len; } if (strncmp("default", set_name, set_name_len) == 0) { *(const sqli_fingerprint_set_t **)instance_data = NULL; return IB_OK; } rc = ib_context_module_config(ctx, m, &cfg); assert(rc == IB_OK); if (cfg->fingerprint_sets == NULL) { rc = IB_ENOENT; } else { rc = ib_hash_get_ex(cfg->fingerprint_sets, &ps, set_name, set_name_len); } if (rc == IB_ENOENT) { ib_log_error(ib, "No such fingerprint set: %s", parameters); return IB_EINVAL; } assert(rc == IB_OK); assert(ps != NULL); *(const sqli_fingerprint_set_t **)instance_data = ps; return IB_OK; }
/** * Add a prefix to the prefixes of the binradix, given a prefix and * callback + extra arg * * @param mpr matcher provider * @param prefixes pointer to the prefix container (i.e.: an BinRadix tree) * @param prefix the prefix to be added * @param callback the callback to register with the given prefix * @param arg the extra argument to pass to the callback * @param errptr a pointer reference to point where an error occurred * @param erroffset a pointer holding the offset of the error * * @return status of the operation */ static ib_status_t modbinradix_add_prefix_ex(ib_provider_inst_t *mpi, void *prefixes, const char *prefix, ib_void_fn_t callback, void *arg, const char **errptr, int *erroffset) { IB_FTRACE_INIT(); ib_status_t rc; ib_radix_t *binradix_tree = (ib_radix_t *)mpi->data; modbinradix_content_t *mrc = NULL; mrc = (modbinradix_content_t *)ib_mpool_calloc(mpi->pr->mp, 1, sizeof(modbinradix_content_t)); if (mrc == NULL) { ib_log_error(mpi->pr->ib, "Failed to allocate modbinradix_content_t" " for %s to the BinRadix tree %x", prefix, binradix_tree); IB_FTRACE_RET_STATUS(IB_EALLOC); } mrc->data = arg; mrc->callback = (modbinradix_callback_t)callback; ib_radix_prefix_t *pre = NULL; rc = ib_radix_ip_to_prefix(prefix, &pre, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, "Failed to create a binradix prefix for %s" " to the BinRadix tree %x", prefix, binradix_tree); IB_FTRACE_RET_STATUS(rc); } rc = ib_radix_insert_data(binradix_tree, pre, (void *) mrc); if (rc == IB_OK) { ib_log_debug(mpi->pr->ib, "prefix %s added to the BinRadix tree %x", prefix, binradix_tree); } else { ib_log_error(mpi->pr->ib, "Failed to load prefix %s to the BinRadix " "tree %x", prefix, binradix_tree); } IB_FTRACE_RET_STATUS(rc); }
/** * Initialize a provider instance with the given data * * @param mpi provider instance * @param extra data * * @return status of the operation */ static ib_status_t modradix_provider_instance_init(ib_provider_inst_t *mpi, void *data) { IB_FTRACE_INIT(modradix_provider_instance_init); ib_status_t rc; modradix_provider_data_t *dt; dt = (modradix_provider_data_t *) ib_mpool_calloc(mpi->mp, 1, sizeof(modradix_provider_data_t)); if (dt == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rc = ib_radix_new((ib_radix_t **)&dt->radix_tree, NULL, NULL, NULL, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, 4, "Unable to create the Radix tree at " "modradix"); IB_FTRACE_RET_STATUS(rc); } mpi->data = dt; IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t DLL_PUBLIC ib_cfgparser_block_pop(ib_cfgparser_t *cp, const char **pname) { IB_FTRACE_INIT(ib_cfgparser_block_pop); ib_engine_t *ib = cp->ib; const char *name; ib_status_t rc; if (pname != NULL) { *pname = NULL; } rc = ib_list_pop(cp->block, &name); if (rc != IB_OK) { ib_log_error(ib, 4, "Failed to pop block: %d", rc); cp->cur_blkname = NULL; IB_FTRACE_RET_STATUS(rc); } if (pname != NULL) { *pname = name; } /* The last in the list is now the current. */ cp->cur_blkname = (const char *)ib_list_node_data(ib_list_last(cp->block)); IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_cfgparser_context_pop(ib_cfgparser_t *cp, ib_context_t **pctx) { IB_FTRACE_INIT(ib_cfgparser_context_pop); ib_engine_t *ib = cp->ib; ib_context_t *ctx; ib_status_t rc; if (pctx != NULL) { *pctx = NULL; } /* Remove the last item. */ rc = ib_list_pop(cp->stack, &ctx); if (rc != IB_OK) { ib_log_error(ib, 4, "Failed to pop context: %d", rc); IB_FTRACE_RET_STATUS(rc); } if (pctx != NULL) { *pctx = ctx; } /* The last in the list is now the current. */ ctx = (ib_context_t *)ib_list_node_data(ib_list_last(cp->stack)); cfgp_set_current(cp, ctx); ib_log_debug(ib, 9, "Stack: ctx=%p site=%p(%s) loc=%p(%s)", cp->cur_ctx, cp->cur_site, cp->cur_site?cp->cur_site->name:"NONE", cp->cur_loc, cp->cur_loc?cp->cur_loc->path:"/"); IB_FTRACE_RET_STATUS(IB_OK); }
/** * @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); }
ib_status_t core_audit_write_header(ib_provider_inst_t *lpi, ib_auditlog_t *log) { IB_FTRACE_INIT(); core_audit_cfg_t *cfg = (core_audit_cfg_t *)log->cfg_data; char header[256]; size_t hlen; int ret = snprintf(header, sizeof(header), "MIME-Version: 1.0\r\n" "Content-Type: multipart/mixed; boundary=%s\r\n" "\r\n" "This is a multi-part message in MIME format.\r\n" "\r\n", cfg->boundary); if ((size_t)ret >= sizeof(header)) { /* Did not fit in buffer. Since this is currently a more-or-less * fixed size, we abort here as this is a programming error. */ abort(); } hlen = strlen(header); if (fwrite(header, hlen, 1, cfg->fp) != 1) { ib_log_error(lpi->pr->ib, "Failed to write audit log header"); IB_FTRACE_RET_STATUS(IB_EUNKNOWN); } fflush(cfg->fp); IB_FTRACE_RET_STATUS(IB_OK); }
/** * * Log to debug log * * Lua parameter stack: * 1) engine handle * 3) format * 4) ... * * @param L Lua state */ static int log_debug(lua_State *L) { ib_engine_t *ib = (ib_engine_t *)lua_topointer(L, 1); int nargs = lua_gettop(L); const char *msg; int ec; /* * Call string.format() to do the actual formatting. * * This is done as lua cannot bind a vararg C function. Instead, * this reorganizes the stack, replacing the "level" arg with the * format function, then calls string.format with the remaining args. * This allows string.format to do the formatting so that a single * string arg can be passed to the underlying ironbee log function. */ /// @todo Store the format function for faster access??? lua_getglobal(L, "string"); lua_getfield(L, -1, "format"); /* string.format() */ lua_pop(L, 1); /* cleanup the stack used to find string table */ ec = lua_pcall(L, (nargs - 2), 1, 0); /* format(fmt, ...) */ if (ec != 0) { ib_log_error(ib, "Failed to exec string.format - %s (%d)", lua_tostring(L, -1), ec); return 0; } msg = lua_tostring(L, -1); /* formatted string */ /* Call the ironbee API with the formatted message. */ ib_log_debug(ib, "%s", msg); return 1; }
ib_status_t ibpp_caught_std_exception( ib_engine_t* engine, ib_status_t status, const std::exception& e ) { if (status == IB_EALLOC) { return status; } std::string message; if (status == IB_EINVAL) { message = "Invalid argument: "; } else { message = "Unknown std::exception thrown: "; } message += e.what(); if (engine) { ib_log_error(engine, "%s", message.c_str()); } else { ib_util_log_error("%s", message.c_str()); } return status; }
ib_status_t core_audit_write_header(ib_engine_t *ib, ib_auditlog_t *log) { ib_core_audit_cfg_t *cfg = (ib_core_audit_cfg_t *)log->cfg_data; char header[256]; size_t hlen; int ret = snprintf(header, sizeof(header), "MIME-Version: 1.0\r\n" "Content-Type: multipart/mixed; boundary=%s\r\n" "X-IronBee-AuditLog: type=multipart; version=%d\r\n" "\r\n" "This is a multi-part message in MIME format.\r\n" "\r\n", cfg->boundary, IB_AUDITLOG_VERSION); if ((size_t)ret >= sizeof(header)) { /* Did not fit in buffer. Since this is currently a more-or-less * fixed size, we abort here as this is a programming error. */ abort(); } hlen = strlen(header); if (fwrite(header, hlen, 1, cfg->fp) != 1) { ib_log_error(ib, "Failed to write audit log header."); return IB_EUNKNOWN; } fflush(cfg->fp); return IB_OK; }
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); }
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); }
/** * Feed data to the automata. * * @param[in] ib IronBee engine; used for logging. * @param[in] eudoxus Eudoxus engine; used for ia_eudoxus_error(). * @param[in] state Current Eudoxus execution state; updated. * @param[in] data Data to send to automata. * @param[in] data_length Length of @a data. * @return * - IB_OK on success. * - IB_EINVAL on IronAutomata failure; will emit log message. */ static ib_status_t fast_feed( const ib_engine_t *ib, const ia_eudoxus_t *eudoxus, ia_eudoxus_state_t *state, const uint8_t *data, size_t data_length ) { assert(ib != NULL); assert(eudoxus != NULL); assert(state != NULL); assert(data != NULL); ia_eudoxus_result_t irc; irc = ia_eudoxus_execute(state, data, data_length); if (irc != IA_EUDOXUS_OK) { ib_log_error( ib, "fast: Eudoxus Execution Failure: %s", fast_eudoxus_error(eudoxus) ); return IB_EINVAL; } return IB_OK; }
ib_status_t core_audit_write_part(ib_engine_t *ib, ib_auditlog_part_t *part) { ib_auditlog_t *log = part->log; ib_core_audit_cfg_t *cfg = (ib_core_audit_cfg_t *)log->cfg_data; const uint8_t *chunk; size_t chunk_size; /* Write the MIME boundary and part header */ fprintf(cfg->fp, "\r\n--%s" "\r\nContent-Disposition: audit-log-part; name=\"%s\"" "\r\nContent-Transfer-Encoding: binary" "\r\nContent-Type: %s" "\r\n\r\n", cfg->boundary, part->name, part->content_type); /* Write the part data. */ while((chunk_size = part->fn_gen(part, &chunk)) != 0) { if (fwrite(chunk, chunk_size, 1, cfg->fp) != 1) { ib_log_error(ib, "Failed to write audit log part."); fflush(cfg->fp); return IB_EUNKNOWN; } cfg->parts_written++; } /* Finish the part. */ fflush(cfg->fp); return IB_OK; }
static ib_status_t ib_errclose_callback( ib_conn_t *conn, ib_tx_t *tx, void *cbdata) { ib_log_error(conn->ib, "BLOCK BY CLOSE NOT IMPLEMENTED."); return IB_ENOTIMPL; }
static ib_status_t ib_errclose_callback( ib_conn_t *conn, ib_tx_t *tx, void *cbdata) { ib_log_error(conn->ib, "Block by close not implemented."); return IB_ENOTIMPL; }
/** * Called by IronBee when a connection should be blocked by closing the conn. * * If this returns not-IB_OK a block by status code will be attempted. * * @param[in] conn The connection to close. * @param[in] tx The transaction, if available. If a transaction is * not available, this will be NULL. * @param[in] cbdata Callback data. * * @returns * - IB_OK on success. */ static ib_status_t ib_errclose_callback( ib_conn_t *conn, ib_tx_t *tx, void *cbdata) { ib_log_error(conn->ib, "Block by close not implemented; returning Internal Error."); return ib_error_callback(tx, 500, cbdata); }
static ib_status_t cpy_psntsfw_cfg( ib_engine_t *ib, ib_mpool_t *mp, ib_mpool_t *local_mp, const ib_persist_fw_cfg_t *persist_fw_src, ib_persist_fw_cfg_t **persist_fw_dst ) { assert(ib != NULL); assert(mp != NULL); assert(local_mp != NULL); assert(persist_fw_src != NULL); assert(persist_fw_dst != NULL); ib_list_t *list = NULL; ib_list_node_t *list_node; ib_status_t rc; ib_persist_fw_cfg_t *persist_fw_out; rc = ib_persist_fw_cfg_create(mp, &persist_fw_out); if (rc != IB_OK) { ib_log_error(ib, "Failed to create new persist_fw_cfg."); return rc; } rc = ib_list_create(&list, local_mp); if (rc != IB_OK) { return rc; } /* Copy the src store hash to the dst store hash. */ if (ib_hash_size(persist_fw_src->stores) > 0) { rc = ib_hash_get_all(persist_fw_src->stores, list); if (rc != IB_OK) { ib_log_error(ib, "Failed to get entries from hash."); return rc; } IB_LIST_LOOP(list, list_node) { ib_persist_fw_store_t *store = (ib_persist_fw_store_t *)ib_list_node_data_const(list_node); rc = ib_hash_set(persist_fw_out->stores, store->name, store); if (rc != IB_OK) { ib_log_error(ib, "Failed to set store %s", store->name); return rc; } }
/** * Perf Event Start Event Callback. * * On a connection started event we register connection * counters for the connection. * * @param[in] ib IronBee object. * @param[in] event Event type. * @param[in] connp Connection object. * @param[in] cbdata Callback data: actually an perf_info_t describing the * event. */ static ib_status_t mod_perf_stats_reg_conn_counter( ib_engine_t *ib, ib_state_event_type_t event_type, ib_conn_t *connp, void *cbdata ) { IB_FTRACE_INIT(); perf_info_t *perf_info; event_info_t *eventp = (event_info_t *)cbdata; int cevent = eventp->number; int rc; int event; perf_info = ib_mpool_alloc(connp->mp, sizeof(*perf_info) * IB_STATE_EVENT_NUM); for (event = 0; event < IB_STATE_EVENT_NUM; ++event) { if ((eventp->cbdata_type == IB_CBDATA_NONE) || (eventp->cbdata_type == IB_CBDATA_CONN_DATA_T)) { ib_log_error(ib, "Cannot collect stats for:%d name:%s cbdata_type: %d", eventp->number, eventp->name, eventp->cbdata_type); } else { perf_info_t *perfp = &perf_info[event]; /* Does this event match conn_started_event? * If so we should init counters for this event. */ if (event == cevent) { perfp->call_cnt = 1; perfp->start_usec = ib_clock_get_time(); } else { perfp->call_cnt = 0; perfp->start_usec = 0; } /* Setup other defaults */ perfp->number = event; perfp->name = ib_state_event_name((ib_state_event_type_t)event); perfp->cbdata_type = ib_state_event_cbdata_type(event); perfp->max_usec = 0; perfp->total_usec = 0; perfp->stop_usec = 0; ib_log_debug(ib, "Perf callback registered %s (%d) (%d)", perfp->name, perfp->number, perfp->cbdata_type); } } rc = ib_hash_set(connp->data, "MOD_PERF_STATS" ,perf_info); if (rc != IB_OK) { ib_log_debug(ib, "Failed to store perf stats in connection data: %s", ib_status_to_string(rc)); IB_FTRACE_RET_STATUS(rc); } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_core_collection_managers_register( ib_engine_t *ib, const ib_module_t *module) { assert(ib != NULL); assert(module != NULL); const char *pattern = "^([^\\s=]+)=(.*)$"; const int compile_flags = PCRE_DOTALL | PCRE_DOLLAR_ENDONLY; pcre *compiled; const char *error; int eoff; ib_status_t rc; const ib_collection_manager_t *manager; /* Register the name/value pair InitCollection manager */ rc = ib_collection_manager_register( ib, module, "core name/value pair", "vars:", core_managed_collection_vars_register_fn, NULL, NULL, NULL, core_managed_collection_vars_populate_fn, NULL, NULL, NULL, &manager); if (rc != IB_OK) { ib_log_alert(ib, "Failed to register core name/value pair handler: %s", ib_status_to_string(rc)); return rc; } /* Compile the name/value pair pattern */ compiled = pcre_compile(pattern, compile_flags, &error, &eoff, NULL); if (compiled == NULL) { ib_log_error(ib, "Failed to compile pattern \"%s\": %s", pattern, error ? error : "(null)"); return IB_EUNKNOWN; } core_vars_manager.pattern = compiled; core_vars_manager.manager = manager; #if ENABLE_JSON /* Register the JSON file InitCollection manager */ rc = ib_collection_manager_register( ib, module, "core JSON file", "json-file://", core_managed_collection_jsonfile_register_fn, NULL, NULL, NULL, core_managed_collection_jsonfile_populate_fn, NULL, core_managed_collection_jsonfile_persist_fn, NULL, &manager); if (rc != IB_OK) { ib_log_alert(ib, "Failed to register core JSON file handler: %s", ib_status_to_string(rc)); return rc; } #endif return IB_OK; }
/** * 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); }
/** * Add a pattern to the patterns of the matcher given a pattern and * callback + extra arg * * @param mpr matcher provider * @param patterns pointer to the pattern container (ie: an AC tree) * @param patt the pattern to be added * @param callback the callback to register with the given pattern * @param arg the extra argument to pass to the callback * @param errptr a pointer reference to point where an error ocur * @param erroffset a pointer holding the offset of the error * * @return status of the operation */ static ib_status_t modac_add_pattern_ex(ib_provider_inst_t *mpi, void *patterns, const char *patt, ib_void_fn_t callback, void *arg, const char **errptr, int *erroffset) { IB_FTRACE_INIT(modac_add_pattern_ex); ib_status_t rc; ib_ac_t *ac_tree = (ib_ac_t *)((modac_provider_data_t*)mpi->data)->ac_tree; /* If the ac_tree doesn't exist, create it before adding the pattern */ if (ac_tree == NULL) { rc = ib_ac_create(&ac_tree, 0, mpi->mp); if (rc != IB_OK || ac_tree == NULL) { ib_log_error(mpi->pr->ib, 4, "Unable to create the AC tree at modac"); IB_FTRACE_RET_STATUS(rc); } ((modac_provider_data_t*)mpi->data)->ac_tree = ac_tree; } rc = ib_ac_add_pattern(ac_tree, patt, (ib_ac_callback_t)callback, arg, 0); if (rc == IB_OK) { ib_log_debug(mpi->pr->ib, 4, "pattern %s added to the AC tree %x", patt, ac_tree); } else { ib_log_error(mpi->pr->ib, 4, "Failed to load pattern %s to the AC tree %x", patt, ac_tree); } IB_FTRACE_RET_STATUS(rc); }
ib_status_t DLL_PUBLIC ib_cfgparser_block_push(ib_cfgparser_t *cp, const char *name) { IB_FTRACE_INIT(ib_cfgparser_block_push); ib_engine_t *ib = cp->ib; ib_status_t rc; rc = ib_list_push(cp->block, (void *)name); if (rc != IB_OK) { ib_log_error(ib, 4, "Failed to push block %p: %d", name, rc); IB_FTRACE_RET_STATUS(rc); } cp->cur_blkname = name; IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ibpp_caught_unknown_exception( ib_engine_t* engine ) { if (engine) { ib_log_error(engine, "%s", "Completely unknown exception thrown. " "Please report as bug." ); } else { ib_util_log_error("%s", "Completely unknown exception thrown. " "Please report as bug." ); } return IB_EUNKNOWN; }
/** * @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 dfa_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; dfa_rule_data_t *rule_data = NULL; ib_status_t rc; rc = dfa_compile_internal(pool, &rule_data, pattern, &errptr, &erroffset); if (rc==IB_OK) { ib_log_debug(ib, "Compiled DFA operator pattern: %s", pattern); /* We compute the length of the string buffer as such: * +2 for the 0x prefix. * +1 for the \0 string terminations. * +16 for encoding 8 bytes (64 bits) as hex-pairs (2 chars / byte). */ size_t id_sz = 16 + 2 + 1; char *id; id = ib_mpool_alloc(pool, id_sz); snprintf(id, id_sz, "%p", op_inst); rule_data->id = id; ib_log_debug(ib, "Created DFA operator with ID %s.", id); op_inst->data = rule_data; } else { ib_log_error(ib, "Failed to parse DFA operator pattern: %s", pattern); } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_cfgparser_context_push(ib_cfgparser_t *cp, ib_context_t *ctx) { IB_FTRACE_INIT(ib_cfgparser_context_push); ib_engine_t *ib = cp->ib; ib_status_t rc; rc = ib_list_push(cp->stack, ctx); if (rc != IB_OK) { ib_log_error(ib, 4, "Failed to push context %p: %d", ctx, rc); IB_FTRACE_RET_STATUS(rc); } cfgp_set_current(cp, ctx); ib_log_debug(ib, 9, "Stack: ctx=%p site=%p(%s) loc=%p(%s)", cp->cur_ctx, cp->cur_site, cp->cur_site?cp->cur_site->name:"NONE", cp->cur_loc, cp->cur_loc?cp->cur_loc->path:"/"); IB_FTRACE_RET_STATUS(IB_OK); }
/** * Initialize a provider instance with the given data * * @param mpi provider instance * @param extra data * * @return status of the operation */ static ib_status_t modac_provider_instance_init(ib_provider_inst_t *mpi, void *data) { IB_FTRACE_INIT(modac_provider_instance_init); ib_status_t rc; modac_provider_data_t *dt; dt = (modac_provider_data_t *) ib_mpool_calloc(mpi->mp, 1, sizeof(modac_provider_data_t)); if (dt == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } mpi->data = (void *)dt; rc = ib_ac_create(&dt->ac_tree, 0, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, 4, "Unable to create the AC tree at modac"); } IB_FTRACE_RET_STATUS(rc); }
/** * @internal * Handle a PocSigTrace directive. * * @param cp Config parser * @param name Directive name * @param p1 First parameter * @param cbdata Callback data (from directive registration) * * @returns Status code */ static ib_status_t pocsig_dir_trace(ib_cfgparser_t *cp, const char *name, const char *p1, void *cbdata) { IB_FTRACE_INIT(pocsig_dir_trace); ib_engine_t *ib = cp->ib; ib_context_t *ctx = cp->cur_ctx ? cp->cur_ctx : ib_context_main(ib); ib_status_t rc; ib_log_debug(ib, 7, "%s: \"%s\" ctx=%p", name, p1, ctx); if (strcasecmp("On", p1) == 0) { rc = ib_context_set_num(ctx, MODULE_NAME_STR ".trace", 1); IB_FTRACE_RET_STATUS(rc); } else if (strcasecmp("Off", p1) == 0) { rc = ib_context_set_num(ctx, MODULE_NAME_STR ".trace", 0); IB_FTRACE_RET_STATUS(rc); } ib_log_error(ib, 1, "Failed to parse directive: %s \"%s\"", name, p1); IB_FTRACE_RET_STATUS(IB_EINVAL); }