internal static NtStatus SamConnectWithCreds(string serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, SafeRpcAuthIdentityHandle authIdentity) { uint unknown = 0; IntPtr objectAttributes = IntPtr.Zero; UnicodeString unicodeServerName = new UnicodeString(serverName); string servicePrincipalName = spnPrefix + serverName; NtStatus result = SamConnectWithCreds(ref unicodeServerName, out serverHandle, accessMask, objectAttributes, authIdentity, servicePrincipalName, out unknown); if (result == NtStatus.RpcUnknownAuthenticationService) { // Try it again, but without the SPN servicePrincipalName = null; return(SamConnectWithCreds(ref unicodeServerName, out serverHandle, accessMask, objectAttributes, authIdentity, servicePrincipalName, out unknown)); } else { return(result); } }
private static extern NtStatus SamConnectWithCreds([In] ref UnicodeString serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, IntPtr objectAttributes, SafeRpcAuthIdentityHandle authIdentity, [MarshalAs(UnmanagedType.LPWStr)] string servicePrincipalName, out uint unknown);
internal static Win32ErrorCode DsMakePasswordCredentials(string user, string domain, SecureString password, out SafeRpcAuthIdentityHandle authIdentity) { using (var passwordPointer = new SafeUnicodeSecureStringPointer(password)) { return(DsMakePasswordCredentials(user, domain, passwordPointer, out authIdentity)); } }
internal static Win32ErrorCode DsMakePasswordCredentials(NetworkCredential credential, out SafeRpcAuthIdentityHandle authIdentity) { return(DsMakePasswordCredentials(credential.UserName, credential.Domain, credential.SecurePassword, out authIdentity)); }
private static extern Win32ErrorCode DsMakePasswordCredentials(string user, string domain, SafeUnicodeSecureStringPointer password, out SafeRpcAuthIdentityHandle authIdentity);