chore: sync LIAM solution snapshot incl. diagnostics tooling
- update multiple LIAM projects and solution/config files - add LiamWorkflowDiagnostics app sources and generated outputs - include current workspace state (dependencies and build outputs)
This commit is contained in:
@@ -1,165 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using C4IT.Logging;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class DataArea
|
||||
{
|
||||
public List<IAM_Folder> IAM_Folders;
|
||||
public string rootUID;
|
||||
public static string GetRelativePath(string childFolder, string rootFolder)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
// Folders must end in a slash
|
||||
if (!childFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
childFolder += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Uri childUri = new Uri(childFolder);
|
||||
|
||||
// Folders must end in a slash
|
||||
if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
rootFolder += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Uri folderUri = new Uri(rootFolder);
|
||||
return Uri.UnescapeDataString(folderUri.MakeRelativeUri(childUri).ToString().Replace('/', Path.DirectorySeparatorChar));
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
public static string GetUniqueDataAreaID(string name)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||||
var utf8 = new System.Text.UTF8Encoding();
|
||||
var hash = BitConverter.ToString(md5.ComputeHash(utf8.GetBytes(name)));
|
||||
hash = hash.ToLower().Replace("-", "");
|
||||
return hash;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DataArea()
|
||||
{
|
||||
IAM_Folders = new List<IAM_Folder>();
|
||||
}
|
||||
public static void AddDirectorySecurity(string baseFolderTechnicalName, string newFolderTechnicalName, SecurityIdentifier Account, FileSystemRights Rights, AccessControlType ControlType)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
// Create a new DirectoryInfo object.
|
||||
DirectoryInfo dInfo = new DirectoryInfo(newFolderTechnicalName);
|
||||
//DirectoryInfo dInfoBaseFolder = new DirectoryInfo(baseFolderTechnicalName);
|
||||
|
||||
// Get a DirectorySecurity object that represents the
|
||||
// current security settings.
|
||||
DirectorySecurity dSecurity = dInfo.GetAccessControl();
|
||||
|
||||
// Add the FileSystemAccessRule to the security settings.
|
||||
|
||||
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
|
||||
Rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
|
||||
AccessControlType.Allow));
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Set ACL for folder: {newFolderTechnicalName} for { Account }");
|
||||
// Set the new access settings.
|
||||
dInfo.SetAccessControl(dSecurity);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
// Removes an ACL entry on the specified directory for the specified account.
|
||||
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Create a new DirectoryInfo object.
|
||||
DirectoryInfo dInfo = new DirectoryInfo(FileName);
|
||||
|
||||
// Get a DirectorySecurity object that represents the
|
||||
// current security settings.
|
||||
DirectorySecurity dSecurity = dInfo.GetAccessControl();
|
||||
|
||||
// Add the FileSystemAccessRule to the security settings.
|
||||
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
|
||||
Rights,
|
||||
ControlType));
|
||||
|
||||
// Set the new access settings.
|
||||
dInfo.SetAccessControl(dSecurity);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IAM_Folder
|
||||
{
|
||||
public string Name = String.Empty;
|
||||
public string technicalName = String.Empty;
|
||||
public string UID = String.Empty;
|
||||
public string Parent = String.Empty;
|
||||
public string ParentUID = String.Empty;
|
||||
public string Owner = String.Empty;
|
||||
public string Write = String.Empty;
|
||||
public string Read = String.Empty;
|
||||
public string Traverse = String.Empty;
|
||||
public string CreatedDate = String.Empty;
|
||||
public int Level = 0;
|
||||
public int targetType;
|
||||
public string configurationID = String.Empty;
|
||||
public string baseFolder = String.Empty;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using C4IT.Logging;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class DataArea
|
||||
{
|
||||
public List<IAM_Folder> IAM_Folders;
|
||||
public string rootUID;
|
||||
public static string GetRelativePath(string childFolder, string rootFolder)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
// Folders must end in a slash
|
||||
if (!childFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
childFolder += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Uri childUri = new Uri(childFolder);
|
||||
|
||||
// Folders must end in a slash
|
||||
if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
rootFolder += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Uri folderUri = new Uri(rootFolder);
|
||||
return Uri.UnescapeDataString(folderUri.MakeRelativeUri(childUri).ToString().Replace('/', Path.DirectorySeparatorChar));
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
public static string GetUniqueDataAreaID(string name)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||||
var utf8 = new System.Text.UTF8Encoding();
|
||||
var hash = BitConverter.ToString(md5.ComputeHash(utf8.GetBytes(name)));
|
||||
hash = hash.ToLower().Replace("-", "");
|
||||
return hash;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DataArea()
|
||||
{
|
||||
IAM_Folders = new List<IAM_Folder>();
|
||||
}
|
||||
public static void AddDirectorySecurity(string baseFolderTechnicalName, string newFolderTechnicalName, SecurityIdentifier Account, FileSystemRights Rights, AccessControlType ControlType)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
// Create a new DirectoryInfo object.
|
||||
DirectoryInfo dInfo = new DirectoryInfo(newFolderTechnicalName);
|
||||
//DirectoryInfo dInfoBaseFolder = new DirectoryInfo(baseFolderTechnicalName);
|
||||
|
||||
// Get a DirectorySecurity object that represents the
|
||||
// current security settings.
|
||||
DirectorySecurity dSecurity = dInfo.GetAccessControl();
|
||||
|
||||
// Add the FileSystemAccessRule to the security settings.
|
||||
|
||||
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
|
||||
Rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
|
||||
AccessControlType.Allow));
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Set ACL for folder: {newFolderTechnicalName} for { Account }");
|
||||
// Set the new access settings.
|
||||
dInfo.SetAccessControl(dSecurity);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
// Removes an ACL entry on the specified directory for the specified account.
|
||||
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Create a new DirectoryInfo object.
|
||||
DirectoryInfo dInfo = new DirectoryInfo(FileName);
|
||||
|
||||
// Get a DirectorySecurity object that represents the
|
||||
// current security settings.
|
||||
DirectorySecurity dSecurity = dInfo.GetAccessControl();
|
||||
|
||||
// Add the FileSystemAccessRule to the security settings.
|
||||
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
|
||||
Rights,
|
||||
ControlType));
|
||||
|
||||
// Set the new access settings.
|
||||
dInfo.SetAccessControl(dSecurity);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IAM_Folder
|
||||
{
|
||||
public string Name = String.Empty;
|
||||
public string technicalName = String.Empty;
|
||||
public string UID = String.Empty;
|
||||
public string Parent = String.Empty;
|
||||
public string ParentUID = String.Empty;
|
||||
public string Owner = String.Empty;
|
||||
public string Write = String.Empty;
|
||||
public string Read = String.Empty;
|
||||
public string Traverse = String.Empty;
|
||||
public string CreatedDate = String.Empty;
|
||||
public int Level = 0;
|
||||
public int targetType;
|
||||
public string configurationID = String.Empty;
|
||||
public string baseFolder = String.Empty;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class DataArea_Enums
|
||||
{
|
||||
|
||||
}
|
||||
public enum IAM_TargetType { FileSystem = 1, Matrix42 = 2, Sharepoint = 3 }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class DataArea_Enums
|
||||
{
|
||||
|
||||
}
|
||||
public enum IAM_TargetType { FileSystem = 1, Matrix42 = 2, Sharepoint = 3 }
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static string ReplaceLoopTag(this string str, int loop)
|
||||
{
|
||||
return Regex.Replace(str, @"(?<loopTag>{{(?<prefix>[^}]*)(?<loop>LOOP)(?<postfix>[^{]*)}})", loop <= 0 ? "" : "${prefix}" + loop + "${postfix}");
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static string ReplaceLoopTag(this string str, int loop)
|
||||
{
|
||||
return Regex.Replace(str, @"(?<loopTag>{{(?<prefix>[^}]*)(?<loop>LOOP)(?<postfix>[^{]*)}})", loop <= 0 ? "" : "${prefix}" + loop + "${postfix}");
|
||||
}
|
||||
public static string ReplaceTags(this string str, IDictionary<string, string> dict)
|
||||
{
|
||||
if (str.Equals(string.Empty) || str == null || dict == null || dict.Count == 0)
|
||||
@@ -61,21 +61,21 @@ namespace C4IT_IAM_Engine
|
||||
try
|
||||
{
|
||||
var PF = Environment.ExpandEnvironmentVariables(FilePath);
|
||||
Directory.CreateDirectory(PF);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
public static string MaskAllButLastAndFirst(this string input, char maskingChar = '*')
|
||||
{
|
||||
if (input.Length > 3)
|
||||
{
|
||||
var pattern = @"^(.{1})(.+)(.{1})$";
|
||||
var match = Regex.Match(input, pattern);
|
||||
var mask = new string(maskingChar, match.Groups[2].Length);
|
||||
return $"{match.Groups[1]}{mask}{match.Groups[3]}";
|
||||
}
|
||||
else
|
||||
return new string(maskingChar, input.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Directory.CreateDirectory(PF);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
public static string MaskAllButLastAndFirst(this string input, char maskingChar = '*')
|
||||
{
|
||||
if (input.Length > 3)
|
||||
{
|
||||
var pattern = @"^(.{1})(.+)(.{1})$";
|
||||
var match = Regex.Match(input, pattern);
|
||||
var mask = new string(maskingChar, match.Groups[2].Length);
|
||||
return $"{match.Groups[1]}{mask}{match.Groups[3]}";
|
||||
}
|
||||
else
|
||||
return new string(maskingChar, input.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class ResultToken
|
||||
{
|
||||
public string resultMessage;
|
||||
public int resultErrorId;
|
||||
public string resultFunction;
|
||||
public ResultToken(string function)
|
||||
{
|
||||
this.resultFunction = function;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class ResultToken
|
||||
{
|
||||
public string resultMessage;
|
||||
public int resultErrorId;
|
||||
public string resultFunction;
|
||||
public ResultToken(string function)
|
||||
{
|
||||
this.resultFunction = function;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +1,139 @@
|
||||
using C4IT_IAM_GET;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
using C4IT.Logging;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class SecurityGroups
|
||||
{
|
||||
public string domainName;
|
||||
public string username;
|
||||
public SecureString password;
|
||||
|
||||
public List<IAM_SecurityGroup> IAM_SecurityGroups;
|
||||
public string rootUID;
|
||||
public SecurityGroups()
|
||||
{
|
||||
IAM_SecurityGroups = new List<IAM_SecurityGroup>();
|
||||
}
|
||||
public bool GroupsAllreadyExisting(string ouPath)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int groupCount = 0;
|
||||
if (IAM_SecurityGroups != null)
|
||||
foreach (var s in IAM_SecurityGroups)
|
||||
{
|
||||
if (s.securityGroupType != SecurityGroupType.Traverse)
|
||||
{
|
||||
DirectoryEntry entry = new DirectoryEntry
|
||||
{
|
||||
Path = "LDAP://" + domainName,
|
||||
Username = username,
|
||||
Password = new NetworkCredential("", password).Password,
|
||||
AuthenticationType = AuthenticationTypes.Secure | AuthenticationTypes.Sealing
|
||||
};
|
||||
DirectorySearcher dSearch = new DirectorySearcher(entry)
|
||||
{
|
||||
Filter = "(&(CN=" + s.Name.ToUpper() + ")(objectClass=group))"
|
||||
};
|
||||
dSearch.PageSize = 100000;
|
||||
SearchResultCollection sr = dSearch.FindAll();
|
||||
groupCount += sr.Count;
|
||||
}
|
||||
}
|
||||
return groupCount > 0;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public bool GroupAllreadyExisting(string CN)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int groupCount = 0;
|
||||
if (CN != string.Empty)
|
||||
{
|
||||
DirectoryEntry entry = new DirectoryEntry
|
||||
{
|
||||
Path = "LDAP://" + domainName,
|
||||
Username = username,
|
||||
Password = new NetworkCredential("", password).Password,
|
||||
AuthenticationType = AuthenticationTypes.Secure | AuthenticationTypes.Sealing
|
||||
};
|
||||
DirectorySearcher dSearch = new DirectorySearcher(entry)
|
||||
{
|
||||
Filter = "(&(CN=" + CN.ToUpper() + ")(objectClass=group))"
|
||||
};
|
||||
dSearch.PageSize = 100000;
|
||||
SearchResultCollection sr = dSearch.FindAll();
|
||||
groupCount += sr.Count;
|
||||
}
|
||||
return groupCount > 0;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateNewSecurityGroups(
|
||||
string baseFolder,
|
||||
string newFolderPath,
|
||||
string groupPrefix,
|
||||
string ouPath,
|
||||
PermissionGroupStrategy groupPermissionStrategy,
|
||||
string groupTraverseTag,
|
||||
string groupReadTag,
|
||||
string groupWriteTag,
|
||||
string groupOwnerTag,
|
||||
string groupDLTag,
|
||||
string groupGTag,
|
||||
IDictionary<string, string> customTags,
|
||||
List<IAM_SecurityGroupTemplate> templates,
|
||||
int readACLPermission,
|
||||
int writeACLPermission,
|
||||
int ownerACLPermission,
|
||||
int loop = 0,
|
||||
int existingADGroupCount = 0)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
|
||||
using C4IT_IAM_GET;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
using C4IT.Logging;
|
||||
|
||||
namespace C4IT_IAM_Engine
|
||||
{
|
||||
public class SecurityGroups
|
||||
{
|
||||
public string domainName;
|
||||
public string username;
|
||||
public SecureString password;
|
||||
|
||||
public List<IAM_SecurityGroup> IAM_SecurityGroups;
|
||||
public string rootUID;
|
||||
public SecurityGroups()
|
||||
{
|
||||
IAM_SecurityGroups = new List<IAM_SecurityGroup>();
|
||||
}
|
||||
public bool GroupsAllreadyExisting(string ouPath)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int groupCount = 0;
|
||||
if (IAM_SecurityGroups != null)
|
||||
foreach (var s in IAM_SecurityGroups)
|
||||
{
|
||||
if (s.securityGroupType != SecurityGroupType.Traverse)
|
||||
{
|
||||
DirectoryEntry entry = new DirectoryEntry
|
||||
{
|
||||
Path = "LDAP://" + domainName,
|
||||
Username = username,
|
||||
Password = new NetworkCredential("", password).Password,
|
||||
AuthenticationType = AuthenticationTypes.Secure | AuthenticationTypes.Sealing
|
||||
};
|
||||
DirectorySearcher dSearch = new DirectorySearcher(entry)
|
||||
{
|
||||
Filter = "(&(CN=" + s.Name.ToUpper() + ")(objectClass=group))"
|
||||
};
|
||||
dSearch.PageSize = 100000;
|
||||
SearchResultCollection sr = dSearch.FindAll();
|
||||
groupCount += sr.Count;
|
||||
}
|
||||
}
|
||||
return groupCount > 0;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public bool GroupAllreadyExisting(string CN)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int groupCount = 0;
|
||||
if (CN != string.Empty)
|
||||
{
|
||||
DirectoryEntry entry = new DirectoryEntry
|
||||
{
|
||||
Path = "LDAP://" + domainName,
|
||||
Username = username,
|
||||
Password = new NetworkCredential("", password).Password,
|
||||
AuthenticationType = AuthenticationTypes.Secure | AuthenticationTypes.Sealing
|
||||
};
|
||||
DirectorySearcher dSearch = new DirectorySearcher(entry)
|
||||
{
|
||||
Filter = "(&(CN=" + CN.ToUpper() + ")(objectClass=group))"
|
||||
};
|
||||
dSearch.PageSize = 100000;
|
||||
SearchResultCollection sr = dSearch.FindAll();
|
||||
groupCount += sr.Count;
|
||||
}
|
||||
return groupCount > 0;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateNewSecurityGroups(
|
||||
string baseFolder,
|
||||
string newFolderPath,
|
||||
string groupPrefix,
|
||||
string ouPath,
|
||||
PermissionGroupStrategy groupPermissionStrategy,
|
||||
string groupTraverseTag,
|
||||
string groupReadTag,
|
||||
string groupWriteTag,
|
||||
string groupOwnerTag,
|
||||
string groupDLTag,
|
||||
string groupGTag,
|
||||
IDictionary<string, string> customTags,
|
||||
List<IAM_SecurityGroupTemplate> templates,
|
||||
int readACLPermission,
|
||||
int writeACLPermission,
|
||||
int ownerACLPermission,
|
||||
int loop = 0,
|
||||
int existingADGroupCount = 0)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
|
||||
var relativePathRaw = DataArea.GetRelativePath(newFolderPath, baseFolder).Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||
relativePathRaw = relativePathRaw.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||
var relativePathSegments = relativePathRaw.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
|
||||
@@ -147,40 +147,40 @@ namespace C4IT_IAM_Engine
|
||||
{
|
||||
var GroupTypeTag = "";
|
||||
switch (template.Type)
|
||||
{
|
||||
case SecurityGroupType.Owner:
|
||||
GroupTypeTag = groupOwnerTag;
|
||||
break;
|
||||
case SecurityGroupType.Write:
|
||||
GroupTypeTag = groupWriteTag;
|
||||
break;
|
||||
case SecurityGroupType.Read:
|
||||
GroupTypeTag = groupReadTag;
|
||||
break;
|
||||
case SecurityGroupType.Traverse:
|
||||
GroupTypeTag = groupTraverseTag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var GroupScopeTag = "";
|
||||
switch (template.Scope)
|
||||
{
|
||||
case GroupScope.Global:
|
||||
GroupScopeTag = groupGTag;
|
||||
break;
|
||||
case GroupScope.Local:
|
||||
GroupScopeTag = groupDLTag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var tags = new Dictionary<string, string>();
|
||||
tags.Add("PREFIX", groupPrefix);
|
||||
tags.Add("GROUPTYPEPOSTFIX", GroupTypeTag);
|
||||
tags.Add("SCOPETAG", GroupScopeTag);
|
||||
|
||||
{
|
||||
case SecurityGroupType.Owner:
|
||||
GroupTypeTag = groupOwnerTag;
|
||||
break;
|
||||
case SecurityGroupType.Write:
|
||||
GroupTypeTag = groupWriteTag;
|
||||
break;
|
||||
case SecurityGroupType.Read:
|
||||
GroupTypeTag = groupReadTag;
|
||||
break;
|
||||
case SecurityGroupType.Traverse:
|
||||
GroupTypeTag = groupTraverseTag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var GroupScopeTag = "";
|
||||
switch (template.Scope)
|
||||
{
|
||||
case GroupScope.Global:
|
||||
GroupScopeTag = groupGTag;
|
||||
break;
|
||||
case GroupScope.Local:
|
||||
GroupScopeTag = groupDLTag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var tags = new Dictionary<string, string>();
|
||||
tags.Add("PREFIX", groupPrefix);
|
||||
tags.Add("GROUPTYPEPOSTFIX", GroupTypeTag);
|
||||
tags.Add("SCOPETAG", GroupScopeTag);
|
||||
|
||||
template.NamingTemplate = Helper.ApplyTemplatePlaceholders(template.NamingTemplate, template.Type != SecurityGroupType.Traverse, relativePath, sanitizedSegments, folderName)
|
||||
.ReplaceTags(customTags).ReplaceTags(tags)
|
||||
.ToUpper();
|
||||
@@ -195,309 +195,309 @@ namespace C4IT_IAM_Engine
|
||||
.ToUpper();
|
||||
|
||||
}
|
||||
|
||||
IAM_SecurityGroupTemplate ownerGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Owner));
|
||||
IAM_SecurityGroup osecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = ownerGlobal.NamingTemplate,
|
||||
description = ownerGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + ownerGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)ownerACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(osecGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate writeGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Write));
|
||||
IAM_SecurityGroup wsecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = writeGlobal.NamingTemplate,
|
||||
description = writeGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + writeGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)writeACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(wsecGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate readGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Read));
|
||||
IAM_SecurityGroup rsecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = readGlobal.NamingTemplate,
|
||||
description = readGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + readGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)readACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(rsecGroup);
|
||||
|
||||
|
||||
//
|
||||
if (groupPermissionStrategy == PermissionGroupStrategy.AGDLP)
|
||||
{
|
||||
IAM_SecurityGroupTemplate ownerDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Owner));
|
||||
IAM_SecurityGroup osecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = ownerDL.NamingTemplate,
|
||||
description = ownerDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + ownerDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)ownerACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
osecDLGroup.memberGroups.Add(osecGroup);
|
||||
IAM_SecurityGroups.Add(osecDLGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate writeDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Write));
|
||||
IAM_SecurityGroup wsecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = writeDL.NamingTemplate,
|
||||
description = writeDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + writeDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)writeACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
wsecDLGroup.memberGroups.Add(wsecGroup);
|
||||
IAM_SecurityGroups.Add(wsecDLGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate readDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Read));
|
||||
IAM_SecurityGroup rsecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = readDL.NamingTemplate,
|
||||
description = readDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + readDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)readACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
rsecDLGroup.memberGroups.Add(rsecGroup);
|
||||
IAM_SecurityGroups.Add(rsecDLGroup);
|
||||
}
|
||||
foreach (var secGroup in IAM_SecurityGroups)
|
||||
{
|
||||
secGroup.description = secGroup.description.ReplaceLoopTag(0);
|
||||
secGroup.Name = secGroup.Name.ReplaceLoopTag(loop);
|
||||
secGroup.technicalName = secGroup.technicalName.ReplaceLoopTag(loop);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Security group generated: {secGroup.technicalName}");
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static string GetRightPartOfPath(string path, string startAfterPart)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
// use the correct seperator for the environment
|
||||
var pathParts = path.Split(Path.DirectorySeparatorChar);
|
||||
if (startAfterPart.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
startAfterPart = startAfterPart.Substring(0, startAfterPart.Length - 1);
|
||||
}
|
||||
var startAfter = startAfterPart.Split(Path.DirectorySeparatorChar);
|
||||
string newPath = String.Empty;
|
||||
if (pathParts.Length > startAfter.Length)
|
||||
{
|
||||
for (int i = startAfter.Length; pathParts.Length > i; i++)
|
||||
{
|
||||
newPath += pathParts[i] + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
if (newPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
newPath = newPath.Substring(0, newPath.Length - 1);
|
||||
}
|
||||
|
||||
// try and work out if last part was a directory - if not, drop the last part as we don't want the filename
|
||||
return newPath;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public static string getSID(DirectoryEntry ent)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
var usrId = (byte[])ent.Properties["objectSid"][0];
|
||||
return (new SecurityIdentifier(usrId, 0)).ToString();
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
|
||||
|
||||
IAM_SecurityGroupTemplate ownerGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Owner));
|
||||
IAM_SecurityGroup osecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = ownerGlobal.NamingTemplate,
|
||||
description = ownerGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + ownerGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)ownerACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(osecGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate writeGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Write));
|
||||
IAM_SecurityGroup wsecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = writeGlobal.NamingTemplate,
|
||||
description = writeGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + writeGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)writeACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(wsecGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate readGlobal = templates.First(t => t.Scope.Equals(GroupScope.Global) && t.Type.Equals(SecurityGroupType.Read));
|
||||
IAM_SecurityGroup rsecGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = readGlobal.NamingTemplate,
|
||||
description = readGlobal.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + readGlobal.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)readACLPermission,
|
||||
Scope = GroupScope.Global
|
||||
};
|
||||
IAM_SecurityGroups.Add(rsecGroup);
|
||||
|
||||
|
||||
//
|
||||
if (groupPermissionStrategy == PermissionGroupStrategy.AGDLP)
|
||||
{
|
||||
IAM_SecurityGroupTemplate ownerDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Owner));
|
||||
IAM_SecurityGroup osecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = ownerDL.NamingTemplate,
|
||||
description = ownerDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + ownerDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)ownerACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
osecDLGroup.memberGroups.Add(osecGroup);
|
||||
IAM_SecurityGroups.Add(osecDLGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate writeDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Write));
|
||||
IAM_SecurityGroup wsecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = writeDL.NamingTemplate,
|
||||
description = writeDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + writeDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)writeACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
wsecDLGroup.memberGroups.Add(wsecGroup);
|
||||
IAM_SecurityGroups.Add(wsecDLGroup);
|
||||
|
||||
IAM_SecurityGroupTemplate readDL = templates.First(t => t.Scope.Equals(GroupScope.Local) && t.Type.Equals(SecurityGroupType.Read));
|
||||
IAM_SecurityGroup rsecDLGroup = new IAM_SecurityGroup()
|
||||
{
|
||||
Name = readDL.NamingTemplate,
|
||||
description = readDL.DescriptionTemplate,
|
||||
|
||||
technicalName = "CN=" + readDL.NamingTemplate + "," + ouPath,
|
||||
targetTyp = (int)IAM_TargetType.FileSystem,
|
||||
rights = (FileSystemRights)readACLPermission,
|
||||
Scope = GroupScope.Local
|
||||
};
|
||||
rsecDLGroup.memberGroups.Add(rsecGroup);
|
||||
IAM_SecurityGroups.Add(rsecDLGroup);
|
||||
}
|
||||
foreach (var secGroup in IAM_SecurityGroups)
|
||||
{
|
||||
secGroup.description = secGroup.description.ReplaceLoopTag(0);
|
||||
secGroup.Name = secGroup.Name.ReplaceLoopTag(loop);
|
||||
secGroup.technicalName = secGroup.technicalName.ReplaceLoopTag(loop);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Security group generated: {secGroup.technicalName}");
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static string GetRightPartOfPath(string path, string startAfterPart)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
// use the correct seperator for the environment
|
||||
var pathParts = path.Split(Path.DirectorySeparatorChar);
|
||||
if (startAfterPart.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
startAfterPart = startAfterPart.Substring(0, startAfterPart.Length - 1);
|
||||
}
|
||||
var startAfter = startAfterPart.Split(Path.DirectorySeparatorChar);
|
||||
string newPath = String.Empty;
|
||||
if (pathParts.Length > startAfter.Length)
|
||||
{
|
||||
for (int i = startAfter.Length; pathParts.Length > i; i++)
|
||||
{
|
||||
newPath += pathParts[i] + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
if (newPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
newPath = newPath.Substring(0, newPath.Length - 1);
|
||||
}
|
||||
|
||||
// try and work out if last part was a directory - if not, drop the last part as we don't want the filename
|
||||
return newPath;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public static string getSID(DirectoryEntry ent)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
var usrId = (byte[])ent.Properties["objectSid"][0];
|
||||
return (new SecurityIdentifier(usrId, 0)).ToString();
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DirectoryEntry CreateADGroup(string ouPath, IAM_SecurityGroup secGroup, List<UserPrincipal> users)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
if (!GroupAllreadyExisting(secGroup.Name.ToUpper()))
|
||||
{
|
||||
|
||||
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domainName + "/" + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Creating ad entry with CN / sAmAccountName: {secGroup.Name.ToUpper()}");
|
||||
DirectoryEntry group = entry.Children.Add("CN=" + secGroup.Name.ToUpper(), "group");
|
||||
group.Properties["sAmAccountName"].Value = secGroup.Name.ToUpper();
|
||||
if (users != null && secGroup.Scope == GroupScope.Global)
|
||||
{
|
||||
foreach (var user in users)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Adding member: {user.DistinguishedName}");
|
||||
group.Properties["member"].Add(user.DistinguishedName);
|
||||
}
|
||||
}
|
||||
if(!String.IsNullOrEmpty(secGroup.description))
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Setting description: {secGroup.description}");
|
||||
group.Properties["description"].Value = secGroup.description;
|
||||
}
|
||||
var groupType = secGroup.Scope == GroupScope.Global ? GroupScopeValues.Global : GroupScopeValues.Local;
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Setting groupType to: {groupType}");
|
||||
group.Properties["groupType"].Value = groupType;
|
||||
if (secGroup.Scope == GroupScope.Local)
|
||||
foreach (var iGroup in secGroup.memberGroups)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Adding member: {iGroup.technicalName}");
|
||||
group.Properties["member"].Add(iGroup.technicalName);
|
||||
}
|
||||
|
||||
group.CommitChanges();
|
||||
DirectoryEntry ent = new DirectoryEntry("LDAP://" + domainName + "/" + "CN =" + secGroup.Name.ToUpper() + "," + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
|
||||
var objectid = SecurityGroups.getSID(ent);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Security group created in ad: {secGroup.technicalName}");
|
||||
secGroup.UID = objectid;
|
||||
return ent;
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryEntry e = new DirectoryEntry("LDAP://" + domainName + "/" + "CN =" + secGroup.Name.ToUpper() + "," + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
var objectid = getSID(e);
|
||||
secGroup.UID = objectid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
public enum GroupScopeValues : int
|
||||
{
|
||||
Global = -2147483646,
|
||||
Local = -2147483644
|
||||
}
|
||||
public class IAM_SecurityGroupTemplate
|
||||
{
|
||||
private string namingTemplate;
|
||||
private string descriptionTemplate;
|
||||
private string wildcardTemplate;
|
||||
private SecurityGroupType type;
|
||||
private GroupScope scope;
|
||||
|
||||
public IAM_SecurityGroupTemplate(string namingTemplate, string descriptionTemplate, string wildcardTemplate, SecurityGroupType type, GroupScope scope)
|
||||
{
|
||||
NamingTemplate = namingTemplate;
|
||||
DescriptionTemplate = descriptionTemplate;
|
||||
WildcardTemplate = wildcardTemplate;
|
||||
Type = type;
|
||||
Scope = scope;
|
||||
}
|
||||
|
||||
public string NamingTemplate
|
||||
{
|
||||
get => namingTemplate; set
|
||||
{
|
||||
namingTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public string DescriptionTemplate
|
||||
{
|
||||
get => descriptionTemplate; set
|
||||
{
|
||||
descriptionTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public string WildcardTemplate
|
||||
{
|
||||
get => wildcardTemplate; set
|
||||
{
|
||||
wildcardTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public SecurityGroupType Type { get => type; set => type = value; }
|
||||
public GroupScope Scope { get => scope; set => scope = value; }
|
||||
}
|
||||
public class IAM_SecurityGroup
|
||||
{
|
||||
|
||||
public string UID;
|
||||
public string Parent = "";
|
||||
public string description;
|
||||
public List<IAM_SecurityGroup> memberGroups;
|
||||
public string Name;
|
||||
public string technicalName;
|
||||
public SecurityGroupType securityGroupType;
|
||||
public int targetTyp;
|
||||
public GroupScope Scope;
|
||||
public FileSystemRights rights;
|
||||
public IAM_SecurityGroup()
|
||||
{
|
||||
memberGroups = new List<IAM_SecurityGroup>();
|
||||
}
|
||||
}
|
||||
public enum SecurityGroupType
|
||||
{
|
||||
[XmlEnum(Name = "0")]
|
||||
Owner,
|
||||
[XmlEnum(Name = "1")]
|
||||
Write,
|
||||
[XmlEnum(Name = "2")]
|
||||
Read,
|
||||
[XmlEnum(Name = "3")]
|
||||
Traverse
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
{
|
||||
if (!GroupAllreadyExisting(secGroup.Name.ToUpper()))
|
||||
{
|
||||
|
||||
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domainName + "/" + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Creating ad entry with CN / sAmAccountName: {secGroup.Name.ToUpper()}");
|
||||
DirectoryEntry group = entry.Children.Add("CN=" + secGroup.Name.ToUpper(), "group");
|
||||
group.Properties["sAmAccountName"].Value = secGroup.Name.ToUpper();
|
||||
if (users != null && secGroup.Scope == GroupScope.Global)
|
||||
{
|
||||
foreach (var user in users)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Adding member: {user.DistinguishedName}");
|
||||
group.Properties["member"].Add(user.DistinguishedName);
|
||||
}
|
||||
}
|
||||
if(!String.IsNullOrEmpty(secGroup.description))
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Setting description: {secGroup.description}");
|
||||
group.Properties["description"].Value = secGroup.description;
|
||||
}
|
||||
var groupType = secGroup.Scope == GroupScope.Global ? GroupScopeValues.Global : GroupScopeValues.Local;
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Setting groupType to: {groupType}");
|
||||
group.Properties["groupType"].Value = groupType;
|
||||
if (secGroup.Scope == GroupScope.Local)
|
||||
foreach (var iGroup in secGroup.memberGroups)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Adding member: {iGroup.technicalName}");
|
||||
group.Properties["member"].Add(iGroup.technicalName);
|
||||
}
|
||||
|
||||
group.CommitChanges();
|
||||
DirectoryEntry ent = new DirectoryEntry("LDAP://" + domainName + "/" + "CN =" + secGroup.Name.ToUpper() + "," + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
|
||||
var objectid = SecurityGroups.getSID(ent);
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Security group created in ad: {secGroup.technicalName}");
|
||||
secGroup.UID = objectid;
|
||||
return ent;
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryEntry e = new DirectoryEntry("LDAP://" + domainName + "/" + "CN =" + secGroup.Name.ToUpper() + "," + ouPath, username, new NetworkCredential("", password).Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing);
|
||||
var objectid = getSID(e);
|
||||
secGroup.UID = objectid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
cLogManager.DefaultLogger.LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
public enum GroupScopeValues : int
|
||||
{
|
||||
Global = -2147483646,
|
||||
Local = -2147483644
|
||||
}
|
||||
public class IAM_SecurityGroupTemplate
|
||||
{
|
||||
private string namingTemplate;
|
||||
private string descriptionTemplate;
|
||||
private string wildcardTemplate;
|
||||
private SecurityGroupType type;
|
||||
private GroupScope scope;
|
||||
|
||||
public IAM_SecurityGroupTemplate(string namingTemplate, string descriptionTemplate, string wildcardTemplate, SecurityGroupType type, GroupScope scope)
|
||||
{
|
||||
NamingTemplate = namingTemplate;
|
||||
DescriptionTemplate = descriptionTemplate;
|
||||
WildcardTemplate = wildcardTemplate;
|
||||
Type = type;
|
||||
Scope = scope;
|
||||
}
|
||||
|
||||
public string NamingTemplate
|
||||
{
|
||||
get => namingTemplate; set
|
||||
{
|
||||
namingTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public string DescriptionTemplate
|
||||
{
|
||||
get => descriptionTemplate; set
|
||||
{
|
||||
descriptionTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public string WildcardTemplate
|
||||
{
|
||||
get => wildcardTemplate; set
|
||||
{
|
||||
wildcardTemplate = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
public SecurityGroupType Type { get => type; set => type = value; }
|
||||
public GroupScope Scope { get => scope; set => scope = value; }
|
||||
}
|
||||
public class IAM_SecurityGroup
|
||||
{
|
||||
|
||||
public string UID;
|
||||
public string Parent = "";
|
||||
public string description;
|
||||
public List<IAM_SecurityGroup> memberGroups;
|
||||
public string Name;
|
||||
public string technicalName;
|
||||
public SecurityGroupType securityGroupType;
|
||||
public int targetTyp;
|
||||
public GroupScope Scope;
|
||||
public FileSystemRights rights;
|
||||
public IAM_SecurityGroup()
|
||||
{
|
||||
memberGroups = new List<IAM_SecurityGroup>();
|
||||
}
|
||||
}
|
||||
public enum SecurityGroupType
|
||||
{
|
||||
[XmlEnum(Name = "0")]
|
||||
Owner,
|
||||
[XmlEnum(Name = "1")]
|
||||
Write,
|
||||
[XmlEnum(Name = "2")]
|
||||
Read,
|
||||
[XmlEnum(Name = "3")]
|
||||
Traverse
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,208 +1,208 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using C4IT.Logging;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace C4IT_IAM
|
||||
{
|
||||
public class cNetworkConnection : IDisposable
|
||||
{
|
||||
private const uint MAX_PREFERRED_LENGTH = 0xFFFFFFFF;
|
||||
private const int NERR_Success = 0;
|
||||
|
||||
string _networkName;
|
||||
|
||||
public cNetworkConnection(string networkName,
|
||||
string userName, string Password)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
_networkName = networkName;
|
||||
|
||||
var netResource = new NetResource()
|
||||
{
|
||||
Scope = ResourceScope.GlobalNetwork,
|
||||
ResourceType = ResourceType.Disk,
|
||||
DisplayType = ResourceDisplaytype.Share,
|
||||
RemoteName = networkName
|
||||
};
|
||||
|
||||
var result = WNetAddConnection2(
|
||||
netResource,
|
||||
Password,
|
||||
userName,
|
||||
0);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Error in connect occured ({result}) {new Win32Exception(result).Message}");
|
||||
throw new Win32Exception(result);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
~cNetworkConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
WNetCancelConnection2(_networkName, 0, true);
|
||||
}
|
||||
|
||||
public SHARE_INFO_1[] EnumNetShares(string Server)
|
||||
{
|
||||
List<SHARE_INFO_1> ShareInfos = new List<SHARE_INFO_1>();
|
||||
int entriesread = 0;
|
||||
int totalentries = 0;
|
||||
int resume_handle = 0;
|
||||
int nStructSize = Marshal.SizeOf(typeof(SHARE_INFO_1));
|
||||
IntPtr bufPtr = IntPtr.Zero;
|
||||
StringBuilder server = new StringBuilder(Server);
|
||||
int ret = NetShareEnum(server, 1, ref bufPtr, MAX_PREFERRED_LENGTH, ref entriesread, ref totalentries, ref resume_handle);
|
||||
if (ret == NERR_Success)
|
||||
{
|
||||
IntPtr currentPtr = bufPtr;
|
||||
for (int i = 0; i < entriesread; i++)
|
||||
{
|
||||
SHARE_INFO_1 shi1 = (SHARE_INFO_1)Marshal.PtrToStructure(currentPtr, typeof(SHARE_INFO_1));
|
||||
ShareInfos.Add(shi1);
|
||||
currentPtr += nStructSize;
|
||||
}
|
||||
NetApiBufferFree(bufPtr);
|
||||
return ShareInfos.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShareInfos.Add(new SHARE_INFO_1("ERROR=" + ret.ToString(), 10, string.Empty));
|
||||
return ShareInfos.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetAddConnection2(NetResource netResource,
|
||||
string password, string username, int flags);
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetCancelConnection2(string name, int flags,
|
||||
bool force);
|
||||
|
||||
[DllImport("Netapi32.dll", SetLastError = true)]
|
||||
static extern int NetApiBufferFree(IntPtr Buffer);
|
||||
|
||||
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int NetShareEnum(
|
||||
StringBuilder ServerName,
|
||||
int level,
|
||||
ref IntPtr bufPtr,
|
||||
uint prefmaxlen,
|
||||
ref int entriesread,
|
||||
ref int totalentries,
|
||||
ref int resume_handle
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class NetResource
|
||||
{
|
||||
public ResourceScope Scope;
|
||||
public ResourceType ResourceType;
|
||||
public ResourceDisplaytype DisplayType;
|
||||
public int Usage;
|
||||
public string LocalName;
|
||||
public string RemoteName;
|
||||
public string Comment;
|
||||
public string Provider;
|
||||
}
|
||||
|
||||
public enum ResourceScope : int
|
||||
{
|
||||
Connected = 1,
|
||||
GlobalNetwork,
|
||||
Remembered,
|
||||
Recent,
|
||||
Context
|
||||
};
|
||||
|
||||
public enum ResourceType : int
|
||||
{
|
||||
Any = 0,
|
||||
Disk = 1,
|
||||
Print = 2,
|
||||
Reserved = 8,
|
||||
}
|
||||
|
||||
public enum ResourceDisplaytype : int
|
||||
{
|
||||
Generic = 0x0,
|
||||
Domain = 0x01,
|
||||
Server = 0x02,
|
||||
Share = 0x03,
|
||||
File = 0x04,
|
||||
Group = 0x05,
|
||||
Network = 0x06,
|
||||
Root = 0x07,
|
||||
Shareadmin = 0x08,
|
||||
Directory = 0x09,
|
||||
Tree = 0x0a,
|
||||
Ndscontainer = 0x0b
|
||||
}
|
||||
|
||||
public enum NetError : uint
|
||||
{
|
||||
NERR_Success = 0,
|
||||
NERR_BASE = 2100,
|
||||
NERR_UnknownDevDir = (NERR_BASE + 16),
|
||||
NERR_DuplicateShare = (NERR_BASE + 18),
|
||||
NERR_BufTooSmall = (NERR_BASE + 23),
|
||||
}
|
||||
public enum SHARE_TYPE : uint
|
||||
{
|
||||
STYPE_DISKTREE = 0,
|
||||
STYPE_PRINTQ = 1,
|
||||
STYPE_DEVICE = 2,
|
||||
STYPE_IPC = 3,
|
||||
STYPE_SPECIAL = 0x80000000,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHARE_INFO_1
|
||||
{
|
||||
public string shi1_netname;
|
||||
public uint shi1_type;
|
||||
public string shi1_remark;
|
||||
public SHARE_INFO_1(string sharename, uint sharetype, string remark)
|
||||
{
|
||||
this.shi1_netname = sharename;
|
||||
this.shi1_type = sharetype;
|
||||
this.shi1_remark = remark;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return shi1_netname;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using C4IT.Logging;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace C4IT_IAM
|
||||
{
|
||||
public class cNetworkConnection : IDisposable
|
||||
{
|
||||
private const uint MAX_PREFERRED_LENGTH = 0xFFFFFFFF;
|
||||
private const int NERR_Success = 0;
|
||||
|
||||
string _networkName;
|
||||
|
||||
public cNetworkConnection(string networkName,
|
||||
string userName, string Password)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
|
||||
try
|
||||
{
|
||||
_networkName = networkName;
|
||||
|
||||
var netResource = new NetResource()
|
||||
{
|
||||
Scope = ResourceScope.GlobalNetwork,
|
||||
ResourceType = ResourceType.Disk,
|
||||
DisplayType = ResourceDisplaytype.Share,
|
||||
RemoteName = networkName
|
||||
};
|
||||
|
||||
var result = WNetAddConnection2(
|
||||
netResource,
|
||||
Password,
|
||||
userName,
|
||||
0);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
DefaultLogger.LogEntry(LogLevels.Debug, $"Error in connect occured ({result}) {new Win32Exception(result).Message}");
|
||||
throw new Win32Exception(result);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(MethodBase.GetCurrentMethod());
|
||||
}
|
||||
}
|
||||
|
||||
~cNetworkConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
WNetCancelConnection2(_networkName, 0, true);
|
||||
}
|
||||
|
||||
public SHARE_INFO_1[] EnumNetShares(string Server)
|
||||
{
|
||||
List<SHARE_INFO_1> ShareInfos = new List<SHARE_INFO_1>();
|
||||
int entriesread = 0;
|
||||
int totalentries = 0;
|
||||
int resume_handle = 0;
|
||||
int nStructSize = Marshal.SizeOf(typeof(SHARE_INFO_1));
|
||||
IntPtr bufPtr = IntPtr.Zero;
|
||||
StringBuilder server = new StringBuilder(Server);
|
||||
int ret = NetShareEnum(server, 1, ref bufPtr, MAX_PREFERRED_LENGTH, ref entriesread, ref totalentries, ref resume_handle);
|
||||
if (ret == NERR_Success)
|
||||
{
|
||||
IntPtr currentPtr = bufPtr;
|
||||
for (int i = 0; i < entriesread; i++)
|
||||
{
|
||||
SHARE_INFO_1 shi1 = (SHARE_INFO_1)Marshal.PtrToStructure(currentPtr, typeof(SHARE_INFO_1));
|
||||
ShareInfos.Add(shi1);
|
||||
currentPtr += nStructSize;
|
||||
}
|
||||
NetApiBufferFree(bufPtr);
|
||||
return ShareInfos.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShareInfos.Add(new SHARE_INFO_1("ERROR=" + ret.ToString(), 10, string.Empty));
|
||||
return ShareInfos.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetAddConnection2(NetResource netResource,
|
||||
string password, string username, int flags);
|
||||
|
||||
[DllImport("mpr.dll")]
|
||||
private static extern int WNetCancelConnection2(string name, int flags,
|
||||
bool force);
|
||||
|
||||
[DllImport("Netapi32.dll", SetLastError = true)]
|
||||
static extern int NetApiBufferFree(IntPtr Buffer);
|
||||
|
||||
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int NetShareEnum(
|
||||
StringBuilder ServerName,
|
||||
int level,
|
||||
ref IntPtr bufPtr,
|
||||
uint prefmaxlen,
|
||||
ref int entriesread,
|
||||
ref int totalentries,
|
||||
ref int resume_handle
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class NetResource
|
||||
{
|
||||
public ResourceScope Scope;
|
||||
public ResourceType ResourceType;
|
||||
public ResourceDisplaytype DisplayType;
|
||||
public int Usage;
|
||||
public string LocalName;
|
||||
public string RemoteName;
|
||||
public string Comment;
|
||||
public string Provider;
|
||||
}
|
||||
|
||||
public enum ResourceScope : int
|
||||
{
|
||||
Connected = 1,
|
||||
GlobalNetwork,
|
||||
Remembered,
|
||||
Recent,
|
||||
Context
|
||||
};
|
||||
|
||||
public enum ResourceType : int
|
||||
{
|
||||
Any = 0,
|
||||
Disk = 1,
|
||||
Print = 2,
|
||||
Reserved = 8,
|
||||
}
|
||||
|
||||
public enum ResourceDisplaytype : int
|
||||
{
|
||||
Generic = 0x0,
|
||||
Domain = 0x01,
|
||||
Server = 0x02,
|
||||
Share = 0x03,
|
||||
File = 0x04,
|
||||
Group = 0x05,
|
||||
Network = 0x06,
|
||||
Root = 0x07,
|
||||
Shareadmin = 0x08,
|
||||
Directory = 0x09,
|
||||
Tree = 0x0a,
|
||||
Ndscontainer = 0x0b
|
||||
}
|
||||
|
||||
public enum NetError : uint
|
||||
{
|
||||
NERR_Success = 0,
|
||||
NERR_BASE = 2100,
|
||||
NERR_UnknownDevDir = (NERR_BASE + 16),
|
||||
NERR_DuplicateShare = (NERR_BASE + 18),
|
||||
NERR_BufTooSmall = (NERR_BASE + 23),
|
||||
}
|
||||
public enum SHARE_TYPE : uint
|
||||
{
|
||||
STYPE_DISKTREE = 0,
|
||||
STYPE_PRINTQ = 1,
|
||||
STYPE_DEVICE = 2,
|
||||
STYPE_IPC = 3,
|
||||
STYPE_SPECIAL = 0x80000000,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHARE_INFO_1
|
||||
{
|
||||
public string shi1_netname;
|
||||
public uint shi1_type;
|
||||
public string shi1_remark;
|
||||
public SHARE_INFO_1(string sharename, uint sharetype, string remark)
|
||||
{
|
||||
this.shi1_netname = sharename;
|
||||
this.shi1_type = sharetype;
|
||||
this.shi1_remark = remark;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return shi1_netname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user