Bug 339461. Fixed memory leak that caused random errors or hangs. Also increased NamedPipe Channels to 1024.
This commit is contained in:
parent
f28ce8f26b
commit
4df0612f64
@ -18,8 +18,8 @@
|
|||||||
* To contact Novell about this file by physical or electronic mail,
|
* To contact Novell about this file by physical or electronic mail,
|
||||||
* you may find current contact information at www.novell.com.
|
* you may find current contact information at www.novell.com.
|
||||||
*
|
*
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using AppModule.NamedPipes;
|
using AppModule.NamedPipes;
|
||||||
@ -28,133 +28,131 @@ using System.Text;
|
|||||||
|
|
||||||
using HANDLE = System.IntPtr;
|
using HANDLE = System.IntPtr;
|
||||||
|
|
||||||
namespace AppModule.NamedPipes
|
namespace AppModule.NamedPipes
|
||||||
{
|
{
|
||||||
#region Comments
|
#region Comments
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A utility class that exposes named pipes operations.
|
/// A utility class that exposes named pipes operations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This class uses the exposed exposed kernel32.dll methods by the
|
/// This class uses the exposed exposed kernel32.dll methods by the
|
||||||
/// <see cref="AppModule.NamedPipes.NamedPipeNative">NamedPipeNative</see> class
|
/// <see cref="AppModule.NamedPipes.NamedPipeNative">NamedPipeNative</see> class
|
||||||
/// to provided controlled named pipe functionality.
|
/// to provided controlled named pipe functionality.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
#endregion
|
#endregion
|
||||||
public sealed class ImpersonateWrapper
|
public sealed class ImpersonateWrapper
|
||||||
{
|
{
|
||||||
|
|
||||||
public const int TOKEN_QUERY = 0X00000008;
|
public const int TOKEN_QUERY = 0X00000008;
|
||||||
|
|
||||||
const int ERROR_NO_MORE_ITEMS = 259;
|
const int ERROR_NO_MORE_ITEMS = 259;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Client USERID stuff
|
// Client USERID stuff
|
||||||
// 1. call ImpersonateNamedPipeClient(hPipe)
|
// 1. call ImpersonateNamedPipeClient(hPipe)
|
||||||
// 2. call OpenThreadToken(GetCurrentThread(),
|
// 2. call OpenThreadToken(GetCurrentThread(),
|
||||||
// TOKEN_QUERY | TOKEN_QUERY_SOURCE,
|
// TOKEN_QUERY | TOKEN_QUERY_SOURCE,
|
||||||
// FALSE,
|
// FALSE,
|
||||||
// phUserToken);
|
// phUserToken);
|
||||||
|
|
||||||
public static int ImpersonateNamedPipeClient(IntPtr hPipeHandle)
|
public static int ImpersonateNamedPipeClient(IntPtr hPipeHandle)
|
||||||
{
|
{
|
||||||
int rcode = ImpersonateNative.ImpersonateNamedPipeClient(hPipeHandle);
|
int rcode = ImpersonateNative.ImpersonateNamedPipeClient(hPipeHandle);
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
static int PerformDump(HANDLE token)
|
static int PerformDump(HANDLE token)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
ImpersonateNative.TOKEN_USER tokUser;
|
ImpersonateNative.TOKEN_USER tokUser;
|
||||||
const int bufLength = 256;
|
const int bufLength = 256;
|
||||||
IntPtr tu = Marshal.AllocHGlobal( bufLength );
|
IntPtr tu = Marshal.AllocHGlobal( bufLength );
|
||||||
int cb = bufLength;
|
int cb = bufLength;
|
||||||
if (ImpersonateNative.GetTokenInformation( token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenUser, tu, cb, ref cb ))
|
if (ImpersonateNative.GetTokenInformation( token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenUser, tu, cb, ref cb ))
|
||||||
Console.WriteLine("GetTokenInformation successful");
|
Console.WriteLine("GetTokenInformation successful");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("GetTokenInformation NOT successful");
|
Console.WriteLine("GetTokenInformation NOT successful");
|
||||||
uint error = NamedPipeNative.GetLastError();
|
uint error = NamedPipeNative.GetLastError();
|
||||||
Console.WriteLine("error" + error.ToString());
|
Console.WriteLine("error" + error.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
tokUser = (ImpersonateNative.TOKEN_USER) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_USER) );
|
tokUser = (ImpersonateNative.TOKEN_USER) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_USER) );
|
||||||
//sb.Append(DumpAccountSid(tokUser.User.Sid));
|
IntPtr pUserID = tokUser.User.Sid;
|
||||||
IntPtr pUserID = tokUser.User.Sid;
|
|
||||||
//Console.WriteLine("UserID: " + pUserID);
|
DumpAccountSid(pUserID);
|
||||||
|
Marshal.FreeHGlobal( tu );
|
||||||
DumpAccountSid(pUserID);
|
|
||||||
Marshal.FreeHGlobal( tu );
|
tu = Marshal.AllocHGlobal(bufLength);
|
||||||
|
cb = bufLength;
|
||||||
|
|
||||||
tu = Marshal.AllocHGlobal(bufLength);
|
// get token states
|
||||||
cb = bufLength;
|
ImpersonateNative.TOKEN_STATISTICS stats;
|
||||||
|
|
||||||
// get token states
|
if (ImpersonateNative.GetTokenInformation(token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
||||||
ImpersonateNative.TOKEN_STATISTICS stats;
|
{
|
||||||
|
stats = (ImpersonateNative.TOKEN_STATISTICS) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
||||||
if (ImpersonateNative.GetTokenInformation(token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
Console.WriteLine("UserLow: "+stats.AuthenticationId.LowPart.ToString());
|
||||||
{
|
Console.WriteLine("UserHigh: "+stats.AuthenticationId.HighPart.ToString());
|
||||||
stats = (ImpersonateNative.TOKEN_STATISTICS) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
}
|
||||||
Console.WriteLine("UserLow: "+stats.AuthenticationId.LowPart.ToString());
|
else
|
||||||
Console.WriteLine("UserHigh: "+stats.AuthenticationId.HighPart.ToString());
|
{
|
||||||
}
|
Console.WriteLine("failed");
|
||||||
else
|
}
|
||||||
{
|
|
||||||
Console.WriteLine("failed");
|
Marshal.FreeHGlobal(tu);
|
||||||
}
|
|
||||||
|
return (int)pUserID;
|
||||||
Marshal.FreeHGlobal(tu);
|
}
|
||||||
|
|
||||||
return (int)pUserID;
|
|
||||||
}
|
static string DumpAccountSid(IntPtr SID)
|
||||||
|
{
|
||||||
|
int cchAccount = 0;
|
||||||
static string DumpAccountSid(IntPtr SID)
|
int cchDomain = 0;
|
||||||
{
|
int snu = 0 ;
|
||||||
int cchAccount = 0;
|
StringBuilder sb = new StringBuilder();
|
||||||
int cchDomain = 0;
|
|
||||||
int snu = 0 ;
|
// Caller allocated buffer
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder Account= null;
|
||||||
|
StringBuilder Domain = null;
|
||||||
// Caller allocated buffer
|
bool ret = ImpersonateNative.LookupAccountSid(null, SID, Account, ref cchAccount, Domain, ref cchDomain, ref snu);
|
||||||
StringBuilder Account= null;
|
if ( ret == true )
|
||||||
StringBuilder Domain = null;
|
if ( Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
|
||||||
bool ret = ImpersonateNative.LookupAccountSid(null, SID, Account, ref cchAccount, Domain, ref cchDomain, ref snu);
|
return "Error";
|
||||||
if ( ret == true )
|
try
|
||||||
if ( Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
|
{
|
||||||
return "Error";
|
Account = new StringBuilder( cchAccount );
|
||||||
try
|
Domain = new StringBuilder( cchDomain );
|
||||||
{
|
ret = ImpersonateNative.LookupAccountSid(null, SID, Account, ref cchAccount, Domain, ref cchDomain, ref snu);
|
||||||
Account = new StringBuilder( cchAccount );
|
if (ret)
|
||||||
Domain = new StringBuilder( cchDomain );
|
{
|
||||||
ret = ImpersonateNative.LookupAccountSid(null, SID, Account, ref cchAccount, Domain, ref cchDomain, ref snu);
|
sb.Append(Domain);
|
||||||
if (ret)
|
sb.Append(@"\\");
|
||||||
{
|
sb.Append(Account);
|
||||||
sb.Append(Domain);
|
}
|
||||||
sb.Append(@"\\");
|
else
|
||||||
sb.Append(Account);
|
Console.WriteLine("logon account (no name) ");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
Console.WriteLine("logon account (no name) ");
|
{
|
||||||
}
|
Console.WriteLine(ex.Message);
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
finally
|
||||||
Console.WriteLine(ex.Message);
|
{
|
||||||
}
|
}
|
||||||
finally
|
string SidString = null;
|
||||||
{
|
ImpersonateNative.ConvertSidToStringSid(SID, ref SidString);
|
||||||
}
|
sb.Append("\nSID: ");
|
||||||
string SidString = null;
|
sb.Append(SidString);
|
||||||
ImpersonateNative.ConvertSidToStringSid(SID, ref SidString);
|
|
||||||
sb.Append("\nSID: ");
|
|
||||||
sb.Append(SidString);
|
Console.WriteLine("Acct info: "+ sb.ToString());
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
Console.WriteLine("Acct info: "+ sb.ToString());
|
#endif
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool GetLinkedToken(IntPtr token, out ImpersonateNative.TOKEN_LINKED_TOKEN linkedToken)
|
public static bool GetLinkedToken(IntPtr token, out ImpersonateNative.TOKEN_LINKED_TOKEN linkedToken)
|
||||||
{
|
{
|
||||||
@ -169,7 +167,6 @@ namespace AppModule.NamedPipes
|
|||||||
|
|
||||||
ImpersonateNative.GetTokenInformation(token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenLinkedToken, IntPtr.Zero, TokenInfLength, ref TokenInfLength);
|
ImpersonateNative.GetTokenInformation(token, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenLinkedToken, IntPtr.Zero, TokenInfLength, ref TokenInfLength);
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ptrLinkedToken = Marshal.AllocHGlobal(TokenInfLength);
|
ptrLinkedToken = Marshal.AllocHGlobal(TokenInfLength);
|
||||||
@ -198,53 +195,48 @@ namespace AppModule.NamedPipes
|
|||||||
return TokenInfoSuccess;
|
return TokenInfoSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetLocalUserID(PipeHandle handle, ref int lowPart, ref int highPart, ref string SidString, ref int lowPartElevated, ref int highPartElevated)
|
public static int GetLocalUserID(PipeHandle handle, ref int lowPart, ref int highPart, ref string SidString, ref int lowPartElevated, ref int highPartElevated)
|
||||||
{
|
{
|
||||||
int rcode = -1;
|
int rcode = -1;
|
||||||
// get client userID
|
// get client userID
|
||||||
int code = ImpersonateNative.ImpersonateNamedPipeClient(handle.Handle);
|
int code = ImpersonateNative.ImpersonateNamedPipeClient(handle.Handle);
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
{
|
{
|
||||||
uint lastError = NamedPipeNative.GetLastError();
|
uint lastError = NamedPipeNative.GetLastError();
|
||||||
Console.WriteLine("ImpersonateNamedPipeClient Error: "+rcode.ToString());
|
System.Diagnostics.Debug.WriteLine("CASA: ImpersonateNamedPipeClient Error: " + rcode.ToString());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr hThread = ImpersonateNative.GetCurrentThread();
|
IntPtr hThread = ImpersonateNative.GetCurrentThread();
|
||||||
uint iDesiredInfo = 24; //TOKEN_QUERY | TOKEN_QUERY_SOURCE;
|
uint iDesiredInfo = 24; //TOKEN_QUERY | TOKEN_QUERY_SOURCE;
|
||||||
IntPtr userToken = Marshal.AllocHGlobal(4);
|
IntPtr userToken = IntPtr.Zero;
|
||||||
IntPtr userTokenElevated = IntPtr.Zero;
|
IntPtr userTokenElevated = IntPtr.Zero;
|
||||||
|
|
||||||
if (ImpersonateNative.OpenThreadToken(hThread, iDesiredInfo, true, out userToken))
|
if (ImpersonateNative.OpenThreadToken(hThread, iDesiredInfo, true, out userToken))
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
ImpersonateNative.TOKEN_USER tokUser;
|
ImpersonateNative.TOKEN_USER tokUser;
|
||||||
const int bufLength = 256;
|
const int bufLength = 256;
|
||||||
IntPtr tu = Marshal.AllocHGlobal( bufLength );
|
IntPtr tu = Marshal.AllocHGlobal(bufLength);
|
||||||
int cb = bufLength;
|
int cb = bufLength;
|
||||||
|
|
||||||
// on Vista use the elevated token if there is one.
|
// on Vista use the elevated token if there is one.
|
||||||
System.OperatingSystem os = System.Environment.OSVersion;
|
System.OperatingSystem os = System.Environment.OSVersion;
|
||||||
System.Diagnostics.Trace.WriteLine("OS Version: " + os.Version.ToString());
|
|
||||||
if (os.Version.Major > 5)
|
if (os.Version.Major > 5)
|
||||||
{
|
{
|
||||||
if (ImpersonateNative.GetTokenInformation(userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenElevationType, tu, cb, ref cb))
|
if (ImpersonateNative.GetTokenInformation(userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenElevationType, tu, cb, ref cb))
|
||||||
{
|
{
|
||||||
int iTokenType;
|
int iTokenType;
|
||||||
iTokenType = (int)Marshal.PtrToStructure(tu, typeof(int));
|
iTokenType = (int)Marshal.PtrToStructure(tu, typeof(int));
|
||||||
|
|
||||||
System.Diagnostics.Trace.WriteLine("Token Type: " + iTokenType.ToString());
|
|
||||||
if (iTokenType == (int)ImpersonateNative.TOKEN_ELEVATION_TYPE.TokenElevationTypeLimited)
|
if (iTokenType == (int)ImpersonateNative.TOKEN_ELEVATION_TYPE.TokenElevationTypeLimited)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Trace.WriteLine("Getting linked token");
|
|
||||||
|
|
||||||
ImpersonateNative.TOKEN_LINKED_TOKEN newLinkedToken;
|
ImpersonateNative.TOKEN_LINKED_TOKEN newLinkedToken;
|
||||||
if (GetLinkedToken(userToken, out newLinkedToken))
|
if (GetLinkedToken(userToken, out newLinkedToken))
|
||||||
{
|
{
|
||||||
//userToken = newLinkedToken.LinkedToken;
|
|
||||||
userTokenElevated = Marshal.AllocHGlobal(4);
|
|
||||||
userTokenElevated = newLinkedToken.LinkedToken;
|
userTokenElevated = newLinkedToken.LinkedToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,38 +244,38 @@ namespace AppModule.NamedPipes
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint error = ImpersonateNative.GetLastError();
|
uint error = ImpersonateNative.GetLastError();
|
||||||
System.Diagnostics.Trace.WriteLine("linked token error: " + error.ToString());
|
System.Diagnostics.Debug.WriteLine("CASA: linked token error: " + error.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = bufLength;
|
cb = bufLength;
|
||||||
if (ImpersonateNative.GetTokenInformation( userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenUser, tu, cb, ref cb ))
|
if (ImpersonateNative.GetTokenInformation(userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenUser, tu, cb, ref cb))
|
||||||
{
|
{
|
||||||
tokUser = (ImpersonateNative.TOKEN_USER) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_USER) );
|
tokUser = (ImpersonateNative.TOKEN_USER)Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_USER));
|
||||||
IntPtr pUserID = tokUser.User.Sid;
|
IntPtr pUserID = tokUser.User.Sid;
|
||||||
Marshal.FreeHGlobal( tu );
|
Marshal.FreeHGlobal(tu);
|
||||||
|
|
||||||
// get SID
|
// get SID
|
||||||
//string SidString = null;
|
ImpersonateNative.ConvertSidToStringSid(pUserID, ref SidString);
|
||||||
ImpersonateNative.ConvertSidToStringSid(pUserID, ref SidString);
|
|
||||||
|
|
||||||
// get token states
|
// get token states
|
||||||
tu = Marshal.AllocHGlobal(bufLength);
|
tu = Marshal.AllocHGlobal(bufLength);
|
||||||
cb = bufLength;
|
cb = bufLength;
|
||||||
ImpersonateNative.TOKEN_STATISTICS stats;
|
ImpersonateNative.TOKEN_STATISTICS stats;
|
||||||
if (ImpersonateNative.GetTokenInformation(userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
if (ImpersonateNative.GetTokenInformation(userToken, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
||||||
{
|
{
|
||||||
stats = (ImpersonateNative.TOKEN_STATISTICS) Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
stats = (ImpersonateNative.TOKEN_STATISTICS)Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
||||||
// copy low and high part
|
|
||||||
lowPart = stats.AuthenticationId.LowPart;
|
// copy low and high part
|
||||||
highPart = stats.AuthenticationId.HighPart;
|
lowPart = stats.AuthenticationId.LowPart;
|
||||||
rcode = -1;
|
highPart = stats.AuthenticationId.HighPart;
|
||||||
}
|
rcode = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// get elevated token stats
|
// get elevated token stats
|
||||||
if (userTokenElevated != IntPtr.Zero)
|
if (userTokenElevated != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
cb = bufLength;
|
cb = bufLength;
|
||||||
if (ImpersonateNative.GetTokenInformation(userTokenElevated, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
if (ImpersonateNative.GetTokenInformation(userTokenElevated, ImpersonateNative.TOKEN_INFORMATION_CLASS.TokenStatistics, tu, cb, ref cb))
|
||||||
{
|
{
|
||||||
stats = (ImpersonateNative.TOKEN_STATISTICS)Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
stats = (ImpersonateNative.TOKEN_STATISTICS)Marshal.PtrToStructure(tu, typeof(ImpersonateNative.TOKEN_STATISTICS));
|
||||||
@ -292,44 +284,57 @@ namespace AppModule.NamedPipes
|
|||||||
highPartElevated = stats.AuthenticationId.HighPart;
|
highPartElevated = stats.AuthenticationId.HighPart;
|
||||||
rcode = -1;
|
rcode = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ImpersonateNative.CloseHandle(userTokenElevated))
|
||||||
|
{
|
||||||
|
uint errCode = ImpersonateNative.GetLastError();
|
||||||
|
System.Diagnostics.Debug.WriteLine("CASA: Closing elevated handle failed: {0}", errCode.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
userTokenElevated = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("GetTokenInformation NOT successful");
|
uint error = NamedPipeNative.GetLastError();
|
||||||
uint error = NamedPipeNative.GetLastError();
|
System.Diagnostics.Debug.WriteLine("CASA: GetTokenInformation NOT successful " + error.ToString());
|
||||||
Console.WriteLine("error" + error.ToString());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Marshal.FreeHGlobal(tu);
|
Marshal.FreeHGlobal(tu);
|
||||||
|
|
||||||
// close handle
|
// close handles
|
||||||
ImpersonateNative.CloseHandle(hThread);
|
if (!ImpersonateNative.CloseHandle(userToken))
|
||||||
ImpersonateNative.RevertToSelf();
|
{
|
||||||
}
|
uint errCode = ImpersonateNative.GetLastError();
|
||||||
else
|
System.Diagnostics.Debug.WriteLine("CASA: Close userToken failed: {0}", errCode.ToString());
|
||||||
{
|
}
|
||||||
int lastError = Marshal.GetLastWin32Error();
|
else
|
||||||
uint errorcode = NamedPipeNative.GetLastError();
|
{
|
||||||
Console.WriteLine("OpenThreadToken Error: "+ errorcode.ToString() + " code2: "+rcode.ToString());
|
userToken = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ImpersonateNative.RevertToSelf())
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine("CASA: RevertToSelf failed");
|
||||||
|
}
|
||||||
|
|
||||||
Marshal.FreeHGlobal(userToken);
|
|
||||||
if (userTokenElevated != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
Marshal.FreeHGlobal(userTokenElevated);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
uint errorcode = NamedPipeNative.GetLastError();
|
||||||
int error = Marshal.GetLastWin32Error();
|
System.Diagnostics.Debug.WriteLine("CASA: OpenThreadToken Error: " + errorcode.ToString());
|
||||||
Console.WriteLine(ex.ToString());
|
}
|
||||||
return rcode;
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
// end
|
{
|
||||||
|
int error = Marshal.GetLastWin32Error();
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex.ToString());
|
||||||
|
return rcode;
|
||||||
|
}
|
||||||
|
// end
|
||||||
|
|
||||||
return rcode;
|
return rcode;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
CASA/micasad/cache/SecretStore.cs
vendored
4
CASA/micasad/cache/SecretStore.cs
vendored
@ -895,8 +895,8 @@ namespace sscs.cache
|
|||||||
return passwd;
|
return passwd;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
CSSSLogger.ExpLog(e.ToString());
|
CSSSLogger.DbgLog("Desktop password not set");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -20,148 +20,148 @@
|
|||||||
*
|
*
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using AppModule.InterProcessComm;
|
using AppModule.InterProcessComm;
|
||||||
using AppModule.NamedPipes;
|
using AppModule.NamedPipes;
|
||||||
|
|
||||||
namespace sscs.communication.win {
|
namespace sscs.communication.win {
|
||||||
|
|
||||||
public class PipeManager : IChannelManager {
|
public class PipeManager : IChannelManager {
|
||||||
|
|
||||||
public Hashtable Pipes;
|
public Hashtable Pipes;
|
||||||
|
|
||||||
private uint NumberPipes = 16;
|
private uint NumberPipes = 1024;
|
||||||
private uint OutBuffer = 65536; //512;
|
private uint OutBuffer = 65536; //512;
|
||||||
private uint InBuffer = 65536; //512;
|
private uint InBuffer = 65536; //512;
|
||||||
private const int MAX_READ_BYTES = 15000;
|
private const int MAX_READ_BYTES = 15000;
|
||||||
private bool _listen = true;
|
private bool _listen = true;
|
||||||
public bool Listen {
|
public bool Listen {
|
||||||
get {
|
get {
|
||||||
return _listen;
|
return _listen;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
_listen=value;
|
_listen=value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int numChannels = 0;
|
private int numChannels = 0;
|
||||||
private Hashtable _pipes = new Hashtable();
|
private Hashtable _pipes = new Hashtable();
|
||||||
|
|
||||||
//private Thread MainThread;
|
//private Thread MainThread;
|
||||||
private string CASA_RPC_PIPE = "\\\\.\\PIPE\\SS_RPC_PIPE";
|
private string CASA_RPC_PIPE = "\\\\.\\PIPE\\SS_RPC_PIPE";
|
||||||
private ManualResetEvent Mre;
|
private ManualResetEvent Mre;
|
||||||
private const int PIPE_MAX_STUFFED_TIME = 5000;
|
private const int PIPE_MAX_STUFFED_TIME = 5000;
|
||||||
|
|
||||||
public object SyncRoot = new object();
|
public object SyncRoot = new object();
|
||||||
|
|
||||||
public void Initialize() {
|
public void Initialize() {
|
||||||
Pipes = Hashtable.Synchronized(_pipes);
|
Pipes = Hashtable.Synchronized(_pipes);
|
||||||
Mre = new ManualResetEvent(false);
|
Mre = new ManualResetEvent(false);
|
||||||
/*
|
/*
|
||||||
MainThread = new Thread(new ThreadStart(Start));
|
MainThread = new Thread(new ThreadStart(Start));
|
||||||
MainThread.IsBackground = true;
|
MainThread.IsBackground = true;
|
||||||
MainThread.Name = "Main Pipe Thread";
|
MainThread.Name = "Main Pipe Thread";
|
||||||
MainThread.Start();
|
MainThread.Start();
|
||||||
*/
|
*/
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
public string HandleRequest(string request) {
|
public string HandleRequest(string request) {
|
||||||
string returnVal;
|
string returnVal;
|
||||||
|
|
||||||
//Form1.ActivityRef.AppendText(request + Environment.NewLine);
|
//Form1.ActivityRef.AppendText(request + Environment.NewLine);
|
||||||
returnVal = "Response to: " + request;
|
returnVal = "Response to: " + request;
|
||||||
|
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start() {
|
public void Start() {
|
||||||
try {
|
try {
|
||||||
while (_listen) {
|
while (_listen) {
|
||||||
int[] keys = new int[Pipes.Keys.Count];
|
int[] keys = new int[Pipes.Keys.Count];
|
||||||
Pipes.Keys.CopyTo(keys,0);
|
Pipes.Keys.CopyTo(keys,0);
|
||||||
foreach (int key in keys) {
|
foreach (int key in keys) {
|
||||||
ServerNamedPipe serverPipe = (ServerNamedPipe)Pipes[key];
|
ServerNamedPipe serverPipe = (ServerNamedPipe)Pipes[key];
|
||||||
if (serverPipe != null && DateTime.Now.Subtract(serverPipe.LastAction).Milliseconds > PIPE_MAX_STUFFED_TIME && serverPipe.PipeConnection.GetState() != InterProcessConnectionState.WaitingForClient) {
|
if (serverPipe != null && DateTime.Now.Subtract(serverPipe.LastAction).Milliseconds > PIPE_MAX_STUFFED_TIME && serverPipe.PipeConnection.GetState() != InterProcessConnectionState.WaitingForClient) {
|
||||||
serverPipe.Listen = false;
|
serverPipe.Listen = false;
|
||||||
serverPipe.PipeThread.Abort();
|
serverPipe.PipeThread.Abort();
|
||||||
RemoveServerChannel(serverPipe.PipeConnection.NativeHandle);
|
RemoveServerChannel(serverPipe.PipeConnection.NativeHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numChannels <= NumberPipes) {
|
if (numChannels <= NumberPipes) {
|
||||||
ServerNamedPipe pipe = new ServerNamedPipe(CASA_RPC_PIPE, OutBuffer, InBuffer, MAX_READ_BYTES);
|
ServerNamedPipe pipe = new ServerNamedPipe(CASA_RPC_PIPE, OutBuffer, InBuffer, MAX_READ_BYTES);
|
||||||
try {
|
try {
|
||||||
pipe.Connect();
|
pipe.Connect();
|
||||||
pipe.LastAction = DateTime.Now;
|
pipe.LastAction = DateTime.Now;
|
||||||
System.Threading.Interlocked.Increment(ref numChannels);
|
System.Threading.Interlocked.Increment(ref numChannels);
|
||||||
pipe.Start();
|
pipe.Start();
|
||||||
Pipes.Add(pipe.PipeConnection.NativeHandle, pipe);
|
Pipes.Add(pipe.PipeConnection.NativeHandle, pipe);
|
||||||
}
|
}
|
||||||
catch (InterProcessIOException) {
|
catch (InterProcessIOException) {
|
||||||
RemoveServerChannel(pipe.PipeConnection.NativeHandle);
|
RemoveServerChannel(pipe.PipeConnection.NativeHandle);
|
||||||
pipe.Dispose();
|
pipe.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mre.Reset();
|
Mre.Reset();
|
||||||
Mre.WaitOne(1000, false);
|
Mre.WaitOne(1000, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Exception starting server: "+e.ToString());
|
Console.WriteLine("Exception starting server: "+e.ToString());
|
||||||
// Log exception
|
// Log exception
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Stop() {
|
public void Stop() {
|
||||||
_listen = false;
|
_listen = false;
|
||||||
Mre.Set();
|
Mre.Set();
|
||||||
try {
|
try {
|
||||||
int[] keys = new int[Pipes.Keys.Count];
|
int[] keys = new int[Pipes.Keys.Count];
|
||||||
Pipes.Keys.CopyTo(keys,0);
|
Pipes.Keys.CopyTo(keys,0);
|
||||||
foreach (int key in keys) {
|
foreach (int key in keys) {
|
||||||
((ServerNamedPipe)Pipes[key]).Listen = false;
|
((ServerNamedPipe)Pipes[key]).Listen = false;
|
||||||
}
|
}
|
||||||
int i = numChannels * 3;
|
int i = numChannels * 3;
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
StopServerPipe();
|
StopServerPipe();
|
||||||
}
|
}
|
||||||
Pipes.Clear();
|
Pipes.Clear();
|
||||||
Mre.Close();
|
Mre.Close();
|
||||||
Mre = null;
|
Mre = null;
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
// Log exception
|
// Log exception
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WakeUp() {
|
public void WakeUp() {
|
||||||
if (Mre != null) {
|
if (Mre != null) {
|
||||||
Mre.Set();
|
Mre.Set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void StopServerPipe() {
|
private void StopServerPipe() {
|
||||||
try {
|
try {
|
||||||
ClientPipeConnection pipe = new ClientPipeConnection(CASA_RPC_PIPE);
|
ClientPipeConnection pipe = new ClientPipeConnection(CASA_RPC_PIPE);
|
||||||
if (pipe.TryConnect()) {
|
if (pipe.TryConnect()) {
|
||||||
pipe.Close();
|
pipe.Close();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Log exception
|
// Log exception
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveServerChannel(object param) {
|
public void RemoveServerChannel(object param) {
|
||||||
int handle = (int)param;
|
int handle = (int)param;
|
||||||
System.Threading.Interlocked.Decrement(ref numChannels);
|
System.Threading.Interlocked.Decrement(ref numChannels);
|
||||||
Pipes.Remove(handle);
|
Pipes.Remove(handle);
|
||||||
this.WakeUp();
|
this.WakeUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@ void RemoveServerSecret()
|
|||||||
RemoveSecret(SSCS_CRED_TYPE_SERVER_F);
|
RemoveSecret(SSCS_CRED_TYPE_SERVER_F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunTest()
|
void RunTest(char *SecretID)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
SSCS_BASIC_CREDENTIAL credential = {0};
|
SSCS_BASIC_CREDENTIAL credential = {0};
|
||||||
@ -604,7 +604,8 @@ void RunTest()
|
|||||||
int rcode = 0;
|
int rcode = 0;
|
||||||
int iFlags = 0;
|
int iFlags = 0;
|
||||||
|
|
||||||
sscs_Utf8Strcpy(appSecretId.id, "NativeC.AppSecretID");
|
//sscs_Utf8Strcpy(appSecretId.id, "NativeC.AppSecretID");
|
||||||
|
sscs_Utf8Strcpy(appSecretId.id, SecretID);
|
||||||
appSecretId.len = sscs_Utf8Strlen(appSecretId.id) + 1;
|
appSecretId.len = sscs_Utf8Strlen(appSecretId.id) + 1;
|
||||||
|
|
||||||
credential.unFlags = USERNAME_TYPE_CN_F;
|
credential.unFlags = USERNAME_TYPE_CN_F;
|
||||||
@ -765,6 +766,7 @@ void RunTests()
|
|||||||
int iCount = 1;
|
int iCount = 1;
|
||||||
int iTemp = 0;
|
int iTemp = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
char inputID[20];
|
||||||
|
|
||||||
printf("Enter number interations to run (default 1): ");
|
printf("Enter number interations to run (default 1): ");
|
||||||
gets(runtimes);
|
gets(runtimes);
|
||||||
@ -773,9 +775,13 @@ void RunTests()
|
|||||||
if (iTemp > 1)
|
if (iTemp > 1)
|
||||||
iCount=iTemp;
|
iCount=iTemp;
|
||||||
|
|
||||||
|
printf("Enter secretID: ");
|
||||||
|
gets(inputID);
|
||||||
|
|
||||||
for (i=0; i<iCount; i++)
|
for (i=0; i<iCount; i++)
|
||||||
{
|
{
|
||||||
RunTest();
|
printf("Count: %d\r\n", i);
|
||||||
|
RunTest(&inputID);
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user