Пример #1
0
        protected override bool ReleaseHandle()
        {
            SecurityStatus status = CredentialNativeMethods.FreeCredentialsHandle(
                ref base.rawHandle
                );

            base.ReleaseHandle();

            return(status == SecurityStatus.OK);
        }
Пример #2
0
        private void Init(CredentialUse use)
        {
            string         packageName;
            TimeStamp      rawExpiry = new TimeStamp();
            SecurityStatus status    = SecurityStatus.InternalError;

            // -- Package --
            // Copy off for the call, since this.SecurityPackage is a property.
            packageName = this.SecurityPackage;

            this.Handle = new SafeCredentialHandle();

            // The finally clause is the actual constrained region. The VM pre-allocates any stack space,
            // performs any allocations it needs to prepare methods for execution, and postpones any
            // instances of the 'uncatchable' exceptions (ThreadAbort, StackOverflow, OutOfMemory).
            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                status = CredentialNativeMethods.AcquireCredentialsHandle(
                    null,
                    packageName,
                    use,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    ref this.Handle.rawHandle,
                    ref rawExpiry
                    );
            }

            if (status != SecurityStatus.OK)
            {
                SSPIException exc = new SSPIException("Failed to call AcquireCredentialHandle", status);
                throw new SecurityException(ErrorHandling.ErrorCodes.Security.SSPI_ERROR, new string[] { exc.Message });
            }

            this.Expiry = rawExpiry.ToDateTime();
        }