/*********************************************************************** * * Copyright (C) 2005-2006 Novell, Inc. * * 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 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, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * To contact Novell about this file by physical or electronic mail, * you may find current contact information at www.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 synchronization mutex and variables static pthread_mutex_t g_authTokenIfMutex = PTHREAD_MUTEX_INITIALIZER; static int g_numAuthTokenIfObjs = 0; //++======================================================================= int SSCS_CALL Krb5AuthTokenIf_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, "krb5_token -Krb5AuthTokenIf_AddReference- Start\n", 0); // Increment the reference count on the object pthread_mutex_lock(&g_authTokenIfMutex); pAuthTokenIfInstance->refCount ++; refCount = pAuthTokenIfInstance->refCount; pthread_mutex_unlock(&g_authTokenIfMutex); DbgTrace(2, "krb5_token -Krb5AuthTokenIf_AddReference- End, refCount = %08X\n", refCount); return refCount; } //++======================================================================= void SSCS_CALL Krb5AuthTokenIf_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, "krb5_token -Krb5AuthTokenIf_ReleaseReference- Start\n", 0); // Decrement the reference count on the object and determine if it needs to // be released. pthread_mutex_lock(&g_authTokenIfMutex); pAuthTokenIfInstance->refCount --; if (pAuthTokenIfInstance->refCount == 0) { // The object needs to be released, forget about it. freeObj = true; g_numAuthTokenIfObjs --; } pthread_mutex_unlock(&g_authTokenIfMutex); // Free object if necessary if (freeObj) free(pAuthTokenIfInstance); DbgTrace(2, "krb5_token -Krb5AuthTokenIf_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, "krb5_token -GetAuthTokenInterface- Start\n", 0); // Validate input parameters if (pModuleConfigIf == NULL || ppAuthTokenIf == NULL) { DbgTrace(0, "krb5_token -GetAuthTokenInterface- Invalid input parameter\n", 0); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_KRB5TOKEN, 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 = Krb5AuthTokenIf_AddReference; pAuthTokenIfInstance->authTokenIf.releaseReference = Krb5AuthTokenIf_ReleaseReference; pAuthTokenIfInstance->authTokenIf.getAuthTokenCredentials = Krb5AuthTokenIf_GetAuthTokenCredentials; pAuthTokenIfInstance->authTokenIf.validateAuthTokenCredentials = Krb5AuthTokenIf_ValidateAuthTokenCredentials; // Keep track of this object pthread_mutex_lock(&g_authTokenIfMutex); g_numAuthTokenIfObjs ++; pthread_mutex_unlock(&g_authTokenIfMutex); // Return the interface to the caller *ppAuthTokenIf = &pAuthTokenIfInstance->authTokenIf; // Success retStatus = CASA_STATUS_SUCCESS; } else { DbgTrace(0, "krb5_token -GetAuthTokenInterface- Buffer allocation failure\n", 0); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_KRB5TOKEN, CASA_STATUS_INSUFFICIENT_RESOURCES); } exit: DbgTrace(1, "krb5_token -GetAuthTokenInterface- End, retStatus = %08X\n", retStatus); return retStatus; } //++======================================================================= //++======================================================================= //++=======================================================================