static extern int AcquireCredentialsHandle( string pszPrincipal, //SEC_CHAR* string pszPackage, //SEC_CHAR* //"Kerberos","NTLM","Negotiative" int fCredentialUse, IntPtr PAuthenticationID, //_LUID AuthenticationID,//pvLogonID, //PLUID ref SEC_WINNT_AUTH_IDENTITY pAuthData, //PVOID int pGetKeyFn, //SEC_GET_KEY_FN IntPtr pvGetKeyArgument, //PVOID ref SECURITY_HANDLE phCredential, //SecHandle //PCtxtHandle ref ref SECURITY_INTEGER ptsExpiry); //PTimeStamp //TimeStamp ref
public void LoginClient(NetworkCredential login) { int ss = -1; SECURITY_INTEGER ClientLifeTime = new SECURITY_INTEGER(0); SEC_WINNT_AUTH_IDENTITY auth = new SEC_WINNT_AUTH_IDENTITY(); auth.Domain = login.Domain; auth.DomainLength = login.Domain.Length; auth.User = login.UserName; auth.UserLength = login.UserName.Length; auth.Password = login.Password; auth.PasswordLength = login.Password.Length; auth.Flags = 2; // unicode ss = AcquireCredentialsHandle(_szTarget, SecurityPackage, SECPKG_CRED_OUTBOUND, IntPtr.Zero, ref auth, 0, IntPtr.Zero, ref _hCred, ref ClientLifeTime); if (ss != SEC_E_OK) { throw new Exception("Couldn't acquire client credentials", new Win32Exception(ss)); } _bGotCredentials = true; }
internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc);
internal static extern Int32 RpcBindingSetAuthInfoEx(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc, ref RPC_SECURITY_QOS SecurityQOS);