private static void BindingSetAuthInfo(RpcProtectionLevel level, RpcAuthentication[] authTypes, RpcHandle handle, string serverPrincipalName, NetworkCredential credentails) { if (credentails == null) { foreach (RpcAuthentication atype in authTypes) { RpcError result = RpcBindingSetAuthInfo2(handle.Handle, serverPrincipalName, level, atype, IntPtr.Zero, 0); if (result != RpcError.RPC_S_OK) { Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message); } } } else { SEC_WINNT_AUTH_IDENTITY pSecInfo = new SEC_WINNT_AUTH_IDENTITY(credentails); foreach (RpcAuthentication atype in authTypes) { RpcError result = RpcBindingSetAuthInfo(handle.Handle, serverPrincipalName, level, atype, ref pSecInfo, 0); if (result != RpcError.RPC_S_OK) { Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message); } } } }
/// <summary> /// Adds authentication information to the client, use the static Self to /// authenticate as the currently logged on Windows user. /// </summary> public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials) { RpcAuthentication[] types = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_GSS_NEGOTIATE, RpcAuthentication.RPC_C_AUTHN_WINNT }; RpcProtectionLevel protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY; bool isAnon = (credentials != null && credentials.UserName == Anonymous.UserName && credentials.Domain == Anonymous.Domain); if (isAnon) { protect = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_DEFAULT; types = new RpcAuthentication[] { RpcAuthentication.RPC_C_AUTHN_NONE }; } AuthenticateAs(serverPrincipalName, credentials, protect, types); }
public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials) { RpcAuthentication[] rpcAuthenticationArray = new RpcAuthentication[2] { RpcAuthentication.RPC_C_AUTHN_GSS_NEGOTIATE, RpcAuthentication.RPC_C_AUTHN_WINNT }; RpcProtectionLevel level = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY; if (credentials != null && credentials.UserName == RpcClientApi.Anonymous.UserName && credentials.Domain == RpcClientApi.Anonymous.Domain) { level = RpcProtectionLevel.RPC_C_PROTECT_LEVEL_DEFAULT; rpcAuthenticationArray = new RpcAuthentication[1]; credentials = (NetworkCredential)null; } this.AuthenticateAs(serverPrincipalName, credentials, level, rpcAuthenticationArray); }
private static void BindingSetAuthInfo(RpcProtectionLevel level, RpcAuthentication[] authTypes, RpcHandle handle, string serverPrincipalName, NetworkCredential credentails) { if (credentails == null) { foreach (RpcAuthentication AuthnSvc in authTypes) { int num = (int)RpcClientApi.RpcBindingSetAuthInfo2(handle.Handle, serverPrincipalName, level, AuthnSvc, IntPtr.Zero, 0U); } } else { SEC_WINNT_AUTH_IDENTITY AuthIdentity = new SEC_WINNT_AUTH_IDENTITY(credentails); foreach (RpcAuthentication AuthnSvc in authTypes) { int num = (int)RpcClientApi.RpcBindingSetAuthInfo(handle.Handle, serverPrincipalName, level, AuthnSvc, ref AuthIdentity, 0U); } } }
private static extern RpcError RpcBindingSetAuthInfo2(IntPtr Binding, String ServerPrincName, RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc, IntPtr p, uint AuthzSvc);
private static extern RpcError RpcBindingSetAuthInfo(IntPtr Binding, String ServerPrincName, RpcProtectionLevel AuthnLevel, RpcAuthentication AuthnSvc, [In] ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, uint AuthzSvc);
/// <summary> /// Adds authentication information to the client, use the static Self to /// authenticate as the currently logged on Windows user. This overload allows /// you to specify the privacy level and authentication types to try. Normally /// these default to RPC_C_PROTECT_LEVEL_PKT_PRIVACY, and both RPC_C_AUTHN_GSS_NEGOTIATE /// or RPC_C_AUTHN_WINNT if that fails. If credentials is null, or is the Anonymous /// user, RPC_C_PROTECT_LEVEL_DEFAULT and RPC_C_AUTHN_NONE are used instead. /// </summary> public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials, RpcProtectionLevel level, params RpcAuthentication[] authTypes) { if (!_authenticated) { BindingSetAuthInfo(level, authTypes, _handle, serverPrincipalName, credentials); _authenticated = true; } }
private static void BindingSetAuthInfo(RpcProtectionLevel level, RpcAuthentication[] authTypes, RpcHandle handle, string serverPrincipalName, NetworkCredential credentails) { if (credentails == null) { foreach (RpcAuthentication atype in authTypes) { RpcError result = RpcBindingSetAuthInfo2(handle.Handle, serverPrincipalName, level, atype, IntPtr.Zero, 0); if (result != RpcError.RPC_S_OK) Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message); } } else { SEC_WINNT_AUTH_IDENTITY pSecInfo = new SEC_WINNT_AUTH_IDENTITY(credentails); foreach (RpcAuthentication atype in authTypes) { RpcError result = RpcBindingSetAuthInfo(handle.Handle, serverPrincipalName, level, atype, ref pSecInfo, 0); if (result != RpcError.RPC_S_OK) Log.Warning("Unable to register {0}, result = {1}", atype, new RpcException(result).Message); } } }
public void AuthenticateAs(string serverPrincipalName, NetworkCredential credentials, RpcProtectionLevel level, params RpcAuthentication[] authTypes) { if (this._authenticated) { return; } RpcClientApi.BindingSetAuthInfo(level, authTypes, this._handle, serverPrincipalName, credentials); this._authenticated = true; }