dict-ldap.c (dovecot-2.3.16) | : | dict-ldap.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 39 | skipping to change at line 39 | |||
struct dict_lookup_result res; | struct dict_lookup_result res; | |||
dict_lookup_callback_t *callback; | dict_lookup_callback_t *callback; | |||
void *callback_ctx; | void *callback_ctx; | |||
}; | }; | |||
struct ldap_dict { | struct ldap_dict { | |||
struct dict dict; | struct dict dict; | |||
struct dict_ldap_settings *set; | struct dict_ldap_settings *set; | |||
const char *uri; | const char *uri; | |||
const char *username; | ||||
const char *base_dn; | const char *base_dn; | |||
enum ldap_scope scope; | enum ldap_scope scope; | |||
pool_t pool; | pool_t pool; | |||
struct ldap_client *client; | struct ldap_client *client; | |||
unsigned long last_txid; | unsigned long last_txid; | |||
unsigned int pending; | unsigned int pending; | |||
struct ldap_dict *prev,*next; | struct ldap_dict *prev,*next; | |||
}; | }; | |||
static | static | |||
void ldap_dict_lookup_async(struct dict *dict, const char *key, | void ldap_dict_lookup_async(struct dict *dict, | |||
dict_lookup_callback_t *callback, void *context); | const struct dict_op_settings *set, const char *key, | |||
dict_lookup_callback_t *callback, void *context); | ||||
static bool | static bool | |||
dict_ldap_map_match(const struct dict_ldap_map *map, const char *path, | dict_ldap_map_match(const struct dict_ldap_map *map, const char *path, | |||
ARRAY_TYPE(const_string) *values, size_t *pat_len_r, | ARRAY_TYPE(const_string) *values, size_t *pat_len_r, | |||
size_t *path_len_r, bool partial_ok, bool recurse) | size_t *path_len_r, bool partial_ok, bool recurse) | |||
{ | { | |||
const char *path_start = path; | const char *path_start = path; | |||
const char *pat, *attribute, *p; | const char *pat, *attribute, *p; | |||
size_t len; | size_t len; | |||
skipping to change at line 192 | skipping to change at line 192 | |||
} | } | |||
str_printfa(ret, "\\%02X", (unsigned char)*p); | str_printfa(ret, "\\%02X", (unsigned char)*p); | |||
} else if (ret != NULL) | } else if (ret != NULL) | |||
str_append_c(ret, *p); | str_append_c(ret, *p); | |||
} | } | |||
return ret == NULL ? str : str_c(ret); | return ret == NULL ? str : str_c(ret); | |||
} | } | |||
static bool | static bool | |||
ldap_dict_build_query(struct ldap_dict *dict, const struct dict_ldap_map *map, | ldap_dict_build_query(const struct dict_op_settings *set, | |||
const struct dict_ldap_map *map, | ||||
ARRAY_TYPE(const_string) *values, bool priv, | ARRAY_TYPE(const_string) *values, bool priv, | |||
string_t *query_r, const char **error_r) | string_t *query_r, const char **error_r) | |||
{ | { | |||
const char *template, *error; | const char *template, *error; | |||
ARRAY(struct var_expand_table) exp; | ARRAY(struct var_expand_table) exp; | |||
struct var_expand_table entry; | struct var_expand_table entry; | |||
t_array_init(&exp, 8); | t_array_init(&exp, 8); | |||
entry.key = '\0'; | entry.key = '\0'; | |||
entry.value = ldap_escape(dict->username); | entry.value = ldap_escape(set->username); | |||
entry.long_key = "username"; | entry.long_key = "username"; | |||
array_push_back(&exp, &entry); | array_push_back(&exp, &entry); | |||
if (priv) { | if (priv) { | |||
template = t_strdup_printf("(&(%s=%s)%s)", map->username_attribut e, "%{username}", map->filter); | template = t_strdup_printf("(&(%s=%s)%s)", map->username_attribut e, "%{username}", map->filter); | |||
} else { | } else { | |||
template = map->filter; | template = map->filter; | |||
} | } | |||
for(size_t i = 0; i < array_count(values) && i < array_count(&map->ldap_a ttributes); i++) { | for(size_t i = 0; i < array_count(values) && i < array_count(&map->ldap_a ttributes); i++) { | |||
skipping to change at line 233 | skipping to change at line 234 | |||
if (var_expand(query_r, template, array_front(&exp), &error) <= 0) { | if (var_expand(query_r, template, array_front(&exp), &error) <= 0) { | |||
*error_r = t_strdup_printf("Failed to expand %s: %s", template, e rror); | *error_r = t_strdup_printf("Failed to expand %s: %s", template, e rror); | |||
return FALSE; | return FALSE; | |||
} | } | |||
return TRUE; | return TRUE; | |||
} | } | |||
static | static | |||
int ldap_dict_init(struct dict *dict_driver, const char *uri, | int ldap_dict_init(struct dict *dict_driver, const char *uri, | |||
const struct dict_settings *set, | const struct dict_settings *set ATTR_UNUSED, | |||
struct dict **dict_r, const char **error_r) | struct dict **dict_r, const char **error_r) | |||
{ | { | |||
pool_t pool = pool_alloconly_create("ldap dict", 2048); | pool_t pool = pool_alloconly_create("ldap dict", 2048); | |||
struct ldap_dict *dict = p_new(pool, struct ldap_dict, 1); | struct ldap_dict *dict = p_new(pool, struct ldap_dict, 1); | |||
dict->pool = pool; | dict->pool = pool; | |||
dict->dict = *dict_driver; | dict->dict = *dict_driver; | |||
dict->username = p_strdup(pool, set->username); | ||||
dict->uri = p_strdup(pool, uri); | dict->uri = p_strdup(pool, uri); | |||
dict->set = dict_ldap_settings_read(pool, uri, error_r); | dict->set = dict_ldap_settings_read(pool, uri, error_r); | |||
if (dict->set == NULL) { | if (dict->set == NULL) { | |||
pool_unref(&pool); | pool_unref(&pool); | |||
return -1; | return -1; | |||
} | } | |||
if (dict_ldap_connect(dict, error_r) < 0) { | if (dict_ldap_connect(dict, error_r) < 0) { | |||
pool_unref(&pool); | pool_unref(&pool); | |||
skipping to change at line 355 | skipping to change at line 355 | |||
io_loop_set_current(op->dict->dict.prev_ioloop); | io_loop_set_current(op->dict->dict.prev_ioloop); | |||
op->callback(&op->res, op->callback_ctx); | op->callback(&op->res, op->callback_ctx); | |||
if (op->dict->dict.prev_ioloop != NULL) { | if (op->dict->dict.prev_ioloop != NULL) { | |||
io_loop_set_current(op->dict->dict.ioloop); | io_loop_set_current(op->dict->dict.ioloop); | |||
io_loop_stop(op->dict->dict.ioloop); | io_loop_stop(op->dict->dict.ioloop); | |||
} | } | |||
pool_unref(&pool); | pool_unref(&pool); | |||
} | } | |||
static int | static int | |||
ldap_dict_lookup(struct dict *dict, pool_t pool, const char *key, | ldap_dict_lookup(struct dict *dict, const struct dict_op_settings *set, | |||
pool_t pool, const char *key, | ||||
const char **value_r, const char **error_r) | const char **value_r, const char **error_r) | |||
{ | { | |||
struct dict_lookup_result res; | struct dict_lookup_result res; | |||
ldap_dict_lookup_async(dict, key, ldap_dict_lookup_done, &res); | ldap_dict_lookup_async(dict, set, key, ldap_dict_lookup_done, &res); | |||
ldap_dict_wait(dict); | ldap_dict_wait(dict); | |||
if (res.ret < 0) { | if (res.ret < 0) { | |||
*error_r = res.error; | *error_r = res.error; | |||
return -1; | return -1; | |||
} | } | |||
if (res.ret > 0) | if (res.ret > 0) | |||
*value_r = p_strdup(pool, res.value); | *value_r = p_strdup(pool, res.value); | |||
return res.ret; | return res.ret; | |||
} | } | |||
skipping to change at line 417 | skipping to change at line 418 | |||
const char *key, const char *value); | const char *key, const char *value); | |||
static | static | |||
void ldap_dict_unset(struct dict_transaction_context *ctx, | void ldap_dict_unset(struct dict_transaction_context *ctx, | |||
const char *key); | const char *key); | |||
static | static | |||
void ldap_dict_atomic_inc(struct dict_transaction_context *ctx, | void ldap_dict_atomic_inc(struct dict_transaction_context *ctx, | |||
const char *key, long long diff); | const char *key, long long diff); | |||
*/ | */ | |||
static | static | |||
void ldap_dict_lookup_async(struct dict *dict, const char *key, | void ldap_dict_lookup_async(struct dict *dict, | |||
dict_lookup_callback_t *callback, void *context) | const struct dict_op_settings *set, | |||
const char *key, | ||||
dict_lookup_callback_t *callback, void *context) | ||||
{ | { | |||
struct ldap_search_input input; | struct ldap_search_input input; | |||
struct ldap_dict *ctx = (struct ldap_dict*)dict; | struct ldap_dict *ctx = (struct ldap_dict*)dict; | |||
struct dict_ldap_op *op; | struct dict_ldap_op *op; | |||
const char *error; | const char *error; | |||
pool_t oppool = pool_alloconly_create("ldap dict lookup", 64); | pool_t oppool = pool_alloconly_create("ldap dict lookup", 64); | |||
string_t *query = str_new(oppool, 64); | string_t *query = str_new(oppool, 64); | |||
op = p_new(oppool, struct dict_ldap_op, 1); | op = p_new(oppool, struct dict_ldap_op, 1); | |||
op->pool = oppool; | op->pool = oppool; | |||
skipping to change at line 447 | skipping to change at line 450 | |||
t_array_init(&values, 8); | t_array_init(&values, 8); | |||
const struct dict_ldap_map *map = ldap_dict_find_map(ctx, key, &values); | const struct dict_ldap_map *map = ldap_dict_find_map(ctx, key, &values); | |||
if (map != NULL) { | if (map != NULL) { | |||
op->map = map; | op->map = map; | |||
attributes[0] = map->value_attribute; | attributes[0] = map->value_attribute; | |||
/* build lookup */ | /* build lookup */ | |||
i_zero(&input); | i_zero(&input); | |||
input.base_dn = map->base_dn; | input.base_dn = map->base_dn; | |||
input.scope = map->scope_val; | input.scope = map->scope_val; | |||
if (!ldap_dict_build_query(ctx, map, &values, strncmp(key, DICT_P ATH_PRIVATE, strlen(DICT_PATH_PRIVATE))==0, query, &error)) { | if (!ldap_dict_build_query(set, map, &values, strncmp(key, DICT_P ATH_PRIVATE, strlen(DICT_PATH_PRIVATE))==0, query, &error)) { | |||
op->res.error = error; | op->res.error = error; | |||
callback(&op->res, context); | callback(&op->res, context); | |||
pool_unref(&oppool); | pool_unref(&oppool); | |||
return; | return; | |||
} | } | |||
input.filter = str_c(query); | input.filter = str_c(query); | |||
input.attributes = attributes; | input.attributes = attributes; | |||
input.timeout_secs = ctx->set->timeout; | input.timeout_secs = ctx->set->timeout; | |||
ctx->pending++; | ctx->pending++; | |||
ldap_search_start(ctx->client, &input, ldap_dict_lookup_callback, op); | ldap_search_start(ctx->client, &input, ldap_dict_lookup_callback, op); | |||
End of changes. 10 change blocks. | ||||
12 lines changed or deleted | 15 lines changed or added |