Merge tcpsvcs changes from audited repositry

Revision: 73
Author: gedmurphy
Date: 17:36:44, 03 February 2006
Message:
fixed security issues - fixes bug 1307
fixed unicode over network issues
----
Modified : /trunk/reactos/base/services/tcpsvcs/chargen.c
Modified : /trunk/reactos/base/services/tcpsvcs/daytime.c
Modified : /trunk/reactos/base/services/tcpsvcs/discard.c
Modified : /trunk/reactos/base/services/tcpsvcs/echo.c
Modified : /trunk/reactos/base/services/tcpsvcs/qotd.c
Modified : /trunk/reactos/base/services/tcpsvcs/skelserver.c
Modified : /trunk/reactos/base/services/tcpsvcs/tcpsvcs.c
Modified : /trunk/reactos/base/services/tcpsvcs/tcpsvcs.h



svn path=/trunk/; revision=21163
This commit is contained in:
Ged Murphy 2006-02-19 16:33:14 +00:00
parent fb1a32ea73
commit db000e5299
9 changed files with 87 additions and 127 deletions

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/chargen.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/chargen.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -35,7 +30,7 @@ DWORD WINAPI ChargenHandler(VOID* Sock_)
LogEvent(_T("Chargen: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
LogEvent(_T("Chargen: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
@ -78,8 +73,8 @@ BOOL GenerateChars(SOCKET Sock)
charIndex++;
}
Line[LINESIZ - 2] = L'\r';
Line[LINESIZ - 1] = L'\n';
Line[LINESIZ - 2] = '\r';
Line[LINESIZ - 1] = '\n';
if (! SendLine(Sock, Line))
break;
@ -87,14 +82,14 @@ BOOL GenerateChars(SOCKET Sock)
/* increment loop index to start printing from next char in ring */
loopIndex++;
}
if (bShutDown)
return FALSE;
else
return TRUE;
}
BOOL SendLine(SOCKET Sock, TCHAR* Line)
BOOL SendLine(SOCKET Sock, char* Line)
{
INT RetVal;
INT SentBytes;

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/daytime.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/daytime.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -18,14 +13,14 @@ DWORD WINAPI DaytimeHandler(VOID* Sock_)
{
struct tm *newtime;
time_t aclock;
TCHAR *pszTime;
CHAR *pszTime;
DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
time(&aclock);
newtime = localtime(&aclock);
pszTime = _tasctime(newtime);
pszTime = asctime(newtime);
SendTime(Sock, pszTime);
LogEvent(_T("DayTime: Shutting connection down...\n"), 0, FALSE);
@ -36,17 +31,17 @@ DWORD WINAPI DaytimeHandler(VOID* Sock_)
LogEvent(_T("DayTime: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
LogEvent(_T("DayTime: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
BOOL SendTime(SOCKET Sock, TCHAR *time)
BOOL SendTime(SOCKET Sock, CHAR *time)
{
INT StringSize = (INT)_tcsclen(time);
INT RetVal = send(Sock, time, sizeof(TCHAR) * StringSize, 0);
INT StringSize = (INT)strlen(time);
INT RetVal = send(Sock, time, sizeof(CHAR) * StringSize, 0);
if (RetVal == SOCKET_ERROR)
return FALSE;

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/discard.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/discard.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -35,7 +30,7 @@ DWORD WINAPI DiscardHandler(VOID* Sock_)
LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
@ -44,7 +39,7 @@ DWORD WINAPI DiscardHandler(VOID* Sock_)
BOOL RecieveIncomingPackets(SOCKET Sock)
{
TCHAR ReadBuffer[BUF];
char ReadBuffer[BUF];
TCHAR buf[256];
INT ReadBytes;
@ -58,7 +53,7 @@ BOOL RecieveIncomingPackets(SOCKET Sock)
}
else if (ReadBytes == SOCKET_ERROR)
{
_stprintf(buf, ("Socket Error: %d\n"), WSAGetLastError());
_stprintf(buf, _T("Socket Error: %d\n"), WSAGetLastError());
LogEvent(buf, 0, TRUE);
return FALSE;
}

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/echo.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/echo.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -27,7 +22,7 @@ DWORD WINAPI EchoHandler(VOID* Sock_)
}
LogEvent(_T("Echo: Shutting connection down...\n"), 0, FALSE);
if (ShutdownConnection(Sock, TRUE))
LogEvent(_T("Echo: Connection is down\n"), 0, FALSE);
else
@ -35,7 +30,7 @@ DWORD WINAPI EchoHandler(VOID* Sock_)
LogEvent(_T("Echo: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
LogEvent(_T("Echo: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
@ -44,7 +39,7 @@ DWORD WINAPI EchoHandler(VOID* Sock_)
BOOL EchoIncomingPackets(SOCKET Sock)
{
TCHAR ReadBuffer[BUF];
char ReadBuffer[BUF];
TCHAR buf[256]; // temp for holding LogEvent text
INT Temp;
INT ReadBytes;

View file

@ -1,29 +1,24 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/qotd.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/qotd.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "tcpsvcs.h"
#define QBUFSIZ 160
#define QBUFSIZ 60
LPCTSTR FilePath = _T("\\drivers\\etc\\quotes");
LPCTSTR FilePath = _T("\\drivers\\etc\\quotes"); /* 19 chars */
DWORD WINAPI QotdHandler(VOID* Sock_)
{
FILE *fp;
SOCKET Sock;
TCHAR Sys[MAX_PATH];
TCHAR Quote[60][BUFSIZ]; // need to set this dynamically
TCHAR Sys[MAX_PATH + 20];
char Quote[QBUFSIZ][BUFSIZ]; // need to set this dynamically
INT QuoteToPrint;
INT NumQuotes;
@ -34,15 +29,15 @@ DWORD WINAPI QotdHandler(VOID* Sock_)
LogEvent(_T("QOTD: Getting system path failed.\n"), 0, TRUE);
ExitThread(1);
}
_tcscat(Sys, FilePath);
_tcsncat(Sys, FilePath, _tcslen(FilePath));
LogEvent(_T("QOTD: Opening quotes file\n"), 0, FALSE);
if ((fp = _tfopen(Sys, "r")) == NULL)
if ((fp = _tfopen(Sys, _T("r"))) == NULL)
{
TCHAR buf[256];
TCHAR buf[320];
_stprintf(buf, _T("QOTD: Error opening quote file : %s\n"), Sys);
_sntprintf(buf, 320, _T("QOTD: Error opening quote file : %s\n"), Sys);
LogEvent(buf, 0, TRUE);
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(1);
@ -50,7 +45,8 @@ DWORD WINAPI QotdHandler(VOID* Sock_)
/* read all quotes in the file into an array */
NumQuotes = 0;
while (_fgetts(Quote[NumQuotes], QBUFSIZ, fp) != NULL)
while ((fgets(Quote[NumQuotes], QBUFSIZ, fp) != NULL) &&
(NumQuotes != QBUFSIZ))
NumQuotes++;
LogEvent(_T("QOTD: Closing quotes file\n"), 0, FALSE);
@ -73,21 +69,20 @@ DWORD WINAPI QotdHandler(VOID* Sock_)
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(1);
}
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(0);
//return Retval;
}
BOOL SendQuote(SOCKET Sock, TCHAR* Quote)
BOOL SendQuote(SOCKET Sock, char* Quote)
{
INT StringSize;
INT RetVal;
StringSize = (INT)_tcsclen(Quote);
RetVal = send(Sock, Quote, sizeof(TCHAR) * StringSize, 0);
StringSize = (INT)strlen(Quote);
RetVal = send(Sock, Quote, sizeof(char) * StringSize, 0);
if (RetVal == SOCKET_ERROR)
return FALSE;

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/skelserver.c
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/skelserver.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -29,7 +24,7 @@ DWORD WINAPI StartServer(LPVOID lpParam)
ListeningSocket = SetUpListener(htons(pServices->Port));
if (ListeningSocket == INVALID_SOCKET)
{
LogEvent("Socket error when setting up listener\n", 0, TRUE);
LogEvent(_T("Socket error when setting up listener\n"), 0, TRUE);
return 3;
}
@ -136,7 +131,7 @@ VOID AcceptConnections(SOCKET ListeningSocket,
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
else

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/tcpsvcs.c
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/tcpsvcs.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
/*
@ -36,7 +31,7 @@ FILE *hLogFile;
BOOL bShutDown = FALSE;
BOOL bPause = FALSE;
LPCTSTR LogFileName = "\\tcpsvcs_log.log";
LPCTSTR LogFileName = _T("\\tcpsvcs_log.log");
LPTSTR ServiceName = _T("Simp Tcp");
//LPTSTR DisplayName = _T("Simple TCP/IP Services");
@ -74,19 +69,19 @@ main(void)
VOID WINAPI
ServiceMain(DWORD argc, LPTSTR argv[])
{
TCHAR LogFilePath[MAX_PATH];
TCHAR LogFilePath[MAX_PATH + 17];
if(! GetSystemDirectory(LogFilePath, MAX_PATH))
return;
_tcscat(LogFilePath, LogFileName);
_tcsncat(LogFilePath, LogFileName, 17);
hLogFile = fopen(LogFilePath, _T("a+"));
hLogFile = _tfopen(LogFilePath, _T("a+"));
if (hLogFile == NULL)
{
TCHAR buf[50];
TCHAR buf[300];
_stprintf(buf, _T("Could not open log file: %s\n"), LogFilePath);
_sntprintf(buf, 300, _T("Could not open log file: %s\n"), LogFilePath);
MessageBox(NULL, buf, NULL, MB_OK);
return;
}
@ -125,7 +120,7 @@ ServiceMain(DWORD argc, LPTSTR argv[])
UpdateStatus (SERVICE_STOPPED, 0);
LogEvent(_T("Service status set to SERVICE_STOPPED\n"), 0, FALSE);
LogEvent(_T("Leaving ServiceMain\n"), 0, FALSE);
fclose(hLogFile);
return;
@ -237,10 +232,10 @@ CreateServers()
{
CloseHandle(hThread[i]);
}
LogEvent(_T("Detaching Winsock2...\n"), 0, FALSE);
WSACleanup();
return 0;
}
@ -252,7 +247,7 @@ LogEvent (LPCTSTR UserMessage, INT ExitCode, BOOL PrintErrorMsg)
{
DWORD eMsgLen, ErrNum = GetLastError ();
LPTSTR lpvSysMsg;
TCHAR MessageBuffer[512];
TCHAR MessageBuffer[1024];
@ -263,16 +258,16 @@ LogEvent (LPCTSTR UserMessage, INT ExitCode, BOOL PrintErrorMsg)
ErrNum, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpvSysMsg, 0, NULL);
_stprintf(MessageBuffer, _T("%s %s ErrNum = %lu. ExitCode = %d."),
_sntprintf(MessageBuffer, 1024, _T("%s %s ErrNum = %lu. ExitCode = %d."),
UserMessage, lpvSysMsg, ErrNum, ExitCode);
HeapFree(GetProcessHeap (), 0, lpvSysMsg);
}
else
{
_stprintf(MessageBuffer, _T("%s"), UserMessage);
_sntprintf(MessageBuffer, 1024, _T("%s"), UserMessage);
}
fputs (MessageBuffer, hLogFile);
_fputts(MessageBuffer, hLogFile);
if (ExitCode != 0)
ExitProcess(ExitCode);

View file

@ -1,14 +1,9 @@
/*
* ReactOS Services
* Copyright (C) 2005 ReactOS Team
*
* LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
* FILE: apps/utils/net/tcpsvcs/tcpsvcs.h
* LICENSE: GPL - See COPYING in the top level directory
* FILE: /base/services/tcpsvcs/tcpsvcs.h
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
* REVISIONS:
* GM 04/10/05 Created
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -17,9 +12,6 @@
#include <tchar.h>
#include <time.h>
#define UNICODE
#define _UNICODE
/* default port numbers */
#define ECHO_PORT 7
#define DISCARD_PORT 9
@ -68,11 +60,11 @@ BOOL ShutdownConnection(SOCKET Sock, BOOL bRec);
/* chargen functions */
DWORD WINAPI ChargenHandler(VOID* Sock_);
BOOL GenerateChars(SOCKET Sock);
BOOL SendLine(SOCKET Sock, TCHAR* Line);
BOOL SendLine(SOCKET Sock, char* Line);
/* daytime functions */
DWORD WINAPI DaytimeHandler(VOID* Sock_);
BOOL SendTime(SOCKET Sock, TCHAR *time);
BOOL SendTime(SOCKET Sock, char *time);
/* echo functions */
DWORD WINAPI EchoHandler(VOID* Sock_);
@ -84,4 +76,4 @@ BOOL RecieveIncomingPackets(SOCKET Sock);
/* qotd functions */
DWORD WINAPI QotdHandler(VOID* Sock_);
BOOL SendQuote(SOCKET Sock, TCHAR* Quote);
BOOL SendQuote(SOCKET Sock, char* Quote);

View file

@ -1,4 +1,6 @@
<module name="tcpsvcs" type="win32cui" installbase="system32" installname="tcpsvcs.exe">
<?xml version="1.0"?>
<rbuild xmlns:xi="http://www.w3.org/2001/XInclude">
<module name="tcpsvcs" type="win32cui" installbase="system32" installname="tcpsvcs.exe">
<include base="arp">.</include>
<define name="__USE_W32API" />
<library>kernel32</library>
@ -14,4 +16,5 @@
<file>chargen.c</file>
<file>tcpsvcs.rc</file>
<pch>tcpsvcs.h</pch>
</module>
</module>
</rbuild>