область видимости других сужена
return port;
}
//-----------------------------------------------------------------------------
return port;
}
//-----------------------------------------------------------------------------
-uint32_t RAD_SETTINGS::GetServerIP() const
-{
-return serverIP;
-}
-//-----------------------------------------------------------------------------
int RAD_SETTINGS::GetPassword(string * password) const
{
*password = RAD_SETTINGS::password;
int RAD_SETTINGS::GetPassword(string * password) const
{
*password = RAD_SETTINGS::password;
}
port = p;
///////////////////////////
}
port = p;
///////////////////////////
-pv.param = "ServerIP";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
- {
- serverIP = 0;
- }
-else
- {
- if (ParseIP(pvi->value[0], &serverIP))
- {
- serverIP = 0;
- }
- }
-///////////////////////////
pv.param = "Password";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
pv.param = "Password";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
RADIUS::RADIUS()
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
RADIUS::RADIUS()
+ : nonstop(false),
+ isRunning(false),
+ users(NULL),
+ stgSettings(NULL),
+ store(NULL),
+ sock(-1)
}
//-----------------------------------------------------------------------------
void RADIUS::SetUsers(USERS * u)
}
//-----------------------------------------------------------------------------
void RADIUS::SetUsers(USERS * u)
+struct sockaddr_in inAddr;
inAddr.sin_family = AF_INET;
inAddr.sin_family = AF_INET;
-inAddr.sin_port = htons(port);
+inAddr.sin_port = htons(radSettings.GetPort());
inAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
if (bind(sock, (struct sockaddr*)&inAddr, sizeof(inAddr)) < 0)
inAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
if (bind(sock, (struct sockaddr*)&inAddr, sizeof(inAddr)) < 0)
string password;
radSettings.GetPassword(&password);
string password;
radSettings.GetPassword(&password);
-port = radSettings.GetPort();
-serverIP = radSettings.GetServerIP();
radSettings.GetAuthServices(&authServices);
radSettings.GetAcctServices(&acctServices);
radSettings.GetAuthServices(&authServices);
radSettings.GetAcctServices(&acctServices);
- if (rad->RecvData(&packet))
+ struct sockaddr_in outerAddr;
+ if (rad->RecvData(&packet, &outerAddr))
{
printfd(__FILE__, "RADIUS::Run Error on RecvData\n");
}
{
printfd(__FILE__, "RADIUS::Run Error on RecvData\n");
}
{
packet.packetType = RAD_REJECT_PACKET;
}
{
packet.packetType = RAD_REJECT_PACKET;
}
+ rad->Send(packet, &outerAddr);
return NULL;
}
//-----------------------------------------------------------------------------
return NULL;
}
//-----------------------------------------------------------------------------
-int RADIUS::RecvData(RAD_PACKET * packet)
+int RADIUS::RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr)
{
int8_t buf[RAD_MAX_PACKET_LEN];
{
int8_t buf[RAD_MAX_PACKET_LEN];
- outerAddrLen = sizeof(struct sockaddr_in);
- int dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, (struct sockaddr *)&outerAddr, &outerAddrLen);
+ socklen_t outerAddrLen = sizeof(struct sockaddr_in);
+ int dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast<struct sockaddr *>(outerAddr), &outerAddrLen);
if (dataLen > 0) {
Decrypt(&ctx, (char *)packet, (const char *)buf, dataLen / 8);
}
if (dataLen > 0) {
Decrypt(&ctx, (char *)packet, (const char *)buf, dataLen / 8);
}
return 0;
}
//-----------------------------------------------------------------------------
return 0;
}
//-----------------------------------------------------------------------------
-int RADIUS::Send(const RAD_PACKET & packet)
+int RADIUS::Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr)
-int res, len = sizeof(RAD_PACKET);
+size_t len = sizeof(RAD_PACKET);
char buf[1032];
Encrypt(&ctx, buf, (char *)&packet, len / 8);
char buf[1032];
Encrypt(&ctx, buf, (char *)&packet, len / 8);
-res = sendto(sock, buf, len, 0, (struct sockaddr *)&outerAddr, outerAddrLen);
-
-return 0;
+return sendto(sock, buf, len, 0, reinterpret_cast<struct sockaddr *>(outerAddr), sizeof(struct sockaddr_in));
}
//-----------------------------------------------------------------------------
int RADIUS::ProcessData(RAD_PACKET * packet)
{
}
//-----------------------------------------------------------------------------
int RADIUS::ProcessData(RAD_PACKET * packet)
{
-//struct in_addr addr = {packet->ip};
if (strncmp((const char *)packet->protoVer, "01", 2))
{
printfd(__FILE__, "RADIUS::ProcessData packet.protoVer incorrect\n");
if (strncmp((const char *)packet->protoVer, "01", 2))
{
printfd(__FILE__, "RADIUS::ProcessData packet.protoVer incorrect\n");
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctUpdatePacket(RAD_PACKET * packet)
{
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctUpdatePacket(RAD_PACKET * packet)
{
-// Fake. May be used later
+// Fake. May be use it later
packet->packetType = RAD_ACCEPT_PACKET;
return 0;
}
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctOtherPacket(RAD_PACKET * packet)
{
packet->packetType = RAD_ACCEPT_PACKET;
return 0;
}
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctOtherPacket(RAD_PACKET * packet)
{
-// Fake. May be used later
+// Fake. May be use it later
packet->packetType = RAD_ACCEPT_PACKET;
return 0;
}
packet->packetType = RAD_ACCEPT_PACKET;
return 0;
}
const string& GetStrError() const { return errorStr; };
int ParseSettings(const MODULE_SETTINGS & s);
uint16_t GetPort() const;
const string& GetStrError() const { return errorStr; };
int ParseSettings(const MODULE_SETTINGS & s);
uint16_t GetPort() const;
- uint32_t GetServerIP() const;
int GetPassword(string * password) const;
int GetAuthServices(list<string> * svcs) const;
int GetAcctServices(list<string> * svcs) const;
int GetPassword(string * password) const;
int GetAuthServices(list<string> * svcs) const;
int GetAcctServices(list<string> * svcs) const;
uint16_t port;
string errorStr;
string password;
uint16_t port;
string errorStr;
string password;
list<string> authServices;
list<string> acctServices;
};
list<string> authServices;
list<string> acctServices;
};
void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
- int Send(const RAD_PACKET & packet);
- int RecvData(RAD_PACKET * packet);
+ int Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr);
+ int RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr);
int ProcessData(RAD_PACKET * packet);
int ProcessAutzPacket(RAD_PACKET * packet);
int ProcessData(RAD_PACKET * packet);
int ProcessAutzPacket(RAD_PACKET * packet);
map<string, RAD_SESSION> sessions;
bool nonstop;
map<string, RAD_SESSION> sessions;
bool nonstop;
bool isRunning;
USERS * users;
bool isRunning;
USERS * users;
pthread_mutex_t mutex;
int sock;
pthread_mutex_t mutex;
int sock;
- struct sockaddr_in inAddr;
- socklen_t inAddrLen;
- uint16_t port;
- uint32_t serverIP;
- struct sockaddr_in outerAddr;
- socklen_t outerAddrLen;
//-----------------------------------------------------------------------------
#endif
//-----------------------------------------------------------------------------
#endif