bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 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 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) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_error(auth_request, AUTH_SUBSYS_DB, "%s", error);
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenpassdb_dict_lookup_key(struct auth_request *auth_request,
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen ret = db_dict_value_iter_init(module->conn, auth_request,
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen else if (ret == 0) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_unknown_user(auth_request, AUTH_SUBSYS_DB);
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen if (dict_query_save_results(auth_request, module->conn, iter) < 0)
31633d676642b83305b8d46da495d9bb4e2d1ff8Timo Sirainen !auth_fields_exists(auth_request->extra_fields, "nopassword")) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_info(auth_request, AUTH_SUBSYS_DB,
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;
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen if (array_count(&module->conn->set.passdb_fields) == 0 &&
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen array_count(&module->conn->set.parsed_passdb_objects) == 0) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_error(auth_request, AUTH_SUBSYS_DB,
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen "No passdb_objects or passdb_fields specified");
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
79042f8c2ec1778528584c064b164d1ebcdde16bTimo 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);
74674a53a72dab535c61f455b2246ef2797844eaTimo Sirainen module->module.default_cache_key = auth_cache_parse_key(pool,
79042f8c2ec1778528584c064b164d1ebcdde16bTimo Sirainen db_dict_parse_cache_key(&conn->set.keys, &conn->set.passdb_fields,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen module->module.default_pass_scheme = conn->set.default_pass_scheme;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenstatic void passdb_dict_deinit(struct passdb_module *_module)