]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - win/inspircd_win32wrapper.cpp
Remove incorrect access checks from m_ojoin
[user/henk/code/inspircd.git] / win / inspircd_win32wrapper.cpp
index 223fb648ebba170bf7c91a2891c7d32f15ed095e..d82c90a61be9d6a99f380e507d01e03e25afdc99 100644 (file)
@@ -354,7 +354,7 @@ bool GetInterface(HKEY regkey, const char *key, char* &output)
 
 std::string FindNameServerWin()
 {
-       std::string returnval = "127.0.0.1";
+       std::string returnval;
        HKEY top, key;
        char* dns = NULL;
 
@@ -415,7 +415,7 @@ void ClearConsole()
  */
 void ChangeWindowsSpecificPointers()
 {
-       Instance->Logs->Log("win32",DEBUG,"Changing to windows specific pointer and functor set");
+       ServerInstance->Logs->Log("win32",DEBUG,"Changing to windows specific pointer and functor set");
 }
 
 DWORD WindowsForkStart()
@@ -504,50 +504,59 @@ void WindowsForkKillOwner()
         if(!hProcess || !owner_processid)
         {
                 printf("Could not open process id %u: %s.\n", owner_processid, dlerror());
-                Instance->Exit(14);
+                ServerInstance->Exit(14);
         }
 
         // die die die
         if(!TerminateProcess(hProcess, 0))
         {
                 printf("Could not TerminateProcess(): %s\n", dlerror());
-                Instance->Exit(14);
+                ServerInstance->Exit(14);
         }
 
         CloseHandle(hProcess);
 }
 
-bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+void FindDNS(std::string& server)
 {
-       if (!*(data.GetString()))
+       if (!server.empty())
+               return;
+
+       ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in the registry...");
+       std::string nameserver = FindNameServerWin();
+
+       /* If empty use default to 127.0.0.1 */
+       if (nameserver.empty())
        {
-               std::string nameserver;
-               conf->GetInstance()->Logs->Log("win32",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in the registry...");
-               nameserver = FindNameServerWin();
-               /* Windows stacks multiple nameservers in one registry key, seperated by commas.
-                * Spotted by Cataclysm.
-                */
-               if (nameserver.find(',') != std::string::npos)
-                       nameserver = nameserver.substr(0, nameserver.find(','));
-               /* Just to be FUCKING AKWARD, windows fister... err i mean vista...
-                * seperates the nameservers with spaces instead.
-                */
-               if (nameserver.find(' ') != std::string::npos)
-                       nameserver = nameserver.substr(0, nameserver.find(' '));
-               data.Set(nameserver.c_str());
-               conf->GetInstance()->Logs->Log("win32",DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
+               ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found in registry! Defaulting to nameserver '127.0.0.1'!");
+               server = "127.0.0.1";
+               return;
        }
-       return true;
+
+       /* Windows stacks multiple nameservers in one registry key, seperated by commas.
+        * Spotted by Cataclysm.
+        */
+       if (nameserver.find(',') != std::string::npos)
+               nameserver = nameserver.substr(0, nameserver.find(','));
+
+       /* Just to be FUCKING AKWARD, windows fister... err i mean vista...
+        * seperates the nameservers with spaces instead.
+        */
+       if (nameserver.find(' ') != std::string::npos)
+               nameserver = nameserver.substr(0, nameserver.find(' '));
+
+       server = nameserver;
+       ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
 }
 
-int gettimeofday(struct timeval * tv, void * tz)
+int clock_gettime(int clock, struct timespec * tv)
 {
        if(tv == NULL)
                return -1;
 
        DWORD mstime = timeGetTime();
        tv->tv_sec   = time(NULL);
-       tv->tv_usec  = (mstime - (tv->tv_sec * 1000)) * 1000;
+       tv->tv_usec  = (mstime - (tv->tv_sec * 1000)) * 1000000;
        return 0;       
 }
 
@@ -643,6 +652,7 @@ int getcpu()
                while (pEnumerator)
                {
                        VARIANT vtProp;
+                       VariantInit(&vtProp);
                        /* Next item */
                        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
 
@@ -655,9 +665,10 @@ int getcpu()
                        if (!FAILED(hr))
                        {
                                /* Matches our process ID? */
-                               if (vtProp.uintVal == GetCurrentProcessId())
-                               {
-                                       VariantClear(&vtProp);
+                               UINT pid = vtProp.uintVal;
+                               VariantClear(&vtProp);
+                               if (pid == GetCurrentProcessId())
+                               {                                       
                                        /* Get CPU percentage for this process */
                                        hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0);
                                        if (!FAILED(hr))
@@ -665,18 +676,19 @@ int getcpu()
                                                /* Deal with wide string ickyness. Who in their right
                                                 * mind puts a number in a bstrVal wide string item?!
                                                 */
-                                               VariantClear(&vtProp);
                                                cpu = 0;
                                                std::wstringstream out(vtProp.bstrVal);
                                                out >> cpu;
-                                               break;
+                                               VariantClear(&vtProp);
                                        }
+                                       pclsObj->Release();
+                                       break;
                                }
+                               pclsObj->Release();
                        }
                }
 
                pEnumerator->Release();
-               pclsObj->Release();
        }
 
        SysFreeString(Language);