[Haiku-commits] r31240 - in haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows: . VS2008

modeenf at mail.berlios.de modeenf at mail.berlios.de
Thu Jun 25 21:56:23 CEST 2009


Author: modeenf
Date: 2009-06-25 21:56:19 +0200 (Thu, 25 Jun 2009)
New Revision: 31240
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31240&view=rev

Added:
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.sln
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.vcproj
Modified:
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/BeServed.cpp
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/NTServApp.aps
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/authentication.cpp
   haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/readerWriter.cpp
Log:
Ticket #2547 can now be closed. this makes all the Windows parts of BeServed build in VS2008.
As Olivier Coursi?\195?\168re wrote in the ticket/Patch he did.
To install
copy the control panel application in the c:\windows\system32 directory 
run "BeServerd.exe -install" from the command line to install BeServed as a Windows service.

Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/BeServed.cpp
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/BeServed.cpp	2009-06-25 19:05:29 UTC (rev 31239)
+++ haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/BeServed.cpp	2009-06-25 19:56:19 UTC (rev 31240)
@@ -72,7 +72,7 @@
 	char attrBuffer[BT_MAX_ATTR_BUFFER + 1];
 	char pathBuffer[B_PATH_NAME_LENGTH];
 
-	struct session *next;
+	struct session *next;
 } bt_session_t;
 
 typedef void (*bt_net_func)(bt_session_t *, unsigned int, int, bt_arg_t *);
@@ -81,9 +81,9 @@
 {
 	unsigned char command;
 	bt_net_func handler;
-	bool supported;
-	uint8 args;
-	uint32 argTypes[MAX_COMMAND_ARGS];
+	bool supported;
+	uint8 args;
+	uint32 argTypes[MAX_COMMAND_ARGS];
 } bt_command_t;
 
 typedef struct
@@ -2247,7 +2247,7 @@
 	return fileShares[shareId].security;
 }
 
-int btMount(bt_session_t *session, char *shareName, char *user, char *password)
+int btMount(bt_session_t *session, char *shareName, char *user, char *password, vnode_id *vnid)
 {
 	bt_user_rights *ur;
 	struct stat st;
@@ -2340,7 +2340,7 @@
 	return ENOTSUP;
 }
 
