]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Remove an extremely noisy piece of debug on startup/rehash - this code works fine...
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 3a2392ee67f7b9a0051adb50fef6acdb33ff1a00..9a64331b5f1faeabe84d3a3540f96e15db0edccf 100644 (file)
@@ -35,6 +35,9 @@
        #include <stdlib.h>
        #include <crtdbg.h>
        #endif
+
+       #include <pwd.h> // setuid
+       #include <grp.h> // setgid
 #endif
 
 #include <fstream>
@@ -656,8 +659,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
        /* set up fake client again this time with the correct uid */
        this->FakeClient = new User(this, "#INVALID");
        this->FakeClient->SetFd(FD_MAGIC_NUMBER);
-       this->FakeClient->HasPrivPermission("users/override/topic");
-       exit(0);
 
        // Get XLine to do it's thing.
        this->XLines->CheckELines();
@@ -728,6 +729,54 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
 
+#ifndef WIN32
+       if (*(this->Config->SetUser))
+       {
+               // setuid
+               struct passwd *u;
+
+               errno = 0;
+               u = getpwnam(this->Config->SetUser);
+
+               if (!u)
+               {
+                       this->Logs->Log("SETGUID", DEFAULT, "getpwnam() failed (bad user?): %s", strerror(errno));
+                       this->QuickExit(0);
+               }
+
+               int ret = setuid(u->pw_uid);
+
+               if (ret == -1)
+               {
+                       this->Logs->Log("SETGUID", DEFAULT, "setuid() failed (bad user?): %s", strerror(errno));
+                       this->QuickExit(0);
+               }
+       }
+
+       if (*(this->Config->SetGroup))
+       {
+               // setgid
+               struct group *g;
+
+               errno = 0;
+               g = getgrnam(this->Config->SetGroup);
+
+               if (!g)
+               {
+                       this->Logs->Log("SETGUID", DEFAULT, "getgrnam() failed (bad user?): %s", strerror(errno));
+                       this->QuickExit(0);
+               }
+
+               int ret = setgid(g->gr_gid);
+
+               if (ret == -1)
+               {
+                       this->Logs->Log("SETGUID", DEFAULT, "setgid() failed (bad user?): %s", strerror(errno));
+                       this->QuickExit(0);
+               }
+       }
+#endif
+
        this->WritePID(Config->PID);
 }