]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/radius/radius.cpp
Introduced logger for plugins.
[stg.git] / projects / stargazer / plugins / other / radius / radius.cpp
index efa995704ad0baad95a33c7f2523767730d9dc50..6fb4d2f94577cdfc8afc7b76d1314632e2664fc0 100644 (file)
@@ -121,36 +121,27 @@ return 0;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 RADIUS::RADIUS()
-    : nonstop(false),
+    : ctx(),
+      errorStr(),
+      radSettings(),
+      settings(),
+      authServices(),
+      acctServices(),
+      sessions(),
+      nonstop(false),
       isRunning(false),
       users(NULL),
       stgSettings(NULL),
       store(NULL),
-      sock(-1)
+      thread(),
+      mutex(),
+      sock(-1),
+      packet(),
+      logger(GetPluginLogger(GetStgLogger(), "radius"))
 {
 InitEncrypt(&ctx, "");
 }
 //-----------------------------------------------------------------------------
-void RADIUS::SetUsers(USERS * u)
-{
-users = u;
-}
-//-----------------------------------------------------------------------------
-void RADIUS::SetStgSettings(const SETTINGS * s)
-{
-stgSettings = s;
-}
-//-----------------------------------------------------------------------------
-void RADIUS::SetSettings(const MODULE_SETTINGS & s)
-{
-settings = s;
-}
-//-----------------------------------------------------------------------------
-void RADIUS::SetStore(STORE * s)
-{
-store = s;
-}
-//-----------------------------------------------------------------------------
 int RADIUS::ParseSettings()
 {
 int ret = radSettings.ParseSettings(settings);
@@ -159,27 +150,6 @@ if (ret)
 return ret;
 }
 //-----------------------------------------------------------------------------
-bool RADIUS::IsRunning()
-{
-return isRunning;
-}
-//-----------------------------------------------------------------------------
-const std::string RADIUS::GetVersion() const
-{
-return "RADIUS data access plugin v 0.6";
-}
-//-----------------------------------------------------------------------------
-uint16_t RADIUS::GetStartPosition() const
-{
-// Start before any authorizers!!!
-return 20;
-}
-//-----------------------------------------------------------------------------
-uint16_t RADIUS::GetStopPosition() const
-{
-return 20;
-}
-//-----------------------------------------------------------------------------
 int RADIUS::PrepareNet()
 {
 sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -267,27 +237,23 @@ if (isRunning)
     //5 seconds to thread stops itself
     for (int i = 0; i < 25 && isRunning; i++)
         {
-        usleep(200000);
-        }
-
-    //after 5 seconds waiting thread still running. now killing it
-    if (isRunning)
-        {
-        if (pthread_kill(thread, SIGINT))
-            {
-            errorStr = "Cannot kill thread.";
-            printfd(__FILE__, "Cannot kill thread\n");
-            return -1;
-            }
-        printfd(__FILE__, "RADIUS::Stop killed Run\n");
+        struct timespec ts = {0, 200000000};
+        nanosleep(&ts, NULL);
         }
     }
 
+if (isRunning)
+    return -1;
+
 return 0;
 }
 //-----------------------------------------------------------------------------
 void * RADIUS::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 RADIUS * rad = (RADIUS *)d;
 RAD_PACKET packet;
 
@@ -498,7 +464,7 @@ if (CanAcctService((char *)packet->service))
         return -1;
         }
     USER_IPS ips = ui->GetProperty().ips;
-    if (users->Authorize(ui->GetLogin(), ips[0].ip, 0xffFFffFF, this))
+    if (!users->Authorize(ui->GetLogin(), ips[0].ip, 0xffFFffFF, this))
         {
         printfd(__FILE__, "RADIUS::ProcessAcctStartPacket cannot authorize user '%s'\n", packet->login);
         packet->packetType = RAD_REJECT_PACKET;