-int btLookup(char *fileName)
+int btLookup(char *pathBuf, vnode_id dir_vnid, char *fileName, vnode_id *file_vnid)
 {
 	struct _stat st;
 	if (_stat(fileName, &st) != 0)

Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/NTServApp.aps
===================================================================
(Binary files differ)

Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.sln
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.sln	2009-06-25 19:05:29 UTC (rev 31239)
+++ haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.sln	2009-06-25 19:56:19 UTC (rev 31240)
@@ -0,0 +1,19 @@
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ntservice", "ntservice.vcproj", "{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}.Debug|Win32.ActiveCfg = Debug|Win32
+		{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}.Debug|Win32.Build.0 = Debug|Win32
+		{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}.Release|Win32.ActiveCfg = Release|Win32
+		{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.vcproj
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.vcproj	2009-06-25 19:05:29 UTC (rev 31239)
+++ haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/VS2008/ntservice.vcproj	2009-06-25 19:56:19 UTC (rev 31240)
@@ -0,0 +1,341 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9,00"
+	Name="ntservice"
+	ProjectGUID="{51D2F8FD-A2E2-4749-9B09-D0D783638DBE}"
+	TargetFrameworkVersion="131072"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory=".\WinDebug"
+			IntermediateDirectory=".\WinDebug"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TypeLibraryName=".\WinDebug/ntservice.tlb"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="_DEBUG,WIN32,_CONSOLE"
+				RuntimeLibrary="0"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderFile=".\WinDebug/ntservice.pch"
+				AssemblerListingLocation=".\WinDebug/"
+				ObjectFile=".\WinDebug/"
+				ProgramDataBaseFileName=".\WinDebug/"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/MACHINE:I386"
+				AdditionalDependencies="ws2_32.lib"
+				OutputFile=".\WinDebug/BeServed.exe"
+				LinkIncremental="2"
+				SuppressStartupBanner="true"
+				GenerateDebugInformation="true"
+				ProgramDatabaseFile=".\WinDebug/BeServed.pdb"
+				SubSystem="1"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory=".\WinRel"
+			IntermediateDirectory=".\WinRel"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TypeLibraryName=".\WinRel/ntservice.tlb"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="3"
+				InlineFunctionExpansion="1"
+				EnableIntrinsicFunctions="true"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="true"
+				PreprocessorDefinitions="NDEBUG,WIN32,_CONSOLE"
+				StringPooling="true"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderFile=".\WinRel/ntservice.pch"
+				AssemblerListingLocation=".\WinRel/"
+				ObjectFile=".\WinRel/"
+				ProgramDataBaseFileName=".\WinRel/"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalOptions="/MACHINE:I386"
+				AdditionalDependencies="ws2_32.lib"
+				OutputFile=".\WinRel\BeServed.exe"
+				LinkIncremental="1"
+				SuppressStartupBanner="true"
+				ProgramDatabaseFile=".\WinRel/BeServed.pdb"
+				SubSystem="1"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
+			>
+			<File
+				RelativePath="..\authentication.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\BeServed.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\BlowFish.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\myservice.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservapp.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\NTServApp.rc"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservice.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservmsg.mc"
+				>
+			</File>
+			<File
+				RelativePath="..\printing.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\readerWriter.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_AVLtree.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_BinTree.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_SplayTree.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;fi;fd"
+			>
+			<File
+				RelativePath="..\authentication.h"
+				>
+			</File>
+			<File
+				RelativePath="..\beCompat.h"
+				>
+			</File>
+			<File
+				RelativePath="..\betalk.h"
+				>
+			</File>
+			<File
+				RelativePath="..\BlowFish.h"
+				>
+			</File>
+			<File
+				RelativePath="..\BlowFishTable.h"
+				>
+			</File>
+			<File
+				RelativePath="..\myservice.h"
+				>
+			</File>
+			<File
+				RelativePath="..\node.h"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservapp.h"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservice.h"
+				>
+			</File>
+			<File
+				RelativePath="..\ntservmsg.h"
+				>
+			</File>
+			<File
+				RelativePath="..\printing.h"
+				>
+			</File>
+			<File
+				RelativePath="..\readerWriter.h"
+				>
+			</File>
+			<File
+				RelativePath="..\resource.h"
+				>
+			</File>
+			<File
+				RelativePath="..\STDAFX.H"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_AVLtree.h"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_BinTree.h"
+				>
+			</File>
+			<File
+				RelativePath="..\ubi_SplayTree.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
+			>
+			<File
+				RelativePath="..\icon1.ico"
+				>
+			</File>
+			<File
+				RelativePath="..\msg00001.bin"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/authentication.cpp
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/authentication.cpp	2009-06-25 19:05:29 UTC (rev 31239)
+++ haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/authentication.cpp	2009-06-25 19:56:19 UTC (rev 31240)
@@ -1,266 +1,266 @@
 #include "stdafx.h"
 
-#include "beCompat.h"
-#include "betalk.h"
-#include "authentication.h"
-
-#include "ctype.h"
-#include "signal.h"
-#include "stdlib.h"
-
-extern bool getAuthServerAddress(const char *name);
-
-bt_inPacket *btRPCSimpleCall(unsigned int serverIP, int port, bt_outPacket *outPacket);
-int btRPCConnect(unsigned int serverIP, int port);
-bool btRPCSend(int session, bt_outPacket *outPacket);
-bool btRPCCheckSignature(int session);
-bt_outPacket *btRPCPutHeader(unsigned char command, unsigned char argc, int32 length);
-void btRPCPutArg(bt_outPacket *packet, unsigned int type, void *data, int length);
-
-
-int btRPCConnect(unsigned int serverIP, int port)
-{
-	struct sockaddr_in serverAddr;
-	int session;
-
-	// Initialize the server address structure.
-	memset(&serverAddr, 0, sizeof(serverAddr));
-	serverAddr.sin_port = htons(port);
-	serverAddr.sin_family = AF_INET;
-	serverAddr.sin_addr.s_addr = htonl(serverIP);
-
-	// Create a new socket to receive incoming requests.
-	session = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-	if (session == INVALID_SOCKET)
-		return INVALID_SOCKET;
-
-	// Bind that socket to the address constructed above.
-	if (connect(session, (struct sockaddr *) &serverAddr, sizeof(serverAddr)))
-		return INVALID_SOCKET;
-
-	return session;
-}
-
-bool btRPCSend(int session, bt_outPacket *outPacket)
-{
-	// The XID will be 0.
-	btRPCPutInt32(outPacket, 0);
-	btRPCPutChar(outPacket, BT_CMD_TERMINATOR);
-
-	if (btSendMsg(session, outPacket->buffer, outPacket->length, 0) == -1)
-		return false;
-
-	return true;
-}
-
-bool btRPCCheckSignature(int session)
-{
-	char signature[20];
-	unsigned int sigLen;
-
-	sigLen = strlen(BT_RPC_SIGNATURE);
-	memset(signature, 0, sigLen);
-	if (btRecvMsg(session, signature, sigLen, 0) == -1)
-		return false;
-
-	// Check the signature's validity.
-	signature[sigLen] = 0;
-	return (strcmp(signature, BT_RPC_SIGNATURE) == 0);
-}
-
-// btRPCSimpleCall()
-//
-bt_inPacket *btRPCSimpleCall(unsigned int serverIP, int port, bt_outPacket *outPacket)
-{
-	struct timeval timeout;
-	bt_inPacket *inPacket;
-	fd_set sockSet;
-	char *buffer;
-	int session;
-	int32 xid, length;
-
-	// Establish a connection with the requested server, on the requested port.
-	// If we can't connect, abort and return a NULL packet.
-	inPacket = NULL;
-	session = btRPCConnect(serverIP, port);
-	if (session == INVALID_SOCKET)
-		return NULL;
-
-	// If we connected, send the requested RPC packet.  If the packet cannot be
-	// sent, the connection has dropped and we'll abort the call.
-	if (!btRPCSend(session, outPacket))
-	{
-		close(session);
-		return NULL;
-	}
-
-	// Set a reasonable timeout period.  Select() is used in leiu of alarm() because
-	// select() also aborts on error, alarm() effects all threads in a process.
-	FD_ZERO(&sockSet);
-	timeout.tv_sec = 8;
-	timeout.tv_usec = 0;
-
-	// Block in select() waiting for activity.  This will block until data is available
-	// or until a socket error is pending.
-	FD_SET(session, &sockSet);
-	select(session + 1, &sockSet, NULL, NULL, &timeout);
-
-	// If our socket has data pending, then read the incoming RPC response packet.
-	// This should consist of a valid RPC signature, a tranaction ID (xid), the length
-	// of the variable data, and the data itself.
-	if (FD_ISSET(session, &sockSet))
-		if (btRPCCheckSignature(session))
-		{
-			if (btRecvMsg(session, &xid, sizeof(int32), 0) == -1 ||
-				btRecvMsg(session, &length, sizeof(int32), 0) == -1)
-				goto abortCall;
-
-			// Now allocate a buffer of the appropriate length.  If one cannot be
-			// allocated, we won't be able to store incoming information and the call
-			// must be aborted.
-			xid = B_LENDIAN_TO_HOST_INT32(xid);
-			length = B_LENDIAN_TO_HOST_INT32(length);
-			if (length > 0 && length < BT_RPC_MAX_PACKET_SIZE)
-			{
-				buffer = (char *) malloc(length + 1);
-				if (buffer)
-				{
-					// Read the remaining packet contents.  The btRecv() function takes
-					// care of restarting the recv() when signal interrupts occur.  It
-					// will always return -1 on error, even upon orderly shutdown of the peer.
-					if (btRecvMsg(session, buffer, length, 0) == -1)
-					{
-						free(buffer);
-						goto abortCall;
-					}
-
-					// Terminate the buffer.
-					buffer[length] = 0;
-
-					// Allocate a new incoming packet and set its buffer and length.
-					inPacket = (bt_inPacket *) malloc(sizeof(bt_inPacket));
-					if (inPacket)
-					{
-						inPacket->buffer = buffer;
-						inPacket->length = length;
-						inPacket->offset = 0;
-					}
-					else
-						free(buffer);
-				}
-			}
-		}
-
-	// Execution can naturally lead here or we can jump here from a failed attempt to
-	// send or receive an RPC packet.  The socket is closed and the current incoming
-	// packet returned, which will be NULL upon failure.
-abortCall:
-	shutdown(session, 2);
-	close(session);
-	return inPacket;
-}
-
-bt_outPacket *btRPCPutHeader(unsigned char command, unsigned char argc, int32 length)
-{
-	bt_outPacket *packet;
-
-	packet = (bt_outPacket *) malloc(sizeof(bt_outPacket));
-	if (!packet)
-		return NULL;
-
-	packet->size = BT_RPC_MIN_PACKET_SIZE;
-	packet->buffer = (char *) malloc(packet->size);
-	packet->length = 0;
-
-	if (!packet->buffer)
-	{
-		free(packet);
-		return NULL;
-	}
-
-	strcpy(packet->buffer, BT_RPC_SIGNATURE);
-	packet->length += strlen(BT_RPC_SIGNATURE);
-
-//	btRPCPutChar(packet, BT_RPC_VERSION_HI);
-//	btRPCPutChar(packet, BT_RPC_VERSION_LO);
-	btRPCPutInt32(packet, 7 + (8 * argc) + length);
-	btRPCPutChar(packet, command);
-	btRPCPutChar(packet, argc);
-
-	return packet;
-}
-
-void btRPCPutArg(bt_outPacket *packet, unsigned int type, void *data, int length)
-{
-	btRPCPutInt32(packet, type);
-	btRPCPutInt32(packet, length);
-	btRPCPutBinary(packet, data, length);
-}
-
-bool authenticateUser(char *user, char *password)
-{
-	extern char *authServerName;
-	extern unsigned int authServerIP;
-	bt_outPacket *outPacket;
-	bt_inPacket *inPacket;
-	bool authenticated = false;
-	int error;
-
-	getAuthServerAddress(authServerName);
-
-	outPacket = btRPCPutHeader(BT_CMD_AUTH, 2, strlen(user) + BT_AUTH_TOKEN_LENGTH);
-	if (outPacket)
-	{
-		btRPCPutArg(outPacket, B_STRING_TYPE, user, strlen(user));
-		btRPCPutArg(outPacket, B_STRING_TYPE, password, BT_AUTH_TOKEN_LENGTH);
-		inPacket = btRPCSimpleCall(authServerIP, BT_BESURE_PORT, outPacket);
-		if (inPacket)
-		{
-			error = btRPCGetInt32(inPacket);
-			if (error == B_OK)
-				authenticated = true;
-	
-			free(inPacket->buffer);
-			free(inPacket);
-		}
-
-		free(outPacket->buffer);
-		free(outPacket);
-	}
-
-	return authenticated;
-}
-
-void getUserGroups(char *user, char **groups)
-{
-	extern char *authServerName;
-	extern unsigned int authServerIP;
-	bt_outPacket *outPacket;
-	bt_inPacket *inPacket;
-	int i, error;
-
-	getAuthServerAddress(authServerName);
-
-	outPacket = btRPCPutHeader(BT_CMD_WHICHGROUPS, 1, strlen(user));
-	if (outPacket)
-	{
-		btRPCPutArg(outPacket, B_STRING_TYPE, user, strlen(user));
-		inPacket = btRPCSimpleCall(authServerIP, BT_BESURE_PORT, outPacket);
-		if (inPacket)
-		{
-			i = 0;
-			error = btRPCGetInt32(inPacket);
-			while (error == B_OK)
-			{
-				groups[i++] = btRPCGetNewString(inPacket);
-				error = btRPCGetInt32(inPacket);
-			}
-	
-			free(inPacket->buffer);
-			free(inPacket);
-		}
-
-		free(outPacket->buffer);
-		free(outPacket);
-	}
-}
+#include "beCompat.h"
+#include "betalk.h"
+#include "authentication.h"
+
+#include "ctype.h"
+#include "signal.h"
+#include "stdlib.h"
+
+extern bool getAuthServerAddress(const char *name);
+
+bt_inPacket *btRPCSimpleCall(unsigned int serverIP, int port, bt_outPacket *outPacket);
+int btRPCConnect(unsigned int serverIP, int port);
+bool btRPCSend(int session, bt_outPacket *outPacket);
+bool btRPCCheckSignature(int session);
+bt_outPacket *btRPCPutHeader(unsigned char command, unsigned char argc, int32 length);
+void btRPCPutArg(bt_outPacket *packet, unsigned int type, void *data, int length);
+
+
+int btRPCConnect(unsigned int serverIP, int port)
+{
+	struct sockaddr_in serverAddr;
+	int session;
+
+	// Initialize the server address structure.
+	memset(&serverAddr, 0, sizeof(serverAddr));
+	serverAddr.sin_port = htons(port);
+	serverAddr.sin_family = AF_INET;
+	serverAddr.sin_addr.s_addr = htonl(serverIP);
+
+	// Create a new socket to receive incoming requests.
+	session = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if (session == INVALID_SOCKET)
+		return INVALID_SOCKET;
+
+	// Bind that socket to the address constructed above.
+	if (connect(session, (struct sockaddr *) &serverAddr, sizeof(serverAddr)))
+		return INVALID_SOCKET;
+
+	return session;
+}
+
+bool btRPCSend(int session, bt_outPacket *outPacket)
+{
+	// The XID will be 0.
+	btRPCPutInt32(outPacket, 0);
+	btRPCPutChar(outPacket, BT_CMD_TERMINATOR);
+
+	if (btSendMsg(session, outPacket->buffer, outPacket->length, 0) == -1)
+		return false;
+
+	return true;
+}
+
+bool btRPCCheckSignature(int session)
+{
+	char signature[20];
+	unsigned int sigLen;
+
+	sigLen = strlen(BT_RPC_SIGNATURE);
+	memset(signature, 0, sigLen);
+	if (btRecvMsg(session, signature, sigLen, 0) == -1)
+		return false;
+
+	// Check the signature's validity.
+	signature[sigLen] = 0;
+	return (strcmp(signature, BT_RPC_SIGNATURE) == 0);
+}
+
+// btRPCSimpleCall()
+//
+bt_inPacket *btRPCSimpleCall(unsigned int serverIP, int port, bt_outPacket *outPacket)
+{
+	struct timeval timeout;
+	bt_inPacket *inPacket;
+	fd_set sockSet;
+	char *buffer;
+	int session;
+	int32 xid, length;
+
+	// Establish a connection with the requested server, on the requested port.
+	// If we can't connect, abort and return a NULL packet.
+	inPacket = NULL;
+	session = btRPCConnect(serverIP, port);
+	if (session == INVALID_SOCKET)
+		return NULL;
+
+	// If we connected, send the requested RPC packet.  If the packet cannot be
+	// sent, the connection has dropped and we'll abort the call.
+	if (!btRPCSend(session, outPacket))
+	{
+		close(session);
+		return NULL;
+	}
+
+	// Set a reasonable timeout period.  Select() is used in leiu of alarm() because
+	// select() also aborts on error, alarm() effects all threads in a process.
+	FD_ZERO(&sockSet);
+	timeout.tv_sec = 8;
+	timeout.tv_usec = 0;
+
+	// Block in select() waiting for activity.  This will block until data is available
+	// or until a socket error is pending.
+	FD_SET(session, &sockSet);
+	select(session + 1, &sockSet, NULL, NULL, &timeout);
+
+	// If our socket has data pending, then read the incoming RPC response packet.
+	// This should consist of a valid RPC signature, a tranaction ID (xid), the length
+	// of the variable data, and the data itself.
+	if (FD_ISSET(session, &sockSet))
+		if (btRPCCheckSignature(session))
+		{
+			if (btRecvMsg(session, &xid, sizeof(int32), 0) == -1 ||
+				btRecvMsg(session, &length, sizeof(int32), 0) == -1)
+				goto abortCall;
+
+			// Now allocate a buffer of the appropriate length.  If one cannot be
+			// allocated, we won't be able to store incoming information and the call
+			// must be aborted.
+			xid = B_LENDIAN_TO_HOST_INT32(xid);
+			length = B_LENDIAN_TO_HOST_INT32(length);
+			if (length > 0 && length < BT_RPC_MAX_PACKET_SIZE)
+			{
+				buffer = (char *) malloc(length + 1);
+				if (buffer)
+				{
+					// Read the remaining packet contents.  The btRecv() function takes
+					// care of restarting the recv() when signal interrupts occur.  It
+					// will always return -1 on error, even upon orderly shutdown of the peer.
+					if (btRecvMsg(session, buffer, length, 0) == -1)
+					{
+						free(buffer);
+						goto abortCall;
+					}
+
+					// Terminate the buffer.
+					buffer[length] = 0;
+
+					// Allocate a new incoming packet and set its buffer and length.
+					inPacket = (bt_inPacket *) malloc(sizeof(bt_inPacket));
+					if (inPacket)
+					{
+						inPacket->buffer = buffer;
+						inPacket->length = length;
+						inPacket->offset = 0;
+					}
+					else
+						free(buffer);
+				}
+			}
+		}
+
+	// Execution can naturally lead here or we can jump here from a failed attempt to
+	// send or receive an RPC packet.  The socket is closed and the current incoming
+	// packet returned, which will be NULL upon failure.
+abortCall:
+	shutdown(session, 2);
+	close(session);
+	return inPacket;
+}
+
+bt_outPacket *btRPCPutHeader(unsigned char command, unsigned char argc, int32 length)
+{
+	bt_outPacket *packet;
+
+	packet = (bt_outPacket *) malloc(sizeof(bt_outPacket));
+	if (!packet)
+		return NULL;
+
+	packet->size = BT_RPC_MIN_PACKET_SIZE;
+	packet->buffer = (char *) malloc(packet->size);
+	packet->length = 0;
+
+	if (!packet->buffer)
+	{
+		free(packet);
+		return NULL;
+	}
+
+	strcpy(packet->buffer, BT_RPC_SIGNATURE);
+	packet->length += strlen(BT_RPC_SIGNATURE);
+
+//	btRPCPutChar(packet, BT_RPC_VERSION_HI);
+//	btRPCPutChar(packet, BT_RPC_VERSION_LO);
+	btRPCPutInt32(packet, 7 + (8 * argc) + length);
+	btRPCPutChar(packet, command);
+	btRPCPutChar(packet, argc);
+
+	return packet;
+}
+
+void btRPCPutArg(bt_outPacket *packet, unsigned int type, void *data, int length)
+{
+	btRPCPutInt32(packet, type);
+	btRPCPutInt32(packet, length);
+	btRPCPutBinary(packet, data, length);
+}
+
+bool authenticateUser(char *user, char *password)
+{
+	extern char *authServerName;
+	extern unsigned int authServerIP;
+	bt_outPacket *outPacket;
+	bt_inPacket *inPacket;
+	bool authenticated = false;
+	int error;
+
+	getAuthServerAddress(authServerName);
+
+	outPacket = btRPCPutHeader(BT_CMD_AUTH, 2, strlen(user) + BT_AUTH_TOKEN_LENGTH);
+	if (outPacket)
+	{
+		btRPCPutArg(outPacket, B_STRING_TYPE, user, strlen(user));
+		btRPCPutArg(outPacket, B_STRING_TYPE, password, BT_AUTH_TOKEN_LENGTH);
+		inPacket = btRPCSimpleCall(authServerIP, BT_BESURE_PORT, outPacket);
+		if (inPacket)
+		{
+			error = btRPCGetInt32(inPacket);
+			if (error == B_OK)
+				authenticated = true;
+	
+			free(inPacket->buffer);
+			free(inPacket);
+		}
+
+		free(outPacket->buffer);
+		free(outPacket);
+	}
+
+	return authenticated;
+}
+
+void getUserGroups(char *user, char **groups)
+{
+	extern char *authServerName;
+	extern unsigned int authServerIP;
+	bt_outPacket *outPacket;
+	bt_inPacket *inPacket;
+	int i, error;
+
+	getAuthServerAddress(authServerName);
+
+	outPacket = btRPCPutHeader(BT_CMD_WHICHGROUPS, 1, strlen(user));
+	if (outPacket)
+	{
+		btRPCPutArg(outPacket, B_STRING_TYPE, user, strlen(user));
+		inPacket = btRPCSimpleCall(authServerIP, BT_BESURE_PORT, outPacket);
+		if (inPacket)
+		{
+			i = 0;
+			error = btRPCGetInt32(inPacket);
+			while (error == B_OK)
+			{
+				groups[i++] = btRPCGetNewString(inPacket);
+				error = btRPCGetInt32(inPacket);
+			}
+	
+			free(inPacket->buffer);
+			free(inPacket);
+		}
+
+		free(outPacket->buffer);
+		free(outPacket);
+	}
+}

Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/readerWriter.cpp
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/readerWriter.cpp	2009-06-25 19:05:29 UTC (rev 31239)
+++ haiku/trunk/src/tests/add-ons/kernel/file_systems/beserved/server-Windows/readerWriter.cpp	2009-06-25 19:56:19 UTC (rev 31240)
@@ -1,110 +1,110 @@
-// readerWriter.c
-
+// readerWriter.c
+
 #include "stdafx.h"
-
-#include "beCompat.h"
-#include "betalk.h"
-#include "readerWriter.h"
-
-
-bool initManagedData(bt_managed_data *data)
-{
-	data->readCount = 0;
-	data->writeCount = 0;
-
+
+#include "beCompat.h"
+#include "betalk.h"
+#include "readerWriter.h"
+
+
+bool initManagedData(bt_managed_data *data)
+{
+	data->readCount = 0;
+	data->writeCount = 0;
+
 	if (!(data->readCountSem = CreateSemaphore(NULL, 1, 1, NULL)))
 		return false;
-
+
 	if (!(data->writeCountSem = CreateSemaphore(NULL, 1, 1, NULL)))
-	{
-		CloseHandle(data->readCountSem);
-		return false;
-	}
-
+	{

[... truncated: 176 lines follow ...]



More information about the Haiku-commits mailing list