public override byte CheckSettings(LDAPUserImporter importer, bool acceptCertificate = false)
        {
            var settings = importer.Settings;

            // call static constructor of MonitorEventRequest class
            MonitorEventRequest.RegisterResponseTypes = true;

            _novellLdapHelper.AcceptCertificate = acceptCertificate;

            if (!settings.EnableLdapAuthentication)
            {
                return(OPERATION_OK);
            }

            var password = GetPassword(settings.PasswordBytes);

            if (settings.Server.Equals("LDAP://", StringComparison.InvariantCultureIgnoreCase))
            {
                return(WRONG_SERVER_OR_PORT);
            }

            try
            {
                if (settings.Authentication)
                {
                    CheckCredentials(settings.Login, password, settings.Server, settings.PortNumber, settings.StartTls);
                }
            }
            catch (NovellLdapTlsCertificateRequestedException ex)
            {
                CertificateConfirmRequest = ex.CertificateConfirmRequest;
                return(CERTIFICATE_REQUEST);
            }
            catch (NotSupportedException)
            {
                return(TLS_NOT_SUPPORTED);
            }
            catch (InvalidOperationException)
            {
                return(CONNECT_ERROR);
            }
            catch (ArgumentException)
            {
                return(WRONG_SERVER_OR_PORT);
            }
            catch (SecurityException)
            {
                return(STRONG_AUTH_REQUIRED);
            }
            catch (SystemException)
            {
                return(WRONG_SERVER_OR_PORT);
            }
            catch (Exception)
            {
                return(CREDENTIALS_NOT_VALID);
            }

            if (!CheckUserDN(settings.UserDN, settings.Server, settings.PortNumber,
                             settings.Authentication, settings.Login, password, settings.StartTls))
            {
                return(WRONG_USER_DN);
            }

            if (settings.GroupMembership)
            {
                if (!CheckGroupDN(settings.GroupDN, settings.Server, settings.PortNumber,
                                  settings.Authentication, settings.Login, password, settings.StartTls))
                {
                    return(WRONG_GROUP_DN);
                }

                if (!importer.TryLoadLDAPGroups())
                {
                    return(INCORRECT_GROUP_LDAP_FILTER);
                }

                if (!importer.AllDomainGroups.Any())
                {
                    return(GROUPS_NOT_FOUND);
                }

                foreach (var group in importer.AllDomainGroups)
                {
                    if (!CheckGroupAttribute(group, settings.GroupAttribute))
                    {
                        return(WRONG_GROUP_ATTRIBUTE);
                    }

                    if (!CheckGroupNameAttribute(group, settings.GroupNameAttribute))
                    {
                        return(WRONG_GROUP_NAME_ATTRIBUTE);
                    }

                    if (group.Sid == null)
                    {
                        return(WRONG_SID_ATTRIBUTE);
                    }
                }
            }

            if (!importer.TryLoadLDAPDomain())
            {
                return(DOMAIN_NOT_FOUND);
            }

            if (!importer.TryLoadLDAPUsers())
            {
                return(INCORRECT_LDAP_FILTER);
            }

            if (!importer.AllDomainUsers.Any())
            {
                return(USERS_NOT_FOUND);
            }

            foreach (var user in importer.AllDomainUsers)
            {
                if (!CheckLoginAttribute(user, settings.LoginAttribute))
                {
                    return(WRONG_LOGIN_ATTRIBUTE);
                }

                if (user.Sid == null)
                {
                    return(WRONG_SID_ATTRIBUTE);
                }

                if (settings.GroupMembership && !CheckUserAttribute(user, settings.UserAttribute))
                {
                    return(WRONG_USER_ATTRIBUTE);
                }
            }

            return(OPERATION_OK);
        }
Ejemplo n.º 2
0
        public override byte CheckSettings(LDAPUserImporter importer,
                                           bool acceptCertificate = false)
        {
            var settings = importer.Settings;

            if (!settings.EnableLdapAuthentication)
            {
                return(OPERATION_OK);
            }

            var password = GetPassword(settings.PasswordBytes);

            try
            {
                if (settings.Authentication)
                {
                    CheckCredentials(settings.Login, password, settings.Server, settings.PortNumber, settings.StartTls);
                }
                if (!CheckServerAndPort(settings.Server,
                                        settings.PortNumber, settings.Authentication, settings.Login, password))
                {
                    return(WRONG_SERVER_OR_PORT);
                }
            }
            catch (DirectoryServicesCOMException)
            {
                return(CREDENTIALS_NOT_VALID);
            }
            catch (COMException)
            {
                return(WRONG_SERVER_OR_PORT);
            }

            if (!CheckUserDN(settings.UserDN, settings.Server, settings.PortNumber,
                             settings.Authentication, settings.Login, password, settings.StartTls))
            {
                return(WRONG_USER_DN);
            }

            if (settings.GroupMembership)
            {
                if (!CheckGroupDN(settings.UserDN, settings.Server, settings.PortNumber,
                                  settings.Authentication, settings.Login, password, settings.StartTls))
                {
                    return(WRONG_USER_DN);
                }

                if (!importer.TryLoadLDAPGroups())
                {
                    return(INCORRECT_GROUP_LDAP_FILTER);
                }

                if (!importer.AllDomainGroups.Any())
                {
                    return(GROUPS_NOT_FOUND);
                }

                foreach (var group in importer.AllDomainGroups)
                {
                    if (!CheckGroupAttribute(group, settings.GroupAttribute))
                    {
                        return(WRONG_GROUP_ATTRIBUTE);
                    }

                    if (!CheckGroupNameAttribute(group, settings.GroupNameAttribute))
                    {
                        return(WRONG_GROUP_NAME_ATTRIBUTE);
                    }

                    if (group.Sid == null)
                    {
                        return(WRONG_SID_ATTRIBUTE);
                    }
                }
            }

            if (!importer.TryLoadLDAPDomain())
            {
                return(DOMAIN_NOT_FOUND);
            }

            if (!importer.TryLoadLDAPUsers())
            {
                return(INCORRECT_LDAP_FILTER);
            }

            if (!importer.AllDomainUsers.Any())
            {
                return(USERS_NOT_FOUND);
            }

            foreach (var user in importer.AllDomainUsers)
            {
                if (!CheckLoginAttribute(user, settings.LoginAttribute))
                {
                    return(WRONG_LOGIN_ATTRIBUTE);
                }

                if (user.Sid == null)
                {
                    return(WRONG_SID_ATTRIBUTE);
                }

                if (settings.GroupMembership && !CheckUserAttribute(user, settings.UserAttribute))
                {
                    return(WRONG_USER_ATTRIBUTE);
                }
            }

            return(OPERATION_OK);
        }