X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=rosapps%2Fapplications%2Fsysutils%2Ftelnetd%2Ftelnetd.c;h=882e272aadec0feca9a8317c7e3ca5f1d579d009;hp=d8d0e985c8adc5d5aee23ebea89243d373139f3a;hb=748579a668de5df68c8839a84e9700ae9fd1fcc8;hpb=070cba2db8b19638bed1956a5104067b2c0a16c9 diff --git a/rosapps/applications/sysutils/telnetd/telnetd.c b/rosapps/applications/sysutils/telnetd/telnetd.c index d8d0e985c8a..882e272aade 100644 --- a/rosapps/applications/sysutils/telnetd/telnetd.c +++ b/rosapps/applications/sysutils/telnetd/telnetd.c @@ -17,19 +17,14 @@ * - Unify Debugging output and return StatusCodes */ -#include -#include - #include "telnetd.h" #define telnetd_printf printf - #if 0 -extern void syslog (int priority, const char *fmt, ...); - -int telnetd_printf(const char *format, ...) +static inline int telnetd_printf(const char *format, ...); { - syslog (6, format); + printf(format,...); + syslog (6, format); } #endif @@ -37,7 +32,6 @@ int telnetd_printf(const char *format, ...) static BOOLEAN bShutdown = 0; static BOOLEAN bSocketInterfaceInitialised = 0; - static int sock; /* In the future, some options might be passed here to handle @@ -50,6 +44,9 @@ static int sock; */ int main(int argc, char **argv) { + printf("Attempting to start Simple TelnetD\n"); + +// DetectPlatform(); SetConsoleCtrlHandler(Cleanup, 1); if (!StartSocketInterface()) @@ -143,7 +140,6 @@ static void UserLogin(int client_socket) if (client == NULL) ErrorExit("failed to allocate memory for client"); - client->socket = client_socket; CreateThread(NULL, 0, UserLoginThread, client, 0, &threadID); } @@ -574,35 +570,52 @@ static DWORD WINAPI ReadFromPipeThread(LPVOID data) /* TerminateShell */ static void TerminateShell(client_t *client) { - DWORD exitCode; - DWORD dwWritten; - char stop[] = "\003\r\nexit\r\n"; /* Ctrl-C + exit */ + DWORD exitCode; + DWORD dwWritten; + char stop[] = "\003\r\nexit\r\n"; /* Ctrl-C + exit */ - GetExitCodeProcess(client->hProcess, &exitCode); - if (exitCode == STILL_ACTIVE) { - telnetd_printf("user shell still active, send Ctrl-Break to group-id %lu\n", client->dwProcessId ); + GetExitCodeProcess(client->hProcess, &exitCode); - if (!GenerateConsoleCtrlEvent( CTRL_BREAK_EVENT, client->dwProcessId )) - telnetd_printf("Failed to send Ctrl_break\n"); + if (exitCode == STILL_ACTIVE) + { + HANDLE hEvent = NULL; + DWORD dwWaitResult; - Sleep(500); + telnetd_printf("user shell still active, send Ctrl-Break to group-id %lu\n", client->dwProcessId ); - if (!GenerateConsoleCtrlEvent( CTRL_C_EVENT, client->dwProcessId )) - telnetd_printf("Failed to send Ctrl_C\n"); + hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - Sleep(500); + if (hEvent == NULL) + printf("CreateEvent error\n"); - if (!WriteFile(client->hChildStdinWr, stop, sizeof(stop), &dwWritten, NULL)) - telnetd_printf("Error writing to pipe\n"); + if (!GenerateConsoleCtrlEvent( CTRL_BREAK_EVENT, client->dwProcessId )) + telnetd_printf("Failed to send Ctrl_break\n"); - Sleep(500); + if (!GenerateConsoleCtrlEvent( CTRL_C_EVENT, client->dwProcessId )) + telnetd_printf("Failed to send Ctrl_C\n"); - GetExitCodeProcess(client->hProcess, &exitCode); - if (exitCode == STILL_ACTIVE) { - telnetd_printf("user shell still active, attempt to terminate it now...\n"); - TerminateProcess(client->hProcess, 0); + if (!WriteFile(client->hChildStdinWr, stop, sizeof(stop), &dwWritten, NULL)) + telnetd_printf("Error writing to pipe\n"); + + /* wait for our handler to be called */ + dwWaitResult=WaitForSingleObject(hEvent, 500); + + if (WAIT_FAILED==dwWaitResult) + telnetd_printf("WaitForSingleObject failed\n"); + + GetExitCodeProcess(client->hProcess, &exitCode); + if (exitCode == STILL_ACTIVE) + { + telnetd_printf("user shell still active, attempt to terminate it now...\n"); + + if (hEvent != NULL) + { + if (!CloseHandle(hEvent)) + telnetd_printf("CloseHandle"); + } + TerminateProcess(client->hProcess, 0); + } } - } } /* ErrorExit */