public void Constructor_Should_ParseCorrectly_When_VariousDNCausedParsingIssues() { // Arrange var listOfDistinguishedNames = new string[] { "CN=gen-boslwdf&b,OU=Users,OU=BOSLW,DC=fs,DC=corp,DC=example,DC=com", "CN=Exchange Administrators,OU=MVCI,OU=Exchange 5.5 Directory Objects,DC=mv,DC=corp,DC=example,DC=com", "CN=GPO-SUBJW-Restricted Local Drives,OU=Groups,OU=SUBJW,DC=int,DC=corp,DC=example,DC=com", "CN=DF&B - International - RHRS - Managed?Franchise,OU=Exchange Distribution Groups,DC=hdq,DC=corp,DC=example,DC=com", "CN=EBC\\, VA Northern,OU=Exchange Distribution Groups,DC=hdq,DC=corp,DC=example,DC=com", "CN=vquga140,OU=Users,OU=HDQRK,DC=hdq,DC=corp,DC=example,DC=com", "CN=jlmu1007,OU=Users,OU=SXFCZ,DC=int,DC=corp,DC=example,DC=com", "CN=AGRP-AD-West-RSM,OU=Administrative Global Groups,OU=Administrative Groups,DC=corp,DC=example,DC=com", "CN=DL - BackUp Exec (CTDCA),OU=Exchange Distribution Groups,DC=hdq,DC=corp,DC=example,DC=com", "CN=dl-wst26,OU=Exchange Distribution Groups,DC=hdq,DC=corp,DC=example,DC=com", "CN=UAGRP-AD-Rit-RSM,OU=Administrative Universal Groups,OU=Administrative Groups,DC=corp,DC=example,DC=com", "OU=Administrative Universal Groups,OU=Administrative Groups,DC=corp,DC=example,DC=com", "OU=TSTOU,DC=corp,DC=example,DC=COM", "OU=ENTLOG,DC=MICROSOFT,DC=COM", "DC=corp,DC=example,DC=COM", "DC=example,DC=COM", "DC=CORP,DC=LOCAL", "CN=Xerox Document Imaging (WERCC),OU=Users,OU=TSTOU,DC=hdq,DC=corp,DC=example,DC=com" }; // Act // Assert foreach (var dn in listOfDistinguishedNames) { Assert.Equal(dn, DistinguishedName.Parse(dn).ToString()); } }
public void B() { var subject = DistinguishedName.Parse("C=US, ST=California, L=San Francisco, O=Wikimedia Foundation, CN=*.wikipedia.org"); Assert.Equal("US", subject.Country); Assert.Equal("San Francisco", subject.Locality); Assert.Equal("Wikimedia Foundation", subject.Organization); Assert.Equal("*.wikipedia.org", subject.CommonName); }
/// <summary> /// Initializes a new instance of the <see /// cref="ToolKit.DirectoryServices.ActiveDirectory.DirectoryObject" /> class. /// </summary> /// <param name="result">A SearchResult Object.</param> protected DirectoryObject(SearchResult result) { _distinguishedName = string.Empty; if (result == null) { throw new ArgumentNullException(nameof(result)); } Initialize(DistinguishedName.Parse(result.Path)); }
/// <summary> /// Initializes a new instance of the <see /// cref="ToolKit.DirectoryServices.ActiveDirectory.DirectoryObject" /> class. /// </summary> /// <param name="distinguishedName">string representation of the distinguished name.</param> protected DirectoryObject(string distinguishedName) { _distinguishedName = string.Empty; if (string.IsNullOrEmpty(distinguishedName)) { throw new ArgumentNullException(nameof(distinguishedName)); } Initialize(DistinguishedName.Parse(distinguishedName)); }
/// <summary> /// Initializes a new instance of the <see /// cref="ToolKit.DirectoryServices.ActiveDirectory.DirectoryObject" /> class. /// </summary> /// <param name="entry">A DirectoryEntry Object.</param> protected DirectoryObject(DirectoryEntry entry) { _distinguishedName = string.Empty; if (entry == null) { throw new ArgumentNullException(nameof(entry)); } Initialize(DistinguishedName.Parse(entry.Path)); }
public void A() { var text = "CN=test-dir, O=Golang Tests, S=Test-State, C=UK"; var dn = DistinguishedName.Parse(text); Assert.Equal("test-dir", dn.CommonName); Assert.Equal("Golang Tests", dn.Organization); // Assert.Equal("Test-State", dn.Region); Assert.Equal("UK", dn.Country); }
public void Contacts_In_Group() { // Arrange const string expected = "(&(&(objectCategory=person)(objectClass=contact))" + "(memberOf=CN=TEST,OU=Groups,OU=HDQRK,DC=COMPANY,DC=COM))"; // Act var filter = ActiveDirectoryCommonFilters.ContactsInGroup( DistinguishedName.Parse( "CN=TEST,OU=Groups,OU=HDQRK,DC=COMPANY,DC=COM")); // Assert Assert.Equal(expected, filter.ToString()); }
private string ResolveNetBios() { // This Value would only exist for an Active Directory Distinguished Name. string netBiosName = null; var dn = DistinguishedName.Parse(_distinguishedName); var context = new DirectoryContext(DirectoryContextType.Domain, dn.DnsDomain); var forest = Domain.GetDomain(context).Forest; using (var root = forest.RootDomain.GetDirectoryEntry()) { var path = root.Path.Substring(7); var slash = path.IndexOf("/", StringComparison.Ordinal); path = $"LDAP://{path.Insert(slash + 1, "CN=Partitions, CN=Configuration,")}"; using (var entry = new DirectoryEntry(path)) { SearchResultCollection results; using (var search = new DirectorySearcher(entry)) { search.Filter = "(&(objectClass=top)(nETBIOSName=*))"; search.PropertiesToLoad.Add("nETBIOSName"); search.PropertiesToLoad.Add("nCName"); results = search.FindAll(); } foreach (SearchResult result in results) { var contextName = (string)result.Properties["nCName"][0]; if (string.Equals(contextName, dn.DomainRoot, StringComparison.OrdinalIgnoreCase)) { netBiosName = (string)result.Properties["netBIOSName"][0]; } } } } return(netBiosName); }
private FilePropertiesInfo(FileInfo fileInfo) { if (fileInfo == null) { return; } if (!fileInfo.Exists) { Logger.GetInstance(typeof(FilePropertiesInfo)).Warn("Can not find " + fileInfo.FullName + " to get properties"); return; } X509Certificate certificate = null; try { certificate = X509Certificate.CreateFromSignedFile(fileInfo.FullName); } catch (Exception) { var key = Sha1.GetInstance().GenerateInHex( fileInfo.FullName + "_" + Util.Convert.ToTimestampInMilli(DateTime.UtcNow) / ErrorPathCacheTimeInMilli ); if (string.IsNullOrEmpty(key)) { Logger.GetInstance(typeof(FilePropertiesInfo)).Warn("Can not find certificate from file " + fileInfo.FullName); } else if (!CachedErrorPaths.Contains(key)) { Logger.GetInstance(typeof(FilePropertiesInfo)).Warn("Can not find certificate from file " + fileInfo.FullName); CachedErrorPaths.Add(key); } } if (certificate != null) { IssuerDistinguishedName = certificate.Issuer; IssuerName = DistinguishedName.Parse(IssuerDistinguishedName).O; SubjectDistinguishedName = certificate.Subject; SubjectName = DistinguishedName.Parse(SubjectDistinguishedName).O; PublicKey = certificate.GetPublicKeyString(); Verified = Authenticode.IsVerified(fileInfo); } var versionInfo = FileVersionInfo.GetVersionInfo(fileInfo.FullName); try { Version = string.Format( CultureInfo.InvariantCulture, @"{0}.{1}.{2}.{3}", versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart ); } catch (Exception) { Logger.GetInstance(typeof(FilePropertiesInfo)).Warn("Can not find version from file " + fileInfo.FullName); Version = "0.0.0.0"; } try { ProductVersion = string.Format( CultureInfo.InvariantCulture, @"{0}.{1}.{2}.{3}", versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart ); } catch (Exception) { Logger.GetInstance(typeof(FilePropertiesInfo)).Warn("Can not find product version from file " + fileInfo.FullName); ProductVersion = "0.0.0.0"; } if (Verified) { TimestampList.AddRange(Authenticode.GetTimestampList(fileInfo)); } }
/// <summary> /// Converts this object to a DirectoryEntry. /// </summary> /// <returns>This object as a DirectoryEntry.</returns> public DirectoryEntry ToDirectoryEntry() { return(new DirectoryEntry(DistinguishedName.Parse(_distinguishedName).LdapPath)); }
/// <summary> /// Moves this object to the distinguished name of the new parent container. /// </summary> /// <param name="newLocation">The distinguished name of the new parent container.</param> public void Move(string newLocation) { Move(DistinguishedName.Parse(newLocation)); }
/// <summary> /// Determines whether the specified distinguished name is a user object. /// </summary> /// <param name="distinguishedName">The distinguished name representing the ADSI object.</param> /// <returns><c>true</c> if the specified distinguished name is a user; otherwise, <c>false</c>.</returns> public static bool IsUser(string distinguishedName) { return(IsUser(DistinguishedName.Parse(distinguishedName))); }
/// <summary> /// Determines whether the specified distinguished name is a contact object. /// </summary> /// <param name="distinguishedName">The distinguished name representing the ADSI object.</param> /// <returns> /// <c>true</c> if the specified distinguished name is a contact; otherwise, <c>false</c>. /// </returns> public static bool IsContact(string distinguishedName) { return(IsContact(DistinguishedName.Parse(distinguishedName))); }
/// <summary> /// Determines if the specified distinguished name exists. /// </summary> /// <param name="distinguishedName">The distinguished Name of the object.</param> /// <returns><c>True</c> if the object exists, otherwise <c>False</c>.</returns> public static bool Exists(string distinguishedName) { return(DirectoryEntry.Exists(DistinguishedName.Parse(distinguishedName).LdapPath)); }