X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..8d18bde0f40cac840d25b98e48b1a8dfcc2157ff:/projects/stargazer/plugins/other/radius/radius.cpp?ds=inline diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 591f4b63..4dd18c46 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -26,8 +26,8 @@ * */ +#include #include -#include #include "radius.h" #include "common.h" @@ -71,40 +71,6 @@ return radc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -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; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::GetAuthServices(list * svcs) const -{ -*svcs = authServices; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::GetAcctServices(list * svcs) const -{ -*svcs = acctServices; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::ParseIP(const string & str, uint32_t * IP) -{ -*IP = inet_addr(str.c_str()); -return *IP == INADDR_NONE ? -1 : 0; -} -//----------------------------------------------------------------------------- int RAD_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val) { if (str2x(str.c_str(), *val)) @@ -154,20 +120,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 +150,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 +227,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) @@ -292,13 +250,10 @@ return 0; //----------------------------------------------------------------------------- int RADIUS::Start() { -string password; +string password(radSettings.GetPassword()); -radSettings.GetPassword(&password); -port = radSettings.GetPort(); -serverIP = radSettings.GetServerIP(); -radSettings.GetAuthServices(&authServices); -radSettings.GetAcctServices(&acctServices); +authServices = radSettings.GetAuthServices(); +acctServices = radSettings.GetAcctServices(); InitEncrypt(&ctx, password); @@ -380,7 +335,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 +346,7 @@ while (rad->nonstop) { packet.packetType = RAD_REJECT_PACKET; } - rad->Send(packet); + rad->Send(packet, &outerAddr); } } @@ -399,11 +355,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 +371,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 +583,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; }