summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/md5calc.c21
-rw-r--r--src/common/md5calc.h16
-rw-r--r--src/login/lclif.c10
-rw-r--r--src/login/login.c14
-rw-r--r--src/map/script.c4
-rw-r--r--src/plugins/HPMHooking.c1
-rw-r--r--vcproj-11/char-server.vcxproj2
-rw-r--r--vcproj-11/char-server.vcxproj.filters6
-rw-r--r--vcproj-12/char-server.vcxproj2
-rw-r--r--vcproj-12/char-server.vcxproj.filters6
-rw-r--r--vcproj-14/char-server.vcxproj2
-rw-r--r--vcproj-14/char-server.vcxproj.filters6
13 files changed, 66 insertions, 26 deletions
diff --git a/src/common/core.c b/src/common/core.c
index ce92a77e3..19f2ef0c7 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -40,6 +40,7 @@
# include "common/HPM.h"
# include "common/conf.h"
# include "common/ers.h"
+# include "common/md5calc.h"
# include "common/socket.h"
# include "common/sql.h"
# include "common/thread.h"
@@ -261,6 +262,7 @@ void core_defaults(void) {
timer_defaults();
db_defaults();
socket_defaults();
+ md5_defaults();
#endif
}
/**
diff --git a/src/common/md5calc.c b/src/common/md5calc.c
index d346c8aa4..ad0f7c2d8 100644
--- a/src/common/md5calc.c
+++ b/src/common/md5calc.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -37,6 +37,9 @@
#include <stdlib.h>
#include <string.h>
+struct md5_interface md5_s;
+struct md5_interface *md5;
+
// Global variable
static unsigned int *pX;
@@ -232,18 +235,12 @@ static void MD5_String2binary(const char * string, unsigned char * output)
//-------------------------------------------------------------------
// The function for the exteriors
-/** output is the coded binary in the character sequence which wants to code string. */
-void MD5_Binary(const char * string, unsigned char * output)
-{
- MD5_String2binary(string,output);
-}
-
/** output is the coded character sequence in the character sequence which wants to code string. */
void MD5_String(const char *string, char *output)
{
unsigned char digest[16];
- MD5_String2binary(string,digest);
+ md5->binary(string,digest);
snprintf(output, 33, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[ 0], digest[ 1], digest[ 2], digest[ 3],
digest[ 4], digest[ 5], digest[ 6], digest[ 7],
@@ -259,3 +256,11 @@ void MD5_Salt(unsigned int len, char * output)
output[i] = (char)(1 + rnd() % 255);
}
+
+void md5_defaults(void)
+{
+ md5 = &md5_s;
+ md5->binary = MD5_String2binary;
+ md5->string = MD5_String;
+ md5->salt = MD5_Salt;
+}
diff --git a/src/common/md5calc.h b/src/common/md5calc.h
index 0294c3ca1..1611b6fee 100644
--- a/src/common/md5calc.h
+++ b/src/common/md5calc.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -21,10 +21,18 @@
#ifndef COMMON_MD5CALC_H
#define COMMON_MD5CALC_H
+#include "common/hercules.h"
+
+struct md5_interface {
+ void (*string) (const char *string, char *output);
+ void (*binary) (const char *string, unsigned char *output);
+ void (*salt) (unsigned int len, char *output);
+};
+
#ifdef HERCULES_CORE
-void MD5_String(const char * string, char * output);
-void MD5_Binary(const char * string, unsigned char * output);
-void MD5_Salt(unsigned int len, char * output);
+void md5_defaults(void);
#endif // HERCULES_CORE
+HPShared struct md5_interface *md5;
+
#endif /* COMMON_MD5CALC_H */
diff --git a/src/login/lclif.c b/src/login/lclif.c
index 9515c5940..3ed257e85 100644
--- a/src/login/lclif.c
+++ b/src/login/lclif.c
@@ -86,7 +86,7 @@ enum parsefunc_rcode lclif_parse_CA_LOGIN(int fd, struct login_session_data *sd)
safestrncpy(sd->passwd, packet->password, PASSWD_LEN);
if (login->config->use_md5_passwds)
- MD5_String(sd->passwd, sd->passwd);
+ md5->string(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
login->client_login(fd, sd);
@@ -160,7 +160,7 @@ enum parsefunc_rcode lclif_parse_CA_LOGIN_PCBANG(int fd, struct login_session_da
safestrncpy(sd->passwd, packet->password, PASSWD_LEN);
if (login->config->use_md5_passwds)
- MD5_String(sd->passwd, sd->passwd);
+ md5->string(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
login->client_login(fd, sd);
@@ -183,7 +183,7 @@ enum parsefunc_rcode lclif_parse_CA_LOGIN_HAN(int fd, struct login_session_data
safestrncpy(sd->passwd, packet->password, PASSWD_LEN);
if (login->config->use_md5_passwds)
- MD5_String(sd->passwd, sd->passwd);
+ md5->string(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
login->client_login(fd, sd);
@@ -209,7 +209,7 @@ enum parsefunc_rcode lclif_parse_CA_SSO_LOGIN_REQ(int fd, struct login_session_d
safestrncpy(sd->passwd, packet->t1, min(tokenlen + 1, PASSWD_LEN)); // Variable-length field, don't copy more than necessary
if (login->config->use_md5_passwds)
- MD5_String(sd->passwd, sd->passwd);
+ md5->string(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
login->client_login(fd, sd);
@@ -222,7 +222,7 @@ enum parsefunc_rcode lclif_parse_CA_REQ_HASH(int fd, struct login_session_data *
{
memset(sd->md5key, '\0', sizeof(sd->md5key));
sd->md5keylen = (uint16)(12 + rnd() % 4);
- MD5_Salt(sd->md5keylen, sd->md5key);
+ md5->salt(sd->md5keylen, sd->md5key);
lclif->coding_key(fd, sd);
return PACKET_VALID;
diff --git a/src/login/login.c b/src/login/login.c
index a8ba3d9b7..7f5f78a4d 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -239,7 +239,7 @@ bool login_check_encrypted(const char* str1, const char* str2, const char* passw
nullpo_ret(str2);
nullpo_ret(passwd);
safesnprintf(tmpstr, sizeof(tmpstr), "%s%s", str1, str2);
- MD5_String(tmpstr, md5str);
+ md5->string(tmpstr, md5str);
return (0==strcmp(passwd, md5str));
}
@@ -1378,7 +1378,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const
safestrncpy(sd->userid, RFIFOP(fd,2), NAME_LENGTH);
safestrncpy(sd->passwd, RFIFOP(fd,26), NAME_LENGTH);
if (login->config->use_md5_passwds)
- MD5_String(sd->passwd, sd->passwd);
+ md5->string(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
sd->version = login->config->client_version_to_connect; // hack to skip version check
server_ip = ntohl(RFIFOL(fd,54));
@@ -1529,14 +1529,14 @@ int login_config_read(const char *cfgName)
login->config->client_hash_check = config_switch(w2);
else if(!strcmpi(w1, "client_hash")) {
int group = 0;
- char md5[33];
- memset(md5, '\0', 33);
+ char md5hash[33];
+ memset(md5hash, '\0', 33);
- if (sscanf(w2, "%d, %32s", &group, md5) == 2) {
+ if (sscanf(w2, "%d, %32s", &group, md5hash) == 2) {
struct client_hash_node *nnode;
CREATE(nnode, struct client_hash_node, 1);
- if (strcmpi(md5, "disabled") == 0) {
+ if (strcmpi(md5hash, "disabled") == 0) {
nnode->hash[0] = '\0';
} else {
int i;
@@ -1544,7 +1544,7 @@ int login_config_read(const char *cfgName)
char buf[3];
unsigned int byte;
- memcpy(buf, &md5[i], 2);
+ memcpy(buf, &md5hash[i], 2);
buf[2] = 0;
sscanf(buf, "%x", &byte);
diff --git a/src/map/script.c b/src/map/script.c
index 90a70e48d..effe40ea5 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -16049,7 +16049,7 @@ BUILDIN(md5)
tmpstr = script_getstr(st,2);
md5str = (char *)aMalloc((32+1)*sizeof(char));
- MD5_String(tmpstr, md5str);
+ md5->string(tmpstr, md5str);
script_pushstr(st, md5str);
return true;
}
diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c
index b383d30a5..be6947754 100644
--- a/src/plugins/HPMHooking.c
+++ b/src/plugins/HPMHooking.c
@@ -110,6 +110,7 @@
#include "common/console.h"
#include "common/db.h"
#include "common/des.h"
+#include "common/md5calc.h"
#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
diff --git a/vcproj-11/char-server.vcxproj b/vcproj-11/char-server.vcxproj
index 764fb3378..abd954904 100644
--- a/vcproj-11/char-server.vcxproj
+++ b/vcproj-11/char-server.vcxproj
@@ -155,6 +155,7 @@
<ClInclude Include="..\src\common\HPMSymbols.inc.h" />
<ClInclude Include="..\src\common\memmgr.h" />
<ClInclude Include="..\src\common\mapindex.h" />
+ <ClInclude Include="..\src\common\md5calc.h" />
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
@@ -208,6 +209,7 @@
<ClCompile Include="..\src\common\HPM.c" />
<ClCompile Include="..\src\common\memmgr.c" />
<ClCompile Include="..\src\common\mapindex.c" />
+ <ClCompile Include="..\src\common\md5calc.c" />
<ClCompile Include="..\src\common\mutex.c" />
<ClCompile Include="..\src\common\nullpo.c" />
<ClCompile Include="..\src\common\random.c" />
diff --git a/vcproj-11/char-server.vcxproj.filters b/vcproj-11/char-server.vcxproj.filters
index 751afc993..8cd2d592f 100644
--- a/vcproj-11/char-server.vcxproj.filters
+++ b/vcproj-11/char-server.vcxproj.filters
@@ -25,6 +25,9 @@
<ClCompile Include="..\src\common\mapindex.c">
<Filter>common</Filter>
</ClCompile>
+ <ClCompile Include="..\src\common\md5calc.c">
+ <Filter>common</Filter>
+ </ClCompile>
<ClCompile Include="..\src\common\nullpo.c">
<Filter>common</Filter>
</ClCompile>
@@ -162,6 +165,9 @@
<ClInclude Include="..\src\common\mapindex.h">
<Filter>common</Filter>
</ClInclude>
+ <ClInclude Include="..\src\common\md5calc.h">
+ <Filter>common</Filter>
+ </ClInclude>
<ClInclude Include="..\src\common\mmo.h">
<Filter>common</Filter>
</ClInclude>
diff --git a/vcproj-12/char-server.vcxproj b/vcproj-12/char-server.vcxproj
index 2077f08ee..fe4706d14 100644
--- a/vcproj-12/char-server.vcxproj
+++ b/vcproj-12/char-server.vcxproj
@@ -154,6 +154,7 @@
<ClInclude Include="..\src\common\HPMSymbols.inc.h" />
<ClInclude Include="..\src\common\memmgr.h" />
<ClInclude Include="..\src\common\mapindex.h" />
+ <ClInclude Include="..\src\common\md5calc.h" />
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
@@ -207,6 +208,7 @@
<ClCompile Include="..\src\common\HPM.c" />
<ClCompile Include="..\src\common\memmgr.c" />
<ClCompile Include="..\src\common\mapindex.c" />
+ <ClCompile Include="..\src\common\md5calc.c" />
<ClCompile Include="..\src\common\mutex.c" />
<ClCompile Include="..\src\common\nullpo.c" />
<ClCompile Include="..\src\common\random.c" />
diff --git a/vcproj-12/char-server.vcxproj.filters b/vcproj-12/char-server.vcxproj.filters
index 751afc993..8cd2d592f 100644
--- a/vcproj-12/char-server.vcxproj.filters
+++ b/vcproj-12/char-server.vcxproj.filters
@@ -25,6 +25,9 @@
<ClCompile Include="..\src\common\mapindex.c">
<Filter>common</Filter>
</ClCompile>
+ <ClCompile Include="..\src\common\md5calc.c">
+ <Filter>common</Filter>
+ </ClCompile>
<ClCompile Include="..\src\common\nullpo.c">
<Filter>common</Filter>
</ClCompile>
@@ -162,6 +165,9 @@
<ClInclude Include="..\src\common\mapindex.h">
<Filter>common</Filter>
</ClInclude>
+ <ClInclude Include="..\src\common\md5calc.h">
+ <Filter>common</Filter>
+ </ClInclude>
<ClInclude Include="..\src\common\mmo.h">
<Filter>common</Filter>
</ClInclude>
diff --git a/vcproj-14/char-server.vcxproj b/vcproj-14/char-server.vcxproj
index 4e30a1f74..0868d56ee 100644
--- a/vcproj-14/char-server.vcxproj
+++ b/vcproj-14/char-server.vcxproj
@@ -153,6 +153,7 @@
<ClInclude Include="..\src\common\HPMSymbols.inc.h" />
<ClInclude Include="..\src\common\memmgr.h" />
<ClInclude Include="..\src\common\mapindex.h" />
+ <ClInclude Include="..\src\common\md5calc.h" />
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
@@ -206,6 +207,7 @@
<ClCompile Include="..\src\common\HPM.c" />
<ClCompile Include="..\src\common\memmgr.c" />
<ClCompile Include="..\src\common\mapindex.c" />
+ <ClCompile Include="..\src\common\md5calc.c" />
<ClCompile Include="..\src\common\mutex.c" />
<ClCompile Include="..\src\common\nullpo.c" />
<ClCompile Include="..\src\common\random.c" />
diff --git a/vcproj-14/char-server.vcxproj.filters b/vcproj-14/char-server.vcxproj.filters
index 751afc993..8cd2d592f 100644
--- a/vcproj-14/char-server.vcxproj.filters
+++ b/vcproj-14/char-server.vcxproj.filters
@@ -25,6 +25,9 @@
<ClCompile Include="..\src\common\mapindex.c">
<Filter>common</Filter>
</ClCompile>
+ <ClCompile Include="..\src\common\md5calc.c">
+ <Filter>common</Filter>
+ </ClCompile>
<ClCompile Include="..\src\common\nullpo.c">
<Filter>common</Filter>
</ClCompile>
@@ -162,6 +165,9 @@
<ClInclude Include="..\src\common\mapindex.h">
<Filter>common</Filter>
</ClInclude>
+ <ClInclude Include="..\src\common\md5calc.h">
+ <Filter>common</Filter>
+ </ClInclude>
<ClInclude Include="..\src\common\mmo.h">
<Filter>common</Filter>
</ClInclude>