/** * Get or create an ib_hash_t inside of @c tx for storing the operator state. * * The hash is stored at the key @c HASH_NAME_STR. * * @param[in] m This module. * @param[in] tx The transaction containing @c tx->data which holds * the @a operator_data object. * @param[out] hash The fetched or created rule data hash. This is set * to NULL on failure. * * @return * - IB_OK on success. * - IB_EALLOC on allocation failure */ static ib_status_t get_or_create_operator_data_hash( const ib_module_t *m, ib_tx_t *tx, ib_hash_t **hash ) { assert(tx != NULL); ib_status_t rc; /* Get or create the hash that contains the rule data. */ rc = ib_tx_get_module_data(tx, m, hash); if ( (rc == IB_OK) && (*hash != NULL) ) { return IB_OK; } rc = ib_hash_create(hash, tx->mm); if (rc != IB_OK) { return rc; } rc = ib_tx_set_module_data(tx, m, *hash); if (rc != IB_OK) { *hash = NULL; } return rc; }
ib_status_t ib_cfgmap_create(ib_cfgmap_t **pcm, ib_mpool_t *pool) { IB_FTRACE_INIT(ib_cfgmap_create); ib_hash_t *hash; ib_status_t rc; /* Underlying hash structure. */ rc = ib_hash_create(&hash, pool); if (rc != IB_OK) { rc = IB_EALLOC; goto failed; } pool = hash->mp; *pcm = (ib_cfgmap_t *)ib_mpool_alloc(pool, sizeof(**pcm)); if (*pcm == NULL) { rc = IB_EALLOC; goto failed; } (*pcm)->mp = pool; (*pcm)->hash = hash; (*pcm)->data = NULL; IB_FTRACE_RET_STATUS(IB_OK); failed: /* Make sure everything is cleaned up on failure. */ *pcm = NULL; IB_FTRACE_RET_STATUS(rc); }
/** * Get or create an ib_hash_t inside of @c tx->data for storing dfa rule data. * * The hash is stored at the key @c MODULE_DATA_STR. * * @param[in] tx The transaction containing @c tx->data which holds * the @a rule_data object. * @param[out] rule_data The fetched or created rule data hash. This is set * to NULL on failure. * * @return * - IB_OK on success. * - IB_EALLOC on allocation failure */ static ib_status_t get_or_create_rule_data_hash(ib_tx_t *tx, ib_hash_t **rule_data) { IB_FTRACE_INIT(); assert(tx); assert(tx->mp); ib_status_t rc; /* Get or create the hash that contains the rule data. */ rc = ib_hash_get(tx->data, rule_data, MODULE_DATA_STR); if (rc == IB_OK && *rule_data != NULL) { ib_log_debug2_tx(tx, "Found rule data hash in tx data named " MODULE_DATA_STR); IB_FTRACE_RET_STATUS(IB_OK); } ib_log_debug2_tx(tx, "Rule data hash did not exist in tx data."); ib_log_debug2_tx(tx, "Creating rule data hash " MODULE_DATA_STR); rc = ib_hash_create(rule_data, tx->mp); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to create hash " MODULE_DATA_STR ": %d", rc); IB_FTRACE_RET_STATUS(rc); } rc = ib_hash_set(tx->data, MODULE_DATA_STR, *rule_data); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to store hash " MODULE_DATA_STR ": %d", rc); *rule_data = NULL; } ib_log_debug2_tx(tx, "Returning rule hash " MODULE_DATA_STR " at %p.", *rule_data); IB_FTRACE_RET_STATUS(rc); }
/** * Function exported to enable a module to register an ident provider * * @param engine Engine to register with * @param name Provider name (referenced in IdentType directive) * @param provider The identity provider * @return status */ ib_status_t ib_ident_provider_register(ib_engine_t *engine, const char *name, ib_ident_provider_t *provider) { ident_cfg_t *cfg; ib_status_t rc; ib_module_t *m; rc = ib_engine_module_get(engine, MODULE_NAME_STR, &m); assert((rc == IB_OK) && (m != NULL)); rc = ib_context_module_config(ib_context_main(engine), m, &cfg); assert((rc == IB_OK) && (cfg != NULL)); if (cfg->providers == NULL) { rc = ib_hash_create(&cfg->providers, ib_engine_mm_main_get(engine)); assert((rc == IB_OK) && (cfg->providers != NULL)); } return ib_hash_set(cfg->providers, name, provider); }
/** * Get or create an ib_hash_t inside of @c tx for storing dfa rule data. * * The hash is stored at the key @c HASH_NAME_STR. * * @param[in] m PCRE module. * @param[in] tx The transaction containing @c tx->data which holds * the @a operator_data object. * @param[out] hash The fetched or created rule data hash. This is set * to NULL on failure. * * @return * - IB_OK on success. * - IB_EALLOC on allocation failure */ static ib_status_t get_or_create_operator_data_hash( const ib_module_t *m, ib_tx_t *tx, ib_hash_t **hash ) { assert(tx); assert(tx->mp); ib_status_t rc; /* Get or create the hash that contains the rule data. */ rc = ib_tx_get_module_data(tx, m, hash); if ( (rc == IB_OK) && (*hash != NULL) ) { ib_log_debug2_tx(tx, "Found rule data hash in tx."); return IB_OK; } ib_log_debug2_tx(tx, "Rule data hash did not exist in tx."); rc = ib_hash_create(hash, tx->mp); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to create hash: %s", ib_status_to_string(rc)); return rc; } rc = ib_tx_set_module_data(tx, m, *hash); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to store hash: %s", ib_status_to_string(rc)); *hash = NULL; } ib_log_debug2_tx(tx, "Returning rule hash at %p.", *hash); return rc; }
static ib_status_t sqli_dir_fingerprint_set( ib_cfgparser_t *cp, const char *directive_name, const char *set_name, const char *set_path, void *cbdata ) { assert(cp != NULL); assert(directive_name != NULL); assert(set_name != NULL); assert(set_path != NULL); ib_status_t rc; ib_context_t *ctx = NULL; ib_module_t *m = NULL; sqli_module_config_t *cfg = NULL; sqli_fingerprint_set_t *ps = NULL; ib_mm_t mm; char *abs_set_path = NULL; rc = ib_cfgparser_context_current(cp, &ctx); assert(rc == IB_OK); assert(ctx != NULL); if (ctx != ib_context_main(cp->ib)) { ib_cfg_log_error(cp, "%s: Only valid at main context.", directive_name ); return IB_EINVAL; } if (strcmp("default", set_name) == 0) { ib_cfg_log_error(cp, "%s: default is a reserved set name.", directive_name ); return IB_EINVAL; } mm = ib_engine_mm_main_get(cp->ib); rc = ib_engine_module_get( ib_context_get_engine(ctx), MODULE_NAME_STR, &m ); assert(rc == IB_OK); rc = ib_context_module_config(ctx, m, &cfg); assert(rc == IB_OK); if (cfg->fingerprint_sets == NULL) { rc = ib_hash_create(&cfg->fingerprint_sets, mm); assert(rc == IB_OK); } assert(cfg->fingerprint_sets != NULL); rc = ib_hash_get(cfg->fingerprint_sets, NULL, set_name); if (rc == IB_OK) { ib_cfg_log_error(cp, "%s: Duplicate fingerprint set definition: %s", directive_name, set_name ); return IB_EINVAL; } assert(rc == IB_ENOENT); abs_set_path = ib_util_relative_file( ib_engine_mm_config_get(cp->ib), ib_cfgparser_curr_file(cp), set_path ); if (abs_set_path == NULL) { return IB_EALLOC; } rc = sqli_create_fingerprint_set_from_file(&ps, abs_set_path, mm); if (rc != IB_OK) { ib_cfg_log_error(cp, "%s: Failure to load fingerprint set from file: %s", directive_name, abs_set_path ); return IB_EINVAL; } assert(ps != NULL); rc = ib_hash_set(cfg->fingerprint_sets, ib_mm_strdup(mm, set_name), ps); assert(rc == IB_OK); return IB_OK; }