diff --git a/CASA/CASA.changes b/CASA/CASA.changes index c826604d..93cd8209 100644 --- a/CASA/CASA.changes +++ b/CASA/CASA.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Oct 15 14:51:32 MDT 2008 - jnorman@novell.com + +- Bug 407409. Account for a filehandles equal to 0. + ------------------------------------------------------------------- Tue Aug 26 14:32:58 MDT 2008 - cgardner@novell.com diff --git a/CASA/include/sscs_cache.h b/CASA/include/sscs_cache.h index a4abf941..60d6f7c1 100644 --- a/CASA/include/sscs_cache.h +++ b/CASA/include/sscs_cache.h @@ -65,9 +65,11 @@ static SS_UTF8_T SSCS_RESERVED2_KEY_CHAIN_ID[] = "SSCS_RESERVED2_KEYCHAIN2_ID"; #define NSSCS_MAX_ID_LEN 256 #define DebugLevel 0 +#ifdef DEBUG + +#ifdef SSCS_WIN32_PLAT_F static SS_UTF8_T g_pDebugLogFilePath[] = {"\\micasa_lib.log"}; -#ifdef DEBUG #define DbgTrace(LEVEL, X, Y) { \ char formatBuff[256]; \ char printBuff[384]; \ @@ -77,7 +79,7 @@ FILE *pDebugFile; \ SYSTEMTIME sysTime; \ GetLocalTime(&sysTime); \ _snprintf(formatBuff, sizeof(formatBuff), "[%X-%X] [%02d:%02d:%02d] CASA_library ", GetCurrentProcessId(), GetCurrentThreadId(), sysTime.wHour, sysTime.wMinute, sysTime.wSecond); \ - strncat(formatBuff, X, sizeof(formatBuff) - strlen(formatBuff) - 1); \ + strncat(formatBuff, X, sizeof(formatBuff) -:q: strlen(formatBuff) - 1); \ _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ if (g_pDebugLogFilePath) \ { \ @@ -93,15 +95,44 @@ FILE *pDebugFile; \ OutputDebugString(printBuff); \ } \ } +#else +//#ifdef SSCS_LINUX_PLAT_F +#include +#include +static SS_UTF8_T g_pDebugLogFilePath[] = {"/micasa_lib.log"}; + +#define DbgTrace(LEVEL, X, Y) { \ +char formatBuff[256]; \ +char printBuff[384]; \ +char timeBuff[64]; \ +time_t t; \ +struct tm *tmp; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || DebugLevel >= LEVEL) \ + { \ + time(&t); \ + tmp = localtime(&t); \ + strftime(timeBuff, sizeof(timeBuff), "%a %b %d %H:%M:%S", tmp); \ + snprintf(formatBuff, sizeof(formatBuff), "[%u] [%s]: ", getpid(), timeBuff); \ + strncat(formatBuff, X, sizeof(formatBuff) - strlen(formatBuff) - 1); \ + snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + pDebugFile = fopen(g_pDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fflush(pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ +} +#endif + #else #define DbgTrace(LEVEL, X, Y) {} #endif - - - typedef struct _sscs_linux_ss_handle { int32_t socketID; @@ -115,7 +146,11 @@ typedef struct _sscs_win32_ss_handle typedef struct _sscs_secretstore_handle { int32_t platformID; +#ifdef SSCS_WIN32_PLAT_F void *platHandle; +#else + int platHandle; +#endif } SSCS_SECRETSTORE_HANDLE_T; diff --git a/CASA/include/sscs_ipc.h b/CASA/include/sscs_ipc.h index 2d7a7463..9e1960c5 100644 --- a/CASA/include/sscs_ipc.h +++ b/CASA/include/sscs_ipc.h @@ -36,6 +36,7 @@ typedef uint8_t Byte; #define MIN_REPLY_BUF_LEN 32*1024 #define MAX_BINARY_KEY_LEN 256*1024 + #ifdef SSCS_LINUX_PLAT_F #include "sscs_unx_ipc_client.h" #include "sscs_unx_cache_defines.h" @@ -44,9 +45,9 @@ typedef uint8_t Byte; #include #include -void* ipc_unx_create(void); -int ipc_unx_write(int fd, Byte *pData, int bytes); -int ipc_unx_read(int fd, Byte *pData, int bytes); +int ipc_unx_create(void); +int ipc_unx_write(int fd, void *pData, int bytes); +int ipc_unx_read(int fd, void *pData, int bytes); int ipc_unx_close(int fd); #define IPC_CREATE(...) ipc_unx_create(__VA_ARGS__); @@ -54,6 +55,8 @@ int ipc_unx_close(int fd); #define IPC_WRITE(...) ipc_unx_write(__VA_ARGS__); #define IPC_CLOSE(...) ipc_unx_close(__VA_ARGS__); +#define IPC_INVALID_HANDLE (-1) + #else //#ifdef SSCS_WIN32_PLAT_F @@ -74,7 +77,9 @@ int ipc_win_close(HANDLE hPipe); #define IPC_WRITE(s1,s2,s3) ipc_win_write(s1,s2,s3); #define IPC_CLOSE(s1) ipc_win_close(s1); -//#endif +#define IPC_INVALID_HANDLE ((void *)-1) + +#endif // function prototypes int ipc_OpenSecretStore @@ -272,7 +277,5 @@ int ipc_MergeCache int32_t bDestorySrc ); - -#endif #endif diff --git a/CASA/micasacache/sscs_ipc.c b/CASA/micasacache/sscs_ipc.c index 4506ac8e..282c95e4 100644 --- a/CASA/micasacache/sscs_ipc.c +++ b/CASA/micasacache/sscs_ipc.c @@ -21,6 +21,8 @@ ***********************************************************************/ #include "sscs_ipc.h" +// DEBUG +#include "sscs_cache.h" #ifdef SSCS_WIN32_PLAT_F #include "windows.h" @@ -37,27 +39,30 @@ int firstReadAfterWrite = 0; */ #ifdef SSCS_LINUX_PLAT_F -void* ipc_unx_create() +int ipc_unx_create() { int retVal = 0; struct sockaddr_un servAddr; char path[MAX_SOCKET_PATH_LEN]; - int sockFd = 0; + int sockFd = 0; + do { sockFd = socket(AF_UNIX,SOCK_STREAM,0); if( sockFd < 0 ) { + DbgTrace(1, "Failed to open socket, sockFd = %x\n", sockFd); retVal = sockFd; break; } + DbgTrace(1, "-ipc_unx_create- sockFd = %x\n", sockFd); retVal = fcntl(sockFd, F_SETFL, O_NONBLOCK); if ( retVal < 0 ) { - DMSG(("Failed to make the socket non-blocking : %s\n",strerror(errno))); - DMSG(("Closing socket : %d\n",sockFd)); + DbgTrace(1, "Failed to make the socket non-blocking : %s\n",strerror(errno)); + DbgTrace(1, "Closing socket : %d\n",sockFd); close(sockFd); break; } @@ -69,15 +74,16 @@ void* ipc_unx_create() retVal = connect(sockFd,(struct sockaddr*)&servAddr, sizeof(servAddr)); if(retVal < 0 ) { - DMSG(("Connect fails : %s\n",strerror(errno))); - DMSG(("Closing socket : %d\n",sockFd)); + DbgTrace(1, "Connect fails : %s\n",strerror(errno)); + DbgTrace(1, "Closing socket : %d\n",sockFd); close(sockFd); break; } else retVal = sockFd; }while(0); - return (void*)retVal; + + return retVal; } #else @@ -117,7 +123,7 @@ void * ipc_win_create() #endif #ifdef SSCS_LINUX_PLAT_F -int ipc_unx_write(int fd, Byte *pData, int bytes) +int ipc_unx_write(int fd, void *pData, int bytes) { int retVal = 0; int retries = RETRIES; @@ -237,7 +243,7 @@ int ipc_win_write(HANDLE hPipe, LPCVOID lpBuffer, DWORD bytesToWrite) #ifdef SSCS_LINUX_PLAT_F -int ipc_unx_read(int fd, Byte *pData, int bytes) +int ipc_unx_read(int fd, void *pData, int bytes) { int retVal = 0; int retries = RETRIES; diff --git a/CASA/micasacache/sscs_unx_cache.c b/CASA/micasacache/sscs_unx_cache.c index 3fcb9444..564bd74c 100644 --- a/CASA/micasacache/sscs_unx_cache.c +++ b/CASA/micasacache/sscs_unx_cache.c @@ -29,8 +29,8 @@ extern "C" #ifdef SSCS_WIN32_PLAT_F #include -#include #endif +#include #include "sscs_cache.h" @@ -61,7 +61,6 @@ void* sscs_CacheOpenSecretStore } memset(ssHandle,0,sizeof(SSCS_SECRETSTORE_HANDLE_T)); - ssHandle->platHandle = ssHandle + sizeof(SSCS_SECRETSTORE_HANDLE_T); retVal = ipc_OpenSecretStore(secretStoreID,ssHandle); if(retVal) @@ -96,7 +95,7 @@ int32_t sscs_CacheCloseSecretStore int32_t retVal = 0; SSCS_SECRETSTORE_HANDLE_T *ssHandleCopy = (SSCS_SECRETSTORE_HANDLE_T *)ssHandle; - if(ssHandleCopy->platHandle) + if(ssHandleCopy->platHandle >= 0) { retVal = ipc_CloseSecretStore(ssHandleCopy, ssFlags); } @@ -438,8 +437,12 @@ int32_t sscs_CacheGetSecretStoreInfo int32_t retVal = 0; SSCS_SECRETSTORE_HANDLE_T *ssHandleCopy = (SSCS_SECRETSTORE_HANDLE_T *)ssHandle; + DbgTrace(1, "-sscs_CacheGetSecretStoreInfo- start:\n", 0); + retVal = ipc_GetSecretStoreInfo(ssHandleCopy,ssInfo); + DbgTrace(1, "-sscs_CacheGetSecretStoreInfo- end: %d \n", retVal); + return retVal; } diff --git a/CASA/micasacache/sscs_unx_ipc_client.c b/CASA/micasacache/sscs_unx_ipc_client.c index d7011ed2..afe208ae 100644 --- a/CASA/micasacache/sscs_unx_ipc_client.c +++ b/CASA/micasacache/sscs_unx_ipc_client.c @@ -249,7 +249,7 @@ int32_t ipc_OpenSecretStore do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (NULL == secretStoreID) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -257,7 +257,8 @@ int32_t ipc_OpenSecretStore } ssHandle->platHandle = IPC_CREATE(); - if(ssHandle->platHandle < 0) + DbgTrace(1, "-ipc_OpenSecretStore- ssHandle->platHandle = %x\n", ssHandle->platHandle); + if(ssHandle->platHandle == IPC_INVALID_HANDLE) { retCode = NSSCS_E_SYSTEM_FAILURE; break; @@ -404,7 +405,7 @@ DbgTrace(1, "-ipc_CloseSecretStore- start \n", 0); do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -519,7 +520,7 @@ int32_t ipc_RemoveSecretStore do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -604,7 +605,6 @@ int32_t ipc_EnumerateKeychainIDs SS_UTF8_T nulc = '\0'; SS_UTF8_T delimiter = '*'; - int i = 0,j = 0; uint16_t msgid = 0; uint32_t msgLen = 0; @@ -613,7 +613,6 @@ int32_t ipc_EnumerateKeychainIDs SS_UTF8_T *tmpBuf = NULL; SS_UTF8_T *tmpPtr = NULL; - SS_UTF8_T *tok = NULL; Byte *gpReqBuf = NULL; Byte *gpReplyBuf = NULL; @@ -635,7 +634,7 @@ int32_t ipc_EnumerateKeychainIDs do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == kcIDList) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -761,7 +760,7 @@ int32_t ipc_EnumerateKeychainIDs #endif // Count number of ids numIds = 1; // Atleast there is one !! - while( tmpPtr = sscs_Utf8Strchr(tmpPtr, delimiter) ) + while( (tmpPtr = sscs_Utf8Strchr(tmpPtr, delimiter)) != NULL ) { numIds++; tmpPtr++; @@ -872,8 +871,8 @@ int32_t ipc_AddKeychain do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || - (NULL == keychainID) ) + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || + (NULL == keychainID) ) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -998,7 +997,7 @@ int32_t ipc_RemoveKeychain do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -1105,11 +1104,9 @@ int32_t ipc_EnumerateSecretIDs uint32_t bufLen = 0; uint32_t numIds = 0; - int i = 0; SS_UTF8_T *tmpBuf = NULL; SS_UTF8_T *tmpPtr = NULL; - SS_UTF8_T *tok = NULL; Byte *gpReqBuf = NULL; Byte *gpReplyBuf = NULL; @@ -1131,7 +1128,7 @@ int32_t ipc_EnumerateSecretIDs do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretIDList) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -1272,7 +1269,7 @@ int32_t ipc_EnumerateSecretIDs // Count number of ids numIds = 1; // Atleast there is one !! - while(tmpPtr = sscs_Utf8Strchr(tmpPtr, delimiter)) + while((tmpPtr = sscs_Utf8Strchr(tmpPtr, delimiter)) != NULL) { numIds++; tmpPtr++; @@ -1398,7 +1395,7 @@ int32_t ipc_ReadSecret do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) || (NULL == secretData) || (NULL == bytesRequired)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) || (NULL == secretData) || (NULL == bytesRequired)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -1670,7 +1667,7 @@ int ipc_WriteSecret do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) ||(NULL == secretData)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) ||(NULL == secretData)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -1907,7 +1904,7 @@ int32_t ipc_RemoveSecret do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -2105,14 +2102,17 @@ int32_t ipc_GetSecretStoreInfo do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { + DbgTrace(1, "-ipc_GetSecretStoreInfo- ssHandle = %x\n", ssHandle); + DbgTrace(1, "-ipc_GetSecretStoreInfo- ssHandle->platHandle = %x\n", ssHandle->platHandle); retCode = NSSCS_E_INVALID_PARAM; break; } if( NULL == ssInfo ) { + DbgTrace(1, "-ipc_GetSecretStoreInfo- ssInfo = %x\n", ssInfo); retCode = NSSCS_E_INVALID_PARAM; break; } @@ -2232,7 +2232,7 @@ int32_t ipc_GetKeychainInfo do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -2362,7 +2362,7 @@ int32_t ipc_LockCache do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -2473,7 +2473,7 @@ int32_t ipc_UnlockCache do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -2589,7 +2589,7 @@ int32_t ipc_SetMasterPasscode do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == passcode) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -2694,7 +2694,6 @@ int32_t ipc_RemoveKey int32_t retCode = NSSCS_SUCCESS; //to be returned to caller int32_t sockReturn = 0; //obtained from the server - uint32_t dataLen = 0; uint16_t msgid = 0; uint32_t keychainIDLen = 0; uint32_t secretIDLen = 0; @@ -2728,7 +2727,7 @@ int32_t ipc_RemoveKey do { if((NULL == ssHandle) - || (NULL == ssHandle->platHandle) + || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) || (NULL == key) @@ -2952,7 +2951,7 @@ int32_t ipc_ReadKey do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) || (NULL == bytesRequired)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) || (NULL == bytesRequired)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -3233,7 +3232,7 @@ int32_t ipc_ReadBinaryKey do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) || (NULL == bytesRequired)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) || (NULL == bytesRequired)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -3510,7 +3509,7 @@ int ipc_WriteKey do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) ||(NULL == key)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) ||(NULL == key)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -3734,8 +3733,6 @@ int ipc_WriteBinaryKey int32_t retCode = NSSCS_SUCCESS; //to be returned to caller int32_t sockReturn = 0; //obtained from the server - Byte *tmpBuf = NULL; - uint16_t msgid = 0; uint32_t keychainIDLen = 0; uint32_t secretIDLen = 0; @@ -3766,7 +3763,7 @@ int ipc_WriteBinaryKey do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle) || (NULL == keychainID) || (NULL == secretID) ||(NULL == key)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == keychainID) || (NULL == secretID) ||(NULL == key)) { retCode = NSSCS_E_INVALID_PARAM; break; @@ -3987,7 +3984,7 @@ int32_t ipc_SetMasterPassword do { - if( (NULL == ssHandle) || (NULL == ssHandle->platHandle) || + if( (NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE) || (NULL == passwd) ) { retCode = NSSCS_E_INVALID_PARAM; @@ -4118,7 +4115,7 @@ int ipc_IsSecretPersistent do { - if((NULL == ssHandle) || (NULL == ssHandle->platHandle)) + if((NULL == ssHandle) || (ssHandle->platHandle == IPC_INVALID_HANDLE)) { retCode = NSSCS_E_INVALID_PARAM; break;