/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="principal">User principal.</param>
        /// <param name="package">The package name.</param>
        /// <param name="auth_id">Optional authentication ID for the user.</param>
        /// <param name="cred_use_flag">Credential user flags.</param>
        /// <param name="auth_data">Optional authentication data.</param>
        public CredentialHandle(string principal, string package, Luid?auth_id,
                                SecPkgCredFlags cred_use_flag, SafeBuffer auth_data)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            OptionalLuid luid = null;

            if (auth_id.HasValue)
            {
                luid = new OptionalLuid()
                {
                    luid = auth_id.Value
                };
            }
            SecHandle    cred_handle = new SecHandle();
            LargeInteger expiry      = new LargeInteger();

            SecurityNativeMethods.AcquireCredentialsHandle(principal, package, cred_use_flag,
                                                           luid, auth_data ?? SafeHGlobalBuffer.Null,
                                                           IntPtr.Zero, IntPtr.Zero, cred_handle, expiry)
            .CheckResult();
            CredHandle  = cred_handle;
            PackageName = package;
            Expiry      = expiry.QuadPart;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new credential handle.
 /// </summary>
 /// <param name="principal">User principal.</param>
 /// <param name="package">The package name.</param>
 /// <param name="auth_id">Optional authentication ID for the user.</param>
 /// <param name="cred_use_flag">Credential user flags.</param>
 /// <param name="credentials">Optional credentials.</param>
 /// <returns>The credential handle.</returns>
 public static CredentialHandle Create(string principal, string package, Luid?auth_id,
                                       SecPkgCredFlags cred_use_flag, AuthenticationCredentials credentials)
 {
     using (var list = new DisposableList()) {
         var buffer = credentials?.ToBuffer(list, package);
         return(new CredentialHandle(principal, package, auth_id, cred_use_flag, buffer));
     }
 }
Exemplo n.º 3
0
 internal static extern SecStatusCode AcquireCredentialsHandle(
     string pszPrincipal,
     string pszPackage,
     SecPkgCredFlags fCredentialUse,
     OptionalLuid pvLogonId,
     SafeBuffer pAuthData,
     IntPtr pGetKeyFn,
     IntPtr pvGetKeyArgument,
     [Out] SecHandle phCredential,
     [Out] LargeInteger ptsExpiry
     );
 /// <summary>
 /// Create a new credential handle.
 /// </summary>
 /// <param name="package">The package name.</param>
 /// <param name="cred_use_flag">Credential user flags.</param>
 /// <returns>The credential handle.</returns>
 public static CredentialHandle Create(string package,
                                       SecPkgCredFlags cred_use_flag)
 {
     return(Create(package, cred_use_flag, null));
 }
 /// <summary>
 /// Create a new credential handle.
 /// </summary>
 /// <param name="package">The package name.</param>
 /// <param name="cred_use_flag">Credential user flags.</param>
 /// <param name="credentials">Optional credentials.</param>
 /// <returns>The credential handle.</returns>
 public static CredentialHandle Create(string package,
                                       SecPkgCredFlags cred_use_flag, AuthenticationCredentials credentials)
 {
     return(Create(null, package, null, cred_use_flag, credentials));
 }