Fix for bug 209858. This fix changes the micasa socket from blocking to

non-blocking and implements the logic for timeout.
This commit is contained in:
Rajasekaran Nagarajan 2007-07-19 06:34:32 +00:00
parent 4379981b78
commit b5e3515487
4 changed files with 453 additions and 187 deletions

View File

@ -42,6 +42,7 @@ typedef uint8_t Byte;
#include <sscs_lldefs.h> #include <sscs_lldefs.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
void* ipc_unx_create(void); void* ipc_unx_create(void);
int ipc_unx_write(int fd, Byte *pData, int bytes); int ipc_unx_write(int fd, Byte *pData, int bytes);

View File

@ -30,6 +30,9 @@
int firstReadAfterWrite = 0; int firstReadAfterWrite = 0;
#endif #endif
#ifdef SSCS_LINUX_PLAT_F
#define RETRIES 1000
#endif
/* /*
*/ */
@ -49,6 +52,16 @@ void* ipc_unx_create()
retVal = sockFd; retVal = sockFd;
break; break;
} }
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));
close(sockFd);
break;
}
memset(&servAddr,0,sizeof(servAddr)); memset(&servAddr,0,sizeof(servAddr));
servAddr.sun_family = AF_UNIX; servAddr.sun_family = AF_UNIX;
@ -101,7 +114,62 @@ void * ipc_win_create()
#ifdef SSCS_LINUX_PLAT_F #ifdef SSCS_LINUX_PLAT_F
int ipc_unx_write(int fd, Byte *pData, int bytes) int ipc_unx_write(int fd, Byte *pData, int bytes)
{ {
int retVal = write(fd,pData,bytes); int retVal = 0;
int retries = RETRIES;
ssize_t bytesWriten = 0;
ssize_t bytesToWrite = 0;
bytesToWrite = bytes;
while (1)
{
bytesWriten = write(fd, pData, bytesToWrite);
if (bytesWriten == 0)
{
break;
}
else
{
if (bytesWriten > 0)
{
// We wrote some data, account for it.
bytesToWrite -= bytesWriten;
pData += bytesWriten;
// Done if all of the data has been writen
if (bytesToWrite == 0)
{
break;
}
}
else
{
// The write failed, proceed based on the reason.
if (errno == EINTR || errno == EAGAIN)
{
// Check if we have exhausted the retry count
if (retries)
{
// Sleep and then retry
retries --;
usleep(1000);
}
else
{
// The retry count has been exceeded
retVal = -1;
break;
}
}
else
{
// Do not retry under this type of error
retVal = -1;
break;
}
}
}
}
if( retVal < 0 ) if( retVal < 0 )
{ {
DMSG(("Write returns error : %d - %s\n",retVal, strerror(errno))); DMSG(("Write returns error : %d - %s\n",retVal, strerror(errno)));
@ -175,30 +243,68 @@ int ipc_win_write(HANDLE hPipe, LPCVOID lpBuffer, DWORD bytesToWrite)
int ipc_unx_read(int fd, Byte *pData, int bytes) int ipc_unx_read(int fd, Byte *pData, int bytes)
{ {
int retVal = 0;
int retries = RETRIES;
ssize_t bytesRead = 0;
ssize_t bytesToRead = 0;
int bytesToRead = 0; // Keep track of number of bytes to read bytesToRead = bytes;
int bytesRead = 0; // Number of bytes read while (1)
int totalBytesRead = 0;
int retVal = 0;
for(bytesToRead = bytes; bytesToRead;)
{ {
if ((bytesRead = read(fd, pData, bytesToRead)) == 0) bytesRead = read(fd, pData, bytesToRead);
if (bytesRead == 0)
{
break;
}
else
{
if (bytesRead > 0)
{
// We read some data, account for it.
bytesToRead -= bytesRead;
pData += bytesRead;
// Done if all of the data has been read
if (bytesToRead == 0)
{ {
break; break;
}
else
{
if(bytesRead < 0)
{
return -1;
}
bytesToRead -= bytesRead;
pData += bytesRead;
totalBytesRead += bytesRead;
} }
}
else
{
// The read failed, proceed based on the reason.
if (errno == EINTR || errno == EAGAIN)
{
// Check if we have exhausted the retry count
if (retries)
{
// Sleep and then retry
retries --;
usleep(1000);
}
else
{
// The retry count has been exceeded
retVal = -1;
break;
}
}
else
{
// Do not retry under this type of error
retVal = -1;
break;
}
}
}
} }
return totalBytesRead;
if( retVal < 0 )
{
DMSG(("Read returns error : %d - %s\n",retVal, strerror(errno)));
}
return retVal;
} }
//#endif //#endif

View File

@ -230,7 +230,6 @@ int32_t ipc_OpenSecretStore
Byte *gpReqBuf = NULL; Byte *gpReqBuf = NULL;
Byte *gpReplyBuf = NULL; Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL; Byte *pReq = NULL, *pReply = NULL;
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL) if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{ {
return(NSSCS_E_SYSTEM_FAILURE); return(NSSCS_E_SYSTEM_FAILURE);
@ -427,7 +426,8 @@ int32_t ipc_CloseSecretStore
retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen);
if(retVal < 0) if(retVal < 0)
{ {
retVal = NSSCS_E_SYSTEM_FAILURE; IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -437,6 +437,7 @@ int32_t ipc_CloseSecretStore
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -535,6 +536,7 @@ int32_t ipc_RemoveSecretStore
retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -544,6 +546,7 @@ int32_t ipc_RemoveSecretStore
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -650,6 +653,7 @@ int32_t ipc_EnumerateKeychainIDs
retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -660,6 +664,7 @@ int32_t ipc_EnumerateKeychainIDs
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -673,14 +678,17 @@ int32_t ipc_EnumerateKeychainIDs
memcpy(&bufLen, pReply, MSG_DWORD_LEN); memcpy(&bufLen, pReply, MSG_DWORD_LEN);
if( 0 == bufLen ) if( 0 == bufLen )
{ {
kcIDList->returnedIDs = 0;
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal)); DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
} }
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
kcIDList->returnedIDs = 0;
break; break;
} }
// Let me check if the global buffer is sufficient // Let me check if the global buffer is sufficient
@ -688,33 +696,40 @@ int32_t ipc_EnumerateKeychainIDs
pReply = gpReplyBuf; pReply = gpReplyBuf;
else else
{ {
if((bufLen + 1) >= MIN_REQUEST_BUF_LEN)
if((bufLen + 1) >= MIN_REQUEST_BUF_LEN) {
{ retCode = NSSCS_E_SYSTEM_FAILURE;
retCode = NSSCS_E_SYSTEM_FAILURE; break;
break; }
}
pReply = (Byte *)malloc( (bufLen + 1) * sizeof(char)); pReply = (Byte *)malloc( (bufLen + 1) * sizeof(char));
if( NULL == pReply ) if( NULL == pReply )
{ {
// Cleanup the channel by reading the remaining and return error. // Cleanup the channel by reading the remaining and return error.
int n; int n;
n = msgLen - MSG_REPLY_GENERAL; n = msgLen - MSG_REPLY_GENERAL;
while(n) while(n > 0)
{ {
int bytes = IPC_READ(ssHandle->platHandle, gpReplyBuf, MIN_REPLY_BUF_LEN); retVal = IPC_READ((ssHandle->platHandle), gpReplyBuf, MIN_REPLY_BUF_LEN);
if( bytes > 0 ) if (retVal < 0)
n -= MIN_REPLY_BUF_LEN; {
else IPC_CLOSE(ssHandle->platHandle);
break; DMSG(("Reading retcode::%d\n",retVal));
} retCode = NSSCS_E_SYSTEM_FAILURE;
retVal = IPC_READ(ssHandle->platHandle, break;
&sockReturn, MSG_DWORD_LEN); }
else
n -= MIN_REPLY_BUF_LEN;
}
retVal = IPC_READ(ssHandle->platHandle, &sockReturn, MSG_DWORD_LEN);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal)); DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
} }
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
@ -723,6 +738,14 @@ int32_t ipc_EnumerateKeychainIDs
tmpBuf = (SS_UTF8_T *)pReply; // Save this ptr to free later. tmpBuf = (SS_UTF8_T *)pReply; // Save this ptr to free later.
} }
retVal = IPC_READ(ssHandle->platHandle,pReply, bufLen*sizeof(char)); retVal = IPC_READ(ssHandle->platHandle,pReply, bufLen*sizeof(char));
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
tmpPtr = (SS_UTF8_T *)pReply; tmpPtr = (SS_UTF8_T *)pReply;
tmpPtr[bufLen] = nulc; tmpPtr[bufLen] = nulc;
@ -744,8 +767,16 @@ int32_t ipc_EnumerateKeychainIDs
free(tmpBuf); free(tmpBuf);
tmpBuf = NULL; tmpBuf = NULL;
} }
kcIDList->enumHandle = 0;
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
kcIDList->enumHandle = 0; if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = NSSS_E_ENUM_BUFF_TOO_SHORT; retCode = NSSS_E_ENUM_BUFF_TOO_SHORT;
break; break;
@ -766,11 +797,12 @@ int32_t ipc_EnumerateKeychainIDs
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
DMSG(("Reading retcode::%d\n",retVal)); IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
} }
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
while(0); while(0);
@ -876,6 +908,7 @@ int32_t ipc_AddKeychain
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -885,7 +918,9 @@ int32_t ipc_AddKeychain
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
//log debug info here //log debug info here
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -994,6 +1029,7 @@ int32_t ipc_RemoveKeychain
retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle, gpReqBuf, msgLen);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1003,6 +1039,8 @@ int32_t ipc_RemoveKeychain
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1126,6 +1164,7 @@ int32_t ipc_EnumerateSecretIDs
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1136,6 +1175,8 @@ int32_t ipc_EnumerateSecretIDs
if( retVal < 0 ) if( retVal < 0 )
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1150,8 +1191,16 @@ int32_t ipc_EnumerateSecretIDs
if( 0 == bufLen ) if( 0 == bufLen )
{ {
// Cleanup the channel by reading the return code. // Cleanup the channel by reading the return code.
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
secretIDList->returnedIDs = 0; secretIDList->returnedIDs = 0;
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
break; break;
} }
@ -1160,43 +1209,56 @@ int32_t ipc_EnumerateSecretIDs
pReply = gpReplyBuf; pReply = gpReplyBuf;
else else
{ {
if((bufLen + 1) >= MIN_REQUEST_BUF_LEN) if((bufLen + 1) >= MIN_REQUEST_BUF_LEN)
{ {
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
pReply = (Byte *)malloc( (bufLen + 1) * sizeof(SS_UTF8_T)); pReply = (Byte *)malloc( (bufLen + 1) * sizeof(SS_UTF8_T));
if(pReply == NULL) if(pReply == NULL)
{ {
// Cleanup the channel by reading the remaining and return error. // Cleanup the channel by reading the remaining and return error.
int n; int n;
n = msgLen - MSG_REPLY_GENERAL; n = msgLen - MSG_REPLY_GENERAL;
while(n) while(n > 0)
{ {
int bytes = IPC_READ((ssHandle->platHandle), gpReplyBuf, MIN_REPLY_BUF_LEN); retVal = IPC_READ((ssHandle->platHandle), gpReplyBuf, MIN_REPLY_BUF_LEN);
if(bytes > 0 ) if (retVal < 0)
n -= MIN_REPLY_BUF_LEN; {
else IPC_CLOSE(ssHandle->platHandle);
break; DMSG(("Reading retcode::%d\n",retVal));
} retCode = NSSCS_E_SYSTEM_FAILURE;
retVal = IPC_READ(ssHandle->platHandle, break;
&sockReturn, MSG_DWORD_LEN); }
if(retVal < 0) else
{ n -= MIN_REPLY_BUF_LEN;
//log debug info here }
DMSG(("Reading retcode::%d\n",retVal));
} retCode = NSSCS_E_SYSTEM_FAILURE;
retVal = IPC_READ(ssHandle->platHandle, &sockReturn, MSG_DWORD_LEN);
retCode = NSSCS_E_SYSTEM_FAILURE; if(retVal < 0)
break; {
} //log debug info here
else IPC_CLOSE(ssHandle->platHandle);
tmpBuf = (SS_UTF8_T *)pReply; // Save this ptr to free later. DMSG(("Reading retcode::%d\n",retVal));
break;
}
break;
}
else
tmpBuf = (SS_UTF8_T *)pReply; // Save this ptr to free later.
} }
retVal = IPC_READ(ssHandle->platHandle,pReply, bufLen*sizeof(SS_UTF8_T)); retVal = IPC_READ(ssHandle->platHandle,pReply, bufLen*sizeof(SS_UTF8_T));
DMSG(("Read returns..%d\n",retVal)); if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
tmpPtr = (SS_UTF8_T *)pReply; tmpPtr = (SS_UTF8_T *)pReply;
tmpPtr[bufLen] = nulc; tmpPtr[bufLen] = nulc;
DMSG(("Secretid list is %s\n", pReply)); DMSG(("Secretid list is %s\n", pReply));
@ -1217,6 +1279,15 @@ int32_t ipc_EnumerateSecretIDs
tmpBuf = NULL; tmpBuf = NULL;
} }
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
secretIDList->enumHandle = 0;
break;
}
secretIDList->enumHandle = 0; secretIDList->enumHandle = 0;
retCode = NSSS_E_ENUM_BUFF_TOO_SHORT; retCode = NSSS_E_ENUM_BUFF_TOO_SHORT;
break; break;
@ -1237,11 +1308,13 @@ int32_t ipc_EnumerateSecretIDs
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal)); DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
} }
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
while(0); while(0);
@ -1420,6 +1493,7 @@ int32_t ipc_ReadSecret
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1427,9 +1501,10 @@ int32_t ipc_ReadSecret
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if( 0 == retVal ) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1445,6 +1520,8 @@ int32_t ipc_ReadSecret
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1459,6 +1536,8 @@ int32_t ipc_ReadSecret
retVal = IPC_READ(ssHandle->platHandle, secretData->data, dataLen); retVal = IPC_READ(ssHandle->platHandle, secretData->data, dataLen);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1471,26 +1550,40 @@ int32_t ipc_ReadSecret
*bytesRequired = dataLen; *bytesRequired = dataLen;
{ {
// Cleanup the channel by reading the remaining and return error. // Cleanup the channel by reading the remaining and return error.
int n; retVal = IPC_READ(ssHandle->platHandle, gpReplyBuf, dataLen);
n = dataLen; if (retVal < 0)
while(n) {
{ IPC_CLOSE(ssHandle->platHandle);
int bytesRead = IPC_READ(ssHandle->platHandle, gpReplyBuf, n); DMSG(("Reading retcode::%d\n",retVal));
if( bytesRead > 0) retCode = NSSCS_E_SYSTEM_FAILURE;
n -= bytesRead; break;
else }
break;
}
// Read the sscs return code also. // Read the sscs return code also.
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT; retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT;
break; break;
} }
} }
// Read the sscs return code also. // Read the sscs return code also.
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
@ -1706,6 +1799,7 @@ int ipc_WriteSecret
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1716,6 +1810,8 @@ int ipc_WriteSecret
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1726,7 +1822,6 @@ int ipc_WriteSecret
pReply += MSG_LEN; pReply += MSG_LEN;
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
while(0); while(0);
@ -1916,6 +2011,7 @@ int32_t ipc_RemoveSecret
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -1925,16 +2021,17 @@ int32_t ipc_RemoveSecret
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
memcpy(&msgid,pReply, MSGID_LEN); memcpy(&msgid,pReply, MSGID_LEN);
pReply += MSGID_LEN; pReply += MSGID_LEN;
memcpy(&msgLen,pReply, MSG_LEN); memcpy(&msgLen,pReply, MSG_LEN);
pReply += MSG_LEN; pReply += MSG_LEN;
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
while(0); while(0);
@ -2029,17 +2126,17 @@ int32_t ipc_GetSecretStoreInfo
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = SSCS_E_SYSTEM_ERROR; retCode = SSCS_E_SYSTEM_ERROR;
break; break;
} }
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GETSSINFO);
MSG_REPLY_GETSSINFO);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here IPC_CLOSE(ssHandle->platHandle);
retCode = SSCS_E_SYSTEM_ERROR; retCode = SSCS_E_SYSTEM_ERROR;
break; break;
} }
@ -2155,6 +2252,7 @@ int32_t ipc_GetKeychainInfo
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2164,6 +2262,7 @@ int32_t ipc_GetKeychainInfo
retVal = IPC_READ(ssHandle->platHandle, pReply,MSG_REPLY_GETKEYCHAIN_INFO); retVal = IPC_READ(ssHandle->platHandle, pReply,MSG_REPLY_GETKEYCHAIN_INFO);
if(retVal < 0) if(retVal < 0)
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2272,6 +2371,7 @@ int32_t ipc_LockCache
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2280,7 +2380,7 @@ int32_t ipc_LockCache
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2382,18 +2482,22 @@ int32_t ipc_UnlockCache
if(retVal < 0) if(retVal < 0)
{ {
// log debug info here // log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = SSCS_E_SYSTEM_ERROR; retCode = SSCS_E_SYSTEM_ERROR;
break; break;
} }
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = SSCS_E_SYSTEM_ERROR; retCode = SSCS_E_SYSTEM_ERROR;
break; break;
} }
memcpy(&msgid,pReply, MSGID_LEN); memcpy(&msgid,pReply, MSGID_LEN);
pReply += MSGID_LEN; pReply += MSGID_LEN;
memcpy(&msgLen,pReply, MSG_LEN); memcpy(&msgLen,pReply, MSG_LEN);
@ -2405,7 +2509,6 @@ int32_t ipc_UnlockCache
DMSG(("Ret code :%d\n",sockReturn)); DMSG(("Ret code :%d\n",sockReturn));
} }
retCode = sockReturn; retCode = sockReturn;
} }
while(0); while(0);
@ -2427,7 +2530,6 @@ int32_t ipc_UnlockCache
/* /*
* NAME - ipc_SetMasterPasscode * NAME - ipc_SetMasterPasscode
* *
@ -2512,6 +2614,7 @@ int32_t ipc_SetMasterPasscode
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2522,6 +2625,7 @@ int32_t ipc_SetMasterPasscode
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2532,7 +2636,6 @@ int32_t ipc_SetMasterPasscode
pReply += MSG_LEN; pReply += MSG_LEN;
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = sockReturn; retCode = sockReturn;
} }
while(0); while(0);
@ -2730,6 +2833,7 @@ int32_t ipc_RemoveKey
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2737,9 +2841,10 @@ int32_t ipc_RemoveKey
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if( 0 == retVal ) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2941,6 +3046,7 @@ int32_t ipc_ReadKey
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2948,9 +3054,9 @@ int32_t ipc_ReadKey
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if( 0 == retVal ) if(retVal < 0)
{ {
//log debug info here IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2967,6 +3073,7 @@ int32_t ipc_ReadKey
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -2980,11 +3087,12 @@ int32_t ipc_ReadKey
retVal = IPC_READ(ssHandle->platHandle, val, dataLen); retVal = IPC_READ(ssHandle->platHandle, val, dataLen);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
// set the length of the data // set the length of the data
*valLen = dataLen; *valLen = dataLen;
} }
else else
@ -2993,25 +3101,38 @@ int32_t ipc_ReadKey
*bytesRequired = dataLen; *bytesRequired = dataLen;
{ {
// Cleanup the channel by reading the remaining and return error. // Cleanup the channel by reading the remaining and return error.
int n; retVal = IPC_READ(ssHandle->platHandle, gpReplyBuf, dataLen);
n = dataLen; if(retVal < 0)
while(n) {
{ //log debug info here
int bytesRead = IPC_READ(ssHandle->platHandle, gpReplyBuf, n); IPC_CLOSE(ssHandle->platHandle);
if( bytesRead > 0) retCode = NSSCS_E_SYSTEM_FAILURE;
n -= bytesRead; break;
else }
break;
}
// Read the sscs return code also. // Read the sscs return code also.
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT; retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT;
break; break;
} }
} }
// Read the sscs return code also. // Read the sscs return code also.
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
@ -3199,6 +3320,7 @@ int32_t ipc_ReadBinaryKey
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3206,9 +3328,10 @@ int32_t ipc_ReadBinaryKey
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL); retVal = IPC_READ(ssHandle->platHandle, pReply, MSG_REPLY_GENERAL);
if( 0 == retVal ) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3224,6 +3347,7 @@ int32_t ipc_ReadBinaryKey
retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle,&sockReturn, MSG_DWORD_LEN);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3237,11 +3361,11 @@ int32_t ipc_ReadBinaryKey
retVal = IPC_READ(ssHandle->platHandle, val, dataLen); retVal = IPC_READ(ssHandle->platHandle, val, dataLen);
if( retVal < 0 ) if( retVal < 0 )
{ {
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
*valLen = dataLen; *valLen = dataLen;
} }
else else
{ {
@ -3249,24 +3373,39 @@ int32_t ipc_ReadBinaryKey
*bytesRequired = dataLen; *bytesRequired = dataLen;
{ {
// Cleanup the channel by reading the remaining and return error. // Cleanup the channel by reading the remaining and return error.
int n; retVal = IPC_READ(ssHandle->platHandle, gpReplyBuf, dataLen);
n = dataLen; if(retVal < 0)
while(n) {
{ //log debug info here
int bytesRead = IPC_READ(ssHandle->platHandle, gpReplyBuf, n); IPC_CLOSE(ssHandle->platHandle);
if( bytesRead > 0) DMSG(("Reading retcode::%d\n",retVal));
n -= bytesRead; retCode = NSSCS_E_SYSTEM_FAILURE;
else break;
break; }
}
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT; retCode = NSSCS_E_ENUM_BUFF_TOO_SHORT;
break; break;
} }
} }
// Read the sscs return code also. // Read the sscs return code also.
IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN); retVal = IPC_READ(ssHandle->platHandle, (Byte *) &sockReturn, MSG_DWORD_LEN);
if(retVal < 0)
{
//log debug info here
IPC_CLOSE(ssHandle->platHandle);
DMSG(("Reading retcode::%d\n",retVal));
retCode = NSSCS_E_SYSTEM_FAILURE;
break;
}
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} while(0); } while(0);
@ -3492,9 +3631,11 @@ int ipc_WriteKey
{ {
retVal = IPC_WRITE(ssHandle->platHandle,gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle,gpReqBuf, msgLen);
} }
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3505,6 +3646,7 @@ int ipc_WriteKey
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3729,14 +3871,15 @@ int ipc_WriteBinaryKey
} }
// write the data // write the data
retVal = IPC_WRITE(ssHandle->platHandle,gpReqBuf, msgLen); retVal = IPC_WRITE(ssHandle->platHandle,gpReqBuf, msgLen);
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
retCode = NSSCS_E_SYSTEM_FAILURE; IPC_CLOSE(ssHandle->platHandle);
break; retCode = NSSCS_E_SYSTEM_FAILURE;
} break;
}
// Read reply // Read reply
pReply = gpReplyBuf; pReply = gpReplyBuf;
@ -3744,6 +3887,7 @@ int ipc_WriteBinaryKey
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3754,7 +3898,6 @@ int ipc_WriteBinaryKey
pReply += MSG_LEN; pReply += MSG_LEN;
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
while(0); while(0);
@ -3859,6 +4002,7 @@ int32_t ipc_SetMasterPassword
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3869,6 +4013,7 @@ int32_t ipc_SetMasterPassword
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -3879,21 +4024,20 @@ int32_t ipc_SetMasterPassword
pReply += MSG_LEN; pReply += MSG_LEN;
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = sockReturn; retCode = sockReturn;
} }
while(0); while(0);
if(gpReqBuf) if(gpReqBuf)
{ {
memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN); memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN);
free(gpReqBuf); free(gpReqBuf);
} }
if(gpReplyBuf) if(gpReplyBuf)
{ {
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN); memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf); free(gpReplyBuf);
} }
return retCode; return retCode;
} }
@ -4041,6 +4185,7 @@ int ipc_IsSecretPersistent
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -4051,6 +4196,7 @@ int ipc_IsSecretPersistent
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -4071,23 +4217,23 @@ int ipc_IsSecretPersistent
} }
while(0); while(0);
if( tmpBuf != NULL ) if( tmpBuf != NULL )
{ {
free(tmpBuf); free(tmpBuf);
tmpBuf = NULL; tmpBuf = NULL;
} }
if(gpReqBuf) if(gpReqBuf)
{ {
memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN); memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN);
free(gpReqBuf); free(gpReqBuf);
} }
if(gpReplyBuf) if(gpReplyBuf)
{ {
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN); memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf); free(gpReplyBuf);
} }
return retCode; return retCode;
@ -4228,6 +4374,7 @@ int32_t ipc_MergeCache(SSCS_SECRETSTORE_HANDLE_T *ssHandle,
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -4238,6 +4385,7 @@ int32_t ipc_MergeCache(SSCS_SECRETSTORE_HANDLE_T *ssHandle,
if(retVal < 0) if(retVal < 0)
{ {
//log debug info here //log debug info here
IPC_CLOSE(ssHandle->platHandle);
retCode = NSSCS_E_SYSTEM_FAILURE; retCode = NSSCS_E_SYSTEM_FAILURE;
break; break;
} }
@ -4249,27 +4397,26 @@ int32_t ipc_MergeCache(SSCS_SECRETSTORE_HANDLE_T *ssHandle,
memcpy(&sockReturn, pReply, MSG_DWORD_LEN); memcpy(&sockReturn, pReply, MSG_DWORD_LEN);
retCode = mapReturnCode(sockReturn); retCode = mapReturnCode(sockReturn);
} }
} }
while(0); while(0);
if( tmpBuf != NULL ) if( tmpBuf != NULL )
{ {
free(tmpBuf); free(tmpBuf);
tmpBuf = NULL; tmpBuf = NULL;
} }
if(gpReqBuf) if(gpReqBuf)
{ {
memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN); memset(gpReqBuf, 0, MIN_REQUEST_BUF_LEN);
free(gpReqBuf); free(gpReqBuf);
} }
if(gpReplyBuf) if(gpReplyBuf)
{ {
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN); memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf); free(gpReplyBuf);
} }
return retCode; return retCode;
} }

View File

@ -39,6 +39,7 @@ namespace Novell.CASA.MiCasa.Communication
private Socket mSocket = null; private Socket mSocket = null;
private string socketFileName = "/var/run/.novellCASA"; private string socketFileName = "/var/run/.novellCASA";
private EndPoint sockEndPoint; private EndPoint sockEndPoint;
private const int TimeOut = 3 * 1000 * 1000; //3 seconds
public UnixIPCClientChannel() public UnixIPCClientChannel()
{ {
@ -60,6 +61,7 @@ namespace Novell.CASA.MiCasa.Communication
// root is the owner of the file "/var/run/.novellCASA" // root is the owner of the file "/var/run/.novellCASA"
if (socketFileStatus.st_uid == 0) if (socketFileStatus.st_uid == 0)
{ {
mSocket.Blocking = false;
sockEndPoint = new UnixEndPoint(socketFileName); sockEndPoint = new UnixEndPoint(socketFileName);
mSocket.Connect(sockEndPoint); mSocket.Connect(sockEndPoint);
} }
@ -90,6 +92,11 @@ namespace Novell.CASA.MiCasa.Communication
try try
{ {
if (!mSocket.Poll(TimeOut, SelectMode.SelectRead))
{
throw new Exception("Timed out or Poll failed during socket read.");
}
/* We need to read 'msgLen' to know how many bytes to /* We need to read 'msgLen' to know how many bytes to
* allocate. * allocate.
*/ */
@ -163,6 +170,11 @@ namespace Novell.CASA.MiCasa.Communication
{ {
try try
{ {
if (!mSocket.Poll(TimeOut, SelectMode.SelectWrite))
{
throw new Exception("Timed out or Poll failed during socket write.");
}
mSocket.Send(buf); mSocket.Send(buf);
return buf.Length; return buf.Length;
} }