コード例 #1
0
        public static byte[] GetType1Message(string domainName, string userName, string password, out SecHandle clientContext)
        {
            SecHandle handle = AcquireNTLMCredentialsHandle(domainName, userName, password);

            clientContext = new SecHandle();
            SecBufferDesc    output = new SecBufferDesc(MAX_TOKEN_SIZE);
            uint             contextAttributes;
            SECURITY_INTEGER expiry;

            int result = InitializeSecurityContext(ref handle, IntPtr.Zero, null, ISC_REQ_CONFIDENTIALITY | ISC_REQ_INTEGRITY, 0, SECURITY_NATIVE_DREP, IntPtr.Zero, 0, ref clientContext, ref output, out contextAttributes, out expiry);

            if (result != SEC_E_OK && result != SEC_I_CONTINUE_NEEDED)
            {
                if ((uint)result == SEC_E_INVALID_HANDLE)
                {
                    throw new Exception("InitializeSecurityContext failed, Invalid handle");
                }
                else if ((uint)result == SEC_E_BUFFER_TOO_SMALL)
                {
                    throw new Exception("InitializeSecurityContext failed, Buffer too small");
                }
                else
                {
                    throw new Exception("InitializeSecurityContext failed, Error code " + ((uint)result).ToString("X"));
                }
            }
            return(output.GetSecBufferBytes());
        }
コード例 #2
0
 private extern static int DeleteSecurityContext(
     ref SecHandle phContext
     );
コード例 #3
0
 public static byte[] GetType1Message(string userName, string password, out SecHandle clientContext)
 {
     return(GetType1Message(String.Empty, userName, password, out clientContext));
 }
コード例 #4
0
 private extern static int FreeCredentialsHandle(
     ref SecHandle phCredential
     );