Adding new components to the server side of auth_token.
This commit is contained in:
		| @@ -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 | ||||
|  | ||||
| CFILES = | ||||
|  | ||||
| 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 | ||||
|  | ||||
| @@ -0,0 +1,39 @@ | ||||
| /*********************************************************************** | ||||
|  * | ||||
|  *  README for casa_identoken | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
| INTRODUCTION | ||||
|  | ||||
| casa_identoken is the Identity Token Provider plug-in for tokens of type | ||||
| CasaIdentityToken. This are the default identity tokens utilized by CASA | ||||
| Authentication. | ||||
|  | ||||
| CONFIGURATION | ||||
|  | ||||
| The path to the casa_identoken plug-in is configured by placing the file | ||||
| CasaIdentityToken.conf in the /etc/opt/CASA/authtoken.d/modules.d folder. | ||||
|  | ||||
| PROGRAMMING NOTES | ||||
|  | ||||
| This module does not provide APIs to components outside of the CASA | ||||
| Authentication framework. | ||||
|  | ||||
| SECURITY CONSIDERATIONS | ||||
|  | ||||
| CasaIdentityTokens are embedded inside CASA Authentication Tokens. CasaIdentityTokens | ||||
| contain identity information which may be confidential and no attempts are made to | ||||
| ensure the confidentiality of the data. Because of this it is important that CASA | ||||
| Authentication Tokens be secured by applications making use of them. It is recommended | ||||
| that CASA authentication tokens be transmitted using SSL. | ||||
|   | ||||
|  | ||||
|  | ||||
|  | ||||
|                  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| @@ -0,0 +1,13 @@ | ||||
| /*********************************************************************** | ||||
|  * | ||||
|  *  TODO for casa_identoken | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
| INTRODUCTION | ||||
|  | ||||
| This file contains a list of the items still outstanding for casa_identoken. | ||||
|  | ||||
| OUTSTANDING ITEMS | ||||
|  | ||||
| None. | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -0,0 +1,346 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  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 ]================================================== | ||||
|  | ||||
| // | ||||
| // Identity Token Provider Interface instance data | ||||
| //  | ||||
| typedef struct _IdenTokenProviderIfInstance | ||||
| { | ||||
|    int                  refCount; | ||||
|    IdenTokenProviderIf  idenTokenProviderIf; | ||||
|  | ||||
| } IdenTokenProviderIfInstance, *PIdenTokenProviderIfInstance; | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| // IdenTokenProviderIf variables | ||||
| static | ||||
| int   g_numIdenTokenProviderIfObjs = 0; | ||||
|  | ||||
| // Debug Level | ||||
| int   DebugLevel = 0; | ||||
|  | ||||
| // | ||||
| // Initialization variables | ||||
| // | ||||
| static | ||||
| bool  g_moduleInitialized = false; | ||||
|  | ||||
| // Synchronization mutex | ||||
| static | ||||
| HANDLE   g_idenTokenProviderIfMutex = NULL; | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| int SSCS_CALL | ||||
| AddReference( | ||||
|    IN       const void  *pIfInstance) | ||||
| // | ||||
| // Arguments:   | ||||
| //    pIfInstance - | ||||
| //       Pointer to interface object. | ||||
| //    | ||||
| // Returns: | ||||
| //    Interface reference count. | ||||
| //                            | ||||
| // Description: | ||||
| //    Increases interface reference count. | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    int                           refCount; | ||||
|    IdenTokenProviderIfInstance   *pIdenTokenProviderIfInstance = CONTAINING_RECORD(pIfInstance, IdenTokenProviderIfInstance, idenTokenProviderIf); | ||||
|  | ||||
|    DbgTrace(2, "-AddReference- Start\n", 0); | ||||
|  | ||||
|    // Increment the reference count on the object | ||||
|    PlatAcquireMutex(g_idenTokenProviderIfMutex); | ||||
|    pIdenTokenProviderIfInstance->refCount ++; | ||||
|    refCount = pIdenTokenProviderIfInstance->refCount; | ||||
|    PlatReleaseMutex(g_idenTokenProviderIfMutex); | ||||
|  | ||||
|    DbgTrace(2, "-AddReference- End, refCount = %08X\n", refCount); | ||||
|  | ||||
|    return refCount; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| void SSCS_CALL | ||||
| 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; | ||||
|    IdenTokenProviderIfInstance   *pIdenTokenProviderIfInstance = CONTAINING_RECORD(pIfInstance, IdenTokenProviderIfInstance, idenTokenProviderIf); | ||||
|  | ||||
|    DbgTrace(2, "-ReleaseReference- Start\n", 0); | ||||
|  | ||||
|    // Decrement the reference count on the object and determine if it needs to | ||||
|    // be released. | ||||
|    PlatAcquireMutex(g_idenTokenProviderIfMutex); | ||||
|    pIdenTokenProviderIfInstance->refCount --; | ||||
|    if (pIdenTokenProviderIfInstance->refCount == 0) | ||||
|    { | ||||
|       // The object needs to be released, forget about it. | ||||
|       freeObj = true; | ||||
|       g_numIdenTokenProviderIfObjs --; | ||||
|    } | ||||
|    PlatReleaseMutex(g_idenTokenProviderIfMutex); | ||||
|  | ||||
|    // Free object if necessary | ||||
|    if (freeObj) | ||||
|       free(pIdenTokenProviderIfInstance); | ||||
|  | ||||
|    DbgTrace(2, "-ReleaseReference- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| CasaStatus  | ||||
| GetIdentityTokenIf( | ||||
|    IN       const void        *pIfInstance, | ||||
|    IN       const char        *pTokenBuf, | ||||
|    IN       const int         tokenLen, | ||||
|    INOUT    IdenTokenIf       **ppIdenTokenIf) | ||||
| // | ||||
| // Arguments:   | ||||
| //    pIfInstance - | ||||
| //       Pointer to interface object. | ||||
| //    | ||||
| //    pTokenBuf - | ||||
| //       Pointer to null terminated string containing an identity token. | ||||
| // | ||||
| //    tokenLen - | ||||
| //       Length of the token contained in the token buffer. | ||||
| // | ||||
| //    ppIdenTokenIf - | ||||
| //       Pointer to variable that will receive pointer to identity | ||||
| //       token interface. | ||||
| //    | ||||
| // Returns: | ||||
| //    Casa Status | ||||
| //                            | ||||
| // Description: | ||||
| //    Get identity token interface instance for the specified token. | ||||
| //  | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus  retStatus; | ||||
|    char        *pDecodedTokenBuf; | ||||
|    int         decodedTokenBufLen; | ||||
|  | ||||
|    DbgTrace(2, "-GetIdentityTokenIf- Start\n", 0); | ||||
|  | ||||
|    // Validate input parameters | ||||
|    if (pIfInstance == NULL | ||||
|        || pTokenBuf == NULL | ||||
|        || tokenLen == 0 | ||||
|        || ppIdenTokenIf == NULL) | ||||
|    { | ||||
|       DbgTrace(0, "-GetIdentityTokenIf- Invalid input parameter\n", 0); | ||||
|  | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_INVALID_PARAMETER); | ||||
|       goto exit; | ||||
|    } | ||||
|  | ||||
|    // First decode the token string | ||||
|    retStatus = DecodeData(pTokenBuf, | ||||
|                           tokenLen, | ||||
|                           (void**) &pDecodedTokenBuf, | ||||
|                           &decodedTokenBufLen); | ||||
|    if (CASA_SUCCESS(retStatus)) | ||||
|    { | ||||
|       // Get the identity token interface | ||||
|       retStatus = GetIdenTokenInterface(pDecodedTokenBuf, | ||||
|                                         decodedTokenBufLen, | ||||
|                                         ppIdenTokenIf); | ||||
|  | ||||
|       // Free the decoded token buffer | ||||
|       free(pDecodedTokenBuf); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-GetIdentityTokenIf- Token decode failure\n", 0); | ||||
|    } | ||||
|  | ||||
| exit: | ||||
|  | ||||
|    DbgTrace(2, "-GetIdentityTokenIf- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus SSCS_CALL | ||||
| GET_IDEN_TOKEN_PROVIDER_INTERFACE_RTN( | ||||
|    IN       const ConfigIf    *pModuleConfigIf, | ||||
|    INOUT    IdenTokenProviderIf  **ppIdenTokenProviderIf) | ||||
| // | ||||
| // Arguments:   | ||||
| //    pModuleConfigIf - | ||||
| //       Pointer to configuration interface instance for the module. | ||||
| //                | ||||
| //    ppIdenTokenProviderIf - | ||||
| //       Pointer to variable that will receive pointer to | ||||
| //       IdentityTokenProviderIf instance. | ||||
| // | ||||
| // Returns: | ||||
| //    Casa Status | ||||
| //                            | ||||
| // Description: | ||||
| //    Gets identity token provider interface instance. | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus                    retStatus; | ||||
|    IdenTokenProviderIfInstance   *pIdenTokenProviderIfInstance; | ||||
|  | ||||
|    DbgTrace(1, "-GetIdenTokenProviderInterface- Start\n", 0); | ||||
|  | ||||
|    // Validate input parameters | ||||
|    if (pModuleConfigIf == NULL | ||||
|        || ppIdenTokenProviderIf == NULL) | ||||
|    { | ||||
|       DbgTrace(0, "-GetIdenTokenProviderInterface- Invalid input parameter\n", 0); | ||||
|  | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_KRB5TOKEN, | ||||
|                                   CASA_STATUS_INVALID_PARAMETER); | ||||
|       goto exit; | ||||
|    } | ||||
|  | ||||
|     // Make sure that the module has been initialized | ||||
|    if (g_moduleInitialized == false) | ||||
|    { | ||||
|       // The module has not been initialized, synchronize access thought this section | ||||
|       // to avoid having two threads performing initialization. | ||||
|       AcquireModuleMutex; | ||||
|  | ||||
|       // Assume success | ||||
|       retStatus = CASA_STATUS_SUCCESS; | ||||
|  | ||||
|       // Check again in case another thread pre-empted us. | ||||
|       if (g_moduleInitialized == false) | ||||
|       { | ||||
|          // Initialize the IdenTokenIf complex | ||||
|          retStatus = IdenTokenIfInit(); | ||||
|          if (CASA_SUCCESS(retStatus)) | ||||
|          { | ||||
|             // Allocate mutex | ||||
|             if ((g_idenTokenProviderIfMutex = PlatAllocMutex()) != NULL) | ||||
|             { | ||||
|                // Success | ||||
|                g_moduleInitialized = true; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                IdenTokenIfUninit(); | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_INFORMATIONAL, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|  | ||||
|       // Stop synchronization | ||||
|       ReleaseModuleMutex; | ||||
|  | ||||
|       // Exit if we failed | ||||
|       if (g_moduleInitialized == false) | ||||
|          goto exit; | ||||
|    } | ||||
|  | ||||
|    // Allocate space for the interface instance | ||||
|    pIdenTokenProviderIfInstance = malloc(sizeof(*pIdenTokenProviderIfInstance)); | ||||
|    if (pIdenTokenProviderIfInstance) | ||||
|    { | ||||
|       // Initialize the interface instance data | ||||
|       pIdenTokenProviderIfInstance->refCount = 1; | ||||
|       pIdenTokenProviderIfInstance->idenTokenProviderIf.addReference = AddReference; | ||||
|       pIdenTokenProviderIfInstance->idenTokenProviderIf.releaseReference = ReleaseReference; | ||||
|       pIdenTokenProviderIfInstance->idenTokenProviderIf.getIdentityTokenIf = GetIdentityTokenIf; | ||||
|  | ||||
|       // Keep track of this object | ||||
|       PlatAcquireMutex(g_idenTokenProviderIfMutex); | ||||
|       g_numIdenTokenProviderIfObjs ++; | ||||
|       PlatReleaseMutex(g_idenTokenProviderIfMutex); | ||||
|  | ||||
|       // Return the interface to the caller | ||||
|       *ppIdenTokenProviderIf = &pIdenTokenProviderIfInstance->idenTokenProviderIf; | ||||
|  | ||||
|       // Success | ||||
|       retStatus = CASA_STATUS_SUCCESS; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-GetIdenTokenProviderInterface- Buffer allocation failure\n", 0); | ||||
|  | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_KRB5TOKEN, | ||||
|                                   CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|    } | ||||
|  | ||||
| exit: | ||||
|  | ||||
|    DbgTrace(1, "-GetIdenTokenProviderInterface- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|  | ||||
| @@ -0,0 +1,122 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  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_s_authtoken.h> | ||||
| #include "config_if.h" | ||||
| #include "iden_token_provider_if.h" | ||||
| #include "list_entry.h" | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| //===[ Inlines functions   ]=============================================== | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| //===[ Global externals ]================================================== | ||||
|  | ||||
| extern int  DebugLevel; | ||||
|  | ||||
| //===[ External prototypes ]=============================================== | ||||
|  | ||||
| // | ||||
| // Defined in identoken.c | ||||
| // | ||||
|  | ||||
| extern | ||||
| CasaStatus | ||||
| GetIdenTokenInterface( | ||||
|    IN       const char   *pTokenBuf, | ||||
|    IN       const int    tokenLen, | ||||
|    INOUT    IdenTokenIf  **ppIdenTokenIf); | ||||
|  | ||||
| extern | ||||
| CasaStatus | ||||
| IdenTokenIfInit(void); | ||||
|  | ||||
| extern | ||||
| void | ||||
| IdenTokenIfUninit(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); | ||||
|  | ||||
| extern | ||||
| int | ||||
| dtoul( | ||||
|    IN    char *cp, | ||||
|    IN    int len); | ||||
|  | ||||
| // | ||||
| // Functions exported by platform.c | ||||
| //  | ||||
|  | ||||
| extern | ||||
| HANDLE | ||||
| PlatAllocMutex(void); | ||||
|  | ||||
| extern | ||||
| void | ||||
| PlatDestroyMutex(HANDLE hMutex); | ||||
|  | ||||
| extern | ||||
| void | ||||
| PlatAcquireMutex(HANDLE hMutex); | ||||
|  | ||||
| extern | ||||
| void | ||||
| PlatReleaseMutex(HANDLE hMutex); | ||||
|  | ||||
|  | ||||
| //========================================================================= | ||||
|  | ||||
| #endif // _INTERNAL_H_ | ||||
|  | ||||
| @@ -0,0 +1,15 @@ | ||||
| ####################################################### | ||||
| #                                                     # | ||||
| # CASA Authentication Token System configuration file # | ||||
| # for module:                                         # | ||||
| #                                                     # | ||||
| #     CasaIdentityToken                               # | ||||
| #                                                     #  | ||||
| # Note: This module is the provider of Casa Identity  # | ||||
| #       tokens.                                       # | ||||
| #                                                     # | ||||
| ####################################################### | ||||
|  | ||||
| LibraryName		/opt/novell/CASA/lib/casa_iden_token.so | ||||
|  | ||||
|  | ||||
| @@ -0,0 +1,112 @@ | ||||
| ####################################################################### | ||||
| # | ||||
| #  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 | ||||
| else | ||||
| TARGET_CFG = Release | ||||
| endif | ||||
|  | ||||
| SUBDIRS = | ||||
|  | ||||
| DIST_SUBDIRS = | ||||
|  | ||||
| CASAROOT = ../../../../../.. | ||||
|  | ||||
| CASALIBDIR = $(CASAROOT)/$(LIB) | ||||
|  | ||||
| # handle Mono secondary dependencies | ||||
| export MONO_PATH := $(MONO_PATH) | ||||
|  | ||||
| PLATFORMINDEPENDENTSOURCEDIR = .. | ||||
| PLATFORMDEPENDENTSOURCEDIR = . | ||||
|  | ||||
| MODULE_NAME = casa_iden_token | ||||
| MODULE_EXT = so | ||||
|  | ||||
| CFILES = $(srcdir)/identokenprovider.c \ | ||||
| 	 $(srcdir)/identoken.c \ | ||||
| 	 $(srcdir)/util.c \ | ||||
| 	 $(srcdir)/platform.c | ||||
|  | ||||
| CSFILES_CSC := | ||||
| INCLUDES = -I. -I.. -I../../.. -I$(CASAROOT)/include -I../../../../../include | ||||
| RESOURCES = | ||||
| DEFINES = -Wno-format-extra-args -fno-strict-aliasing  | ||||
| CFLAGS += $(INCLUDES) $(DEFINES) | ||||
| LIBS = -lpthread -ldl -lexpat | ||||
| LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT) | ||||
|  | ||||
| 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) $(CASALIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT) | ||||
|  | ||||
| $(OBJDIR): | ||||
| 	[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR) | ||||
| 	[ -d $(CASALIBDIR) ] || mkdir -p $(CASALIBDIR) | ||||
| 	[ -d $(CASALIBDIR)/$(TARGET_CFG) ] || mkdir -p $(CASALIBDIR)/$(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,178 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  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 ]================================================== | ||||
|  | ||||
| // | ||||
| // Platform Mutex structure | ||||
| // | ||||
| typedef struct _PlatformMutex | ||||
| { | ||||
|    pthread_mutex_t   mutex; | ||||
|  | ||||
| } PlatformMutex, *PPlatformMutex; | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| // | ||||
| // Module synchronization mutex | ||||
| //  | ||||
| pthread_mutex_t   g_hModuleMutex = PTHREAD_MUTEX_INITIALIZER; | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| HANDLE | ||||
| PlatAllocMutex(void) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| //  Environment: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    PlatformMutex        *pPlatMutex; | ||||
|    pthread_mutexattr_t  mutexAttr = {PTHREAD_MUTEX_RECURSIVE}; | ||||
|  | ||||
|    DbgTrace(2, "-PlatAllocMutex- Start\n", 0); | ||||
|  | ||||
|    // Allocate space for our mutex structure | ||||
|    pPlatMutex = malloc(sizeof(*pPlatMutex)); | ||||
|    if (pPlatMutex) | ||||
|    { | ||||
|       // Finish initializing the mutex | ||||
|       pthread_mutex_init(&pPlatMutex->mutex, &mutexAttr); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-PlatAllocMutex- Memory allocation failure\n", 0); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-PlatAllocMutex- End, retHandle = %08X\n", (unsigned int) pPlatMutex); | ||||
|  | ||||
|    return (HANDLE) pPlatMutex; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| PlatDestroyMutex(HANDLE hMutex) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| //  Environment: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    PlatformMutex  *pPlatMutex = (PlatformMutex*) hMutex; | ||||
|  | ||||
|    DbgTrace(2, "-PlatDestroyMutex- Start\n", 0); | ||||
|  | ||||
|    // Free the resources associated with the mutex | ||||
|    pthread_mutex_destroy(&pPlatMutex->mutex); | ||||
|    free(pPlatMutex); | ||||
|  | ||||
|    DbgTrace(2, "-PlatDestroyMutex- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| PlatAcquireMutex(HANDLE hMutex) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| //  Environment: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    PlatformMutex  *pPlatMutex = (PlatformMutex*) hMutex; | ||||
|  | ||||
|    DbgTrace(2, "-PlatAcquireMutex- Start\n", 0); | ||||
|  | ||||
|    // Acquire the mutex | ||||
|    pthread_mutex_lock(&pPlatMutex->mutex); | ||||
|  | ||||
|    DbgTrace(2, "-PlatAcquireMutex- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| PlatReleaseMutex(HANDLE hMutex) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| //  Environment: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    PlatformMutex  *pPlatMutex = (PlatformMutex*) hMutex; | ||||
|  | ||||
|    DbgTrace(2, "-PlatReleaseMutex- Start\n", 0); | ||||
|  | ||||
|    // Release the mutex | ||||
|    pthread_mutex_unlock(&pPlatMutex->mutex); | ||||
|  | ||||
|    DbgTrace(2, "-PlatRelease- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|  | ||||
| @@ -0,0 +1,93 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  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> | ||||
|  | ||||
| //===[ 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_IdenToken %s", printBuff);    \ | ||||
|    }                                                     \ | ||||
| } | ||||
| /*#define DbgTrace(LEVEL, X, Y) {                                                  \ | ||||
|    if (LEVEL == 0 || DebugLevel >= LEVEL)                                        \ | ||||
|    {                                                                             \ | ||||
|       openlog("CASA_IdenToken", 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 | ||||
|  | ||||
|  | ||||
| // | ||||
| // Module synchronization | ||||
| //  | ||||
| extern pthread_mutex_t  g_hModuleMutex; | ||||
|  | ||||
| #define AcquireModuleMutex    pthread_mutex_lock(&g_hModuleMutex) | ||||
| #define ReleaseModuleMutex    pthread_mutex_unlock(&g_hModuleMutex) | ||||
|  | ||||
|  | ||||
| //===[ Inlines functions   ]=============================================== | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global externals ]================================================== | ||||
|  | ||||
| //===[ External prototypes ]=============================================== | ||||
|  | ||||
| //========================================================================= | ||||
|  | ||||
| @@ -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    char *cp, | ||||
|    IN    int len) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L0 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    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; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|  | ||||
		Reference in New Issue
	
	Block a user