diff options
| author | leak <leak@bitmx.net> | 2012-02-19 13:51:16 +0100 |
|---|---|---|
| committer | leak <leak@bitmx.net> | 2012-02-19 13:51:16 +0100 |
| commit | 8e3a4b956e8fcc3ec31240d847a7a630eaf2bba2 (patch) | |
| tree | c7a797f883906019d9fa820b4d782eb7dfd4c1c5 /src/server/shared | |
| parent | f0f68f15a86c5ac0c83c47c6db67786506f8460d (diff) | |
Core/Warden: Base implementation for Warden functionality
Note: The default config file action for clients failing the checks can be changed for each check via the characters.warden_action table
Credits to TOM_RUS
Diffstat (limited to 'src/server/shared')
| -rw-r--r-- | src/server/shared/Cryptography/WardenKeyGeneration.h | 73 | ||||
| -rwxr-xr-x | src/server/shared/Database/Implementation/LoginDatabase.cpp | 2 | ||||
| -rwxr-xr-x | src/server/shared/Logging/Log.cpp | 24 | ||||
| -rwxr-xr-x | src/server/shared/Logging/Log.h | 3 | ||||
| -rwxr-xr-x | src/server/shared/Utilities/Util.cpp | 13 | ||||
| -rwxr-xr-x | src/server/shared/Utilities/Util.h | 1 |
6 files changed, 114 insertions, 2 deletions
diff --git a/src/server/shared/Cryptography/WardenKeyGeneration.h b/src/server/shared/Cryptography/WardenKeyGeneration.h new file mode 100644 index 00000000000..1a0ef5c515c --- /dev/null +++ b/src/server/shared/Cryptography/WardenKeyGeneration.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "SHA1.h" + +#ifndef _WARDEN_KEY_GENERATION_H +#define _WARDEN_KEY_GENERATION_H + +class SHA1Randx { +public: + SHA1Randx(uint8 *buff, uint32 size) { + uint32 taken = size/2; + + sh.Initialize(); + sh.UpdateData(buff,taken); + sh.Finalize(); + + memcpy(o1,sh.GetDigest(),20); + + sh.Initialize(); + sh.UpdateData(buff+taken,size-taken); + sh.Finalize(); + + memcpy(o2,sh.GetDigest(),20); + + memset(o0,0x00,20); + + fillUp(); + } + + void generate(uint8 *buf, uint32 sz) { + for(uint32 i=0;i<sz;i++) { + if(taken == 20) { + fillUp(); + } + + buf[i] = o0[taken]; + taken++; + } + } +private: + void fillUp() { + sh.Initialize(); + sh.UpdateData(o1,20); + sh.UpdateData(o0,20); + sh.UpdateData(o2,20); + sh.Finalize(); + + memcpy(o0,sh.GetDigest(),20); + + taken = 0; + } + SHA1Hash sh; + uint32 taken; + uint8 o0[20],o1[20],o2[20]; +}; + +#endif diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 7e497c4437b..8ef8d3b48cf 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -31,7 +31,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_INS_ACCOUNT_AUTO_BANNED, "INSERT INTO account_banned VALUES (?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+?, 'Trinity realmd', 'Failed login autoban', 1)", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_SEL_SESSIONKEY, "SELECT a.sessionkey, a.id, aa.gmlevel FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE username = ?", CONNECTION_SYNCH) PREPARE_STATEMENT(LOGIN_UPD_VS, "UPDATE account SET v = ?, s = ? WHERE username = ?", CONNECTION_ASYNC) - PREPARE_STATEMENT(LOGIN_UPD_LOGONPROOF, "UPDATE account SET sessionkey = ?, last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0 WHERE username = ?", CONNECTION_ASYNC) + PREPARE_STATEMENT(LOGIN_UPD_LOGONPROOF, "UPDATE account SET sessionkey = ?, last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE username = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_SEL_LOGONCHALLENGE, "SELECT a.sha_pass_hash, a.id, a.locked, a.last_ip, aa.gmlevel, a.v, a.s FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = ?", CONNECTION_SYNCH) PREPARE_STATEMENT(LOGIN_UPD_FAILEDLOGINS, "UPDATE account SET failed_logins = failed_logins + 1 WHERE username = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_SEL_FAILEDLOGINS, "SELECT id, failed_logins FROM account WHERE username = ?", CONNECTION_SYNCH) diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index abdeace4d97..a9bb282cf86 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -29,7 +29,7 @@ extern LoginDatabaseWorkerPool LoginDatabase; Log::Log() : raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), - dberLogfile(NULL), chatLogfile(NULL), arenaLogFile(NULL), sqlLogFile(NULL), sqlDevLogFile(NULL), + dberLogfile(NULL), chatLogfile(NULL), arenaLogFile(NULL), sqlLogFile(NULL), sqlDevLogFile(NULL), wardenLogFile(NULL), m_gmlog_per_account(false), m_enableLogDBLater(false), m_enableLogDB(false), m_colored(false) { @@ -73,6 +73,10 @@ Log::~Log() if (sqlDevLogFile != NULL) fclose(sqlDevLogFile); sqlDevLogFile = NULL; + + if (wardenLogFile != NULL) + fclose(wardenLogFile); + wardenLogFile = NULL; } void Log::SetLogLevel(char *Level) @@ -166,6 +170,7 @@ void Log::Initialize() arenaLogFile = openLogFile("ArenaLogFile", NULL, "a"); sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a"); sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a"); + wardenLogFile = openLogFile("Warden.LogFile",NULL,"a"); // Main log file settings m_logLevel = ConfigMgr::GetIntDefault("LogLevel", LOGL_NORMAL); @@ -1055,3 +1060,20 @@ void Log::outErrorST(const char * str, ...) ACE_Stack_Trace st; outError("%s [Stacktrace: %s]", nnew_str, st.c_str()); } + +void Log::outWarden(const char * str, ...) +{ + if (!str) + return; + + if (wardenLogFile) + { + outTimestamp(wardenLogFile); + va_list ap; + va_start(ap, str); + vfprintf(wardenLogFile, str, ap); + fprintf(wardenLogFile, "\n" ); + fflush(wardenLogFile); + va_end(ap); + } +} diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 2381d91d98d..4baa1695a55 100755 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -50,6 +50,7 @@ enum DebugLogFilters LOG_FILTER_LOOT = 0x00100000, // Loot related LOG_FILTER_GUILD = 0x00200000, // Guild related LOG_FILTER_TRANSPORTS = 0x00400000, // Transport related + LOG_FILTER_WARDEN = 0x00800000, // Warden related }; enum LogTypes @@ -136,6 +137,7 @@ class Log void outChat( const char * str, ... ) ATTR_PRINTF(2, 3); void outArena( const char * str, ... ) ATTR_PRINTF(2, 3); void outSQLDriver( const char* str, ... ) ATTR_PRINTF(2, 3); + void outWarden( const char * str, ... ) ATTR_PRINTF(2, 3); void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name ); static void outTimestamp(FILE* file); @@ -168,6 +170,7 @@ class Log FILE* arenaLogFile; FILE* sqlLogFile; FILE* sqlDevLogFile; + FILE* wardenLogFile; // cache values for after initilization use (like gm log per account case) std::string m_logsDir; diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 6ae43bc6840..52ce74be8f8 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -16,6 +16,7 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <iostream> #include "Util.h" #include "utf8.h" #ifdef USE_SFMT_FOR_RNG @@ -529,3 +530,15 @@ void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result) result = ss.str(); } +std::string ByteArrayToHexStr(uint8* bytes, uint32 length) +{ + std::ostringstream ss; + for (uint32 i = 0; i < length; ++i) + { + char buffer[4]; + sprintf(buffer, "%02X ", bytes[i]); + ss << buffer; + } + + return ss.str(); +} diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index 684b26eea63..4c2c1936993 100755 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -378,6 +378,7 @@ bool IsIPAddress(char const* ipaddress); uint32 CreatePIDFile(const std::string& filename); void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result); +std::string ByteArrayToHexStr(uint8* bytes, uint32 length); #endif //handler for operations on large flags |
