#include <stdlib.h>
#include <crtdbg.h>
#endif
+
+ #include <pwd.h> // setuid
+ #include <grp.h> // setgid
#endif
#include <fstream>
#include "caller.h"
#include "testsuite.h"
-using irc::sockets::insp_ntoa;
-using irc::sockets::insp_inaddr;
-using irc::sockets::insp_sockaddr;
-
InspIRCd* SI = NULL;
int* mysig = NULL;
ThreadEngineFactory* tef = new ThreadEngineFactory();
this->Threads = tef->Create(this);
delete tef;
+ this->Mutexes = new MutexFactory(this);
/* Default implementation does nothing */
this->PI = new ProtocolInterface(this);
/* During startup we don't actually initialize this
* in the thread engine.
*/
- this->ConfigThread = new ConfigReaderThread(this, true, NULL);
+ this->ConfigThread = new ConfigReaderThread(this, true, "");
ConfigThread->Run();
delete ConfigThread;
this->ConfigThread = NULL;
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->SetGroup))
+ {
+ int ret;
+
+ // setgroups
+ ret = setgroups(0, NULL);
+
+ if (ret == -1)
+ {
+ this->Logs->Log("SETGROUPS", DEFAULT, "setgroups() failed (wtf?): %s", strerror(errno));
+ this->QuickExit(0);
+ }
+
+ // 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);
+ }
+
+ ret = setgid(g->gr_gid);
+
+ if (ret == -1)
+ {
+ this->Logs->Log("SETGUID", DEFAULT, "setgid() failed (bad user?): %s", strerror(errno));
+ this->QuickExit(0);
+ }
+ }
+
+ 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);
+ }
+ }
+#endif
+
this->WritePID(Config->PID);
}
this->Res->Rehash();
this->ResetMaxBans();
InitializeDisabledCommands(Config->DisabledCommands, this);
- FOREACH_MOD_I(this, I_OnRehash, OnRehash(Config->RehashUser, Config->RehashParameter));
+ User* user = !Config->RehashUserUID.empty() ? FindNick(Config->RehashUserUID) : NULL;
+ FOREACH_MOD_I(this, I_OnRehash, OnRehash(user, Config->RehashParameter));
this->BuildISupport();
}