Example #1
0
        internal override async Task <IntPtr> BindSimpleAsync(SafeHandle ld, string who, string password)
        {
            LdapConnect(ld);
            return(await Task.Factory.StartNew(() =>
            {
                var berval = new Native.berval
                {
                    bv_len = password.Length,
                    bv_val = Marshal.StringToHGlobalAnsi(password)
                };
                var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(berval));
                Marshal.StructureToPtr(berval, ptr, false);
                var result = IntPtr.Zero;
                var msgidp = NativeMethodsWindows.ldap_simple_bind(ld, who, password);

                if (msgidp == -1)
                {
                    throw new LdapException($"{nameof(BindSimpleAsync)} failed. {nameof(NativeMethodsWindows.ldap_simple_bind)} returns wrong or empty result", nameof(NativeMethodsWindows.ldap_simple_bind), 1);
                }

                var rc = ldap_result(ld, msgidp, 0, IntPtr.Zero, ref result);

                if (rc == Native.LdapResultType.LDAP_ERROR || rc == Native.LdapResultType.LDAP_TIMEOUT)
                {
                    ThrowIfError((int)rc, nameof(NativeMethodsWindows.ldap_simple_bind));
                }

                return result;
            }).ConfigureAwait(false));
        }
Example #2
0
 internal override int ldap_rename(SafeHandle ld, string dn, string newrdn, string newparent, int deleteoldrdn, IntPtr serverctrls,
                                   IntPtr clientctrls, ref int msgidp)
 {
     return(NativeMethodsWindows.ldap_rename(ld, dn,
                                             newrdn, newparent, deleteoldrdn,
                                             serverctrls, clientctrls, ref msgidp));
 }
Example #3
0
        internal override int BindSasl(SafeHandle ld, Native.LdapAuthType authType, LdapCredential ldapCredential)
        {
            LdapConnect(ld);
            var cred = ToNative(ldapCredential);

            return(NativeMethodsWindows.ldap_bind_s(ld, null, cred, Native.LdapAuthMechanism.ToBindMethod(authType)));
        }
Example #4
0
        internal override int ldap_start_tls_s(SafeHandle ld, ref int serverReturnValue, ref IntPtr message,
                                               IntPtr serverctrls, IntPtr clientctrls)
        {
            var rc = NativeMethodsWindows.ldap_start_tls_s(ld, serverReturnValue, message, serverctrls, clientctrls);

            _tlsStarted = rc == (int)Native.ResultCode.Success;
            return(rc);
        }
Example #5
0
        private void LdapConnect(SafeHandle ld)
        {
            var timeout = new LDAP_TIMEVAL
            {
                tv_sec = (int)(TimeSpan.FromMinutes(10).Ticks / TimeSpan.TicksPerSecond)
            };

            ThrowIfError(NativeMethodsWindows.ldap_connect(ld, timeout), nameof(NativeMethodsWindows.ldap_connect));
        }
Example #6
0
        internal override void LdapConnect(SafeHandle ld, TimeSpan connectionTimeout)
        {
            var timeout = new LDAP_TIMEVAL
            {
                tv_sec = (int)(connectionTimeout.Ticks / TimeSpan.TicksPerSecond)
            };

            ThrowIfError(NativeMethodsWindows.ldap_connect(ld, timeout), nameof(NativeMethodsWindows.ldap_connect));
        }
Example #7
0
 internal override int Init(ref IntPtr ld, string hostname, int port)
 {
     ld = NativeMethodsWindows.ldap_init(hostname, port);
     if (ld == IntPtr.Zero)
     {
         return(-1);
     }
     return((int)Native.ResultCode.Success);
 }
Example #8
0
        internal override int ldap_get_option(SafeHandle ld, int option, ref string value)
        {
            IntPtr outValue = default;
            var    rc       = NativeMethodsWindows.ldap_get_option(ld, option, ref outValue);

            if (rc == (int)Native.ResultCode.Success && outValue != IntPtr.Zero)
            {
                value = Encoder.Instance.PtrToString(outValue);
            }
            return(rc);
        }
Example #9
0
        internal override int BindKerberos(SafeHandle ld)
        {
            LdapConnect(ld);
            var cred = new SEC_WINNT_AUTH_IDENTITY_EX
            {
                version = NativeMethodsWindows.SEC_WINNT_AUTH_IDENTITY_VERSION,
                length  = Marshal.SizeOf(typeof(SEC_WINNT_AUTH_IDENTITY_EX)),
                flags   = NativeMethodsWindows.SEC_WINNT_AUTH_IDENTITY_UNICODE
            };

            return(NativeMethodsWindows.ldap_bind_s(ld, null, cred, BindMethod.LDAP_AUTH_NEGOTIATE));
        }
Example #10
0
        internal override async Task <IntPtr> BindSaslAsync(SafeHandle ld, Native.LdapAuthType authType, LdapCredential ldapCredential)
        {
            LdapConnect(ld);
            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));
        }
