#include <sys/types.h>
#include <sys/socket.h>
-#include <unistd.h> // usleep, close
+#include <unistd.h> // close
#include <csignal>
#include <cstdlib>
#include <cstdio> // snprintf
#include <cerrno>
+#include <cmath>
#include <algorithm>
#include "stg/common.h"
#include "stg/plugin_creator.h"
#include "inetaccess.h"
-extern volatile const time_t stgTime;
-
-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);
+extern volatile time_t stgTime;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
+namespace
+{
PLUGIN_CREATOR<AUTH_IA> iac;
+
+void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
+void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8);
+void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8);
+}
+
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
: userDelay(0),
userTimeout(0),
port(0),
+ errorStr(),
freeMbShowType(freeMbCash)
{
}
{
int p;
PARAM_VALUE pv;
-vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<PARAM_VALUE>::const_iterator pvi;
///////////////////////////
pv.param = "Port";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
printfd(__FILE__, "Cannot parse parameter 'Port'\n");
return -1;
}
-port = p;
+port = static_cast<uint16_t>(p);
///////////////////////////
pv.param = "UserDelay";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
return -1;
}
/////////////////////////////////////////////////////////////
-string freeMbType;
+std::string freeMbType;
int n = 0;
pv.param = "FreeMb";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
#ifdef IA_PHASE_DEBUG
IA_PHASE::IA_PHASE()
: phase(1),
+ phaseTime(),
flog(NULL)
{
gettimeofday(&phaseTime, NULL);
}
#else
IA_PHASE::IA_PHASE()
- : phase(1)
+ : phase(1),
+ phaseTime()
{
gettimeofday(&phaseTime, NULL);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
AUTH_IA::AUTH_IA()
- : nonstop(false),
+ : ctxS(),
+ errorStr(),
+ iaSettings(),
+ settings(),
+ nonstop(false),
isRunningRun(false),
isRunningRunTimeouter(false),
users(NULL),
stgSettings(NULL),
+ ip2user(),
+ recvThread(),
+ timeouterThread(),
+ mutex(),
listenSocket(-1),
- WriteServLog(GetStgLogger()),
+ connSynAck6(),
+ connSynAck8(),
+ disconnSynAck6(),
+ disconnSynAck8(),
+ aliveSyn6(),
+ aliveSyn8(),
+ fin6(),
+ fin8(),
+ packetTypes(),
enabledDirs(0xFFffFFff),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "auth_ia"))
{
InitEncrypt(&ctxS, "pr7Hhen");
{
errorStr = "Cannot create thread.";
printfd(__FILE__, "Cannot create recv thread\n");
+ logger("Cannot create recv thread.");
return -1;
}
}
{
errorStr = "Cannot create thread.";
printfd(__FILE__, "Cannot create timeouter thread\n");
+ logger("Cannot create timeouter thread.");
return -1;
}
}
//5 seconds to thread stops itself
for (int i = 0; i < 25 && isRunningRun; i++)
{
- usleep(200000);
- }
-
- //after 5 seconds waiting thread still running. now killing it
- if (isRunningRun)
- {
- if (pthread_kill(recvThread, SIGINT))
- {
- errorStr = "Cannot kill thread.";
- printfd(__FILE__, "Cannot kill thread\n");
- return -1;
- }
- for (int i = 0; i < 25 && isRunningRun; ++i)
- usleep(200000);
- if (isRunningRun)
- {
- printfd(__FILE__, "Failed to stop recv thread\n");
- }
- else
- {
- pthread_join(recvThread, NULL);
- }
- printfd(__FILE__, "AUTH_IA killed Run\n");
+ struct timespec ts = {0, 200000000};
+ nanosleep(&ts, NULL);
}
}
//5 seconds to thread stops itself
for (int i = 0; i < 25 && isRunningRunTimeouter; i++)
{
- usleep(200000);
- }
-
- //after 5 seconds waiting thread still running. now killing it
- if (isRunningRunTimeouter)
- {
- if (pthread_kill(timeouterThread, SIGINT))
- {
- errorStr = "Cannot kill thread.";
- return -1;
- }
- for (int i = 0; i < 25 && isRunningRunTimeouter; ++i)
- usleep(200000);
- if (isRunningRunTimeouter)
- {
- printfd(__FILE__, "Failed to stop timeouter thread\n");
- }
- else
- {
- pthread_join(timeouterThread, NULL);
- }
- printfd(__FILE__, "AUTH_IA killed Timeouter\n");
+ struct timespec ts = {0, 200000000};
+ nanosleep(&ts, NULL);
}
}
-printfd(__FILE__, "AUTH_IA::Stoped successfully.\n");
+
users->DelNotifierUserDel(&onDelUserNotifier);
+
+if (isRunningRun || isRunningRunTimeouter)
+ return -1;
+
+printfd(__FILE__, "AUTH_IA::Stoped successfully.\n");
return 0;
}
//-----------------------------------------------------------------------------
void * AUTH_IA::Run(void * d)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
AUTH_IA * ia = static_cast<AUTH_IA *>(d);
ia->isRunningRun = true;
if ((touchTime + MONITOR_TIME_DELAY_SEC <= stgTime) && ia->stgSettings->GetMonitoring())
{
touchTime = stgTime;
- string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_r";
+ std::string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_r";
TouchFile(monFile.c_str());
}
}
//-----------------------------------------------------------------------------
void * AUTH_IA::RunTimeouter(void * d)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
AUTH_IA * ia = static_cast<AUTH_IA *>(d);
ia->isRunningRunTimeouter = true;
int a = -1;
-string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_t";
+std::string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_t";
while (ia->nonstop)
{
- usleep(20000);
+ struct timespec ts = {0, 20000000};
+ nanosleep(&ts, NULL);
ia->Timeouter();
// TODO change counter to timer and MONITOR_TIME_DELAY_SEC
if (++a % (50 * 60) == 0 && ia->stgSettings->GetMonitoring())
if (listenSocket < 0)
{
errorStr = "Cannot create socket.";
+ logger("Cannot create a socket: %s", strerror(errno));
return -1;
}
listenAddr.sin_family = AF_INET;
-listenAddr.sin_port = htons(iaSettings.GetUserPort());
+listenAddr.sin_port = htons(static_cast<uint16_t>(iaSettings.GetUserPort()));
listenAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
if (bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr)) < 0)
{
errorStr = "AUTH_IA: Bind failed.";
+ logger("Cannot bind the socket: %s", strerror(errno));
return -1;
}
struct sockaddr_in outerAddr;
socklen_t outerAddrLen(sizeof(outerAddr));
-int dataLen = recvfrom(listenSocket, buffer, bufferSize, 0, (struct sockaddr *)&outerAddr, &outerAddrLen);
+ssize_t dataLen = recvfrom(listenSocket, buffer, bufferSize, 0, (struct sockaddr *)&outerAddr, &outerAddrLen);
if (!dataLen) // EOF
{
if (errno != EINTR)
{
printfd(__FILE__, "recvfrom res=%d, error: '%s'\n", dataLen, strerror(errno));
+ logger("recvfrom error: %s", strerror(errno));
return -1;
}
return 0;
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);
+ logger("User's connect failed: user '%s' not found. IP %s",
+ login,
+ inet_ntostring(sip).c_str());
+ printfd(__FILE__, "User '%s' NOT found!\n", login);
SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ!");
+ return -1;
}
printfd(__FILE__, "User '%s' FOUND!\n", user->GetLogin().c_str());
if (user->GetProperty().disabled.Get())
{
+ logger("Cannont authorize '%s', user is disabled.", login);
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÂÌÏËÉÒÏ×ÁÎÁ");
return 0;
}
if (user->GetProperty().passive.Get())
{
+ logger("Cannont authorize '%s', user is passive.", login);
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÍÏÒÏÖÅÎÁ");
return 0;
}
{
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());
+ logger("User %s. IP address is incorrect. IP %s",
+ user->GetLogin().c_str(), inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "ðÏÌØÚÏ×ÁÔÅÌØ ÎÅ ÏÐÏÚÎÁÎ! ðÒÏ×ÅÒØÔÅ IP ÁÄÒÅÓ.");
return 0;
}
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-map<uint32_t, IA_USER>::iterator it;
+std::map<uint32_t, IA_USER>::iterator it;
it = ip2user.begin();
uint32_t sip;
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user)
+int AUTH_IA::PacketProcessor(void * buff, size_t 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;
+const size_t offset = LOGIN_LEN + 2 + 6; // LOGIN_LEN + sizeOfMagic + sizeOfVer;
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-map<uint32_t, IA_USER>::iterator it(ip2user.find(sip));
+std::map<uint32_t, IA_USER>::iterator it(ip2user.find(sip));
if (it == ip2user.end())
{
userPtr->GetLogin().c_str(),
inet_ntostring(sip).c_str(),
login.c_str());
- WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
- userPtr->GetLogin().c_str(),
- inet_ntostring(sip).c_str(),
- login.c_str());
+ logger("IP address is already in use by user '%s'. IP %s, login: '%s'",
+ userPtr->GetLogin().c_str(),
+ inet_ntostring(sip).c_str(),
+ login.c_str());
SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
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;
- ip2user[sip].user = user;
- ip2user[sip].protoVer = protoVer;
- ip2user[sip].port = sport;
+ std::pair<std::map<uint32_t, IA_USER>::iterator, bool> res;
+ res = ip2user.insert(std::make_pair(sip, IA_USER(login, user, sport, protoVer)));
+ it = res.first;
#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
- if (it == ip2user.end())
- {
- printfd(__FILE__, "+++ ERROR +++\n");
- return -1;
- }
}
else if (user->GetID() != it->second.user->GetID())
{
it->second.user->GetLogin().c_str(),
inet_ntostring(sip).c_str(),
user->GetLogin().c_str());
- WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
- it->second.user->GetLogin().c_str(),
- inet_ntostring(sip).c_str(),
- user->GetLogin().c_str());
+ logger("IP address is already in use by user '%s'. IP %s, login: '%s'",
+ it->second.user->GetLogin().c_str(),
+ inet_ntostring(sip).c_str(),
+ user->GetLogin().c_str());
SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
return 0;
}
IA_USER * iaUser = &(it->second);
-if (iaUser->port != sport)
- iaUser->port = sport;
-
if (iaUser->password != user->GetProperty().password.Get())
{
InitEncrypt(&iaUser->ctx, user->GetProperty().password.Get());
iaUser->password = user->GetProperty().password.Get();
}
-buff += offset;
-Decrypt(&iaUser->ctx, buff, buff, (dataLen - offset) / 8);
+Decrypt(&iaUser->ctx, static_cast<char *>(buff) + offset, static_cast<char *>(buff) + offset, (dataLen - offset) / 8);
char packetName[IA_MAX_TYPE_LEN];
-strncpy(packetName, buff + 4, IA_MAX_TYPE_LEN);
+strncpy(packetName, static_cast<char *>(buff) + offset + 4, IA_MAX_TYPE_LEN);
packetName[IA_MAX_TYPE_LEN - 1] = 0;
-map<string, int>::iterator pi(packetTypes.find(packetName));
+std::map<std::string, int>::iterator pi(packetTypes.find(packetName));
if (pi == packetTypes.end())
{
SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ ÉÌÉ ÐÁÒÏÌØ!");
printfd(__FILE__, "Login or password is wrong!\n");
- WriteServLog("User's connect failed. User: '%s', ip %s. Wrong login or password",
- login.c_str(),
- inet_ntostring(sip).c_str());
+ logger("User's connect failed. User: '%s', ip %s. Wrong login or password",
+ login.c_str(),
+ inet_ntostring(sip).c_str());
ip2user.erase(it);
return 0;
}
printfd(__FILE__, "Login %s already in use from ip %s. IP %s\n",
login.c_str(), inet_ntostring(user->GetCurrIP()).c_str(),
inet_ntostring(sip).c_str());
- WriteServLog("Login %s already in use from ip %s. IP %s",
- login.c_str(),
- inet_ntostring(user->GetCurrIP()).c_str(),
- inet_ntostring(sip).c_str());
+ logger("Login '%s' is already in use from ip %s. IP %s",
+ login.c_str(),
+ inet_ntostring(user->GetCurrIP()).c_str(),
+ inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "÷ÁÛ ÌÏÇÉÎ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
ip2user.erase(it);
return 0;
switch (protoVer)
{
case 6:
- if (Process_CONN_SYN_6((CONN_SYN_6 *)(buff - offset), &(it->second), sip))
+ if (Process_CONN_SYN_6(static_cast<CONN_SYN_6 *>(buff), &(it->second), sip))
return -1;
return Send_CONN_SYN_ACK_6(iaUser, sip);
case 7:
- if (Process_CONN_SYN_7((CONN_SYN_7 *)(buff - offset), &(it->second), sip))
+ if (Process_CONN_SYN_7(static_cast<CONN_SYN_7 *>(buff), &(it->second), sip))
return -1;
return Send_CONN_SYN_ACK_7(iaUser, sip);
case 8:
- if (Process_CONN_SYN_8((CONN_SYN_8 *)(buff - offset), &(it->second), sip))
+ if (Process_CONN_SYN_8(static_cast<CONN_SYN_8 *>(buff), &(it->second), sip))
return -1;
return Send_CONN_SYN_ACK_8(iaUser, sip);
}
switch (protoVer)
{
case 6:
- if (Process_CONN_ACK_6((CONN_ACK_6 *)(buff - offset), iaUser, sip))
+ if (Process_CONN_ACK_6(static_cast<CONN_ACK_6 *>(buff), iaUser, sip))
return -1;
return Send_ALIVE_SYN_6(iaUser, sip);
case 7:
- if (Process_CONN_ACK_7((CONN_ACK_6 *)(buff - offset), iaUser, sip))
+ if (Process_CONN_ACK_7(static_cast<CONN_ACK_6 *>(buff), iaUser, sip))
return -1;
return Send_ALIVE_SYN_7(iaUser, sip);
case 8:
- if (Process_CONN_ACK_8((CONN_ACK_8 *)(buff - offset), iaUser, sip))
+ if (Process_CONN_ACK_8(static_cast<CONN_ACK_8 *>(buff), iaUser, sip))
return -1;
return Send_ALIVE_SYN_8(iaUser, sip);
}
switch (protoVer)
{
case 6:
- return Process_ALIVE_ACK_6((ALIVE_ACK_6 *)(buff - offset), iaUser, sip);
+ return Process_ALIVE_ACK_6(static_cast<ALIVE_ACK_6 *>(buff), iaUser, sip);
case 7:
- return Process_ALIVE_ACK_7((ALIVE_ACK_6 *)(buff - offset), iaUser, sip);
+ return Process_ALIVE_ACK_7(static_cast<ALIVE_ACK_6 *>(buff), iaUser, sip);
case 8:
- return Process_ALIVE_ACK_8((ALIVE_ACK_8 *)(buff - offset), iaUser, sip);
+ return Process_ALIVE_ACK_8(static_cast<ALIVE_ACK_8 *>(buff), iaUser, sip);
}
break;
switch (protoVer)
{
case 6:
- if (Process_DISCONN_SYN_6((DISCONN_SYN_6 *)(buff - offset), iaUser, sip))
+ if (Process_DISCONN_SYN_6(static_cast<DISCONN_SYN_6 *>(buff), iaUser, sip))
return -1;
return Send_DISCONN_SYN_ACK_6(iaUser, sip);
case 7:
- if (Process_DISCONN_SYN_7((DISCONN_SYN_6 *)(buff - offset), iaUser, sip))
+ if (Process_DISCONN_SYN_7(static_cast<DISCONN_SYN_6 *>(buff), iaUser, sip))
return -1;
return Send_DISCONN_SYN_ACK_7(iaUser, sip);
case 8:
- if (Process_DISCONN_SYN_8((DISCONN_SYN_8 *)(buff - offset), iaUser, sip))
+ if (Process_DISCONN_SYN_8(static_cast<DISCONN_SYN_8 *>(buff), iaUser, sip))
return -1;
return Send_DISCONN_SYN_ACK_8(iaUser, sip);
}
switch (protoVer)
{
case 6:
- if (Process_DISCONN_ACK_6((DISCONN_ACK_6 *)(buff - offset), iaUser, sip, it))
+ if (Process_DISCONN_ACK_6(static_cast<DISCONN_ACK_6 *>(buff), iaUser, sip, it))
return -1;
return Send_FIN_6(iaUser, sip, it);
case 7:
- if (Process_DISCONN_ACK_7((DISCONN_ACK_6 *)(buff - offset), iaUser, sip, it))
+ if (Process_DISCONN_ACK_7(static_cast<DISCONN_ACK_6 *>(buff), iaUser, sip, it))
return -1;
return Send_FIN_7(iaUser, sip, it);
case 8:
- if (Process_DISCONN_ACK_8((DISCONN_ACK_8 *)(buff - offset), iaUser, sip, it))
+ if (Process_DISCONN_ACK_8(static_cast<DISCONN_ACK_8 *>(buff), iaUser, sip, it))
return -1;
return Send_FIN_8(iaUser, sip, it);
}
if (!ip)
return;
-map<uint32_t, IA_USER>::iterator it;
+std::map<uint32_t, IA_USER>::iterator it;
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
it = ip2user.find(ip);
}
}
//-----------------------------------------------------------------------------
-int AUTH_IA::SendError(uint32_t ip, uint16_t port, int protoVer, const string & text)
+int AUTH_IA::SendError(uint32_t ip, uint16_t port, int protoVer, const std::string & text)
{
struct sockaddr_in sendAddr;
+ssize_t res;
switch (protoVer)
{
- int res;
case 6:
case 7:
ERR err;
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send(uint32_t ip, uint16_t port, const char * buffer, int len)
+int AUTH_IA::Send(uint32_t ip, uint16_t port, const char * buffer, size_t len)
{
struct sockaddr_in sendAddr;
sendAddr.sin_port = htons(port);
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)
+if (sendto(listenSocket, buffer, len, 0, (struct sockaddr*)&sendAddr, sizeof(sendAddr)) == static_cast<ssize_t>(len))
return 0;
return -1;
{
printfd(__FILE__, "SendMessage userIP=%s\n", inet_ntostring(ip).c_str());
-map<uint32_t, IA_USER>::iterator it;
+std::map<uint32_t, IA_USER>::iterator it;
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
it = ip2user.find(ip);
info.len = 264;
strncpy((char*)info.type, "INFO_7", 16);
-info.infoType = msg.header.type;
-info.showTime = msg.header.showTime;
+info.infoType = static_cast<int8_t>(msg.header.type);
+info.showTime = static_cast<int8_t>(msg.header.showTime);
info.sendTime = msg.header.creationTime;
size_t len = info.len;
info.len = 1056;
strncpy((char*)info.type, "INFO_8", 16);
-info.infoType = msg.header.type;
-info.showTime = msg.header.showTime;
+info.infoType = static_cast<int8_t>(msg.header.type);
+info.showTime = static_cast<int8_t>(msg.header.showTime);
info.sendTime = msg.header.creationTime;
strncpy((char*)info.text, msg.text.c_str(), IA_MAX_MSG_LEN_8 - 1);
SwapBytes(connAck->rnd);
#endif
printfd( __FILE__, "CONN_ACK_6 %s\n", connAck->type);
-// ÕÓÔÁÎÏ×ÉÔØ ÎÏ×ÕÀ ÆÁÚÕ É ×ÒÅÍÑ É ÒÁÚÒÅÛÉÔØ ÉÎÅÔ
+
if ((iaUser->phase.GetPhase() == 2) && (connAck->rnd == iaUser->rnd + 1))
{
iaUser->phase.UpdateTime();
int AUTH_IA::Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnAck,
IA_USER * iaUser,
uint32_t,
- map<uint32_t, IA_USER>::iterator)
+ std::map<uint32_t, IA_USER>::iterator)
{
#ifdef ARCH_BE
SwapBytes(disconnAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, 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, std::map<uint32_t, IA_USER>::iterator it)
{
return Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, map<uint32_t, IA_USER>::iterator)
+int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, std::map<uint32_t, IA_USER>::iterator)
{
#ifdef ARCH_BE
SwapBytes(disconnAck->len);
}
//--- Fill static data in connSynAck ---
-iaUser->rnd = random();
+iaUser->rnd = static_cast<uint32_t>(random());
connSynAck6.rnd = iaUser->rnd;
connSynAck6.userTimeOut = iaSettings.GetUserTimeout();
}
//--- Fill static data in connSynAck ---
-iaUser->rnd = random();
+iaUser->rnd = static_cast<uint32_t>(random());
connSynAck8.rnd = iaUser->rnd;
connSynAck8.userTimeOut = iaSettings.GetUserTimeout();
int AUTH_IA::Send_ALIVE_SYN_6(IA_USER * iaUser, uint32_t sip)
{
aliveSyn6.len = Min8(sizeof(ALIVE_SYN_6));
-aliveSyn6.rnd = iaUser->rnd = random();
+aliveSyn6.rnd = iaUser->rnd = static_cast<uint32_t>(random());
strcpy((char*)aliveSyn6.type, "ALIVE_SYN");
aliveSyn6.md[dn],
dn,
stgTime);
- p *= (1024 * 1024);
- if (p == 0)
+ p *= 1024 * 1024;
+ if (std::fabs(p) < 1.0e-3)
{
snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "---");
}
aliveSyn8.hdr.protoVer[1] = 8;
aliveSyn8.len = Min8(sizeof(ALIVE_SYN_8));
-aliveSyn8.rnd = iaUser->rnd = random();
+aliveSyn8.rnd = iaUser->rnd = static_cast<uint32_t>(random());
strcpy((char*)aliveSyn8.type, "ALIVE_SYN");
aliveSyn8.md[dn],
dn,
stgTime);
- p *= (1024 * 1024);
- if (p == 0)
+ p *= 1024 * 1024;
+ if (std::fabs(p) < 1.0e-3)
{
snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "---");
}
{
disconnSynAck6.len = Min8(sizeof(DISCONN_SYN_ACK_6));
strcpy((char*)disconnSynAck6.type, "DISCONN_SYN_ACK");
-disconnSynAck6.rnd = iaUser->rnd = random();
+disconnSynAck6.rnd = iaUser->rnd = static_cast<uint32_t>(random());
#ifdef ARCH_BE
SwapBytes(disconnSynAck6.len);
disconnSynAck8.len = Min8(sizeof(DISCONN_SYN_ACK_8));
strcpy((char*)disconnSynAck8.type, "DISCONN_SYN_ACK");
-disconnSynAck8.rnd = iaUser->rnd = random();
+disconnSynAck8.rnd = iaUser->rnd = static_cast<uint32_t>(random());
#ifdef ARCH_BE
SwapBytes(disconnSynAck8.len);
return Send(sip, iaUser->port, (char*)&disconnSynAck8, Min8(sizeof(disconnSynAck8)));
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_FIN_6(IA_USER * iaUser, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
+int AUTH_IA::Send_FIN_6(IA_USER * iaUser, uint32_t sip, std::map<uint32_t, IA_USER>::iterator it)
{
fin6.len = Min8(sizeof(FIN_6));
strcpy((char*)fin6.type, "FIN");
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<uint32_t, IA_USER>::iterator it)
+int AUTH_IA::Send_FIN_7(IA_USER * iaUser, uint32_t sip, std::map<uint32_t, IA_USER>::iterator it)
{
return Send_FIN_6(iaUser, sip, it);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_FIN_8(IA_USER * iaUser, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
+int AUTH_IA::Send_FIN_8(IA_USER * iaUser, uint32_t sip, std::map<uint32_t, IA_USER>::iterator it)
{
strcpy((char*)fin8.hdr.magic, IA_ID);
fin8.hdr.protoVer[0] = 0;
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;
}
+namespace
+{
//-----------------------------------------------------------------------------
inline
-void InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
+void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password)
{
unsigned char keyL[PASSWD_LEN];
memset(keyL, 0, PASSWD_LEN);
}
//-----------------------------------------------------------------------------
inline
-void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8)
{
-for (int i = 0; i < len8; i++)
- DecodeString(dst + i * 8, src + i * 8, ctx);
+for (size_t i = 0; i < len8; i++)
+ DecodeString(static_cast<char *>(dst) + i * 8, static_cast<const char *>(src) + i * 8, ctx);
}
//-----------------------------------------------------------------------------
inline
-void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8)
{
-for (int i = 0; i < len8; i++)
- EncodeString(dst + i * 8, src + i * 8, ctx);
+for (size_t i = 0; i < len8; i++)
+ EncodeString(static_cast<char *>(dst) + i * 8, static_cast<const char *>(src) + i * 8, ctx);
+}
+//-----------------------------------------------------------------------------
}