X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/b5e75bbd70279384c22f598a6f41f0714b537e4e..3c6b99f269e502e31ee14b1ae9060de334012c82:/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 4e4dd60c..94104ac1 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -213,8 +213,6 @@ void IA_PHASE::WritePhaseChange(int newPhase) UTIME newPhaseTime; gettimeofday(&newPhaseTime, NULL); flog = fopen(log.c_str(), "at"); -/*int64_t tn = newPhaseTime.GetSec()*1000000 + newPhaseTime.GetUSec(); -int64_t to = phaseTime.GetSec()*1000000 + phaseTime.GetUSec();*/ if (flog) { string action = newPhase == phase ? "U" : "C"; @@ -416,7 +414,6 @@ if (isRunningRun) //after 5 seconds waiting thread still running. now killing it if (isRunningRun) { - //TODO pthread_cancel() if (pthread_kill(recvThread, SIGINT)) { errorStr = "Cannot kill thread."; @@ -450,7 +447,6 @@ if (isRunningRunTimeouter) //after 5 seconds waiting thread still running. now killing it if (isRunningRunTimeouter) { - //TODO pthread_cancel() if (pthread_kill(timeouterThread, SIGINT)) { errorStr = "Cannot kill thread."; @@ -603,13 +599,14 @@ uint32_t sip = outerAddr.sin_addr.s_addr; uint16_t sport = htons(outerAddr.sin_port); USER_PTR user; -if (users->FindByName(login, &user) == 0) +if (users->FindByName(login, &user)) { WriteServLog("User's connect failed: user '%s' not found. IP %s", login, inet_ntostring(sip).c_str()); - printfd(__FILE__, "User %s NOT found!\n", login); + printfd(__FILE__, "User '%s' NOT found!\n", login); SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ!"); + return -1; } printfd(__FILE__, "User '%s' FOUND!\n", user->GetLogin().c_str()); @@ -752,7 +749,6 @@ return 0; int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user) { std::string login(user->GetLogin()); -// ôÕÔ ÓÏÂÒÁÎÙ ÏÂÒÁÂÏÔÞÉËÉ ÒÁÚÎÙÈ ÐÁËÅÔÏ× const int offset = LOGIN_LEN + 2 + 6; // LOGIN_LEN + sizeOfMagic + sizeOfVer; STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -777,25 +773,27 @@ if (it == ip2user.end()) return 0; } } - // åÝÅ ÎÅ ÂÙÌÏ ÚÁÐÒÏÓÏ× Ó ÜÔÏÇÏ IP + printfd(__FILE__, "Add new user '%s' from ip %s\n", login.c_str(), inet_ntostring(sip).c_str()); - ip2user[sip].login = login; + std::pair::iterator, bool> res; + res = ip2user.insert(std::make_pair(sip, IA_USER(login, user, sport, protoVer))); + it = res.first; + /*ip2user[sip].login = login; ip2user[sip].user = user; ip2user[sip].protoVer = protoVer; - ip2user[sip].port = sport; + ip2user[sip].port = sport;*/ #ifdef IA_PHASE_DEBUG - ip2user[sip].phase.SetLogFileName(stgSettings->GetLogFileName()); - ip2user[sip].phase.SetUserLogin(login); + it->second.phase.SetLogFileName(stgSettings->GetLogFileName()); + it->second.phase.SetUserLogin(login); #endif - - it = ip2user.find(sip); //TODO + /*it = ip2user.find(sip); //TODO if (it == ip2user.end()) { printfd(__FILE__, "+++ ERROR +++\n"); return -1; - } + }*/ } else if (user->GetID() != it->second.user->GetID()) { @@ -813,8 +811,8 @@ else if (user->GetID() != it->second.user->GetID()) IA_USER * iaUser = &(it->second); -if (iaUser->port != sport) - iaUser->port = sport; +/*if (iaUser->port != sport) + iaUser->port = sport;*/ if (iaUser->password != user->GetProperty().password.Get()) { @@ -985,8 +983,7 @@ switch (protoVer) sendAddr.sin_family = AF_INET; sendAddr.sin_port = htons(port); - - sendAddr.sin_addr.s_addr = ip;// IP ÐÏÌØÚÏ×ÁÔÅÌÑ + sendAddr.sin_addr.s_addr = ip; err.len = 1; strncpy((char*)err.type, "ERR", 16); @@ -1006,8 +1003,7 @@ switch (protoVer) sendAddr.sin_family = AF_INET; sendAddr.sin_port = htons(port); - - sendAddr.sin_addr.s_addr = ip;// IP ÐÏÌØÚÏ×ÁÔÅÌÑ + sendAddr.sin_addr.s_addr = ip; err8.len = 256; strncpy((char*)err8.type, "ERR", 16); @@ -1035,9 +1031,6 @@ sendAddr.sin_addr.s_addr = ip; int res = sendto(listenSocket, buffer, len, 0, (struct sockaddr*)&sendAddr, sizeof(sendAddr)); -static struct timeval tv; -gettimeofday(&tv, NULL); - if (res == len) return 0; @@ -1654,9 +1647,12 @@ SwapBytes(fin6.len); Encrypt(&iaUser->ctx, (char*)&fin6, (char*)&fin6, Min8(sizeof(fin6))/8); users->Unauthorize(iaUser->login, this); + +int res = Send(sip, iaSettings.GetUserPort(), (char*)&fin6, Min8(sizeof(fin6))); + ip2user.erase(it); -return Send(sip, iaSettings.GetUserPort(), (char*)&fin6, Min8(sizeof(fin6))); +return res; } //----------------------------------------------------------------------------- int AUTH_IA::Send_FIN_7(IA_USER * iaUser, uint32_t sip, map::iterator it) @@ -1681,9 +1677,12 @@ SwapBytes(fin8.len); Encrypt(&iaUser->ctx, (char*)&fin8, (char*)&fin8, Min8(sizeof(fin8))/8); users->Unauthorize(iaUser->login, this); + +int res = Send(sip, iaUser->port, (char*)&fin8, Min8(sizeof(fin8))); + ip2user.erase(it); -return Send(sip, iaUser->port, (char*)&fin8, Min8(sizeof(fin8))); +return res; } //----------------------------------------------------------------------------- inline