]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/radius/radius.cpp
Додано пропущені заголовочні файли
[stg.git] / projects / stargazer / plugins / other / radius / radius.cpp
index 8c7d53d1116aad3f0b015a25b7c1581f8b3bbea6..9c5ab1db128c9b28dc36d4c0d9c82ee4fec77774 100644 (file)
  *
  */
 
+#include <csignal>
+#include <cerrno>
 #include <algorithm>
-#include <signal.h>
 
 #include "radius.h"
 #include "common.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);
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -71,35 +76,6 @@ return radc.GetPlugin();
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-uint16_t RAD_SETTINGS::GetPort() const
-{
-return port;
-}
-//-----------------------------------------------------------------------------
-int RAD_SETTINGS::GetPassword(string * password) const
-{
-*password = RAD_SETTINGS::password;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int RAD_SETTINGS::GetAuthServices(list<string> * svcs) const
-{
-*svcs = authServices;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int RAD_SETTINGS::GetAcctServices(list<string> * 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))
@@ -186,6 +162,7 @@ RADIUS::RADIUS()
       store(NULL),
       sock(-1)
 {
+InitEncrypt(&ctx, "");
 }
 //-----------------------------------------------------------------------------
 void RADIUS::SetUsers(USERS * u)
@@ -237,14 +214,6 @@ uint16_t RADIUS::GetStopPosition() const
 return 20;
 }
 //-----------------------------------------------------------------------------
-void RADIUS::SetUserNotifier(user_iter)
-{
-}
-//-----------------------------------------------------------------------------
-void RADIUS::UnSetUserNotifier(user_iter)
-{
-}
-//-----------------------------------------------------------------------------
 int RADIUS::PrepareNet()
 {
 sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -279,11 +248,10 @@ return 0;
 //-----------------------------------------------------------------------------
 int RADIUS::Start()
 {
-string password;
+string password(radSettings.GetPassword());
 
-radSettings.GetPassword(&password);
-radSettings.GetAuthServices(&authServices);
-radSettings.GetAcctServices(&acctServices);
+authServices = radSettings.GetAuthServices();
+acctServices = radSettings.GetAcctServices();
 
 InitEncrypt(&ctx, password);
 
@@ -625,34 +593,6 @@ packet->packetType = RAD_ACCEPT_PACKET;
 return 0;
 }
 //-----------------------------------------------------------------------------
-void RADIUS::InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
-{
-unsigned char keyL[RAD_PASSWORD_LEN];  // Пароль для шифровки
-memset(keyL, 0, RAD_PASSWORD_LEN);
-strncpy((char *)keyL, password.c_str(), RAD_PASSWORD_LEN);
-Blowfish_Init(ctx, keyL, RAD_PASSWORD_LEN);
-}
-//-----------------------------------------------------------------------------
-void RADIUS::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int 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));
-}
-//-----------------------------------------------------------------------------
-void RADIUS::Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int 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));
-}
-//-----------------------------------------------------------------------------
 void RADIUS::PrintServices(const list<string> & svcs)
 {
     for_each(svcs.begin(), svcs.end(), Printer());
@@ -709,3 +649,34 @@ if (res == 0) // Timeout
 
 return true;
 }
+//-----------------------------------------------------------------------------
+inline
+void InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
+{
+unsigned char keyL[RAD_PASSWORD_LEN];  // Пароль для шифровки
+memset(keyL, 0, RAD_PASSWORD_LEN);
+strncpy((char *)keyL, password.c_str(), RAD_PASSWORD_LEN);
+Blowfish_Init(ctx, keyL, RAD_PASSWORD_LEN);
+}
+//-----------------------------------------------------------------------------
+inline
+void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int 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));
+}
+//-----------------------------------------------------------------------------
+inline
+void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int 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));
+}