This commit is contained in:
Alexander Aleksandrovič Klimov 2026-02-03 15:23:51 +01:00 committed by GitHub
commit b85bc92210
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 5 deletions

View file

@ -231,6 +231,9 @@ endif()
if(WIN32)
list(APPEND base_DEPS ws2_32 dbghelp shlwapi msi)
else()
find_library(CRYPT_LIBRARIES NAMES crypt)
list(APPEND base_DEPS ${CRYPT_LIBRARIES})
endif()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2")

View file

@ -6,6 +6,11 @@
#include "base/base64.hpp"
#include "base/tlsutility.hpp"
#include "base/utility.hpp"
#include <mutex>
#ifndef _WIN32
# include <unistd.h>
#endif /* _WIN32 */
using namespace icinga;
@ -45,10 +50,23 @@ ApiUser::Ptr ApiUser::GetByAuthHeader(const String& auth_header)
* 2) given password is empty
* 2) configured password does not match.
*/
if (!user || password.IsEmpty())
return nullptr;
else if (user && !Utility::ComparePasswords(password, user->GetPassword()))
if (!user) {
return nullptr;
}
return user;
#ifndef _WIN32
auto hash (user->GetHashedPassword());
if (!hash.IsEmpty()) {
static std::mutex mtx;
std::unique_lock lock (mtx);
auto hashed (crypt(password.CStr(), hash.CStr()));
return hashed == hash ? user : nullptr;
}
#endif /* _WIN32 */
auto plain (user->GetPassword());
return !plain.IsEmpty() && Utility::ComparePasswords(password, plain) ? user : nullptr;
}

View file

@ -11,7 +11,8 @@ namespace icinga
class ApiUser : ConfigObject
{
/* No show config */
[config, no_user_view] String password;
[deprecated, config, no_user_view] String password;
[no_user_view, no_user_modify] String hashed_password;
[deprecated, config, no_user_view] String password_hash;
[config] String client_cn (ClientCN);
[config] array(Value) permissions;