public unsafe static int AcquireCredentialsHandle( SecurDll dll, string package, CredentialUse intent, ref SecureCredential authdata, out SafeFreeCredentials outCredential ) { GlobalLog.Print("SafeFreeCredentials::AcquireCredentialsHandle#2(" + dll + "," + package + ", " + intent + ", " + authdata + ")" ); int errorCode = -1; long timeStamp; // If there is a certificate, wrap it into an array. // Not threadsafe. IntPtr copiedPtr = authdata.certContextArray; try { IntPtr certArrayPtr = new IntPtr(&copiedPtr); if (copiedPtr != IntPtr.Zero) { authdata.certContextArray = certArrayPtr; } switch (dll) { case SecurDll.SECURITY: outCredential = new SafeFreeCredential_SECURITY(); RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { errorCode = UnsafeNclNativeMethods.SafeNetHandles_SECURITY.AcquireCredentialsHandleW( null, package, (int)intent, null, ref authdata, null, null, ref outCredential._handle, out timeStamp ); } break; default: throw new ArgumentException(SR.GetString(SR.net_invalid_enum, "SecurDll"), "Dll"); } } finally { authdata.certContextArray = copiedPtr; } #if TRAVE GlobalLog.Print("Unmanaged::AcquireCredentialsHandle() returns 0x" + errorCode.ToString("x") + ", handle = " + outCredential.ToString() ); #endif if (errorCode != 0) { outCredential.SetHandleAsInvalid(); } return errorCode; }
public unsafe static int AcquireDefaultCredential( SecurDll dll, string package, CredentialUse intent, out SafeFreeCredentials outCredential ) { GlobalLog.Print("SafeFreeCredentials::AcquireDefaultCredential(" + dll + "," + package + ", " + intent + ")" ); int errorCode = -1; long timeStamp; switch (dll) { case SecurDll.SECURITY: outCredential = new SafeFreeCredential_SECURITY(); RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { errorCode = UnsafeNclNativeMethods.SafeNetHandles_SECURITY.AcquireCredentialsHandleW( null, package, (int)intent, null, IntPtr.Zero, null, null, ref outCredential._handle, out timeStamp ); } break; default: throw new ArgumentException(SR.GetString(SR.net_invalid_enum, "SecurDll"), "Dll"); } #if TRAVE GlobalLog.Print("Unmanaged::AcquireCredentialsHandle() returns 0x" + errorCode.ToString("x") + ", handle = " + outCredential.ToString() ); #endif if (errorCode != 0) { outCredential.SetHandleAsInvalid(); } return errorCode; }