X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspircd.cpp;h=9a64331b5f1faeabe84d3a3540f96e15db0edccf;hb=f7730d08b695019c84a0b5961d8fb6bdb67365b9;hp=6ecf688e866149a2bd5256cd603394522f18d333;hpb=76e9dc04d73d94e178224bcda021edae2f7bed9b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6ecf688e8..9a64331b5 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -35,6 +35,9 @@ #include #include #endif + + #include // setuid + #include // setgid #endif #include @@ -622,7 +625,7 @@ InspIRCd::InspIRCd(int argc, char** argv) /* 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; @@ -726,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); } @@ -774,7 +825,8 @@ int InspIRCd::Run() 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(); }