Example #11
0
        internal override async Task <IntPtr> BindKerberosAsync(SafeHandle ld)
        {
            LdapConnect(ld);
            var cred = new SEC_WINNT_AUTH_IDENTITY_EX
            {
                version = NativeMethodsWindows.SEC_WINNT_AUTH_IDENTITY_VERSION,
                length  = Marshal.SizeOf(typeof(SEC_WINNT_AUTH_IDENTITY_EX)),
                flags   = NativeMethodsWindows.SEC_WINNT_AUTH_IDENTITY_UNICODE
            };

            var task = Task.Factory.StartNew(() =>
            {
                ThrowIfError(NativeMethodsWindows.ldap_bind_s(ld, null, cred, BindMethod.LDAP_AUTH_NEGOTIATE), nameof(NativeMethodsWindows.ldap_bind_s));

                return(IntPtr.Zero);
            });

            return(await task.ConfigureAwait(false));
        }
Example #12
0
        internal override async Task <IntPtr> BindSimpleAsync(SafeHandle ld, string who, string password)
        {
            LdapConnect(ld);
            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($"{nameof(BindSimpleAsync)} failed. {nameof(NativeMethodsWindows.ldap_bind)} returns wrong or empty result", nameof(NativeMethodsWindows.ldap_bind), 1);
                }

                var rc = ldap_result(ld, msgidp, 0, IntPtr.Zero, ref result);

                if (rc == Native.LdapResultType.LDAP_ERROR || rc == Native.LdapResultType.LDAP_TIMEOUT)
                {
                    ThrowIfError((int)rc, nameof(NativeMethodsWindows.ldap_bind));
                }

                return result;
            }).ConfigureAwait(false));
        }
Example #13
0
 internal override string LdapError2String(int error) => NativeMethodsWindows.LdapError2String(error);
Example #14
0
 internal override string GetAdditionalErrorInfo(SafeHandle ld) => NativeMethodsWindows.GetAdditionalErrorInfo(ld);
Example #15
0
 internal override void ldap_controls_free(IntPtr ctrls) => NativeMethodsWindows.ldap_controls_free(ctrls);
Example #16
0
 internal override int ldap_parse_extended_result(SafeHandle ldapHandle, IntPtr result, ref IntPtr oid, ref IntPtr data, byte freeIt) =>
 NativeMethodsWindows.ldap_parse_extended_result(ldapHandle, result, ref oid, ref data, freeIt);
Example #17
0
 internal override int ldap_extended_operation(SafeHandle ld, string requestoid, IntPtr requestdata, IntPtr serverctrls,
                                               IntPtr clientctrls, ref int msgidp) =>
 NativeMethodsWindows.ldap_extended_operation(ld, requestoid, requestdata, serverctrls, clientctrls, ref msgidp);
Example #18
0
 internal override IntPtr ldap_get_dn(SafeHandle ld, IntPtr message) => NativeMethodsWindows.ldap_get_dn(ld, message);
Example #19
0
 internal override int ldap_delete_ext(SafeHandle ld, string dn, IntPtr serverctrls, IntPtr clientctrls, ref int msgidp) => NativeMethodsWindows.ldap_delete_ext(ld, dn, serverctrls, clientctrls, ref msgidp);
Example #20
0
 internal override IntPtr ldap_get_values(SafeHandle ld, IntPtr entry, IntPtr pBer) => NativeMethodsWindows.ldap_get_values(ld, entry, pBer);
Example #21
0
 internal override void ldap_value_free(IntPtr vals) => NativeMethodsWindows.ldap_value_free(vals);
Example #22
0
 internal override int ldap_parse_reference(SafeHandle ld, IntPtr reference, ref string[] referralsp, ref IntPtr serverctrlsp, int freeit) => NativeMethodsWindows.ldap_parse_reference(ld, reference, ref referralsp, ref serverctrlsp, freeit);
Example #23
0
 internal override void ldap_msgfree(IntPtr message) => NativeMethodsWindows.ldap_msgfree(message);
Example #24
0
 internal override void ldap_memfree(IntPtr ptr) => NativeMethodsWindows.ldap_memfree(ptr);
Example #25
0
 internal override int BindSimple(SafeHandle ld, string who, string password)
 {
     LdapConnect(ld);
     return(NativeMethodsWindows.ldap_simple_bind_s(ld, who, password));
 }
Example #26
0
 internal override int Compare(SafeHandle ld, string dn, string attr, string value, IntPtr bvalue, IntPtr serverctrls,
                               IntPtr clientctrls,
                               ref int msgidp) =>
 NativeMethodsWindows.ldap_compare_ext(ld, dn, attr, value, bvalue, serverctrls, clientctrls, ref msgidp);
Example #27
0
 internal override IntPtr ldap_first_attribute(SafeHandle ld, IntPtr entry, ref IntPtr ppBer) => NativeMethodsWindows.ldap_first_attribute(ld, entry, ref ppBer);
Example #28
0
 internal override IntPtr ldap_next_entry(SafeHandle ld, IntPtr message) => NativeMethodsWindows.ldap_next_entry(ld, message);
Example #29
0
 internal override int ldap_set_option(SafeHandle ld, int option, ref int invalue)
 => NativeMethodsWindows.ldap_set_option(ld, option, ref invalue);
Example #30
0
 internal override IntPtr ldap_next_attribute(SafeHandle ld, IntPtr entry, IntPtr pBer) => NativeMethodsWindows.ldap_next_attribute(ld, entry, pBer);