passdb-dict.c revision 31633d676642b83305b8d46da495d9bb4e2d1ff8
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen lookup_credentials_callback_t *lookup_credentials;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainendict_query_save_results(struct auth_request *auth_request,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen struct dict_connection *conn, const char *result)
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen while (db_dict_value_iter_next(iter, &key, &value)) {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_request_set_field(auth_request, key, value,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen if (db_dict_value_iter_deinit(&iter, &error) < 0) {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen "Value '%s' not in valid %s format: %s",
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenpassdb_dict_lookup_key(struct auth_request *auth_request,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen struct dict_passdb_module *module, const char *key)
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_request_log_debug(auth_request, "dict", "lookup %s", key);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen ret = dict_lookup(module->conn->dict, pool_datastack_create(),
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_request_log_error(auth_request, "dict", "Lookup failed");
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen } else if (ret == 0) {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_request_log_info(auth_request, "dict", "unknown user");
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen if (dict_query_save_results(auth_request, module->conn, value) < 0)
31633d676642b83305b8d46da495d9bb4e2d1ff8Timo Sirainen !auth_fields_exists(auth_request->extra_fields, "nopassword")) {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen "No password returned (and no nopassword)");
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenstatic void passdb_dict_lookup_pass(struct passdb_dict_request *dict_request)
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen struct auth_request *auth_request = dict_request->auth_request;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen struct passdb_module *_module = auth_request->passdb->passdb;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen var_expand(key, module->conn->set.password_key,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_request_get_var_expand_table(auth_request, NULL));
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen if (*module->conn->set.password_key == '\0') {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen "password_key not specified");
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen passdb_result = passdb_dict_lookup_key(auth_request, module,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen /* passdb_password may change on the way,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen so we'll need to strdup. */
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen password = t_strdup(auth_request->passdb_password);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen /* auth_request_set_field() sets scheme */
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen if (auth_request->credentials_scheme != NULL) {
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen passdb_handle_credentials(passdb_result, password, scheme,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen ret = auth_request_password_verify(auth_request,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen dict_request->callback.verify_plain(passdb_result,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenstatic void dict_verify_plain(struct auth_request *request,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen dict_request = p_new(request->pool, struct passdb_dict_request, 1);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen dict_request->callback.verify_plain = callback;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenstatic void dict_lookup_credentials(struct auth_request *request,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen dict_request = p_new(request->pool, struct passdb_dict_request, 1);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen dict_request->callback.lookup_credentials = callback;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenpassdb_dict_preinit(pool_t pool, const char *args)
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen module = p_new(pool, struct dict_passdb_module, 1);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen auth_cache_parse_key(pool, conn->set.password_key);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen module->module.default_pass_scheme = conn->set.default_pass_scheme;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenstatic void passdb_dict_deinit(struct passdb_module *_module)