[Server] Expose the audit log on the database interface (#7835)

addAuditRecord existed only on Servatrice_DatabaseInterface, so 37 moderator and admin commands reached through the concrete class just to append a log row. Declare it on Server_DatabaseInterface with an empty default, mark the Servatrice implementation as an override, and switch the handler's call sites to the injected interface. No SQL moves; the argument hashes are unchanged.
This commit is contained in:
BruebachL 2026-11-10 12:16:24 +01:00 • committed by GitHub
parent 7734a94f83
commit 417e7f7db4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 95 additions and 83 deletions

View file

@ -248,6 +248,15 @@ public:
{ {
return DeckStorageResult::Failed; return DeckStorageResult::Failed;
} }
/** @brief Append a moderator/admin action to the server audit log. */
virtual void addAuditRecord(const QString & /* user */,
const QString & /* ipaddress */,
const QString & /* clientid */,
const QString & /* action */,
const QString & /* details */,
bool /* results */)
{
}
virtual bool removeForgotPassword(const QString & /* user */) virtual bool removeForgotPassword(const QString & /* user */)
{ {
return false; return false;

View file

@ -3320,7 +3320,7 @@ void Servatrice_DatabaseInterface::addAuditRecord(const QString &user,
const QString &clientid, const QString &clientid,
const QString &action, const QString &action,
const QString &details, const QString &details,
const bool &results = false) bool results)
{ {
if (!checkSql()) { if (!checkSql()) {
return; return;

View file

@ -302,7 +302,7 @@ public:
const QString &clientid, const QString &clientid,
const QString &action, const QString &action,
const QString &details, const QString &details,
const bool &results); bool results) override;
}; };
#endif #endif

View file

@ -2083,10 +2083,10 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReportResolve(const Com
return Response::RespInvalidData; return Response::RespInvalidData;
} }
sqlInterface->addAuditRecord(QString::number(reportId), this->getAddress(), databaseInterface->addAuditRecord(QString::number(reportId), this->getAddress(),
QString::fromStdString(userInfo->clientid()), QString::fromStdString(userInfo->clientid()),
dismissed ? "REPORT_DISMISSED" : "REPORT_RESOLVED", dismissed ? "REPORT_DISMISSED" : "REPORT_RESOLVED",
QString("Report #%1 %2").arg(reportId).arg(newStatus), true); QString("Report #%1 %2").arg(reportId).arg(newStatus), true);
// Notifying the reporter is best-effort: the resolve already succeeded. If any of the lookup // Notifying the reporter is best-effort: the resolve already succeeded. If any of the lookup
// queries below fail, the report is simply left with notified = 0 and the notification is // queries below fail, the report is simply left with notified = 0 and the notification is
@ -2538,8 +2538,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdResetUserPassword(const
} }
sqlInterface->setForcePasswordChange(userName, true); sqlInterface->setForcePasswordChange(userName, true);
sqlInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()), databaseInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()),
"PASSWORD_RESET", "Admin password reset", true); "PASSWORD_RESET", "Admin password reset", true);
// Notify the affected user if they are currently online. // Notify the affected user if they are currently online.
QReadLocker clientsLocker(&servatrice->clientsLock); QReadLocker clientsLocker(&servatrice->clientsLock);
@ -2580,8 +2580,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRemoveUserAvatar(const
return Response::RespInternalError; return Response::RespInternalError;
} }
sqlInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()), databaseInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()),
"REMOVE_USER_AVATAR", "Moderator removed user avatar", true); "REMOVE_USER_AVATAR", "Moderator removed user avatar", true);
Response_RemoveUserAvatar *re = new Response_RemoveUserAvatar; Response_RemoveUserAvatar *re = new Response_RemoveUserAvatar;
re->set_user_name(userName.toStdString()); re->set_user_name(userName.toStdString());
@ -2616,8 +2616,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRemoveUserBanner(const
} }
if (hadBanner) { if (hadBanner) {
sqlInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()), databaseInterface->addAuditRecord(userName, this->getAddress(), QString::fromStdString(userInfo->clientid()),
"REMOVE_USER_BANNER", "Moderator removed user banner card", true); "REMOVE_USER_BANNER", "Moderator removed user banner card", true);
} }
Response_RemoveUserBanner *re = new Response_RemoveUserBanner; Response_RemoveUserBanner *re = new Response_RemoveUserBanner;
@ -2640,9 +2640,9 @@ AbstractServerSocketInterface::cmdClearBlacklistedBanners(const Command_ClearBla
return Response::RespInternalError; return Response::RespInternalError;
} }
sqlInterface->addAuditRecord(QString::fromStdString(userInfo->name()), this->getAddress(), databaseInterface->addAuditRecord(QString::fromStdString(userInfo->name()), this->getAddress(),
QString::fromStdString(userInfo->clientid()), "CLEAR_BLACKLISTED_BANNERS", QString::fromStdString(userInfo->clientid()), "CLEAR_BLACKLISTED_BANNERS",
QString("Moderator cleared %1 blacklisted banner(s)").arg(cleared), true); QString("Moderator cleared %1 blacklisted banner(s)").arg(cleared), true);
Response_ClearBlacklistedBanners *re = new Response_ClearBlacklistedBanners; Response_ClearBlacklistedBanners *re = new Response_ClearBlacklistedBanners;
re->set_cleared_count(static_cast<unsigned int>(cleared)); re->set_cleared_count(static_cast<unsigned int>(cleared));
@ -2837,8 +2837,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReportReopen(const Comm
if (!note.isEmpty()) { if (!note.isEmpty()) {
auditDetails += QString(". Reason: %1").arg(note.left(200)); auditDetails += QString(". Reason: %1").arg(note.left(200));
} }
sqlInterface->addAuditRecord(QString::number(reportId), this->getAddress(), databaseInterface->addAuditRecord(QString::number(reportId), this->getAddress(),
QString::fromStdString(userInfo->clientid()), "REPORT_REOPENED", auditDetails, true); QString::fromStdString(userInfo->clientid()), "REPORT_REOPENED", auditDetails,
true);
return Response::RespOk; return Response::RespOk;
} }
@ -3127,8 +3128,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
bool registrationEnabled = settingsCache->value("registration/enabled", false).toBool(); bool registrationEnabled = settingsCache->value("registration/enabled", false).toBool();
if (!registrationEnabled) { if (!registrationEnabled) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Server functionality disabled", false); "REGISTER_ACCOUNT", "Server functionality disabled", false);
} }
return Response::RespRegistrationDisabled; return Response::RespRegistrationDisabled;
@ -3150,8 +3151,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
// If a whitelist exists, ensure the email address domain IS in the whitelist // If a whitelist exists, ensure the email address domain IS in the whitelist
if (!emailWhiteListFilters.isEmpty() && !emailWhiteListFilters.contains(emailDomain, Qt::CaseInsensitive)) { if (!emailWhiteListFilters.isEmpty() && !emailWhiteListFilters.contains(emailDomain, Qt::CaseInsensitive)) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Email used is not whitelisted", false); "REGISTER_ACCOUNT", "Email used is not whitelisted", false);
} }
auto *re = new Response_Register; auto *re = new Response_Register;
re->set_denied_reason_str( re->set_denied_reason_str(
@ -3163,8 +3164,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
// If a blacklist exists, ensure the email address domain is NOT in the blacklist // If a blacklist exists, ensure the email address domain is NOT in the blacklist
if (!emailBlackListFilters.isEmpty() && emailBlackListFilters.contains(emailDomain, Qt::CaseInsensitive)) { if (!emailBlackListFilters.isEmpty() && emailBlackListFilters.contains(emailDomain, Qt::CaseInsensitive)) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Email used is blacklisted", false); "REGISTER_ACCOUNT", "Email used is blacklisted", false);
} }
return Response::RespEmailBlackListed; return Response::RespEmailBlackListed;
@ -3174,8 +3175,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
QString errorString; QString errorString;
if (!sqlInterface->usernameIsValid(userName, errorString)) { if (!sqlInterface->usernameIsValid(userName, errorString)) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Username is invalid", false); "REGISTER_ACCOUNT", "Username is invalid", false);
} }
Response_Register *re = new Response_Register; Response_Register *re = new Response_Register;
@ -3186,8 +3187,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
if (userName.toLower().simplified() == "servatrice") { if (userName.toLower().simplified() == "servatrice") {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Username is invalid", false); "REGISTER_ACCOUNT", "Username is invalid", false);
} }
return Response::RespUsernameInvalid; return Response::RespUsernameInvalid;
@ -3195,8 +3196,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
if (sqlInterface->userExists(userName)) { if (sqlInterface->userExists(userName)) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Username already exists", false); "REGISTER_ACCOUNT", "Username already exists", false);
} }
return Response::RespUserAlreadyExists; return Response::RespUserAlreadyExists;
@ -3206,9 +3207,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
if (servatrice->getMaxAccountsPerEmail() > 0 && if (servatrice->getMaxAccountsPerEmail() > 0 &&
sqlInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) { sqlInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Too many usernames registered with this email address", "REGISTER_ACCOUNT",
false); "Too many usernames registered with this email address", false);
} }
return Response::RespTooManyRequests; return Response::RespTooManyRequests;
@ -3218,8 +3219,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
int banSecondsRemaining; int banSecondsRemaining;
if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) { if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "User is banned", false); "REGISTER_ACCOUNT", "User is banned", false);
} }
Response_Register *re = new Response_Register; Response_Register *re = new Response_Register;
@ -3233,9 +3234,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
if (tooManyRegistrationAttempts(this->getAddress())) { if (tooManyRegistrationAttempts(this->getAddress())) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Too many registration attempts from this ip address", "REGISTER_ACCOUNT", "Too many registration attempts from this ip address",
false); false);
} }
Response_Register *re = new Response_Register; Response_Register *re = new Response_Register;
@ -3262,8 +3263,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
passwordNeedsHash = true; passwordNeedsHash = true;
if (!isPasswordLongEnough(password.length())) { if (!isPasswordLongEnough(password.length())) {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Password is too short", false); "REGISTER_ACCOUNT", "Password is too short", false);
} }
return Response::RespPasswordTooShort; return Response::RespPasswordTooShort;
} }
@ -3293,24 +3294,24 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
} }
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "", true); "REGISTER_ACCOUNT", "", true);
} }
return Response::RespRegistrationAcceptedNeedsActivation; return Response::RespRegistrationAcceptedNeedsActivation;
} else { } else {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "", true); "REGISTER_ACCOUNT", "", true);
} }
return Response::RespRegistrationAccepted; return Response::RespRegistrationAccepted;
} }
} else { } else {
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Unknown reason for failure", false); "REGISTER_ACCOUNT", "Unknown reason for failure", false);
} }
return Response::RespRegistrationFailed; return Response::RespRegistrationFailed;
@ -3361,8 +3362,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdActivateAccount(const C
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted activation for user" << userName; qCDebug(AbstractServerSocketInterfaceLog) << "Accepted activation for user" << userName;
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"ACTIVATE_ACCOUNT", "", true); "ACTIVATE_ACCOUNT", "", true);
} }
return Response::RespActivationAccepted; return Response::RespActivationAccepted;
@ -3370,9 +3371,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdActivateAccount(const C
qCDebug(AbstractServerSocketInterfaceLog) << "Failed activation for user" << userName; qCDebug(AbstractServerSocketInterfaceLog) << "Failed activation for user" << userName;
if (servatrice->getEnableRegistrationAudit()) { if (servatrice->getEnableRegistrationAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"ACTIVATE_ACCOUNT", "Failed to activate account, incorrect activation token", "ACTIVATE_ACCOUNT",
false); "Failed to activate account, incorrect activation token", false);
} }
return Response::RespActivationFailed; return Response::RespActivationFailed;
@ -3688,8 +3689,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordRequest(c
if (servatrice->recordForgotPasswordAttempt(this->getAddress())) { if (servatrice->recordForgotPasswordAttempt(this->getAddress())) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "Too many requests from this ip address", false); "PASSWORD_RESET_REQUEST", "Too many requests from this ip address",
false);
} }
return Response::RespTooManyRequests; return Response::RespTooManyRequests;
@ -3697,8 +3699,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordRequest(c
if (!servatrice->getEnableForgotPassword()) { if (!servatrice->getEnableForgotPassword()) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "Server functionality disabled", false); "PASSWORD_RESET_REQUEST", "Server functionality disabled", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
@ -3713,8 +3715,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordRequest(c
if (!sqlInterface->userExists(userName)) { if (!sqlInterface->userExists(userName)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "User does not exist", false); "PASSWORD_RESET_REQUEST", "User does not exist", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
@ -3731,8 +3733,8 @@ Response::ResponseCode AbstractServerSocketInterface::continuePasswordRequest(co
if (sqlInterface->doesForgotPasswordExist(userName)) { if (sqlInterface->doesForgotPasswordExist(userName)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "Request already exists", true); "PASSWORD_RESET_REQUEST", "Request already exists", true);
} }
Response_ForgotPasswordRequest *re = new Response_ForgotPasswordRequest; Response_ForgotPasswordRequest *re = new Response_ForgotPasswordRequest;
@ -3745,8 +3747,8 @@ Response::ResponseCode AbstractServerSocketInterface::continuePasswordRequest(co
int banTimeRemaining; int banTimeRemaining;
if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banTimeRemaining)) { if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banTimeRemaining)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "User is banned", false); "PASSWORD_RESET_REQUEST", "User is banned", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
@ -3754,8 +3756,8 @@ Response::ResponseCode AbstractServerSocketInterface::continuePasswordRequest(co
if (!sqlInterface->addForgotPassword(userName)) { if (!sqlInterface->addForgotPassword(userName)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", "Failed to create password reset", false); "PASSWORD_RESET_REQUEST", "Failed to create password reset", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
} }
@ -3763,8 +3765,8 @@ Response::ResponseCode AbstractServerSocketInterface::continuePasswordRequest(co
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
QString details = QString details =
challenged ? "Request does not exist, challenge passed" : "Request does not exist, challenge not requested"; challenged ? "Request does not exist, challenge passed" : "Request does not exist, challenge not requested";
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_REQUEST", details, true); "PASSWORD_RESET_REQUEST", details, true);
} }
Response_ForgotPasswordRequest *re = new Response_ForgotPasswordRequest; Response_ForgotPasswordRequest *re = new Response_ForgotPasswordRequest;
@ -3783,8 +3785,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordReset(con
if (!sqlInterface->doesForgotPasswordExist(userName)) { if (!sqlInterface->doesForgotPasswordExist(userName)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET", "Request does not exist for user", false); "PASSWORD_RESET", "Request does not exist for user", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
@ -3793,8 +3795,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordReset(con
if (!sqlInterface->validateTableColumnStringData("{prefix}_users", "token", userName, if (!sqlInterface->validateTableColumnStringData("{prefix}_users", "token", userName,
nameFromStdString(cmd.token()))) { nameFromStdString(cmd.token()))) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), userName.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), userName.simplified(),
"PASSWORD_RESET", "Failed token validation", false); "PASSWORD_RESET", "Failed token validation", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
@ -3821,8 +3823,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForgotPasswordReset(con
if (sqlInterface->changeUserPassword(nameFromStdString(cmd.user_name()), password, passwordNeedsHash)) { if (sqlInterface->changeUserPassword(nameFromStdString(cmd.user_name()), password, passwordNeedsHash)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET", "", true); "PASSWORD_RESET", "", true);
} }
sqlInterface->setForcePasswordChange(nameFromStdString(cmd.user_name()), false); sqlInterface->setForcePasswordChange(nameFromStdString(cmd.user_name()), false);
@ -3844,24 +3846,25 @@ AbstractServerSocketInterface::cmdForgotPasswordChallenge(const Command_ForgotPa
if (servatrice->recordForgotPasswordAttempt(this->getAddress())) { if (servatrice->recordForgotPasswordAttempt(this->getAddress())) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_CHALLENGE", "Too many requests from this ip address", false); "PASSWORD_RESET_CHALLENGE", "Too many requests from this ip address",
false);
} }
return Response::RespTooManyRequests; return Response::RespTooManyRequests;
} }
if (!servatrice->getEnableForgotPasswordChallenge()) { if (!servatrice->getEnableForgotPasswordChallenge()) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_CHALLENGE", "Feature not enabled", false); "PASSWORD_RESET_CHALLENGE", "Feature not enabled", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
} }
if (!sqlInterface->userExists(userName)) { if (!sqlInterface->userExists(userName)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_CHALLENGE", "User does not exist", false); "PASSWORD_RESET_CHALLENGE", "User does not exist", false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
} }
@ -3869,16 +3872,16 @@ AbstractServerSocketInterface::cmdForgotPasswordChallenge(const Command_ForgotPa
const auto parsedEmailAddress = EmailParser::getParsedEmailAddress(nameFromStdString(cmd.email())); const auto parsedEmailAddress = EmailParser::getParsedEmailAddress(nameFromStdString(cmd.email()));
if (!sqlInterface->validateTableColumnStringData("{prefix}_users", "email", userName, parsedEmailAddress)) { if (!sqlInterface->validateTableColumnStringData("{prefix}_users", "email", userName, parsedEmailAddress)) {
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_CHALLENGE", "Failed to answer email challenge question", "PASSWORD_RESET_CHALLENGE", "Failed to answer email challenge question",
false); false);
} }
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
} }
if (servatrice->getEnableForgotPasswordAudit()) { if (servatrice->getEnableForgotPasswordAudit()) {
sqlInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(), databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"PASSWORD_RESET_CHALLENGE", "", true); "PASSWORD_RESET_CHALLENGE", "", true);
} }
return continuePasswordRequest(userName, clientId, rc, true); return continuePasswordRequest(userName, clientId, rc, true);
} }
@ -4259,8 +4262,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdForceActivateUser(const
// Add audit log that Moderator activated account on behalf of user // Add audit log that Moderator activated account on behalf of user
const auto &msg = QString("Attempt Force Activation by %1").arg(QString::fromStdString(cmd.moderator_name())); const auto &msg = QString("Attempt Force Activation by %1").arg(QString::fromStdString(cmd.moderator_name()));
sqlInterface->addAuditRecord(QString::fromStdString(cmd.username_to_activate()), this->getAddress(), "UNKNOWN", databaseInterface->addAuditRecord(QString::fromStdString(cmd.username_to_activate()), this->getAddress(), "UNKNOWN",
"ACTIVATE_ACCOUNT", msg, true); "ACTIVATE_ACCOUNT", msg, true);
// Build up activation request // Build up activation request
Command_Activate cmdActivate; Command_Activate cmdActivate;