refactor: Add Doxygen comments for MSWindowsWatchdog member functions
This commit is contained in:
parent
55b4cffd3f
commit
1bd3f5060e
1 changed files with 78 additions and 0 deletions
|
|
@ -21,6 +21,9 @@ typedef VOID(WINAPI *SendSas)(BOOL asUser);
|
||||||
class Thread;
|
class Thread;
|
||||||
class FileLogOutputter;
|
class FileLogOutputter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Monitors and controls a core process on Windows, elevating if necessary.
|
||||||
|
*/
|
||||||
class MSWindowsWatchdog
|
class MSWindowsWatchdog
|
||||||
{
|
{
|
||||||
enum class ProcessState
|
enum class ProcessState
|
||||||
|
|
@ -36,22 +39,94 @@ public:
|
||||||
explicit MSWindowsWatchdog(bool foreground);
|
explicit MSWindowsWatchdog(bool foreground);
|
||||||
~MSWindowsWatchdog() = default;
|
~MSWindowsWatchdog() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Start threads for main loop and and output loop.
|
||||||
|
*/
|
||||||
void startAsync();
|
void startAsync();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the command to run and whether to elevate the process.
|
||||||
|
*/
|
||||||
void setProcessConfig(const std::string_view &command, bool elevate);
|
void setProcessConfig(const std::string_view &command, bool elevate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stop the main loop and output loop threads.
|
||||||
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the process is running.
|
||||||
|
*/
|
||||||
bool isProcessRunning();
|
bool isProcessRunning();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the file log outputter.
|
||||||
|
*
|
||||||
|
* Outputter is not adopted by the watchdog, so the caller must manage the memory.
|
||||||
|
*
|
||||||
|
* Standard out/error from the launched core process is written to the file log outputter.
|
||||||
|
*/
|
||||||
void setFileLogOutputter(FileLogOutputter *outputter);
|
void setFileLogOutputter(FileLogOutputter *outputter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Monitor the process state and start/stop the process as necessary.
|
||||||
|
*/
|
||||||
void mainLoop(void *);
|
void mainLoop(void *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Monitor the process standard out/error and write to the file log outputter.
|
||||||
|
*/
|
||||||
void outputLoop(void *);
|
void outputLoop(void *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stops any core processes which were not started by the watchdog.
|
||||||
|
*/
|
||||||
void shutdownExistingProcesses();
|
void shutdownExistingProcesses();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Duplicates the process token for the given process.
|
||||||
|
*
|
||||||
|
* Required for starting a process in the user session; when we start an elevated process
|
||||||
|
* to ensure that it has access to secure processes, such as the login screen, we duplicate
|
||||||
|
* the token of an existing process that has the necessary access such as `winlogon.exe`.
|
||||||
|
*
|
||||||
|
* @param process The process to duplicate the token from (typically `winlogon.exe`).
|
||||||
|
*/
|
||||||
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
|
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a security token for the user session.
|
||||||
|
*
|
||||||
|
* Checks to see if logonui.exe is running or if the `elevatedToken` arg is true,
|
||||||
|
* which indicates either we're in a secure user session or we need an elevated token.
|
||||||
|
* If either case is true, it duplicates the token from `winlogon.exe`.
|
||||||
|
*/
|
||||||
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security, bool elevatedToken);
|
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security, bool elevatedToken);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Start the core process, elevating if necessary.
|
||||||
|
*/
|
||||||
void startProcess();
|
void startProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Controls whether the process should restart immediately or delay start.
|
||||||
|
*/
|
||||||
void handleStartError(const std::string_view &message = "");
|
void handleStartError(const std::string_view &message = "");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Init the output read pipe for standard out/error.
|
||||||
|
*/
|
||||||
void initOutputReadPipe();
|
void initOutputReadPipe();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Init the SendSAS function, used for Ctrl+Alt+Del emulation.
|
||||||
|
*/
|
||||||
void initSasFunc();
|
void initSasFunc();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send a SAS (Secure Attention Sequence) for Ctrl+Alt+Del emulation.
|
||||||
|
*/
|
||||||
void sendSas() const;
|
void sendSas() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,6 +139,9 @@ private:
|
||||||
*/
|
*/
|
||||||
std::string runActiveDesktopUtility();
|
std::string runActiveDesktopUtility();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert the process state enum to a string (useful for logging).
|
||||||
|
*/
|
||||||
static std::string processStateToString(ProcessState state);
|
static std::string processStateToString(ProcessState state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue