X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..e1c08c2c174c75d7c5cd2ec5d0b974c6f240ba7e:/stglibs/ia_auth_c.lib/ia_auth_c.cpp diff --git a/stglibs/ia_auth_c.lib/ia_auth_c.cpp b/stglibs/ia_auth_c.lib/ia_auth_c.cpp index d97692ea..fb13d5b6 100644 --- a/stglibs/ia_auth_c.lib/ia_auth_c.cpp +++ b/stglibs/ia_auth_c.lib/ia_auth_c.cpp @@ -23,15 +23,16 @@ /* * Author : * Boris Mikhailenko -* Andrey Rakhmanov - èñïðàâëåíèå äâóõ áàãîâ. +* Maxim Mamontov +* Andrey Rakhmanov - bugfixes. */ //--------------------------------------------------------------------------- -#include -#include - -#include +#include +#include +#include +#include #ifdef WIN32 #include @@ -108,19 +109,13 @@ return 0; //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- IA_CLIENT_PROT::IA_CLIENT_PROT(const string & sn, unsigned short p, uint16_t localPort) - : stat(), - action(IA_NONE), + : action(IA_NONE), phase(1), phaseTime(0), - messageText(), - infoText(), - strError(), codeError(0), - nonstop(true), + nonstop(false), isNetPrepared(false), proxyMode(false), - password(), - login(), serverName(sn), port(p), ip(0), @@ -142,7 +137,6 @@ IA_CLIENT_PROT::IA_CLIENT_PROT(const string & sn, unsigned short p, uint16_t loc infoCbData(NULL), errorCbData(NULL), dirNameCbData(NULL), - packetTypes(), connSyn8(NULL), connSynAck8(NULL), connAck8(NULL), @@ -151,7 +145,6 @@ IA_CLIENT_PROT::IA_CLIENT_PROT(const string & sn, unsigned short p, uint16_t loc disconnSyn8(NULL), disconnSynAck8(NULL), disconnAck8(NULL), - err(), info(NULL) { memset(&stat, 0, sizeof(stat)); @@ -175,9 +168,21 @@ packetTypes["INFO_7"] = INFO_7_N; packetTypes["INFO_8"] = INFO_8_N; unsigned char key[IA_PASSWD_LEN]; -memset(key, 0, IA_LOGIN_LEN); +memset(key, 0, IA_PASSWD_LEN); strncpy((char *)key, "pr7Hhen", 8); Blowfish_Init(&ctxHdr, key, IA_PASSWD_LEN); + +memset(key, 0, IA_PASSWD_LEN); +Blowfish_Init(&ctxPass, key, IA_PASSWD_LEN); + +for (size_t i = 0; i < DIR_NUM; ++i) + { + selectedDirs[i] = false; + } + +servAddr.sin_family = AF_INET; +servAddr.sin_port = htons(port); +servAddr.sin_addr.s_addr = ip; } //--------------------------------------------------------------------------- void IA_CLIENT_PROT::PrepareNet() @@ -198,7 +203,7 @@ if (ip == INADDR_NONE) strError = string("Unknown host ") + "\'" + serverName + "\'"; codeError = IA_GETHOSTBYNAME_ERROR; if (pErrorCb != NULL) - pErrorCb(messageText, IA_GETHOSTBYNAME_ERROR, errorCbData); + pErrorCb(strError, IA_GETHOSTBYNAME_ERROR, errorCbData); } } @@ -208,12 +213,9 @@ close(sockr); closesocket(sockr); #endif -sockr = socket(AF_INET, SOCK_DGRAM, 0); // Cîêåò ÷åðåç êîòîðûé øëåì è ïðèíèìàåì - -localAddrS.sin_family = AF_INET; -localAddrS.sin_port = htons(port); -localAddrS.sin_addr.s_addr = inet_addr("0.0.0.0"); +sockr = socket(AF_INET, SOCK_DGRAM, 0); +struct sockaddr_in localAddrR; localAddrR.sin_family = AF_INET; if (localPort) @@ -232,7 +234,7 @@ if (res == -1) strError = "bind error"; codeError = IA_BIND_ERROR; if (pErrorCb != NULL) - pErrorCb(messageText, IA_BIND_ERROR, errorCbData); + pErrorCb(strError, IA_BIND_ERROR, errorCbData); return; } @@ -245,7 +247,7 @@ if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK)) strError = "fcntl error"; codeError = IA_FCNTL_ERROR; if (pErrorCb != NULL) - pErrorCb(messageText, IA_FCNTL_ERROR, errorCbData); + pErrorCb(strError, IA_FCNTL_ERROR, errorCbData); } #endif @@ -291,14 +293,12 @@ if (!isNetPrepared) isNetPrepared = true; } -// Øèôðóåì LoginS int db = sizeof(HDR_8); for (int i = 0; i < IA_LOGIN_LEN/8; i++) { Blowfish_Encrypt(&ctxHdr, (uint32_t*)(buffer + db + i*8), (uint32_t*)(buffer + db + i*8 + 4)); } -// Øèôðóåì âñ¸ îñòàëüíîå db += IA_LOGIN_LEN; int encLen = (len - sizeof(HDR_8) - IA_LOGIN_LEN)/8; for (int i = 0; i < encLen; i++) @@ -420,6 +420,7 @@ return ret; //--------------------------------------------------------------------------- void IA_CLIENT_PROT::Start() { +nonstop = true; #ifdef WIN32 unsigned long pt; CreateThread(NULL, 16384, RunW, this, 0, &pt); @@ -719,15 +720,9 @@ connSyn8 = (CONN_SYN_8*)buffer; SwapBytes(connSyn8->len); #endif -connSyn8->len = sizeof(CONN_SYN_8); -#ifdef IA_DEBUGPROTO -if (sizeof(CONN_SYN_8) != Min8(sizeof(CONN_SYN_8))) - { - int * a = NULL; - *a = 0; - } -#endif +assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); +connSyn8->len = sizeof(CONN_SYN_8); strncpy((char*)connSyn8->type, "CONN_SYN", IA_MAX_TYPE_LEN); strncpy((char*)connSyn8->login, login.c_str(), IA_LOGIN_LEN); connSyn8->dirs = 0; @@ -747,13 +742,7 @@ SwapBytes(connAck8->len); SwapBytes(connAck8->rnd); #endif -#ifdef IA_DEBUGPROTO -if (sizeof(CONN_ACK_8) != Min8(sizeof(CONN_ACK_8))) - { - int * a = NULL; - *a = 0; - } -#endif +assert(sizeof(CONN_ACK_8) == Min8(sizeof(CONN_ACK_8)) && "CONN_ACK_8 is not aligned to 8 bytes"); connAck8->len = sizeof(CONN_ACK_8); strncpy((char*)connAck8->loginS, login.c_str(), IA_LOGIN_LEN); @@ -773,13 +762,7 @@ SwapBytes(aliveAck8->len); SwapBytes(aliveAck8->rnd); #endif -#ifdef IA_DEBUGPROTO -if (Min8(sizeof(ALIVE_ACK_8)) != sizeof(ALIVE_ACK_8)) - { - int * a = NULL; - *a = 0; - } -#endif +assert(Min8(sizeof(ALIVE_ACK_8)) == sizeof(ALIVE_ACK_8) && "ALIVE_ACK_8 is not aligned to 8 bytes"); aliveAck8 = (ALIVE_ACK_8*)buffer; aliveAck8->len = sizeof(ALIVE_ACK_8); @@ -797,13 +780,7 @@ disconnSyn8 = (DISCONN_SYN_8*)buffer; SwapBytes(disconnSyn8->len); #endif -#ifdef IA_DEBUGPROTO -if (Min8(sizeof(DISCONN_SYN_8)) != sizeof(DISCONN_SYN_8)) - { - int * a = NULL; - *a = 0; - } -#endif +assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); disconnSyn8->len = sizeof(DISCONN_SYN_8); strncpy((char*)disconnSyn8->loginS, login.c_str(), IA_LOGIN_LEN); @@ -821,13 +798,7 @@ SwapBytes(disconnAck8->len); SwapBytes(disconnAck8->rnd); #endif -#ifdef IA_DEBUGPROTO -if (Min8(sizeof(DISCONN_ACK_8)) != sizeof(DISCONN_ACK_8)) - { - int * a = NULL; - *a = 0; - } -#endif +assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); disconnAck8->rnd = rnd + 1;