#include "stg/plugin_creator.h"
#include "radius.h"
-extern volatile const time_t stgTime;
-
-void InitEncrypt(BLOWFISH_CTX * ctx, const std::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<RADIUS> radc;
+
+void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
+void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8);
+void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8);
+}
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
printfd(__FILE__, "Cannot parse parameter 'Port'\n");
return -1;
}
-port = p;
+port = static_cast<uint16_t>(p);
///////////////////////////
pv.param = "Password";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-RADIUS * rad = (RADIUS *)d;
+RADIUS * rad = static_cast<RADIUS *>(d);
RAD_PACKET packet;
rad->isRunning = true;
{
int8_t buf[RAD_MAX_PACKET_LEN];
socklen_t outerAddrLen = sizeof(struct sockaddr_in);
- int dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast<struct sockaddr *>(outerAddr), &outerAddrLen);
+ ssize_t dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast<struct sockaddr *>(outerAddr), &outerAddrLen);
if (dataLen < 0)
{
logger("recvfrom error: %s", strerror(errno));
return 0;
}
//-----------------------------------------------------------------------------
-int RADIUS::Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr)
+ssize_t RADIUS::Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr)
{
size_t len = sizeof(RAD_PACKET);
char buf[1032];
Encrypt(&ctx, buf, (char *)&packet, len / 8);
-int res = sendto(sock, buf, len, 0, reinterpret_cast<struct sockaddr *>(outerAddr), sizeof(struct sockaddr_in));
+ssize_t res = sendto(sock, buf, len, 0, reinterpret_cast<struct sockaddr *>(outerAddr), sizeof(struct sockaddr_in));
if (res < 0)
logger("sendto error: %s", strerror(errno));
return res;
printfd(__FILE__, "RADIUS::ProcessData Unsupported packet type: %d\n", packet->packetType);
return -1;
};
-return 0;
}
//-----------------------------------------------------------------------------
int RADIUS::ProcessAutzPacket(RAD_PACKET * packet)
return 0;
}
//-----------------------------------------------------------------------------
-void RADIUS::PrintServices(const std::list<std::string> & svcs)
-{
-for_each(svcs.begin(), svcs.end(), Printer());
-}
-//-----------------------------------------------------------------------------
bool RADIUS::FindUser(USER_PTR * ui, const std::string & login) const
{
if (users->FindByName(login, ui))
return CanAuthService(svc) || CanAcctService(svc);
}
//-----------------------------------------------------------------------------
+namespace
+{
+
inline
void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password)
{
}
//-----------------------------------------------------------------------------
inline
-void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8)
{
// len8 - длина в 8-ми байтовых блоках
if (dst != src)
memcpy(dst, src, len8 * 8);
-for (int i = 0; i < len8; i++)
- Blowfish_Encrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4));
+for (size_t i = 0; i < len8; i++)
+ Blowfish_Encrypt(ctx, static_cast<uint32_t *>(dst) + i * 2, static_cast<uint32_t *>(dst) + i * 2 + 1);
}
//-----------------------------------------------------------------------------
inline
-void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8)
+void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8)
{
// len8 - длина в 8-ми байтовых блоках
if (dst != src)
memcpy(dst, src, len8 * 8);
-for (int i = 0; i < len8; i++)
- Blowfish_Decrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4));
+for (size_t i = 0; i < len8; i++)
+ Blowfish_Decrypt(ctx, static_cast<uint32_t *>(dst) + i * 2, static_cast<uint32_t *>(dst) + i * 2 + 1);
}
+
+} // namespace anonymous