From 3a4a7fec0d2536b4a5c6f214104be7ee163c3e4b Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Mon, 5 Mar 2007 06:48:26 +0000 Subject: [PATCH] Made the following changes: - Use host name specified in ObtainAuthToken call instead of the normalized host name to connect to the ATS to avoid problems when the host name obtained through a reverse DNS lookup fails to resolve via a forward DNS lookup. - Added the capability log debug messages to a file. - Added method to the ConfigIf to free memory returned by calls to getEntryValue to avoid issues related to freeing memory allocated with a heap different than the one owned by the library freeing the memory. --- CASA-auth-token/client/library/authmech.c | 7 +- CASA-auth-token/client/library/authmsg.c | 2 +- CASA-auth-token/client/library/client.conf | 25 ++++-- CASA-auth-token/client/library/config.c | 37 ++++++++ CASA-auth-token/client/library/config_if.h | 39 +++++++-- CASA-auth-token/client/library/engine.c | 84 ++++++++++++++----- CASA-auth-token/client/library/internal.h | 7 +- CASA-auth-token/client/library/mech_if.h | 8 ++ .../library/mechanisms/krb5/interface.c | 32 ++++--- .../client/library/mechanisms/krb5/internal.h | 2 +- .../client/library/mechanisms/krb5/util.c | 6 +- .../krb5/windows/Krb5Authenticate.conf | 17 ---- .../mechanisms/krb5/windows/platform.h | 32 ++++--- .../client/library/mechanisms/pwd/interface.c | 32 ++++--- .../client/library/mechanisms/pwd/internal.h | 2 +- .../client/library/mechanisms/pwd/util.c | 6 +- .../pwd/windows/PwdAuthenticate.conf | 16 ---- .../library/mechanisms/pwd/windows/platform.h | 32 ++++--- CASA-auth-token/client/library/util.c | 1 - .../client/library/windows/platform.c | 2 +- .../client/library/windows/platform.h | 33 +++++--- CASA-auth-token/client/library/windows/rpc.c | 6 +- 22 files changed, 294 insertions(+), 134 deletions(-) diff --git a/CASA-auth-token/client/library/authmech.c b/CASA-auth-token/client/library/authmech.c index 65d08e02..0675ed12 100644 --- a/CASA-auth-token/client/library/authmech.c +++ b/CASA-auth-token/client/library/authmech.c @@ -159,7 +159,10 @@ GetAuthTokenIf( if (pGetAuthTokenIfRtn) { // Now, obtain the modules AuthTokenIf. - retStatus = (pGetAuthTokenIfRtn)(pModuleConfigIf, &pAuthMechMod->pAuthTokenIf); + retStatus = (pGetAuthTokenIfRtn)(pModuleConfigIf, + DebugLevel, + g_pDebugLogFilePath, + &pAuthMechMod->pAuthTokenIf); } else { @@ -178,7 +181,7 @@ GetAuthTokenIf( } // Free the buffer holding the library name - free(pLibraryName); + pModuleConfigIf->freeValueString(pModuleConfigIf, pLibraryName); } else { diff --git a/CASA-auth-token/client/library/authmsg.c b/CASA-auth-token/client/library/authmsg.c index f441679b..8fe42e9e 100644 --- a/CASA-auth-token/client/library/authmsg.c +++ b/CASA-auth-token/client/library/authmsg.c @@ -629,7 +629,7 @@ AuthRespEndElementHandler( { // Convert the lifetime string to a numeric value pAuthRespParse->pAuthenticateResp->tokenLifetime = dtoul(pAuthRespParse->pLifetimeData, - pAuthRespParse->lifetimeDataLen); + pAuthRespParse->lifetimeDataLen - 1); // Good, advance to the next state. pAuthRespParse->state = AWAITING_SESSION_TOKEN_DATA; diff --git a/CASA-auth-token/client/library/client.conf b/CASA-auth-token/client/library/client.conf index c58b329b..1b388d74 100644 --- a/CASA-auth-token/client/library/client.conf +++ b/CASA-auth-token/client/library/client.conf @@ -48,7 +48,7 @@ #DisableSecureConnections false # -# AllowInvalidCerts setting. +# AllowUntrustedCerts setting. # # Description: Used to specify that the client should ignore # invalid certificates presented by ATSs when @@ -63,7 +63,7 @@ # process to impersonate an ATS and obtain information that # is confidential such as username and passwords. # -AllowInvalidCerts true +AllowUntrustedCerts true # # UsersCannotAllowInvalidCerts setting. @@ -96,8 +96,23 @@ AllowInvalidCerts true # If this parameter is not set, the client defaults # to use a debug level of zero. # -# Note: Debug statements can be viewed under Windows by using -# tools such as DbgView. Under Linux, debug statements are logged -# to /var/log/messages. +# Note: Under Linux, debug output is placed in the /ver/log/messages +# file. Under Windoes, debug output is dumped to the debugger console +# unless a folder is specified using the DebugLogFolderPath setting. +# Output sent to the debug console under windows can be viewed by using +# tools such as DbgView. # #DebugLevel 0 + +# +# DebugLogFolderPath setting. +# +# Description: Used to specify a path to a folder to be used for placing debug +# log files under Windows. +# +# If this parameter is not set on windows, the client defaults +# to dumping debug output to the debug console. +# +# Note: The folder specified must exist. +# +#DebugLogFolderPath c:\logfolder diff --git a/CASA-auth-token/client/library/config.c b/CASA-auth-token/client/library/config.c index c1afbb5d..09d70fe9 100644 --- a/CASA-auth-token/client/library/config.c +++ b/CASA-auth-token/client/library/config.c @@ -353,6 +353,8 @@ ConfigIf_GetEntryValue( // // Returns: // Pointer to NULL terminated string with value being requested or NULL. +// This NULL terminated string must be free by executing the interface +// object freeValueString method. // // Description: // Gets value associated with a key for the configuration object. @@ -418,6 +420,40 @@ ConfigIf_GetEntryValue( } +//++======================================================================= +void SSCS_CALL +ConfigIf_FreeValueString( + IN const void *pIfInstance, + IN char *pValueString) +// +// Arguments: +// pIfInstance - +// Pointer to interface object. +// +// pValueString - +// Pointer to NULL terminated string that contains a value +// returned from a call to the interface getEntryValue method. +// +// Returns: +// Nothing. +// +// Description: +// Frees value string returned by calling interface's getEntryValue +// method. +// +// L2 +//=======================================================================-- +{ + ConfigIfInstance *pConfigIfInstance = CONTAINING_RECORD(pIfInstance, ConfigIfInstance, configIf); + + DbgTrace(2, "-ConfigIf_FreeValueString- Start\n", 0); + + // Free the buffer + free(pValueString); + + DbgTrace(2, "-ConfigIf_FreeValueString- End", 0); +} + //++======================================================================= CasaStatus @@ -516,6 +552,7 @@ GetConfigInterface( pConfigIfInstance->configIf.addReference = ConfigIf_AddReference; pConfigIfInstance->configIf.releaseReference = ConfigIf_ReleaseReference; pConfigIfInstance->configIf.getEntryValue = ConfigIf_GetEntryValue; + pConfigIfInstance->configIf.freeValueString = ConfigIf_FreeValueString; // Save the ConfigFolder and ConfigName information within the instance data pConfigIfInstance->pConfigFolder = (char*) malloc(configFolderLen + 1); diff --git a/CASA-auth-token/client/library/config_if.h b/CASA-auth-token/client/library/config_if.h index 0cdf31ce..4eb54c46 100644 --- a/CASA-auth-token/client/library/config_if.h +++ b/CASA-auth-token/client/library/config_if.h @@ -47,7 +47,7 @@ //++======================================================================= typedef int -(SSCS_CALL *PFNConfiglIf_AddReference)( +(SSCS_CALL *PFNConfigIf_AddReference)( IN const void *pIfInstance); // // Arguments: @@ -65,7 +65,7 @@ int //++======================================================================= typedef void -(SSCS_CALL *PFNConfiglIf_ReleaseReference)( +(SSCS_CALL *PFNConfigIf_ReleaseReference)( IN const void *pIfInstance); // // Arguments: @@ -84,7 +84,7 @@ void //++======================================================================= typedef char* -(SSCS_CALL *PFNConfiglIf_GetEntryValue)( +(SSCS_CALL *PFNConfigIf_GetEntryValue)( IN const void *pIfInstance, IN const char *pKeyName); // @@ -98,20 +98,47 @@ char* // // Returns: // Pointer to NULL terminated string with value being requested or NULL. +// This NULL terminated string must be free by executing the interface +// object freeValueString method. // // Description: // Gets value associated with a key for the configuration object. //=======================================================================-- +//++======================================================================= +typedef +void +(SSCS_CALL *PFNConfigIf_FreeValueString)( + IN const void *pIfInstance, + IN char *pValueString); +// +// Arguments: +// pIfInstance - +// Pointer to interface object. +// +// pValueString - +// Pointer to NULL terminated string that contains a value +// returned from a call to the interface getEntryValue method. +// +// Returns: +// Nothing. +// +// Description: +// Frees value string returned by calling interface's getEntryValue +// method. +//=======================================================================-- + + // // Config Interface Object // typedef struct _ConfigIf { - PFNConfiglIf_AddReference addReference; - PFNConfiglIf_ReleaseReference releaseReference; - PFNConfiglIf_GetEntryValue getEntryValue; + PFNConfigIf_AddReference addReference; + PFNConfigIf_ReleaseReference releaseReference; + PFNConfigIf_GetEntryValue getEntryValue; + PFNConfigIf_FreeValueString freeValueString; } ConfigIf, *PConfigIf; diff --git a/CASA-auth-token/client/library/engine.c b/CASA-auth-token/client/library/engine.c index a75dc73c..0c7f3cd4 100644 --- a/CASA-auth-token/client/library/engine.c +++ b/CASA-auth-token/client/library/engine.c @@ -31,9 +31,7 @@ #define DEFAULT_RETRY_LIFETIME 5 // seconds -#ifndef CASA_STATUS_NAME_RESOLVE_ERROR -#define CASA_STATUS_NAME_RESOLVE_ERROR ((CasaStatus)0x00000024) -#endif +#define LOG_FILE_NAME "\\casaauthtoken.log" //===[ Function prototypes ]=============================================== @@ -43,9 +41,10 @@ InitializeLibrary(void); //===[ Global variables ]================================================== // -// Debug tracing level -// +// Debug tracing level and debug log file path. +// int DebugLevel = 0; +char *g_pDebugLogFilePath = NULL; // // Operating parameter @@ -226,8 +225,8 @@ ObtainSessionToken( 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. + // Add the entry to the cache if the reason that we failed was because + // the server was unavailable. if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) { pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext, @@ -298,6 +297,7 @@ CasaStatus ObtainAuthTokenFromServer( IN const char *pServiceName, IN const char *pHostName, + IN const char *pNormalizedHostName, INOUT char **ppAuthToken, INOUT int *pTokenLifetime, IN void *pCredStoreScope) @@ -649,6 +649,7 @@ ObtainAuthTokenInt( // Cache entry created, now try to obtain auth token from the CASA Server pToken = NULL; retStatus = ObtainAuthTokenFromServer(pServiceName, + pHostName, pNormalizedHostName, &pToken, &cacheEntryLifetime, @@ -831,7 +832,9 @@ InitializeLibrary(void) int getConfigStatus = -1; ConfigIf *pClientConfigIf; char *pDebugLevelSetting; + char *pDebugLogFolderPathSetting; char *pATSPortSetting; + char *pATSHostNameSetting; char *pDisableSecureConnections; char *pAllowInvalidCerts; char *pUsersCannotAllowInvalidCerts; @@ -855,14 +858,50 @@ InitializeLibrary(void) DebugLevel = (int) dtoul(pDebugLevelSetting, strlen(pDebugLevelSetting)); // Free the buffer holding the debug level - free(pDebugLevelSetting); + pClientConfigIf->freeValueString(pClientConfigIf, pDebugLevelSetting); + } + + // Check if a DebugLogFolderPath has been configured + pDebugLogFolderPathSetting = pClientConfigIf->getEntryValue(pClientConfigIf, "DebugLogFolderPath"); + if (pDebugLogFolderPathSetting != NULL) + { + DbgTrace(0, "-InitializeLibrary- DebugLogFolderPath configured = %s\n", pDebugLogFolderPathSetting); + + // Use the setting to come up with the path to the debug log file + g_pDebugLogFilePath = malloc(strlen(LOG_FILE_NAME) + strlen(pDebugLogFolderPathSetting) + 1); + if (g_pDebugLogFilePath) + { + strcpy(g_pDebugLogFilePath, pDebugLogFolderPathSetting); + strcat(g_pDebugLogFilePath, LOG_FILE_NAME); + } + else + { + DbgTrace(0, "-InitializeLibrary- Failed to allocate buffer for debug file path\n", 0); + } + + // Free the buffer holding the debug folder path + pClientConfigIf->freeValueString(pClientConfigIf, pDebugLogFolderPathSetting); } // Check if an ATS hostname has been configured - g_pATSHostName = pClientConfigIf->getEntryValue(pClientConfigIf, "ATS-hostname"); - if (g_pATSHostName != NULL) + pATSHostNameSetting = pClientConfigIf->getEntryValue(pClientConfigIf, "ATS-hostname"); + if (pATSHostNameSetting != NULL) { - DbgTrace(0, "-InitializeLibrary- ATS hostname configured = %s\n", g_pATSHostName); + DbgTrace(0, "-InitializeLibrary- ATS hostname configured = %s\n", pATSHostNameSetting); + + // Remember the ATS host name + g_pATSHostName = malloc(strlen(pATSHostNameSetting) + 1); + if (g_pATSHostName) + { + strcpy(g_pATSHostName, pATSHostNameSetting); + } + else + { + DbgTrace(0, "-InitializeLibrary- Failed to allocate buffer for ATS host name\n", 0); + } + + // Free the buffer holding the ats host name setting + pClientConfigIf->freeValueString(pClientConfigIf, pATSHostNameSetting); } // Check if the DisableSecureConnections setting has been configured @@ -882,17 +921,17 @@ InitializeLibrary(void) } // Free the buffer holding the DisableSecureConnections setting - free(pDisableSecureConnections); + pClientConfigIf->freeValueString(pClientConfigIf, pDisableSecureConnections); } - // Check the AllowInvalidCerts setting if using secure connections + // Check the AllowUntrustedCerts setting if using secure connections if (g_rpcFlags & SECURE_RPC_FLAG) { - // Check if the AllowInvalidCerts setting has been configured - pAllowInvalidCerts = pClientConfigIf->getEntryValue(pClientConfigIf, "AllowInvalidCerts"); + // Check if the AllowUntrustedCerts setting has been configured + pAllowInvalidCerts = pClientConfigIf->getEntryValue(pClientConfigIf, "AllowUntrustedCerts"); if (pAllowInvalidCerts != NULL) { - DbgTrace(0, "-InitializeLibrary- AllowInvalidCerts setting configured = %s\n", pAllowInvalidCerts); + DbgTrace(0, "-InitializeLibrary- AllowUntrustedCerts setting configured = %s\n", pAllowInvalidCerts); // Adjust the g_rpcFlags variable based on the setting if (stricmp(pAllowInvalidCerts, "false") == 0) @@ -905,7 +944,7 @@ InitializeLibrary(void) } // Free the buffer holding the AllowInvalidCerts setting - free(pAllowInvalidCerts); + pClientConfigIf->freeValueString(pClientConfigIf, pAllowInvalidCerts); } // Check the UsersCannotAllowInvalidCerts setting if not allowing invalid certs. @@ -928,7 +967,7 @@ InitializeLibrary(void) } // Free the buffer holding the UsersCannotAllowInvalidCerts setting - free(pUsersCannotAllowInvalidCerts); + pClientConfigIf->freeValueString(pClientConfigIf, pUsersCannotAllowInvalidCerts); } } } @@ -943,7 +982,7 @@ InitializeLibrary(void) g_ATSPort = (int) dtoul(pATSPortSetting, strlen(pATSPortSetting)); // Free the buffer holding the port number - free(pATSPortSetting); + pClientConfigIf->freeValueString(pClientConfigIf, pATSPortSetting); } // Release config interface instance @@ -1018,6 +1057,13 @@ UnInitializeLibrary(void) // Un-initialize the Rpc engine UnInitializeRpc(); + // Free necessary buffers + if (g_pDebugLogFilePath) + free(g_pDebugLogFilePath); + + if (g_pATSHostName) + free(g_pATSHostName); + DbgTrace(1, "-UnInitializeLibrary- End\n", 0); } diff --git a/CASA-auth-token/client/library/internal.h b/CASA-auth-token/client/library/internal.h index 79353323..6a43a0f5 100644 --- a/CASA-auth-token/client/library/internal.h +++ b/CASA-auth-token/client/library/internal.h @@ -124,12 +124,13 @@ typedef struct _AuthCacheEntry //===[ Global externals ]================================================== extern int DebugLevel; +extern char *g_pDebugLogFilePath; -extern char clientConfigFolder[]; +extern char clientConfigFolder[]; -extern char mechConfigFolder[]; +extern char mechConfigFolder[]; -extern char pathCharString[]; +extern char pathCharString[]; //===[ External prototypes ]=============================================== diff --git a/CASA-auth-token/client/library/mech_if.h b/CASA-auth-token/client/library/mech_if.h index 31d5469d..3f183548 100644 --- a/CASA-auth-token/client/library/mech_if.h +++ b/CASA-auth-token/client/library/mech_if.h @@ -159,12 +159,20 @@ typedef CasaStatus (SSCS_CALL *PFN_GetAuthTokenIfRtn)( IN const ConfigIf *pModuleConfigIf, + IN const int debugLevel, + IN const char *pDebugFilePath, INOUT AuthTokenIf **ppAuthTokenIf); // // Arguments: // pModuleConfigIf - // Pointer to configuration interface instance for the module. // +// debugLevel - +// Level to utilize for debugging, 0 being lowest. +// +// pDebugFilePath - +// Path to debug log file. Can be NULL. +// // ppAuthTokenIf - // Pointer to variable that will receive pointer to AuthTokenIf // instance. diff --git a/CASA-auth-token/client/library/mechanisms/krb5/interface.c b/CASA-auth-token/client/library/mechanisms/krb5/interface.c index f2f5ab79..9cc075df 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/interface.c +++ b/CASA-auth-token/client/library/mechanisms/krb5/interface.c @@ -128,12 +128,20 @@ AuthTokenIf_ReleaseReference( CasaStatus SSCS_CALL GET_AUTH_TOKEN_INTERFACE_RTN( IN const ConfigIf *pModuleConfigIf, + IN const int debugLevel, + IN const char *pDebugFilePath, INOUT AuthTokenIf **ppAuthTokenIf) // // Arguments: // pModuleConfigIf - // Pointer to configuration interface instance for the module. // +// debugLevel - +// Level to utilize for debugging, 0 being lowest. +// +// pDebugFilePath - +// Path to debug log file. Can be NULL. +// // ppAuthTokenIf - // Pointer to variable that will receive pointer to AuthTokenIf // instance. @@ -150,6 +158,7 @@ GET_AUTH_TOKEN_INTERFACE_RTN( CasaStatus retStatus; AuthTokenIfInstance *pAuthTokenIfInstance; char *pDebugLevelSetting; + char *pDebugLogFolderPathSetting; DbgTrace(1, "-GetAuthTokenInterface- Start\n", 0); @@ -165,17 +174,20 @@ GET_AUTH_TOKEN_INTERFACE_RTN( goto exit; } - // Check if a DebugLevel has been configured - pDebugLevelSetting = pModuleConfigIf->getEntryValue(pModuleConfigIf, "DebugLevel"); - if (pDebugLevelSetting != NULL) + // Save debug parameters + KrbMechDebugLevel = debugLevel; + if (pDebugFilePath) { - DbgTrace(0, "-GetAuthTokenInterface- DebugLevel configured = %s\n", pDebugLevelSetting); - - // Convert the number to hex - DebugLevel = (int) dtoul(pDebugLevelSetting, strlen(pDebugLevelSetting)); - - // Free the buffer holding the debug level - free(pDebugLevelSetting); + // Use the setting to come up with the path to the debug log file + pKrbMechDebugLogFilePath = malloc(strlen(pDebugFilePath) + 1); + if (pKrbMechDebugLogFilePath) + { + strcpy(pKrbMechDebugLogFilePath, pDebugFilePath); + } + else + { + DbgTrace(0, "-GetAuthTokenInterface- Failed to allocate buffer for debug file path\n", 0); + } } // Allocate space for the interface instance diff --git a/CASA-auth-token/client/library/mechanisms/krb5/internal.h b/CASA-auth-token/client/library/mechanisms/krb5/internal.h index c627dbb0..7646275b 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/internal.h +++ b/CASA-auth-token/client/library/mechanisms/krb5/internal.h @@ -43,7 +43,7 @@ //===[ Global externals ]================================================== -extern int DebugLevel; +extern int KrbMechDebugLevel; //===[ External prototypes ]=============================================== diff --git a/CASA-auth-token/client/library/mechanisms/krb5/util.c b/CASA-auth-token/client/library/mechanisms/krb5/util.c index 946e4e25..a6512faa 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/util.c +++ b/CASA-auth-token/client/library/mechanisms/krb5/util.c @@ -32,8 +32,9 @@ //===[ Global variables ]================================================== -// Debug Level -int DebugLevel = 0; +// Debug Level and debug log file path. +int KrbMechDebugLevel = 0; +char *pKrbMechDebugLogFilePath = NULL; // Tables for Base64 encoding and decoding static const int8_t g_Base64[] = @@ -318,7 +319,6 @@ dtoul( } else { - DbgTrace(0, "-dtoul- Found invalid digit\n", 0); break; } } diff --git a/CASA-auth-token/client/library/mechanisms/krb5/windows/Krb5Authenticate.conf b/CASA-auth-token/client/library/mechanisms/krb5/windows/Krb5Authenticate.conf index 7a785ba8..5fcbf17d 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/windows/Krb5Authenticate.conf +++ b/CASA-auth-token/client/library/mechanisms/krb5/windows/Krb5Authenticate.conf @@ -14,20 +14,3 @@ # implementing the authentication mechanism. # LibraryName \Program Files\novell\casa\lib\krb5mech.dll - -# -# DebugLevel setting. -# -# Description: Used to specify the level of logging utilized for debugging -# purposes. A level of zero being the lowest debugging level. -# -# If this parameter is not set, the client defaults -# to use a debug level of zero. -# -# Note: Debug statements can be viewed under Windows by using -# tools such as DbgView. Under Linux, debug statements are logged -# to /var/log/messages. -# -#DebugLevel 0 - - diff --git a/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h b/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h index bef55eec..1395068a 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h +++ b/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h @@ -52,16 +52,28 @@ // 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); \ - } \ +extern char *pKrbMechDebugLogFilePath; +#define DbgTrace(LEVEL, X, Y) { \ +char formatBuff[128]; \ +char printBuff[256]; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || KrbMechDebugLevel >= LEVEL) \ + { \ + strcpy(formatBuff, "Krb5Mech "); \ + strncat(formatBuff, X, sizeof(formatBuff) - 9); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + if (pKrbMechDebugLogFilePath) \ + { \ + pDebugFile = fopen(pKrbMechDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ + else \ + OutputDebugString(printBuff); \ + } \ } #define INT32_MAX (2147483647) diff --git a/CASA-auth-token/client/library/mechanisms/pwd/interface.c b/CASA-auth-token/client/library/mechanisms/pwd/interface.c index f2f5ab79..524186c4 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/interface.c +++ b/CASA-auth-token/client/library/mechanisms/pwd/interface.c @@ -128,11 +128,19 @@ AuthTokenIf_ReleaseReference( CasaStatus SSCS_CALL GET_AUTH_TOKEN_INTERFACE_RTN( IN const ConfigIf *pModuleConfigIf, + IN const int debugLevel, + IN const char *pDebugFilePath, INOUT AuthTokenIf **ppAuthTokenIf) // // Arguments: // pModuleConfigIf - // Pointer to configuration interface instance for the module. +// +// debugLevel - +// Level to utilize for debugging, 0 being lowest. +// +// pDebugFilePath - +// Path to debug log file. Can be NULL. // // ppAuthTokenIf - // Pointer to variable that will receive pointer to AuthTokenIf @@ -150,6 +158,7 @@ GET_AUTH_TOKEN_INTERFACE_RTN( CasaStatus retStatus; AuthTokenIfInstance *pAuthTokenIfInstance; char *pDebugLevelSetting; + char *pDebugLogFolderPathSetting; DbgTrace(1, "-GetAuthTokenInterface- Start\n", 0); @@ -165,17 +174,20 @@ GET_AUTH_TOKEN_INTERFACE_RTN( goto exit; } - // Check if a DebugLevel has been configured - pDebugLevelSetting = pModuleConfigIf->getEntryValue(pModuleConfigIf, "DebugLevel"); - if (pDebugLevelSetting != NULL) + // Save debug parameters + PwdMechDebugLevel = debugLevel; + if (pDebugFilePath) { - DbgTrace(0, "-GetAuthTokenInterface- DebugLevel configured = %s\n", pDebugLevelSetting); - - // Convert the number to hex - DebugLevel = (int) dtoul(pDebugLevelSetting, strlen(pDebugLevelSetting)); - - // Free the buffer holding the debug level - free(pDebugLevelSetting); + // Use the setting to come up with the path to the debug log file + pPwdMechDebugLogFilePath = malloc(strlen(pDebugFilePath) + 1); + if (pPwdMechDebugLogFilePath) + { + strcpy(pPwdMechDebugLogFilePath, pDebugFilePath); + } + else + { + DbgTrace(0, "-GetAuthTokenInterface- Failed to allocate buffer for debug file path\n", 0); + } } // Allocate space for the interface instance diff --git a/CASA-auth-token/client/library/mechanisms/pwd/internal.h b/CASA-auth-token/client/library/mechanisms/pwd/internal.h index 5c71de1b..f38973b7 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/internal.h +++ b/CASA-auth-token/client/library/mechanisms/pwd/internal.h @@ -45,7 +45,7 @@ //===[ Global externals ]================================================== -extern int DebugLevel; +extern int PwdMechDebugLevel; //===[ External prototypes ]=============================================== diff --git a/CASA-auth-token/client/library/mechanisms/pwd/util.c b/CASA-auth-token/client/library/mechanisms/pwd/util.c index 946e4e25..dae1bd11 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/util.c +++ b/CASA-auth-token/client/library/mechanisms/pwd/util.c @@ -32,8 +32,9 @@ //===[ Global variables ]================================================== -// Debug Level -int DebugLevel = 0; +// Debug Level and debug log file path. +int PwdMechDebugLevel = 0; +char *pPwdMechDebugLogFilePath = NULL; // Tables for Base64 encoding and decoding static const int8_t g_Base64[] = @@ -318,7 +319,6 @@ dtoul( } else { - DbgTrace(0, "-dtoul- Found invalid digit\n", 0); break; } } diff --git a/CASA-auth-token/client/library/mechanisms/pwd/windows/PwdAuthenticate.conf b/CASA-auth-token/client/library/mechanisms/pwd/windows/PwdAuthenticate.conf index 948d43e6..ced947c5 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/windows/PwdAuthenticate.conf +++ b/CASA-auth-token/client/library/mechanisms/pwd/windows/PwdAuthenticate.conf @@ -14,19 +14,3 @@ # implementing the authentication mechanism. # LibraryName \Program Files\novell\casa\lib\pwmech.dll - -# -# DebugLevel setting. -# -# Description: Used to specify the level of logging utilized for debugging -# purposes. A level of zero being the lowest debugging level. -# -# If this parameter is not set, the client defaults -# to use a debug level of zero. -# -# Note: Debug statements can be viewed under Windows by using -# tools such as DbgView. Under Linux, debug statements are logged -# to /var/log/messages. -# -#DebugLevel 0 - diff --git a/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h b/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h index 04877eb8..107c2012 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h +++ b/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h @@ -50,16 +50,28 @@ // 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); \ - } \ +extern char *pPwdMechDebugLogFilePath; +#define DbgTrace(LEVEL, X, Y) { \ +char formatBuff[128]; \ +char printBuff[256]; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || PwdMechDebugLevel >= LEVEL) \ + { \ + strcpy(formatBuff, "CASA_PwdMech "); \ + strncat(formatBuff, X, sizeof(formatBuff) - 8); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + if (pPwdMechDebugLogFilePath) \ + { \ + pDebugFile = fopen(pPwdMechDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ + else \ + OutputDebugString(printBuff); \ + } \ } #define INT32_MAX (2147483647) diff --git a/CASA-auth-token/client/library/util.c b/CASA-auth-token/client/library/util.c index 0cb03fcb..f338cc01 100644 --- a/CASA-auth-token/client/library/util.c +++ b/CASA-auth-token/client/library/util.c @@ -315,7 +315,6 @@ dtoul( } else { - DbgTrace(0, "-dtoul- Found invalid digit\n", 0); break; } } diff --git a/CASA-auth-token/client/library/windows/platform.c b/CASA-auth-token/client/library/windows/platform.c index ac7cfd6f..7510c17e 100644 --- a/CASA-auth-token/client/library/windows/platform.c +++ b/CASA-auth-token/client/library/windows/platform.c @@ -705,7 +705,7 @@ UnInitializeHostNameNormalization(void) hostNameNormalizationInitialized = FALSE; } - DbgTrace(1, "-UnInitializeHostNameNormalization- End", 0); + DbgTrace(1, "-UnInitializeHostNameNormalization- End\n", 0); } diff --git a/CASA-auth-token/client/library/windows/platform.h b/CASA-auth-token/client/library/windows/platform.h index 480b7b7e..c2349c86 100644 --- a/CASA-auth-token/client/library/windows/platform.h +++ b/CASA-auth-token/client/library/windows/platform.h @@ -49,19 +49,30 @@ // if (LEVEL == 0 || DebugLevel >= LEVEL) \ // { \ // _snprintf(printBuff, sizeof(printBuff), X, Y); \ -// printf("CASA_AuthToken %s", printBuff); \ +// 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); \ - } \ +#define DbgTrace(LEVEL, X, Y) { \ +char formatBuff[128]; \ +char printBuff[256]; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || DebugLevel >= LEVEL) \ + { \ + strcpy(formatBuff, "CASA_AuthToken "); \ + strncat(formatBuff, X, sizeof(formatBuff) - 10); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + if (g_pDebugLogFilePath) \ + { \ + pDebugFile = fopen(g_pDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ + else \ + OutputDebugString(printBuff); \ + } \ } // diff --git a/CASA-auth-token/client/library/windows/rpc.c b/CASA-auth-token/client/library/windows/rpc.c index da69c555..6ad448eb 100644 --- a/CASA-auth-token/client/library/windows/rpc.c +++ b/CASA-auth-token/client/library/windows/rpc.c @@ -171,6 +171,8 @@ OpenRpcSession( bool success = false; DbgTrace(1, "-OpenRpcSession- Start\n", 0); + DbgTrace(2, "-OpenRpcSession- Host = %s\n", pHostName); + DbgTrace(2, "-OpenRpcSession- HostPort = %d\n", hostPort); // Allocate space for the session pSession = (RpcSession*) malloc(sizeof(*pSession)); @@ -358,10 +360,6 @@ InternalRpc( { #define RPC_TARGET_FMT_STRING "CasaAuthTokenSvc/Rpc?method=%s" -#ifndef CASA_STATUS_INVALID_SERVER_CERTIFICATE -#define CASA_STATUS_INVALID_SERVER_CERTIFICATE ((CasaStatus)0x00000023) -#endif - CasaStatus retStatus = CASA_STATUS_SUCCESS; char *pRpcTarget; LPWSTR pWideRpcTarget;