Cleaned up code style and comments

This commit is contained in:
antiduh
2014-06-24 21:35:32 +00:00
parent 766b16e93c
commit 56e48dc65d
2 changed files with 54 additions and 157 deletions

View File

@@ -22,15 +22,24 @@ namespace NSspi
_Out_ PULONG pfContextAttr, _Out_ PULONG pfContextAttr,
_Out_opt_ PTimeStamp ptsTimeStamp _Out_opt_ PTimeStamp ptsTimeStamp
); );
SECURITY_STATUS SEC_Entry InitializeSecurityContext(
_In_opt_ PCredHandle phCredential, // [in] handle to the credentials
_In_opt_ PCtxtHandle phContext, // [in/out] handle of partially formed context. Always NULL the first time through
_In_opt_ SEC_CHAR *pszTargetName, // [in] name of the target of the context. Not needed by NTLM
_In_ ULONG fContextReq, // [in] required context attributes
_In_ ULONG Reserved1, // [reserved] reserved; must be zero
_In_ ULONG TargetDataRep, // [in] data representation on the target
_In_opt_ PSecBufferDesc pInput, // [in/out] pointer to the input buffers. Always NULL the first time through
_In_ ULONG Reserved2, // [reserved] reserved; must be zero
_Inout_opt_ PCtxtHandle phNewContext, // [in/out] receives the new context handle (must be pre-allocated)
_Inout_opt_ PSecBufferDesc pOutput, // [out] pointer to the output buffers
_Out_ PULONG pfContextAttr, // [out] receives the context attributes
_Out_opt_ PTimeStamp ptsExpiry // [out] receives the life span of the security context
);
*/ */
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "AcceptSecurityContext",CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "AcceptSecurityContext",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus AcceptSecurityContext_1( public static extern SecurityStatus AcceptSecurityContext_1(
ref RawSspiHandle credHandle, ref RawSspiHandle credHandle,
IntPtr oldContextHandle, IntPtr oldContextHandle,
@@ -44,13 +53,7 @@ namespace NSspi
); );
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "AcceptSecurityContext", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "AcceptSecurityContext",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus AcceptSecurityContext_2( public static extern SecurityStatus AcceptSecurityContext_2(
ref RawSspiHandle credHandle, ref RawSspiHandle credHandle,
ref RawSspiHandle oldContextHandle, ref RawSspiHandle oldContextHandle,
@@ -63,47 +66,8 @@ namespace NSspi
ref long expiry ref long expiry
); );
// 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
);
*/
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "InitializeSecurityContext",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus InitializeSecurityContext_1( public static extern SecurityStatus InitializeSecurityContext_1(
ref RawSspiHandle credentialHandle, ref RawSspiHandle credentialHandle,
IntPtr zero, IntPtr zero,
@@ -119,13 +83,8 @@ namespace NSspi
ref long expiry ref long expiry
); );
[DllImport(
"Secur32.dll", [DllImport( "Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode )]
EntryPoint = "InitializeSecurityContext",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus InitializeSecurityContext_2( public static extern SecurityStatus InitializeSecurityContext_2(
ref RawSspiHandle credentialHandle, ref RawSspiHandle credentialHandle,
ref RawSspiHandle previousHandle, ref RawSspiHandle previousHandle,
@@ -141,22 +100,12 @@ namespace NSspi
ref long expiry ref long expiry
); );
[DllImport(
"Secur32.dll", [DllImport( "Secur32.dll", EntryPoint = "DeleteSecurityContext", CharSet = CharSet.Unicode )]
EntryPoint = "DeleteSecurityContext",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus DeleteSecurityContext( ref RawSspiHandle contextHandle ); public static extern SecurityStatus DeleteSecurityContext( ref RawSspiHandle contextHandle );
[DllImport(
"Secur32.dll", [DllImport( "Secur32.dll", EntryPoint = "EncryptMessage", CharSet = CharSet.Unicode )]
EntryPoint = "EncryptMessage",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus EncryptMessage( public static extern SecurityStatus EncryptMessage(
ref RawSspiHandle contextHandle, ref RawSspiHandle contextHandle,
int qualityOfProtection, int qualityOfProtection,
@@ -165,13 +114,7 @@ namespace NSspi
); );
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "DecryptMessage", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "DecryptMessage",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus DecryptMessage( public static extern SecurityStatus DecryptMessage(
ref RawSspiHandle contextHandle, ref RawSspiHandle contextHandle,
IntPtr bufferDescriptor, IntPtr bufferDescriptor,
@@ -179,22 +122,14 @@ namespace NSspi
int qualityOfProtection int qualityOfProtection
); );
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "QueryContextAttributes",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode )]
public static extern SecurityStatus QueryContextAttributes_Sizes( public static extern SecurityStatus QueryContextAttributes_Sizes(
ref RawSspiHandle contextHandle, ref RawSspiHandle contextHandle,
ContextQueryAttrib attrib, ContextQueryAttrib attrib,
ref SecPkgContext_Sizes sizes ref SecPkgContext_Sizes sizes
); );
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "QueryContextAttributes",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode )]
public static extern SecurityStatus QueryContextAttributes_String( public static extern SecurityStatus QueryContextAttributes_String(
ref RawSspiHandle contextHandle, ref RawSspiHandle contextHandle,
ContextQueryAttrib attrib, ContextQueryAttrib attrib,
@@ -202,11 +137,7 @@ namespace NSspi
); );
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "FreeContextBuffer", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "FreeContextBuffer",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode )]
public static extern SecurityStatus FreeContextBuffer( IntPtr handle ); public static extern SecurityStatus FreeContextBuffer( IntPtr handle );
} }
} }

