recurively import OU, Sub-OU and servers

This commit is contained in:
Sean Kaim
2016-11-08 17:31:50 -05:00
parent 11256e6988
commit c5f199bdf8
3 changed files with 13 additions and 5 deletions

View File

@@ -92,8 +92,7 @@ namespace mRemoteNG.App
{
try
{
var importer = new ActiveDirectoryImporter();
importer.Import(ldapPath, importDestinationContainer);
ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer);
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)

View File

@@ -16,7 +16,7 @@ namespace mRemoteNG.Config.Import
Import(ldapPathAsString, destinationContainer);
}
public void Import(string ldapPath, ContainerInfo destinationContainer)
public static void Import(string ldapPath, ContainerInfo destinationContainer)
{
try
{

View File

@@ -2,6 +2,7 @@
using System.DirectoryServices;
using System.Text.RegularExpressions;
using mRemoteNG.App;
using mRemoteNG.Config.Import;
using mRemoteNG.Connection;
using mRemoteNG.Container;
using mRemoteNG.Tree;
@@ -45,19 +46,27 @@ namespace mRemoteNG.Config.Serializers
{
try
{
const string ldapFilter = "(objectClass=computer)";
const string ldapFilter = "(|(objectClass=computer)(objectClass=organizationalUnit))";
using (var ldapSearcher = new DirectorySearcher())
{
ldapSearcher.SearchRoot = new DirectoryEntry(ldapPath);
ldapSearcher.Filter = ldapFilter;
ldapSearcher.SearchScope = SearchScope.OneLevel;
ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn" });
ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn", "objectClass" });
var ldapResults = ldapSearcher.FindAll();
foreach (SearchResult ldapResult in ldapResults)
{
using (var directoryEntry = ldapResult.GetDirectoryEntry())
{
if (directoryEntry.Properties["objectClass"].Contains("organizationalUnit"))
{
ActiveDirectoryImporter.Import(ldapResult.Path, parentContainer);
continue;
}
DeserializeConnection(directoryEntry, parentContainer);
}
}
}
}