New client components for Casa Authentication.
This commit is contained in:
165
auth_token/client/test/CASA_Auth.cpp
Normal file
165
auth_token/client/test/CASA_Auth.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <windows.h>
|
||||
#include "casa_auth_token.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
|
||||
// Now lets obtain a token for our service
|
||||
retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen);
|
||||
if (retStatus)
|
||||
printf("ObtainAuthToken failed with status %d\n", retStatus);
|
||||
else
|
||||
{
|
||||
char serverAddr[] = "137.65.132.44";
|
||||
char *pServerAddress = serverAddr;
|
||||
int serverPort = 4444;
|
||||
SOCKET sock;
|
||||
struct sockaddr_in localAddr = {0};
|
||||
struct sockaddr_in remoteAddr = {0};
|
||||
struct linger linger_opt = {1, 15};
|
||||
struct hostent *pLookupResult;
|
||||
int winsockStartupResult;
|
||||
WSADATA winsockData;
|
||||
|
||||
//printf("ObtainAuthToken succedded, token = %s\n", authToken);
|
||||
printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
|
||||
// Send the token to the server
|
||||
//
|
||||
// First initialize winsock
|
||||
if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0)
|
||||
{
|
||||
// Open socket
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sock != INVALID_SOCKET)
|
||||
{
|
||||
// Setup the local address structure
|
||||
localAddr.sin_family = AF_INET;
|
||||
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
// Bind socket
|
||||
if (!bind(sock, (const struct sockaddr*) &localAddr, sizeof(struct sockaddr_in)))
|
||||
{
|
||||
// Resolve the server address
|
||||
pLookupResult = gethostbyname(pServerAddress);
|
||||
if (pLookupResult)
|
||||
{
|
||||
// Validate the address type returned
|
||||
if (pLookupResult->h_addrtype == AF_INET)
|
||||
{
|
||||
int numAddressesFound = 0;
|
||||
|
||||
// Determine how many addresses where returned
|
||||
while (pLookupResult->h_addr_list[numAddressesFound] != NULL)
|
||||
{
|
||||
//printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound]));
|
||||
numAddressesFound ++;
|
||||
}
|
||||
//printf("Found %d addresses\n", numAddressesFound);
|
||||
|
||||
|
||||
// Setup the remote address structure with the lookup results
|
||||
remoteAddr.sin_family = AF_INET;
|
||||
remoteAddr.sin_port = htons(serverPort);
|
||||
remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut
|
||||
//printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr);
|
||||
|
||||
// Perform connect operation
|
||||
if (connect(sock,
|
||||
(struct sockaddr*) &remoteAddr,
|
||||
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
|
||||
{
|
||||
printf("main()- Connection creation failed, error = %d\n", WSAGetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now the connection is setup, send the credentials to the server as one line.
|
||||
// using our cheesy protocol followed by a hello string.
|
||||
|
||||
// Send the username to the server (including NULL terminator)
|
||||
//send(sock, userName, userNameBufLen, 0);
|
||||
|
||||
// Send new line
|
||||
//send(sock, "\n", 1, MSG_NOSIGNAL);
|
||||
|
||||
// Send the token to the server (including NULL terminator)
|
||||
send(sock, authToken, (int) strlen(authToken) + 1, 0);
|
||||
|
||||
// Send new line
|
||||
//send(sock, "\n", 1, 0);
|
||||
|
||||
// Send "hello"
|
||||
//send(sock, helloString, strlen(helloString) + 1, MSG_NOSIGNAL);
|
||||
|
||||
// Send new line
|
||||
//send(sock, "\n", 1, 0);
|
||||
|
||||
// Shutdown the connection
|
||||
shutdown(sock, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Lookup for %s failed\n", pServerAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to bind socket, error = %d", errno);
|
||||
}
|
||||
|
||||
// Close the socket
|
||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*) &linger_opt, sizeof(linger_opt));
|
||||
closesocket(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to open socket, error = %d\n", errno);
|
||||
}
|
||||
|
||||
// Close winsock
|
||||
WSACleanup();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Enter to exit application\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
142
auth_token/client/test/test.vcproj
Normal file
142
auth_token/client/test/test.vcproj
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="test"
|
||||
ProjectGUID="{6034EBF1-0838-45C4-A538-A41A31EC8F46}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="authtoken.lib ws2_32.lib"
|
||||
OutputFile="$(OutDir)/test.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\client\win32\Debug"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy ..\win32\debug\authtoken.dll debug\authtoken.dll"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="authtoken.lib ws2_32.lib"
|
||||
OutputFile="$(OutDir)/test.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""C:\Program Files\novell\CASA\lib""
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\CASA_Auth.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Reference in New Issue
Block a user