예제 #1
0
        private void GetMaxTokenSize()
        {
            int count;
            SafeContextBufferHandle secPkgInfos;

            if (Sspi.EnumerateSecurityPackages(out count, out secPkgInfos) != SecurityStatus.SEC_E_OK)
            {
                throw new Win32Exception("Failed to EnumerateSecurityPackages");
            }

            for (int i = 0; i < count; i++)
            {
                var item = secPkgInfos.GetItem <SecPkgInfo>(i);
                if (string.Compare(item.GetName(), @"Schannel", true) == 0)
                {
                    maxTokenSize = item.cbMaxToken;
                    break;
                }
            }

            if (maxTokenSize == 0)
            {
                throw new Exception("Failed to retrive cbMaxToken for Schannel");
            }
        }
예제 #2
0
        private void GetMaxTokenSize()
        {
            int num;
            SafeContextBufferHandle safeContextBufferHandle;

            if (Sspi.EnumerateSecurityPackages(out num, out safeContextBufferHandle) != SecurityStatus.SEC_E_OK)
            {
                throw new Win32Exception("Failed to EnumerateSecurityPackages");
            }
            for (int i = 0; i < num; i++)
            {
                SecPkgInfo item = safeContextBufferHandle.GetItem <SecPkgInfo>(i);
                if (string.Compare(item.GetName(), "Schannel", true) == 0)
                {
                    this.maxTokenSize = item.cbMaxToken;
                    break;
                }
            }
            if (this.maxTokenSize == 0)
            {
                throw new Exception("Failed to retrive cbMaxToken for Schannel");
            }
        }
        private static MaxTokenSizes GetMaxTokenSizes()
        {
            int count;
            SafeContextBufferHandle secPkgInfos;

            if (Sspi.EnumerateSecurityPackages(out count, out secPkgInfos) != SecurityStatus.SEC_E_OK)
            {
                throw new Win32Exception("Failed to EnumerateSecurityPackages");
            }

            int ntlm = 0, kerberos = 0;

            for (int i = 0; i < count; i++)
            {
                var item = secPkgInfos.GetItem <SecPkgInfo>(i);

                if (string.Compare(item.GetName(), @"NTLM", true) == 0)
                {
                    ntlm = item.cbMaxToken;
                }
                if (string.Compare(item.GetName(), @"Kerberos", true) == 0)
                {
                    kerberos = item.cbMaxToken;
                }
            }

            if (ntlm == 0)
            {
                throw new Exception(@"Failed to retrive cbMaxToken for NTLM");
            }
            if (kerberos == 0)
            {
                throw new Exception(@"Failed to retrive cbMaxToken for Kerberos");
            }

            return(new MaxTokenSizes(ntlm, kerberos));
        }