#include <sys/types.h>
#include <sys/socket.h>
+#include <unistd.h> // usleep, close
+
#include <csignal>
#include <cstdlib>
+#include <cstdio> // snprintf
+#include <cerrno>
#include <algorithm>
+#include "stg/common.h"
+#include "stg/locker.h"
+#include "stg/tariff.h"
+#include "stg/user_property.h"
+#include "stg/settings.h"
+#include "stg/plugin_creator.h"
#include "inetaccess.h"
-#include "common.h"
extern volatile const time_t stgTime;
-//-----------------------------------------------------------------------------
-class IA_CREATOR
-{
-private:
- AUTH_IA * ia;
-
-public:
- IA_CREATOR()
- : ia(new AUTH_IA())
- {
- };
- ~IA_CREATOR()
- {
- delete ia;
- };
+void InitEncrypt(BLOWFISH_CTX * ctx, const string & password);
+void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
+void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
- AUTH_IA * GetPlugin()
- {
- return ia;
- };
-};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-IA_CREATOR iac;
+PLUGIN_CREATOR<AUTH_IA> iac;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return iac.GetPlugin();
}
{
}
//-----------------------------------------------------------------------------
-int AUTH_IA_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
-{
-if (str2x(str.c_str(), *val))
- {
- errorStr = "Incorrect value \'" + str + "\'.";
- return -1;
- }
-if (*val < min || *val > max)
- {
- errorStr = "Value \'" + str + "\' out of range.";
- return -1;
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
int AUTH_IA_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
{
int p;
: nonstop(false),
isRunningRun(false),
isRunningRunTimeouter(false),
+ users(NULL),
+ stgSettings(NULL),
+ listenSocket(-1),
WriteServLog(GetStgLogger()),
enabledDirs(0xFFffFFff),
onDelUserNotifier(*this)
uint32_t sip = *((uint32_t*)&outerAddr.sin_addr);
uint16_t sport = htons(outerAddr.sin_port);
-user_iter user;
+USER_PTR user;
if (users->FindByName(login, &user) == 0)
{
printfd(__FILE__, "User %s FOUND!\n", user->GetLogin().c_str());
- PacketProcessor(buffer, dataLen, sip, sport, protoVer, &user);
+ PacketProcessor(buffer, dataLen, sip, sport, protoVer, user);
}
else
{
if ((currTime - it->second.phase.GetTime()) > iaSettings.GetUserTimeout())
{
- it->second.user->Unauthorize(this);
+ users->Unauthorize(it->second.user->GetLogin(), this);
ip2user.erase(it++);
continue;
}
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, user_iter * user)
+int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user)
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::string login(user->GetLogin());
// ôÕÔ ÓÏÂÒÁÎÙ ÏÂÒÁÂÏÔÞÉËÉ ÒÁÚÎÙÈ ÐÁËÅÔÏ×
-int pn = -1;
-int packetLen;
const int offset = LOGIN_LEN + 2 + 6; // LOGIN_LEN + sizeOfMagic + sizeOfVer;
IA_USER * iaUser = NULL;
DISCONN_SYN_6 * disconnSyn;
DISCONN_ACK_6 * disconnAck;
-map<uint32_t, IA_USER>::iterator it;
-it = ip2user.find(sip);
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+map<uint32_t, IA_USER>::iterator it(ip2user.find(sip));
-if (it == ip2user.end() || (*user)->GetID() != it->second.user->GetID())
+if (it == ip2user.end())
{
// åÝÅ ÎÅ ÂÙÌÏ ÚÁÐÒÏÓÏ× Ó ÜÔÏÇÏ IP
printfd(__FILE__, "Add new user\n");
+ ip2user[sip].login = user->GetLogin();
+ ip2user[sip].user = user;
ip2user[sip].protoVer = protoVer;
- ip2user[sip].user = *user;
ip2user[sip].port = sport;
#ifdef IA_PHASE_DEBUG
ip2user[sip].phase.SetLogFileName(stgSettings->GetLogFileName());
- ip2user[sip].phase.SetUserLogin((*user)->GetLogin());
+ ip2user[sip].phase.SetUserLogin(login);
#endif
return -1;
}
}
+else if (user->GetID() != it->second.user->GetID())
+ {
+ printfd(__FILE__, "IP address already in use. IP \'%s\'\n", inet_ntostring(sip).c_str());
+ WriteServLog("IP address already in use. IP \'%s\'", inet_ntostring(sip).c_str());
+ SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
+ return 0;
+ }
iaUser = &(it->second);
if (iaUser->port != sport)
iaUser->port = sport;
-if (iaUser->password != (*user)->property.password.Get())
+if (iaUser->password != user->GetProperty().password.Get())
{
- InitEncrypt(&iaUser->ctx, (*user)->property.password.Get());
- iaUser->password = (*user)->property.password.Get();
+ InitEncrypt(&iaUser->ctx, user->GetProperty().password.Get());
+ iaUser->password = user->GetProperty().password.Get();
}
buff += offset;
strncpy(packetName, buff + 4, IA_MAX_TYPE_LEN);
packetName[IA_MAX_TYPE_LEN - 1] = 0;
-map<string, int>::iterator pi;
-pi = packetTypes.find(packetName);
+map<string, int>::iterator pi(packetTypes.find(packetName));
if (pi == packetTypes.end())
{
SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ ÉÌÉ ÐÁÒÏÌØ!");
WriteServLog("User's connect failed. IP \'%s\'. Wrong login or password", inet_ntostring(sip).c_str());
return 0;
}
-else
- {
- pn = pi->second;
- }
-packetLen = *(int*)buff;
-
-if ((*user)->property.disabled.Get())
+if (user->GetProperty().disabled.Get())
{
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÂÌÏËÉÒÏ×ÁÎÁ");
return 0;
}
-if ((*user)->property.passive.Get())
+if (user->GetProperty().passive.Get())
{
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÍÏÒÏÖÅÎÁ");
return 0;
}
-if ((*user)->GetAuthorized() && (*user)->GetCurrIP() != sip)
+if (user->IsAuthorizedBy(this) && user->GetCurrIP() != sip)
{
- printfd(__FILE__, "Login %s alredy in use. IP \'%s\'\n", (*user)->GetLogin().c_str(), inet_ntostring(sip).c_str());
- WriteServLog("Login %s alredy in use. IP \'%s\'", (*user)->GetLogin().c_str(), inet_ntostring(sip).c_str());
+ printfd(__FILE__, "Login %s already in use. IP \'%s\'\n", login.c_str(), inet_ntostring(sip).c_str());
+ WriteServLog("Login %s already in use. IP \'%s\'", login.c_str(), inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "÷ÁÛ ÌÏÇÉÎ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
return 0;
}
-user_iter u;
-if (users->FindByIPIdx(sip, &u) == 0 && u->GetLogin() != (*user)->GetLogin())
- {
- printfd(__FILE__, "IP address alredy in use. IP \'%s\'", inet_ntostring(sip).c_str());
- WriteServLog("IP address alredy in use. IP \'%s\'", inet_ntostring(sip).c_str());
- SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
- return 0;
- }
-
// ôÅÐÅÒØ ÍÙ ÄÏÌÖÎÙ ÐÒÏ×ÅÒÉÔØ, ÍÏÖÅÔ ÌÉ ÐÏÌØÚÏ×ÁÔÅÌØ ÐÏÄËÌÀÞÉÔÓÑ Ó ÜÔÏÇÏ ÁÄÒÅÓÁ.
-int ipFound = (*user)->property.ips.Get().IsIPInIPS(sip);
+int ipFound = user->GetProperty().ips.Get().IsIPInIPS(sip);
if (!ipFound)
{
- printfd(__FILE__, "User %s. IP address is incorrect. IP \'%s\'\n", (*user)->GetLogin().c_str(), inet_ntostring(sip).c_str());
- WriteServLog("User %s. IP address is incorrect. IP \'%s\'", (*user)->GetLogin().c_str(), inet_ntostring(sip).c_str());
+ printfd(__FILE__, "User %s. IP address is incorrect. IP \'%s\'\n", login.c_str(), inet_ntostring(sip).c_str());
+ WriteServLog("User %s. IP address is incorrect. IP \'%s\'", login.c_str(), inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "ðÏÌØÚÏ×ÁÔÅÌØ ÎÅ ÏÐÏÚÎÁÎ! ðÒÏ×ÅÒØÔÅ IP ÁÄÒÅÓ.");
return 0;
}
int ret = -1;
-switch (pn)
+switch (pi->second)
{
case CONN_SYN_N:
switch (protoVer)
{
case 6:
connSyn6 = (CONN_SYN_6*)(buff - offset);
- ret = Process_CONN_SYN_6(connSyn6, &(it->second), user, sip);
+ ret = Process_CONN_SYN_6(connSyn6, &(it->second), sip);
break;
case 7:
connSyn7 = (CONN_SYN_7*)(buff - offset);
- ret = Process_CONN_SYN_7(connSyn7, &(it->second), user, sip);
+ ret = Process_CONN_SYN_7(connSyn7, &(it->second), sip);
break;
case 8:
connSyn8 = (CONN_SYN_8*)(buff - offset);
- ret = Process_CONN_SYN_8(connSyn8, &(it->second), user, sip);
+ ret = Process_CONN_SYN_8(connSyn8, &(it->second), sip);
break;
}
switch (protoVer)
{
case 6:
- Send_CONN_SYN_ACK_6(iaUser, user, sip);
+ Send_CONN_SYN_ACK_6(iaUser, sip);
break;
case 7:
- Send_CONN_SYN_ACK_7(iaUser, user, sip);
+ Send_CONN_SYN_ACK_7(iaUser, sip);
break;
case 8:
- Send_CONN_SYN_ACK_8(iaUser, user, sip);
+ Send_CONN_SYN_ACK_8(iaUser, sip);
break;
}
break;
switch (protoVer)
{
case 6:
- ret = Process_CONN_ACK_6(connAck, iaUser, user, sip);
+ ret = Process_CONN_ACK_6(connAck, iaUser, sip);
break;
case 7:
- ret = Process_CONN_ACK_7(connAck, iaUser, user, sip);
+ ret = Process_CONN_ACK_7(connAck, iaUser, sip);
break;
case 8:
- ret = Process_CONN_ACK_8((CONN_ACK_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_CONN_ACK_8((CONN_ACK_8*)(buff - offset), iaUser, sip);
break;
}
switch (protoVer)
{
case 6:
- ret = Process_ALIVE_ACK_6(aliveAck, iaUser, user, sip);
+ ret = Process_ALIVE_ACK_6(aliveAck, iaUser, sip);
break;
case 7:
- ret = Process_ALIVE_ACK_7(aliveAck, iaUser, user, sip);
+ ret = Process_ALIVE_ACK_7(aliveAck, iaUser, sip);
break;
case 8:
- ret = Process_ALIVE_ACK_8((ALIVE_ACK_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_ALIVE_ACK_8((ALIVE_ACK_8*)(buff - offset), iaUser, sip);
break;
}
break;
switch (protoVer)
{
case 6:
- ret = Process_DISCONN_SYN_6(disconnSyn, iaUser, user, sip);
+ ret = Process_DISCONN_SYN_6(disconnSyn, iaUser, sip);
break;
case 7:
- ret = Process_DISCONN_SYN_7(disconnSyn, iaUser, user, sip);
+ ret = Process_DISCONN_SYN_7(disconnSyn, iaUser, sip);
break;
case 8:
- ret = Process_DISCONN_SYN_8((DISCONN_SYN_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_DISCONN_SYN_8((DISCONN_SYN_8*)(buff - offset), iaUser, sip);
break;
}
switch (protoVer)
{
case 6:
- ret = Process_DISCONN_ACK_6(disconnAck, iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it);
break;
case 7:
- ret = Process_DISCONN_ACK_7(disconnAck, iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_7(disconnAck, iaUser, sip, it);
break;
case 8:
- ret = Process_DISCONN_ACK_8((DISCONN_ACK_8*)(buff - offset), iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_8((DISCONN_ACK_8*)(buff - offset), iaUser, sip, it);
break;
}
return 0;
}
//-----------------------------------------------------------------------------
-void AUTH_IA::DelUser(user_iter u)
+void AUTH_IA::DelUser(USER_PTR u)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (it->second.user == u)
{
printfd(__FILE__, "User removed!\n");
- it->second.user->Unauthorize(this);
+ users->Unauthorize(u->GetLogin(), this);
ip2user.erase(it);
}
}
return res;
}
//-----------------------------------------------------------------------------
-void AUTH_IA::InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
-{
-unsigned char keyL[PASSWD_LEN]; // ðÁÒÏÌØ ÄÌÑ ÛÉÆÒÏ×ËÉ
-memset(keyL, 0, PASSWD_LEN);
-strncpy((char *)keyL, password.c_str(), PASSWD_LEN);
-Blowfish_Init(ctx, keyL, PASSWD_LEN);
-}
-//-----------------------------------------------------------------------------
-void AUTH_IA::Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
-{
-// len8 - ÄÌÉÎÁ × 8-ÍÉ ÂÁÊÔÏ×ÙÈ ÂÌÏËÁÈ
-
-for (int i = 0; i < len8; i++)
- DecodeString(dst + i * 8, src + i * 8, ctx);
-}
-//-----------------------------------------------------------------------------
-void AUTH_IA::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
-{
-// len8 - ÄÌÉÎÁ × 8-ÍÉ ÂÁÊÔÏ×ÙÈ ÂÌÏËÁÈ
-
-for (int i = 0; i < len8; i++)
- EncodeString(dst + i * 8, src + i * 8, ctx);
-}
-//-----------------------------------------------------------------------------
int AUTH_IA::SendMessage(const STG_MSG & msg, uint32_t ip) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
//-----------------------------------------------------------------------------
int AUTH_IA::RealSendMessage6(const STG_MSG & msg, uint32_t ip, IA_USER & user)
{
-printfd(__FILE__, "RealSendMessage 6 user=%s\n", user.user->GetLogin().c_str());
+printfd(__FILE__, "RealSendMessage 6 user=%s\n", user.login.c_str());
char buffer[256];
INFO_6 info;
//-----------------------------------------------------------------------------
int AUTH_IA::RealSendMessage7(const STG_MSG & msg, uint32_t ip, IA_USER & user)
{
-printfd(__FILE__, "RealSendMessage 7 user=%s\n", user.user->GetLogin().c_str());
+printfd(__FILE__, "RealSendMessage 7 user=%s\n", user.login.c_str());
char buffer[300];
INFO_7 info;
//-----------------------------------------------------------------------------
int AUTH_IA::RealSendMessage8(const STG_MSG & msg, uint32_t ip, IA_USER & user)
{
-printfd(__FILE__, "RealSendMessage 8 user=%s\n", user.user->GetLogin().c_str());
+printfd(__FILE__, "RealSendMessage 8 user=%s\n", user.login.c_str());
char buffer[1500];
memset(buffer, 0, sizeof(buffer));
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_6(CONN_SYN_6 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_CONN_SYN_6(CONN_SYN_6 *, IA_USER * iaUser, uint32_t)
{
if (!(iaUser->phase.GetPhase() == 1 || iaUser->phase.GetPhase() == 3))
return -1;
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, uint32_t sip)
{
-return Process_CONN_SYN_6(connSyn, iaUser, user, sip);
+return Process_CONN_SYN_6(connSyn, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connSyn->dirs);
#endif
-int ret = Process_CONN_SYN_6((CONN_SYN_6*)connSyn, iaUser, user, sip);
+int ret = Process_CONN_SYN_6((CONN_SYN_6*)connSyn, iaUser, sip);
enabledDirs = connSyn->dirs;
return ret;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connAck->len);
iaUser->phase.UpdateTime();
iaUser->lastSendAlive = iaUser->phase.GetTime();
- if (iaUser->user->Authorize(sip, "", enabledDirs, this) == 0)
+ if (users->Authorize(iaUser->login, sip, enabledDirs, this))
{
iaUser->phase.SetPhase3();
printfd(__FILE__, "Phase changed from 2 to 3. Reason: CONN_ACK_6\n");
return -1;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, uint32_t sip)
{
-return Process_CONN_ACK_6(connAck, iaUser, user, sip);
+return Process_CONN_ACK_6(connAck, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connAck->len);
{
iaUser->phase.UpdateTime();
iaUser->lastSendAlive = iaUser->phase.GetTime();
- if (iaUser->user->Authorize(sip, "", enabledDirs, this) == 0)
+ if (users->Authorize(iaUser->login, sip, enabledDirs, this))
{
iaUser->phase.SetPhase3();
printfd(__FILE__, "Phase changed from 2 to 3. Reason: CONN_ACK_8\n");
return -1;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, uint32_t)
{
#ifdef ARCH_BE
SwapBytes(aliveAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, uint32_t sip)
{
-return Process_ALIVE_ACK_6(aliveAck, iaUser, user, sip);
+return Process_ALIVE_ACK_6(aliveAck, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, uint32_t)
{
#ifdef ARCH_BE
SwapBytes(aliveAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_6(DISCONN_SYN_6 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_DISCONN_SYN_6(DISCONN_SYN_6 *, IA_USER * iaUser, uint32_t)
{
printfd(__FILE__, "DISCONN_SYN_6\n");
if (iaUser->phase.GetPhase() != 3)
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, uint32_t sip)
{
-return Process_DISCONN_SYN_6(disconnSyn, iaUser, user, sip);
+return Process_DISCONN_SYN_6(disconnSyn, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_8(DISCONN_SYN_8 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_DISCONN_SYN_8(DISCONN_SYN_8 *, IA_USER * iaUser, uint32_t)
{
if (iaUser->phase.GetPhase() != 3)
{
//-----------------------------------------------------------------------------
int AUTH_IA::Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnAck,
IA_USER * iaUser,
- user_iter *,
uint32_t,
map<uint32_t, IA_USER>::iterator)
{
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, user_iter * user, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
+int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
{
-return Process_DISCONN_ACK_6(disconnAck, iaUser, user, sip, it);
+return Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, user_iter *, uint32_t, map<uint32_t, IA_USER>::iterator)
+int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, map<uint32_t, IA_USER>::iterator)
{
#ifdef ARCH_BE
SwapBytes(disconnAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_6(IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_6(IA_USER * iaUser, uint32_t sip)
{
//+++ Fill static data in connSynAck +++
// TODO Move this code. It must be executed only once
return Send(sip, iaSettings.GetUserPort(), (char*)&connSynAck6, Min8(sizeof(CONN_SYN_ACK_6)));;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_7(IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_7(IA_USER * iaUser, uint32_t sip)
{
-return Send_CONN_SYN_ACK_6(iaUser, user, sip);
+return Send_CONN_SYN_ACK_6(iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_8(IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_8(IA_USER * iaUser, uint32_t sip)
{
strcpy((char*)connSynAck8.hdr.magic, IA_ID);
connSynAck8.hdr.protoVer[0] = 0;
for (int i = 0; i < DIR_NUM; i++)
{
- aliveSyn6.md[i] = iaUser->user->property.down.Get()[i];
- aliveSyn6.mu[i] = iaUser->user->property.up.Get()[i];
+ aliveSyn6.md[i] = iaUser->user->GetProperty().down.Get()[i];
+ aliveSyn6.mu[i] = iaUser->user->GetProperty().up.Get()[i];
aliveSyn6.sd[i] = iaUser->user->GetSessionDownload()[i];
aliveSyn6.su[i] = iaUser->user->GetSessionUpload()[i];
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "%.3f", fmb / p);
}
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "C%.3f", fmb);
}
#ifdef IA_DEBUG
if (iaUser->aliveSent)
{
- printfd(__FILE__, "========= ALIVE_ACK_6(7) TIMEOUT !!! %s =========\n", iaUser->user->GetLogin().c_str());
+ printfd(__FILE__, "========= ALIVE_ACK_6(7) TIMEOUT !!! %s =========\n", iaUser->login.c_str());
}
iaUser->aliveSent = true;
#endif
-aliveSyn6.cash =(int64_t) (iaUser->user->property.cash.Get() * 1000.0);
+aliveSyn6.cash =(int64_t) (iaUser->user->GetProperty().cash.Get() * 1000.0);
if (!stgSettings->GetShowFeeInCash())
aliveSyn6.cash -= (int64_t)(tf->GetFee() * 1000.0);
for (int i = 0; i < DIR_NUM; i++)
{
- aliveSyn8.md[i] = iaUser->user->property.down.Get()[i];
- aliveSyn8.mu[i] = iaUser->user->property.up.Get()[i];
+ aliveSyn8.md[i] = iaUser->user->GetProperty().down.Get()[i];
+ aliveSyn8.mu[i] = iaUser->user->GetProperty().up.Get()[i];
aliveSyn8.sd[i] = iaUser->user->GetSessionDownload()[i];
aliveSyn8.su[i] = iaUser->user->GetSessionUpload()[i];
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "%.3f", fmb / p);
}
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "C%.3f", fmb);
}
const TARIFF * tf = iaUser->user->GetTariff();
-aliveSyn8.cash =(int64_t) (iaUser->user->property.cash.Get() * 1000.0);
+aliveSyn8.cash =(int64_t) (iaUser->user->GetProperty().cash.Get() * 1000.0);
if (!stgSettings->GetShowFeeInCash())
aliveSyn8.cash -= (int64_t)(tf->GetFee() * 1000.0);
Encrypt(&iaUser->ctx, (char*)&fin6, (char*)&fin6, Min8(sizeof(fin6))/8);
-iaUser->user->Unauthorize(this);
+users->Unauthorize(iaUser->login, this);
int ret = Send(sip, iaSettings.GetUserPort(), (char*)&fin6, Min8(sizeof(fin6)));
ip2user.erase(it);
Encrypt(&iaUser->ctx, (char*)&fin8, (char*)&fin8, Min8(sizeof(fin8))/8);
-iaUser->user->Unauthorize(this);
+users->Unauthorize(iaUser->login, this);
int ret = Send(sip, iaUser->port, (char*)&fin8, Min8(sizeof(fin8)));
ip2user.erase(it);
return ret;
}
//-----------------------------------------------------------------------------
-bool AUTH_IA::WaitPackets(int sd) const
+inline
+void InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
{
-fd_set rfds;
-FD_ZERO(&rfds);
-FD_SET(sd, &rfds);
-
-struct timeval tv;
-tv.tv_sec = 0;
-tv.tv_usec = 500000;
-
-int res = select(sd + 1, &rfds, NULL, NULL, &tv);
-if (res == -1) // Error
- {
- if (errno != EINTR)
- {
- printfd(__FILE__, "Error on select: '%s'\n", strerror(errno));
- }
- return false;
- }
+unsigned char keyL[PASSWD_LEN]; // ðÁÒÏÌØ ÄÌÑ ÛÉÆÒÏ×ËÉ
+memset(keyL, 0, PASSWD_LEN);
+strncpy((char *)keyL, password.c_str(), PASSWD_LEN);
+Blowfish_Init(ctx, keyL, PASSWD_LEN);
+}
+//-----------------------------------------------------------------------------
+inline
+void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+{
+// len8 - ÄÌÉÎÁ × 8-ÍÉ ÂÁÊÔÏ×ÙÈ ÂÌÏËÁÈ
-if (res == 0) // Timeout
- {
- return false;
- }
+for (int i = 0; i < len8; i++)
+ DecodeString(dst + i * 8, src + i * 8, ctx);
+}
+//-----------------------------------------------------------------------------
+inline
+void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+{
+// len8 - ÄÌÉÎÁ × 8-ÍÉ ÂÁÊÔÏ×ÙÈ ÂÌÏËÁÈ
-return true;
+for (int i = 0; i < len8; i++)
+ EncodeString(dst + i * 8, src + i * 8, ctx);
}