View File

@@ -10,40 +10,31 @@ namespace NSspi
{ {
public static class CredentialNativeMethods public static class CredentialNativeMethods
{ {
/* /*
SECURITY_STATUS sResult = AcquireCredentialsHandle( SECURITY_STATUS SEC_Entry AcquireCredentialsHandle(
NULL, // [in] name of principal. NULL = principal of current security context _In_ SEC_CHAR *pszPrincipal, // [in] name of principal. NULL = principal of current security context
pszPackageName, // [in] name of package _In_ SEC_CHAR *pszPackage, // [in] name of security package - "Kerberos", "Negotiate", "NTLM", etc
fCredentialUse, // [in] flags indicating use. _In_ ULONG fCredentialUse, // [in] flags indicating use.
NULL, // [in] pointer to logon identifier. NULL = we're not specifying the id of another logon session _In_ PLUID pvLogonID, // [in] pointer to logon identifier. NULL = we're not specifying the id of another logon session
NULL, // [in] package-specific data. NULL = default credentials for security package _In_ PVOID pAuthData, // [in] package-specific data. NULL = default credentials for security package
NULL, // [in] pointer to GetKey function. NULL = we're not using a callback to retrieve the credentials _In_ SEC_GET_KEY_FN pGetKeyFn, // [in] pointer to GetKey function. NULL = we're not using a callback to retrieve the credentials
NULL, // [in] value to pass to GetKey _In_ PVOID pvGetKeyArgument, // [in] value to pass to GetKey
this->credentialHandle, // [out] credential handle (this must be already allocated) _Out_ PCredHandle phCredential, // [out] credential handle (this must be already allocated)
&tsExpiry // [out] lifetime of the returned credentials _Out_ PTimeStamp ptsExpiry // [out] lifetime of the returned credentials
); );
SECURITY_STATUS SEC_Entry AcquireCredentialsHandle( SECURITY_STATUS SEC_Entry FreeCredentialsHandle(
_In_ SEC_CHAR *pszPrincipal, _In_ PCredHandle phCredential
_In_ SEC_CHAR *pszPackage, );
_In_ ULONG fCredentialUse,
_In_ PLUID pvLogonID, SECURITY_STATUS SEC_Entry QueryCredentialsAttributes(
_In_ PVOID pAuthData, _In_ PCredHandle phCredential,
_In_ SEC_GET_KEY_FN pGetKeyFn, _In_ ULONG ulAttribute,
_In_ PVOID pvGetKeyArgument, _Out_ PVOID pBuffer
_Out_ PCredHandle phCredential, );
_Out_ PTimeStamp ptsExpiry */
);
*/
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "AcquireCredentialsHandle",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus AcquireCredentialsHandle( public static extern SecurityStatus AcquireCredentialsHandle(
string principleName, string principleName,
string packageName, string packageName,
@@ -56,29 +47,12 @@ namespace NSspi
ref long expiry ref long expiry
); );
/*
SECURITY_STATUS SEC_Entry FreeCredentialsHandle( [DllImport( "Secur32.dll", EntryPoint = "FreeCredentialsHandle", CharSet = CharSet.Unicode )]
_In_ PCredHandle phCredential
);
*/
[DllImport(
"Secur32.dll",
EntryPoint = "FreeCredentialsHandle",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus FreeCredentialsHandle( public static extern SecurityStatus FreeCredentialsHandle(
ref RawSspiHandle credentialHandle ref RawSspiHandle credentialHandle
); );
/*
SECURITY_STATUS SEC_Entry QueryCredentialsAttributes(
_In_ PCredHandle phCredential,
_In_ ULONG ulAttribute,
_Out_ PVOID pBuffer
);
*/
/// <summary> /// <summary>
/// The overload of the QueryCredentialsAttribute method that is used for querying the name attribute. /// The overload of the QueryCredentialsAttribute method that is used for querying the name attribute.
@@ -89,19 +63,11 @@ namespace NSspi
/// <param name="attributeName"></param> /// <param name="attributeName"></param>
/// <param name="name"></param> /// <param name="name"></param>
/// <returns></returns> /// <returns></returns>
[DllImport( [DllImport( "Secur32.dll", EntryPoint = "QueryCredentialsAttributes", CharSet = CharSet.Unicode )]
"Secur32.dll",
EntryPoint = "QueryCredentialsAttributes",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern SecurityStatus QueryCredentialsAttribute_Name( public static extern SecurityStatus QueryCredentialsAttribute_Name(
ref RawSspiHandle credentialHandle, ref RawSspiHandle credentialHandle,
CredentialQueryAttrib attributeName, CredentialQueryAttrib attributeName,
ref QueryNameAttribCarrier name ref QueryNameAttribCarrier name
); );
} }
} }