Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        private static SEC_WINNT_AUTH_IDENTITY_EX ToNative(LdapCredential ldapCredential)
        {
            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
            };

            if (ldapCredential != null)
            {
                cred.user           = string.IsNullOrEmpty(ldapCredential.UserName) ? null : ldapCredential.UserName;
                cred.userLength     = ldapCredential.UserName?.Length ?? 0;
                cred.password       = string.IsNullOrEmpty(ldapCredential.Password) ? null : ldapCredential.Password;
                cred.passwordLength = ldapCredential.Password?.Length ?? 0;
                cred.domain         = string.IsNullOrEmpty(ldapCredential.Realm) ? null : ldapCredential.Realm;
                cred.domainLength   = ldapCredential.Realm?.Length ?? 0;
            }

            return(cred);
        }
Exemplo n.º 4
0
 internal static extern int ldap_bind_s(SafeHandle ld, string who, SEC_WINNT_AUTH_IDENTITY_EX credentials,
                                        BindMethod method);