From 913b7a4ab586482c853b679fcd8415cf88524c31 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 14:41:40 +0200 Subject: [PATCH] =?utf8?q?=D0=92=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD?= =?utf8?q?=D0=B5=20=D1=80=D0=B0=D0=B4=D0=B8=D1=83=D1=81=D0=B0=20=D1=83?= =?utf8?q?=D0=B1=D1=80=D0=B0=D0=BD=D1=8B=20=D0=BD=D0=B5=20=D0=B8=D1=81?= =?utf8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D0=B5=20?= =?utf8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20?= =?utf8?q?=D0=B8=20=D1=87=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=BB=D0=B0?= =?utf8?q?=D1=81=D1=81=D0=B0,=20=D0=B0=20=D0=BE=D0=B1=D0=BB=D0=B0=D1=81?= =?utf8?q?=D1=82=D1=8C=20=D0=B2=D0=B8=D0=B4=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?utf8?q?=D0=B8=20=D0=B4=D1=80=D1=83=D0=B3=D0=B8=D1=85=20=D1=81=D1=83?= =?utf8?q?=D0=B6=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../stargazer/plugins/other/radius/radius.cpp | 55 +++++++------------ .../stargazer/plugins/other/radius/radius.h | 14 +---- 2 files changed, 21 insertions(+), 48 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 591f4b63..8c7d53d1 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -76,11 +76,6 @@ uint16_t RAD_SETTINGS::GetPort() const return port; } //----------------------------------------------------------------------------- -uint32_t RAD_SETTINGS::GetServerIP() const -{ -return serverIP; -} -//----------------------------------------------------------------------------- int RAD_SETTINGS::GetPassword(string * password) const { *password = RAD_SETTINGS::password; @@ -154,20 +149,6 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &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()) @@ -198,8 +179,13 @@ return 0; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- RADIUS::RADIUS() + : nonstop(false), + isRunning(false), + users(NULL), + stgSettings(NULL), + store(NULL), + sock(-1) { -isRunning = false; } //----------------------------------------------------------------------------- void RADIUS::SetUsers(USERS * u) @@ -270,8 +256,9 @@ if (sock < 0) return -1; } +struct sockaddr_in inAddr; 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) @@ -295,8 +282,6 @@ int RADIUS::Start() string password; radSettings.GetPassword(&password); -port = radSettings.GetPort(); -serverIP = radSettings.GetServerIP(); radSettings.GetAuthServices(&authServices); radSettings.GetAcctServices(&acctServices); @@ -380,7 +365,8 @@ while (rad->nonstop) { continue; } - if (rad->RecvData(&packet)) + struct sockaddr_in outerAddr; + if (rad->RecvData(&packet, &outerAddr)) { printfd(__FILE__, "RADIUS::Run Error on RecvData\n"); } @@ -390,7 +376,7 @@ while (rad->nonstop) { packet.packetType = RAD_REJECT_PACKET; } - rad->Send(packet); + rad->Send(packet, &outerAddr); } } @@ -399,11 +385,11 @@ rad->isRunning = false; 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]; - 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(outerAddr), &outerAddrLen); if (dataLen > 0) { Decrypt(&ctx, (char *)packet, (const char *)buf, dataLen / 8); } @@ -415,20 +401,17 @@ int RADIUS::RecvData(RAD_PACKET * packet) 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); -res = sendto(sock, buf, len, 0, (struct sockaddr *)&outerAddr, outerAddrLen); - -return 0; +return sendto(sock, buf, len, 0, reinterpret_cast(outerAddr), sizeof(struct sockaddr_in)); } //----------------------------------------------------------------------------- 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"); @@ -630,14 +613,14 @@ return 0; //----------------------------------------------------------------------------- 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) { -// Fake. May be used later +// Fake. May be use it later packet->packetType = RAD_ACCEPT_PACKET; return 0; } diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index b26a3bb3..8d37ab14 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -59,7 +59,6 @@ public: 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 * svcs) const; int GetAcctServices(list * svcs) const; @@ -72,7 +71,6 @@ private: uint16_t port; string errorStr; string password; - uint32_t serverIP; list authServices; list acctServices; }; @@ -118,8 +116,8 @@ private: 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); @@ -167,7 +165,6 @@ private: map sessions; bool nonstop; - bool isRunning; USERS * users; @@ -178,12 +175,6 @@ private: 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; RAD_PACKET packet; @@ -191,4 +182,3 @@ private: //----------------------------------------------------------------------------- #endif - -- 2.44.2