|
|
@ -26,6 +26,11 @@
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
@ -98,7 +103,7 @@ void CYSFReflector::run()
|
|
|
|
pid_t pid = ::fork();
|
|
|
|
pid_t pid = ::fork();
|
|
|
|
if (pid == -1) {
|
|
|
|
if (pid == -1) {
|
|
|
|
::LogWarning("Couldn't fork() , exiting");
|
|
|
|
::LogWarning("Couldn't fork() , exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pid != 0)
|
|
|
|
else if (pid != 0)
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
@ -106,13 +111,13 @@ void CYSFReflector::run()
|
|
|
|
// Create new session and process group
|
|
|
|
// Create new session and process group
|
|
|
|
if (::setsid() == -1) {
|
|
|
|
if (::setsid() == -1) {
|
|
|
|
::LogWarning("Couldn't setsid(), exiting");
|
|
|
|
::LogWarning("Couldn't setsid(), exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the working directory to the root directory
|
|
|
|
// Set the working directory to the root directory
|
|
|
|
if (::chdir("/") == -1) {
|
|
|
|
if (::chdir("/") == -1) {
|
|
|
|
::LogWarning("Couldn't cd /, exiting");
|
|
|
|
::LogWarning("Couldn't cd /, exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::close(STDIN_FILENO);
|
|
|
|
::close(STDIN_FILENO);
|
|
|
@ -124,7 +129,7 @@ void CYSFReflector::run()
|
|
|
|
struct passwd* user = ::getpwnam("mmdvm");
|
|
|
|
struct passwd* user = ::getpwnam("mmdvm");
|
|
|
|
if (user == NULL) {
|
|
|
|
if (user == NULL) {
|
|
|
|
::LogError("Could not get the mmdvm user, exiting");
|
|
|
|
::LogError("Could not get the mmdvm user, exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uid_t mmdvm_uid = user->pw_uid;
|
|
|
|
uid_t mmdvm_uid = user->pw_uid;
|
|
|
@ -133,18 +138,18 @@ void CYSFReflector::run()
|
|
|
|
//Set user and group ID's to mmdvm:mmdvm
|
|
|
|
//Set user and group ID's to mmdvm:mmdvm
|
|
|
|
if (setgid(mmdvm_gid) != 0) {
|
|
|
|
if (setgid(mmdvm_gid) != 0) {
|
|
|
|
::LogWarning("Could not set mmdvm GID, exiting");
|
|
|
|
::LogWarning("Could not set mmdvm GID, exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (setuid(mmdvm_uid) != 0) {
|
|
|
|
if (setuid(mmdvm_uid) != 0) {
|
|
|
|
::LogWarning("Could not set mmdvm UID, exiting");
|
|
|
|
::LogWarning("Could not set mmdvm UID, exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Double check it worked (AKA Paranoia)
|
|
|
|
//Double check it worked (AKA Paranoia)
|
|
|
|
if (setuid(0) != -1) {
|
|
|
|
if (setuid(0) != -1) {
|
|
|
|
::LogWarning("It's possible to regain root - something is wrong!, exiting");
|
|
|
|
::LogWarning("It's possible to regain root - something is wrong!, exiting");
|
|
|
|
return -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|