Bug 339641. Fix for ZEN that was hanging logins on Terminal Server.

This commit is contained in:
Jim Norman 2008-01-03 18:06:10 +00:00
parent 154b707eee
commit 11b9891e63
4 changed files with 117 additions and 35 deletions

View File

@ -62,7 +62,45 @@ static SS_UTF8_T SSCS_RESERVED2_KEY_CHAIN_ID[] = "SSCS_RESERVED2_KEYCHAIN2_ID";
#define SSCS_PASSWORD_MP_F 1
#define SSCS_CRED_MP_F 2
#define NSSCS_MAX_ID_LEN 256
#define NSSCS_MAX_ID_LEN 256
#define DebugLevel 0
static SS_UTF8_T g_pDebugLogFilePath[] = {"\\micasa_lib.log"};
#ifdef DEBUG
#define DbgTrace(LEVEL, X, Y) { \
char formatBuff[256]; \
char printBuff[384]; \
FILE *pDebugFile; \
if (LEVEL == 0 || DebugLevel >= LEVEL) \
{ \
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); \
_snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \
if (g_pDebugLogFilePath) \
{ \
pDebugFile = fopen(g_pDebugLogFilePath, "a+"); \
if (pDebugFile) \
{ \
fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \
fflush(pDebugFile); \
fclose(pDebugFile); \
} \
} \
else \
OutputDebugString(printBuff); \
} \
}
#else
#define DbgTrace(LEVEL, X, Y) {}
#endif
typedef struct _sscs_linux_ss_handle
{
@ -100,8 +138,8 @@ typedef struct _sscs_secret
typedef struct _sscs_context_t
{
int32_t version;
int32_t flags;
int32_t version;
int32_t flags;
SSCS_SECRETSTORE_T ssid;
void *ssHandle;
SSCS_KEYCHAIN_ID_LIST_T *kcids;

View File

@ -90,6 +90,8 @@ void * ipc_win_create()
HANDLE hPipe = NULL;
int rcode;
DWORD mode = PIPE_READMODE_MESSAGE;
DbgTrace(1, " -ipc_win_create- start\n", 0);
hPipe = CreateFile(
XTIER_RPC_PIPE,
@ -102,10 +104,13 @@ void * ipc_win_create()
if (hPipe == INVALID_HANDLE_VALUE)
{
rcode = GetLastError();
return 0;
rcode = GetLastError();
DbgTrace(0, " Create Pipe error:%d\r\n", rcode);
return -1;
}
DbgTrace(1, " -ipc_win_create- end\n", 0);
return hPipe;
}
@ -183,19 +188,12 @@ int ipc_unx_write(int fd, Byte *pData, int bytes)
int ipc_win_write(HANDLE hPipe, LPCVOID lpBuffer, DWORD bytesToWrite)
{
//#ifdef SSCS_WIN32_PLAT_F
BOOL rcode;
int icode;
DWORD lpBytesWritten = 0;
//LPCVOID msgLen = malloc(4);
// rcode = WaitNamedPipe(
// XTIER_RPC_PIPE,
// NMPWAIT_WAIT_FOREVER);
DbgTrace(1, " -ipc_win_write- start\n", 0);
// the server expects us to first write the number of bytes in the msg we're about to write.
rcode = WriteFile(
@ -208,14 +206,10 @@ int ipc_win_write(HANDLE hPipe, LPCVOID lpBuffer, DWORD bytesToWrite)
if (!rcode)
{
icode = GetLastError();
return 0;
DbgTrace(0, " Pipe Write Error:%d\r\n", icode);
return -1;
}
// rcode = WaitNamedPipe(
// XTIER_RPC_PIPE,
// NMPWAIT_WAIT_FOREVER);
rcode = WriteFile(
hPipe,
lpBuffer, //LPCVOID lpBuffer,
@ -226,10 +220,12 @@ int ipc_win_write(HANDLE hPipe, LPCVOID lpBuffer, DWORD bytesToWrite)
if (!rcode)
{
icode = GetLastError();
DbgTrace(0, " Pipe Write Error:%d\r\n", icode);
return -1;
}
firstReadAfterWrite = 1;
DbgTrace(1, " -ipc_win_write- end\n", 0);
return lpBytesWritten;
}
@ -320,6 +316,7 @@ int ipc_win_read(HANDLE hPipe, LPVOID lpBuffer, DWORD numOfBytesToRead)
LPVOID pMsgLen = malloc(4);
int icode;
DbgTrace(1, " -ipc_win_read- start\n", 0);
if (firstReadAfterWrite)
{
firstReadAfterWrite = 0;
@ -335,7 +332,8 @@ int ipc_win_read(HANDLE hPipe, LPVOID lpBuffer, DWORD numOfBytesToRead)
if (!rcode)
{
icode = GetLastError();
return 0;
DbgTrace(0, " Pipe Read error: %d\r\n", icode);
return -1;
}
}
@ -347,10 +345,17 @@ int ipc_win_read(HANDLE hPipe, LPVOID lpBuffer, DWORD numOfBytesToRead)
&numBytesRead, //LPDWORD lpNumberOfBytesRead,
NULL); //LPOVERLAPPED lpOverlapped
if (!rcode)
{
icode = GetLastError();
DbgTrace(0, " Pipe Read error: %d\r\n", icode);
return -1;
}
if (pMsgLen)
free(pMsgLen);
DbgTrace(1, " -ipc_win_read- end\n", 0);
return numBytesRead;
}
#endif
@ -368,13 +373,13 @@ int ipc_unx_close(int fd)
int ipc_win_close(HANDLE hPipe)
{
//#ifdef SSCS_WIN32_PLAT_F
BOOL rcode;
DbgTrace(1, " -ipc_win_close- start\n", 0);
rcode = DisconnectNamedPipe(hPipe);
rcode = CloseHandle(hPipe);
return 0;
DbgTrace(1, " -ipc_win_close- end\n", 0);
return 0;
}

View File

@ -230,6 +230,9 @@ int32_t ipc_OpenSecretStore
Byte *gpReqBuf = NULL;
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_OpenSecretStore- start\n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -353,6 +356,7 @@ int32_t ipc_OpenSecretStore
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_OpenSecretStore- end \n", 0);
return retCode; // map the return code from sockReturn
}
@ -382,6 +386,8 @@ int32_t ipc_CloseSecretStore
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_CloseSecretStore- start \n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -453,7 +459,7 @@ int32_t ipc_CloseSecretStore
}
while(0);
DMSG(("Closing socket : %d\n",*(int*)ssHandle->platHandle));
//DMSG(("Closing socket : %d\n",*(int*)ssHandle->platHandle));
IPC_CLOSE(ssHandle->platHandle);
if(gpReqBuf)
@ -468,6 +474,7 @@ int32_t ipc_CloseSecretStore
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_CloseSecretStore- end \r\n\r\n", 0);
return retCode; // map return code
}
@ -1372,6 +1379,8 @@ int32_t ipc_ReadSecret
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_ReadSecret- start %s\n", secretID->id);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -1601,6 +1610,8 @@ int32_t ipc_ReadSecret
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_ReadSecret- end \n", 0);
return retCode;
}
@ -1879,7 +1890,7 @@ int32_t ipc_RemoveSecret
Byte *gpReqBuf = NULL;
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_RemoveSecret- start %s\n", secretID->id);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -2046,7 +2057,7 @@ int32_t ipc_RemoveSecret
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_RemoveSecret- end \n", 0);
return retCode;
}
@ -2077,6 +2088,7 @@ int32_t ipc_GetSecretStoreInfo
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_GetSecretStoreInfo- start \n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -2170,6 +2182,7 @@ int32_t ipc_GetSecretStoreInfo
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_GetSecretStoreInfo- end \n", 0);
return retCode; // map return code
}
@ -2201,6 +2214,8 @@ int32_t ipc_GetKeychainInfo
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_GetKeychainInfo- start \n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -2301,6 +2316,7 @@ int32_t ipc_GetKeychainInfo
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_GetKeychainInfo- start \n", 0);
return retCode;
}
@ -2693,6 +2709,8 @@ int32_t ipc_RemoveKey
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_RemoveKey- start \n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -2871,6 +2889,8 @@ int32_t ipc_RemoveKey
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_RemoveKey- end \n", 0);
return retCode;
}
@ -2915,7 +2935,7 @@ int32_t ipc_ReadKey
Byte *gpReqBuf = NULL;
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_ReadKey- start %s\n",key);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -3149,7 +3169,7 @@ int32_t ipc_ReadKey
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_ReadKey- end\n", 0);
return retCode;
}
@ -3194,6 +3214,9 @@ int32_t ipc_ReadBinaryKey
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_ReadBinaryKey- start\n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -3422,6 +3445,7 @@ int32_t ipc_ReadBinaryKey
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_ReadBinaryKey- end\n", 0);
return retCode;
}
@ -3469,6 +3493,7 @@ int ipc_WriteKey
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_WriteKey- start %s\n", key);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -3678,7 +3703,7 @@ int ipc_WriteKey
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_WriteKey- end\n", 0);
return retCode;
}
@ -3726,6 +3751,7 @@ int ipc_WriteBinaryKey
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_WriteBinaryKey- start %s\n", key);
if (valLen > MAX_BINARY_KEY_LEN)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -3913,7 +3939,7 @@ int ipc_WriteBinaryKey
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_WriteBinaryKey- end\n", 0);
return retCode;
}
@ -4269,6 +4295,8 @@ int32_t ipc_MergeCache(SSCS_SECRETSTORE_HANDLE_T *ssHandle,
Byte *gpReplyBuf = NULL;
Byte *pReq = NULL, *pReply = NULL;
DbgTrace(1, "-ipc_MergeCache- start\n", 0);
if((gpReqBuf = malloc(MIN_REQUEST_BUF_LEN)) == NULL)
{
return(NSSCS_E_SYSTEM_FAILURE);
@ -4417,6 +4445,8 @@ int32_t ipc_MergeCache(SSCS_SECRETSTORE_HANDLE_T *ssHandle,
memset(gpReplyBuf, 0, MIN_REPLY_BUF_LEN);
free(gpReplyBuf);
}
DbgTrace(1, "-ipc_MergeCache- end\n", 0);
return retCode;
}

View File

@ -192,8 +192,17 @@ namespace sscs.common
user = User.CreateUser(userId);
}
mutex.WaitOne();
sessionTable.Add(userId,user);
mutex.WaitOne();
try
{
sessionTable.Add(userId, user);
}
catch (Exception e)
{
CSSSLogger.DbgLog(e.ToString());
}
mutex.ReleaseMutex();
ss = user.GetSecretStore();
ss.IncrRefCount();