private void ReturnSingleAccount(byte[] bootKey) { DSAccount account; switch (this.ParameterSetName) { case parameterSetByDN: var dn = new DistinguishedName(this.DistinguishedName); account = this.DirectoryAgent.GetAccount(dn, bootKey); break; case parameterSetByName: account = this.DirectoryAgent.GetAccount(this.SamAccountName, bootKey); break; case parameterSetByGuid: account = this.DirectoryAgent.GetAccount(this.ObjectGuid, bootKey); break; case parameterSetBySid: account = this.DirectoryAgent.GetAccount(this.ObjectSid, bootKey); break; default: // This should never happen: throw new PSInvalidOperationException(Resources.InvalidParameterSetMessage); } this.WriteObject(account); }
public void AddParent(DistinguishedName dn) { foreach (var component in dn.Components) { this.AddParent(component); } }
protected override void ProcessRecord() { //TODO: Exception handling: Object not found, malformed DN, ... bool hasChanged; switch (this.ParameterSetName) { case ADDBObjectCommandBase.parameterSetByDN: // TODO: Extract these messages as a resource. this.WriteVerbose(String.Format("Adding SID history to principal {0}.", this.DistinguishedName)); var dn = new DistinguishedName(this.DistinguishedName); hasChanged = this.DirectoryAgent.AddSidHistory(dn, this.SidHistory, this.SkipMetaUpdate); break; case ADDBPrincipalCommandBase.parameterSetByName: this.WriteVerbose(String.Format("Adding SID history to principal {0}.", this.SamAccountName)); hasChanged = this.DirectoryAgent.AddSidHistory(this.SamAccountName, this.SidHistory, this.SkipMetaUpdate); break; case ADDBObjectCommandBase.parameterSetByGuid: this.WriteVerbose(String.Format("Adding SID history to principal {0}.", this.ObjectGuid)); hasChanged = this.DirectoryAgent.AddSidHistory(this.ObjectGuid, this.SidHistory, this.SkipMetaUpdate); break; case ADDBPrincipalCommandBase.parameterSetBySid: this.WriteVerbose(String.Format("Adding SID history to principal {0}.", this.ObjectSid)); hasChanged = this.DirectoryAgent.AddSidHistory(this.ObjectSid, this.SidHistory, this.SkipMetaUpdate); break; default: // This should never happen: throw new PSInvalidOperationException(Resources.InvalidParameterSetMessage); } this.WriteVerboseResult(hasChanged); }
public void DistinguishedName_SpaceDot() { string dnStr = @"CN=John,OU=Employees,O=adatum Inc.,C=US"; var dn = new DistinguishedName(dnStr); Assert.AreEqual(dn.ToString(), dnStr); Assert.AreEqual(4, dn.Components.Count); }
protected override void ProcessRecord() { //TODO: Exception handling: Object not found, malformed DN, ... // TODO: Extract as Resource string verboseMessage = "Setting the primary group of account {0}."; bool hasChanged; switch (this.ParameterSetName) { case parameterSetByDN: this.WriteVerbose(String.Format(verboseMessage, this.DistinguishedName)); var dn = new DistinguishedName(this.DistinguishedName); hasChanged = this.DirectoryAgent.SetPrimaryGroupId(dn, this.PrimaryGroupId, this.SkipMetaUpdate); break; case parameterSetByName: this.WriteVerbose(String.Format(verboseMessage, this.SamAccountName)); hasChanged = this.DirectoryAgent.SetPrimaryGroupId(this.SamAccountName, this.PrimaryGroupId, this.SkipMetaUpdate); break; case parameterSetByGuid: this.WriteVerbose(String.Format(verboseMessage, this.ObjectGuid)); hasChanged = this.DirectoryAgent.SetPrimaryGroupId(this.ObjectGuid, this.PrimaryGroupId, this.SkipMetaUpdate); break; case parameterSetBySid: this.WriteVerbose(String.Format(verboseMessage, this.ObjectSid)); hasChanged = this.DirectoryAgent.SetPrimaryGroupId(this.ObjectSid, this.PrimaryGroupId, this.SkipMetaUpdate); break; default: // This should never happen: throw new PSInvalidOperationException(Resources.InvalidParameterSetMessage); } this.WriteVerboseResult(hasChanged); }
/// <summary> /// /// </summary> /// <param name="dn"></param> /// <returns></returns> /// <exception cref="DirectoryObjectNotFoundException"></exception> public int Resolve(DistinguishedName dn) { if(dn.Components.Count == 0) { throw new ArgumentException("Empty distinguished name provided.", "dn"); } cursor.CurrentIndex = parentDNTagIndex; // Start at the root object int currentDNTag = ADConstants.RootDNTag; foreach(var component in dn.Components.Reverse()) { // Indexed columns: PDNT_col, name bool found = cursor.GotoKey(Key.Compose(currentDNTag, component.Value)); if(!found) { throw new DirectoryObjectNotFoundException(dn); } // Test AttrTyp int foundRdnAttId = cursor.RetrieveColumnAsInt(schema.FindColumnId(CommonDirectoryAttributes.RDNType)).Value; string foundRdnAttName = schema.FindAttribute(foundRdnAttId).Name; // Compare the found isRDN attribute with the requested one. Case insensitive. if(String.Compare(component.Name, foundRdnAttName, true) != 0) { throw new DirectoryObjectNotFoundException(dn); } // Move to the found object currentDNTag = cursor.RetrieveColumnAsDNTag(schema.FindColumnId(CommonDirectoryAttributes.DNTag)).Value; } return currentDNTag; }
protected override void ProcessRecord() { // TODO: Extract message strings as resources try { switch (this.ParameterSetName) { case parameterSetByDN: var dn = new DistinguishedName(this.DistinguishedName); if (this.ShouldProcess(this.DistinguishedName, "Remove Object from Database")) { this.DirectoryAgent.RemoveObject(dn); } else { // Just test the objects's presence. this.DirectoryAgent.FindObject(dn); } break; case parameterSetByGuid: if (this.ShouldProcess(this.ObjectGuid.ToString(), "Remove Object from Database")) { this.DirectoryAgent.RemoveObject(this.ObjectGuid); } else { // Just test the objects's presence. this.DirectoryAgent.FindObject(this.ObjectGuid); } break; default: // This should never happen: throw new PSInvalidOperationException(Resources.InvalidParameterSetMessage); } } catch(DirectoryObjectNotFoundException ex) { var error = new ErrorRecord(ex, "RemoveADDBObject_NotFound", ErrorCategory.ObjectNotFound, ex.ObjectIdentifier); this.WriteError(error); } }
/// <summary> /// /// </summary> /// <param name="dnTag"></param> /// <returns></returns> /// <exception cref="DirectoryObjectNotFoundException"></exception> public DistinguishedName Resolve(int dnTag) { if(dnTag < ADConstants.RootDNTag) { throw new ArgumentOutOfRangeException("dnTag"); } if(dnTag == ADConstants.RootDNTag) { // TODO: or null? return new DistinguishedName(); } // TODO: Move to constructor? var dntColId = schema.FindColumnId(CommonDirectoryAttributes.DNTag); var pdntColId = schema.FindColumnId(CommonDirectoryAttributes.ParentDNTag); var rdnColId = schema.FindColumnId(CommonDirectoryAttributes.RDN); var rdnTypeColId = schema.FindColumnId(CommonDirectoryAttributes.RDNType); DistinguishedName dn = new DistinguishedName(); cursor.CurrentIndex = schema.FindIndexName(CommonDirectoryAttributes.DNTag); int currentDNTag = dnTag; do { bool found = cursor.GotoKey(Key.Compose(currentDNTag)); if(!found) { throw new DirectoryObjectNotFoundException(dnTag); } string name = cursor.RetrieveColumnAsString(rdnColId); int rdnType = cursor.RetrieveColumnAsInt(rdnTypeColId).Value; string rdnAtt = schema.FindAttribute(rdnType).Name.ToUpper(); dn.AddParent(rdnAtt, name); currentDNTag = cursor.RetrieveColumnAsDNTag(pdntColId).Value; } while (currentDNTag != ADConstants.RootDNTag); // TODO: Parent DN Caching return dn; }
public void DistinguishedName_QuotesSingle() { var dn = new DistinguishedName(@"OU=""John is cool"""); Assert.AreEqual(dn.ToString(), "OU=John is cool"); }
public void DistinguishedName_HexEncodedBinaryValueEnd() { var dn = new DistinguishedName("CN=John,OU=Employees,DC=adatum,DC=#324312af34e4"); Assert.AreEqual(dn.ToString(), "CN=John,OU=Employees,DC=adatum,DC=#324312af34e4"); }
public void DistinguishedName_HexEncodedBinaryValueSingle() { var dn = new DistinguishedName("CN=#324312af34e4"); Assert.AreEqual(dn.ToString(), "CN=#324312af34e4"); }
public void DistinguishedName_BlankRDNValue() { var dn = new DistinguishedName("CN=,OU=Employees,DC=adatum,DC=com"); }
public void DistinguishedName_Empty() { var dn = new DistinguishedName(String.Empty); Assert.AreEqual(dn.ToString(), String.Empty); }
public void DistinguishedName_EscapedComma() { string dnStr = @"CN=Doe\, John,OU=Employees,DC=adatum,DC=com"; var dn = new DistinguishedName(dnStr); Assert.AreEqual( dnStr, dn.ToString()); }
public void DistinguishedName_QuotesEnd() { var dn = new DistinguishedName(@"OU=John,OU=is,OU=""cool"""); Assert.AreEqual(dn.ToString(), "OU=John,OU=is,OU=cool"); }
public static DistinguishedName GetDNFromDNSName(string domainName) { Validator.AssertNotNullOrWhiteSpace(domainName, "domainName"); var dn = new DistinguishedName(); var dnsComponents = domainName.Split(dnsNameSeparator); foreach(var component in dnsComponents) { dn.AddParent(CommonDirectoryAttributes.DomainComponent, component); } return dn; }
public static string GetDnsNameFromDN(string dn) { var dnParsed = new DistinguishedName(dn); return dnParsed.GetDnsName(); }
public void DistinguishedName_EscapedSpecialChars() { var dn = new DistinguishedName(@"OU=""\,\=\+\<\>\#\;\\\ """); Assert.AreEqual(dn.ToString(), @"OU=\,\=\+\<\>\#\;\\\ "); }
public void AddChild(DistinguishedName dn) { foreach (var component in dn.Components.Reverse()) { this.AddChild(component); } }
public void DistinguishedName_UnterminatedQuotes() { var dn = new DistinguishedName(@"OU=""John is cool"); }
public void DistinguishedName_DCNaming() { string dnStr = @"CN=John,OU=Employees,DC=adatum,DC=com"; var dn = new DistinguishedName(dnStr); Assert.AreEqual(dn.ToString(), dnStr); }
public void DistinguishedName_LongSpaces() { var dn = new DistinguishedName(@" CN = John , OU = Employees,DC = adatum,DC = com"); Assert.AreEqual(dn.ToString(), "CN=John,OU=Employees,DC=adatum,DC=com"); }
public void DistinguishedName_SpacesAtBeginningAndEnd() { var dn = new DistinguishedName(@"CN=\ John \ "); Assert.AreEqual(dn.ToString(), @"CN=\ John \ "); }
public void DistinguishedName_AllSpaces() { var dn = new DistinguishedName(" "); }
public void DistinguishedName_HexEscapeNonSpecialCharacter() { var dn = new DistinguishedName(@"CN=John\20Doe,OU=Employees,DC=adatum,DC=com"); Assert.AreEqual(dn.ToString(), @"CN=John Doe,OU=Employees,DC=adatum,DC=com"); }
public void DistinguishedName_MalformedRDN() { var dn = new DistinguishedName("CN=John,Employees,DC=adatum,DC=com"); }
public void DistinguishedName_UnescapedSpecialCharacter() { var dn = new DistinguishedName(@"CN=Winkin, Blinkin, and Nod,OU=Employees,DC=adatum,DC=com"); }
public void DistinguishedName_HexEncodedBinaryValueMiddle() { var dn = new DistinguishedName("CN=John,OU=#324312af34e4,DC=adatum,DC=com"); Assert.AreEqual(dn.ToString(), "CN=John,OU=#324312af34e4,DC=adatum,DC=com"); }
public void DistinguishedName_OIDs() { string dnStr1 = @"OID.3.43.128=John"; string dnStr2 = @"3.43.128=John"; var dn1 = new DistinguishedName(dnStr1); var dn2 = new DistinguishedName(dnStr2); Assert.AreEqual(dn1.ToString(), dnStr1); Assert.AreEqual(dn1.Components.Count, 1); Assert.AreEqual(dn2.ToString(), dnStr2); Assert.AreEqual(dn2.Components.Count, 1); }
public void DistinguishedName_RDNComponentCount() { var dn = new DistinguishedName("CN=John,OU=Employees,DC=adatum,DC=com"); Assert.AreEqual(dn.Components.Count, 4); }
public abstract void ReadAttribute(string name, out DistinguishedName value);