/// <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;
        }
Beispiel #2
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
     );