Splitted the non-java project into client and server projects in order
to be able to deliver the client component onto distributions targeting desktops without having to deliver the server components. This commit is for the resulting client project.
This commit is contained in:
37
CASA-auth-token/client/core/Makefile.am
Normal file
37
CASA-auth-token/client/core/Makefile.am
Normal file
@@ -0,0 +1,37 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = $(TARGET_OS) mechanisms
|
||||
|
||||
DIST_SUBDIRS = linux windows mechanisms
|
||||
|
||||
CFILES =
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h client.conf
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
90
CASA-auth-token/client/core/README
Normal file
90
CASA-auth-token/client/core/README
Normal file
@@ -0,0 +1,90 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
*
|
||||
* README for libcasa_c_authtoken
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
libcasa_c_authtoken is the client auth_token engine. It is responsible for
|
||||
interacting with ATSs, invoking the authentication mechanism plug-ins, and
|
||||
managing the authentication token cache. libcasa_c_authtoken also provides
|
||||
the Get Authentication Token API.
|
||||
|
||||
CONFIGURING ADDITIONAL AUTHENTICATION MECHANISM MODULES
|
||||
|
||||
libcasa_c_authtoken utilizes mechanism plug-ins for authenticating to ATSs.
|
||||
The client auth_token package installs mechanisms for the support of Kerberos5
|
||||
and Username/Password authentication. To configure additional authentication mechanism
|
||||
plug-ins, place their configuration file in the folder for CASA Authentication Token module
|
||||
configuration. The path to this folder under linux is /etc/CASA/authtoken/client/mechanisms/.
|
||||
The path to this folder under Windows is \Program Files\novell\CASA\Etc\Auth\Mechanisms\. The name of
|
||||
the plug-in configuration file is related to the authentication mechanism type in the following
|
||||
manner: AuthenticationMechanismTypeName.conf.
|
||||
|
||||
Authentication Mechanism plug-in configuration files must must contain a directive indicating the
|
||||
path to the library implementing the Authentication Mechanism (See the configuration file
|
||||
for the Kr5Authenticate plug-in for an example).
|
||||
|
||||
CLIENT APPLICATION PROGRAMMING NOTES
|
||||
|
||||
The Get CASA Authentication Token API is defined in casa_c_authtoken.h.
|
||||
|
||||
The API consists of a call to obtain authentication tokens. The caller must supply the name of the
|
||||
service to which it wants to authenticate along with the name of the host where it resides. The
|
||||
returned authentication token is a Base64 encoded string.
|
||||
|
||||
Applications utilizing CASA Authentication Tokens as passwords in protocols that require the
|
||||
transfer of user name and password credentials should verify or remove any password length limits
|
||||
as the length of CASA Authentication Tokens may be over 1K bytes. The size of the CASA Authentication
|
||||
Tokens is directly dependent on the amount of identity information configured as required by the
|
||||
consuming service. These applications should also set the user name to "CasaPrincipal".
|
||||
|
||||
For examples of code which uses the Get CASA Authentication Token API look at the test application
|
||||
under the test folder.
|
||||
|
||||
AUTHENTICATION MECHANISM PROGRAMMING NOTES
|
||||
|
||||
The Authentication Mechanism API is defined in mech_if.h.
|
||||
|
||||
For example implementations see the code for the krb5 and the pwd mechanisms.
|
||||
|
||||
SECURITY CONSIDERATIONS
|
||||
|
||||
CASA Authentication Tokens when compromised can be used to either impersonate
|
||||
a user or to obtain identity information about the user. Because of this it is
|
||||
important that the tokens be secured by applications making use of them. It is
|
||||
recommended that the tokens be transmitted using SSL.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13
CASA-auth-token/client/core/TODO
Normal file
13
CASA-auth-token/client/core/TODO
Normal file
@@ -0,0 +1,13 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* TODO for libcasa_c_authtoken
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
This file contains a list of the items still outstanding for libcasa_c_authtoken.
|
||||
|
||||
OUTSTANDING ITEMS
|
||||
|
||||
None.
|
||||
343
CASA-auth-token/client/core/authmech.c
Normal file
343
CASA-auth-token/client/core/authmech.c
Normal file
@@ -0,0 +1,343 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// AuthMechMod definition
|
||||
//
|
||||
typedef struct _AuthMechMod
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pAuthTypeName;
|
||||
int authTypeNameLen;
|
||||
LIB_HANDLE libHandle;
|
||||
AuthTokenIf *pAuthTokenIf;
|
||||
|
||||
} AuthMechMod, *PAuthMechMod;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// AuthMechModule List and syncronizing mutex
|
||||
static
|
||||
LIST_ENTRY g_authMechModuleListHead = {&g_authMechModuleListHead,
|
||||
&g_authMechModuleListHead};
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
GetAuthTokenIf(
|
||||
IN const char *pAuthTypeName,
|
||||
INOUT AuthTokenIf **ppAuthTokenIf)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// Environment:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
ConfigIf *pModuleConfigIf;
|
||||
|
||||
DbgTrace(2, "-GetAuthTokenIf- Start\n", 0);
|
||||
|
||||
// Get the configuration for the module
|
||||
retStatus = GetConfigInterface(mechConfigFolder,
|
||||
pAuthTypeName,
|
||||
&pModuleConfigIf);
|
||||
if (CASA_SUCCESS(retStatus)
|
||||
&& CasaStatusCode(retStatus) != CASA_STATUS_OBJECT_NOT_FOUND)
|
||||
{
|
||||
LIST_ENTRY *pListEntry;
|
||||
AuthMechMod *pAuthMechMod = NULL;
|
||||
int authTypeNameLen = strlen(pAuthTypeName);
|
||||
|
||||
// Look if we already have the module in our list
|
||||
pListEntry = g_authMechModuleListHead.Flink;
|
||||
while (pListEntry != &g_authMechModuleListHead)
|
||||
{
|
||||
// Get pointer to the current entry
|
||||
pAuthMechMod = CONTAINING_RECORD(pListEntry, AuthMechMod, listEntry);
|
||||
|
||||
// Check if this is the module that we need
|
||||
if (pAuthMechMod->authTypeNameLen == authTypeNameLen
|
||||
&& memcmp(pAuthTypeName, pAuthMechMod->pAuthTypeName, authTypeNameLen) == 0)
|
||||
{
|
||||
// This is the module that we need, stop looking.
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is not the module that we are looking for
|
||||
pAuthMechMod = NULL;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Proceed based on whether or not a module was found
|
||||
if (pAuthMechMod)
|
||||
{
|
||||
// Module found in our list, provide the caller with its AuthTokenIf
|
||||
// instance after we have incremented its reference count.
|
||||
pAuthMechMod->pAuthTokenIf->addReference(pAuthMechMod->pAuthTokenIf);
|
||||
*ppAuthTokenIf = pAuthMechMod->pAuthTokenIf;
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Needed module not found in our list, create an entry.
|
||||
pAuthMechMod = (AuthMechMod*) malloc(sizeof(*pAuthMechMod));
|
||||
if (pAuthMechMod)
|
||||
{
|
||||
// Allocate buffer to contain the authentication type name within the module entry
|
||||
pAuthMechMod->pAuthTypeName = (char*) malloc(authTypeNameLen + 1);
|
||||
if (pAuthMechMod->pAuthTypeName)
|
||||
{
|
||||
char *pLibraryName;
|
||||
|
||||
// Initialize the library handle field
|
||||
pAuthMechMod->libHandle = NULL;
|
||||
|
||||
// Save the auth type name within the entry
|
||||
strcpy(pAuthMechMod->pAuthTypeName, pAuthTypeName);
|
||||
pAuthMechMod->authTypeNameLen = authTypeNameLen;
|
||||
|
||||
// Obtain the name of the library that we must load
|
||||
pLibraryName = pModuleConfigIf->getEntryValue(pModuleConfigIf, "LibraryName");
|
||||
if (pLibraryName)
|
||||
{
|
||||
// Load the library
|
||||
pAuthMechMod->libHandle = OpenLibrary(pLibraryName);
|
||||
if (pAuthMechMod->libHandle)
|
||||
{
|
||||
PFN_GetAuthTokenIfRtn pGetAuthTokenIfRtn;
|
||||
|
||||
// Library has been loaded, now get a pointer to its GetAuthTokenInterface routine
|
||||
pGetAuthTokenIfRtn = (PFN_GetAuthTokenIfRtn) GetFunctionPtr(pAuthMechMod->libHandle,
|
||||
GET_AUTH_TOKEN_INTERFACE_RTN_SYMBOL);
|
||||
if (pGetAuthTokenIfRtn)
|
||||
{
|
||||
// Now, obtain the modules AuthTokenIf.
|
||||
retStatus = (pGetAuthTokenIfRtn)(pModuleConfigIf, &pAuthMechMod->pAuthTokenIf);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenIf- GetFunctionPtr\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_LIBRARY_LOAD_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenIf- OpenLibrary error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Free the buffer holding the library name
|
||||
free(pLibraryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenIf- Library name not configured\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_CONFIGURATION_ERROR);
|
||||
}
|
||||
|
||||
// Check if we were successful at obtaining the AuthTokenIf instance for the
|
||||
// module.
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Insert the entry in the list, provide the caller with its AuthTokenIf
|
||||
// instance after we have incremented its reference count.
|
||||
InsertTailList(&g_authMechModuleListHead, &pAuthMechMod->listEntry);
|
||||
pAuthMechMod->pAuthTokenIf->addReference(pAuthMechMod->pAuthTokenIf);
|
||||
*ppAuthTokenIf = pAuthMechMod->pAuthTokenIf;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed, free resources.
|
||||
free(pAuthMechMod->pAuthTypeName);
|
||||
if (pAuthMechMod->libHandle)
|
||||
CloseLibrary(pAuthMechMod->libHandle);
|
||||
free(pAuthMechMod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "GetAuthTokenIf-GetAuthTokenIf- Unable to allocate buffer\n", 0);
|
||||
|
||||
// Free buffer allocated for entry
|
||||
free(pAuthMechMod);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenIf- Unable to allocate buffer\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
// Release config interface instance
|
||||
pModuleConfigIf->releaseReference(pModuleConfigIf);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenIf- Unable to obtain config interface\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_CONFIGURATION_ERROR);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetAuthTokenIf- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
GetAuthMechToken(
|
||||
IN AuthContext *pAuthContext,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char **ppAuthToken)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
AuthTokenIf *pAuthTokenIf = NULL;
|
||||
|
||||
DbgTrace(1, "-GetAuthMechToken- Start\n", 0);
|
||||
|
||||
// Initialize output parameter
|
||||
*ppAuthToken = NULL;
|
||||
|
||||
// Obtain the appropriate token interface for the authentication type
|
||||
retStatus = GetAuthTokenIf(pAuthContext->pMechanism,
|
||||
&pAuthTokenIf);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
char *pAuthToken = NULL;
|
||||
int authTokenBufLen = 0;
|
||||
|
||||
// We found a provider for the service, query it for the buffer size
|
||||
// needed to obtain the authentication token.
|
||||
retStatus = pAuthTokenIf->getAuthToken(pAuthTokenIf,
|
||||
pAuthContext->pContext,
|
||||
pAuthContext->pMechInfo,
|
||||
pHostName,
|
||||
pCredStoreScope,
|
||||
pAuthToken,
|
||||
&authTokenBufLen);
|
||||
if (CasaStatusCode(retStatus) == CASA_STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
// Allocate buffer to hold the authentication token
|
||||
pAuthToken = (char*) malloc(authTokenBufLen);
|
||||
if (pAuthToken)
|
||||
{
|
||||
// Request the token from the provider
|
||||
retStatus = pAuthTokenIf->getAuthToken(pAuthTokenIf,
|
||||
pAuthContext->pContext,
|
||||
pAuthContext->pMechInfo,
|
||||
pHostName,
|
||||
pCredStoreScope,
|
||||
pAuthToken,
|
||||
&authTokenBufLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Return the buffer containing the token to the caller
|
||||
*ppAuthToken = pAuthToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Free the allocated buffer
|
||||
free(pAuthToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthMechToken- Buffer allocation failure\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Release token interface
|
||||
pAuthTokenIf->releaseReference(pAuthTokenIf);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No authentication token interface available for authentication type
|
||||
DbgTrace(0, "-GetAuthMechToken- Failed to obtain auth mech token interface\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-GetAuthMechToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
803
CASA-auth-token/client/core/authmsg.c
Normal file
803
CASA-auth-token/client/core/authmsg.c
Normal file
@@ -0,0 +1,803 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Parse states
|
||||
//
|
||||
#define AWAITING_ROOT_ELEMENT_START 0x0
|
||||
#define AWAITING_ROOT_ELEMENT_END 0x1
|
||||
#define AWAITING_STATUS_ELEMENT_START 0x2
|
||||
#define AWAITING_STATUS_ELEMENT_END 0x3
|
||||
#define AWAITING_STATUS_DATA 0x4
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_START 0x5
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_END 0x6
|
||||
#define AWAITING_DESCRIPTION_DATA 0x7
|
||||
#define AWAITING_SESSION_TOKEN_ELEMENT_START 0x8
|
||||
#define AWAITING_SESSION_TOKEN_ELEMENT_END 0x9
|
||||
#define AWAITING_SESSION_TOKEN_DATA 0xA
|
||||
#define AWAITING_LIFETIME_DATA 0xB
|
||||
#define AWAITING_LIFETIME_ELEMENT_START 0xC
|
||||
#define AWAITING_LIFETIME_ELEMENT_END 0xD
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_START 0xE
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_END 0xF
|
||||
#define AWAITING_AUTH_TOKEN_DATA 0x10
|
||||
#define AWAITING_REALM_DATA 0x12
|
||||
#define AWAITING_REALM_ELEMENT_END 0x13
|
||||
#define DONE_PARSING 0x14
|
||||
|
||||
//
|
||||
// Authentication Response Parse Structure
|
||||
//
|
||||
typedef struct _AuthRespParse
|
||||
{
|
||||
XML_Parser p;
|
||||
int state;
|
||||
int elementDataProcessed;
|
||||
AuthenticateResp *pAuthenticateResp;
|
||||
CasaStatus status;
|
||||
|
||||
} AuthRespParse, *PAuthRespParse;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//++=======================================================================
|
||||
char*
|
||||
BuildAuthenticateMsg(
|
||||
IN AuthContext *pAuthContext,
|
||||
IN char *pAuthMechToken)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pMsg = NULL;
|
||||
int bufferSize;
|
||||
|
||||
DbgTrace(1, "-BuildAuthenticateMsg- Start\n", 0);
|
||||
|
||||
/*
|
||||
* The format of the authentication request message is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_req>
|
||||
* <realm>realm value</realm>
|
||||
* <mechanism>mechanism id value</mechanism>
|
||||
* <auth_mech_token>authentication mechanism token data</auth_mech_token>
|
||||
* </auth_req>
|
||||
*
|
||||
*/
|
||||
|
||||
// Determine the buffer size necessary to hold the msg
|
||||
bufferSize = strlen(XML_DECLARATION)
|
||||
+ 2 // crlf
|
||||
+ 1 // <
|
||||
+ strlen(AUTH_REQUEST_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(REALM_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pAuthContext->pContext)
|
||||
+ 2 // </
|
||||
+ strlen(REALM_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(MECHANISM_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pAuthContext->pMechanism)
|
||||
+ 2 // </
|
||||
+ strlen(MECHANISM_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(AUTH_MECH_TOKEN_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pAuthMechToken)
|
||||
+ 2 // </
|
||||
+ strlen(AUTH_MECH_TOKEN_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 2 // </
|
||||
+ strlen(AUTH_REQUEST_ELEMENT_NAME)
|
||||
+ 2; // >null
|
||||
|
||||
// Allocate the msg buffer
|
||||
pMsg = (char*) malloc(bufferSize);
|
||||
if (pMsg)
|
||||
{
|
||||
// Now build the message
|
||||
memset(pMsg, 0, bufferSize);
|
||||
strcat(pMsg, XML_DECLARATION);
|
||||
strcat(pMsg, "\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, AUTH_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, REALM_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pAuthContext->pContext);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, REALM_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, MECHANISM_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pAuthContext->pMechanism);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, MECHANISM_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pAuthMechToken);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, AUTH_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-BuildAuthenticateMsg- Buffer allocation error\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-BuildAuthenticateMsg- End, pMsg = %0lX\n", (long) pMsg);
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthRespStartElementHandler(
|
||||
IN AuthRespParse *pAuthRespParse,
|
||||
IN const XML_Char *name,
|
||||
IN const XML_Char **atts)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AuthRespStartElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Authentication
|
||||
// Response Element.
|
||||
if (strcmp(name, AUTH_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_STATUS_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_DESCRIPTION_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_DESCRIPTION_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_SESSION_TOKEN_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Session Token Element.
|
||||
if (strcmp(name, SESSION_TOKEN_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_LIFETIME_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Lifetime Element.
|
||||
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_LIFETIME_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected state = %d\n", pAuthRespParse->state);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-AuthRespStartElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ConsumeElementData(
|
||||
IN AuthRespParse *pAuthRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len,
|
||||
INOUT char **ppElementData,
|
||||
INOUT int *pElementDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- Start\n", 0);
|
||||
|
||||
// Proceed based on whether or not we have already consumed data
|
||||
// for this element.
|
||||
if (*ppElementData == NULL)
|
||||
{
|
||||
// We have not yet consumed data for this element
|
||||
pAuthRespParse->elementDataProcessed = len;
|
||||
|
||||
// Allocate a buffer to hold this element data (null terminated).
|
||||
*ppElementData = (char*) malloc(len + 1);
|
||||
if (*ppElementData)
|
||||
{
|
||||
memset(*ppElementData, 0, len + 1);
|
||||
memcpy(*ppElementData, s, len);
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pAuthRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pNewBuf;
|
||||
|
||||
// We have already received token data, append this data to it.
|
||||
pNewBuf = (char*) malloc(pAuthRespParse->elementDataProcessed + len + 1);
|
||||
if (pNewBuf)
|
||||
{
|
||||
memset(pNewBuf,
|
||||
0,
|
||||
pAuthRespParse->elementDataProcessed + len + 1);
|
||||
memcpy(pNewBuf,
|
||||
*ppElementData,
|
||||
pAuthRespParse->elementDataProcessed);
|
||||
memcpy(pNewBuf + pAuthRespParse->elementDataProcessed, s, len);
|
||||
pAuthRespParse->elementDataProcessed += len;
|
||||
|
||||
// Swap the buffers
|
||||
free(*ppElementData);
|
||||
*ppElementData = pNewBuf;
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pAuthRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthRespCharDataHandler(
|
||||
IN AuthRespParse *pAuthRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AuthRespCharDataHandler- Start\n", 0);
|
||||
|
||||
// Just exit if being called to process white space
|
||||
if (*s == '\n' || *s == '\r' || *s == '\t' || *s == ' ')
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthRespParse->state)
|
||||
{
|
||||
case AWAITING_DESCRIPTION_DATA:
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// Ignore the status description data for now.
|
||||
// tbd
|
||||
|
||||
// Advanced to the next state
|
||||
pAuthRespParse->state = AWAITING_DESCRIPTION_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_DATA:
|
||||
|
||||
// Set the appropriate status in the AuthenticationResp based on the
|
||||
// returned status.
|
||||
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pAuthRespParse->status = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_AUTHENTICATION_FAILURE);
|
||||
}
|
||||
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_CONFIGURATION_ERROR);
|
||||
}
|
||||
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_SERVER_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespCharDataHandler- Un-expected status\n", 0);
|
||||
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Advanced to the next state
|
||||
pAuthRespParse->state = AWAITING_STATUS_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_DATA:
|
||||
|
||||
// Convert the lifetime string to a numeric value
|
||||
pAuthRespParse->pAuthenticateResp->tokenLifetime = dtoul(s, len);
|
||||
|
||||
// Advanced to the next state
|
||||
pAuthRespParse->state = AWAITING_LIFETIME_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_SESSION_TOKEN_DATA:
|
||||
case AWAITING_SESSION_TOKEN_ELEMENT_END:
|
||||
|
||||
// Consume the data
|
||||
pAuthRespParse->status = ConsumeElementData(pAuthRespParse,
|
||||
s,
|
||||
len,
|
||||
&pAuthRespParse->pAuthenticateResp->pToken,
|
||||
&pAuthRespParse->pAuthenticateResp->tokenLen);
|
||||
if (CASA_SUCCESS(pAuthRespParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthRespCharDataHandler- Un-expected state = %d\n", pAuthRespParse->state);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(2, "-AuthRespCharDataHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthRespEndElementHandler(
|
||||
IN AuthRespParse *pAuthRespParse,
|
||||
IN const XML_Char *name)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AuthRespEndElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Authentication
|
||||
// Response Element.
|
||||
if (strcmp(name, AUTH_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Done.
|
||||
pAuthRespParse->state = DONE_PARSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespEndHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_STATUS_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state based on the status code.
|
||||
if (CASA_SUCCESS(pAuthRespParse->status))
|
||||
{
|
||||
// The request completed successfully
|
||||
pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
pAuthRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Lifetime Element.
|
||||
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_SESSION_TOKEN_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_SESSION_TOKEN_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Session Token Element.
|
||||
if (strcmp(name, SESSION_TOKEN_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected state = %d\n", pAuthRespParse->state);
|
||||
XML_StopParser(pAuthRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-AuthRespEndElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateAuthenticateResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT AuthenticateResp **ppAuthenticateResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
AuthRespParse authRespParse = {0};
|
||||
AuthenticateResp *pAuthenticateResp;
|
||||
|
||||
DbgTrace(1, "-CreateAuthenticateResp- Start\n", 0);
|
||||
|
||||
/*
|
||||
* When an authentication request is processed successfully, the server replies to
|
||||
* the client with a message with the following format:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_resp>
|
||||
* <status><description>ok</description>200</status>
|
||||
* <session_token><lifetime>lifetime value</lifetime>session token data</session_token>
|
||||
* </auth_resp>
|
||||
*
|
||||
* When an authentication request fails to be successfully processed, the server
|
||||
* responds with an error and an error description string. The message format of
|
||||
* an unsuccessful reply is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </auth_resp>
|
||||
*
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allocate AuthenticateResp object
|
||||
pAuthenticateResp = malloc(sizeof(*pAuthenticateResp));
|
||||
if (pAuthenticateResp)
|
||||
{
|
||||
XML_Parser p;
|
||||
|
||||
// Initialize the AuthenticateResp object and set it in the
|
||||
// authentication response parse oject.
|
||||
memset(pAuthenticateResp, 0, sizeof(*pAuthenticateResp));
|
||||
authRespParse.pAuthenticateResp = pAuthenticateResp;
|
||||
|
||||
// Create parser
|
||||
p = XML_ParserCreate(NULL);
|
||||
if (p)
|
||||
{
|
||||
// Keep track of the parser in our parse object
|
||||
authRespParse.p = p;
|
||||
|
||||
// Initialize the status within the parse object
|
||||
authRespParse.status = CASA_STATUS_SUCCESS;
|
||||
|
||||
// Set the start and end element handlers
|
||||
XML_SetElementHandler(p,
|
||||
(XML_StartElementHandler) AuthRespStartElementHandler,
|
||||
(XML_EndElementHandler) AuthRespEndElementHandler);
|
||||
|
||||
// Set the character data handler
|
||||
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) AuthRespCharDataHandler);
|
||||
|
||||
|
||||
// Set our user data
|
||||
XML_SetUserData(p, &authRespParse);
|
||||
|
||||
// Parse the document
|
||||
if (XML_Parse(p, pRespMsg, respLen, 1) == XML_STATUS_OK)
|
||||
{
|
||||
// Verify that the parse operation completed successfully
|
||||
if (authRespParse.state == DONE_PARSING)
|
||||
{
|
||||
// The parse operation succeded, obtain the status returned
|
||||
// by the server.
|
||||
retStatus = authRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthenticateResp- Parse operation did not complete\n", 0);
|
||||
|
||||
// Check if a status has been recorded
|
||||
if (authRespParse.status != CASA_STATUS_SUCCESS)
|
||||
{
|
||||
retStatus = authRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthenticateResp- Parse error %d\n", XML_GetErrorCode(p));
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
// Free the parser
|
||||
XML_ParserFree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthenticateResp- Parser creation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Return the AuthenticationResp object to the caller if necessary
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
*ppAuthenticateResp = pAuthenticateResp;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(pAuthenticateResp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthenticateResp- Memory allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateAuthenticateResp- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
RelAuthenticateResp(
|
||||
IN AuthenticateResp *pAuthenticateResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-RelAuthenticateResp- Start\n", 0);
|
||||
|
||||
// Free the resources associated with the object
|
||||
if (pAuthenticateResp->pToken)
|
||||
free(pAuthenticateResp->pToken);
|
||||
|
||||
free(pAuthenticateResp);
|
||||
|
||||
DbgTrace(1, "-RelAuthenticateResp- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
804
CASA-auth-token/client/core/authpolicy.c
Normal file
804
CASA-auth-token/client/core/authpolicy.c
Normal file
@@ -0,0 +1,804 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Parse states
|
||||
//
|
||||
#define AWAITING_ROOT_ELEMENT_START 0x0
|
||||
#define AWAITING_ROOT_ELEMENT_END 0x1
|
||||
#define AWAITING_AUTH_POLICY_ELEMENT_START 0x2
|
||||
#define AWAITING_AUTH_POLICY_ELEMENT_END 0x3
|
||||
#define AWAITING_AUTH_POLICY_DATA 0x4
|
||||
#define AWAITING_AUTH_SOURCE_ELEMENT_START 0x5
|
||||
#define AWAITING_AUTH_SOURCE_ELEMENT_END 0x6
|
||||
#define AWAITING_AUTH_SOURCE_CHILD_START 0x7
|
||||
#define AWAITING_REALM_DATA 0x8
|
||||
#define AWAITING_REALM_ELEMENT_END 0x9
|
||||
#define AWAITING_MECHANISM_DATA 0xA
|
||||
#define AWAITING_MECHANISM_ELEMENT_END 0xB
|
||||
#define AWAITING_MECHANISM_INFO_DATA 0xC
|
||||
#define AWAITING_MECHANISM_INFO_ELEMENT_END 0xD
|
||||
#define AWAITING_UNKNOWN_DATA 0xE
|
||||
#define AWAITING_UNKNOWN_ELEMENT_END 0xF
|
||||
#define DONE_PARSING 0x10
|
||||
|
||||
//
|
||||
// Authentication Policy Parse Structure
|
||||
//
|
||||
typedef struct _AuthPolicyParse
|
||||
{
|
||||
XML_Parser p;
|
||||
int state;
|
||||
int elementDataProcessed;
|
||||
AuthPolicy *pAuthPolicy;
|
||||
CasaStatus status;
|
||||
|
||||
} AuthPolicyParse, *PAuthPolicyParse;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthPolicyStartElementHandler(
|
||||
IN AuthPolicyParse *pAuthPolicyParse,
|
||||
IN const XML_Char *name,
|
||||
IN const XML_Char **atts)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AuthPolicyStartElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthPolicyParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Authentication
|
||||
// Policy Element.
|
||||
if (strcmp(name, AUTH_POLICY_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_SOURCE_ELEMENT_START:
|
||||
case AWAITING_ROOT_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the start of an Authentication
|
||||
// Source Element.
|
||||
if (strcmp(name, AUTH_SOURCE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
// Create an authentication context structure
|
||||
pAuthContext = (AuthContext*) malloc(sizeof(AuthContext));
|
||||
if (pAuthContext)
|
||||
{
|
||||
// Initialize the allocated AuthContext structure and associate it
|
||||
// with the AuthPolicy structure.
|
||||
memset(pAuthContext, 0, sizeof(*pAuthContext));
|
||||
InsertTailList(&pAuthPolicyParse->pAuthPolicy->authContextListHead, &pAuthContext->listEntry);
|
||||
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_CHILD_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyStartElementHandler- Buffer allocation error\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_SOURCE_CHILD_START:
|
||||
|
||||
// Proceed based on the name of the element
|
||||
if (strcmp(name, REALM_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_REALM_DATA;
|
||||
}
|
||||
else if (strcmp(name, MECHANISM_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_MECHANISM_DATA;
|
||||
}
|
||||
else if (strcmp(name, MECHANISM_INFO_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_MECHANISM_INFO_DATA;
|
||||
}
|
||||
else if (strcmp(name, AUTH_SOURCE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// We are starting a new auth source entry, create an authentication
|
||||
// context structure to hold its information.
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
// Create an authentication context structure
|
||||
pAuthContext = (AuthContext*) malloc(sizeof(AuthContext));
|
||||
if (pAuthContext)
|
||||
{
|
||||
// Initialize the allocated AuthContext structure and associate it
|
||||
// with the AuthPolicy structure.
|
||||
memset(pAuthContext, 0, sizeof(*pAuthContext));
|
||||
InsertTailList(&pAuthPolicyParse->pAuthPolicy->authContextListHead, &pAuthContext->listEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyStartElementHandler- Buffer allocation error\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_UNKNOWN_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected state = %d\n", pAuthPolicyParse->state);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-AuthPolicyStartElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ConsumeElementData(
|
||||
IN AuthPolicyParse *pAuthPolicyParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len,
|
||||
INOUT char **ppElementData,
|
||||
INOUT int *pElementDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- Start\n", 0);
|
||||
|
||||
// Proceed based on whether or not we have already consumed data
|
||||
// for this element.
|
||||
if (*ppElementData == NULL)
|
||||
{
|
||||
// We have not yet consumed data for this element
|
||||
pAuthPolicyParse->elementDataProcessed = len;
|
||||
|
||||
// Allocate a buffer to hold this element data (null terminated).
|
||||
*ppElementData = (char*) malloc(len + 1);
|
||||
if (*ppElementData)
|
||||
{
|
||||
memset(*ppElementData, 0, len + 1);
|
||||
memcpy(*ppElementData, s, len);
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pAuthPolicyParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pNewBuf;
|
||||
|
||||
// We have already received token data, append this data to it.
|
||||
pNewBuf = (char*) malloc(pAuthPolicyParse->elementDataProcessed + len + 1);
|
||||
if (pNewBuf)
|
||||
{
|
||||
memset(pNewBuf,
|
||||
0,
|
||||
pAuthPolicyParse->elementDataProcessed + len + 1);
|
||||
memcpy(pNewBuf,
|
||||
*ppElementData,
|
||||
pAuthPolicyParse->elementDataProcessed);
|
||||
memcpy(pNewBuf + pAuthPolicyParse->elementDataProcessed, s, len);
|
||||
pAuthPolicyParse->elementDataProcessed += len;
|
||||
|
||||
// Swap the buffers
|
||||
free(*ppElementData);
|
||||
*ppElementData = pNewBuf;
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pAuthPolicyParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthPolicyCharDataHandler(
|
||||
IN AuthPolicyParse *pAuthPolicyParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
DbgTrace(2, "-AuthPolicyCharDataHandler- Start\n", 0);
|
||||
|
||||
// Just exit if being called to process white space
|
||||
if (*s == '\n' || *s == '\r' || *s == '\t' || *s == ' ')
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthPolicyParse->state)
|
||||
{
|
||||
case AWAITING_REALM_DATA:
|
||||
|
||||
// Get access to the AuthContext at the tail of the list
|
||||
pAuthContext = CONTAINING_RECORD(pAuthPolicyParse->pAuthPolicy->authContextListHead.Blink,
|
||||
AuthContext,
|
||||
listEntry);
|
||||
|
||||
// Consume the data
|
||||
pAuthPolicyParse->status = ConsumeElementData(pAuthPolicyParse,
|
||||
s,
|
||||
len,
|
||||
&pAuthContext->pContext,
|
||||
&pAuthContext->contextLen);
|
||||
if (CASA_SUCCESS(pAuthPolicyParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pAuthPolicyParse->state = AWAITING_REALM_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_MECHANISM_DATA:
|
||||
case AWAITING_MECHANISM_ELEMENT_END:
|
||||
|
||||
// Get access to the AuthContext at the tail of the list
|
||||
pAuthContext = CONTAINING_RECORD(pAuthPolicyParse->pAuthPolicy->authContextListHead.Blink,
|
||||
AuthContext,
|
||||
listEntry);
|
||||
|
||||
// Consume the data
|
||||
pAuthPolicyParse->status = ConsumeElementData(pAuthPolicyParse,
|
||||
s,
|
||||
len,
|
||||
&pAuthContext->pMechanism,
|
||||
&pAuthContext->mechanismLen);
|
||||
if (CASA_SUCCESS(pAuthPolicyParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pAuthPolicyParse->state = AWAITING_MECHANISM_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_MECHANISM_INFO_DATA:
|
||||
case AWAITING_MECHANISM_INFO_ELEMENT_END:
|
||||
|
||||
// Get access to the AuthContext at the tail of the list
|
||||
pAuthContext = CONTAINING_RECORD(pAuthPolicyParse->pAuthPolicy->authContextListHead.Blink,
|
||||
AuthContext,
|
||||
listEntry);
|
||||
|
||||
// Consume the data
|
||||
pAuthPolicyParse->status = ConsumeElementData(pAuthPolicyParse,
|
||||
s,
|
||||
len,
|
||||
&pAuthContext->pMechInfo,
|
||||
&pAuthContext->mechInfoLen);
|
||||
if (CASA_SUCCESS(pAuthPolicyParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pAuthPolicyParse->state = AWAITING_MECHANISM_INFO_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_UNKNOWN_DATA:
|
||||
case AWAITING_UNKNOWN_ELEMENT_END:
|
||||
|
||||
// Just advance the state
|
||||
pAuthPolicyParse->state = AWAITING_UNKNOWN_ELEMENT_END;
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthPolicyCharDataHandler- Un-expected state = %d\n", pAuthPolicyParse->state);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(2, "-AuthPolicyCharDataHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
AuthPolicyEndElementHandler(
|
||||
IN AuthPolicyParse *pAuthPolicyParse,
|
||||
IN const XML_Char *name)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
DbgTrace(2, "-AuthPolicyEndElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pAuthPolicyParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Authentication
|
||||
// Policy Element.
|
||||
if (strcmp(name, AUTH_POLICY_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Done.
|
||||
pAuthPolicyParse->state = DONE_PARSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_SOURCE_CHILD_START:
|
||||
|
||||
// In this state, we are only expecting the Authentication
|
||||
// Source Response Element.
|
||||
if (strcmp(name, AUTH_SOURCE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_REALM_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Realm Element.
|
||||
if (strcmp(name, REALM_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_CHILD_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_MECHANISM_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Mechanism Element.
|
||||
if (strcmp(name, MECHANISM_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_CHILD_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_MECHANISM_INFO_DATA:
|
||||
|
||||
// Get access to the AuthContext at the tail of the list
|
||||
pAuthContext = CONTAINING_RECORD(pAuthPolicyParse->pAuthPolicy->authContextListHead.Blink,
|
||||
AuthContext,
|
||||
listEntry);
|
||||
|
||||
// There was no mechanism info data. Set it to an empty string.
|
||||
pAuthContext->pMechInfo = (char*) malloc(1);
|
||||
if (pAuthContext->pMechInfo)
|
||||
{
|
||||
*pAuthContext->pMechInfo = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Buffer allocation failure\n", 0);
|
||||
pAuthPolicyParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
// Fall through
|
||||
|
||||
case AWAITING_MECHANISM_INFO_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Mechanism Info Element.
|
||||
if (strcmp(name, MECHANISM_INFO_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_CHILD_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_UNKNOWN_ELEMENT_END:
|
||||
|
||||
// Advance to the next state.
|
||||
pAuthPolicyParse->state = AWAITING_AUTH_SOURCE_CHILD_START;
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected state = %d\n", pAuthPolicyParse->state);
|
||||
XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-AuthPolicyEndElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateAuthPolicy(
|
||||
IN char *pEncodedData,
|
||||
IN int encodedDataLen,
|
||||
INOUT AuthPolicy **ppAuthPolicy)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
AuthPolicy *pAuthPolicy = NULL;
|
||||
AuthPolicyParse authPolicyParse = {0};
|
||||
char *pData = NULL;
|
||||
int dataLen = 0;
|
||||
|
||||
DbgTrace(1, "-CreateAuthPolicy- Start\n", 0);
|
||||
|
||||
/*
|
||||
* An authentication policy document has the following format:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_policy>
|
||||
* <auth_source>
|
||||
* <realm>realm name</realm>
|
||||
* <mechanism>authentication mechanism type</mechanism>
|
||||
* <mechanism_info>authentication mechanism context data</mechanism_info>
|
||||
* </auth_source>
|
||||
* ...
|
||||
* </auth_policy>
|
||||
*
|
||||
* The authentication policy document can contain multiple auth_source
|
||||
* elements. These auth_source elements can be for different authentication
|
||||
* sources or for the same authentication source but specifying a different
|
||||
* authentication mechanism. The mechanism_info element is optional.
|
||||
*
|
||||
* The following is a sample authentication policy document:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_policy>
|
||||
* <auth_source>
|
||||
* <realm>Corp_eDirTree</realm>
|
||||
* <mechanism>Krb5Authenticate</mechanism>
|
||||
* <mechanism_info>host/hostname</mechanism_info>
|
||||
* </auth_source>
|
||||
* <auth_source>
|
||||
* <realm>Corp_eDirTree</realm>
|
||||
* <mechanism>PwdAuthenticate</mechanism>
|
||||
* <mechanism_info></mechanism_info>
|
||||
* </auth_source>
|
||||
* </auth_policy>
|
||||
*
|
||||
* This authentication policy would tell the CASA client that it can
|
||||
* authenticate to the CASA Authentication Token Service using
|
||||
* credentials for the Corp_eDirTree and utilizing either the
|
||||
* Krb5 authentication mechanism or the Pwd authentication mechanism.
|
||||
* The Krb5 authentication mechanism context data specifies the
|
||||
* name of the Kerberos service principal.
|
||||
*
|
||||
*/
|
||||
|
||||
// Initialize output parameter
|
||||
*ppAuthPolicy = NULL;
|
||||
|
||||
// Decode the data
|
||||
retStatus = DecodeData(pEncodedData,
|
||||
encodedDataLen,
|
||||
(void**) &pData,
|
||||
&dataLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Allocate space for the AuthPolicy structure
|
||||
pAuthPolicy = (AuthPolicy*) malloc(sizeof(*pAuthPolicy));
|
||||
if (pAuthPolicy)
|
||||
{
|
||||
XML_Parser p;
|
||||
|
||||
// Initialize the AuthPolicy object
|
||||
memset(pAuthPolicy, 0, sizeof(*pAuthPolicy));
|
||||
InitializeListHead(&pAuthPolicy->authContextListHead);
|
||||
|
||||
// Set the AuthPolicy object in the parse object
|
||||
authPolicyParse.pAuthPolicy = pAuthPolicy;
|
||||
|
||||
// Create parser
|
||||
p = XML_ParserCreate(NULL);
|
||||
if (p)
|
||||
{
|
||||
// Keep track of the parser in our parse object
|
||||
authPolicyParse.p = p;
|
||||
|
||||
// Initialize the status within the parse object
|
||||
authPolicyParse.status = CASA_STATUS_SUCCESS;
|
||||
|
||||
// Set the start and end element handlers
|
||||
XML_SetElementHandler(p,
|
||||
(XML_StartElementHandler) AuthPolicyStartElementHandler,
|
||||
(XML_EndElementHandler) AuthPolicyEndElementHandler);
|
||||
|
||||
// Set the character data handler
|
||||
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) AuthPolicyCharDataHandler);
|
||||
|
||||
// Set our user data
|
||||
XML_SetUserData(p, &authPolicyParse);
|
||||
|
||||
// Parse the document
|
||||
if (XML_Parse(p, pData, dataLen, 1) == XML_STATUS_OK)
|
||||
{
|
||||
// Verify that the parse operation completed successfully
|
||||
if (authPolicyParse.state == DONE_PARSING)
|
||||
{
|
||||
// The parse operation succeded
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthPolicy- Parse operation did not complete\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthPolicy- Parse error %d\n", XML_GetErrorCode(p));
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
// Free the parser
|
||||
XML_ParserFree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthPolicy- Parser creation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Return the AuthPolicy object to the caller if necessary
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
*ppAuthPolicy = pAuthPolicy;
|
||||
|
||||
// Forget about the AuthPolicy object so that it is not release down below
|
||||
pAuthPolicy = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthPolicy- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateAuthPolicy- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Release necessary allocated resources
|
||||
if (pAuthPolicy)
|
||||
RelAuthPolicy(pAuthPolicy);
|
||||
|
||||
if (pData)
|
||||
free(pData);
|
||||
|
||||
DbgTrace(1, "-CreateAuthPolicy- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
RelAuthPolicy(
|
||||
IN AuthPolicy *pAuthPolicy)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
LIST_ENTRY *pListEntry;
|
||||
|
||||
DbgTrace(1, "-RelAuthPolicy- Start\n", 0);
|
||||
|
||||
// Free all of the associated AuthContexts
|
||||
pListEntry = pAuthPolicy->authContextListHead.Flink;
|
||||
while (pListEntry != &pAuthPolicy->authContextListHead)
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
// Get pointer to AuthContext structure
|
||||
pAuthContext = CONTAINING_RECORD(pListEntry, AuthContext, listEntry);
|
||||
|
||||
// Free associated buffers
|
||||
if (pAuthContext->pContext)
|
||||
free(pAuthContext->pContext);
|
||||
|
||||
if (pAuthContext->pMechanism)
|
||||
free(pAuthContext->pMechanism);
|
||||
|
||||
if (pAuthContext->pMechInfo)
|
||||
free(pAuthContext->pMechInfo);
|
||||
|
||||
// Remove the entry from the list
|
||||
RemoveEntryList(&pAuthContext->listEntry);
|
||||
|
||||
// Free the AuthContext
|
||||
free(pAuthContext);
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pAuthPolicy->authContextListHead.Flink;
|
||||
}
|
||||
|
||||
// Free the AuthPolicy
|
||||
free(pAuthPolicy);
|
||||
|
||||
DbgTrace(1, "-RelAuthPolicy- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
588
CASA-auth-token/client/core/cache.c
Normal file
588
CASA-auth-token/client/core/cache.c
Normal file
@@ -0,0 +1,588 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
#include <micasa.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
HANDLE g_hCASAContext;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
AuthCacheEntry*
|
||||
CreateAuthTokenCacheEntry(
|
||||
IN const char *pCacheKey,
|
||||
IN const char *pGroupOrHostName,
|
||||
IN CasaStatus status,
|
||||
IN char *pToken,
|
||||
IN int entryLifetime, // seconds (0 == Lives forever)
|
||||
IN void *pCredStoreScope
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
|
||||
SSCS_SECRET_ID_T sharedId = {27, "CASA_AUTHENTICATION_TOKENS"};
|
||||
int32_t tokenSize, entrySize, keySize;
|
||||
AuthCacheEntry *pEntry = NULL;
|
||||
char *pKey;
|
||||
|
||||
DbgTrace(1, "-CreateAuthTokenCacheEntry- Start\n", 0);
|
||||
|
||||
if (status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
tokenSize = (uint32_t) strlen(pToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenSize = 0;
|
||||
}
|
||||
|
||||
entrySize = tokenSize + sizeof(AuthCacheEntry);
|
||||
|
||||
// Allocate space for the entry
|
||||
// The AuthCacheEntry structure contains room for the tokens NULL terminator
|
||||
pEntry = (AuthCacheEntry*) malloc(entrySize);
|
||||
if (pEntry)
|
||||
{
|
||||
// Set the status
|
||||
pEntry->status = status;
|
||||
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
memcpy(&pEntry->token[0], pToken, tokenSize);
|
||||
}
|
||||
|
||||
pEntry->token[tokenSize] = '\0';
|
||||
|
||||
// Set the time when the entry was added to the cache
|
||||
pEntry->creationTime = GetTickCount();
|
||||
|
||||
// First determine the time when the entry is due to expire
|
||||
if (entryLifetime != 0)
|
||||
{
|
||||
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000);
|
||||
pEntry->doesNotExpire = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entry does not expire
|
||||
pEntry->expirationTime = 0;
|
||||
pEntry->doesNotExpire = true;
|
||||
}
|
||||
|
||||
keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2;
|
||||
|
||||
pKey = malloc(keySize);
|
||||
|
||||
if (pKey)
|
||||
{
|
||||
strncpy(pKey, pCacheKey, keySize);
|
||||
strncat(pKey, "@", keySize);
|
||||
strncat(pKey, pGroupOrHostName, keySize);
|
||||
|
||||
retStatus = miCASAWriteBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pKey,
|
||||
keySize,
|
||||
(uint8_t *) pEntry,
|
||||
(uint32_t*) &entrySize,
|
||||
NULL,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
|
||||
|
||||
free(pKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateAuthTokenCacheEntry- End, pEntry = %0lX\n", (long) pEntry);
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
AuthCacheEntry*
|
||||
CreateSessionTokenCacheEntry(
|
||||
IN const char *pCacheKey,
|
||||
IN CasaStatus status,
|
||||
IN char *pToken,
|
||||
IN int entryLifetime, // seconds (0 == Lives forever)
|
||||
IN void *pCredStoreScope
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
|
||||
SSCS_SECRET_ID_T sharedId = {20, "CASA_SESSION_TOKENS"};
|
||||
int32_t tokenSize, entrySize;
|
||||
AuthCacheEntry *pEntry = NULL;
|
||||
|
||||
DbgTrace(1, "-CreateSessionTokenCacheEntry- Start\n", 0);
|
||||
|
||||
if (status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
tokenSize = (uint32_t)strlen(pToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenSize = 0;
|
||||
}
|
||||
|
||||
entrySize = tokenSize + sizeof(AuthCacheEntry);
|
||||
|
||||
// Allocate space for the entry
|
||||
// The AuthCacheEntry structure contains room for the tokens NULL terminator
|
||||
pEntry = (AuthCacheEntry*) malloc(entrySize);
|
||||
if (pEntry)
|
||||
{
|
||||
// Set the status
|
||||
pEntry->status = status;
|
||||
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
memcpy(&pEntry->token[0], pToken, tokenSize);
|
||||
}
|
||||
|
||||
pEntry->token[tokenSize] = '\0';
|
||||
|
||||
// Set the time when the entry was added to the cache
|
||||
pEntry->creationTime = GetTickCount();
|
||||
|
||||
// First determine the time when the entry is due to expire
|
||||
if (entryLifetime != 0)
|
||||
{
|
||||
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000);
|
||||
pEntry->doesNotExpire = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entry does not expire
|
||||
pEntry->expirationTime = 0;
|
||||
pEntry->doesNotExpire = true;
|
||||
}
|
||||
|
||||
retStatus = miCASAWriteBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pCacheKey,
|
||||
(uint32_t) strlen(pCacheKey) + 1,
|
||||
(uint8_t *) pEntry,
|
||||
(uint32_t*) &entrySize,
|
||||
NULL,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateSessionTokenCacheEntry- End, pEntry = %0lX\n", (long) pEntry);
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
FreeAuthCacheEntry(
|
||||
IN AuthCacheEntry *pEntry
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-FreeAuthCacheEntry- Start, pEntry = %0lX\n", (long) pEntry);
|
||||
|
||||
// Free the entry
|
||||
free(pEntry);
|
||||
|
||||
DbgTrace(1, "-FreeAuthCacheEntry- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
bool
|
||||
CacheEntryLifetimeExpired(
|
||||
IN DWORD creationTime,
|
||||
IN DWORD expirationTime
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DWORD currentTime = GetTickCount();
|
||||
bool expired = false;
|
||||
|
||||
DbgTrace(2, "-CacheEntryLifetimeExpired- Start\n", 0);
|
||||
|
||||
// Check if the clock has wrapped
|
||||
if (currentTime >= creationTime)
|
||||
{
|
||||
// The clock has not wrapped, check if the
|
||||
// expiration time has wrapped.
|
||||
if (expirationTime > creationTime)
|
||||
{
|
||||
// The expiration time also has not wrapped,
|
||||
// do a straight compare against the current
|
||||
// time.
|
||||
if (currentTime >= expirationTime)
|
||||
{
|
||||
// It has expired
|
||||
expired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The clock has wrapped, check if the expiration
|
||||
// time also wrapped.
|
||||
if (expirationTime > creationTime)
|
||||
{
|
||||
// The expiration time did not wrap, therefore
|
||||
// it has been exceeded since the clock wrapped.
|
||||
expired = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The expiration time also wrapped, do a straight
|
||||
// compare against the current time.
|
||||
if (currentTime >= expirationTime)
|
||||
{
|
||||
// It has expired
|
||||
expired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(2, "-CacheEntryLifetimeExpired- End, result = %08X\n", expired);
|
||||
|
||||
return expired;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
AuthCacheEntry*
|
||||
FindSessionTokenEntryInCache(
|
||||
IN const char *pCacheKey,
|
||||
IN void *pCredStoreScope
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
|
||||
SSCS_SECRET_ID_T sharedId = {20, "CASA_SESSION_TOKENS"};
|
||||
int32_t valueLength, bytesRequired;
|
||||
AuthCacheEntry *pEntry = NULL;
|
||||
|
||||
|
||||
DbgTrace(1, "-FindSessionTokenEntryInCache- Start\n", 0);
|
||||
|
||||
valueLength = 0;
|
||||
bytesRequired = 0;
|
||||
|
||||
retStatus = miCASAReadBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pCacheKey,
|
||||
(uint32_t) strlen(pCacheKey) + 1,
|
||||
NULL,
|
||||
(uint32_t*) &valueLength,
|
||||
(SSCS_PASSWORD_T*) NULL,
|
||||
(uint32_t*) &bytesRequired,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
|
||||
if (retStatus == NSSCS_E_ENUM_BUFF_TOO_SHORT
|
||||
&& bytesRequired != 0)
|
||||
{
|
||||
pEntry = (AuthCacheEntry*) malloc(bytesRequired);
|
||||
|
||||
if (pEntry)
|
||||
{
|
||||
valueLength = bytesRequired;
|
||||
bytesRequired = 0;
|
||||
|
||||
retStatus = miCASAReadBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pCacheKey,
|
||||
(uint32_t) strlen(pCacheKey) + 1,
|
||||
(uint8_t *) pEntry,
|
||||
(uint32_t*) &valueLength,
|
||||
(SSCS_PASSWORD_T*) NULL,
|
||||
(uint32_t*) &bytesRequired,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
if (pEntry->doesNotExpire == false
|
||||
&& CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime))
|
||||
{
|
||||
// Remove the entry ???
|
||||
//miCASARemoveBinaryKey();
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
FreeAuthCacheEntry(pEntry);
|
||||
pEntry = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(1, "-FindSessionTokenEntryInCache- End, pEntry = %0lX\n", (long) pEntry);
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
//++=======================================================================
|
||||
AuthCacheEntry*
|
||||
FindAuthTokenEntryInCache(
|
||||
IN const char *pCacheKey,
|
||||
IN const char *pGroupOrHostName,
|
||||
IN void *pCredStoreScope
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
SSCS_KEYCHAIN_ID_T sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"};
|
||||
SSCS_SECRET_ID_T sharedId = {27, "CASA_AUTHENTICATION_TOKENS"};
|
||||
int32_t valueLength, bytesRequired, keySize;
|
||||
AuthCacheEntry *pEntry = NULL;
|
||||
char *pKey;
|
||||
|
||||
|
||||
DbgTrace(1, "-FindAuthTokenEntryInCache- Start\n", 0);
|
||||
|
||||
keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2;
|
||||
|
||||
pKey = malloc(keySize);
|
||||
if (pKey)
|
||||
{
|
||||
strncpy(pKey, pCacheKey, keySize);
|
||||
strncat(pKey, "@", keySize);
|
||||
strncat(pKey, pGroupOrHostName, keySize);
|
||||
|
||||
valueLength = 0;
|
||||
bytesRequired = 0;
|
||||
|
||||
retStatus = miCASAReadBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pKey,
|
||||
keySize,
|
||||
NULL,
|
||||
(uint32_t*) &valueLength,
|
||||
(SSCS_PASSWORD_T*) NULL,
|
||||
(uint32_t*) &bytesRequired,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
|
||||
if (retStatus == NSSCS_E_ENUM_BUFF_TOO_SHORT
|
||||
&& bytesRequired != 0)
|
||||
{
|
||||
pEntry = (AuthCacheEntry*) malloc(bytesRequired);
|
||||
|
||||
if (pEntry)
|
||||
{
|
||||
valueLength = bytesRequired;
|
||||
bytesRequired = 0;
|
||||
|
||||
retStatus = miCASAReadBinaryKey(g_hCASAContext,
|
||||
0,
|
||||
&sessionKeyChain,
|
||||
&sharedId,
|
||||
(SS_UTF8_T*) pKey,
|
||||
keySize,
|
||||
(uint8_t *) pEntry,
|
||||
(uint32_t*) &valueLength,
|
||||
(SSCS_PASSWORD_T*) NULL,
|
||||
(uint32_t*) &bytesRequired,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
if (pEntry->doesNotExpire == false
|
||||
&& CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime))
|
||||
{
|
||||
// Remove the entry ???
|
||||
//miCASARemoveBinaryKey();
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
FreeAuthCacheEntry(pEntry);
|
||||
pEntry = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(pKey);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-FindAuthTokenEntryInCache- End, pEntry = %0lX\n", (long) pEntry);
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
InitializeAuthCache()
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
SSCS_SECRETSTORE_T ssId;
|
||||
|
||||
DbgTrace(1, "-InitializeAuthCache- Start\n", 0);
|
||||
|
||||
ssId.version = NSSCS_VERSION_NUMBER;
|
||||
strcpy((char *)ssId.ssName, (char *)SSCS_DEFAULT_SECRETSTORE_ID);
|
||||
|
||||
g_hCASAContext = miCASAOpenSecretStoreCache(&ssId,
|
||||
0,
|
||||
NULL);
|
||||
if (!g_hCASAContext)
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InitializeAuthCache- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
88
CASA-auth-token/client/core/client.conf
Normal file
88
CASA-auth-token/client/core/client.conf
Normal file
@@ -0,0 +1,88 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for client. #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
#
|
||||
# ATS-hostname setting.
|
||||
#
|
||||
# Description: Used to configure the address of the
|
||||
# ATS that should be used for obtaining
|
||||
# authentication tokens.
|
||||
#
|
||||
# If this parameter is not set, the client
|
||||
# assummes that the ATS resides in the same
|
||||
# host as the authentication token consuming
|
||||
# services.
|
||||
#
|
||||
#ATS-hostname hostname or IP address
|
||||
|
||||
#
|
||||
# ATS-port setting.
|
||||
#
|
||||
# Description: Used to configure the port utilized by the
|
||||
# ATS to listen for connections.
|
||||
#
|
||||
# If this parameter is not set ....
|
||||
#
|
||||
#ATS-port 2645
|
||||
|
||||
#
|
||||
# DisableSecureConnections setting.
|
||||
#
|
||||
# Description: Used to disable the use of secure connections (SSL) between
|
||||
# the Client and ATSs.
|
||||
#
|
||||
# If this parameter is not set to true, the client
|
||||
# defaults to communicating securedly with ATSs.
|
||||
#
|
||||
# Security Note: Disabling secure connections allows
|
||||
# malicious users/processes to view confidential
|
||||
# information such as username/passwords and to tamper
|
||||
# with client-ATS communications without being detected.
|
||||
# You should not disable secure connections unless you are
|
||||
# trying to debug the authentication token infrastructure.
|
||||
#
|
||||
#DisableSecureConnections false
|
||||
|
||||
#
|
||||
# AllowInvalidCerts setting.
|
||||
#
|
||||
# Description: Used to specify that the client should ignore
|
||||
# invalid certificates presented by ATSs when
|
||||
# performing SSL communications.
|
||||
#
|
||||
# If this parameter is not set to true, the client defaults
|
||||
# to not ignoring invalid certificates presented by ATSs.
|
||||
# ATSs.
|
||||
#
|
||||
# Security Note: Ignoring invalid certificates downgrades the
|
||||
# security of your infrastructure by allowing a malicious
|
||||
# process to impersonate an ATS and obtain information that
|
||||
# is confidential such as username and passwords.
|
||||
#
|
||||
AllowInvalidCerts true
|
||||
|
||||
#
|
||||
# UsersCannotAllowInvalidCerts setting.
|
||||
#
|
||||
# Description: Used to specify that the client should not allow users to
|
||||
# decide that invalid certificates presented by ATSs should be
|
||||
# ignored.
|
||||
#
|
||||
# If this parameter is not set to true, the client defaults
|
||||
# to allow users to choose whether or not invalid certificates
|
||||
# presented by ATSs.
|
||||
#
|
||||
# If this parameter is set to true then users are not consulted
|
||||
# when an invalid server certificate is received and communications
|
||||
# between the client and the ATS fail.
|
||||
#
|
||||
# Note: This parameter has no effect if the setting AllowInvalidCerts
|
||||
# is set to true.
|
||||
#
|
||||
# THIS FUNCTIONALITY HAS NOT BEEN IMPLEMENTED
|
||||
#
|
||||
#UsersCannotAllowInvalidCerts true
|
||||
686
CASA-auth-token/client/core/config.c
Normal file
686
CASA-auth-token/client/core/config.c
Normal file
@@ -0,0 +1,686 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Config Key object
|
||||
//
|
||||
typedef struct _ConfigKey
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pKeyName;
|
||||
int keyNameLen;
|
||||
char *pValue;
|
||||
int valueLen;
|
||||
|
||||
} ConfigKey, *pConfigKey;
|
||||
|
||||
//
|
||||
// Config Interface instance data
|
||||
//
|
||||
typedef struct _ConfigIfInstance
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
int refCount;
|
||||
char *pConfigFolder;
|
||||
int configFolderLen;
|
||||
char *pConfigName;
|
||||
int configNameLen;
|
||||
LIST_ENTRY configKeyListHead;
|
||||
ConfigIf configIf;
|
||||
|
||||
} ConfigIfInstance, *PConfigIfInstance;
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// ConfigIf variables
|
||||
static
|
||||
LIST_ENTRY g_configIfListHead = {&g_configIfListHead, &g_configIfListHead};
|
||||
|
||||
static
|
||||
int g_numConfigIfObjs = 0;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static void
|
||||
RemoveWhiteSpaceFromTheEnd(
|
||||
IN const char *pInString)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pLineEnd = (char*) pInString + strlen(pInString) - 1;
|
||||
|
||||
|
||||
DbgTrace(3, "-RemoveWhiteSpaceFromTheEnd- Start\n", 0);
|
||||
|
||||
while (pLineEnd != pInString)
|
||||
{
|
||||
if (*pLineEnd == '\n'
|
||||
|| *pLineEnd == ' '
|
||||
|| *pLineEnd == '\t')
|
||||
{
|
||||
// Strike this character
|
||||
*pLineEnd = '\0';
|
||||
pLineEnd --;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Found a non-white character
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-RemoveWhiteSpaceFromTheEnd- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static char*
|
||||
SkipWhiteSpace(
|
||||
IN const char *pInString)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pOutString = (char*) pInString;
|
||||
|
||||
DbgTrace(3, "-SkipWhiteSpace- Start\n", 0);
|
||||
|
||||
while (*pOutString != '\0')
|
||||
{
|
||||
if (*pOutString == '\n'
|
||||
|| *pOutString == ' '
|
||||
|| *pOutString == '\t')
|
||||
{
|
||||
// Skip this character
|
||||
pOutString ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Found a non-white character
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-SkipWhiteSpace- End\n", 0);
|
||||
|
||||
return pOutString;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static char*
|
||||
SkipNonWhiteSpace(
|
||||
IN const char *pInString)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pOutString = (char*) pInString;
|
||||
|
||||
DbgTrace(3, "-SkipNonWhiteSpace- Start\n", 0);
|
||||
|
||||
while (*pOutString != '\0')
|
||||
{
|
||||
if (*pOutString == '\n'
|
||||
|| *pOutString == ' '
|
||||
|| *pOutString == '\t')
|
||||
{
|
||||
// Found a white character
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip this character
|
||||
pOutString ++;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-SkipNonWhiteSpace- End\n", 0);
|
||||
|
||||
return pOutString;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static void
|
||||
LowerCaseString(
|
||||
IN char *pDestString,
|
||||
IN const char *pSrcString)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int i;
|
||||
|
||||
DbgTrace(3, "-LowerCaseString- Start\n", 0);
|
||||
|
||||
// Copy the string as lower case
|
||||
for (i = 0; pSrcString[i] != '\0'; i++)
|
||||
{
|
||||
if (isalpha(pSrcString[i]))
|
||||
pDestString[i] = tolower(pSrcString[i]);
|
||||
else
|
||||
pDestString[i] = pSrcString[i];
|
||||
}
|
||||
|
||||
// Null terminate the destination string
|
||||
pDestString[i] = '\0';
|
||||
|
||||
DbgTrace(3, "-LowerCaseString- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int SSCS_CALL
|
||||
ConfigIf_AddReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Interface reference count.
|
||||
//
|
||||
// Description:
|
||||
// Increases interface reference count.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int refCount;
|
||||
ConfigIfInstance *pConfigIfInstance = CONTAINING_RECORD(pIfInstance, ConfigIfInstance, configIf);
|
||||
|
||||
DbgTrace(2, "-ConfigIf_AddReference- Start\n", 0);
|
||||
|
||||
// Increment the reference count on the object
|
||||
pConfigIfInstance->refCount ++;
|
||||
refCount = pConfigIfInstance->refCount;
|
||||
|
||||
DbgTrace(2, "-ConfigIf_AddReference- End, refCount = %08X\n", refCount);
|
||||
|
||||
return refCount;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void SSCS_CALL
|
||||
ConfigIf_ReleaseReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Nothing.
|
||||
//
|
||||
// Description:
|
||||
// Decreases interface reference count. The interface is deallocated if
|
||||
// the reference count becomes zero.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
bool freeObj = false;
|
||||
ConfigIfInstance *pConfigIfInstance = CONTAINING_RECORD(pIfInstance, ConfigIfInstance, configIf);
|
||||
|
||||
DbgTrace(2, "-ConfigIf_ReleaseReference- Start\n", 0);
|
||||
|
||||
// Decrement the reference count on the object and determine if it needs to
|
||||
// be released.
|
||||
pConfigIfInstance->refCount --;
|
||||
if (pConfigIfInstance->refCount == 0)
|
||||
{
|
||||
// The object needs to be released, forget about it.
|
||||
freeObj = true;
|
||||
g_numConfigIfObjs --;
|
||||
RemoveEntryList(&pConfigIfInstance->listEntry);
|
||||
}
|
||||
|
||||
// Free object if necessary
|
||||
if (freeObj)
|
||||
{
|
||||
// Free all of the config key objects associated with this configuration
|
||||
// interface instance.
|
||||
while (!IsListEmpty(&pConfigIfInstance->configKeyListHead))
|
||||
{
|
||||
LIST_ENTRY *pListEntry;
|
||||
ConfigKey *pConfigKey;
|
||||
|
||||
// Get reference to entry at the head of the list
|
||||
pListEntry = pConfigIfInstance->configKeyListHead.Flink;
|
||||
pConfigKey = CONTAINING_RECORD(pListEntry, ConfigKey, listEntry);
|
||||
|
||||
// Free the buffers associated with the ConfigKey
|
||||
free(pConfigKey->pKeyName);
|
||||
free(pConfigKey->pValue);
|
||||
|
||||
// Remove the entry from the list
|
||||
RemoveEntryList(&pConfigKey->listEntry);
|
||||
|
||||
// Finish freeing the ConfigKey
|
||||
free(pConfigKey);
|
||||
}
|
||||
|
||||
// Free the rest of the buffers associated with the interface instance data
|
||||
free(pConfigIfInstance->pConfigFolder);
|
||||
free(pConfigIfInstance->pConfigName);
|
||||
free(pConfigIfInstance);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-ConfigIf_ReleaseReference- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
char* SSCS_CALL
|
||||
ConfigIf_GetEntryValue(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pKeyName)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pKeyName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the key whose value is being requested.
|
||||
//
|
||||
// Returns:
|
||||
// Pointer to NULL terminated string with value being requested or NULL.
|
||||
//
|
||||
// Description:
|
||||
// Gets value associated with a key for the configuration object.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
ConfigIfInstance *pConfigIfInstance = CONTAINING_RECORD(pIfInstance, ConfigIfInstance, configIf);
|
||||
char *pValue = NULL;
|
||||
LIST_ENTRY *pListEntry;
|
||||
ConfigKey *pConfigKey;
|
||||
int keyNameLen = (int) strlen(pKeyName);
|
||||
char *pKeyNameLowercase;
|
||||
|
||||
DbgTrace(2, "-ConfigIf_GetEntryValue- Start\n", 0);
|
||||
|
||||
// Allocate enough space to hold lower case version of the key name
|
||||
pKeyNameLowercase = (char*) malloc(keyNameLen + 1);
|
||||
if (pKeyNameLowercase)
|
||||
{
|
||||
// Lower case the key name
|
||||
LowerCaseString(pKeyNameLowercase, pKeyName);
|
||||
|
||||
// Try to find matching ConfigKey
|
||||
pListEntry = pConfigIfInstance->configKeyListHead.Flink;
|
||||
while (pListEntry != &pConfigIfInstance->configKeyListHead)
|
||||
{
|
||||
// Get pointer to the current entry
|
||||
pConfigKey = CONTAINING_RECORD(pListEntry, ConfigKey, listEntry);
|
||||
|
||||
// Check if we have a match
|
||||
if (pConfigKey->keyNameLen == keyNameLen
|
||||
&& memcmp(pKeyNameLowercase, pConfigKey->pKeyName, keyNameLen) == 0)
|
||||
{
|
||||
// We found it, return its value.
|
||||
pValue = (char*) malloc(pConfigKey->valueLen + 1);
|
||||
if (pValue)
|
||||
{
|
||||
strcpy(pValue, pConfigKey->pValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConfigIf_GetEntryValue- Buffer allocation failure\n", 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Free the lower case version of the key name
|
||||
free(pKeyNameLowercase);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConfigIf_GetEntryValue- Buffer allocation failure\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-ConfigIf_GetEntryValue- End, pValue = %08X\n", (unsigned int) pValue);
|
||||
|
||||
return pValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
GetConfigInterface(
|
||||
IN const char *pConfigFolder,
|
||||
IN const char *pConfigName,
|
||||
INOUT ConfigIf **ppConfigIf)
|
||||
//
|
||||
// Arguments:
|
||||
// pConfigFolder -
|
||||
// Pointer to NULL terminated string that contains the name of
|
||||
// the folder containing the configuration file.
|
||||
//
|
||||
// pConfigName -
|
||||
// Pointer to NULL terminated string containing the name of the
|
||||
// configuration entry.
|
||||
//
|
||||
// ppConfigIf -
|
||||
// Pointer to variable that will receive pointer to ConfigIf
|
||||
// instance.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get configuration interface to specified configuration entry.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int configFolderLen = (int) strlen(pConfigFolder);
|
||||
int configNameLen = (int)strlen(pConfigName);
|
||||
ConfigIfInstance *pConfigIfInstance;
|
||||
LIST_ENTRY *pListEntry;
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_INFORMATIONAL,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_OBJECT_NOT_FOUND);
|
||||
|
||||
DbgTrace(2, "-GetConfigInterface- Start\n", 0);
|
||||
|
||||
// Check if we already have an entry in our list for the configuration
|
||||
pListEntry = g_configIfListHead.Flink;
|
||||
while (pListEntry != &g_configIfListHead)
|
||||
{
|
||||
// Get pointer to the current entry
|
||||
pConfigIfInstance = CONTAINING_RECORD(pListEntry, ConfigIfInstance, listEntry);
|
||||
|
||||
// Check if we have a match
|
||||
if (pConfigIfInstance->configFolderLen == configFolderLen
|
||||
&& pConfigIfInstance->configNameLen == configNameLen
|
||||
&& memcmp(pConfigFolder, pConfigIfInstance->pConfigFolder, configFolderLen) == 0
|
||||
&& memcmp(pConfigName, pConfigIfInstance->pConfigName, configNameLen) == 0)
|
||||
{
|
||||
// We found it, return the ConfigIf associated with the instance data
|
||||
// after incrementing its reference count.
|
||||
pConfigIfInstance->refCount ++;
|
||||
*ppConfigIf = &pConfigIfInstance->configIf;
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Proceed to create interface instance data for the configuration if none was found
|
||||
if (retStatus != CASA_STATUS_SUCCESS)
|
||||
{
|
||||
char *pFilePath;
|
||||
|
||||
// Build a string containing the configuration file path
|
||||
pFilePath = (char*) malloc(configFolderLen + 1 + configNameLen + sizeof(".conf"));
|
||||
if (pFilePath)
|
||||
{
|
||||
FILE *pConfigFile;
|
||||
|
||||
strcpy(pFilePath, pConfigFolder);
|
||||
strcat(pFilePath, pathCharString);
|
||||
strcat(pFilePath, pConfigName);
|
||||
strcat(pFilePath, ".conf");
|
||||
|
||||
// Open the configuration file for reading
|
||||
pConfigFile = fopen(pFilePath, "r");
|
||||
if (pConfigFile)
|
||||
{
|
||||
// Opened the file, create a ConfigIfInstance object for it.
|
||||
pConfigIfInstance = (ConfigIfInstance*) malloc(sizeof(*pConfigIfInstance));
|
||||
if (pConfigIfInstance)
|
||||
{
|
||||
// Initialize the list head within the instance data
|
||||
InitializeListHead(&pConfigIfInstance->configKeyListHead);
|
||||
|
||||
// Initialize the ConfigIf within the instance data
|
||||
pConfigIfInstance->configIf.addReference = ConfigIf_AddReference;
|
||||
pConfigIfInstance->configIf.releaseReference = ConfigIf_ReleaseReference;
|
||||
pConfigIfInstance->configIf.getEntryValue = ConfigIf_GetEntryValue;
|
||||
|
||||
// Save the ConfigFolder and ConfigName information within the instance data
|
||||
pConfigIfInstance->pConfigFolder = (char*) malloc(configFolderLen + 1);
|
||||
if (pConfigIfInstance->pConfigFolder)
|
||||
{
|
||||
strcpy(pConfigIfInstance->pConfigFolder, pConfigFolder);
|
||||
pConfigIfInstance->configFolderLen = configFolderLen;
|
||||
|
||||
pConfigIfInstance->pConfigName = (char*) malloc(configNameLen + 1);
|
||||
if (pConfigIfInstance->pConfigName)
|
||||
{
|
||||
strcpy(pConfigIfInstance->pConfigName, pConfigName);
|
||||
pConfigIfInstance->configNameLen = configNameLen;
|
||||
|
||||
// Add the instance data into our list and bump up its reference count
|
||||
// since we did that.
|
||||
InsertTailList(&g_configIfListHead, &pConfigIfInstance->listEntry);
|
||||
pConfigIfInstance->refCount = 1;
|
||||
|
||||
// At this point we want to return success to the caller even if we
|
||||
// experience a read error.
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
// Return the ConfigIf associated with the instance data after
|
||||
// incrementing its reference count.
|
||||
pConfigIfInstance->refCount ++;
|
||||
*ppConfigIf = &pConfigIfInstance->configIf;
|
||||
|
||||
// Now update the instance data with the information present in the file
|
||||
if (fseek(pConfigFile, 0, SEEK_SET) == 0)
|
||||
{
|
||||
char line[512];
|
||||
|
||||
while (fgets(line, sizeof(line), pConfigFile) != NULL)
|
||||
{
|
||||
int lineLength;
|
||||
|
||||
RemoveWhiteSpaceFromTheEnd(line);
|
||||
|
||||
lineLength = (int) strlen(line);
|
||||
if (lineLength != 0)
|
||||
{
|
||||
char *pKey;
|
||||
char *pKeyEnd;
|
||||
char *pValue;
|
||||
ConfigKey *pConfigKey;
|
||||
|
||||
// Attempt to find the key
|
||||
pKey = SkipWhiteSpace(line);
|
||||
|
||||
// Make sure that we are not dealing with an empty line or a comment
|
||||
if (*pKey == '\0' || *pKey == '#')
|
||||
continue;
|
||||
|
||||
// Go past the key
|
||||
pKeyEnd = SkipNonWhiteSpace(pKey);
|
||||
|
||||
// Protect against a malformed line
|
||||
if (*pKeyEnd == '\0')
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Attempt to find the value
|
||||
pValue = SkipWhiteSpace(pKeyEnd);
|
||||
|
||||
// Protect against a malformed line
|
||||
if (*pValue == '\0')
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Delineate the key
|
||||
*pKeyEnd = '\0';
|
||||
|
||||
// Create a ConfigKey object for this key/value pair
|
||||
pConfigKey = (ConfigKey*) malloc(sizeof(*pConfigKey));
|
||||
if (pConfigKey)
|
||||
{
|
||||
pConfigKey->keyNameLen = (int) strlen(pKey);
|
||||
pConfigKey->pKeyName = (char*) malloc(pConfigKey->keyNameLen + 1);
|
||||
if (pConfigKey->pKeyName)
|
||||
{
|
||||
// Save the key name in lower case
|
||||
LowerCaseString(pConfigKey->pKeyName, pKey);
|
||||
|
||||
pConfigKey->valueLen = (int) strlen(pValue);
|
||||
pConfigKey->pValue = (char*) malloc(pConfigKey->valueLen + 1);
|
||||
if (pConfigKey->pValue)
|
||||
{
|
||||
strcpy(pConfigKey->pValue, pValue);
|
||||
|
||||
// The entry is ready, now associate it with the instance data.
|
||||
InsertTailList(&pConfigIfInstance->configKeyListHead, &pConfigKey->listEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
free(pConfigKey->pKeyName);
|
||||
free(pConfigKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
free(pConfigKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- File seek error, errno = %d\n", errno);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
|
||||
// Free the buffers associated with the instance data
|
||||
free(pConfigIfInstance->pConfigFolder);
|
||||
free(pConfigIfInstance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
|
||||
// Free the buffer allocated for the instance data
|
||||
free(pConfigIfInstance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
|
||||
}
|
||||
|
||||
// Close the file
|
||||
fclose(pConfigFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Unable to open config file, errno = %d\n", errno);
|
||||
DbgTrace(0, "-GetConfigInterface- Config file unable to open = %s\n", pFilePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetConfigInterface- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetConfigInterface- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
120
CASA-auth-token/client/core/config_if.h
Normal file
120
CASA-auth-token/client/core/config_if.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _CONFIG_IF_H_
|
||||
#define _CONFIG_IF_H_
|
||||
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
/**************************************************************************
|
||||
***************************************************************************
|
||||
** **
|
||||
** Configuration Object Interface Definitions **
|
||||
** **
|
||||
***************************************************************************
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
int
|
||||
(SSCS_CALL *PFNConfiglIf_AddReference)(
|
||||
IN const void *pIfInstance);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Interface reference count.
|
||||
//
|
||||
// Description:
|
||||
// Increases interface reference count.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
void
|
||||
(SSCS_CALL *PFNConfiglIf_ReleaseReference)(
|
||||
IN const void *pIfInstance);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Nothing.
|
||||
//
|
||||
// Description:
|
||||
// Decreases interface reference count. The interface is deallocated if
|
||||
// the reference count becomes zero.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
char*
|
||||
(SSCS_CALL *PFNConfiglIf_GetEntryValue)(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pKeyName);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pKeyName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the key whose value is being requested.
|
||||
//
|
||||
// Returns:
|
||||
// Pointer to NULL terminated string with value being requested or NULL.
|
||||
//
|
||||
// Description:
|
||||
// Gets value associated with a key for the configuration object.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//
|
||||
// Config Interface Object
|
||||
//
|
||||
typedef struct _ConfigIf
|
||||
{
|
||||
PFNConfiglIf_AddReference addReference;
|
||||
PFNConfiglIf_ReleaseReference releaseReference;
|
||||
PFNConfiglIf_GetEntryValue getEntryValue;
|
||||
|
||||
} ConfigIf, *PConfigIf;
|
||||
|
||||
|
||||
#endif // #ifndef _CONFIG_IF_H_
|
||||
|
||||
894
CASA-auth-token/client/core/engine.c
Normal file
894
CASA-auth-token/client/core/engine.c
Normal file
@@ -0,0 +1,894 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#define DEFAULT_RETRY_LIFETIME 5 // seconds
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
int
|
||||
InitializeLibrary(void);
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//
|
||||
// Debug tracing level
|
||||
//
|
||||
int DebugLevel = 0;
|
||||
|
||||
//
|
||||
// Operating parameter
|
||||
//
|
||||
bool g_bInitialized = false;
|
||||
long g_rpcFlags = SECURE_RPC_FLAG | ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG;
|
||||
char *g_pATSHostName = NULL;
|
||||
uint16_t g_ATSPort = 2645;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ObtainSessionToken(
|
||||
IN RpcSession *pRpcSession,
|
||||
IN AuthPolicy *pAuthPolicy,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char **ppSessionToken)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
LIST_ENTRY *pListEntry;
|
||||
AuthCacheEntry *pCacheEntry = NULL;
|
||||
|
||||
DbgTrace(1, "-ObtainSessionToken- Start\n", 0);
|
||||
|
||||
// Initialize output parameter
|
||||
*ppSessionToken = NULL;
|
||||
|
||||
// Look in our cache for an entry that matches one of the auth
|
||||
// contexts specified in the AuthPolicy object.
|
||||
pListEntry = pAuthPolicy->authContextListHead.Flink;
|
||||
while (pListEntry != &pAuthPolicy->authContextListHead)
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
|
||||
// Get pointer to AuthContext structure
|
||||
pAuthContext = CONTAINING_RECORD(pListEntry, AuthContext, listEntry);
|
||||
|
||||
// Try to find a cache entry for the auth context
|
||||
pCacheEntry = FindSessionTokenEntryInCache(pAuthContext->pContext,
|
||||
pCredStoreScope);
|
||||
if (pCacheEntry != NULL)
|
||||
{
|
||||
// Cache entry found, check if it is of use to us.
|
||||
if (CASA_SUCCESS(pCacheEntry->status))
|
||||
{
|
||||
// This entry can be used, stop looking.
|
||||
retStatus = pCacheEntry->status;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Free the entry
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// If we did not find a cache entry that we can use, then try to create one.
|
||||
pListEntry = pAuthPolicy->authContextListHead.Flink;
|
||||
while (!CASA_SUCCESS(retStatus)
|
||||
&& pListEntry != &pAuthPolicy->authContextListHead)
|
||||
{
|
||||
AuthContext *pAuthContext;
|
||||
char *pAuthMechToken;
|
||||
|
||||
// Get pointer to AuthContext structure
|
||||
pAuthContext = CONTAINING_RECORD(pListEntry, AuthContext, listEntry);
|
||||
|
||||
// Only try to create cache entry for the auth context if there is not
|
||||
// one already.
|
||||
pCacheEntry = FindSessionTokenEntryInCache(pAuthContext->pContext,
|
||||
pCredStoreScope);
|
||||
if (pCacheEntry == NULL)
|
||||
{
|
||||
char *pReqMsg = NULL;
|
||||
char *pRespMsg = NULL;
|
||||
int respLen;
|
||||
|
||||
// Get authentication mechanism token
|
||||
retStatus = GetAuthMechToken(pAuthContext,
|
||||
pHostName,
|
||||
pCredStoreScope,
|
||||
&pAuthMechToken);
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// We were not able to obtain an authentication mechanism token
|
||||
// for the context.
|
||||
//
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Authenticate to the ATS
|
||||
pReqMsg = BuildAuthenticateMsg(pAuthContext, pAuthMechToken);
|
||||
if (pReqMsg)
|
||||
{
|
||||
// Issue rpc
|
||||
retStatus = Rpc(pRpcSession,
|
||||
"Authenticate",
|
||||
g_rpcFlags,
|
||||
pReqMsg,
|
||||
&pRespMsg,
|
||||
&respLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
AuthenticateResp *pAuthenticateResp;
|
||||
|
||||
// Create Authenticate response object
|
||||
retStatus = CreateAuthenticateResp(pRespMsg, respLen, &pAuthenticateResp);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Return the auth token to the caller
|
||||
pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
|
||||
retStatus,
|
||||
pAuthenticateResp->pToken,
|
||||
pAuthenticateResp->tokenLifetime,
|
||||
pCredStoreScope);
|
||||
|
||||
pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer
|
||||
|
||||
// Free the Authenticate response object
|
||||
RelAuthenticateResp(pAuthenticateResp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainSessionToken- Authenticate Rpc failure, error = %08X\n", retStatus);
|
||||
}
|
||||
|
||||
// Free resources that may be hanging around
|
||||
if (pRespMsg)
|
||||
free(pRespMsg);
|
||||
|
||||
free(pReqMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainSessionToken- Error building Authenticate msg\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Add the entry to the cache if successful or if the reason that we failed
|
||||
// was because the server was unavailable.
|
||||
if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE)
|
||||
{
|
||||
pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
|
||||
retStatus,
|
||||
NULL,
|
||||
DEFAULT_RETRY_LIFETIME,
|
||||
pCredStoreScope);
|
||||
|
||||
}
|
||||
|
||||
// Release the cache entry if the resulting status is not successful
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
|
||||
// Free up the buffer associated with the authentication mechanism token
|
||||
free(pAuthMechToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Free the entry
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Return session token if successful
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Allocate a buffer for the return token
|
||||
*ppSessionToken = (char*) malloc(strlen(pCacheEntry->token) + 1);
|
||||
if (*ppSessionToken)
|
||||
{
|
||||
// Copy the token onto the allocated buffer
|
||||
strcpy(*ppSessionToken, pCacheEntry->token);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainSessionToken- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-ObtainSessionToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ObtainAuthTokenFromServer(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
INOUT char **ppAuthToken,
|
||||
INOUT int *pTokenLifetime,
|
||||
IN void *pCredStoreScope)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
RpcSession *pRpcSession;
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenFromServer- Start\n", 0);
|
||||
|
||||
// Initialize output parameter
|
||||
*ppAuthToken = NULL;
|
||||
|
||||
// Open Rpc Session to the auth service at the specified host
|
||||
pRpcSession = OpenRpcSession((g_pATSHostName != NULL) ? g_pATSHostName : pHostName,
|
||||
g_ATSPort);
|
||||
if (pRpcSession)
|
||||
{
|
||||
char *pReqMsg = NULL;
|
||||
char *pRespMsg = NULL;
|
||||
int respLen;
|
||||
AuthPolicy *pAuthPolicy = NULL;
|
||||
GetAuthPolicyResp *pGetAuthPolicyResp = NULL;
|
||||
GetAuthTokenResp *pGetAuthTokenResp = NULL;
|
||||
char *pSessionToken = NULL;
|
||||
|
||||
// Request the auth parameters associated with this service
|
||||
pReqMsg = BuildGetAuthPolicyMsg(pServiceName, "localhost"); // tbd - This will be changed in the future so that we can support services residing in a different host than the ATS
|
||||
if (pReqMsg)
|
||||
{
|
||||
// Issue rpc
|
||||
retStatus = Rpc(pRpcSession,
|
||||
"GetAuthPolicy",
|
||||
g_rpcFlags,
|
||||
pReqMsg,
|
||||
&pRespMsg,
|
||||
&respLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Create GetAuthPolicy response object
|
||||
retStatus = CreateGetAuthPolicyResp(pRespMsg, respLen, &pGetAuthPolicyResp);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Create the AuthPolicy object
|
||||
retStatus = CreateAuthPolicy(pGetAuthPolicyResp->pPolicy,
|
||||
pGetAuthPolicyResp->policyLen,
|
||||
&pAuthPolicy);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Now try to obtain a session token
|
||||
retStatus = ObtainSessionToken(pRpcSession,
|
||||
pAuthPolicy,
|
||||
(g_pATSHostName != NULL) ? g_pATSHostName : pHostName,
|
||||
pCredStoreScope,
|
||||
&pSessionToken);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Request auth token for the service
|
||||
free(pReqMsg);
|
||||
pReqMsg = BuildGetAuthTokenMsg(pServiceName, "localhost", pSessionToken); // tbd - This will be changed in the future so that we can support services residing in a different host than the ATS
|
||||
if (pReqMsg)
|
||||
{
|
||||
// Free the previous response msg buffer
|
||||
free(pRespMsg);
|
||||
pRespMsg = NULL;
|
||||
|
||||
// Issue rpc
|
||||
retStatus = Rpc(pRpcSession,
|
||||
"GetAuthToken",
|
||||
g_rpcFlags,
|
||||
pReqMsg,
|
||||
&pRespMsg,
|
||||
&respLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Create GetAuthPolicy response object
|
||||
retStatus = CreateGetAuthTokenResp(pRespMsg, respLen, &pGetAuthTokenResp);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Return the auth token to the caller
|
||||
*ppAuthToken = pGetAuthTokenResp->pToken;
|
||||
pGetAuthTokenResp->pToken = NULL; // To keep us from freeing the buffer
|
||||
*pTokenLifetime = pGetAuthTokenResp->tokenLifetime;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthTokenResp object, error = %08X\n", retStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- GetAuthToken Rpc failure, error = %08X\n", retStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Error building GetAuthToken msg\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to obtain session token, error = %08X\n", retStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create AuthPolicy object, error = %08X\n", retStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthPolicyResp object, error = %08X\n", retStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- GetAuthPolicy Rpc failure, error = %08X\n", retStatus);
|
||||
}
|
||||
|
||||
// Free resources that may be hanging around
|
||||
if (pReqMsg)
|
||||
free(pReqMsg);
|
||||
|
||||
if (pRespMsg)
|
||||
free(pRespMsg);
|
||||
|
||||
if (pSessionToken)
|
||||
free(pSessionToken);
|
||||
|
||||
if (pGetAuthTokenResp)
|
||||
RelGetAuthTokenResp(pGetAuthTokenResp);
|
||||
|
||||
if (pGetAuthPolicyResp)
|
||||
RelGetAuthPolicyResp(pGetAuthPolicyResp);
|
||||
|
||||
if (pAuthPolicy)
|
||||
RelAuthPolicy(pAuthPolicy);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Error building GetAuthPolicy msg\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Close the Rpc Session
|
||||
CloseRpcSession(pRpcSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenFromServer- Error opening Rpc session\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenFromServer- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
ObtainAuthTokenInt(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
INOUT char *pAuthTokenBuf,
|
||||
INOUT int *pAuthTokenBufLen,
|
||||
IN void *pCredStoreScope)
|
||||
//
|
||||
// Arguments:
|
||||
// pServiceName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the service to which the client is trying to
|
||||
// authenticate.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the host where resides the service to which the
|
||||
// client is trying to authenticate. Note that the name
|
||||
// can either be a DNS name or a dotted IP address.
|
||||
//
|
||||
// pAuthTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pAuthTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pAuthTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pAuthTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pAuthTokenBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged by applications
|
||||
// running in the context of System.
|
||||
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified
|
||||
// service at host. The user is scoped using the info associated
|
||||
// with the magic cookie.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
AuthCacheEntry *pCacheEntry;
|
||||
char *pNormalizedHostName;
|
||||
char *pToken;
|
||||
HANDLE hUserMutex = NULL;
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenInt- Start\n", 0);
|
||||
|
||||
// Verify the input parameters
|
||||
if (pServiceName == NULL
|
||||
|| pHostName == NULL
|
||||
|| pAuthTokenBufLen == NULL
|
||||
|| (*pAuthTokenBufLen != 0 && pAuthTokenBuf == NULL))
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenInt- Invalid parameter\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenInt- ServiceName = %s\n", pServiceName);
|
||||
DbgTrace(1, "-ObtainAuthTokenInt- HostName = %s\n", pHostName);
|
||||
DbgTrace(1, "-ObtainAuthTokenInt- BufferLength = %d\n", *pAuthTokenBufLen);
|
||||
|
||||
// Obtain our synchronization mutex
|
||||
AcquireModuleMutex;
|
||||
|
||||
// Create user synchronization mutex
|
||||
retStatus = CreateUserMutex(&hUserMutex);
|
||||
if (retStatus != CASA_STATUS_SUCCESS)
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenInt- Error creating mutex for the user\n", 0);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Make sure we are fully initialized
|
||||
if (g_bInitialized == false)
|
||||
{
|
||||
retStatus = InitializeLibrary();
|
||||
|
||||
if (retStatus == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
g_bInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Release our synchronization mutex
|
||||
ReleaseModuleMutex;
|
||||
|
||||
// Normalize the host name
|
||||
pNormalizedHostName = NormalizeHostName(pHostName);
|
||||
if (pNormalizedHostName)
|
||||
{
|
||||
// Start user process synchronization
|
||||
AcquireUserMutex(hUserMutex);
|
||||
|
||||
// Try to find a cache entry for the service
|
||||
pCacheEntry = FindAuthTokenEntryInCache(pServiceName,
|
||||
pNormalizedHostName,
|
||||
pCredStoreScope);
|
||||
if (pCacheEntry == NULL)
|
||||
{
|
||||
// Initialize to retry in case of failure
|
||||
int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;
|
||||
|
||||
// Cache entry created, now try to obtain auth token from the CASA Server
|
||||
retStatus = ObtainAuthTokenFromServer(pServiceName,
|
||||
pNormalizedHostName,
|
||||
&pToken,
|
||||
&cacheEntryLifetime,
|
||||
pCredStoreScope);
|
||||
|
||||
// Add the entry to the cache if successful or if the reason that we failed
|
||||
// was because the server was un-available.
|
||||
if (CASA_SUCCESS(retStatus)
|
||||
|| CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE)
|
||||
{
|
||||
pCacheEntry = CreateAuthTokenCacheEntry(pServiceName,
|
||||
pNormalizedHostName,
|
||||
retStatus,
|
||||
pToken,
|
||||
cacheEntryLifetime,
|
||||
pCredStoreScope);
|
||||
if (pCacheEntry)
|
||||
{
|
||||
// Release the cache entry if the resulting status is not successful
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cache entry found, update the return status with the information saved in it
|
||||
// and release it if its status is not successful.
|
||||
if (!CASA_SUCCESS(retStatus = pCacheEntry->status))
|
||||
{
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to return auth token if we have one to return
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
int tokenLen = (int) strlen(pCacheEntry->token) + 1;
|
||||
|
||||
// We have an authentication token, try to return it to the caller
|
||||
// after verifying that the supplied buffer is big enough.
|
||||
if (*pAuthTokenBufLen >= tokenLen)
|
||||
{
|
||||
// Return the auth token to the caller
|
||||
DbgTrace(2, "-ObtainAuthTokenInt- Copying the token into the callers buffer\n", 0);
|
||||
strcpy(pAuthTokenBuf, pCacheEntry->token);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenInt- The supplied buffer is not large enough", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
}
|
||||
|
||||
// Return the token length to the caller
|
||||
*pAuthTokenBufLen = tokenLen;
|
||||
|
||||
FreeAuthCacheEntry(pCacheEntry);
|
||||
}
|
||||
|
||||
// Stop user process synchronization
|
||||
ReleaseUserMutex(hUserMutex);
|
||||
|
||||
// Free the space allocated for the normalized host name
|
||||
free(pNormalizedHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ObtainAuthTokenInt- Host name normalization failed\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
if (hUserMutex != NULL)
|
||||
{
|
||||
DestroyUserMutex(hUserMutex);
|
||||
}
|
||||
DbgTrace(1, "-ObtainAuthTokenInt- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
ObtainAuthToken(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
INOUT char *pAuthTokenBuf,
|
||||
INOUT int *pAuthTokenBufLen)
|
||||
//
|
||||
// Arguments:
|
||||
// pServiceName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the service to which the client is trying to
|
||||
// authenticate.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the host where resides the service to which the
|
||||
// client is trying to authenticate. Note that the name
|
||||
// can either be a DNS name or a dotted IP address.
|
||||
//
|
||||
// pAuthTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pAuthTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pAuthTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pAuthTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pAuthTokenBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified
|
||||
// service at host.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
|
||||
DbgTrace(1, "-ObtainAuthToken- Start\n", 0);
|
||||
|
||||
// Call our internal worker
|
||||
retStatus = ObtainAuthTokenInt(pServiceName,
|
||||
pHostName,
|
||||
pAuthTokenBuf,
|
||||
pAuthTokenBufLen,
|
||||
NULL);
|
||||
|
||||
DbgTrace(1, "-ObtainAuthToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
InitializeLibrary(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int retStatus = -1;
|
||||
int getConfigStatus = -1;
|
||||
ConfigIf *pClientConfigIf;
|
||||
char *pATSPortSetting;
|
||||
char *pDisableSecureConnections;
|
||||
char *pAllowInvalidCerts;
|
||||
char *pUsersCannotAllowInvalidCerts;
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- Start\n", 0);
|
||||
|
||||
// Try to obtain client configuration settings
|
||||
getConfigStatus = GetConfigInterface(clientConfigFolder,
|
||||
"client",
|
||||
&pClientConfigIf);
|
||||
if (CASA_SUCCESS(getConfigStatus)
|
||||
&& CasaStatusCode(getConfigStatus) != CASA_STATUS_OBJECT_NOT_FOUND)
|
||||
{
|
||||
// Check if an ATS hostname has been configured
|
||||
g_pATSHostName = pClientConfigIf->getEntryValue(pClientConfigIf, "ATS-hostname");
|
||||
if (g_pATSHostName != NULL)
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- ATS hostname configured = %s\n", g_pATSHostName);
|
||||
}
|
||||
|
||||
// Check if the DisableSecureConnections setting has been configured
|
||||
pDisableSecureConnections = pClientConfigIf->getEntryValue(pClientConfigIf, "DisableSecureConnections");
|
||||
if (pDisableSecureConnections != NULL)
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- DisableSecureConnections setting configured = %s\n", pDisableSecureConnections);
|
||||
|
||||
// Adjust the g_rpcFlags variable based on the setting
|
||||
if (stricmp(pDisableSecureConnections, "true") == 0)
|
||||
{
|
||||
g_rpcFlags &= ~SECURE_RPC_FLAG;
|
||||
|
||||
// Change the default ATS port to 80 from 443
|
||||
g_ATSPort = 80;
|
||||
}
|
||||
else if (stricmp(pDisableSecureConnections, "false") == 0)
|
||||
{
|
||||
g_rpcFlags |= SECURE_RPC_FLAG;
|
||||
}
|
||||
|
||||
// Free the buffer holding the DisableSecureConnections setting
|
||||
free(pDisableSecureConnections);
|
||||
}
|
||||
|
||||
// Check the AllowInvalidCerts setting if using secure connections
|
||||
if (g_rpcFlags & SECURE_RPC_FLAG)
|
||||
{
|
||||
// Check if the AllowInvalidCerts setting has been configured
|
||||
pAllowInvalidCerts = pClientConfigIf->getEntryValue(pClientConfigIf, "AllowInvalidCerts");
|
||||
if (pAllowInvalidCerts != NULL)
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- AllowInvalidCerts setting configured = %s\n", pAllowInvalidCerts);
|
||||
|
||||
// Adjust the g_rpcFlags variable based on the setting
|
||||
if (stricmp(pAllowInvalidCerts, "false") == 0)
|
||||
{
|
||||
g_rpcFlags &= ~ALLOW_INVALID_CERTS_RPC_FLAG;
|
||||
}
|
||||
else if (stricmp(pAllowInvalidCerts, "true") == 0)
|
||||
{
|
||||
g_rpcFlags |= ALLOW_INVALID_CERTS_RPC_FLAG;
|
||||
}
|
||||
|
||||
// Free the buffer holding the AllowInvalidCerts setting
|
||||
free(pAllowInvalidCerts);
|
||||
}
|
||||
|
||||
// Check the UsersCannotAllowInvalidCerts setting if not allowing invalid certs.
|
||||
if ((g_rpcFlags & ALLOW_INVALID_CERTS_RPC_FLAG) == 0)
|
||||
{
|
||||
// Check if the UsersCannotAllowInvalidCerts setting has been configured
|
||||
pUsersCannotAllowInvalidCerts = pClientConfigIf->getEntryValue(pClientConfigIf, "UsersCannotAllowInvalidCerts");
|
||||
if (pUsersCannotAllowInvalidCerts != NULL)
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- UsersCannotAllowInvalidCerts setting configured = %s\n", pUsersCannotAllowInvalidCerts);
|
||||
|
||||
// Adjust the g_rpcFlags variable based on the setting
|
||||
if (stricmp(pUsersCannotAllowInvalidCerts, "false") == 0)
|
||||
{
|
||||
g_rpcFlags |= ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG;
|
||||
}
|
||||
else if (stricmp(pUsersCannotAllowInvalidCerts, "true") == 0)
|
||||
{
|
||||
g_rpcFlags &= ~ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG;
|
||||
}
|
||||
|
||||
// Free the buffer holding the UsersCannotAllowInvalidCerts setting
|
||||
free(pUsersCannotAllowInvalidCerts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if an ATS port number has been configured
|
||||
pATSPortSetting = pClientConfigIf->getEntryValue(pClientConfigIf, "ATS-port");
|
||||
if (pATSPortSetting != NULL)
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- ATS port number configured = %s\n", pATSPortSetting);
|
||||
|
||||
// Convert the number to hex
|
||||
g_ATSPort = (int) dtoul(pATSPortSetting, strlen(pATSPortSetting));
|
||||
|
||||
// Free the buffer holding the port number
|
||||
free(pATSPortSetting);
|
||||
}
|
||||
|
||||
// Release config interface instance
|
||||
pClientConfigIf->releaseReference(pClientConfigIf);
|
||||
}
|
||||
|
||||
// Initialize the host name normalization
|
||||
retStatus = InitializeHostNameNormalization();
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Normalize ATS host name if configured
|
||||
if (g_pATSHostName)
|
||||
{
|
||||
char *pNormalizedHostName = NormalizeHostName(g_pATSHostName);
|
||||
if (pNormalizedHostName)
|
||||
{
|
||||
// Use this name instead of the one that we already have
|
||||
free(g_pATSHostName);
|
||||
g_pATSHostName = pNormalizedHostName;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- ATS Hostname normalization failed\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the auth cache
|
||||
retStatus = InitializeAuthCache();
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
retStatus = InitializeRpc();
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- Auth cache intialization failed\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InitializeLibrary- HostName Normalizer intialization failed\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
745
CASA-auth-token/client/core/getpolicymsg.c
Normal file
745
CASA-auth-token/client/core/getpolicymsg.c
Normal file
@@ -0,0 +1,745 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Parse states
|
||||
//
|
||||
#define AWAITING_ROOT_ELEMENT_START 0x0
|
||||
#define AWAITING_ROOT_ELEMENT_END 0x1
|
||||
#define AWAITING_STATUS_ELEMENT_START 0x2
|
||||
#define AWAITING_STATUS_ELEMENT_END 0x3
|
||||
#define AWAITING_STATUS_DATA 0x4
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_START 0x5
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_END 0x6
|
||||
#define AWAITING_DESCRIPTION_DATA 0x7
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_START 0x8
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_END 0x9
|
||||
#define AWAITING_AUTH_TOKEN_DATA 0xA
|
||||
#define AWAITING_AUTH_POLICY_ELEMENT_START 0xB
|
||||
#define AWAITING_AUTH_POLICY_ELEMENT_END 0xC
|
||||
#define AWAITING_AUTH_POLICY_DATA 0xD
|
||||
#define DONE_PARSING 0xE
|
||||
|
||||
//
|
||||
// Get Authentication Policy Response Parse Structure
|
||||
//
|
||||
typedef struct _GetAuthPolicyRespParse
|
||||
{
|
||||
XML_Parser p;
|
||||
int state;
|
||||
int elementDataProcessed;
|
||||
GetAuthPolicyResp *pGetAuthPolicyResp;
|
||||
CasaStatus status;
|
||||
|
||||
} GetAuthPolicyRespParse, *PGetAuthPolicyRespParse;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
char*
|
||||
BuildGetAuthPolicyMsg(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pMsg = NULL;
|
||||
int bufferSize;
|
||||
|
||||
DbgTrace(1, "-BuildGetAuthPolicyMsg- Start\n", 0);
|
||||
|
||||
/*
|
||||
* The format of the get authentication policy request message is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_req>
|
||||
* <service>service name<\service>
|
||||
* <host>host name</host>
|
||||
* </get_auth_policy_req>
|
||||
*
|
||||
*/
|
||||
|
||||
// Determine the buffer size necessary to hold the msg
|
||||
bufferSize = strlen(XML_DECLARATION)
|
||||
+ 2 // crlf
|
||||
+ 1 // <
|
||||
+ strlen(GET_AUTH_POLICY_REQUEST_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(SERVICE_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pServiceName)
|
||||
+ 2 // </
|
||||
+ strlen(SERVICE_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 2 // </
|
||||
+ strlen(HOST_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pHostName)
|
||||
+ 2 // </
|
||||
+ strlen(HOST_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 2 // </
|
||||
+ strlen(GET_AUTH_POLICY_REQUEST_ELEMENT_NAME)
|
||||
+ 2; // >null
|
||||
|
||||
// Allocate the msg buffer
|
||||
pMsg = (char*) malloc(bufferSize);
|
||||
if (pMsg)
|
||||
{
|
||||
// Now build the message
|
||||
memset(pMsg, 0, bufferSize);
|
||||
strcat(pMsg, XML_DECLARATION);
|
||||
strcat(pMsg, "\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, GET_AUTH_POLICY_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, SERVICE_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pServiceName);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, SERVICE_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, HOST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pHostName);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, HOST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, GET_AUTH_POLICY_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-BuildGetAuthPolicyMsg- Buffer allocation error\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-BuildGetAuthPolicyMsg- End, pMsg = %0lX\n", (long) pMsg);
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthPolicyRespStartElementHandler(
|
||||
IN GetAuthPolicyRespParse *pGetAuthPolicyRespParse,
|
||||
IN const XML_Char *name,
|
||||
IN const XML_Char **atts)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthPolicyRespStartElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthPolicyRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Get Authentication
|
||||
// Policy Response Element.
|
||||
if (strcmp(name, GET_AUTH_POLICY_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_STATUS_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_DESCRIPTION_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_DESCRIPTION_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_POLICY_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Authentication Policy Element.
|
||||
if (strcmp(name, AUTH_POLICY_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_AUTH_POLICY_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected state = %d\n", pGetAuthPolicyRespParse->state);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetAuthPolicyRespStartElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ConsumeElementData(
|
||||
IN GetAuthPolicyRespParse *pGetAuthPolicyRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len,
|
||||
INOUT char **ppElementData,
|
||||
INOUT int *pElementDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- Start\n", 0);
|
||||
|
||||
// Proceed based on whether or not we have already consumed data
|
||||
// for this element.
|
||||
if (*ppElementData == NULL)
|
||||
{
|
||||
// We have not yet consumed data for this element
|
||||
pGetAuthPolicyRespParse->elementDataProcessed = len;
|
||||
|
||||
// Allocate a buffer to hold this element data (null terminated).
|
||||
*ppElementData = (char*) malloc(len + 1);
|
||||
if (*ppElementData)
|
||||
{
|
||||
memset(*ppElementData, 0, len + 1);
|
||||
memcpy(*ppElementData, s, len);
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pGetAuthPolicyRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pNewBuf;
|
||||
|
||||
// We have already received token data, append this data to it.
|
||||
pNewBuf = (char*) malloc(pGetAuthPolicyRespParse->elementDataProcessed + len + 1);
|
||||
if (pNewBuf)
|
||||
{
|
||||
memset(pNewBuf,
|
||||
0,
|
||||
pGetAuthPolicyRespParse->elementDataProcessed + len + 1);
|
||||
memcpy(pNewBuf,
|
||||
*ppElementData,
|
||||
pGetAuthPolicyRespParse->elementDataProcessed);
|
||||
memcpy(pNewBuf + pGetAuthPolicyRespParse->elementDataProcessed, s, len);
|
||||
pGetAuthPolicyRespParse->elementDataProcessed += len;
|
||||
|
||||
// Swap the buffers
|
||||
free(*ppElementData);
|
||||
*ppElementData = pNewBuf;
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pGetAuthPolicyRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthPolicyRespCharDataHandler(
|
||||
IN GetAuthPolicyRespParse *pGetAuthPolicyRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthPolicyRespCharDataHandler- Start\n", 0);
|
||||
|
||||
// Just exit if being called to process white space
|
||||
if (*s == '\n' || *s == '\r' || *s == '\t' || *s == ' ')
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthPolicyRespParse->state)
|
||||
{
|
||||
case AWAITING_DESCRIPTION_DATA:
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// Ignore the status description data for now.
|
||||
// tbd
|
||||
|
||||
// Advanced to the next state
|
||||
pGetAuthPolicyRespParse->state = AWAITING_DESCRIPTION_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_DATA:
|
||||
|
||||
// Set the appropriate status in the AuthenticationResp based on the
|
||||
// returned status.
|
||||
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthPolicyRespParse->status = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_AUTHENTICATION_FAILURE);
|
||||
}
|
||||
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_NOT_CONFIGURED);
|
||||
}
|
||||
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_SERVER_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespCharDataHandler- Un-expected status\n", 0);
|
||||
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Advanced to the next state
|
||||
pGetAuthPolicyRespParse->state = AWAITING_STATUS_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_POLICY_DATA:
|
||||
case AWAITING_AUTH_POLICY_ELEMENT_END:
|
||||
|
||||
pGetAuthPolicyRespParse->status = ConsumeElementData(pGetAuthPolicyRespParse,
|
||||
s,
|
||||
len,
|
||||
&pGetAuthPolicyRespParse->pGetAuthPolicyResp->pPolicy,
|
||||
&pGetAuthPolicyRespParse->pGetAuthPolicyResp->policyLen);
|
||||
if (CASA_SUCCESS(pGetAuthPolicyRespParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pGetAuthPolicyRespParse->state = AWAITING_AUTH_POLICY_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthPolicyRespCharDataHandler- Un-expected state = %d\n", pGetAuthPolicyRespParse->state);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(2, "-GetAuthPolicyRespCharDataHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthPolicyRespEndElementHandler(
|
||||
IN GetAuthPolicyRespParse *pGetAuthPolicyRespParse,
|
||||
IN const XML_Char *name)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthPolicyRespEndElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthPolicyRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Get Authentication
|
||||
// Policy Response Element.
|
||||
if (strcmp(name, GET_AUTH_POLICY_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Done.
|
||||
pGetAuthPolicyRespParse->state = DONE_PARSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespEndHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_STATUS_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state based on the status code.
|
||||
if (CASA_SUCCESS(pGetAuthPolicyRespParse->status))
|
||||
{
|
||||
// The request completed successfully
|
||||
pGetAuthPolicyRespParse->state = AWAITING_AUTH_POLICY_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
pGetAuthPolicyRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_POLICY_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Authentication Policy Element.
|
||||
if (strcmp(name, AUTH_POLICY_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthPolicyRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected state = %d\n", pGetAuthPolicyRespParse->state);
|
||||
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetAuthPolicyRespEndElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateGetAuthPolicyResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT GetAuthPolicyResp **ppGetAuthPolicyResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
GetAuthPolicyRespParse getAuthPolicyRespParse = {0};
|
||||
GetAuthPolicyResp *pGetAuthPolicyResp;
|
||||
|
||||
DbgTrace(1, "-CreateGetAuthPolicyResp- Start\n", 0);
|
||||
|
||||
/*
|
||||
* When a get authentication policy request is processed successfully, the
|
||||
* server replies to the client with a message with the following format:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>ok</description>200</status>
|
||||
* <auth_policy>authentication policy data</auth_policy>
|
||||
* </get_auth_policy_resp>
|
||||
*
|
||||
* When a get authentication policy request fails to be successfully processed,
|
||||
* the server responds with an error and an error description string. The message
|
||||
* format of an unsuccessful reply is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_policy_resp>
|
||||
*
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allocate GetAuthPolicyResp object
|
||||
pGetAuthPolicyResp = malloc(sizeof(*pGetAuthPolicyResp));
|
||||
if (pGetAuthPolicyResp)
|
||||
{
|
||||
XML_Parser p;
|
||||
|
||||
// Initialize the GetAuthPolicyResp object and set it in the
|
||||
// parse oject.
|
||||
memset(pGetAuthPolicyResp, 0, sizeof(*pGetAuthPolicyResp));
|
||||
getAuthPolicyRespParse.pGetAuthPolicyResp = pGetAuthPolicyResp;
|
||||
|
||||
// Create parser
|
||||
p = XML_ParserCreate(NULL);
|
||||
if (p)
|
||||
{
|
||||
// Keep track of the parser in our parse object
|
||||
getAuthPolicyRespParse.p = p;
|
||||
|
||||
// Initialize the status within the parse object
|
||||
getAuthPolicyRespParse.status = CASA_STATUS_SUCCESS;
|
||||
|
||||
// Set the start and end element handlers
|
||||
XML_SetElementHandler(p,
|
||||
(XML_StartElementHandler) GetAuthPolicyRespStartElementHandler,
|
||||
(XML_EndElementHandler) GetAuthPolicyRespEndElementHandler);
|
||||
|
||||
// Set the character data handler
|
||||
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthPolicyRespCharDataHandler);
|
||||
|
||||
|
||||
// Set our user data
|
||||
XML_SetUserData(p, &getAuthPolicyRespParse);
|
||||
|
||||
// Parse the document
|
||||
if (XML_Parse(p, pRespMsg, respLen, 1) == XML_STATUS_OK)
|
||||
{
|
||||
// Verify that the parse operation completed successfully
|
||||
if (getAuthPolicyRespParse.state == DONE_PARSING)
|
||||
{
|
||||
// The parse operation succeded, obtain the status returned
|
||||
// by the server.
|
||||
retStatus = getAuthPolicyRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthPolicyResp- Parse operation did not complete\n", 0);
|
||||
|
||||
// Check if a status has been recorded
|
||||
if (getAuthPolicyRespParse.status != CASA_STATUS_SUCCESS)
|
||||
{
|
||||
retStatus = getAuthPolicyRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthPolicyResp- Parse error %d\n", XML_GetErrorCode(p));
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
// Free the parser
|
||||
XML_ParserFree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthPolicyResp- Parser creation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Return the AuthenticationResp object to the caller if necessary
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
*ppGetAuthPolicyResp = pGetAuthPolicyResp;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(pGetAuthPolicyResp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthPolicyResp- Memory allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateGetAuthPolicyResp- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
RelGetAuthPolicyResp(
|
||||
IN GetAuthPolicyResp *pGetAuthPolicyResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-RelGetAuthPolicyResp- Start\n", 0);
|
||||
|
||||
// Free the buffer holding the authentication policy
|
||||
if (pGetAuthPolicyResp->pPolicy)
|
||||
free(pGetAuthPolicyResp->pPolicy);
|
||||
|
||||
// Free the GetAuthPolicyResp
|
||||
free(pGetAuthPolicyResp);
|
||||
|
||||
DbgTrace(1, "-RelGetAuthPolicyResp- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
793
CASA-auth-token/client/core/gettokenmsg.c
Normal file
793
CASA-auth-token/client/core/gettokenmsg.c
Normal file
@@ -0,0 +1,793 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Parse states
|
||||
//
|
||||
#define AWAITING_ROOT_ELEMENT_START 0x0
|
||||
#define AWAITING_ROOT_ELEMENT_END 0x1
|
||||
#define AWAITING_STATUS_ELEMENT_START 0x2
|
||||
#define AWAITING_STATUS_ELEMENT_END 0x3
|
||||
#define AWAITING_STATUS_DATA 0x4
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_START 0x5
|
||||
#define AWAITING_DESCRIPTION_ELEMENT_END 0x6
|
||||
#define AWAITING_DESCRIPTION_DATA 0x7
|
||||
#define AWAITING_LIFETIME_DATA 0x8
|
||||
#define AWAITING_LIFETIME_ELEMENT_START 0x9
|
||||
#define AWAITING_LIFETIME_ELEMENT_END 0xA
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_START 0xB
|
||||
#define AWAITING_AUTH_TOKEN_ELEMENT_END 0xC
|
||||
#define AWAITING_AUTH_TOKEN_DATA 0xD
|
||||
#define DONE_PARSING 0xE
|
||||
|
||||
//
|
||||
// Get Authentication Token Response Parse Structure
|
||||
//
|
||||
typedef struct _GetAuthTokenRespParse
|
||||
{
|
||||
XML_Parser p;
|
||||
int state;
|
||||
int elementDataProcessed;
|
||||
GetAuthTokenResp *pGetAuthTokenResp;
|
||||
CasaStatus status;
|
||||
|
||||
} GetAuthTokenRespParse, *PGetAuthTokenRespParse;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//++=======================================================================
|
||||
char*
|
||||
BuildGetAuthTokenMsg(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
IN char *pSessionToken)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pMsg = NULL;
|
||||
int bufferSize;
|
||||
|
||||
DbgTrace(1, "-BuildGetAuthTokenMsg- Start\n", 0);
|
||||
|
||||
/*
|
||||
* The format of the get authentication token request message
|
||||
* is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_token_req>
|
||||
* <service>service name</service>
|
||||
* <host>host name</host>
|
||||
* <session_token>session token data</session_token>
|
||||
* </get_auth_token_req>
|
||||
*
|
||||
*/
|
||||
|
||||
// Determine the buffer size necessary to hold the msg
|
||||
bufferSize = strlen(XML_DECLARATION)
|
||||
+ 2 // crlf
|
||||
+ 1 // <
|
||||
+ strlen(GET_AUTH_TOKEN_REQUEST_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(SERVICE_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pServiceName)
|
||||
+ 2 // </
|
||||
+ strlen(SERVICE_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(HOST_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pHostName)
|
||||
+ 2 // </
|
||||
+ strlen(HOST_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 1 // <
|
||||
+ strlen(SESSION_TOKEN_ELEMENT_NAME)
|
||||
+ 1 // >
|
||||
+ strlen(pSessionToken)
|
||||
+ 2 // </
|
||||
+ strlen(SESSION_TOKEN_ELEMENT_NAME)
|
||||
+ 3 // >crlf
|
||||
+ 2 // </
|
||||
+ strlen(GET_AUTH_TOKEN_REQUEST_ELEMENT_NAME)
|
||||
+ 2; // >null
|
||||
|
||||
// Allocate the msg buffer
|
||||
pMsg = (char*) malloc(bufferSize);
|
||||
if (pMsg)
|
||||
{
|
||||
// Now build the message
|
||||
memset(pMsg, 0, bufferSize);
|
||||
strcat(pMsg, XML_DECLARATION);
|
||||
strcat(pMsg, "\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, GET_AUTH_TOKEN_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, SERVICE_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pServiceName);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, SERVICE_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, HOST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pHostName);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, HOST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "<");
|
||||
strcat(pMsg, SESSION_TOKEN_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
strcat(pMsg, pSessionToken);
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, SESSION_TOKEN_ELEMENT_NAME);
|
||||
strcat(pMsg, ">\r\n");
|
||||
strcat(pMsg, "</");
|
||||
strcat(pMsg, GET_AUTH_TOKEN_REQUEST_ELEMENT_NAME);
|
||||
strcat(pMsg, ">");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-BuildGetAuthTokenMsg- Buffer allocation error\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-BuildGetAuthTokenMsg- End, pMsg = %0lX\n", (long) pMsg);
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthTokenRespStartElementHandler(
|
||||
IN GetAuthTokenRespParse *pGetAuthTokenRespParse,
|
||||
IN const XML_Char *name,
|
||||
IN const XML_Char **atts)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthTokenRespStartElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthTokenRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Get Authentication
|
||||
// Token Response Element.
|
||||
if (strcmp(name, GET_AUTH_TOKEN_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_STATUS_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_DESCRIPTION_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_DESCRIPTION_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_TOKEN_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Authentication Token Element.
|
||||
if (strcmp(name, AUTH_TOKEN_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_LIFETIME_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_ELEMENT_START:
|
||||
|
||||
// In this state, we are only expecting the Lifetime Element.
|
||||
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_LIFETIME_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected state = %d\n", pGetAuthTokenRespParse->state);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetAuthTokenRespStartElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
ConsumeElementData(
|
||||
IN GetAuthTokenRespParse *pGetAuthTokenRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len,
|
||||
INOUT char **ppElementData,
|
||||
INOUT int *pElementDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- Start\n", 0);
|
||||
|
||||
// Proceed based on whether or not we have already consumed data
|
||||
// for this element.
|
||||
if (*ppElementData == NULL)
|
||||
{
|
||||
// We have not yet consumed data for this element
|
||||
pGetAuthTokenRespParse->elementDataProcessed = len;
|
||||
|
||||
// Allocate a buffer to hold this element data (null terminated).
|
||||
*ppElementData = (char*) malloc(len + 1);
|
||||
if (*ppElementData)
|
||||
{
|
||||
memset(*ppElementData, 0, len + 1);
|
||||
memcpy(*ppElementData, s, len);
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pGetAuthTokenRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pNewBuf;
|
||||
|
||||
// We have already received token data, append this data to it.
|
||||
pNewBuf = (char*) malloc(pGetAuthTokenRespParse->elementDataProcessed + len + 1);
|
||||
if (pNewBuf)
|
||||
{
|
||||
memset(pNewBuf,
|
||||
0,
|
||||
pGetAuthTokenRespParse->elementDataProcessed + len + 1);
|
||||
memcpy(pNewBuf,
|
||||
*ppElementData,
|
||||
pGetAuthTokenRespParse->elementDataProcessed);
|
||||
memcpy(pNewBuf + pGetAuthTokenRespParse->elementDataProcessed, s, len);
|
||||
pGetAuthTokenRespParse->elementDataProcessed += len;
|
||||
|
||||
// Swap the buffers
|
||||
free(*ppElementData);
|
||||
*ppElementData = pNewBuf;
|
||||
|
||||
// Return the length of the element data buffer
|
||||
*pElementDataLen = pGetAuthTokenRespParse->elementDataProcessed + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ConsumeElementData- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(3, "-ConsumeElementData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthTokenRespCharDataHandler(
|
||||
IN GetAuthTokenRespParse *pGetAuthTokenRespParse,
|
||||
IN const XML_Char *s,
|
||||
IN int len)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthTokenRespCharDataHandler- Start\n", 0);
|
||||
|
||||
// Just exit if being called to process white space
|
||||
if (*s == '\n' || *s == '\r' || *s == '\t' || *s == ' ')
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthTokenRespParse->state)
|
||||
{
|
||||
case AWAITING_DESCRIPTION_DATA:
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// Ignore the status description data for now.
|
||||
// tbd
|
||||
|
||||
// Advanced to the next state
|
||||
pGetAuthTokenRespParse->state = AWAITING_DESCRIPTION_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_DATA:
|
||||
|
||||
// Set the appropriate status in the AuthenticationResp based on the
|
||||
// returned status.
|
||||
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthTokenRespParse->status = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_AUTHENTICATION_FAILURE);
|
||||
}
|
||||
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
|
||||
{
|
||||
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_SERVER_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespCharDataHandler- Un-expected status\n", 0);
|
||||
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Advanced to the next state
|
||||
pGetAuthTokenRespParse->state = AWAITING_STATUS_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_DATA:
|
||||
|
||||
// Convert the lifetime string to a numeric value
|
||||
pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLifetime = dtoul(s, len);
|
||||
|
||||
// Advanced to the next state
|
||||
pGetAuthTokenRespParse->state = AWAITING_LIFETIME_ELEMENT_END;
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_TOKEN_DATA:
|
||||
case AWAITING_AUTH_TOKEN_ELEMENT_END:
|
||||
|
||||
// Consume the data
|
||||
pGetAuthTokenRespParse->status = ConsumeElementData(pGetAuthTokenRespParse,
|
||||
s,
|
||||
len,
|
||||
&pGetAuthTokenRespParse->pGetAuthTokenResp->pToken,
|
||||
&pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLen);
|
||||
if (CASA_SUCCESS(pGetAuthTokenRespParse->status))
|
||||
{
|
||||
// Advanced to the next state
|
||||
pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthTokenRespCharDataHandler- Un-expected state = %d\n", pGetAuthTokenRespParse->state);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(2, "-GetAuthTokenRespCharDataHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void XMLCALL
|
||||
GetAuthTokenRespEndElementHandler(
|
||||
IN GetAuthTokenRespParse *pGetAuthTokenRespParse,
|
||||
IN const XML_Char *name)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-GetAuthTokenRespEndElementHandler- Start\n", 0);
|
||||
|
||||
// Proceed based on the state
|
||||
switch (pGetAuthTokenRespParse->state)
|
||||
{
|
||||
case AWAITING_ROOT_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Get Authentication
|
||||
// Token Response Element.
|
||||
if (strcmp(name, GET_AUTH_TOKEN_RESPONSE_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Done.
|
||||
pGetAuthTokenRespParse->state = DONE_PARSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespEndHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_DESCRIPTION_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Description Element.
|
||||
if (strcmp(name, DESCRIPTION_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_STATUS_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected end element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_STATUS_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Status Element.
|
||||
if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state based on the status code.
|
||||
if (CASA_SUCCESS(pGetAuthTokenRespParse->status))
|
||||
{
|
||||
// The request completed successfully
|
||||
pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_ELEMENT_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
pGetAuthTokenRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_LIFETIME_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Lifetime Element.
|
||||
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case AWAITING_AUTH_TOKEN_ELEMENT_END:
|
||||
|
||||
// In this state, we are only expecting the Authentication Token Element.
|
||||
if (strcmp(name, AUTH_TOKEN_ELEMENT_NAME) == 0)
|
||||
{
|
||||
// Good, advance to the next state.
|
||||
pGetAuthTokenRespParse->state = AWAITING_ROOT_ELEMENT_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected state = %d\n", pGetAuthTokenRespParse->state);
|
||||
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetAuthTokenRespEndElementHandler- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateGetAuthTokenResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT GetAuthTokenResp **ppGetAuthTokenResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
GetAuthTokenRespParse getAuthTokenRespParse = {0};
|
||||
GetAuthTokenResp *pGetAuthTokenResp;
|
||||
|
||||
DbgTrace(1, "-CreateGetAuthTokenResp- Start\n", 0);
|
||||
|
||||
/*
|
||||
* When a get authentication token request is processed successfully, the
|
||||
* server replies to the client with a message with the following format:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_token_resp>
|
||||
* <status><description>ok</description>200</status>
|
||||
* <auth_token><lifetime>lifetime value</lifetime>session token data</auth_token>
|
||||
* </get_auth_token_resp>
|
||||
*
|
||||
* When a get authentication token request fails to be successfully processed,
|
||||
* the server responds with an error and an error description string. The message
|
||||
* format of an unsuccessful reply is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_token_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_token_resp>
|
||||
*
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
|
||||
// Allocate GetAuthTokenResp object
|
||||
pGetAuthTokenResp = malloc(sizeof(*pGetAuthTokenResp));
|
||||
if (pGetAuthTokenResp)
|
||||
{
|
||||
XML_Parser p;
|
||||
|
||||
// Initialize the GetAuthTokenResp object and set it in the
|
||||
// parse oject.
|
||||
memset(pGetAuthTokenResp, 0, sizeof(*pGetAuthTokenResp));
|
||||
getAuthTokenRespParse.pGetAuthTokenResp = pGetAuthTokenResp;
|
||||
|
||||
// Create parser
|
||||
p = XML_ParserCreate(NULL);
|
||||
if (p)
|
||||
{
|
||||
// Keep track of the parser in our parse object
|
||||
getAuthTokenRespParse.p = p;
|
||||
|
||||
// Initialize the status within the parse object
|
||||
getAuthTokenRespParse.status = CASA_STATUS_SUCCESS;
|
||||
|
||||
// Set the start and end element handlers
|
||||
XML_SetElementHandler(p,
|
||||
(XML_StartElementHandler) GetAuthTokenRespStartElementHandler,
|
||||
(XML_EndElementHandler) GetAuthTokenRespEndElementHandler);
|
||||
|
||||
// Set the character data handler
|
||||
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthTokenRespCharDataHandler);
|
||||
|
||||
|
||||
// Set our user data
|
||||
XML_SetUserData(p, &getAuthTokenRespParse);
|
||||
|
||||
// Parse the document
|
||||
if (XML_Parse(p, pRespMsg, respLen, 1) == XML_STATUS_OK)
|
||||
{
|
||||
// Verify that the parse operation completed successfully
|
||||
if (getAuthTokenRespParse.state == DONE_PARSING)
|
||||
{
|
||||
// The parse operation succeded, obtain the status returned
|
||||
// by the server.
|
||||
retStatus = getAuthTokenRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthTokenResp- Parse operation did not complete\n", 0);
|
||||
|
||||
// Check if a status has been recorded
|
||||
if (getAuthTokenRespParse.status != CASA_STATUS_SUCCESS)
|
||||
{
|
||||
retStatus = getAuthTokenRespParse.status;
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthTokenResp- Parse error %d\n", XML_GetErrorCode(p));
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
// Free the parser
|
||||
XML_ParserFree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthTokenResp- Parser creation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Return the AuthenticationResp object to the caller if necessary
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
*ppGetAuthTokenResp = pGetAuthTokenResp;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(pGetAuthTokenResp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateGetAuthTokenResp- Memory allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
DbgTrace(1, "-CreateGetAuthTokenResp- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
RelGetAuthTokenResp(
|
||||
IN GetAuthTokenResp *pGetAuthTokenResp)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-RelGetAuthTokenResp- Start\n", 0);
|
||||
|
||||
// Free the resources associated with the object
|
||||
if (pGetAuthTokenResp->pToken)
|
||||
free(pGetAuthTokenResp->pToken);
|
||||
|
||||
free(pGetAuthTokenResp);
|
||||
|
||||
DbgTrace(1, "-RelGetAuthTokenResp- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
437
CASA-auth-token/client/core/internal.h
Normal file
437
CASA-auth-token/client/core/internal.h
Normal file
@@ -0,0 +1,437 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _INTERNAL_H_
|
||||
#define _INTERNAL_H_
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include "platform.h"
|
||||
#include <expat.h>
|
||||
#include <micasa_types.h>
|
||||
#include <casa_status.h>
|
||||
#include <casa_c_authtoken.h>
|
||||
#include "list_entry.h"
|
||||
#include "config_if.h"
|
||||
#include "mech_if.h"
|
||||
#include "proto.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Authentication Context structure
|
||||
//
|
||||
typedef struct _AuthContext
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pContext;
|
||||
int contextLen;
|
||||
char *pMechanism;
|
||||
int mechanismLen;
|
||||
char *pMechInfo;
|
||||
int mechInfoLen;
|
||||
|
||||
} AuthContext, *PAuthContext;
|
||||
|
||||
//
|
||||
// Authentication Policy structure
|
||||
//
|
||||
typedef struct _AuthPolicy
|
||||
{
|
||||
LIST_ENTRY authContextListHead;
|
||||
|
||||
} AuthPolicy, *PAuthPolicy;
|
||||
|
||||
//
|
||||
// Get Authentication Policy Response structure
|
||||
//
|
||||
typedef struct _GetAuthPolicyResp
|
||||
{
|
||||
char *pPolicy;
|
||||
int policyLen;
|
||||
|
||||
} GetAuthPolicyResp, *PGetAuthPolicyResp;
|
||||
|
||||
//
|
||||
// Get Authentication Token Response structure
|
||||
//
|
||||
typedef struct _GetAuthTokenResp
|
||||
{
|
||||
char *pToken;
|
||||
int tokenLen;
|
||||
int tokenLifetime;
|
||||
|
||||
} GetAuthTokenResp, *PGetAuthTokenResp;
|
||||
|
||||
//
|
||||
// Authenticate Response structure
|
||||
//
|
||||
typedef struct _AuthenticateResp
|
||||
{
|
||||
char *pToken;
|
||||
int tokenLen;
|
||||
int tokenLifetime;
|
||||
|
||||
} AuthenticateResp, *PAuthenticateResp;
|
||||
|
||||
//
|
||||
// Auth Cache Entry definition
|
||||
//
|
||||
typedef struct _AuthCacheEntry
|
||||
{
|
||||
int status;
|
||||
DWORD creationTime;
|
||||
DWORD expirationTime;
|
||||
bool doesNotExpire;
|
||||
char token[1];
|
||||
|
||||
} AuthCacheEntry, *PAuthCacheEntry;
|
||||
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
extern int DebugLevel;
|
||||
|
||||
extern char clientConfigFolder[];
|
||||
|
||||
extern char mechConfigFolder[];
|
||||
|
||||
extern char pathCharString[];
|
||||
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
//
|
||||
// Functions exported by engine.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
ObtainAuthTokenInt(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
INOUT char *pAuthTokenBuf,
|
||||
INOUT int *pAuthTokenBufLen,
|
||||
IN void *pCredStoreScope);
|
||||
|
||||
//
|
||||
// Functions exported by authmech.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
GetAuthMechToken(
|
||||
IN AuthContext *pAuthContext,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char **ppAuthMechToken);
|
||||
|
||||
//
|
||||
// Functions exported by getpolicymsg.c
|
||||
//
|
||||
|
||||
extern
|
||||
char*
|
||||
BuildGetAuthPolicyMsg(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
CreateGetAuthPolicyResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT GetAuthPolicyResp **ppGetAuthPolicyResp);
|
||||
|
||||
extern
|
||||
void
|
||||
RelGetAuthPolicyResp(
|
||||
IN GetAuthPolicyResp *pGetAuthPolicyResp);
|
||||
|
||||
//
|
||||
// Functions exported by authpolicy.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
CreateAuthPolicy(
|
||||
IN char *pEncodedData,
|
||||
IN int encodedDataLen,
|
||||
INOUT AuthPolicy **ppAuthPolicy);
|
||||
|
||||
extern
|
||||
void
|
||||
RelAuthPolicy(
|
||||
IN AuthPolicy *pAuthPolicy);
|
||||
|
||||
//
|
||||
// Functions exported by authmsg.c
|
||||
//
|
||||
|
||||
extern
|
||||
char*
|
||||
BuildAuthenticateMsg(
|
||||
IN AuthContext *pAuthContext,
|
||||
IN char *pAuthMechToken);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
CreateAuthenticateResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT AuthenticateResp **ppAuthenticateResp);
|
||||
|
||||
extern
|
||||
void
|
||||
RelAuthenticateResp(
|
||||
IN AuthenticateResp *pAuthenticateResp);
|
||||
|
||||
//
|
||||
// Functions exported by gettokenmsg.c
|
||||
//
|
||||
|
||||
extern
|
||||
char*
|
||||
BuildGetAuthTokenMsg(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
IN char *pSessionToken);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
CreateGetAuthTokenResp(
|
||||
IN char *pRespMsg,
|
||||
IN int respLen,
|
||||
INOUT GetAuthTokenResp **ppGetAuthTokenResp);
|
||||
|
||||
extern
|
||||
void
|
||||
RelGetAuthTokenResp(
|
||||
IN GetAuthTokenResp *pGetAuthTokenResp);
|
||||
|
||||
//
|
||||
// Functions exported by cache.c
|
||||
//
|
||||
|
||||
extern
|
||||
AuthCacheEntry*
|
||||
CreateSessionTokenCacheEntry(
|
||||
IN const char *pCacheKey,
|
||||
IN CasaStatus status,
|
||||
IN char *pToken,
|
||||
IN int entryLifetime,
|
||||
IN void *pCredStoreScope);
|
||||
|
||||
extern
|
||||
AuthCacheEntry*
|
||||
CreateAuthTokenCacheEntry(
|
||||
IN const char *pCacheKey,
|
||||
IN const char *pHostName,
|
||||
IN CasaStatus status,
|
||||
IN char *pToken,
|
||||
IN int entryLifetime,
|
||||
IN void *pCredStoreScope);
|
||||
|
||||
extern
|
||||
void
|
||||
FreeAuthCacheEntry(
|
||||
IN AuthCacheEntry *pEntry);
|
||||
|
||||
extern
|
||||
AuthCacheEntry*
|
||||
FindSessionTokenEntryInCache(
|
||||
IN const char *pCacheKey,
|
||||
IN void *pCredStoreScope);
|
||||
|
||||
extern
|
||||
AuthCacheEntry*
|
||||
FindAuthTokenEntryInCache(
|
||||
IN const char *pCacheKey,
|
||||
IN const char *pGroupOrHostName,
|
||||
IN void *pCredStoreScope);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
InitializeAuthCache(void);
|
||||
|
||||
//
|
||||
// Functions exported by config.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
GetConfigInterface(
|
||||
IN const char *pConfigFolder,
|
||||
IN const char *pConfigName,
|
||||
INOUT ConfigIf **ppConfigIf);
|
||||
|
||||
//
|
||||
// Functions exported by platform.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
CreateUserMutex(
|
||||
HANDLE *phMutex
|
||||
);
|
||||
|
||||
extern
|
||||
void
|
||||
AcquireUserMutex(
|
||||
HANDLE hMutex
|
||||
);
|
||||
|
||||
extern
|
||||
void
|
||||
ReleaseUserMutex(
|
||||
HANDLE hMutex
|
||||
);
|
||||
|
||||
extern
|
||||
void
|
||||
DestroyUserMutex(
|
||||
HANDLE hMutex
|
||||
);
|
||||
|
||||
extern
|
||||
LIB_HANDLE
|
||||
OpenLibrary(
|
||||
IN char *pFileName);
|
||||
|
||||
extern
|
||||
void
|
||||
CloseLibrary(
|
||||
IN LIB_HANDLE libHandle);
|
||||
|
||||
extern
|
||||
void*
|
||||
GetFunctionPtr(
|
||||
IN LIB_HANDLE libHandle,
|
||||
IN char *pFunctionName);
|
||||
|
||||
extern
|
||||
char*
|
||||
NormalizeHostName(
|
||||
IN const char *pHostName);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
InitializeHostNameNormalization(void);
|
||||
|
||||
//
|
||||
// Functions exported by rpc.c
|
||||
//
|
||||
|
||||
extern
|
||||
RpcSession*
|
||||
OpenRpcSession(
|
||||
IN const char *pHostName,
|
||||
IN const uint16_t hostPort);
|
||||
|
||||
extern
|
||||
void
|
||||
CloseRpcSession(
|
||||
IN RpcSession *pSession);
|
||||
|
||||
#define SECURE_RPC_FLAG 1
|
||||
#define ALLOW_INVALID_CERTS_RPC_FLAG 2
|
||||
#define ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG 4
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
Rpc(
|
||||
IN RpcSession *pSession,
|
||||
IN char *pMethod,
|
||||
IN long flags,
|
||||
IN char *pRequestData,
|
||||
INOUT char **ppResponseData,
|
||||
INOUT int *pResponseDataLen);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
InitializeRpc(void);
|
||||
|
||||
//
|
||||
// Functions exported by utils.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen);
|
||||
|
||||
extern
|
||||
int
|
||||
dtoul(
|
||||
IN const char *cp,
|
||||
IN const int len);
|
||||
|
||||
//
|
||||
// Functions exported by invalidcert.c
|
||||
//
|
||||
|
||||
extern
|
||||
bool
|
||||
InvalidCertsFromHostAllowed(
|
||||
IN char *pHostName);
|
||||
|
||||
extern
|
||||
void
|
||||
AllowInvalidCertsFromHost(
|
||||
IN char *pHostName);
|
||||
|
||||
#define INVALID_CERT_CA_FLAG 1
|
||||
#define INVALID_CERT_CN_FLAG 2
|
||||
#define INVALID_CERT_DATE_FLAG 4
|
||||
|
||||
extern
|
||||
bool
|
||||
UserApprovedCert(
|
||||
IN char *pHostName,
|
||||
IN char *pCertSubject,
|
||||
IN char *pCertIssuer,
|
||||
IN long invalidCertFlags);
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
#endif // _INTERNAL_H_
|
||||
|
||||
140
CASA-auth-token/client/core/invalidcert.c
Normal file
140
CASA-auth-token/client/core/invalidcert.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//++=======================================================================
|
||||
bool
|
||||
InvalidCertsFromHostAllowed(
|
||||
IN char *pHostName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L0
|
||||
//=======================================================================--
|
||||
{
|
||||
bool retStatus = false;
|
||||
|
||||
DbgTrace(2, "-InvalidCertsFromHostAllowed- Start\n", 0);
|
||||
|
||||
// tbd
|
||||
|
||||
DbgTrace(2, "-InvalidCertsFromHostAllowed- End, retStatus = %0X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
AllowInvalidCertsFromHost(
|
||||
IN char *pHostName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L0
|
||||
//=======================================================================--
|
||||
{
|
||||
bool retStatus = true;
|
||||
|
||||
DbgTrace(2, "-AllowInvalidCertsFromHost- Start\n", 0);
|
||||
|
||||
// tbd
|
||||
|
||||
DbgTrace(2, "-AllowInvalidCertsFromHost- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
bool
|
||||
UserApprovedCert(
|
||||
IN char *pHostName,
|
||||
IN char *pCertSubject,
|
||||
IN char *pCertIssuer,
|
||||
IN long invalidCertFlags)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L0
|
||||
//=======================================================================--
|
||||
{
|
||||
bool retStatus = false;
|
||||
|
||||
DbgTrace(2, "-UserApprovedCert- Start\n", 0);
|
||||
|
||||
// tbd
|
||||
|
||||
if (invalidCertFlags & INVALID_CERT_CN_FLAG)
|
||||
{
|
||||
DbgTrace(0, "-UserApprovedCert- Invalid Cert from Host = %s\n", pHostName);
|
||||
}
|
||||
if (invalidCertFlags & INVALID_CERT_CA_FLAG)
|
||||
{
|
||||
DbgTrace(0, "-UserApprovedCert- Invalid CA in Cert from Host = %s\n", pHostName);
|
||||
}
|
||||
if (invalidCertFlags & INVALID_CERT_DATE_FLAG)
|
||||
{
|
||||
DbgTrace(0, "-UserApprovedCert- Invalid DATE in Cert from Host = %s\n", pHostName);
|
||||
}
|
||||
DbgTrace(0, "-UserApprovedCert- Approving Invalid Cert from Host = %s\n", pHostName);
|
||||
DbgTrace(0, "-UserApprovedCert- Invalid Cert Subject = %s\n", pCertSubject);
|
||||
DbgTrace(0, "-UserApprovedCert- Invalid Cert Issuer = %s\n", pCertIssuer);
|
||||
|
||||
DbgTrace(2, "-UserApprovedCert- End, retStatus = %0X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
126
CASA-auth-token/client/core/linux/Makefile.am
Normal file
126
CASA-auth-token/client/core/linux/Makefile.am
Normal file
@@ -0,0 +1,126 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
CFLAGS += -v -w
|
||||
DEFINES = -DDBG
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEFINES = -DNDEBUG
|
||||
endif
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
ROOT = ../..
|
||||
|
||||
LIBDIR = $(ROOT)/$(LIB)
|
||||
|
||||
# handle Mono secondary dependencies
|
||||
export MONO_PATH := $(MONO_PATH)
|
||||
|
||||
PLATFORMINDEPENDENTSOURCEDIR = ..
|
||||
PLATFORMDEPENDENTSOURCEDIR = .
|
||||
|
||||
MODULE_NAME = libcasa_c_authtoken
|
||||
MODULE_EXT = so
|
||||
|
||||
CFILES = ../authmech.c \
|
||||
../authmsg.c \
|
||||
../authpolicy.c \
|
||||
../cache.c \
|
||||
../config.c \
|
||||
../engine.c \
|
||||
../getpolicymsg.c \
|
||||
../gettokenmsg.c \
|
||||
../util.c \
|
||||
../invalidcert.c \
|
||||
rpc.c \
|
||||
platform.c
|
||||
|
||||
CSFILES_CSC :=
|
||||
INCLUDES = -I. -I.. -I../../include
|
||||
RESOURCES =
|
||||
|
||||
if LIB64
|
||||
DEFINES += -D_LIB64
|
||||
endif
|
||||
|
||||
CFLAGS += -Wno-format-extra-args -fno-strict-aliasing $(INCLUDES) $(DEFINES)
|
||||
LIBS = -lpthread -ldl -lexpat -lcurl -lidn -lssl -lcrypto -lz -lmicasa
|
||||
LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) -L$(ROOT)/lib/$(TARGET_CFG)
|
||||
|
||||
OBJDIR = ./$(TARGET_CFG)/$(LIB)
|
||||
OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o))
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h
|
||||
|
||||
CUR_DIR := $(shell pwd)
|
||||
|
||||
all: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
|
||||
#
|
||||
# Pattern based rules.
|
||||
#
|
||||
vpath %.c $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
vpath %.cpp $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT): $(OBJDIR) $(OBJS)
|
||||
@echo [======== Linking $@ ========]
|
||||
$(LINK) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
|
||||
cp -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(LIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
|
||||
$(OBJDIR):
|
||||
[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR)
|
||||
[ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
|
||||
[ -d $(LIBDIR)/$(TARGET_CFG) ] || mkdir -p $(LIBDIR)/$(TARGET_CFG)
|
||||
|
||||
|
||||
install-exec-local: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
$(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
$(INSTALL_PROGRAM) $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(DESTDIR)$(libdir)/
|
||||
|
||||
uninstall-local:
|
||||
cd $(DESTDIR)$(libdir); rm -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
rmdir $(DESTDIR)$(libdir)
|
||||
|
||||
#installcheck-local: install
|
||||
# $(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
# $(INSTALL_PROGRAM) $(DESTDIR)$(libdir)
|
||||
# cd $(DESTDIR)$(libdir); $(MONO)
|
||||
|
||||
clean-local:
|
||||
if [ -d $(TARGET_CFG) ]; then rm -rf $(TARGET_CFG); fi
|
||||
|
||||
distclean-local:
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
831
CASA-auth-token/client/core/linux/platform.c
Normal file
831
CASA-auth-token/client/core/linux/platform.c
Normal file
@@ -0,0 +1,831 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Normalized Host Name Cache Entry definition
|
||||
//
|
||||
typedef struct _NormalizedHostNameCacheEntry
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pHostName;
|
||||
char *pNormalizedHostName;
|
||||
int buffLengthRequired;
|
||||
|
||||
} NormalizedHostNameCacheEntry, *PNormalizedHostNameCacheEntry;
|
||||
|
||||
|
||||
//===[ Type definitions for Local_sem ]====================================
|
||||
//
|
||||
// Notes: Most of the code for this definitions and the Local_sem_xxxx
|
||||
// functions was copied with minor modifications from W. Richard
|
||||
// Stevens book: UNIX Network Programming, Interprocess
|
||||
// Communications (Printed in 1999).
|
||||
//
|
||||
// You may ask, why not just use Posix Named Semaphores? The answer
|
||||
// is that I wish that I could but I can not tolerate that they are
|
||||
// not released when the process that holds them terminates abnormally.
|
||||
//
|
||||
|
||||
union semun /* define union for semctl() */
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short *array;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sem_semid; /* the System V semaphore ID */
|
||||
int sem_magic; /* magic number if open */
|
||||
|
||||
} Local_sem_t;
|
||||
|
||||
#ifndef SEM_R
|
||||
#define SEM_R 0400
|
||||
#endif
|
||||
|
||||
#ifndef SEM_A
|
||||
#define SEM_A 0200
|
||||
#endif
|
||||
|
||||
#define SVSEM_MODE (SEM_R | SEM_A | SEM_R>>3 | SEM_R>>6)
|
||||
|
||||
#define SEM_MAGIC 0x45678923
|
||||
|
||||
#define SEM_FAILED ((Local_sem_t *)(-1)) /* avoid compiler warnings */
|
||||
|
||||
#ifndef SEMVMX
|
||||
#define SEMVMX 32767 /* historical System V max value for sem */
|
||||
#endif
|
||||
|
||||
#define MAX_OPEN_SEM_TRIES 10 /* for waiting for initialization */
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Normalized host name cache variables
|
||||
static
|
||||
LIST_ENTRY normalizedHostNameCacheListHead;
|
||||
|
||||
static
|
||||
pthread_mutex_t g_hNormalizedHostNameCacheMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// Client configuration file folder
|
||||
char clientConfigFolder[] = "/etc/CASA/authtoken/client";
|
||||
|
||||
// Authentication mechanism configuration file folder
|
||||
char mechConfigFolder[] = "/etc/CASA/authtoken/client/mechanisms";
|
||||
|
||||
// Module Synchronization mutex
|
||||
pthread_mutex_t g_hModuleMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// Path separator
|
||||
char pathCharString[] = "/";
|
||||
|
||||
// Milliseconds per System Tick
|
||||
static
|
||||
long g_milliSecondsPerTicks = 0;
|
||||
|
||||
// Named Semaphore for user variables
|
||||
static
|
||||
char g_userNamedSemName[256];
|
||||
|
||||
static
|
||||
Local_sem_t *g_userNamedSem = SEM_FAILED;
|
||||
|
||||
static
|
||||
bool g_userNamedSemAcquired = false;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
Local_sem_t*
|
||||
Local_sem_open(const char *pathname, int oflag, ... )
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes: Most of the code for this routine was copied with minor
|
||||
// modifications from W. Richard Stevens book: UNIX Network
|
||||
// Programming, Interprocess Communications (Printed in 1999).
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int i, fd, semflag, semid, save_errno;
|
||||
key_t key;
|
||||
mode_t mode;
|
||||
va_list ap;
|
||||
Local_sem_t *sem;
|
||||
union semun arg;
|
||||
unsigned int value;
|
||||
struct semid_ds seminfo;
|
||||
struct sembuf initop;
|
||||
|
||||
/* 4no mode for sem_open() w/out O_CREAT; guess */
|
||||
semflag = SVSEM_MODE;
|
||||
semid = -1;
|
||||
|
||||
if (oflag & O_CREAT) {
|
||||
va_start(ap, oflag); /* init ap to final named argument */
|
||||
mode = va_arg(ap, mode_t);
|
||||
value = va_arg(ap, unsigned int);
|
||||
va_end(ap);
|
||||
|
||||
/* 4convert to key that will identify System V semaphore */
|
||||
if ( (fd = open(pathname, oflag, mode)) == -1)
|
||||
return(SEM_FAILED);
|
||||
close(fd);
|
||||
if ( (key = ftok(pathname, 0)) == (key_t) -1)
|
||||
return(SEM_FAILED);
|
||||
|
||||
semflag = IPC_CREAT | (mode & 0777);
|
||||
if (oflag & O_EXCL)
|
||||
semflag |= IPC_EXCL;
|
||||
|
||||
/* 4create the System V semaphore with IPC_EXCL */
|
||||
if ( (semid = semget(key, 1, semflag | IPC_EXCL)) >= 0) {
|
||||
/* 4success, we're the first so initialize to 0 */
|
||||
arg.val = 0;
|
||||
if (semctl(semid, 0, SETVAL, arg) == -1)
|
||||
goto err;
|
||||
/* 4then increment by value to set sem_otime nonzero */
|
||||
if (value > SEMVMX) {
|
||||
errno = EINVAL;
|
||||
goto err;
|
||||
}
|
||||
initop.sem_num = 0;
|
||||
initop.sem_op = value;
|
||||
initop.sem_flg = 0;
|
||||
if (semop(semid, &initop, 1) == -1)
|
||||
goto err;
|
||||
goto finish;
|
||||
|
||||
} else if (errno != EEXIST || (semflag & IPC_EXCL) != 0)
|
||||
goto err;
|
||||
/* else fall through */
|
||||
}
|
||||
|
||||
/*
|
||||
* (O_CREAT not secified) or
|
||||
* (O_CREAT without O_EXCL and semaphore already exists).
|
||||
* Must open semaphore and make certain it has been initialized.
|
||||
*/
|
||||
if ( (key = ftok(pathname, 0)) == (key_t) -1)
|
||||
goto err;
|
||||
if ( (semid = semget(key, 0, semflag)) == -1)
|
||||
goto err;
|
||||
|
||||
arg.buf = &seminfo;
|
||||
for (i = 0; i < MAX_OPEN_SEM_TRIES; i++) {
|
||||
if (semctl(semid, 0, IPC_STAT, arg) == -1)
|
||||
goto err;
|
||||
if (arg.buf->sem_otime != 0)
|
||||
goto finish;
|
||||
sleep(1);
|
||||
}
|
||||
errno = ETIMEDOUT;
|
||||
err:
|
||||
save_errno = errno; /* don't let semctl() change errno */
|
||||
if (semid != -1)
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
errno = save_errno;
|
||||
return(SEM_FAILED);
|
||||
|
||||
finish:
|
||||
if ( (sem = malloc(sizeof(Local_sem_t))) == NULL)
|
||||
goto err;
|
||||
sem->sem_semid = semid;
|
||||
sem->sem_magic = SEM_MAGIC;
|
||||
return(sem);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
Local_sem_wait(Local_sem_t *sem)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes: Most of the code for this routine was copied with minor
|
||||
// modifications from W. Richard Stevens book: UNIX Network
|
||||
// Programming, Interprocess Communications (Printed in 1999).
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
struct sembuf op;
|
||||
|
||||
if (sem->sem_magic != SEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
op.sem_num = 0;
|
||||
op.sem_op = -1;
|
||||
//op.sem_flg = 0;
|
||||
op.sem_flg = SEM_UNDO; // Deviation from Richard's to allow cleanup in case of abnormal termination.
|
||||
if (semop(sem->sem_semid, &op, 1) < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
Local_sem_post(Local_sem_t *sem)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes: Most of the code for this routine was copied with minor
|
||||
// modifications from W. Richard Stevens book: UNIX Network
|
||||
// Programming, Interprocess Communications (Printed in 1999).
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
struct sembuf op;
|
||||
|
||||
if (sem->sem_magic != SEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
op.sem_num = 0;
|
||||
op.sem_op = 1;
|
||||
op.sem_flg = 0;
|
||||
if (semop(sem->sem_semid, &op, 1) < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
Local_sem_close(Local_sem_t *sem)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes: Most of the code for this routine was copied with minor
|
||||
// modifications from W. Richard Stevens book: UNIX Network
|
||||
// Programming, Interprocess Communications (Printed in 1999).
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
if (sem->sem_magic != SEM_MAGIC) {
|
||||
errno = EINVAL;
|
||||
return(-1);
|
||||
}
|
||||
sem->sem_magic = 0; /* just in case */
|
||||
|
||||
free(sem);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
DWORD
|
||||
GetTickCount(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
struct tms tm;
|
||||
DWORD tickCount;
|
||||
|
||||
DbgTrace(2, "-GetTickCount- Start\n", 0);
|
||||
|
||||
// Determine milliseconds per tick if we have not done already
|
||||
if (g_milliSecondsPerTicks == 0)
|
||||
{
|
||||
long ticksPerSecond;
|
||||
|
||||
ticksPerSecond = sysconf(_SC_CLK_TCK);
|
||||
DbgTrace(3, "-GetTickCount- TicksPerSec = %0lX\n", ticksPerSecond);
|
||||
g_milliSecondsPerTicks = 1000 / ticksPerSecond;
|
||||
}
|
||||
|
||||
// Determine the tickCount as milliseconds
|
||||
tickCount = g_milliSecondsPerTicks * times(&tm);
|
||||
|
||||
DbgTrace(2, "-GetTickCount- End, retValue = %0lX\n", tickCount);
|
||||
|
||||
return tickCount;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateUserMutex(
|
||||
HANDLE *phMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
|
||||
DbgTrace(1, "-CreateUserMutex- Start\n", 0);
|
||||
|
||||
// We use Named Semaphores to provide this functionality. The semaphore names are
|
||||
// linked to the user via its uid.
|
||||
if (sprintf(g_userNamedSemName, "/var/lib/CASA/authtoken/semuser_%d", geteuid()) != -1)
|
||||
{
|
||||
// Create or open semaphore to be only used by the effective user
|
||||
g_userNamedSem = Local_sem_open((const char*) g_userNamedSemName, O_RDWR | O_CREAT, 0600, 1);
|
||||
if (g_userNamedSem == SEM_FAILED)
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- Error opening named semaphore, errno = %d\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- sprintf failed, error = %d\n", errno);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateUserMutex- End, retStatus\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
AcquireUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AcquireUserMutex- Start\n", 0);
|
||||
|
||||
// Wait on the named semaphore
|
||||
if (Local_sem_wait(g_userNamedSem) != 0)
|
||||
{
|
||||
DbgTrace(0, "-AcquireUserMutex- Error returned by sem_wait(), errno = %d\n", errno);
|
||||
}
|
||||
|
||||
// The user semaphore has been acquired
|
||||
g_userNamedSemAcquired = true;
|
||||
|
||||
DbgTrace(2, "-AcquireUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
ReleaseUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-ReleaseUserMutex- Start\n", 0);
|
||||
|
||||
// The user semaphore is no longer acquired
|
||||
g_userNamedSemAcquired = false;
|
||||
|
||||
// Post on the named semaphore
|
||||
if (Local_sem_post(g_userNamedSem) != 0)
|
||||
{
|
||||
DbgTrace(0, "-ReleaseUserMutex- Error returned by sem_post(), errno = %d\n", errno);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-ReleaseUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
DestroyUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-DestroyUserMutex- Start\n", 0);
|
||||
|
||||
// Do not do anything if the named semaphore is invalid
|
||||
if (g_userNamedSem != SEM_FAILED)
|
||||
{
|
||||
// Close the named semaphore. Note that we want user semaphores to
|
||||
// hang around, therefore we will not unlink them. This is per-design as
|
||||
// is not a resource leak. If someone has an issue with this, then it can
|
||||
// be solved by installing a cron job that cleans up the semaphores for
|
||||
// deleted users.
|
||||
if (Local_sem_close(g_userNamedSem) != 0)
|
||||
{
|
||||
DbgTrace(0, "-DestroyUserMutex- Error returned by sem_close(), errno = %d\n", errno);
|
||||
}
|
||||
|
||||
// Forget about the semaphore
|
||||
g_userNamedSem = SEM_FAILED;
|
||||
}
|
||||
|
||||
DbgTrace(2, "-DestroyUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
LIB_HANDLE
|
||||
OpenLibrary(
|
||||
IN char *pFileName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
LIB_HANDLE libHandle;
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- Start\n", 0);
|
||||
|
||||
libHandle = dlopen(pFileName, RTLD_LAZY);
|
||||
if (libHandle == NULL)
|
||||
{
|
||||
DbgTrace(0, "-OpenLibrary- Not able to load library, error = %s\n", dlerror());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- End, handle = %0lX\n", (long) libHandle);
|
||||
|
||||
return libHandle;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
CloseLibrary(
|
||||
IN LIB_HANDLE libHandle)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-CloseLibrary- Start\n", 0);
|
||||
|
||||
dlclose(libHandle);
|
||||
|
||||
DbgTrace(1, "-CloseLibrary- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void*
|
||||
GetFunctionPtr(
|
||||
IN LIB_HANDLE libHandle,
|
||||
IN char *pFunctionName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
void *pFuncPtr;
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- Start\n", 0);
|
||||
|
||||
pFuncPtr = dlsym(libHandle, pFunctionName);
|
||||
if (pFuncPtr == NULL)
|
||||
{
|
||||
DbgTrace(0, "-GetFunctionPtr- Not able to obtain func ptr, error = %s\n", dlerror());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- End, pFuncPtr = %0lX\n", (long) pFuncPtr);
|
||||
|
||||
return pFuncPtr;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
char*
|
||||
NormalizeHostName(
|
||||
IN const char *pHostName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pNormalizedName = NULL;
|
||||
LIST_ENTRY *pListEntry;
|
||||
NormalizedHostNameCacheEntry *pEntry = NULL;
|
||||
|
||||
DbgTrace(1, "-NormalizeHostName- Start\n", 0);
|
||||
|
||||
// Obtain our synchronization mutex
|
||||
pthread_mutex_lock(&g_hNormalizedHostNameCacheMutex);
|
||||
|
||||
// First try to find an entry in the normalized host name cache
|
||||
// for the host name provided.
|
||||
pListEntry = normalizedHostNameCacheListHead.Flink;
|
||||
while (pListEntry != &normalizedHostNameCacheListHead)
|
||||
{
|
||||
// Get pointer to the entry
|
||||
pEntry = CONTAINING_RECORD(pListEntry, NormalizedHostNameCacheEntry, listEntry);
|
||||
|
||||
// Check if the entry is for the host name
|
||||
if (strcmp(pHostName, pEntry->pHostName) == 0)
|
||||
{
|
||||
// This entry corresponds to the given host name
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entry does not correspond to the given host name
|
||||
pEntry = NULL;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Check if we found an entry in our cache for the given host name
|
||||
if (pEntry)
|
||||
{
|
||||
// Entry found, obtain the normalized name from it.
|
||||
pNormalizedName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pNormalizedName)
|
||||
{
|
||||
// Copy the normalized name onto the allocated buffer
|
||||
strcpy(pNormalizedName, pEntry->pNormalizedHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// An entry was not found in our cache, create one.
|
||||
pEntry = (NormalizedHostNameCacheEntry*) malloc(sizeof(NormalizedHostNameCacheEntry));
|
||||
if (pEntry)
|
||||
{
|
||||
// Zero the entry
|
||||
memset(pEntry, 0, sizeof(*pEntry));
|
||||
|
||||
// Allocate a buffer to hold the host name in the entry
|
||||
pEntry->pHostName = (char*) malloc(strlen(pHostName) + 1);
|
||||
if (pEntry->pHostName)
|
||||
{
|
||||
struct hostent *pLookupResult;
|
||||
struct sockaddr_in sockAddr = {0};
|
||||
|
||||
// Copy the host name given into the allocated buffer
|
||||
strcpy(pEntry->pHostName, pHostName);
|
||||
|
||||
// Now try to resolve the normalized name
|
||||
pLookupResult = gethostbyname(pHostName);
|
||||
if (pLookupResult && pLookupResult->h_addrtype == AF_INET)
|
||||
{
|
||||
char dnsHostName[NI_MAXHOST];
|
||||
|
||||
// Set up a sockaddr structure
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]);
|
||||
|
||||
// Now try to resolve the name using DNS
|
||||
if (getnameinfo((const struct sockaddr*) &sockAddr,
|
||||
sizeof(sockAddr),
|
||||
dnsHostName,
|
||||
sizeof(dnsHostName),
|
||||
NULL,
|
||||
0,
|
||||
NI_NAMEREQD) == 0)
|
||||
{
|
||||
// We resolved the address to a DNS name, use it as the normalized name.
|
||||
pEntry->buffLengthRequired = (int) strlen(dnsHostName) + 1;
|
||||
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// Copy the dns name
|
||||
strcpy(pEntry->pNormalizedHostName, dnsHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- getnameInfo failed, error %d\n", errno);
|
||||
|
||||
// Not able to resolve the name in DNS, just use the host name as
|
||||
// the normalized name.
|
||||
pEntry->buffLengthRequired = (int) strlen(pHostName) + 1;
|
||||
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// Copy the host name
|
||||
strcpy(pEntry->pNormalizedHostName, pHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Name resolution failed, error = %d\n", errno);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
|
||||
// Free the space allocated for the entry
|
||||
free(pEntry);
|
||||
}
|
||||
|
||||
// Proceed based on whether or not we normalized the name
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// The name was normalized, save the entry in our cache.
|
||||
InsertHeadList(&normalizedHostNameCacheListHead, &pEntry->listEntry);
|
||||
|
||||
// Return the normalized name present in the entry
|
||||
pNormalizedName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pNormalizedName)
|
||||
{
|
||||
// Copy the normalized name onto the allocated buffer
|
||||
strcpy(pNormalizedName, pEntry->pNormalizedHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The host name was not normalized, free allocated resources.
|
||||
if (pEntry->pHostName)
|
||||
free(pEntry->pHostName);
|
||||
free(pEntry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Release our synchronization mutex
|
||||
pthread_mutex_unlock(&g_hNormalizedHostNameCacheMutex);
|
||||
|
||||
DbgTrace(1, "-NormalizeHostName- End, pNormalizedName = %0lX\n", (long) pNormalizedName);
|
||||
|
||||
return pNormalizedName;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
InitializeHostNameNormalization(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(1, "-InitializeHostNameNormalization- Start\n", 0);
|
||||
|
||||
// Initialize the cache list head
|
||||
InitializeListHead(&normalizedHostNameCacheListHead);
|
||||
|
||||
DbgTrace(1, "-InitializeHostNameNormalization- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
130
CASA-auth-token/client/core/linux/platform.h
Normal file
130
CASA-auth-token/client/core/linux/platform.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <curl/curl.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
_snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
fprintf(stderr, "CASA_AuthToken %s", printBuff); \
|
||||
} \
|
||||
}
|
||||
/*#define DbgTrace(LEVEL, X, Y) { \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
openlog("CASA_AuthToken", LOG_CONS | LOG_NOWAIT | LOG_ODELAY, LOG_USER); \
|
||||
syslog(LOG_USER | LOG_INFO, X, Y); \
|
||||
closelog(); \
|
||||
} \
|
||||
}*/
|
||||
|
||||
|
||||
//
|
||||
// Rpc Session definition
|
||||
//
|
||||
typedef struct _RpcSession
|
||||
{
|
||||
CURL *hCurl;
|
||||
char *pPartialHttpUrl;
|
||||
int partialHttpUrlLen;
|
||||
char *pPartialHttpsUrl;
|
||||
int partialHttpsUrlLen;
|
||||
struct curl_slist *headers;
|
||||
char *pRecvData;
|
||||
int recvDataLen;
|
||||
|
||||
} RpcSession, *PRpcSession;
|
||||
|
||||
|
||||
//
|
||||
// Other definitions
|
||||
//
|
||||
#define HANDLE void*
|
||||
#define LIB_HANDLE void*
|
||||
#define DWORD unsigned long
|
||||
|
||||
#define AcquireModuleMutex pthread_mutex_lock(&g_hModuleMutex)
|
||||
#define ReleaseModuleMutex pthread_mutex_unlock(&g_hModuleMutex)
|
||||
|
||||
//
|
||||
// Deal with function name mapping issues
|
||||
//
|
||||
#define _snprintf snprintf
|
||||
#define stricmp strcasecmp
|
||||
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
extern
|
||||
DWORD
|
||||
GetTickCount(void);
|
||||
|
||||
//===[ External data ]=====================================================
|
||||
|
||||
extern pthread_mutex_t g_hModuleMutex;
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
566
CASA-auth-token/client/core/linux/rpc.c
Normal file
566
CASA-auth-token/client/core/linux/rpc.c
Normal file
@@ -0,0 +1,566 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#define MAX_RPC_RETRIES 3
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
size_t
|
||||
CurlWriteCallback(
|
||||
IN void *pData,
|
||||
IN size_t dataItemSz,
|
||||
IN size_t numDataItems,
|
||||
IN RpcSession *pSession)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
size_t dataConsumed = numDataItems;
|
||||
|
||||
DbgTrace(1, "-CurlWriteCallback- Start\n", 0);
|
||||
|
||||
// Consume the data by keeping a copy of the data. Note that we may have
|
||||
// already consumed some data in which case we need to allocate a new
|
||||
// buffer big enough to hold all of it.
|
||||
if (pSession->pRecvData == NULL)
|
||||
{
|
||||
// We have not yet consumed receive data for the current Rpc
|
||||
pSession->pRecvData = (char*) malloc(numDataItems * dataItemSz);
|
||||
if (pSession->pRecvData)
|
||||
{
|
||||
// Consume the data
|
||||
memcpy(pSession->pRecvData, pData, numDataItems * dataItemSz);
|
||||
pSession->recvDataLen = numDataItems * dataItemSz;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CurlWriteCallback- Buffer allocation error\n", 0);
|
||||
dataConsumed = CURLE_WRITE_ERROR; // To abort RPC
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have already consumed receive data for the current Rpc, append the new data to it.
|
||||
char *pNewRecvDataBuf = (char*) malloc(pSession->recvDataLen + (numDataItems * dataItemSz));
|
||||
if (pNewRecvDataBuf)
|
||||
{
|
||||
memcpy(pNewRecvDataBuf, pSession->pRecvData, pSession->recvDataLen);
|
||||
memcpy(pNewRecvDataBuf + pSession->recvDataLen, pData, numDataItems * dataItemSz);
|
||||
pSession->recvDataLen += numDataItems * dataItemSz;
|
||||
free(pSession->pRecvData);
|
||||
pSession->pRecvData = pNewRecvDataBuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CurlWriteCallback- Buffer allocation error\n", 0);
|
||||
dataConsumed = CURLE_WRITE_ERROR; // To abort RPC
|
||||
|
||||
// Forget about already consumed data
|
||||
free(pSession->pRecvData);
|
||||
pSession->pRecvData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CurlWriteCallback- End\n", 0);
|
||||
|
||||
return dataConsumed;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
RpcSession*
|
||||
OpenRpcSession(
|
||||
IN const char *pHostName,
|
||||
IN const uint16_t hostPort)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
RpcSession *pSession = NULL;
|
||||
char *pPartialHttpUrl = NULL;
|
||||
char *pPartialHttpsUrl = NULL;
|
||||
int hostNameLen = strlen(pHostName);
|
||||
|
||||
DbgTrace(1, "-OpenRpcSession- Start\n", 0);
|
||||
|
||||
// Build the partial URL strings that may be used with this session.
|
||||
pPartialHttpUrl = (char*) malloc(7 /*"http://"*/ + hostNameLen + 34 /*":XXXX/CasaAuthTokenSvc/Rpc?method="*/ + 1 /*NULL Terminator*/);
|
||||
pPartialHttpsUrl = (char*) malloc(8 /*"https://"*/ + hostNameLen + 34 /*":XXXX/CasaAuthTokenSvc/Rpc?method="*/ + 1 /*NULL Terminator*/);
|
||||
if (pPartialHttpUrl && pPartialHttpsUrl)
|
||||
{
|
||||
sprintf(pPartialHttpUrl, "http://%s:%d/CasaAuthTokenSvc/Rpc?method=", pHostName, hostPort);
|
||||
sprintf(pPartialHttpsUrl, "https://%s:%d/CasaAuthTokenSvc/Rpc?method=", pHostName, hostPort);
|
||||
|
||||
// Allocate space for the session
|
||||
pSession = (RpcSession*) malloc(sizeof(*pSession));
|
||||
if (pSession)
|
||||
{
|
||||
// Zero the session structure
|
||||
memset(pSession, 0, sizeof(*pSession));
|
||||
|
||||
// Get a curl handle
|
||||
pSession->hCurl = curl_easy_init();
|
||||
if (pSession->hCurl != NULL)
|
||||
{
|
||||
CURLcode result;
|
||||
bool setOptError = false;
|
||||
|
||||
// Set necessary options on the handle
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_NOSIGNAL, 0)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_NOSIGNAL, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_USERAGENT, "CASA Client/1.0")) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_USERAGENT, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_POST, 1)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_POST, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
pSession->headers = curl_slist_append(pSession->headers, "Content-Type: text/html");
|
||||
pSession->headers = curl_slist_append(pSession->headers, "Expect:");
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_HTTPHEADER, pSession->headers)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_HTTPHEADER, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_WRITEFUNCTION, CurlWriteCallback)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_WRITEFUNCTION, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
if ((result = curl_easy_setopt(pSession->hCurl, CURLOPT_WRITEDATA, pSession)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_WRITEDATA, code = %d\n", result);
|
||||
setOptError = true;
|
||||
}
|
||||
|
||||
// Now check if we succeded
|
||||
if (setOptError == false)
|
||||
{
|
||||
// Success, finish setting up the session object.
|
||||
pSession->pPartialHttpUrl = pPartialHttpUrl;
|
||||
pSession->partialHttpUrlLen = strlen(pPartialHttpUrl);
|
||||
pSession->pPartialHttpsUrl = pPartialHttpsUrl;
|
||||
pSession->partialHttpsUrlLen = strlen(pPartialHttpsUrl);
|
||||
|
||||
// Forget about the partial URL buffers so that they do not get deleted below
|
||||
pPartialHttpUrl = NULL;
|
||||
pPartialHttpsUrl = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed to set a needed curl option
|
||||
if (pSession->headers)
|
||||
curl_slist_free_all(pSession->headers);
|
||||
|
||||
curl_easy_cleanup(pSession->hCurl);
|
||||
|
||||
free(pSession);
|
||||
pSession = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error creating curl handle\n", 0);
|
||||
free(pSession);
|
||||
pSession = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to allocate buffer for rpc session\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to allocate buffer for URL\n", 0);
|
||||
}
|
||||
|
||||
// Free buffers not utilized
|
||||
if (pPartialHttpUrl)
|
||||
free(pPartialHttpUrl);
|
||||
|
||||
if (pPartialHttpsUrl)
|
||||
free(pPartialHttpsUrl);
|
||||
|
||||
DbgTrace(2, "-OpenRpcSession- End, pSession = %0lX\n", (long) pSession);
|
||||
|
||||
return pSession;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
CloseRpcSession(
|
||||
IN RpcSession *pSession)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-CloseRpcSession- Start\n", 0);
|
||||
|
||||
// Free any HTTP headers associated with the session
|
||||
if (pSession->headers)
|
||||
curl_slist_free_all(pSession->headers);
|
||||
|
||||
// Close the curl handle associated with this session
|
||||
curl_easy_cleanup(pSession->hCurl);
|
||||
|
||||
// Free the space allocated for the session
|
||||
if (pSession->pRecvData)
|
||||
free(pSession->pRecvData);
|
||||
|
||||
free(pSession->pPartialHttpUrl);
|
||||
free(pSession->pPartialHttpsUrl);
|
||||
|
||||
free(pSession);
|
||||
|
||||
DbgTrace(1, "-CloseRpcSession- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
InternalRpc(
|
||||
IN RpcSession *pSession,
|
||||
IN char *pMethod,
|
||||
IN long flags,
|
||||
IN char *pRequestData,
|
||||
INOUT char **ppResponseData,
|
||||
INOUT int *pResponseDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
#define CASA_STATUS_INVALID_SERVER_CERTIFICATE CASA_STATUS_UNSUCCESSFUL // temporary until casa_status.h is updated
|
||||
|
||||
CasaStatus retStatus;
|
||||
char *pPartialUrl;
|
||||
int partialUrlLen;
|
||||
char *pUrl;
|
||||
CURLcode curlResult;
|
||||
|
||||
DbgTrace(1, "-InternalRpc- Start\n", 0);
|
||||
|
||||
// Initialize output parameters
|
||||
*ppResponseData = NULL;
|
||||
*pResponseDataLen = 0;
|
||||
|
||||
// Setup the URL using the input parameters
|
||||
if (flags & SECURE_RPC_FLAG)
|
||||
{
|
||||
pPartialUrl = pSession->pPartialHttpsUrl;
|
||||
partialUrlLen = pSession->partialHttpsUrlLen;
|
||||
|
||||
// Check if we need to ignore invalid CERTS
|
||||
if (flags & ALLOW_INVALID_CERTS_RPC_FLAG)
|
||||
{
|
||||
if ((curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_SSL_VERIFYPEER, 0)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Error setting CURLOPT_SSL_VERIFYPEER, code = %d\n", curlResult);
|
||||
}
|
||||
|
||||
if ((curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_SSL_VERIFYHOST, 0)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Error setting CURLOPT_SSL_VERIFYHOST, code = %d\n", curlResult);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_SSL_VERIFYPEER, 1)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Error setting CURLOPT_SSL_VERIFYPEER, code = %d\n", curlResult);
|
||||
}
|
||||
|
||||
if ((curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_SSL_VERIFYHOST, 2)) != CURLE_OK)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Error setting CURLOPT_SSL_VERIFYHOST, code = %d\n", curlResult);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pPartialUrl = pSession->pPartialHttpUrl;
|
||||
partialUrlLen = pSession->partialHttpUrlLen;
|
||||
}
|
||||
|
||||
pUrl = (char*) malloc(partialUrlLen + strlen(pMethod) + 1);
|
||||
|
||||
if (pUrl)
|
||||
{
|
||||
strcpy(pUrl, pPartialUrl);
|
||||
strcat(pUrl, pMethod);
|
||||
|
||||
// Tell curl about the URL
|
||||
curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_URL, pUrl);
|
||||
if (curlResult == CURLE_OK)
|
||||
{
|
||||
// Tell curl about our post data
|
||||
curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_POSTFIELDS, pRequestData);
|
||||
if (curlResult == CURLE_OK)
|
||||
{
|
||||
// Tell curl about our post data len
|
||||
curlResult = curl_easy_setopt(pSession->hCurl, CURLOPT_POSTFIELDSIZE, strlen(pRequestData));
|
||||
if (curlResult == CURLE_OK)
|
||||
{
|
||||
// Now do the HTTP request
|
||||
curlResult = curl_easy_perform(pSession->hCurl);
|
||||
if (curlResult == CURLE_OK)
|
||||
{
|
||||
// Get the HTTP Response code
|
||||
long httpCompStatus;
|
||||
curlResult = curl_easy_getinfo(pSession->hCurl, CURLINFO_RESPONSE_CODE, &httpCompStatus);
|
||||
if (curlResult == CURLE_OK)
|
||||
{
|
||||
// Verify that the HTTP request was successfully completed by the server
|
||||
if (httpCompStatus == 200)
|
||||
{
|
||||
// Success, return the response data to the caller.
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
*ppResponseData = pSession->pRecvData;
|
||||
*pResponseDataLen = pSession->recvDataLen;;
|
||||
|
||||
// Forget about the response data buffer to keep from freeing it.
|
||||
pSession->pRecvData = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- HTTP request did not complete successfully, status = %ld\n", httpCompStatus);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Curl get info failed, code = %d\n", curlResult);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Curl perform failed, code = %d\n", curlResult);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Make sure that we never exit with a recv data buffer hanging off the session
|
||||
if (pSession->pRecvData)
|
||||
{
|
||||
free(pSession->pRecvData);
|
||||
pSession->pRecvData = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_POSTFIELDSIZE, code = %d\n", curlResult);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_POSTFIELDS, code = %d\n", curlResult);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error setting CURLOPT_URL, code = %d\n", curlResult);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Free the buffer used to hold the URL
|
||||
free(pUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InternalRpc- End, retStatus = %d\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
Rpc(
|
||||
IN RpcSession *pSession,
|
||||
IN char *pMethod,
|
||||
IN long flags,
|
||||
IN char *pRequestData,
|
||||
INOUT char **ppResponseData,
|
||||
INOUT int *pResponseDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int retries = 0;
|
||||
|
||||
DbgTrace(1, "-Rpc- Start\n", 0);
|
||||
|
||||
// Retry the RPC as needed
|
||||
do
|
||||
{
|
||||
// Issue the RPC
|
||||
retStatus = InternalRpc(pSession,
|
||||
pMethod,
|
||||
flags,
|
||||
pRequestData,
|
||||
ppResponseData,
|
||||
pResponseDataLen);
|
||||
|
||||
// Account for this try
|
||||
retries ++;
|
||||
|
||||
} while (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE
|
||||
&& retries < MAX_RPC_RETRIES);
|
||||
|
||||
DbgTrace(1, "-Rpc- End, retStatus = %d\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
InitializeRpc(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
|
||||
DbgTrace(1, "-InitializeRpc- Start\n", 0);
|
||||
|
||||
// Perform libcurl initializatoin
|
||||
CURLcode curlStatus = curl_global_init(CURL_GLOBAL_SSL);
|
||||
if (curlStatus != 0)
|
||||
{
|
||||
DbgTrace(0, "-InitializeRpc- Error initializing libcurl, curlStatus = %08X\n", curlStatus);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InitializeRpc- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
184
CASA-auth-token/client/core/mech_if.h
Normal file
184
CASA-auth-token/client/core/mech_if.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _MECH_IF_H_
|
||||
#define _MECH_IF_H_
|
||||
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
/**************************************************************************
|
||||
***************************************************************************
|
||||
** **
|
||||
** Authentication Mechanism Token Interface Definitions **
|
||||
** **
|
||||
***************************************************************************
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
int
|
||||
(SSCS_CALL *PFNAuthTokenIf_AddReference)(
|
||||
IN const void *pIfInstance);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Interface reference count.
|
||||
//
|
||||
// Description:
|
||||
// Increases interface reference count.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
void
|
||||
(SSCS_CALL *PFNAuthTokenIf_ReleaseReference)(
|
||||
IN const void *pIfInstance);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Nothing.
|
||||
//
|
||||
// Description:
|
||||
// Decreases interface reference count. The interface is deallocated if
|
||||
// the reference count becomes zero.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
CasaStatus
|
||||
(SSCS_CALL *PFNAuthTokenIf_GetAuthToken)(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen);
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pContext -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// context information. Another name for context is Authentication
|
||||
// Realm.
|
||||
//
|
||||
// pMechInfo -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// information. This is information is provided by the server to
|
||||
// aid the mechanism to generate an authentication token. For
|
||||
// example, the mechanism information for a Kerberos mechanism
|
||||
// may be the service principal name to which the user will be
|
||||
// authenticating.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to null terminated string containing the name of the
|
||||
// host where the ATS resides.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged when running in
|
||||
// the context of System under Windows.
|
||||
//
|
||||
// pTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pUserNameBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified service.
|
||||
//=======================================================================--
|
||||
|
||||
|
||||
//
|
||||
// AuthMechToken Interface Object
|
||||
//
|
||||
typedef struct _AuthTokenIf
|
||||
{
|
||||
PFNAuthTokenIf_AddReference addReference;
|
||||
PFNAuthTokenIf_ReleaseReference releaseReference;
|
||||
PFNAuthTokenIf_GetAuthToken getAuthToken;
|
||||
|
||||
} AuthTokenIf, *PAuthTokenIf;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
typedef
|
||||
CasaStatus
|
||||
(SSCS_CALL *PFN_GetAuthTokenIfRtn)(
|
||||
IN const ConfigIf *pModuleConfigIf,
|
||||
INOUT AuthTokenIf **ppAuthTokenIf);
|
||||
//
|
||||
// Arguments:
|
||||
// pModuleConfigIf -
|
||||
// Pointer to configuration interface instance for the module.
|
||||
//
|
||||
// ppAuthTokenIf -
|
||||
// Pointer to variable that will receive pointer to AuthTokenIf
|
||||
// instance.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Gets authentication token interface instance.
|
||||
//=======================================================================--
|
||||
|
||||
#define GET_AUTH_TOKEN_INTERFACE_RTN_SYMBOL "GetAuthTokenInterface"
|
||||
#define GET_AUTH_TOKEN_INTERFACE_RTN GetAuthTokenInterface
|
||||
|
||||
|
||||
#endif // #ifndef _MECH_IF_H_
|
||||
|
||||
37
CASA-auth-token/client/core/mechanisms/Makefile.am
Normal file
37
CASA-auth-token/client/core/mechanisms/Makefile.am
Normal file
@@ -0,0 +1,37 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = krb5 pwd
|
||||
|
||||
DIST_SUBDIRS = krb5 pwd
|
||||
|
||||
CFILES =
|
||||
|
||||
EXTRA_DIST = $(CFILES)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
37
CASA-auth-token/client/core/mechanisms/krb5/Makefile.am
Normal file
37
CASA-auth-token/client/core/mechanisms/krb5/Makefile.am
Normal file
@@ -0,0 +1,37 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = $(TARGET_OS)
|
||||
|
||||
DIST_SUBDIRS = linux windows
|
||||
|
||||
CFILES = *.c
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
53
CASA-auth-token/client/core/mechanisms/krb5/README
Normal file
53
CASA-auth-token/client/core/mechanisms/krb5/README
Normal file
@@ -0,0 +1,53 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
*
|
||||
* README for krb5mech
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
krb5mech is a client authentication mechanism for the support of Kerberos 5
|
||||
authentication. The mechanism leverages the services of the native Kerberos 5
|
||||
client to obtain Kerberos Tokens that can be used for authenticating an entity
|
||||
to a Kerberos service.
|
||||
|
||||
|
||||
SECURITY CONSIDERATIONS
|
||||
|
||||
The tokens that krb5mech generates are only utilized to authenticate the client
|
||||
entity to the Kerberos service, because of this, auth_token relies on SSL for
|
||||
server authentication. auth_token does not leverage the capabilities of GSSAPI
|
||||
for data privacy and data integrity purposes.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13
CASA-auth-token/client/core/mechanisms/krb5/TODO
Normal file
13
CASA-auth-token/client/core/mechanisms/krb5/TODO
Normal file
@@ -0,0 +1,13 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* TODO for krb5mech
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
This file contains a list of the items still outstanding for krb5mech.
|
||||
|
||||
OUTSTANDING ITEMS
|
||||
|
||||
None.
|
||||
207
CASA-auth-token/client/core/mechanisms/krb5/interface.c
Normal file
207
CASA-auth-token/client/core/mechanisms/krb5/interface.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Authentication Token Interface instance data
|
||||
//
|
||||
typedef struct _AuthTokenIfInstance
|
||||
{
|
||||
int refCount;
|
||||
AuthTokenIf authTokenIf;
|
||||
|
||||
} AuthTokenIfInstance, *PAuthTokenIfInstance;
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// AuthTokenIf variables
|
||||
static
|
||||
int g_numAuthTokenIfObjs = 0;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
int SSCS_CALL
|
||||
AuthTokenIf_AddReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Interface reference count.
|
||||
//
|
||||
// Description:
|
||||
// Increases interface reference count.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int refCount;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance = CONTAINING_RECORD(pIfInstance, AuthTokenIfInstance, authTokenIf);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_AddReference- Start\n", 0);
|
||||
|
||||
// Increment the reference count on the object
|
||||
pAuthTokenIfInstance->refCount ++;
|
||||
refCount = pAuthTokenIfInstance->refCount;
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %08X\n", refCount);
|
||||
|
||||
return refCount;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void SSCS_CALL
|
||||
AuthTokenIf_ReleaseReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Nothing.
|
||||
//
|
||||
// Description:
|
||||
// Decreases interface reference count. The interface is deallocated if
|
||||
// the reference count becomes zero.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
bool freeObj = false;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance = CONTAINING_RECORD(pIfInstance, AuthTokenIfInstance, authTokenIf);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_ReleaseReference- Start\n", 0);
|
||||
|
||||
// Decrement the reference count on the object and determine if it needs to
|
||||
// be released.
|
||||
pAuthTokenIfInstance->refCount --;
|
||||
if (pAuthTokenIfInstance->refCount == 0)
|
||||
{
|
||||
// The object needs to be released, forget about it.
|
||||
freeObj = true;
|
||||
g_numAuthTokenIfObjs --;
|
||||
}
|
||||
|
||||
// Free object if necessary
|
||||
if (freeObj)
|
||||
free(pAuthTokenIfInstance);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_ReleaseReference- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
GET_AUTH_TOKEN_INTERFACE_RTN(
|
||||
IN const ConfigIf *pModuleConfigIf,
|
||||
INOUT AuthTokenIf **ppAuthTokenIf)
|
||||
//
|
||||
// Arguments:
|
||||
// pModuleConfigIf -
|
||||
// Pointer to configuration interface instance for the module.
|
||||
//
|
||||
// ppAuthTokenIf -
|
||||
// Pointer to variable that will receive pointer to AuthTokenIf
|
||||
// instance.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Gets authentication token interface instance.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance;
|
||||
|
||||
|
||||
DbgTrace(1, "-GetAuthTokenInterface- Start\n", 0);
|
||||
|
||||
// Validate input parameters
|
||||
if (pModuleConfigIf == NULL
|
||||
|| ppAuthTokenIf == NULL)
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenInterface- Invalid input parameter\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Allocate space for the interface instance
|
||||
pAuthTokenIfInstance = malloc(sizeof(*pAuthTokenIfInstance));
|
||||
if (pAuthTokenIfInstance)
|
||||
{
|
||||
// Initialize the interface instance data
|
||||
pAuthTokenIfInstance->refCount = 1;
|
||||
pAuthTokenIfInstance->authTokenIf.addReference = AuthTokenIf_AddReference;
|
||||
pAuthTokenIfInstance->authTokenIf.releaseReference = AuthTokenIf_ReleaseReference;
|
||||
pAuthTokenIfInstance->authTokenIf.getAuthToken = AuthTokenIf_GetAuthToken;
|
||||
|
||||
// Keep track of this object
|
||||
g_numAuthTokenIfObjs ++;
|
||||
|
||||
// Return the interface to the caller
|
||||
*ppAuthTokenIf = &pAuthTokenIfInstance->authTokenIf;
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenInterface- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
92
CASA-auth-token/client/core/mechanisms/krb5/internal.h
Normal file
92
CASA-auth-token/client/core/mechanisms/krb5/internal.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _INTERNAL_H_
|
||||
#define _INTERNAL_H_
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include "platform.h"
|
||||
#include <micasa_types.h>
|
||||
#include <casa_status.h>
|
||||
#include "config_if.h"
|
||||
#include "mech_if.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
extern int DebugLevel;
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
//
|
||||
// Defined in get.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus SSCS_CALL
|
||||
AuthTokenIf_GetAuthToken(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen);
|
||||
|
||||
extern
|
||||
int
|
||||
InitializeLibrary(void);
|
||||
|
||||
//
|
||||
// Defined in utils.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen);
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
#endif // _INTERNAL_H_
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# Krb5Authenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName /usr/lib/CASA/authtoken/krb5mech.so
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# Krb5Authenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName /usr/lib64/CASA/authtoken/krb5mech.so
|
||||
|
||||
|
||||
122
CASA-auth-token/client/core/mechanisms/krb5/linux/Makefile.am
Normal file
122
CASA-auth-token/client/core/mechanisms/krb5/linux/Makefile.am
Normal file
@@ -0,0 +1,122 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
CFLAGS += -v -w
|
||||
DEFINES = -DDBG
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEFINES = -DNDEBUG
|
||||
endif
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
ROOT = ../../../..
|
||||
|
||||
LIBDIR = $(ROOT)/$(LIB)
|
||||
|
||||
# handle Mono secondary dependencies
|
||||
export MONO_PATH := $(MONO_PATH)
|
||||
|
||||
PLATFORMINDEPENDENTSOURCEDIR = ..
|
||||
PLATFORMDEPENDENTSOURCEDIR = .
|
||||
|
||||
MODULE_NAME = krb5mech
|
||||
MODULE_EXT = so
|
||||
|
||||
CFILES = get.c \
|
||||
../interface.c \
|
||||
../util.c \
|
||||
platform.c
|
||||
|
||||
CSFILES_CSC :=
|
||||
INCLUDES = -I. -I.. -I../../.. -I$(ROOT)/include
|
||||
RESOURCES =
|
||||
|
||||
DEST_CONF_FILE_NAME = Krb5Authenticate.conf
|
||||
if LIB64
|
||||
DEFINES += -D_LIB64
|
||||
SRC_CONF_FILE_NAME = Krb5Authenticate_lib64.conf
|
||||
else
|
||||
SRC_CONF_FILE_NAME = Krb5Authenticate.conf
|
||||
endif
|
||||
|
||||
CFLAGS += -Wno-format-extra-args -fno-strict-aliasing $(INCLUDES) $(DEFINES)
|
||||
LIBS = -lpthread -lc -lgssapi
|
||||
LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) -L$(ROOT)/lib/$(TARGET_CFG)
|
||||
|
||||
OBJDIR = ./$(TARGET_CFG)/$(LIB)
|
||||
OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o))
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h Krb5Authenticate.conf Krb5Authenticate_lib64.conf
|
||||
|
||||
CUR_DIR := $(shell pwd)
|
||||
|
||||
all: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
|
||||
#
|
||||
# Pattern based rules.
|
||||
#
|
||||
vpath %.c $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
vpath %.cpp $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT): $(OBJDIR) $(OBJS)
|
||||
@echo [======== Linking $@ ========]
|
||||
$(LINK) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
|
||||
cp -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(LIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
cp -f $(SRC_CONF_FILE_NAME) $(LIBDIR)/$(TARGET_CFG)/$(DEST_CONF_FILE_NAME)
|
||||
|
||||
$(OBJDIR):
|
||||
[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR)
|
||||
[ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
|
||||
[ -d $(LIBDIR)/$(TARGET_CFG) ] || mkdir -p $(LIBDIR)/$(TARGET_CFG)
|
||||
|
||||
install-exec-local: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
$(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
$(INSTALL_PROGRAM) $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(DESTDIR)$(libdir)/
|
||||
|
||||
uninstall-local:
|
||||
cd $(DESTDIR)$(libdir); rm -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
rmdir $(DESTDIR)$(libdir)
|
||||
|
||||
#installcheck-local: install
|
||||
# $(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
# $(INSTALL_PROGRAM) $(DESTDIR)$(libdir)
|
||||
# cd $(DESTDIR)$(libdir); $(MONO)
|
||||
|
||||
clean-local:
|
||||
if [ -d $(TARGET_CFG) ]; then rm -rf $(TARGET_CFG); fi
|
||||
|
||||
distclean-local:
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
385
CASA-auth-token/client/core/mechanisms/krb5/linux/get.c
Normal file
385
CASA-auth-token/client/core/mechanisms/krb5/linux/get.c
Normal file
@@ -0,0 +1,385 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Mechanism OID
|
||||
gss_OID g_mechOid = GSS_C_NULL_OID;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
LogGssStatuses(
|
||||
IN char *operation,
|
||||
IN OM_uint32 majorGssStatus,
|
||||
IN OM_uint32 minorGssStatus)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
OM_uint32 gssMajStat;
|
||||
OM_uint32 gssMinStat;
|
||||
gss_buffer_desc msg = GSS_C_EMPTY_BUFFER;
|
||||
OM_uint32 gssMsgCtx;
|
||||
|
||||
// Trace the messages associated with the major status
|
||||
gssMsgCtx = 0;
|
||||
while (1)
|
||||
{
|
||||
gssMajStat = gss_display_status(&gssMinStat,
|
||||
majorGssStatus,
|
||||
GSS_C_GSS_CODE,
|
||||
g_mechOid,
|
||||
&gssMsgCtx,
|
||||
&msg);
|
||||
if (gssMajStat != GSS_S_COMPLETE)
|
||||
{
|
||||
DbgTrace(0, "-LogGssStatuses- Error obtaining display status\n", 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Trace this message
|
||||
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation);
|
||||
DbgTrace(0, "%s\n", (char *)msg.value);
|
||||
|
||||
if (msg.length != 0)
|
||||
gss_release_buffer(&gssMinStat, &msg);
|
||||
|
||||
if (!gssMsgCtx)
|
||||
break;
|
||||
}
|
||||
|
||||
// Trace the messages associated with the minor status
|
||||
gssMsgCtx = 0;
|
||||
while (1)
|
||||
{
|
||||
gssMajStat = gss_display_status(&gssMinStat,
|
||||
minorGssStatus,
|
||||
GSS_C_MECH_CODE,
|
||||
g_mechOid,
|
||||
&gssMsgCtx,
|
||||
&msg);
|
||||
if (gssMajStat != GSS_S_COMPLETE)
|
||||
{
|
||||
DbgTrace(0, "-LogGssStatuses- Error obtaining display status\n", 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Trace this message
|
||||
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation);
|
||||
DbgTrace(0, "%s\n", (char *)msg.value);
|
||||
|
||||
if (msg.length != 0)
|
||||
gss_release_buffer(&gssMinStat, &msg);
|
||||
|
||||
if (!gssMsgCtx)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
AuthTokenIf_GetAuthToken(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pServiceConfigIf -
|
||||
// Pointer to service config object to which the client is trying to
|
||||
// authenticate.
|
||||
//
|
||||
// pContext -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// context information. Another name for context is Authentication
|
||||
// Realm.
|
||||
//
|
||||
// pMechInfo -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// information. This is information is provided by the server to
|
||||
// aid the mechanism to generate an authentication token. For
|
||||
// example, the mechanism information for a Kerberos mechanism
|
||||
// may be the service principal name to which the user will be
|
||||
// authenticating.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to null terminated string containing the name of the
|
||||
// host where the ATS resides.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged when running in
|
||||
// the context of System under Windows.
|
||||
//
|
||||
// pTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pUserNameBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified service.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char const *pKrbServiceName = pMechInfo;
|
||||
OM_uint32 gssMajStat;
|
||||
OM_uint32 gssMinStat;
|
||||
gss_buffer_desc gssBuffer;
|
||||
gss_name_t gssServiceName;
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Start\n", 0);
|
||||
|
||||
// Validate input parameters
|
||||
if (pIfInstance == NULL
|
||||
|| pContext == NULL
|
||||
|| pHostName == NULL
|
||||
|| pTokenBufLen == NULL
|
||||
|| (pTokenBuf == NULL && *pTokenBufLen != 0))
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Invalid input parameter\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Check if we need to construct the service name
|
||||
if (pKrbServiceName == NULL
|
||||
|| strlen(pKrbServiceName) == 0)
|
||||
{
|
||||
// The service name will default to host/hostname
|
||||
pKrbServiceName = malloc(5 /*"host/"*/ + strlen(pHostName) + 1 /*'/0'*/);
|
||||
if (pKrbServiceName)
|
||||
{
|
||||
sprintf(pKrbServiceName, "host/%s", pHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Memory allocation failure\n", 0);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Import the service principal name into something that
|
||||
// GSS-API can understand based on its form.
|
||||
gssBuffer.value = (void*) pKrbServiceName;
|
||||
gssBuffer.length = strlen(pKrbServiceName) + 1;
|
||||
if (strchr(pKrbServiceName, '@') != NULL)
|
||||
{
|
||||
// The name is of the form "servicename@hostname"
|
||||
gssMajStat = gss_import_name(&gssMinStat,
|
||||
&gssBuffer,
|
||||
(gss_OID) GSS_C_NT_HOSTBASED_SERVICE,
|
||||
&gssServiceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The name is of the form "servicename"
|
||||
gssMajStat = gss_import_name(&gssMinStat,
|
||||
&gssBuffer,
|
||||
(gss_OID) GSS_C_NT_USER_NAME,
|
||||
&gssServiceName);
|
||||
}
|
||||
|
||||
// Proceed based on the result of the name import operation
|
||||
if (gssMajStat == GSS_S_COMPLETE)
|
||||
{
|
||||
// Establish a context
|
||||
gss_ctx_id_t gssContext = GSS_C_NO_CONTEXT;
|
||||
gss_buffer_desc gssSendToken = {0};
|
||||
OM_uint32 gssRetFlags;
|
||||
gssMajStat = gss_init_sec_context(&gssMinStat,
|
||||
GSS_C_NO_CREDENTIAL,
|
||||
&gssContext,
|
||||
gssServiceName,
|
||||
g_mechOid,
|
||||
0, // Flags
|
||||
0,
|
||||
NULL, // no channel bindings
|
||||
GSS_C_NO_BUFFER, // no token from peer
|
||||
NULL, // ignore mech type
|
||||
&gssSendToken,
|
||||
&gssRetFlags,
|
||||
NULL); // ignore time rec
|
||||
|
||||
// Proceed based on the result of the gss_init_sec_context operation
|
||||
if (gssMajStat == GSS_S_COMPLETE
|
||||
&& gssSendToken.length != 0)
|
||||
{
|
||||
char *pEncodedToken;
|
||||
int encodedTokenLen;
|
||||
|
||||
// The security context was initialized, now return the token to the
|
||||
// caller after base64 encoding it.
|
||||
retStatus = EncodeData(gssSendToken.value,
|
||||
gssSendToken.length,
|
||||
&pEncodedToken,
|
||||
&encodedTokenLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Verify that the caller provided a buffer that is big enough
|
||||
if (encodedTokenLen > *pTokenBufLen)
|
||||
{
|
||||
// At least one of the supplied buffers is not big enough
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Insufficient buffer space provided\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The buffer provided is large enough, copy the data and return the actual size.
|
||||
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen +1);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Return the actual size or the size required
|
||||
*pTokenBufLen = encodedTokenLen;
|
||||
|
||||
// Free the buffer containing the encoded token
|
||||
free(pEncodedToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Encoding failed\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Error initing sec context\n", 0);
|
||||
LogGssStatuses("initializing context", gssMajStat, gssMinStat);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Release send token buffer if necessary
|
||||
if (gssSendToken.length != 0)
|
||||
gss_release_buffer(&gssMinStat, &gssSendToken);
|
||||
|
||||
|
||||
// Free context if necessary
|
||||
if (gssContext != GSS_C_NO_CONTEXT)
|
||||
gss_delete_sec_context(&gssMinStat, &gssContext, GSS_C_NO_BUFFER);
|
||||
|
||||
// Release the buffer associated with the service name
|
||||
gss_release_name(&gssMinStat, &gssServiceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Error importing service name\n", 0);
|
||||
LogGssStatuses("importing service name", gssMajStat, gssMinStat);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_OBJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
// Free buffer holding the Krb Service Name if necessary
|
||||
if (pKrbServiceName
|
||||
&& pKrbServiceName != pMechInfo)
|
||||
free(pKrbServiceName);
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
InitializeLibrary(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int retStatus = 0;
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- Start\n", 0);
|
||||
|
||||
// Nothing to do at this time.
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
35
CASA-auth-token/client/core/mechanisms/krb5/linux/platform.c
Normal file
35
CASA-auth-token/client/core/mechanisms/krb5/linux/platform.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
90
CASA-auth-token/client/core/mechanisms/krb5/linux/platform.h
Normal file
90
CASA-auth-token/client/core/mechanisms/krb5/linux/platform.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include </usr/include/gssapi/gssapi.h>
|
||||
#include </usr/include/gssapi/gssapi_krb5.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#define HANDLE void*
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
_snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
fprintf(stderr, "CASA_Krb5Mech %s", printBuff); \
|
||||
} \
|
||||
}
|
||||
/*#define DbgTrace(LEVEL, X, Y) { \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
openlog("CASA_Krb5Mech", LOG_CONS | LOG_NOWAIT | LOG_ODELAY, LOG_USER); \
|
||||
syslog(LOG_USER | LOG_INFO, X, Y); \
|
||||
closelog(); \
|
||||
} \
|
||||
}*/
|
||||
|
||||
|
||||
//
|
||||
// Deal with function name mapping issues
|
||||
//
|
||||
#define _snprintf snprintf
|
||||
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
282
CASA-auth-token/client/core/mechanisms/krb5/util.c
Normal file
282
CASA-auth-token/client/core/mechanisms/krb5/util.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Debug Level
|
||||
int DebugLevel = 0;
|
||||
|
||||
// Tables for Base64 encoding and decoding
|
||||
static const int8_t g_Base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
static const uint8_t g_Expand64[256] =
|
||||
{
|
||||
/* ASCII table */
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
DbgTrace(3, "-EncodeData- Start\n", 0);
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = g_Base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-EncodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int i, j;
|
||||
int decodedSize;
|
||||
|
||||
DbgTrace(3, "-DecodeData- Start\n", 0);
|
||||
|
||||
// Determine the decoded size
|
||||
for (i = 0, j = 0; i < encodedDataLen; i++)
|
||||
if (g_Expand64[((uint8_t*) pEncodedData)[i]] < 64)
|
||||
j++;
|
||||
decodedSize = (j * 3 + 3) / 4;
|
||||
|
||||
// Allocate buffer to hold the decoded data
|
||||
*ppData = malloc(decodedSize);
|
||||
if (*ppData)
|
||||
{
|
||||
bool endReached = false;
|
||||
uint8_t c0, c1, c2, c3;
|
||||
uint8_t *p, *q;
|
||||
|
||||
// Initialize parameters that will be used during the decode operation
|
||||
c0 = c1 = c2 = c3 = 0;
|
||||
p = (uint8_t*) pEncodedData;
|
||||
q = (uint8_t*) *ppData;
|
||||
|
||||
// Decode the data
|
||||
//
|
||||
// Loop through the data, piecing back information. Any newlines, and/or
|
||||
// carriage returns need to be skipped.
|
||||
while (j > 4)
|
||||
{
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c0 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2);
|
||||
j--;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c1 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4);
|
||||
j -= 2;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c2 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6);
|
||||
j -= 3;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c3 = *(p++);
|
||||
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6 | g_Expand64[c3]);
|
||||
j -= 4;
|
||||
}
|
||||
if (!endReached)
|
||||
{
|
||||
if (j > 1)
|
||||
*(q++) = (uint8_t)(g_Expand64[*p] << 2 | g_Expand64[p[1]] >> 4);
|
||||
if (j > 2)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[1]] << 4 | g_Expand64[p[2]] >> 2);
|
||||
if (j > 3)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[2]] << 6 | g_Expand64[p[3]]);
|
||||
}
|
||||
|
||||
// Return the length of the decoded data
|
||||
*pDataLen = (int32_t)(q - (uint8_t*)*ppData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-DecodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# Krb5Authenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName \Program Files\novell\casa\lib\krb5mech.dll
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = krb5.vcproj ../*.c *.c *.h *.conf *.def
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
endif
|
||||
|
||||
PACKAGE = krb5
|
||||
TARGET_FILE = krb5mech.dll
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
|
||||
all-am: $(TARGET_FILE)
|
||||
|
||||
.PHONY: $TARGET_FILE) devenv
|
||||
|
||||
devenv:
|
||||
@if ! test -x "$(VSINSTALLDIR)/devenv.exe"; then echo "Error: Microsoft Visual Studio .NET is currently required to build MSI and MSM packages"; exit 1; fi
|
||||
|
||||
$(TARGET_FILE): devenv
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@CMD='"$(VSINSTALLDIR)/devenv.exe" ../../../../auth.sln /build $(TARGET_CFG) /project $(PACKAGE) /out $(LOG_FILE)'; \
|
||||
echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(TARGET_CFG)/$(TARGET_FILE); \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf Release/* Release Debug/* Debug*/Release */Debug *.log *.suo
|
||||
|
||||
clean:
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
||||
132
CASA-auth-token/client/core/mechanisms/krb5/windows/dllsup.c
Normal file
132
CASA-auth-token/client/core/mechanisms/krb5/windows/dllsup.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ External data ]=====================================================
|
||||
|
||||
//===[ Manifest constants ]================================================
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
UINT32 g_ulCount = 0;
|
||||
UINT32 g_ulLock = 0;
|
||||
HANDLE g_hModule;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
BOOL APIENTRY DllMain(
|
||||
HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
//=======================================================================--
|
||||
{
|
||||
BOOL retStatus = TRUE;
|
||||
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
|
||||
// Initialize the library
|
||||
if (InitializeLibrary() != 0)
|
||||
{
|
||||
// Failed to initialize the library
|
||||
OutputDebugString("CASA_KRB5_MECH -DllMain- Library initialization failed\n");
|
||||
retStatus = FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
/* Don't uninitialize on windows
|
||||
tbd
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
//++=======================================================================
|
||||
//
|
||||
// DllCanUnloadNow
|
||||
//
|
||||
// Synopsis
|
||||
//
|
||||
//
|
||||
STDAPI
|
||||
DllCanUnloadNow()
|
||||
//
|
||||
// Input Arguments
|
||||
//
|
||||
// Ouput Arguments
|
||||
//
|
||||
// Return Value
|
||||
// S_OK The DLL can be unloaded.
|
||||
// S_FALSE The DLL cannot be unloaded now.
|
||||
//
|
||||
// Description
|
||||
// An Exported Function.
|
||||
// DLLs that support the OLE Component Object Model (COM) should implement
|
||||
// and export DllCanUnloadNow.
|
||||
// A call to DllCanUnloadNow determines whether the DLL from which it is
|
||||
// exported is still in use. A DLL is no longer in use when it is not
|
||||
// managing any existing objects (the reference count on all of its objects
|
||||
// is 0).
|
||||
// DllCanUnloadNow returns S_FALSE if there are any existing references to
|
||||
// objects that the DLL manages.
|
||||
//
|
||||
// Environment
|
||||
//
|
||||
// See Also
|
||||
//
|
||||
//=======================================================================--
|
||||
{
|
||||
// tbd
|
||||
return ((g_ulCount == 0 && g_ulLock == 0) ? S_OK : S_FALSE);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
//=========================================================================
|
||||
|
||||
300
CASA-auth-token/client/core/mechanisms/krb5/windows/get.c
Normal file
300
CASA-auth-token/client/core/mechanisms/krb5/windows/get.c
Normal file
@@ -0,0 +1,300 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
AuthTokenIf_GetAuthToken(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pContext -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// context information. Another name for context is Authentication
|
||||
// Realm.
|
||||
//
|
||||
// pMechInfo -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// information. This is information is provided by the server to
|
||||
// aid the mechanism to generate an authentication token. For
|
||||
// example, the mechanism information for a Kerberos mechanism
|
||||
// may be the service principal name to which the user will be
|
||||
// authenticating.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to null terminated string containing the name of the
|
||||
// host where the ATS resides.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged when running in
|
||||
// the context of System under Windows.
|
||||
//
|
||||
// pTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pUserNameBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified service.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char *pKrbServiceName = pMechInfo;
|
||||
SECURITY_STATUS secStatus;
|
||||
TimeStamp expiry;
|
||||
CredHandle hCredentials = {0};
|
||||
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Start\n", 0);
|
||||
|
||||
// Validate input parameters
|
||||
if (pIfInstance == NULL
|
||||
|| pContext == NULL
|
||||
|| pHostName == NULL
|
||||
|| pTokenBufLen == NULL
|
||||
|| (pTokenBuf == NULL && *pTokenBufLen != 0))
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Invalid input parameter\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Check if we need to construct the service name
|
||||
if (pKrbServiceName == NULL
|
||||
|| strlen(pKrbServiceName) == 0)
|
||||
{
|
||||
// The service name will default to host/hostname
|
||||
pKrbServiceName = malloc(5 /*"host/"*/ + strlen(pHostName) + 1 /*'/0'*/);
|
||||
if (pKrbServiceName)
|
||||
{
|
||||
sprintf(pKrbServiceName, "host/%s", pHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Memory allocation failure\n", 0);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Acquire a credential handle for the current user
|
||||
secStatus = AcquireCredentialsHandle(NULL, // no principal name
|
||||
"Kerberos", // package name
|
||||
SECPKG_CRED_OUTBOUND,
|
||||
NULL, // no logon id
|
||||
NULL, // no auth data
|
||||
NULL, // no get key fn
|
||||
NULL, // noget key arg
|
||||
&hCredentials,
|
||||
&expiry);
|
||||
if (secStatus == SEC_E_OK)
|
||||
{
|
||||
CtxtHandle hContext = {0};
|
||||
SecBuffer sendTok;
|
||||
SecBufferDesc outputDesc;
|
||||
ULONG retFlags;
|
||||
|
||||
// We acquired the credential, now initialize a security context
|
||||
// so that we can authenticate the user to the specified service.
|
||||
//
|
||||
// First ready an output descriptor so that we can receive the
|
||||
// token buffer.
|
||||
outputDesc.cBuffers = 1;
|
||||
outputDesc.pBuffers = &sendTok;
|
||||
outputDesc.ulVersion = SECBUFFER_VERSION;
|
||||
|
||||
sendTok.BufferType = SECBUFFER_TOKEN;
|
||||
sendTok.cbBuffer = 0;
|
||||
sendTok.pvBuffer = NULL;
|
||||
|
||||
// Initialize the security context for the specified service
|
||||
secStatus = InitializeSecurityContext(&hCredentials,
|
||||
NULL,
|
||||
pKrbServiceName,
|
||||
ISC_REQ_ALLOCATE_MEMORY,
|
||||
0, // reserved
|
||||
SECURITY_NATIVE_DREP,
|
||||
NULL,
|
||||
0, // reserved
|
||||
&hContext,
|
||||
&outputDesc,
|
||||
&retFlags,
|
||||
&expiry);
|
||||
if (secStatus == SEC_E_OK)
|
||||
{
|
||||
char *pEncodedToken;
|
||||
int encodedTokenLen;
|
||||
|
||||
// The security context was initialized, now return it to the caller after base64 encoding it.
|
||||
retStatus = EncodeData(sendTok.pvBuffer,
|
||||
(const int) sendTok.cbBuffer,
|
||||
&pEncodedToken,
|
||||
&encodedTokenLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Verify that the caller provided a buffer that is big enough
|
||||
if (encodedTokenLen > *pTokenBufLen)
|
||||
{
|
||||
// The buffer is not big enough
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The buffer provided is large enough, copy the data.
|
||||
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Return the actual size or the size required
|
||||
*pTokenBufLen = encodedTokenLen;
|
||||
|
||||
// Free the buffer containing the encoded token
|
||||
free(pEncodedToken);
|
||||
}
|
||||
|
||||
// Delete the security context
|
||||
DeleteSecurityContext(&hContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Failed to initialize the security context, error = %08X\n", secStatus);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Free any buffer associated with the sendToken
|
||||
if (sendTok.pvBuffer)
|
||||
FreeContextBuffer(sendTok.pvBuffer);
|
||||
|
||||
// Free the credential handle obtained
|
||||
FreeCredentialsHandle(&hCredentials);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Failed to obtain the credentials handle, error = %08X\n", secStatus);
|
||||
|
||||
// Set retStatus based on secStatus
|
||||
if (secStatus == SEC_E_NOT_OWNER
|
||||
|| secStatus == SEC_E_NO_CREDENTIALS)
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_NO_CREDENTIALS);
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
// Free buffer holding the Krb Service Name if necessary
|
||||
if (pKrbServiceName
|
||||
&& pKrbServiceName != pMechInfo)
|
||||
free(pKrbServiceName);
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
InitializeLibrary(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int retStatus = 0;
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- Start\n", 0);
|
||||
|
||||
// Nothing to do at this time.
|
||||
|
||||
DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
182
CASA-auth-token/client/core/mechanisms/krb5/windows/krb5.vcproj
Normal file
182
CASA-auth-token/client/core/mechanisms/krb5/windows/krb5.vcproj
Normal file
@@ -0,0 +1,182 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="krb5"
|
||||
ProjectGUID="{5499F624-F371-4559-B4C2-A484BCE892FD}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)client\mechanisms\krb5\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\mechanisms\krb5\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="-DSECURITY_WIN32"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\;..\;..\..\..;..\..\..\..\include;"..\..\..\..\..\..\..\Expat-2.0.0\source\lib";"c:\Program Files\Novell\CASA\include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/EXPORT:GetAuthTokenInterface"
|
||||
AdditionalDependencies="secur32.lib"
|
||||
OutputFile="$(OutDir)/krb5mech.dll"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/pw.pdb"
|
||||
SubSystem="0"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
mkdir \"Program Files"\novell\casa\etc\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\mechanisms\
|
||||
copy Krb5Authenticate.conf \"Program Files"\novell\casa\etc\auth\mechanisms\Krb5Authenticate.conf
|
||||
copy $(OutDir)\krb5mech.dll \"Program Files"\novell\casa\lib\krb5mech.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="$(SolutionDir)client\mechanisms\krb5\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\mechanisms\krb5\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="-DSECURITY_WIN32"
|
||||
AdditionalIncludeDirectories=".\;..\;..\..\..;..\..\..\..\include;"..\..\..\..\..\..\..\Expat-2.0.0\source\lib";"c:\Program Files\Novell\CASA\include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/EXPORT:GetAuthTokenInterface"
|
||||
AdditionalDependencies="secur32.lib"
|
||||
OutputFile="$(OutDir)/krb5mech.dll"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="0"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
mkdir \"Program Files"\novell\casa\etc\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\mechanisms\
|
||||
copy Krb5Authenticate.conf \"Program Files"\novell\casa\etc\auth\mechanisms\Krb5Authenticate.conf
|
||||
copy $(OutDir)\krb5mech.dll \"Program Files"\novell\casa\lib\krb5mech.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>
|
||||
</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=".\dllsup.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\get.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Krb5Authenticate.conf">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\krb5mech.def">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\util.c">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath="..\internal.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.h">
|
||||
</File>
|
||||
</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>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,10 @@
|
||||
LIBRARY KRB5MECH
|
||||
DESCRIPTION 'CASA Kerberos V Authentication Mechanism Library.'
|
||||
|
||||
|
||||
EXPORTS
|
||||
; DllRegisterServer PRIVATE
|
||||
; DllUnregisterServer PRIVATE
|
||||
; DllGetClassObject PRIVATE
|
||||
GetAuthTokenInterface PRIVATE
|
||||
; DllCanUnloadNow PRIVATE
|
||||
@@ -0,0 +1,35 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <winerror.h>
|
||||
#include <security.h>
|
||||
#include <sspi.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
//#define DbgTrace(LEVEL, X, Y) { \
|
||||
//char printBuff[256]; \
|
||||
// if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
// { \
|
||||
// _snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
// printf("Krb5Mech %s", printBuff); \
|
||||
// } \
|
||||
//}
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char formatBuff[128]; \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
strcpy(formatBuff, "Krb5Mech "); \
|
||||
strncat(formatBuff, X, sizeof(formatBuff) - 9); \
|
||||
_snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \
|
||||
OutputDebugString(printBuff); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define bool BOOLEAN
|
||||
#define true TRUE
|
||||
#define false FALSE
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
#endif // _PLATFORM_H_
|
||||
|
||||
37
CASA-auth-token/client/core/mechanisms/pwd/Makefile.am
Normal file
37
CASA-auth-token/client/core/mechanisms/pwd/Makefile.am
Normal file
@@ -0,0 +1,37 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = $(TARGET_OS)
|
||||
|
||||
DIST_SUBDIRS = linux windows
|
||||
|
||||
CFILES = *.c
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
50
CASA-auth-token/client/core/mechanisms/pwd/README
Normal file
50
CASA-auth-token/client/core/mechanisms/pwd/README
Normal file
@@ -0,0 +1,50 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
*
|
||||
* README for pwmech
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
pwmech is a client authentication mechanism for the support of username
|
||||
and password authenticaton. The mechanism leverages the credentials stored
|
||||
in the miCASA cache and does not prompt the user for credentials.
|
||||
|
||||
SECURITY CONSIDERATIONS
|
||||
|
||||
The tokens that pwmech generates contain the user's username and password,
|
||||
this mandates that the auth_token client utilize a secure channel when
|
||||
transfering them to the ATS.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
13
CASA-auth-token/client/core/mechanisms/pwd/TODO
Normal file
13
CASA-auth-token/client/core/mechanisms/pwd/TODO
Normal file
@@ -0,0 +1,13 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* TODO for pwmech
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
INTRODUCTION
|
||||
|
||||
This file contains a list of the items still outstanding for pwmech.
|
||||
|
||||
OUTSTANDING ITEMS
|
||||
|
||||
None.
|
||||
352
CASA-auth-token/client/core/mechanisms/pwd/get.c
Normal file
352
CASA-auth-token/client/core/mechanisms/pwd/get.c
Normal file
@@ -0,0 +1,352 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
GetUserCredentials(
|
||||
IN const char *pRealm,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char **ppUsername,
|
||||
INOUT char **ppPassword)
|
||||
//
|
||||
// Arguments:
|
||||
// pRealm -
|
||||
// The realm to which the credentials apply.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged when running in
|
||||
// the context of System under Windows.
|
||||
//
|
||||
// ppUsername -
|
||||
// Pointer to variable that will receive buffer with the username.
|
||||
//
|
||||
// ppPassword -
|
||||
// Pointer to variable that will receive buffer with the password.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication credentials for the specified realm.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
char *pUsername;
|
||||
char *pPassword;
|
||||
int rcode = NSSCS_E_OBJECT_NOT_FOUND;
|
||||
uint32_t credtype = SSCS_CRED_TYPE_BASIC_F;
|
||||
SSCS_BASIC_CREDENTIAL credential = {0};
|
||||
SSCS_SECRET_ID_T secretId = {0};
|
||||
|
||||
DbgTrace(1, "-GetUserCredentials- Start\n", 0);
|
||||
|
||||
// Initialize output parameters
|
||||
*ppUsername = NULL;
|
||||
*ppPassword = NULL;
|
||||
|
||||
// Get the length of the realm string into the secret id structure
|
||||
// and verify thatr it is not too long.
|
||||
secretId.len = sscs_Utf8Strlen(pRealm) + 1;
|
||||
if (secretId.len <= NSSCS_MAX_SECRET_ID_LEN)
|
||||
{
|
||||
// Set the secret id in the structure
|
||||
sscs_Utf8Strcpy((char*) secretId.id, pRealm);
|
||||
|
||||
// Specify that we want the common name
|
||||
credential.unFlags = USERNAME_TYPE_CN_F;
|
||||
|
||||
// Now try to get the credentials
|
||||
rcode = miCASAGetCredential(0,
|
||||
&secretId,
|
||||
NULL,
|
||||
&credtype,
|
||||
&credential,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
if (rcode != NSSCS_SUCCESS)
|
||||
{
|
||||
// There were no credentials for the realm, now try to obtain the
|
||||
// desktop credentials.
|
||||
secretId.len = sscs_Utf8Strlen("Desktop") + 1;
|
||||
sscs_Utf8Strcpy((char*) secretId.id, "Desktop");
|
||||
rcode = miCASAGetCredential(0,
|
||||
&secretId,
|
||||
NULL,
|
||||
&credtype,
|
||||
&credential,
|
||||
(SSCS_EXT_T*) pCredStoreScope);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetUserCredentials- Realm name too long\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Proceed based on the result of the operatiosn above
|
||||
if (rcode == NSSCS_SUCCESS
|
||||
&& credential.username != NULL
|
||||
&& credential.password != NULL)
|
||||
{
|
||||
// Allocate a buffer to return the username
|
||||
pUsername = (char*) malloc(strlen((char*) credential.username) + 1);
|
||||
if (pUsername)
|
||||
{
|
||||
// Copy the username into the buffer that we will be returning
|
||||
strcpy(pUsername, (char*) credential.username);
|
||||
|
||||
// Allocate a buffer to return the password
|
||||
pPassword = (char*) malloc(strlen((char*) credential.password) + 1);
|
||||
if (pPassword)
|
||||
{
|
||||
// Copy the password into the buffer that we will be returning
|
||||
strcpy(pPassword, (char*) credential.password);
|
||||
|
||||
DbgTrace(1, "-GetUserCredentials- Username = %s\n", pUsername);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetUserCredentials- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
|
||||
// Free the buffer allocated for the username
|
||||
free(pUsername);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetUserCredentials- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetUserCredentials- Failed to obtain credentials for pw authentication\n", 0);
|
||||
}
|
||||
|
||||
// Return the buffers to the caller if successful
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
*ppUsername = pUsername;
|
||||
*ppPassword = pPassword;
|
||||
}
|
||||
|
||||
DbgTrace(1, "-GetUserCredentials- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
AuthTokenIf_GetAuthToken(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// pContext -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// context information. Another name for context is Authentication
|
||||
// Realm.
|
||||
//
|
||||
// pMechInfo -
|
||||
// Pointer to null terminated string containing mechanism specific
|
||||
// information. This is information is provided by the server to
|
||||
// aid the mechanism to generate an authentication token. For
|
||||
// example, the mechanism information for a Kerberos mechanism
|
||||
// may be the service principal name to which the user will be
|
||||
// authenticating.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to null terminated string containing the name of the
|
||||
// host where the ATS resides.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged when running in
|
||||
// the context of System under Windows.
|
||||
//
|
||||
// pTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pUserNameBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified service.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char *pUsername = NULL;
|
||||
char *pPassword = NULL;
|
||||
char *pToken;
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Start\n", 0);
|
||||
|
||||
// Validate input parameters
|
||||
if (pIfInstance == NULL
|
||||
|| pContext == NULL
|
||||
|| pHostName == NULL
|
||||
|| pTokenBufLen == NULL
|
||||
|| (pTokenBuf == NULL && *pTokenBufLen != 0))
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Invalid input parameter\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Get the user credentials
|
||||
retStatus = GetUserCredentials(pContext,
|
||||
pCredStoreScope,
|
||||
&pUsername,
|
||||
&pPassword);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Now construct the PW token with the following format:
|
||||
// "username\r\n" + "password\r\n"
|
||||
//
|
||||
// First allocate a buffer large enough to hold the token
|
||||
pToken = (char*) malloc(strlen(pUsername) + 2 + strlen(pPassword) + 2 + 1);
|
||||
if (pToken)
|
||||
{
|
||||
char *pEncodedToken;
|
||||
int encodedTokenLen;
|
||||
|
||||
// Now assemble the token
|
||||
sprintf(pToken, "%s\r\n%s\r\n", pUsername, pPassword);
|
||||
|
||||
// The token has been assembled, now encode it.
|
||||
retStatus = EncodeData(pToken,
|
||||
(const int) strlen(pToken),
|
||||
&pEncodedToken,
|
||||
&encodedTokenLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Verify that the caller provided a buffer that is big enough
|
||||
if (encodedTokenLen > *pTokenBufLen)
|
||||
{
|
||||
// The buffer is not big enough
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The buffer provided is large enough, copy the data.
|
||||
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Return the actual size or the size required
|
||||
*pTokenBufLen = encodedTokenLen;
|
||||
|
||||
// Free the buffer containing the encoded token
|
||||
free(pEncodedToken);
|
||||
}
|
||||
|
||||
// Free the buffer allocated for the token
|
||||
free(pToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Free allocated buffers
|
||||
free(pUsername);
|
||||
free(pPassword);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Failed to obtain the user credentials\n", 0);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
207
CASA-auth-token/client/core/mechanisms/pwd/interface.c
Normal file
207
CASA-auth-token/client/core/mechanisms/pwd/interface.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Authentication Token Interface instance data
|
||||
//
|
||||
typedef struct _AuthTokenIfInstance
|
||||
{
|
||||
int refCount;
|
||||
AuthTokenIf authTokenIf;
|
||||
|
||||
} AuthTokenIfInstance, *PAuthTokenIfInstance;
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// AuthTokenIf variables
|
||||
static
|
||||
int g_numAuthTokenIfObjs = 0;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
int SSCS_CALL
|
||||
AuthTokenIf_AddReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Interface reference count.
|
||||
//
|
||||
// Description:
|
||||
// Increases interface reference count.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int refCount;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance = CONTAINING_RECORD(pIfInstance, AuthTokenIfInstance, authTokenIf);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_AddReference- Start\n", 0);
|
||||
|
||||
// Increment the reference count on the object
|
||||
pAuthTokenIfInstance->refCount ++;
|
||||
refCount = pAuthTokenIfInstance->refCount;
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %08X\n", refCount);
|
||||
|
||||
return refCount;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void SSCS_CALL
|
||||
AuthTokenIf_ReleaseReference(
|
||||
IN const void *pIfInstance)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
// Pointer to interface object.
|
||||
//
|
||||
// Returns:
|
||||
// Nothing.
|
||||
//
|
||||
// Description:
|
||||
// Decreases interface reference count. The interface is deallocated if
|
||||
// the reference count becomes zero.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
bool freeObj = false;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance = CONTAINING_RECORD(pIfInstance, AuthTokenIfInstance, authTokenIf);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_ReleaseReference- Start\n", 0);
|
||||
|
||||
// Decrement the reference count on the object and determine if it needs to
|
||||
// be released.
|
||||
pAuthTokenIfInstance->refCount --;
|
||||
if (pAuthTokenIfInstance->refCount == 0)
|
||||
{
|
||||
// The object needs to be released, forget about it.
|
||||
freeObj = true;
|
||||
g_numAuthTokenIfObjs --;
|
||||
}
|
||||
|
||||
// Free object if necessary
|
||||
if (freeObj)
|
||||
free(pAuthTokenIfInstance);
|
||||
|
||||
DbgTrace(2, "-AuthTokenIf_ReleaseReference- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
GET_AUTH_TOKEN_INTERFACE_RTN(
|
||||
IN const ConfigIf *pModuleConfigIf,
|
||||
INOUT AuthTokenIf **ppAuthTokenIf)
|
||||
//
|
||||
// Arguments:
|
||||
// pModuleConfigIf -
|
||||
// Pointer to configuration interface instance for the module.
|
||||
//
|
||||
// ppAuthTokenIf -
|
||||
// Pointer to variable that will receive pointer to AuthTokenIf
|
||||
// instance.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Gets authentication token interface instance.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
AuthTokenIfInstance *pAuthTokenIfInstance;
|
||||
|
||||
|
||||
DbgTrace(1, "-GetAuthTokenInterface- Start\n", 0);
|
||||
|
||||
// Validate input parameters
|
||||
if (pModuleConfigIf == NULL
|
||||
|| ppAuthTokenIf == NULL)
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenInterface- Invalid input parameter\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INVALID_PARAMETER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Allocate space for the interface instance
|
||||
pAuthTokenIfInstance = malloc(sizeof(*pAuthTokenIfInstance));
|
||||
if (pAuthTokenIfInstance)
|
||||
{
|
||||
// Initialize the interface instance data
|
||||
pAuthTokenIfInstance->refCount = 1;
|
||||
pAuthTokenIfInstance->authTokenIf.addReference = AuthTokenIf_AddReference;
|
||||
pAuthTokenIfInstance->authTokenIf.releaseReference = AuthTokenIf_ReleaseReference;
|
||||
pAuthTokenIfInstance->authTokenIf.getAuthToken = AuthTokenIf_GetAuthToken;
|
||||
|
||||
// Keep track of this object
|
||||
g_numAuthTokenIfObjs ++;
|
||||
|
||||
// Return the interface to the caller
|
||||
*ppAuthTokenIf = &pAuthTokenIfInstance->authTokenIf;
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetAuthTokenInterface- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
90
CASA-auth-token/client/core/mechanisms/pwd/internal.h
Normal file
90
CASA-auth-token/client/core/mechanisms/pwd/internal.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _INTERNAL_H_
|
||||
#define _INTERNAL_H_
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include "platform.h"
|
||||
#include <micasa_types.h>
|
||||
#include <micasa_mgmd.h>
|
||||
#include <sscs_utf8.h>
|
||||
#include <casa_status.h>
|
||||
#include "config_if.h"
|
||||
#include "mech_if.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
extern int DebugLevel;
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
//
|
||||
// Defined in get.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus SSCS_CALL
|
||||
AuthTokenIf_GetAuthToken(
|
||||
IN const void *pIfInstance,
|
||||
IN const char *pContext,
|
||||
IN const char *pMechInfo,
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen);
|
||||
|
||||
//
|
||||
// Defined in utils.c
|
||||
//
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen);
|
||||
|
||||
extern
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen);
|
||||
|
||||
//=========================================================================
|
||||
|
||||
#endif // _INTERNAL_H_
|
||||
|
||||
122
CASA-auth-token/client/core/mechanisms/pwd/linux/Makefile.am
Normal file
122
CASA-auth-token/client/core/mechanisms/pwd/linux/Makefile.am
Normal file
@@ -0,0 +1,122 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
CFLAGS += -v -w
|
||||
DEFINES = -DDBG
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEFINES = -DNDEBUG
|
||||
endif
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
ROOT = ../../../..
|
||||
|
||||
LIBDIR = $(ROOT)/$(LIB)
|
||||
|
||||
# handle Mono secondary dependencies
|
||||
export MONO_PATH := $(MONO_PATH)
|
||||
|
||||
PLATFORMINDEPENDENTSOURCEDIR = ..
|
||||
PLATFORMDEPENDENTSOURCEDIR = .
|
||||
|
||||
MODULE_NAME = pwmech
|
||||
MODULE_EXT = so
|
||||
|
||||
CFILES = ../get.c \
|
||||
../interface.c \
|
||||
../util.c \
|
||||
platform.c
|
||||
|
||||
CSFILES_CSC :=
|
||||
INCLUDES = -I. -I.. -I../../.. -I$(ROOT)/include
|
||||
RESOURCES =
|
||||
|
||||
DEST_CONF_FILE_NAME = PwdAuthenticate.conf
|
||||
if LIB64
|
||||
DEFINES += -D_LIB64
|
||||
SRC_CONF_FILE_NAME = PwdAuthenticate_lib64.conf
|
||||
else
|
||||
SRC_CONF_FILE_NAME = PwdAuthenticate.conf
|
||||
endif
|
||||
|
||||
CFLAGS += -Wno-format-extra-args -fno-strict-aliasing $(INCLUDES) $(DEFINES)
|
||||
LIBS = -lpthread -lmicasa
|
||||
LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) -L$(ROOT)/lib/$(TARGET_CFG)
|
||||
|
||||
OBJDIR = ./$(TARGET_CFG)/$(LIB)
|
||||
OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o))
|
||||
|
||||
EXTRA_DIST = $(CFILES) *.h PwdAuthenticate.conf PwdAuthenticate_lib64.conf
|
||||
|
||||
CUR_DIR := $(shell pwd)
|
||||
|
||||
all: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
|
||||
#
|
||||
# Pattern based rules.
|
||||
#
|
||||
vpath %.c $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
vpath %.cpp $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT): $(OBJDIR) $(OBJS)
|
||||
@echo [======== Linking $@ ========]
|
||||
$(LINK) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
|
||||
cp -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(LIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
cp -f $(SRC_CONF_FILE_NAME) $(LIBDIR)/$(TARGET_CFG)/$(DEST_CONF_FILE_NAME)
|
||||
|
||||
$(OBJDIR):
|
||||
[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR)
|
||||
[ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
|
||||
[ -d $(LIBDIR)/$(TARGET_CFG) ] || mkdir -p $(LIBDIR)/$(TARGET_CFG)
|
||||
|
||||
install-exec-local: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
$(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
$(INSTALL_PROGRAM) $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(DESTDIR)$(libdir)/
|
||||
|
||||
uninstall-local:
|
||||
cd $(DESTDIR)$(libdir); rm -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
rmdir $(DESTDIR)$(libdir)
|
||||
|
||||
#installcheck-local: install
|
||||
# $(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
# $(INSTALL_PROGRAM) $(DESTDIR)$(libdir)
|
||||
# cd $(DESTDIR)$(libdir); $(MONO)
|
||||
|
||||
clean-local:
|
||||
if [ -d $(TARGET_CFG) ]; then rm -rf $(TARGET_CFG); fi
|
||||
|
||||
distclean-local:
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# PwdAuthenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName /usr/lib/CASA/authtoken/pwmech.so
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# PwdAuthenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName /usr/lib64/CASA/authtoken/pwmech.so
|
||||
|
||||
|
||||
35
CASA-auth-token/client/core/mechanisms/pwd/linux/platform.c
Normal file
35
CASA-auth-token/client/core/mechanisms/pwd/linux/platform.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
88
CASA-auth-token/client/core/mechanisms/pwd/linux/platform.h
Normal file
88
CASA-auth-token/client/core/mechanisms/pwd/linux/platform.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#define HANDLE void*
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
_snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
fprintf(stderr, "CASA_PwMech %s", printBuff); \
|
||||
} \
|
||||
}
|
||||
/*#define DbgTrace(LEVEL, X, Y) { \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
openlog("CASA_PwMech", LOG_CONS | LOG_NOWAIT | LOG_ODELAY, LOG_USER); \
|
||||
syslog(LOG_USER | LOG_INFO, X, Y); \
|
||||
closelog(); \
|
||||
} \
|
||||
}*/
|
||||
|
||||
|
||||
//
|
||||
// Deal with function name mapping issues
|
||||
//
|
||||
#define _snprintf snprintf
|
||||
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
282
CASA-auth-token/client/core/mechanisms/pwd/util.c
Normal file
282
CASA-auth-token/client/core/mechanisms/pwd/util.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Debug Level
|
||||
int DebugLevel = 0;
|
||||
|
||||
// Tables for Base64 encoding and decoding
|
||||
static const int8_t g_Base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
static const uint8_t g_Expand64[256] =
|
||||
{
|
||||
/* ASCII table */
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
DbgTrace(3, "-EncodeData- Start\n", 0);
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = g_Base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-EncodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int i, j;
|
||||
int decodedSize;
|
||||
|
||||
DbgTrace(3, "-DecodeData- Start\n", 0);
|
||||
|
||||
// Determine the decoded size
|
||||
for (i = 0, j = 0; i < encodedDataLen; i++)
|
||||
if (g_Expand64[((uint8_t*) pEncodedData)[i]] < 64)
|
||||
j++;
|
||||
decodedSize = (j * 3 + 3) / 4;
|
||||
|
||||
// Allocate buffer to hold the decoded data
|
||||
*ppData = malloc(decodedSize);
|
||||
if (*ppData)
|
||||
{
|
||||
bool endReached = false;
|
||||
uint8_t c0, c1, c2, c3;
|
||||
uint8_t *p, *q;
|
||||
|
||||
// Initialize parameters that will be used during the decode operation
|
||||
c0 = c1 = c2 = c3 = 0;
|
||||
p = (uint8_t*) pEncodedData;
|
||||
q = (uint8_t*) *ppData;
|
||||
|
||||
// Decode the data
|
||||
//
|
||||
// Loop through the data, piecing back information. Any newlines, and/or
|
||||
// carriage returns need to be skipped.
|
||||
while (j > 4)
|
||||
{
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c0 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2);
|
||||
j--;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c1 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4);
|
||||
j -= 2;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c2 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6);
|
||||
j -= 3;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c3 = *(p++);
|
||||
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6 | g_Expand64[c3]);
|
||||
j -= 4;
|
||||
}
|
||||
if (!endReached)
|
||||
{
|
||||
if (j > 1)
|
||||
*(q++) = (uint8_t)(g_Expand64[*p] << 2 | g_Expand64[p[1]] >> 4);
|
||||
if (j > 2)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[1]] << 4 | g_Expand64[p[2]] >> 2);
|
||||
if (j > 3)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[2]] << 6 | g_Expand64[p[3]]);
|
||||
}
|
||||
|
||||
// Return the length of the decoded data
|
||||
*pDataLen = (int32_t)(q - (uint8_t*)*ppData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-DecodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_PWTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = pwd.vcproj ../*.c *.c *.h *.conf *.def
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
endif
|
||||
|
||||
PACKAGE = pwd
|
||||
TARGET_FILE = pwmech.dll
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
|
||||
all-am: $(TARGET_FILE)
|
||||
|
||||
.PHONY: $TARGET_FILE) devenv
|
||||
|
||||
devenv:
|
||||
@if ! test -x "$(VSINSTALLDIR)/devenv.exe"; then echo "Error: Microsoft Visual Studio .NET is currently required to build MSI and MSM packages"; exit 1; fi
|
||||
|
||||
$(TARGET_FILE): devenv
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@CMD='"$(VSINSTALLDIR)/devenv.exe" ../../../../auth.sln /build $(TARGET_CFG) /project $(PACKAGE) /out $(LOG_FILE)'; \
|
||||
echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(TARGET_CFG)/$(TARGET_FILE); \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf Release/* Release Debug/* Debug*/Release */Debug *.log *.suo
|
||||
|
||||
clean:
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#######################################################
|
||||
# #
|
||||
# CASA Authentication Token System configuration file #
|
||||
# for module: #
|
||||
# #
|
||||
# PwdAuthenticate #
|
||||
# #
|
||||
#######################################################
|
||||
|
||||
LibraryName \Program Files\novell\casa\lib\pwmech.dll
|
||||
|
||||
|
||||
126
CASA-auth-token/client/core/mechanisms/pwd/windows/dllsup.c
Normal file
126
CASA-auth-token/client/core/mechanisms/pwd/windows/dllsup.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ External data ]=====================================================
|
||||
|
||||
//===[ Manifest constants ]================================================
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
UINT32 g_ulCount = 0;
|
||||
UINT32 g_ulLock = 0;
|
||||
HANDLE g_hModule;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
BOOL APIENTRY DllMain(
|
||||
HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
//=======================================================================--
|
||||
{
|
||||
BOOL retStatus = TRUE;
|
||||
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
|
||||
// Nothing else to do at this time
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
/* Don't uninitialize on windows
|
||||
tbd
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
//++=======================================================================
|
||||
//
|
||||
// DllCanUnloadNow
|
||||
//
|
||||
// Synopsis
|
||||
//
|
||||
//
|
||||
STDAPI
|
||||
DllCanUnloadNow()
|
||||
//
|
||||
// Input Arguments
|
||||
//
|
||||
// Ouput Arguments
|
||||
//
|
||||
// Return Value
|
||||
// S_OK The DLL can be unloaded.
|
||||
// S_FALSE The DLL cannot be unloaded now.
|
||||
//
|
||||
// Description
|
||||
// An Exported Function.
|
||||
// DLLs that support the OLE Component Object Model (COM) should implement
|
||||
// and export DllCanUnloadNow.
|
||||
// A call to DllCanUnloadNow determines whether the DLL from which it is
|
||||
// exported is still in use. A DLL is no longer in use when it is not
|
||||
// managing any existing objects (the reference count on all of its objects
|
||||
// is 0).
|
||||
// DllCanUnloadNow returns S_FALSE if there are any existing references to
|
||||
// objects that the DLL manages.
|
||||
//
|
||||
// Environment
|
||||
//
|
||||
// See Also
|
||||
//
|
||||
//=======================================================================--
|
||||
{
|
||||
// tbd
|
||||
return ((g_ulCount == 0 && g_ulLock == 0) ? S_OK : S_FALSE);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
//=========================================================================
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
|
||||
//===[ Include files ]=====================================================
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <winerror.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
//#define DbgTrace(LEVEL, X, Y) { \
|
||||
//char printBuff[256]; \
|
||||
// if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
// { \
|
||||
// _snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
// printf("PwdMech %s", printBuff); \
|
||||
// } \
|
||||
//}
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char formatBuff[128]; \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
strcpy(formatBuff, "CASA_PwdMech "); \
|
||||
strncat(formatBuff, X, sizeof(formatBuff) - 8); \
|
||||
_snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \
|
||||
OutputDebugString(printBuff); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define bool BOOLEAN
|
||||
#define true TRUE
|
||||
#define false FALSE
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
|
||||
//=========================================================================
|
||||
|
||||
#endif // _PLATFORM_H_
|
||||
|
||||
182
CASA-auth-token/client/core/mechanisms/pwd/windows/pwd.vcproj
Normal file
182
CASA-auth-token/client/core/mechanisms/pwd/windows/pwd.vcproj
Normal file
@@ -0,0 +1,182 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="pwd"
|
||||
ProjectGUID="{5499F624-F371-4559-B4C2-A484BCE892FD}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)client\mechanisms\pwd\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\mechanisms\pwd\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\;..\;..\..\..;..\..\..\..\include;"..\..\..\..\..\..\..\Expat-2.0.0\source\lib";"c:\Program Files\Novell\CASA\include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/EXPORT:GetAuthTokenInterface"
|
||||
AdditionalDependencies="micasa.lib"
|
||||
OutputFile="$(OutDir)/pwmech.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="C:\Program Files\novell\CASA\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/pw.pdb"
|
||||
SubSystem="0"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
mkdir \"Program Files"\novell\casa\etc\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\mechanisms\
|
||||
copy PwdAuthenticate.conf \"Program Files"\novell\casa\etc\auth\mechanisms\PwdAuthenticate.conf
|
||||
copy $(OutDir)\pwmech.dll \"Program Files"\novell\casa\lib\pwmech.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="$(SolutionDir)client\mechanisms\pwd\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\mechanisms\pwd\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=".\;..\;..\..\..;..\..\..\..\include;"..\..\..\..\..\..\..\Expat-2.0.0\source\lib";"c:\Program Files\Novell\CASA\include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/EXPORT:GetAuthTokenInterface"
|
||||
AdditionalDependencies="micasa.lib"
|
||||
OutputFile="$(OutDir)/pwmech.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="C:\Program Files\novell\CASA\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="0"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
mkdir \"Program Files"\novell\casa\etc\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\
|
||||
mkdir \"Program Files"\novell\casa\etc\auth\mechanisms\
|
||||
copy PwdAuthenticate.conf \"Program Files"\novell\casa\etc\auth\mechanisms\PwdAuthenticate.conf
|
||||
copy $(OutDir)\pwmech.dll \"Program Files"\novell\casa\lib\pwmech.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>
|
||||
</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=".\dllsup.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\get.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PwdAuthenticate.conf">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pwmech.def">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\util.c">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath="..\internal.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.h">
|
||||
</File>
|
||||
</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>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,10 @@
|
||||
LIBRARY PWMECH
|
||||
DESCRIPTION 'CASA PW Authentication Mechanism Library.'
|
||||
|
||||
|
||||
EXPORTS
|
||||
; DllRegisterServer PRIVATE
|
||||
; DllUnregisterServer PRIVATE
|
||||
; DllGetClassObject PRIVATE
|
||||
GetAuthTokenInterface PRIVATE
|
||||
; DllCanUnloadNow PRIVATE
|
||||
382
CASA-auth-token/client/core/test/CASA_Auth.cpp
Normal file
382
CASA-auth-token/client/core/test/CASA_Auth.cpp
Normal file
@@ -0,0 +1,382 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 "platform.h"
|
||||
|
||||
// Externals
|
||||
extern
|
||||
char *pServerAddress;
|
||||
|
||||
extern
|
||||
int serverPort;
|
||||
|
||||
extern
|
||||
bool execHttpTest;
|
||||
|
||||
extern
|
||||
char serviceName[];
|
||||
|
||||
extern
|
||||
char *pServiceName;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* EncodeData()
|
||||
*
|
||||
***********************************************************************/
|
||||
int
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
{
|
||||
int8_t base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
int retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-EncodeData- Buffer allocation failure\n");
|
||||
retStatus = -1;
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* NonHttpTest()
|
||||
*
|
||||
***********************************************************************/
|
||||
void NonHttpTest(void)
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char authToken[8192];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
|
||||
// Obtain an authentication token for the targeted service
|
||||
retStatus = ObtainAuthToken(pServiceName, pServerAddress, authToken, &authTokenLen);
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
SOCKET sock;
|
||||
struct sockaddr_in localAddr = {0};
|
||||
struct sockaddr_in remoteAddr = {0};
|
||||
struct linger linger_opt = {1, 15};
|
||||
struct hostent *pLookupResult;
|
||||
|
||||
printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
|
||||
// Send the token to the server
|
||||
//
|
||||
// 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 = 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("-NonHttpTest- Connection creation failed, error = %d\n", errno);
|
||||
}
|
||||
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 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("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-NonHttpTest- 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("-NonHttpTest- Unable to open socket, error = %d\n", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* HttpTest()
|
||||
*
|
||||
***********************************************************************/
|
||||
void HttpTest(void)
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
|
||||
// Obtain an authentication token for the targeted service
|
||||
retStatus = ObtainAuthToken(pServiceName, pServerAddress, authToken, &authTokenLen);
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
printf("-HttpTest- ObtainAuthToken failed with status %d\n", retStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
SOCKET sock;
|
||||
struct sockaddr_in localAddr = {0};
|
||||
struct sockaddr_in remoteAddr = {0};
|
||||
struct linger linger_opt = {1, 15};
|
||||
struct hostent *pLookupResult;
|
||||
|
||||
//printf("ObtainAuthToken succedded, token = %s\n", authToken);
|
||||
printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
|
||||
// Send the token to the server
|
||||
// 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 = 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("-HttpTest- Connection creation failed, error = %d\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pBasicCredentials;
|
||||
char *pEncodedBasicCredentials;
|
||||
int encodedLength;
|
||||
char CasaPrincipal[] = "CasaPrincipal:";
|
||||
char HTTPReqPart1[] = "GET /example-info HTTP/1.1\r\\nUser-Agent: CasaTestClient\r\nHost: jcstation.dnsdhcp.provo.novell.com:4096\r\nConnection: Keep-Alive\r\nAuthorization: Basic ";
|
||||
|
||||
// Now the connection is setup, send 1st part of HTTP request to the server.
|
||||
send(sock, HTTPReqPart1, (int) strlen(HTTPReqPart1), 0);
|
||||
|
||||
// Now setup the HTTP Basic Credentials
|
||||
pBasicCredentials = (char*) malloc(strlen(CasaPrincipal) + strlen(authToken) + 1);
|
||||
if (pBasicCredentials)
|
||||
{
|
||||
memcpy(pBasicCredentials, CasaPrincipal, sizeof(CasaPrincipal));
|
||||
strcat(pBasicCredentials, authToken);
|
||||
|
||||
// Now Base64 encode the credentials
|
||||
if (EncodeData((const void*) pBasicCredentials,
|
||||
(const int32_t) strlen(pBasicCredentials),
|
||||
&pEncodedBasicCredentials,
|
||||
(int32_t *) &encodedLength) == 0)
|
||||
{
|
||||
// Send the encoded credentials
|
||||
send(sock, pEncodedBasicCredentials, encodedLength - 1, 0);
|
||||
|
||||
// Send the rest of the header
|
||||
send(sock, "\r\n\r\n", 4, 0);
|
||||
|
||||
// Free the buffer holding the encoded credentials
|
||||
free(pEncodedBasicCredentials);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-HttpTest- Error encoding credentials\n");
|
||||
}
|
||||
|
||||
// Free the buffer containing the basic credentials
|
||||
free(pBasicCredentials);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-HttpTest- Buffer allocation failure\n");
|
||||
}
|
||||
|
||||
// Shutdown the connection
|
||||
shutdown(sock, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-HttpTest- Lookup for %s failed\n", pServerAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-HttpTest- 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("-HttpTest- Unable to open socket, error = %d\n", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
171
CASA-auth-token/client/core/test/linux/main.cpp
Normal file
171
CASA-auth-token/client/core/test/linux/main.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 "platform.h"
|
||||
|
||||
|
||||
// Extern functions
|
||||
extern
|
||||
void NonHttpTest(void);
|
||||
|
||||
extern
|
||||
void HttpTest(void);
|
||||
|
||||
|
||||
// Globals
|
||||
char usageString[] = "usage: test -a serverAddress -p serverPort [-s serviceName] [-h]\n";
|
||||
|
||||
char *pServerAddress = NULL;
|
||||
int serverPort = 0;
|
||||
bool execHttpTest = false;
|
||||
|
||||
char serviceName[] = "testService";
|
||||
char *pServiceName = serviceName;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* dtoul()
|
||||
*
|
||||
***********************************************************************/
|
||||
int
|
||||
dtoul(
|
||||
IN char *cp,
|
||||
IN int len)
|
||||
{
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++, cp++)
|
||||
{
|
||||
// Verify that we are dealing with a valid digit
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
n = 10 * n + (*cp - '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-dtoul- Found invalid digit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* main()
|
||||
*
|
||||
***********************************************************************/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Process input parameters
|
||||
int i = 1;
|
||||
while(argv[i] != NULL)
|
||||
{
|
||||
if (strcasecmp(argv[i], "-a") == 0)
|
||||
{
|
||||
// Server Address option, the next argument should
|
||||
// contain the address.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
pServerAddress = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(argv[i], "-p") == 0)
|
||||
{
|
||||
// Server port option, the next argument should
|
||||
// contain the port.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
serverPort = htons(dtoul(argv[i], strlen(argv[i])));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(argv[i], "-s") == 0)
|
||||
{
|
||||
// Service name option, the next argument should
|
||||
// contain the name of the service to be targeted.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
pServiceName = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(argv[i], "-h") == 0)
|
||||
{
|
||||
// Perform http test option
|
||||
execHttpTest = true;
|
||||
}
|
||||
|
||||
// Advance to the next argument
|
||||
i++;
|
||||
}
|
||||
|
||||
// Verify that the server address and port were specified
|
||||
if (pServerAddress && serverPort != 0)
|
||||
{
|
||||
// Repeat the test when indicated
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
while(getchar() != 'n')
|
||||
{
|
||||
// Execute the appropriate test
|
||||
if (execHttpTest)
|
||||
{
|
||||
HttpTest();
|
||||
}
|
||||
else
|
||||
{
|
||||
NonHttpTest();
|
||||
}
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
2
CASA-auth-token/client/core/test/linux/make.sh
Executable file
2
CASA-auth-token/client/core/test/linux/make.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
g++ -o authClientTest ../CASA_Auth.cpp main.cpp -g -DN_PLAT_UNIX -I. -I../../../include -L"../../../lib/Release" -lcasa_c_authtoken -Xlinker -rpath -Xlinker ../../../lib/Release
|
||||
54
CASA-auth-token/client/core/test/linux/platform.h
Normal file
54
CASA-auth-token/client/core/test/linux/platform.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <micasa_types.h>
|
||||
#include <casa_status.h>
|
||||
#include "casa_c_authtoken.h"
|
||||
|
||||
//
|
||||
// Socket Mapping definitions
|
||||
//
|
||||
#undef SOCKET
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#define LINGER struct linger
|
||||
#define SOCKADDR_IN struct sockaddr_in
|
||||
#define closesocket close
|
||||
|
||||
187
CASA-auth-token/client/core/test/windows/main.cpp
Normal file
187
CASA-auth-token/client/core/test/windows/main.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 "platform.h"
|
||||
|
||||
// Extern functions
|
||||
extern
|
||||
void NonHttpTest(void);
|
||||
|
||||
extern
|
||||
void HttpTest(void);
|
||||
|
||||
|
||||
// Globals
|
||||
char usageString[] = "usage: test -a serverAddress -p serverPort [-s serviceName] [-h]\n";
|
||||
|
||||
char *pServerAddress = NULL;
|
||||
int serverPort = 0;
|
||||
BOOLEAN execHttpTest = FALSE;
|
||||
|
||||
char serviceName[] = "testService";
|
||||
char *pServiceName = serviceName;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* dtoul()
|
||||
*
|
||||
***********************************************************************/
|
||||
int
|
||||
dtoul(
|
||||
IN char *cp,
|
||||
IN int len)
|
||||
{
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++, cp++)
|
||||
{
|
||||
// Verify that we are dealing with a valid digit
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
n = 10 * n + (*cp - '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-dtoul- Found invalid digit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* main()
|
||||
*
|
||||
***********************************************************************/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Process input parameters
|
||||
int i = 1;
|
||||
while(argv[i] != NULL)
|
||||
{
|
||||
if (stricmp(argv[i], "-a") == 0)
|
||||
{
|
||||
// Server Address option, the next argument should
|
||||
// contain the address.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
pServerAddress = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (stricmp(argv[i], "-p") == 0)
|
||||
{
|
||||
// Server port option, the next argument should
|
||||
// contain the port.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
serverPort = htons(dtoul(argv[i], (int) strlen(argv[i])));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (stricmp(argv[i], "-s") == 0)
|
||||
{
|
||||
// Service name option, the next argument should
|
||||
// contain the name of the service to be targeted.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
pServiceName = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (stricmp(argv[i], "-h") == 0)
|
||||
{
|
||||
// Perform http test option
|
||||
execHttpTest = TRUE;
|
||||
}
|
||||
|
||||
// Advance to the next argument
|
||||
i++;
|
||||
}
|
||||
|
||||
// Verify that the server address and port were specified
|
||||
if (pServerAddress && serverPort != 0)
|
||||
{
|
||||
int winsockStartupResult;
|
||||
WSADATA winsockData;
|
||||
|
||||
// First initialize winsock
|
||||
if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0)
|
||||
{
|
||||
// Repeat the test when indicated
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
while(getchar() != 'n')
|
||||
{
|
||||
// Execute the appropriate test
|
||||
if (execHttpTest)
|
||||
{
|
||||
HttpTest();
|
||||
}
|
||||
else
|
||||
{
|
||||
NonHttpTest();
|
||||
}
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
}
|
||||
|
||||
// Close winsock
|
||||
WSACleanup();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-main- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
29
CASA-auth-token/client/core/test/windows/platform.h
Normal file
29
CASA-auth-token/client/core/test/windows/platform.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <windows.h>
|
||||
#include "casa_c_authtoken.h"
|
||||
|
||||
//#define errno WSAGetLastError()
|
||||
145
CASA-auth-token/client/core/test/windows/test.vcproj
Normal file
145
CASA-auth-token/client/core/test/windows/test.vcproj
Normal file
@@ -0,0 +1,145 @@
|
||||
<?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;"C:\Program Files\novell\CASA\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=""C:\Program Files\novell\CASA\lib""
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy ..\..\windows\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;"C:\Program Files\novell\CASA\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>
|
||||
<File
|
||||
RelativePath=".\main.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath=".\platform.h">
|
||||
</File>
|
||||
</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>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
321
CASA-auth-token/client/core/util.c
Normal file
321
CASA-auth-token/client/core/util.c
Normal file
@@ -0,0 +1,321 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Tables for Base64 encoding and decoding
|
||||
static const int8_t g_Base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
static const uint8_t g_Expand64[256] =
|
||||
{
|
||||
/* ASCII table */
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
DbgTrace(3, "-EncodeData- Start\n", 0);
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = g_Base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-EncodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
DecodeData(
|
||||
IN const char *pEncodedData,
|
||||
IN const int32_t encodedDataLen, // Does not include NULL terminator
|
||||
INOUT void **ppData,
|
||||
INOUT int32_t *pDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int i, j;
|
||||
int decodedSize;
|
||||
|
||||
DbgTrace(3, "-DecodeData- Start\n", 0);
|
||||
|
||||
// Determine the decoded size
|
||||
for (i = 0, j = 0; i < encodedDataLen; i++)
|
||||
if (g_Expand64[((uint8_t*) pEncodedData)[i]] < 64)
|
||||
j++;
|
||||
decodedSize = (j * 3 + 3) / 4;
|
||||
|
||||
// Allocate buffer to hold the decoded data
|
||||
*ppData = malloc(decodedSize);
|
||||
if (*ppData)
|
||||
{
|
||||
bool endReached = false;
|
||||
uint8_t c0, c1, c2, c3;
|
||||
uint8_t *p, *q;
|
||||
|
||||
// Initialize parameters that will be used during the decode operation
|
||||
c0 = c1 = c2 = c3 = 0;
|
||||
p = (uint8_t*) pEncodedData;
|
||||
q = (uint8_t*) *ppData;
|
||||
|
||||
// Decode the data
|
||||
//
|
||||
// Loop through the data, piecing back information. Any newlines, and/or
|
||||
// carriage returns need to be skipped.
|
||||
while (j > 4)
|
||||
{
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c0 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2);
|
||||
j--;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c1 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4);
|
||||
j -= 2;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c2 = *(p++);
|
||||
|
||||
while ((64 == g_Expand64[*p]) && (('\n' == *p) || ('\r' == *p)))
|
||||
p++;
|
||||
if (64 == g_Expand64[*p])
|
||||
{
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6);
|
||||
j -= 3;
|
||||
endReached = true;
|
||||
break;
|
||||
}
|
||||
c3 = *(p++);
|
||||
|
||||
*(q++) = (uint8_t)(g_Expand64[c0] << 2 | g_Expand64[c1] >> 4);
|
||||
*(q++) = (uint8_t)(g_Expand64[c1] << 4 | g_Expand64[c2] >> 2);
|
||||
*(q++) = (uint8_t)(g_Expand64[c2] << 6 | g_Expand64[c3]);
|
||||
j -= 4;
|
||||
}
|
||||
if (!endReached)
|
||||
{
|
||||
if (j > 1)
|
||||
*(q++) = (uint8_t)(g_Expand64[*p] << 2 | g_Expand64[p[1]] >> 4);
|
||||
if (j > 2)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[1]] << 4 | g_Expand64[p[2]] >> 2);
|
||||
if (j > 3)
|
||||
*(q++) = (uint8_t)(g_Expand64[p[2]] << 6 | g_Expand64[p[3]]);
|
||||
}
|
||||
|
||||
// Return the length of the decoded data
|
||||
*pDataLen = (int32_t)(q - (uint8_t*)*ppData);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-DecodeData- Buffer allocation failure\n", 0);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
int
|
||||
dtoul(
|
||||
IN const char *cp,
|
||||
IN const int len)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
DbgTrace(2, "-dtoul- Start\n", 0);
|
||||
|
||||
for (i = 0; i < len; i++, cp++)
|
||||
{
|
||||
// Verify that we are dealing with a valid digit
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
n = 10 * n + (*cp - '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-dtoul- Found invalid digit\n", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(2, "-dtoul- End, result = %d\n", n);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
69
CASA-auth-token/client/core/windows/Makefile.am
Normal file
69
CASA-auth-token/client/core/windows/Makefile.am
Normal file
@@ -0,0 +1,69 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program 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
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = client.vcproj ../*.c *.c *.h *.def
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
endif
|
||||
|
||||
PACKAGE = client
|
||||
TARGET_FILE = authtoken.dll
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
|
||||
all-am: $(TARGET_FILE)
|
||||
|
||||
.PHONY: $TARGET_FILE) devenv
|
||||
|
||||
devenv:
|
||||
@if ! test -x "$(VSINSTALLDIR)/devenv.exe"; then echo "Error: Microsoft Visual Studio .NET is currently required to build MSI and MSM packages"; exit 1; fi
|
||||
|
||||
$(TARGET_FILE): devenv
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@CMD='"$(VSINSTALLDIR)/devenv.exe" ../../auth.sln /build $(TARGET_CFG) /project $(PACKAGE) /out $(LOG_FILE)'; \
|
||||
echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(TARGET_CFG)/$(TARGET_FILE); \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf Release/* Release Debug/* Debug*/Release */Debug *.log *.suo
|
||||
|
||||
clean:
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
||||
11
CASA-auth-token/client/core/windows/authtoken.def
Normal file
11
CASA-auth-token/client/core/windows/authtoken.def
Normal file
@@ -0,0 +1,11 @@
|
||||
LIBRARY AUTHTOKEN
|
||||
DESCRIPTION 'CASA Authentication Token Library.'
|
||||
|
||||
|
||||
EXPORTS
|
||||
; DllRegisterServer PRIVATE
|
||||
; DllUnregisterServer PRIVATE
|
||||
; DllGetClassObject PRIVATE
|
||||
ObtainAuthToken PRIVATE
|
||||
ObtainAuthTokenEx PRIVATE
|
||||
; DllCanUnloadNow PRIVATE
|
||||
224
CASA-auth-token/client/core/windows/client.vcproj
Normal file
224
CASA-auth-token/client/core/windows/client.vcproj
Normal file
@@ -0,0 +1,224 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="client"
|
||||
ProjectGUID="{7BD9A5DB-DE7D-40B7-A397-04182DC2F632}"
|
||||
RootNamespace="client"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)client\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "XML_STATIC""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".;..\;..\..\include;..\..\include\windows;"\Program Files\novell\casa\include";"C:\Dev\Expat-2.0.0\Source\lib""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="FALSE"
|
||||
AdditionalOptions="/EXPORT:ObtainAuthToken /EXPORT:ObtainAuthTokenEx"
|
||||
AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib shlwapi.lib"
|
||||
OutputFile="$(OutDir)/authtoken.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""\Program Files\Novell\CASA\lib";"C:\Dev\Expat-2.0.0\StaticLibs""
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/client.pdb"
|
||||
SubSystem="0"
|
||||
ImportLibrary="$(SolutionDir)client\windows/$(TargetName).lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
copy $(OutDir)\authtoken.dll \"Program Files"\novell\casa\lib\authtoken.dll
|
||||
copy $(SolutionDir)\client\windows\authtoken.lib \"Program Files"\novell\casa\lib\authtoken.lib
|
||||
"/>
|
||||
<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="$(SolutionDir)client\windows\$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)client\windows\$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "XML_STATIC""
|
||||
AdditionalIncludeDirectories=".;..\;..\..\include;..\..\include\windows;"\Program Files\novell\casa\include";"C:\Dev\Expat-2.0.0\Source\lib""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/EXPORT:ObtainAuthToken /EXPORT:ObtainAuthTokenEx"
|
||||
AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib shlwapi.lib"
|
||||
OutputFile="$(OutDir)/authtoken.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""\Program Files\Novell\CASA\lib";"C:\Dev\Expat-2.0.0\StaticLibs""
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="0"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(SolutionDir)client\windows\$(TargetName).lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="mkdir \"Program Files"\novell\
|
||||
mkdir \"Program Files"\novell\casa
|
||||
mkdir \"Program Files"\novell\casa\lib\
|
||||
copy $(OutDir)\authtoken.dll \"Program Files"\novell\casa\lib\authtoken.dll
|
||||
copy $(SolutionDir)\client\windows\authtoken.lib \"Program Files"\novell\casa\lib\authtoken.lib
|
||||
"/>
|
||||
<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="..\authmech.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\authmsg.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\authpolicy.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\authtoken.def">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\cache.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\client.conf">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\config.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dllsup.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\engine.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\getpolicymsg.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\gettokenmsg.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\invalidcert.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\rpc.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\util.c">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath="..\..\include\casa_c_authtoken.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\windows\casa_c_authtoken_ex.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\config_if.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\internal.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\list_entry.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\mech_if.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\platform.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\proto.h">
|
||||
</File>
|
||||
</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>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
233
CASA-auth-token/client/core/windows/dllsup.c
Normal file
233
CASA-auth-token/client/core/windows/dllsup.c
Normal file
@@ -0,0 +1,233 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
#include <shlobj.h>
|
||||
#include <shlwapi.h>
|
||||
#include "casa_c_authtoken_ex.h"
|
||||
|
||||
//===[ External data ]=====================================================
|
||||
extern
|
||||
char clientConfigFolderPartialPath[];
|
||||
|
||||
extern
|
||||
char mechConfigFolderPartialPath[];
|
||||
|
||||
//===[ Manifest constants ]================================================
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
UINT32 g_ulCount = 0;
|
||||
UINT32 g_ulLock = 0;
|
||||
HANDLE g_hModule;
|
||||
HANDLE g_hModuleMutex;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
ObtainAuthTokenEx(
|
||||
IN const char *pServiceName,
|
||||
IN const char *pHostName,
|
||||
INOUT char *pAuthTokenBuf,
|
||||
INOUT int *pAuthTokenBufLen,
|
||||
IN void *pCredStoreScope)
|
||||
//
|
||||
// Arguments:
|
||||
// pServiceName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the service to which the client is trying to
|
||||
// authenticate.
|
||||
//
|
||||
// pHostName -
|
||||
// Pointer to NULL terminated string that contains the
|
||||
// name of the host where resides the service to which the
|
||||
// client is trying to authenticate. Note that the name
|
||||
// can either be a DNS name or a dotted IP address.
|
||||
//
|
||||
// pAuthTokenBuf -
|
||||
// Pointer to buffer that will receive the authentication
|
||||
// token. The length of this buffer is specified by the
|
||||
// pAuthTokenBufLen parameter. Note that the the authentication
|
||||
// token will be in the form of a NULL terminated string.
|
||||
//
|
||||
// pAuthTokenBufLen -
|
||||
// Pointer to integer that contains the length of the
|
||||
// buffer pointed at by pAuthTokenBuf. Upon return of the
|
||||
// function, the integer will contain the actual length
|
||||
// of the authentication token if the function successfully
|
||||
// completes or the buffer length required if the function
|
||||
// fails because the buffer pointed at by pAuthTokenBuf is
|
||||
// not large enough.
|
||||
//
|
||||
// pCredStoreScope -
|
||||
// Pointer to CASA structure for scoping credential store access
|
||||
// to specific users. This can only be leveraged by applications
|
||||
// running in the context of System.
|
||||
//
|
||||
// Returns:
|
||||
// Casa Status
|
||||
//
|
||||
// Description:
|
||||
// Get authentication token to authenticate user to specified
|
||||
// service at host. The user is scoped using the info associated
|
||||
// with the magic cookie.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenEx- Start\n", 0);
|
||||
|
||||
// Call our internal worker
|
||||
retStatus = ObtainAuthTokenInt(pServiceName,
|
||||
pHostName,
|
||||
pAuthTokenBuf,
|
||||
pAuthTokenBufLen,
|
||||
pCredStoreScope);
|
||||
|
||||
DbgTrace(1, "-ObtainAuthTokenEx- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
BOOL APIENTRY DllMain(
|
||||
HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
//=======================================================================--
|
||||
{
|
||||
BOOL retStatus = TRUE;
|
||||
char programFilesFolder[MAX_PATH];
|
||||
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
|
||||
// Setup the path to the client and auth mechanisms config folders
|
||||
if (SHGetFolderPath(NULL,
|
||||
CSIDL_PROGRAM_FILES,
|
||||
NULL,
|
||||
0,
|
||||
programFilesFolder) == 0)
|
||||
{
|
||||
strcpy(clientConfigFolder, programFilesFolder);
|
||||
PathAppend(clientConfigFolder, clientConfigFolderPartialPath);
|
||||
|
||||
strcpy(mechConfigFolder, programFilesFolder);
|
||||
PathAppend(mechConfigFolder, mechConfigFolderPartialPath);
|
||||
|
||||
// Allocate module mutex
|
||||
g_hModuleMutex = CreateMutex(NULL, FALSE, NULL);
|
||||
if (! g_hModuleMutex)
|
||||
{
|
||||
// Module initialization failed
|
||||
OutputDebugString("CASAAUTH -DllMain- Failed to create mutex\n");
|
||||
retStatus = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed to obtain the Program Files path
|
||||
OutputDebugString("CASAAUTH -DllMain- Failed to obtain the Program Files path\n");
|
||||
retStatus = FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
g_hModule = hModule;
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
/* Don't uninitialize on windows
|
||||
tbd
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
//++=======================================================================
|
||||
//
|
||||
// DllCanUnloadNow
|
||||
//
|
||||
// Synopsis
|
||||
//
|
||||
//
|
||||
STDAPI
|
||||
DllCanUnloadNow()
|
||||
//
|
||||
// Input Arguments
|
||||
//
|
||||
// Ouput Arguments
|
||||
//
|
||||
// Return Value
|
||||
// S_OK The DLL can be unloaded.
|
||||
// S_FALSE The DLL cannot be unloaded now.
|
||||
//
|
||||
// Description
|
||||
// An Exported Function.
|
||||
// DLLs that support the OLE Component Object Model (COM) should implement
|
||||
// and export DllCanUnloadNow.
|
||||
// A call to DllCanUnloadNow determines whether the DLL from which it is
|
||||
// exported is still in use. A DLL is no longer in use when it is not
|
||||
// managing any existing objects (the reference count on all of its objects
|
||||
// is 0).
|
||||
// DllCanUnloadNow returns S_FALSE if there are any existing references to
|
||||
// objects that the DLL manages.
|
||||
//
|
||||
// Environment
|
||||
//
|
||||
// See Also
|
||||
//
|
||||
//=======================================================================--
|
||||
{
|
||||
// tbd
|
||||
return ((g_ulCount == 0 && g_ulLock == 0) ? S_OK : S_FALSE);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
//=========================================================================
|
||||
|
||||
580
CASA-auth-token/client/core/windows/platform.c
Normal file
580
CASA-auth-token/client/core/windows/platform.c
Normal file
@@ -0,0 +1,580 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Normalized Host Name Cache Entry definition
|
||||
//
|
||||
typedef struct _NormalizedHostNameCacheEntry
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pHostName;
|
||||
char *pNormalizedHostName;
|
||||
int buffLengthRequired;
|
||||
|
||||
} NormalizedHostNameCacheEntry, *PNormalizedHostNameCacheEntry;
|
||||
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
// Normalized host name cache list head
|
||||
static
|
||||
LIST_ENTRY normalizedHostNameCacheListHead;
|
||||
|
||||
// Synchronization mutex for the normalized host name cache
|
||||
static
|
||||
HANDLE hNormalizedHostNameCacheMutex;
|
||||
|
||||
// Client configuration file folder
|
||||
char clientConfigFolder[MAX_PATH];
|
||||
char clientConfigFolderPartialPath[] = "Novell\\Casa\\Etc\\Auth";
|
||||
|
||||
// Authentication mechanism configuration file folder
|
||||
char mechConfigFolder[MAX_PATH];
|
||||
char mechConfigFolderPartialPath[] = "Novell\\Casa\\Etc\\Auth\\Mechanisms";
|
||||
|
||||
// Path separator
|
||||
char pathCharString[] = "\\";
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
CreateUserMutex(
|
||||
HANDLE *phMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
char *pUsername = NULL;
|
||||
DWORD nameLength = 0;
|
||||
|
||||
DbgTrace(1, "-CreateUserMutex- Start\n", 0);
|
||||
|
||||
// Get the size of the buffer required to obtain the user name
|
||||
GetUserName(pUsername, &nameLength);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
// Allocate buffer to hold the user name
|
||||
pUsername = (char*) malloc(nameLength);
|
||||
if (pUsername)
|
||||
{
|
||||
// Get the name of the user
|
||||
if (GetUserName(pUsername, &nameLength))
|
||||
{
|
||||
SECURITY_ATTRIBUTES mutexAttributes;
|
||||
char mutexName[256];
|
||||
|
||||
// Now lets create a global semaphore for the
|
||||
// user and allow its handle to be inherited.
|
||||
mutexAttributes.nLength = sizeof(mutexAttributes);
|
||||
mutexAttributes.lpSecurityDescriptor = NULL;
|
||||
mutexAttributes.bInheritHandle = TRUE;
|
||||
if (sprintf(mutexName, "Global\\CASA_Auth_Mutex_%s", pUsername) != -1)
|
||||
{
|
||||
*phMutex = CreateMutex(&mutexAttributes,
|
||||
FALSE,
|
||||
mutexName);
|
||||
if (*phMutex == NULL)
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- CreateMutex failed, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- sprintf failed, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- GetUserName failed, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Free the buffer allocated to hold the user name
|
||||
free(pUsername);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- Buffer allocation error\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-CreateUserMutex- Unexpected GetUserName error, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-CreateUserMutex- End, retStatus\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
AcquireUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-AcquireUserMutex- Start\n", 0);
|
||||
|
||||
WaitForSingleObject(hMutex, INFINITE);
|
||||
|
||||
DbgTrace(2, "-AcquireUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
ReleaseUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-ReleaseUserMutex- Start\n", 0);
|
||||
|
||||
if (ReleaseMutex(hMutex) == 0)
|
||||
{
|
||||
DbgTrace(0, "-ReleaseUserMutex- ReleaseMutex failed, error = %d\n", GetLastError());
|
||||
}
|
||||
|
||||
DbgTrace(2, "-ReleaseUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
DestroyUserMutex(
|
||||
HANDLE hMutex
|
||||
)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(2, "-DestroyUserMutex- Start\n", 0);
|
||||
|
||||
if (CloseHandle(hMutex) == 0)
|
||||
{
|
||||
DbgTrace(0, "-DestroyUserMutex- CloseHandle failed, error = %d\n", GetLastError());
|
||||
}
|
||||
|
||||
DbgTrace(2, "-DestroyUserMutex- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
LIB_HANDLE
|
||||
OpenLibrary(
|
||||
IN char *pFileName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
LIB_HANDLE libHandle;
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- Start\n", 0);
|
||||
|
||||
libHandle = LoadLibrary(pFileName);
|
||||
if (libHandle == NULL)
|
||||
{
|
||||
DbgTrace(0, "-OpenLibrary- Not able to load library, error = %d\n", GetLastError());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- End, handle = %08X\n", libHandle);
|
||||
|
||||
return libHandle;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
CloseLibrary(
|
||||
IN LIB_HANDLE libHandle)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-CloseLibrary- Start\n", 0);
|
||||
|
||||
FreeLibrary(libHandle);
|
||||
|
||||
DbgTrace(1, "-CloseLibrary- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void*
|
||||
GetFunctionPtr(
|
||||
IN LIB_HANDLE libHandle,
|
||||
IN char *pFunctionName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
void *pFuncPtr;
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- Start\n", 0);
|
||||
|
||||
pFuncPtr = GetProcAddress(libHandle, pFunctionName);
|
||||
if (pFuncPtr == NULL)
|
||||
{
|
||||
DbgTrace(0, "-GetFunctionPtr- Not able to obtain func ptr, error = %d\n", GetLastError());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- End, pFuncPtr = %08X\n", pFuncPtr);
|
||||
|
||||
return pFuncPtr;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
char*
|
||||
NormalizeHostName(
|
||||
IN const char *pHostName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
char *pNormalizedName = NULL;
|
||||
LIST_ENTRY *pListEntry;
|
||||
NormalizedHostNameCacheEntry *pEntry = NULL;
|
||||
|
||||
DbgTrace(1, "-NormalizeHostName- Start\n", 0);
|
||||
|
||||
// Obtain our synchronization mutex
|
||||
WaitForSingleObject(hNormalizedHostNameCacheMutex, INFINITE);
|
||||
|
||||
// First try to find an entry in the normalized host name cache
|
||||
// for the host name provided.
|
||||
pListEntry = normalizedHostNameCacheListHead.Flink;
|
||||
while (pListEntry != &normalizedHostNameCacheListHead)
|
||||
{
|
||||
// Get pointer to the entry
|
||||
pEntry = CONTAINING_RECORD(pListEntry, NormalizedHostNameCacheEntry, listEntry);
|
||||
|
||||
// Check if the entry is for the host name
|
||||
if (strcmp(pHostName, pEntry->pHostName) == 0)
|
||||
{
|
||||
// This entry corresponds to the given host name
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entry does not correspond to the given host name
|
||||
pEntry = NULL;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Check if we found an entry in our cache for the given host name
|
||||
if (pEntry)
|
||||
{
|
||||
// Entry found, obtain the normalized name from it.
|
||||
pNormalizedName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pNormalizedName)
|
||||
{
|
||||
// Copy the normalized name onto the allocated buffer
|
||||
strcpy(pNormalizedName, pEntry->pNormalizedHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// An entry was not found in our cache, create one.
|
||||
pEntry = (NormalizedHostNameCacheEntry*) malloc(sizeof(NormalizedHostNameCacheEntry));
|
||||
if (pEntry)
|
||||
{
|
||||
// Zero the entry
|
||||
memset(pEntry, 0, sizeof(*pEntry));
|
||||
|
||||
// Allocate a buffer to hold the host name in the entry
|
||||
pEntry->pHostName = (char*) malloc(strlen(pHostName) + 1);
|
||||
if (pEntry->pHostName)
|
||||
{
|
||||
struct hostent *pLookupResult;
|
||||
struct sockaddr_in sockAddr = {0};
|
||||
|
||||
// Copy the host name given into the allocated buffer
|
||||
strcpy(pEntry->pHostName, pHostName);
|
||||
|
||||
// Now try to resolve the normalized name
|
||||
pLookupResult = gethostbyname(pHostName);
|
||||
if (pLookupResult && pLookupResult->h_addrtype == AF_INET)
|
||||
{
|
||||
char dnsHostName[NI_MAXHOST];
|
||||
|
||||
// Set up a sockaddr structure
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_addr.S_un.S_addr = *((int*) pLookupResult->h_addr_list[0]);
|
||||
|
||||
// Now try to resolve the name using DNS
|
||||
if (getnameinfo((const struct sockaddr*) &sockAddr,
|
||||
sizeof(sockAddr),
|
||||
dnsHostName,
|
||||
sizeof(dnsHostName),
|
||||
NULL,
|
||||
0,
|
||||
NI_NAMEREQD) == 0)
|
||||
{
|
||||
// We resolved the address to a DNS name, use it as the normalized name.
|
||||
pEntry->buffLengthRequired = (int) strlen(dnsHostName) + 1;
|
||||
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// Copy the dns name
|
||||
strcpy(pEntry->pNormalizedHostName, dnsHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- getnameInfo failed, error %d\n", WSAGetLastError());
|
||||
|
||||
// Not able to resolve the name in DNS, just use the host name as
|
||||
// the normalized name.
|
||||
pEntry->buffLengthRequired = (int) strlen(pHostName) + 1;
|
||||
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// Copy the host name
|
||||
strcpy(pEntry->pNormalizedHostName, pHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Name resolution failed, error = %d\n", WSAGetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
|
||||
// Free the space allocated for the entry
|
||||
free(pEntry);
|
||||
}
|
||||
|
||||
// Proceed based on whether or not we normalized the name
|
||||
if (pEntry->pNormalizedHostName)
|
||||
{
|
||||
// The name was normalized, save the entry in our cache.
|
||||
InsertHeadList(&normalizedHostNameCacheListHead, &pEntry->listEntry);
|
||||
|
||||
// Return the normalized name present in the entry
|
||||
pNormalizedName = (char*) malloc(pEntry->buffLengthRequired);
|
||||
if (pNormalizedName)
|
||||
{
|
||||
// Copy the normalized name onto the allocated buffer
|
||||
strcpy(pNormalizedName, pEntry->pNormalizedHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The host name was not normalized, free allocated resources.
|
||||
if (pEntry->pHostName)
|
||||
free(pEntry->pHostName);
|
||||
free(pEntry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Release our synchronization mutex
|
||||
if (ReleaseMutex(hNormalizedHostNameCacheMutex) == 0)
|
||||
{
|
||||
DbgTrace(0, "-NormalizeHostName- ReleaseMutex failed, error\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-NormalizeHostName- End, pNormalizedName = %08X\n", pNormalizedName);
|
||||
|
||||
return pNormalizedName;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
InitializeHostNameNormalization(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
int winsockStartupResult;
|
||||
WSADATA winsockData;
|
||||
|
||||
DbgTrace(1, "-InitializeHostNameNormalization- Start\n", 0);
|
||||
|
||||
// Initialize winsock
|
||||
if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0)
|
||||
{
|
||||
// Initialize the cache list head
|
||||
InitializeListHead(&normalizedHostNameCacheListHead);
|
||||
|
||||
// Create a cache mutex only applicable to the current process
|
||||
hNormalizedHostNameCacheMutex = CreateMutex(NULL,
|
||||
FALSE,
|
||||
NULL);
|
||||
if (hNormalizedHostNameCacheMutex != NULL)
|
||||
{
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InitializeHostNameNormalization- CreateMutex failed, error = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InitializeHostNameNormalization- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InitializeHostNameNormalization- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
103
CASA-auth-token/client/core/windows/platform.h
Normal file
103
CASA-auth-token/client/core/windows/platform.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <aclapi.h>
|
||||
#include <winerror.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <winhttp.h>
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#ifndef CONTAINING_RECORD
|
||||
#define CONTAINING_RECORD(address, type, field) ((type *)( \
|
||||
(char*)(address) - \
|
||||
(char*)(&((type *)0)->field)))
|
||||
#endif
|
||||
|
||||
//
|
||||
// DbgTrace macro define
|
||||
//
|
||||
//#define DbgTrace(LEVEL, X, Y) { \
|
||||
//char printBuff[256]; \
|
||||
// if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
// { \
|
||||
// _snprintf(printBuff, sizeof(printBuff), X, Y); \
|
||||
// printf("CASA_AuthToken %s", printBuff); \
|
||||
// } \
|
||||
//}
|
||||
#define DbgTrace(LEVEL, X, Y) { \
|
||||
char formatBuff[128]; \
|
||||
char printBuff[256]; \
|
||||
if (LEVEL == 0 || DebugLevel >= LEVEL) \
|
||||
{ \
|
||||
strcpy(formatBuff, "CASA_AuthToken "); \
|
||||
strncat(formatBuff, X, sizeof(formatBuff) - 10); \
|
||||
_snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \
|
||||
OutputDebugString(printBuff); \
|
||||
} \
|
||||
}
|
||||
|
||||
//
|
||||
// Rpc Session definition
|
||||
//
|
||||
typedef struct _RpcSession
|
||||
{
|
||||
HINTERNET hSession;
|
||||
HINTERNET hConnection;
|
||||
char *pHostName;
|
||||
|
||||
} RpcSession, *PRpcSession;
|
||||
|
||||
|
||||
//
|
||||
// Other definitions
|
||||
//
|
||||
#define LIB_HANDLE HMODULE
|
||||
#define bool BOOLEAN
|
||||
#define true TRUE
|
||||
#define false FALSE
|
||||
|
||||
#define AcquireModuleMutex WaitForSingleObjectEx(g_hModuleMutex, INFINITE, FALSE)
|
||||
#define ReleaseModuleMutex ReleaseMutex(g_hModuleMutex)
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global externals ]==================================================
|
||||
|
||||
//===[ External prototypes ]===============================================
|
||||
|
||||
//===[ External data ]=====================================================
|
||||
|
||||
extern HANDLE g_hModuleMutex;
|
||||
|
||||
//=========================================================================
|
||||
|
||||
799
CASA-auth-token/client/core/windows/rpc.c
Normal file
799
CASA-auth-token/client/core/windows/rpc.c
Normal file
@@ -0,0 +1,799 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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 files ]=====================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
#define INITIAL_RESPONSE_DATA_BUF_SIZE 1028
|
||||
#define INCREMENT_RESPONSE_DATA_BUF_SIZE 256
|
||||
|
||||
#define MAX_RPC_RETRIES 3
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
|
||||
//===[ Global variables ]==================================================
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
CopyMultiToWideAlloc(
|
||||
IN char *pMulti,
|
||||
IN int multiSize,
|
||||
INOUT LPWSTR *ppWide,
|
||||
INOUT int *pWideSize)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int retStatus;
|
||||
int size, i;
|
||||
|
||||
DbgTrace(2, "-CopyMultiToWideAlloc- Start\n", 0);
|
||||
|
||||
size = (multiSize + 1) * sizeof(WCHAR);
|
||||
|
||||
if ((*ppWide = (PWCHAR) malloc(size)) != NULL)
|
||||
{
|
||||
for (i = 0; i < multiSize; i++)
|
||||
{
|
||||
*(*ppWide + i) = (unsigned char) *(pMulti + i);
|
||||
}
|
||||
|
||||
*(*ppWide + i) = L'\0';
|
||||
|
||||
if (pWideSize)
|
||||
{
|
||||
*pWideSize = size - sizeof(WCHAR);
|
||||
}
|
||||
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-CopyMultiToWideAlloc- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
CopyWideToMultiAlloc(
|
||||
IN LPWSTR pWide,
|
||||
IN int wideSize,
|
||||
INOUT char **ppMulti,
|
||||
INOUT int *pMultiSize)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
int retStatus;
|
||||
int size, i;
|
||||
|
||||
DbgTrace(2, "-CopyWideToMultiAlloc- Start\n", 0);
|
||||
|
||||
size = wideSize + 1;
|
||||
|
||||
if ((*ppMulti = malloc(size)) != NULL)
|
||||
{
|
||||
for (i = 0; i < wideSize; i++)
|
||||
{
|
||||
*(*ppMulti + i) = (char) *(pWide + i);
|
||||
}
|
||||
|
||||
*(*ppMulti + i) = '\0';
|
||||
|
||||
if (pMultiSize)
|
||||
{
|
||||
*pMultiSize = size - 1;
|
||||
}
|
||||
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-CopyWideToMultiAlloc- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
RpcSession*
|
||||
OpenRpcSession(
|
||||
IN char *pHostName,
|
||||
IN uint16_t hostPort)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
RpcSession *pSession;
|
||||
bool success = false;
|
||||
|
||||
DbgTrace(1, "-OpenRpcSession- Start\n", 0);
|
||||
|
||||
// Allocate space for the session
|
||||
pSession = (RpcSession*) malloc(sizeof(*pSession));
|
||||
if (pSession)
|
||||
{
|
||||
// Zero the session structure
|
||||
memset(pSession, 0, sizeof(*pSession));
|
||||
|
||||
// Save copy of the hostname
|
||||
pSession->pHostName = malloc(strlen(pHostName) + 1);
|
||||
if (pSession->pHostName)
|
||||
{
|
||||
strcpy(pSession->pHostName, pHostName);
|
||||
|
||||
// Open a Winhttp session
|
||||
pSession->hSession = WinHttpOpen(L"CASA Client/1.0",
|
||||
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
|
||||
WINHTTP_NO_PROXY_NAME,
|
||||
WINHTTP_NO_PROXY_BYPASS,
|
||||
0);
|
||||
if (pSession->hSession)
|
||||
{
|
||||
LPWSTR pWideHostName;
|
||||
int wideHostLen;
|
||||
|
||||
// Session opened, now convert the host name to Unicode so that
|
||||
// we can open a connection.
|
||||
if (CopyMultiToWideAlloc(pHostName,
|
||||
(int) strlen(pHostName),
|
||||
&pWideHostName,
|
||||
&wideHostLen) == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
// Now open connection
|
||||
pSession->hConnection = WinHttpConnect(pSession->hSession,
|
||||
pWideHostName,
|
||||
hostPort,
|
||||
0);
|
||||
if (pSession->hConnection == NULL)
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to open connection, error = %d\n", GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
||||
// Free the host name wide string buffer
|
||||
free(pWideHostName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Error converting host name to wide string\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to open session, error = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to allocate buffer for host name\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-OpenRpcSession- Failed to allocate buffer for rpc session\n", 0);
|
||||
}
|
||||
|
||||
// Clean up if we did not succeed
|
||||
if (!success)
|
||||
{
|
||||
if (pSession)
|
||||
{
|
||||
if (pSession->hConnection)
|
||||
WinHttpCloseHandle(pSession->hConnection);
|
||||
|
||||
if (pSession->hSession)
|
||||
WinHttpCloseHandle(pSession->hSession);
|
||||
|
||||
if (pSession->pHostName)
|
||||
free(pSession->pHostName);
|
||||
|
||||
free(pSession);
|
||||
pSession = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DbgTrace(2, "-OpenRpcSession- End, pSession = %08X\n", pSession);
|
||||
|
||||
return pSession;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
CloseRpcSession(
|
||||
IN RpcSession *pSession)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-CloseRpcSession- Start\n", 0);
|
||||
|
||||
// Close the connection handle
|
||||
WinHttpCloseHandle(pSession->hConnection);
|
||||
|
||||
// Close the session handle
|
||||
WinHttpCloseHandle(pSession->hSession);
|
||||
|
||||
// Free hostname buffer if necessary
|
||||
if (pSession->pHostName)
|
||||
free(pSession->pHostName);
|
||||
|
||||
// Free the space allocated for the session
|
||||
free(pSession);
|
||||
|
||||
DbgTrace(1, "-CloseRpcSession- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
void CALLBACK
|
||||
SecureFailureStatusCallback(
|
||||
IN HINTERNET hRequest,
|
||||
IN DWORD *pContext,
|
||||
IN DWORD internetStatus,
|
||||
IN LPVOID pStatusInformation,
|
||||
IN DWORD statusInformationLength)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L0
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-SecureFailureStatusCallback- Start\n", 0);
|
||||
|
||||
// Only deal with failures related to certificates
|
||||
if (internetStatus == WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)
|
||||
{
|
||||
// Save the specific failure status
|
||||
*pContext = *(DWORD*) pStatusInformation;
|
||||
}
|
||||
|
||||
DbgTrace(1, "-SecureFailureStatusCallback- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static
|
||||
CasaStatus
|
||||
InternalRpc(
|
||||
IN RpcSession *pSession,
|
||||
IN char *pMethod,
|
||||
IN long flags,
|
||||
IN char *pRequestData,
|
||||
INOUT char **ppResponseData,
|
||||
INOUT int *pResponseDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
#define CASA_STATUS_INVALID_SERVER_CERTIFICATE CASA_STATUS_UNSUCCESSFUL // temporary until casa_status.h is updated
|
||||
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
char rpcTarget[256];
|
||||
LPWSTR pWideRpcTarget;
|
||||
int wideRpcTargetLen;
|
||||
WCHAR sendHeaders[] = L"Content-Type: text/html";
|
||||
DWORD securityFailureStatusFlags;
|
||||
int retriesAllowed = 1;
|
||||
bool attemptRetry;
|
||||
|
||||
DbgTrace(1, "-InternalRpc- Start\n", 0);
|
||||
|
||||
// Initialize output parameter
|
||||
*ppResponseData = NULL;
|
||||
|
||||
// Create rpc target string and convert it to a wide string
|
||||
sprintf(rpcTarget, "CasaAuthTokenSvc/Rpc?method=%s", pMethod);
|
||||
retStatus = CopyMultiToWideAlloc(rpcTarget,
|
||||
(int) strlen(rpcTarget),
|
||||
&pWideRpcTarget,
|
||||
&wideRpcTargetLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
HINTERNET hRequest;
|
||||
|
||||
do
|
||||
{
|
||||
// Forget about having been told to retry
|
||||
attemptRetry = false;
|
||||
|
||||
// Open a request handle
|
||||
hRequest = WinHttpOpenRequest(pSession->hConnection,
|
||||
L"POST",
|
||||
pWideRpcTarget,
|
||||
NULL,
|
||||
WINHTTP_NO_REFERER,
|
||||
WINHTTP_DEFAULT_ACCEPT_TYPES,
|
||||
flags & SECURE_RPC_FLAG? WINHTTP_FLAG_REFRESH | WINHTTP_FLAG_SECURE : WINHTTP_FLAG_REFRESH);
|
||||
if (hRequest)
|
||||
{
|
||||
int reqDataLen = (int) strlen(pRequestData);
|
||||
|
||||
// Check if we need to set options to deal with secure connections
|
||||
if (flags & SECURE_RPC_FLAG)
|
||||
{
|
||||
// We are using secure connections, now proceed based on whether or not
|
||||
// we are configured to allow invalid certificates.
|
||||
if (flags & ALLOW_INVALID_CERTS_RPC_FLAG
|
||||
|| (flags & ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG
|
||||
&& InvalidCertsFromHostAllowed(pSession->pHostName)))
|
||||
{
|
||||
DWORD secFlags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA;
|
||||
|
||||
// We are configured to allow invalid certificates, inform the HTTP stack.
|
||||
if (WinHttpSetOption(hRequest,
|
||||
WINHTTP_OPTION_SECURITY_FLAGS,
|
||||
&secFlags,
|
||||
sizeof(secFlags)) == FALSE)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Failed setting options to ignore invalid certs, error = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We are not configured to allow invalid certificates, set a callback handler
|
||||
// to detect invalid certificate conditions.
|
||||
if (WinHttpSetStatusCallback(hRequest,
|
||||
SecureFailureStatusCallback,
|
||||
WINHTTP_CALLBACK_FLAG_SECURE_FAILURE,
|
||||
(DWORD_PTR) NULL) == WINHTTP_INVALID_STATUS_CALLBACK)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Failed setting status callback, error = %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send the request
|
||||
securityFailureStatusFlags = 0;
|
||||
if (WinHttpSendRequest(hRequest,
|
||||
sendHeaders,
|
||||
-1,
|
||||
pRequestData,
|
||||
reqDataLen,
|
||||
reqDataLen,
|
||||
(DWORD_PTR) &securityFailureStatusFlags))
|
||||
{
|
||||
// Request sent, now await for the response.
|
||||
if (WinHttpReceiveResponse(hRequest, NULL))
|
||||
{
|
||||
WCHAR httpCompStatus[4] = {0};
|
||||
DWORD httpCompStatusLen = sizeof(httpCompStatus);
|
||||
|
||||
// Response received, make sure that it completed successfully.
|
||||
if (WinHttpQueryHeaders(hRequest,
|
||||
WINHTTP_QUERY_STATUS_CODE,
|
||||
NULL,
|
||||
&httpCompStatus,
|
||||
&httpCompStatusLen,
|
||||
WINHTTP_NO_HEADER_INDEX))
|
||||
{
|
||||
// Check that the request completed successfully
|
||||
if (memcmp(httpCompStatus, L"200", sizeof(httpCompStatus)) == 0)
|
||||
{
|
||||
char *pResponseData;
|
||||
int responseDataBufSize = INITIAL_RESPONSE_DATA_BUF_SIZE;
|
||||
int responseDataRead = 0;
|
||||
|
||||
// Now read the response data, to do so we need to allocate a buffer.
|
||||
pResponseData = (char*) malloc(INITIAL_RESPONSE_DATA_BUF_SIZE);
|
||||
if (pResponseData)
|
||||
{
|
||||
char *pCurrLocation = pResponseData;
|
||||
DWORD bytesRead;
|
||||
|
||||
do
|
||||
{
|
||||
bytesRead = 0;
|
||||
if (WinHttpReadData(hRequest,
|
||||
(LPVOID) pCurrLocation,
|
||||
responseDataBufSize - responseDataRead,
|
||||
&bytesRead))
|
||||
{
|
||||
pCurrLocation += bytesRead;
|
||||
responseDataRead += bytesRead;
|
||||
|
||||
// Check if we need to allocate a larger buffer
|
||||
if (responseDataRead == responseDataBufSize)
|
||||
{
|
||||
char *pTmpBuf;
|
||||
|
||||
// We need to upgrade the receive buffer
|
||||
pTmpBuf = (char*) malloc(responseDataBufSize + INCREMENT_RESPONSE_DATA_BUF_SIZE);
|
||||
if (pTmpBuf)
|
||||
{
|
||||
memcpy(pTmpBuf, pResponseData, responseDataBufSize);
|
||||
free(pResponseData);
|
||||
pResponseData = pTmpBuf;
|
||||
pCurrLocation = pResponseData + responseDataBufSize;
|
||||
responseDataBufSize += INCREMENT_RESPONSE_DATA_BUF_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Failed reading response data, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
} while (CASA_SUCCESS(retStatus)
|
||||
&& bytesRead != 0);
|
||||
|
||||
// Check if the response data was successfully received
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// The response data was received, return it to the caller.
|
||||
*ppResponseData = pResponseData;
|
||||
*pResponseDataLen = responseDataRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed to receive the response data, free the allocated buffer.
|
||||
free(pResponseData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- HTTP request did not complete successfully, status = %S\n", httpCompStatus);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unable to obtain http request completion status, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unable to receive response, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int error = GetLastError();
|
||||
|
||||
if (error == ERROR_WINHTTP_CANNOT_CONNECT)
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unable to connect to server\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_AUTH_SERVER_UNAVAILABLE);
|
||||
}
|
||||
else if (error == ERROR_WINHTTP_SECURE_FAILURE)
|
||||
{
|
||||
DbgTrace(1, "-InternalRpc- Secure connection failure, flags = %0x\n", securityFailureStatusFlags);
|
||||
|
||||
// Try to deal with the issue
|
||||
if ((securityFailureStatusFlags & ~(WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA
|
||||
| WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID
|
||||
| WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID)) == 0
|
||||
&& flags & ALLOW_INVALID_CERTS_USER_APPROVAL_RPC_FLAG)
|
||||
{
|
||||
WINHTTP_CERTIFICATE_INFO certInfo;
|
||||
DWORD certInfoLen = sizeof(certInfo);
|
||||
|
||||
// The failure was due to an invalid CN, CA, or both.
|
||||
//
|
||||
// Obtain information about the server certificate to give user
|
||||
// the choice of accepting it.
|
||||
if (WinHttpQueryOption(hRequest,
|
||||
WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT,
|
||||
&certInfo,
|
||||
&certInfoLen)
|
||||
&& certInfo.lpszSubjectInfo != NULL
|
||||
&& certInfo.lpszIssuerInfo != NULL)
|
||||
{
|
||||
char *pSubjectInfo;
|
||||
int subjectInfoLen;
|
||||
|
||||
// Convert the subjectInfo to multi-byte
|
||||
retStatus = CopyWideToMultiAlloc(certInfo.lpszSubjectInfo,
|
||||
(int) wcslen(certInfo.lpszSubjectInfo),
|
||||
&pSubjectInfo,
|
||||
&subjectInfoLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
char *pIssuerInfo;
|
||||
int issuerInfoLen;
|
||||
|
||||
// Convert the issuerInfo to multi-byte
|
||||
retStatus = CopyWideToMultiAlloc(certInfo.lpszIssuerInfo,
|
||||
(int) wcslen(certInfo.lpszIssuerInfo),
|
||||
&pIssuerInfo,
|
||||
&issuerInfoLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
long invalidCertFlags = 0;
|
||||
|
||||
// Setup the invalid cert flags
|
||||
if (securityFailureStatusFlags & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA)
|
||||
invalidCertFlags |= INVALID_CERT_CA_FLAG;
|
||||
|
||||
if (securityFailureStatusFlags & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID)
|
||||
invalidCertFlags |= INVALID_CERT_CN_FLAG;
|
||||
|
||||
if (securityFailureStatusFlags & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID)
|
||||
invalidCertFlags |= INVALID_CERT_DATE_FLAG;
|
||||
|
||||
// Give user the choice to accept the certificate
|
||||
if (UserApprovedCert(pSession->pHostName,
|
||||
pSubjectInfo,
|
||||
pIssuerInfo,
|
||||
invalidCertFlags))
|
||||
{
|
||||
DbgTrace(1, "-InternalRpc- User approved invalid certificate from %s\n", pSession->pHostName);
|
||||
|
||||
// tbd - Investigate if there is a way to set the accepted certificate in a store so that
|
||||
// it can be utilized by the SSL stack directly. This would be a better method for dealing with
|
||||
// this issue.
|
||||
|
||||
AllowInvalidCertsFromHost(pSession->pHostName);
|
||||
|
||||
// Try to retry the request
|
||||
attemptRetry = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(1, "-InternalRpc- User did not approve invalid certificate from %s\n", pSession->pHostName);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INVALID_SERVER_CERTIFICATE);
|
||||
}
|
||||
|
||||
// Free the buffer containing the issuerInfo
|
||||
free(pIssuerInfo);
|
||||
}
|
||||
|
||||
// Free the buffer containing the subjectInfo
|
||||
free(pSubjectInfo);
|
||||
}
|
||||
|
||||
// Free necessary certificate information
|
||||
if (certInfo.lpszSubjectInfo) LocalFree(certInfo.lpszSubjectInfo);
|
||||
if (certInfo.lpszIssuerInfo) LocalFree(certInfo.lpszIssuerInfo);
|
||||
if (certInfo.lpszProtocolName) LocalFree(certInfo.lpszProtocolName);
|
||||
if (certInfo.lpszSignatureAlgName) LocalFree(certInfo.lpszSignatureAlgName);
|
||||
if (certInfo.lpszEncryptionAlgName) LocalFree(certInfo.lpszEncryptionAlgName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unable to obtain server certificate struct, error = %0x\n", GetLastError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decided to no give the user a choice to accept invalid server certificate
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INVALID_SERVER_CERTIFICATE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unsuccessful send http request, error = %d\n", error);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the request handle
|
||||
WinHttpCloseHandle(hRequest);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Unable to open http request, error = %d\n", GetLastError());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
} while (attemptRetry && retriesAllowed--);
|
||||
|
||||
// Free the rpc target wide string buffer
|
||||
free(pWideRpcTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-InternalRpc- Error converting method name to wide string\n", 0);
|
||||
}
|
||||
|
||||
DbgTrace(1, "-InternalRpc- End, retStatus = %d\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
Rpc(
|
||||
IN RpcSession *pSession,
|
||||
IN char *pMethod,
|
||||
IN long flags,
|
||||
IN char *pRequestData,
|
||||
INOUT char **ppResponseData,
|
||||
INOUT int *pResponseDataLen)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
int retries = 0;
|
||||
|
||||
DbgTrace(1, "-Rpc- Start\n", 0);
|
||||
|
||||
// Retry the RPC as needed
|
||||
do
|
||||
{
|
||||
// Issue the RPC
|
||||
retStatus = InternalRpc(pSession,
|
||||
pMethod,
|
||||
flags,
|
||||
pRequestData,
|
||||
ppResponseData,
|
||||
pResponseDataLen);
|
||||
|
||||
// Account for this try
|
||||
retries ++;
|
||||
|
||||
} while (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE
|
||||
&& retries < MAX_RPC_RETRIES);
|
||||
|
||||
DbgTrace(1, "-Rpc- End, retStatus = %d\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
InitializeRpc(void)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus = CASA_STATUS_SUCCESS;
|
||||
|
||||
DbgTrace(1, "-InitializeRpc- Start\n", 0);
|
||||
|
||||
// Nothing to do for windows
|
||||
|
||||
DbgTrace(1, "-InitializeRpc- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
Reference in New Issue
Block a user