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 <errno.h>
#include <unistd.h>
#include <fcntl.h>
void* ipc_unx_create(void);
int ipc_unx_write(int fd, Byte *pData, int bytes);

View File

@ -30,6 +30,9 @@
int firstReadAfterWrite = 0;
#endif
#ifdef SSCS_LINUX_PLAT_F
#define RETRIES 1000
#endif
/*
*/
@ -49,6 +52,16 @@ void* ipc_unx_create()
retVal = sockFd;
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));
servAddr.sun_family = AF_UNIX;
@ -101,7 +114,62 @@ void * ipc_win_create()
#ifdef SSCS_LINUX_PLAT_F
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 )
{
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 bytesToRead = 0; // Keep track of number of bytes to read
int bytesRead = 0; // Number of bytes read
int totalBytesRead = 0;
int retVal = 0;
int retries = RETRIES;
ssize_t bytesRead = 0;
ssize_t bytesToRead = 0;
for(bytesToRead = bytes; bytesToRead;)
bytesToRead = bytes;
while (1)
{
if ((bytesRead = read(fd, pData, bytesToRead)) == 0)
bytesRead = read(fd, pData, bytesToRead);
if (bytesRead == 0)
{
break;
}
else
{
if(bytesRead < 0)
if (bytesRead > 0)
{
return -1;
}
// We read some data, account for it.
bytesToRead -= bytesRead;
pData += bytesRead;
totalBytesRead += bytesRead;
// Done if all of the data has been read
if (bytesToRead == 0)
{
break;
}
}
return totalBytesRead;
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;
}
}
}
}
if( retVal < 0 )
{
DMSG(("Read returns error : %d - %s\n",retVal, strerror(errno)));
}
return retVal;
}
//#endif

View File

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

View File

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