From 241b2a596f851866a80f5235ea28d9a25efebd20 Mon Sep 17 00:00:00 2001 From: antiduh Date: Thu, 19 Jun 2014 18:45:15 +0000 Subject: [PATCH] Slowly working on InitializeSecurityContext --- NativeMethods.cs | 64 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/NativeMethods.cs b/NativeMethods.cs index 6351187..2c36f98 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -98,7 +98,8 @@ namespace NSspi /// /// The overload of the QueryCredentialsAttribute method that is used for querying the name attribute. - /// In this call, it takes a void* to a structure that contains a wide char pointer. + /// In this call, it takes a void* to a structure that contains a wide char pointer. The wide character + /// pointer is allocated by the SSPI api, and thus needs to be released by a call to FreeContextBuffer(). /// /// /// @@ -122,5 +123,66 @@ namespace NSspi { public IntPtr Name; } + + + + // When used in the ClientContext: + /* + SECURITY_STATUS sResult = InitializeSecurityContext( + phCredential, // [in] handle to the credentials + NULL, // [in/out] handle of partially formed context. Always NULL the first time through + pwszServerPrincipalName, // [in] name of the target of the context. Not needed by NTLM + reqContextAttributes, // [in] required context attributes + 0, // [reserved] reserved; must be zero + SECURITY_NATIVE_DREP, // [in] data representation on the target + NULL, // [in/out] pointer to the input buffers. Always NULL the first time through + 0, // [reserved] reserved; must be zero + this->contextHandle, // [in/out] receives the new context handle (must be pre-allocated) + &outBuffDesc, // [out] pointer to the output buffers + pulContextAttributes, // [out] receives the context attributes + &tsLifeSpan // [out] receives the life span of the security context + ); + */ + /* + SECURITY_STATUS SEC_Entry InitializeSecurityContext( + _In_opt_ PCredHandle phCredential, + _In_opt_ PCtxtHandle phContext, + _In_opt_ SEC_CHAR *pszTargetName, + _In_ ULONG fContextReq, + _In_ ULONG Reserved1, + _In_ ULONG TargetDataRep, + _In_opt_ PSecBufferDesc pInput, + _In_ ULONG Reserved2, + _Inout_opt_ PCtxtHandle phNewContext, + _Inout_opt_ PSecBufferDesc pOutput, + _Out_ PULONG pfContextAttr, + _Out_opt_ PTimeStamp ptsExpiry + ); + */ + + public static extern SecurityStatus InitializeSecurityContext_Client( + ref long credentialHandle, + ref long prevContextHandle, + string serverPrincipleName, + int requiredAttribs, + int reserved1, + int dataRep, + IntPtr dataBuffers, + int reserved2, + ref long newContextHandle, + IntPtr outputBuffer, + ref int contextAttribs, + ref long expiry + ); + + + [DllImport( + "Secur32.dll", + EntryPoint = "DeleteSecurityContext", + CallingConvention = CallingConvention.Winapi, + CharSet = CharSet.Unicode, + SetLastError = true + )] + public static extern SecurityStatus DeleteSecurityContext( ref long contextHandle ); } }