passdb-ldap.c revision afa2af53ff06152efa65f6cc0e54fb1eb319d2fd
0c04407550130c0ea040b5675f2c214426b27718fuankg/* Copyright (C) 2003 Timo Sirainen */
0c04407550130c0ea040b5675f2c214426b27718fuankg/* using posixAccount */
0c04407550130c0ea040b5675f2c214426b27718fuankg unsigned int *attrs;
0c04407550130c0ea040b5675f2c214426b27718fuankgstatic struct passdb_ldap_connection *passdb_ldap_conn;
0c04407550130c0ea040b5675f2c214426b27718fuankgstatic void handle_request(struct ldap_connection *conn,
0c04407550130c0ea040b5675f2c214426b27718fuankg struct auth_request *auth_request = request->context;
0c04407550130c0ea040b5675f2c214426b27718fuankg "ldap_search() failed: %s",
0c04407550130c0ea040b5675f2c214426b27718fuankg entry = res == NULL ? NULL : ldap_first_entry(conn->ld, res);
0c04407550130c0ea040b5675f2c214426b27718fuankg "unknown user");
0c04407550130c0ea040b5675f2c214426b27718fuankg "No password in reply");
0c04407550130c0ea040b5675f2c214426b27718fuankg } else if (ldap_next_entry(conn->ld, entry) != NULL) {
0c04407550130c0ea040b5675f2c214426b27718fuankg "Multiple password replies");
0c04407550130c0ea040b5675f2c214426b27718fuankg /* LDAP result is freed now. we can check if auth_request is
0c04407550130c0ea040b5675f2c214426b27718fuankg even needed anymore */
0662ed52e814f8f08ef0e09956413a792584eddffuankg passdb_handle_credentials(result, ldap_request->credentials,
0c04407550130c0ea040b5675f2c214426b27718fuankg /* verify plain */
0c04407550130c0ea040b5675f2c214426b27718fuankg ldap_request->callback.verify_plain(result, auth_request);
0c04407550130c0ea040b5675f2c214426b27718fuankg ret = password_verify(ldap_request->password, password, scheme, user);
0c04407550130c0ea040b5675f2c214426b27718fuankg } else if (ret == 0) {
0c04407550130c0ea040b5675f2c214426b27718fuankg "password mismatch");
0c04407550130c0ea040b5675f2c214426b27718fuankg ldap_request->callback.verify_plain(ret > 0 ? PASSDB_RESULT_OK :
0c04407550130c0ea040b5675f2c214426b27718fuankgstatic void ldap_lookup_pass(struct auth_request *auth_request,
0c04407550130c0ea040b5675f2c214426b27718fuankg struct ldap_connection *conn = passdb_ldap_conn->conn;
0c04407550130c0ea040b5675f2c214426b27718fuankg const char **attr_names = (const char **)passdb_ldap_conn->attr_names;
0c04407550130c0ea040b5675f2c214426b27718fuankg vars = auth_request_get_var_expand_table(auth_request, ldap_escape);
0c04407550130c0ea040b5675f2c214426b27718fuankg filter = t_strdup_printf("(&(objectClass=posixAccount)(%s=%s))",
0c04407550130c0ea040b5675f2c214426b27718fuankg "base=%s scope=%s filter=%s fields=%s",
0c04407550130c0ea040b5675f2c214426b27718fuankgldap_verify_plain(struct auth_request *request, const char *password,
0c04407550130c0ea040b5675f2c214426b27718fuankg struct ldap_connection *conn = passdb_ldap_conn->conn;
0c04407550130c0ea040b5675f2c214426b27718fuankg if (passdb_cache_verify_plain(request, passdb_ldap_cache_key, password,
0c04407550130c0ea040b5675f2c214426b27718fuankg ldap_request = i_malloc(sizeof(struct passdb_ldap_request) +
0c04407550130c0ea040b5675f2c214426b27718fuankgstatic void ldap_lookup_credentials(struct auth_request *request,
0c04407550130c0ea040b5675f2c214426b27718fuankg if (passdb_cache_lookup_credentials(request, passdb_ldap_cache_key,
0c04407550130c0ea040b5675f2c214426b27718fuankg passdb_handle_credentials(result != NULL ? PASSDB_RESULT_OK :
0c04407550130c0ea040b5675f2c214426b27718fuankg ldap_request->callback.lookup_credentials = callback;
0662ed52e814f8f08ef0e09956413a792584eddffuankg passdb_ldap_conn = i_new(struct passdb_ldap_connection, 1);
0c04407550130c0ea040b5675f2c214426b27718fuankg passdb_ldap_cache_key = auth_cache_parse_key(conn->set.pass_filter);
0c04407550130c0ea040b5675f2c214426b27718fuankgstatic void passdb_ldap_init(const char *args __attr_unused__)
0662ed52e814f8f08ef0e09956413a792584eddffuankgstatic void passdb_ldap_deinit(void)