internal override Native.LdapResultType ldap_result(SafeHandle ld, int msgid, int all, LDAP_TIMEVAL timeout, ref IntPtr pMessage) => NativeMethodsLinux.ldap_result(ld, msgid, all, timeout, ref pMessage);
internal override async Task <IntPtr> BindSaslAsync(SafeHandle ld, Native.LdapAuthType authType, LdapCredential ldapCredential, LDAP_TIMEVAL timeout) { var task = Task.Factory.StartNew(() => { int rc; var msgid = 0; var result = IntPtr.Zero; var rmech = IntPtr.Zero; var mech = Native.LdapAuthMechanism.FromAuthType(authType); var cred = ToNative(ld, mech, ldapCredential); var saslDefaults = Marshal.PtrToStructure <Native.LdapSaslDefaults>(cred); do { rc = NativeMethodsLinux.ldap_sasl_interactive_bind(ld, null, mech, IntPtr.Zero, IntPtr.Zero, (uint)Native.LdapInteractionFlags.LDAP_SASL_QUIET, UnixSaslMethods.SaslInteractionProcedure, cred, result, ref rmech, ref msgid); if (rc != (int)Native.ResultCode.SaslBindInProgress) { break; } ldap_msgfree(result); if (ldap_result(ld, msgid, 0, timeout, ref result) == Native.LdapResultType.LDAP_ERROR) { ThrowIfError(rc, nameof(NativeMethodsLinux.ldap_sasl_interactive_bind)); } if (result == IntPtr.Zero) { throw new LdapException(new LdapExceptionData("Result is not initialized", nameof(NativeMethodsLinux.ldap_sasl_interactive_bind), 1)); } } while (rc == (int)Native.ResultCode.SaslBindInProgress); Marshal.FreeHGlobal(cred); ThrowIfError(ld, rc, nameof(NativeMethodsLinux.ldap_sasl_interactive_bind), new Dictionary <string, string> { [nameof(saslDefaults)] = saslDefaults.ToString() }); return(result); }); return(await task.ConfigureAwait(false)); }
internal override async Task <IntPtr> BindSimpleAsync(SafeHandle ld, string userDn, string password, LDAP_TIMEVAL timeout) { return(await Task.Factory.StartNew(() => { var berval = new Native.berval { bv_len = password.Length, bv_val = Encoder.Instance.StringToPtr(password) }; var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(berval)); Marshal.StructureToPtr(berval, ptr, false); var msgidp = 0; var result = IntPtr.Zero; NativeMethodsLinux.ldap_sasl_bind(ld, userDn, null, ptr, IntPtr.Zero, IntPtr.Zero, ref msgidp); Marshal.FreeHGlobal(ptr); if (msgidp == -1) { throw new LdapException( new LdapExceptionData($"{nameof(BindSimpleAsync)} failed. {nameof(NativeMethodsLinux.ldap_sasl_bind)} returns wrong or empty result", nameof(NativeMethodsLinux.ldap_sasl_bind), 1)); } var rc = ldap_result(ld, msgidp, 0, timeout, ref result); if (rc == Native.LdapResultType.LDAP_ERROR || rc == Native.LdapResultType.LDAP_TIMEOUT) { ThrowIfError((int)rc, nameof(NativeMethodsLinux.ldap_sasl_bind)); } return result; }).ConfigureAwait(false)); }
internal abstract Task <IntPtr> BindSimpleAsync(SafeHandle ld, string who, string password, LDAP_TIMEVAL timeout);
internal abstract LdapResultType ldap_result(SafeHandle ld, int msgid, int all, LDAP_TIMEVAL timeout, ref IntPtr pMessage);
internal abstract Task <IntPtr> BindSaslAsync(SafeHandle ld, LdapAuthType authType, LdapCredential ldapCredential, LDAP_TIMEVAL timeout);
internal override async Task <IntPtr> BindSimpleAsync(SafeHandle ld, string who, string password, LDAP_TIMEVAL timeout) { return(await Task.Factory.StartNew(() => { var result = IntPtr.Zero; var msgidp = NativeMethodsWindows.ldap_bind(ld, who, password, BindMethod.LDAP_AUTH_SIMPLE); if (msgidp == -1) { throw new LdapException( new LdapExceptionData($"{nameof(BindSimpleAsync)} failed. {nameof(NativeMethodsWindows.ldap_bind)} returns wrong or empty result", nameof(NativeMethodsWindows.ldap_bind), 1)); } var rc = ldap_result(ld, msgidp, 0, timeout, ref result); if (rc == Native.LdapResultType.LDAP_ERROR || rc == Native.LdapResultType.LDAP_TIMEOUT) { ThrowIfError((int)rc, nameof(NativeMethodsWindows.ldap_bind)); } return result; }).ConfigureAwait(false)); }
internal override async Task <IntPtr> BindSaslAsync(SafeHandle ld, Native.LdapAuthType authType, LdapCredential ldapCredential, LDAP_TIMEVAL timeout) { var cred = ToNative(ldapCredential); var task = Task.Factory.StartNew(() => { ThrowIfError( NativeMethodsWindows.ldap_bind_s(ld, null, cred, Native.LdapAuthMechanism.ToBindMethod(authType)), nameof(NativeMethodsWindows.ldap_bind_s)); return(IntPtr.Zero); }); return(await task.ConfigureAwait(false)); }
internal static extern int ldap_connect(SafeHandle ld, LDAP_TIMEVAL timeout);
internal static extern Native.LdapResultType ldap_result(SafeHandle ld, int msgid, int all, LDAP_TIMEVAL timeout, ref IntPtr pMessage);