void *dnsbl_table_open(struct ci_lookup_table *table) { struct dnsbl_data *dnsbl_data; if (strlen(table->path) >= CI_MAXHOSTNAMELEN ) { ci_debug_printf(1, "dnsbl_table_open: too long domain name: %s\n", table->path); return NULL; } if (table->key_ops != &ci_str_ops || table->val_ops!= &ci_str_ops) { ci_debug_printf(1, "dnsbl_table_open: Only searching with strings and returning strings supported\n"); return NULL; } dnsbl_data = malloc(sizeof(struct dnsbl_data)); if (!dnsbl_data) { ci_debug_printf(1, "dnsbl_table_open: error allocating memory (dnsbl_data)!\n"); return NULL; } strcpy(dnsbl_data->check_domain, table->path); dnsbl_data->cache = ci_cache_build(65536, CI_MAXHOSTNAMELEN+1, 0, 60, &ci_str_ops, &ci_cache_store_vector_val, /*copy_to*/ &ci_cache_read_vector_val /*copy_from*/ ); table->data = dnsbl_data; return table->data; }
void *dnsbl_table_open(struct ci_lookup_table *table) { struct dnsbl_data *dnsbl_data; if (strlen(table->path) >= CI_MAXHOSTNAMELEN ) { ci_debug_printf(1, "dnsbl_table_open: too long domain name: %s\n", table->path); return NULL; } dnsbl_data = malloc(sizeof(struct dnsbl_data)); if (!dnsbl_data) { ci_debug_printf(1, "dnsbl_table_open: error allocating memory (dnsbl_data)!\n"); return NULL; } strcpy(dnsbl_data->check_domain, table->path); dnsbl_data->cache = ci_cache_build(65536, CI_MAXHOSTNAMELEN+1, 0, 60, &ci_str_ops, store_val, read_val); table->data = dnsbl_data; return table->data; }
void *ldap_table_open(struct ci_lookup_table *table) { int i; char *path; char tname[1024]; struct ldap_table_data *ldapdata; ci_dyn_array_t *args = NULL; ci_array_item_t *arg = NULL; char *use_cache = "local"; int cache_ttl = 60; size_t cache_size = 1*1024*1024; size_t cache_item_size = 2048; long int val; path = strdup(table->path); if (!path) { ci_debug_printf(1, "ldap_table_open: error allocating memory!\n"); return NULL; } ldapdata = malloc(sizeof(struct ldap_table_data)); if(!ldapdata) { free(path); ci_debug_printf(1, "ldap_table_open: error allocating memory (ldapdata)!\n"); return NULL; } ldapdata->str = path; ldapdata->pool = NULL; ldapdata->base = NULL; ldapdata->server = NULL; ldapdata->port = 389; ldapdata->user = NULL; ldapdata->password = NULL; ldapdata->attrs = NULL; ldapdata->filter = NULL; ldapdata->name = NULL; if(!parse_ldap_str(ldapdata)) { free(ldapdata->str); free(ldapdata); ci_debug_printf(1, "ldap_table_open: parse path string error!\n"); return NULL; } if (table->args) { if ((args = ci_parse_key_value_list(table->args, ','))) { for (i = 0; (arg = ci_dyn_array_get_item(args, i)) != NULL; ++i) { ci_debug_printf(5, "Table argument %s:%s\n", arg->name, (char *)arg->value); if(strcasecmp(arg->name, "name") == 0) { ldapdata->name = strdup((char *)arg->value); } else if(strcasecmp(arg->name, "cache") == 0) { if (strcasecmp((char *)arg->value, "no") == 0) use_cache = NULL; else use_cache = (char *)arg->value; } else if (strcasecmp(arg->name, "cache-ttl") == 0) { val = strtol((char *)arg->value, NULL, 10); if (val > 0) cache_ttl = val; else ci_debug_printf(1, "WARNING: wrong cache-ttl value: %ld, using default\n", val); } else if (strcasecmp(arg->name, "cache-size") == 0) { val = ci_atol_ext((char *)arg->value, NULL); if (val > 0) cache_size = (size_t)val; else ci_debug_printf(1, "WARNING: wrong cache-size value: %ld, using default\n", val); } else if (strcasecmp(arg->name, "cache-item-size") == 0) { val = ci_atol_ext((char *)arg->value, NULL); if (val > 0) cache_item_size = (size_t)val; else ci_debug_printf(1, "WARNING: wrong cache-item-size value: %ld, using default\n", val); } } } } ldapdata->pool = ldap_pool_create(ldapdata->server, ldapdata->port, ldapdata->user, ldapdata->password); if (use_cache) { snprintf(tname, sizeof(tname), "ldap:%s", ldapdata->name ? ldapdata->name : ldapdata->str); tname[sizeof(tname) - 1] = '\0'; ldapdata->cache = ci_cache_build(tname, use_cache, cache_size, cache_item_size, cache_ttl, &ci_str_ops); if(!ldapdata->cache) { ci_debug_printf(1, "ldap_table_open: can not create cache! cache is disabled"); } } else ldapdata->cache = NULL; table->data = ldapdata; /*Must released before exit, we have pointes pointing on args array items*/ if (args) ci_dyn_array_destroy(args); return table->data; }