DocSpace-buildtools/common/ASC.ActiveDirectory/Novell/NovellLdapSettingsChecker.cs

223 lines
7.1 KiB
C#
Raw Normal View History

2022-05-05 13:23:05 +00:00
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
namespace ASC.ActiveDirectory.Novell;
2022-05-05 13:23:05 +00:00
2022-03-17 19:44:34 +00:00
[Scope]
public class NovellLdapSettingsChecker : LdapSettingsChecker
{
public LdapCertificateConfirmRequest CertificateConfirmRequest { get; set; }
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
public LdapHelper LdapHelper
{
get { return LdapImporter.LdapHelper; }
}
2022-03-08 05:37:20 +00:00
2022-06-08 09:42:49 +00:00
public NovellLdapSettingsChecker(ILogger<LdapSettingsChecker> logger) :
base(logger)
2022-03-17 19:44:34 +00:00
{
}
2022-03-08 05:37:20 +00:00
2022-05-18 10:54:13 +00:00
public new void Init(LdapUserImporter importer)
2022-03-17 19:44:34 +00:00
{
base.Init(importer);
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
public override LdapSettingsStatus CheckSettings()
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
if (!Settings.EnableLdapAuthentication)
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.Ok;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (Settings.Server.Equals("LDAP://", StringComparison.InvariantCultureIgnoreCase))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongServerOrPort;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (!LdapHelper.IsConnected)
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
try
{
LdapHelper.Connect();
}
catch (NovellLdapTlsCertificateRequestedException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorNovellLdapTlsCertificateRequestedException(Settings.AcceptCertificate, ex);
2022-03-17 19:44:34 +00:00
CertificateConfirmRequest = ex.CertificateConfirmRequest;
return LdapSettingsStatus.CertificateRequest;
}
catch (NotSupportedException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorNotSupportedException(ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.TlsNotSupported;
}
catch (SocketException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorSocketException(ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.ConnectError;
}
catch (ArgumentException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorArgumentException( ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongServerOrPort;
}
catch (SecurityException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorSecurityException(ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.StrongAuthRequired;
}
catch (SystemException ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorSystemException(ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongServerOrPort;
}
catch (Exception ex)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorCheckSettingsException(ex);
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.CredentialsNotValid;
}
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
if (!CheckUserDn(Settings.UserDN))
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongUserDn;
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
if (Settings.GroupMembership)
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
if (!CheckGroupDn(Settings.GroupDN))
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongGroupDn;
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
try
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
new RfcFilter(Settings.GroupFilter);
}
catch
{
return LdapSettingsStatus.IncorrectGroupLDAPFilter;
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
if (!LdapImporter.TryLoadLDAPGroups())
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
if (!LdapImporter.AllSkipedDomainGroups.Any())
2022-06-15 12:39:37 +00:00
{
2022-03-08 05:37:20 +00:00
return LdapSettingsStatus.IncorrectGroupLDAPFilter;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainGroups.All(kv => kv.Value == LdapSettingsStatus.WrongSidAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongSidAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainGroups.All(kv => kv.Value == LdapSettingsStatus.WrongGroupAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongGroupAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainGroups.All(kv => kv.Value == LdapSettingsStatus.WrongGroupNameAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongGroupNameAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-17 19:44:34 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (!LdapImporter.AllDomainGroups.Any())
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.GroupsNotFound;
2022-06-15 12:39:37 +00:00
}
2022-03-17 19:44:34 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
try
{
new RfcFilter(Settings.UserFilter);
}
catch
{
return LdapSettingsStatus.IncorrectLDAPFilter;
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (!LdapImporter.TryLoadLDAPUsers())
{
if (!LdapImporter.AllSkipedDomainUsers.Any())
2022-06-15 12:39:37 +00:00
{
2022-03-08 05:37:20 +00:00
return LdapSettingsStatus.IncorrectLDAPFilter;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainUsers.All(kv => kv.Value == LdapSettingsStatus.WrongSidAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongSidAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainUsers.All(kv => kv.Value == LdapSettingsStatus.WrongLoginAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongLoginAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (LdapImporter.AllSkipedDomainUsers.All(kv => kv.Value == LdapSettingsStatus.WrongUserAttribute))
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.WrongUserAttribute;
2022-06-15 12:39:37 +00:00
}
2022-03-17 19:44:34 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
if (!LdapImporter.AllDomainUsers.Any())
2022-06-15 12:39:37 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapSettingsStatus.UsersNotFound;
2022-06-15 12:39:37 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
return string.IsNullOrEmpty(LdapImporter.LDAPDomain)
? LdapSettingsStatus.DomainNotFound
: LdapSettingsStatus.Ok;
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
private bool CheckUserDn(string userDn)
{
try
{
return LdapHelper.CheckUserDn(userDn);
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
catch (Exception e)
2022-03-08 05:37:20 +00:00
{
2022-06-15 12:39:37 +00:00
_logger.ErrorWrongUserDn(userDn, e);
2022-03-17 19:44:34 +00:00
return false;
2022-03-08 05:37:20 +00:00
}
2022-03-17 19:44:34 +00:00
}
2022-03-08 05:37:20 +00:00
2022-03-17 19:44:34 +00:00
private bool CheckGroupDn(string groupDn)
{
try
2022-03-08 05:37:20 +00:00
{
2022-03-17 19:44:34 +00:00
return LdapHelper.CheckGroupDn(groupDn);
}
catch (Exception e)
{
2022-06-15 12:39:37 +00:00
_logger.ErrorWrongGroupDn(groupDn, e);
2022-03-17 19:44:34 +00:00
return false;
2022-03-08 05:37:20 +00:00
}
}
}