Skip to content

Commit eb1c4b7

Browse files
committed
Added AddCredentials.
1 parent 7ec7435 commit eb1c4b7

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

NtApiDotNet/Win32/Security/Authentication/CredentialHandle.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,37 @@ public IServerAuthenticationContext CreateServer(AcceptContextReqFlags req_attri
231231
return ServerAuthenticationContext.Create(this, req_attributes, channel_binding, data_rep, owns_credentials);
232232
}
233233

234+
/// <summary>
235+
/// Add credentials to the handle.
236+
/// </summary>
237+
/// <param name="principal">User principal.</param>
238+
/// <param name="package">The package name.</param>
239+
/// <param name="cred_use_flag">Credential user flags.</param>
240+
/// <param name="auth_data">Optional authentication data.</param>
241+
public void AddCredentials(string principal, string package, SecPkgCredFlags cred_use_flag, SafeBuffer auth_data)
242+
{
243+
LargeInteger timestamp = new LargeInteger();
244+
SecurityNativeMethods.AddCredentials(CredHandle, principal, package, cred_use_flag, auth_data, IntPtr.Zero, IntPtr.Zero, timestamp).CheckResult();
245+
}
246+
247+
/// <summary>
248+
/// Add credentials to the handle.
249+
/// </summary>
250+
/// <param name="principal">User principal.</param>
251+
/// <param name="package">The package name.</param>
252+
/// <param name="cred_use_flag">Credential user flags.</param>
253+
/// <param name="credentials">Optional credentials.</param>
254+
public void AddCredentials(string principal, string package, SecPkgCredFlags cred_use_flag, AuthenticationCredentials credentials)
255+
{
256+
using (var list = new DisposableList())
257+
{
258+
using (var buffer = credentials.ToBuffer(list, package))
259+
{
260+
AddCredentials(principal, package, cred_use_flag, buffer);
261+
}
262+
}
263+
}
264+
234265
/// <summary>
235266
/// Finalizer.
236267
/// </summary>

NtApiDotNet/Win32/Security/Native/SecurityNativeMethods.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ [Out] LargeInteger ptsExpiry
6161
[DllImport("Secur32.dll", CharSet = CharSet.Unicode)]
6262
internal static extern SecStatusCode FreeCredentialsHandle([In, Out] SecHandle phCredential);
6363

64+
[DllImport("Secur32.dll", CharSet = CharSet.Unicode)]
65+
internal static extern SecStatusCode AddCredentials(
66+
[In] SecHandle hCredentials,
67+
string pszPrincipal,
68+
string pszPackage,
69+
SecPkgCredFlags fCredentialUse,
70+
SafeBuffer pAuthData,
71+
IntPtr pGetKeyFn,
72+
IntPtr pvGetKeyArgument,
73+
[Out] LargeInteger ptsExpiry
74+
);
75+
6476
[DllImport("Secur32.dll", CharSet = CharSet.Unicode)]
6577
internal static extern SecStatusCode InitializeSecurityContext(
6678
[In] SecHandle phCredential,

0 commit comments

Comments
 (0)