Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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);
        }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 9
0
 public void DistinguishedName_QuotesSingle()
 {
     var dn = new DistinguishedName(@"OU=""John is cool""");
     Assert.AreEqual(dn.ToString(), "OU=John is cool");
 }
Ejemplo n.º 10
0
 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");
 }
Ejemplo n.º 11
0
 public void DistinguishedName_HexEncodedBinaryValueSingle()
 {
     var dn = new DistinguishedName("CN=#324312af34e4");
     Assert.AreEqual(dn.ToString(), "CN=#324312af34e4");
 }
Ejemplo n.º 12
0
 public void DistinguishedName_BlankRDNValue()
 {
     var dn = new DistinguishedName("CN=,OU=Employees,DC=adatum,DC=com");
 }
Ejemplo n.º 13
0
 public void DistinguishedName_Empty()
 {
     var dn = new DistinguishedName(String.Empty);
     Assert.AreEqual(dn.ToString(), String.Empty);
 }
Ejemplo n.º 14
0
 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());
 }
Ejemplo n.º 15
0
 public void DistinguishedName_QuotesEnd()
 {
     var dn = new DistinguishedName(@"OU=John,OU=is,OU=""cool""");
     Assert.AreEqual(dn.ToString(), "OU=John,OU=is,OU=cool");
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
 public static string GetDnsNameFromDN(string dn)
 {
     var dnParsed = new DistinguishedName(dn);
     return dnParsed.GetDnsName();
 }
Ejemplo n.º 18
0
 public void DistinguishedName_EscapedSpecialChars()
 {
     var dn = new DistinguishedName(@"OU=""\,\=\+\<\>\#\;\\\ """);
     Assert.AreEqual(dn.ToString(), @"OU=\,\=\+\<\>\#\;\\\ ");
 }
Ejemplo n.º 19
0
 public void AddChild(DistinguishedName dn)
 {
     foreach (var component in dn.Components.Reverse())
     {
         this.AddChild(component);
     }
 }
Ejemplo n.º 20
0
 public void DistinguishedName_UnterminatedQuotes()
 {
     var dn = new DistinguishedName(@"OU=""John is cool");
 }
Ejemplo n.º 21
0
 public void DistinguishedName_DCNaming()
 {
     string dnStr = @"CN=John,OU=Employees,DC=adatum,DC=com";
     var dn = new DistinguishedName(dnStr);
     Assert.AreEqual(dn.ToString(), dnStr);
 }
Ejemplo n.º 22
0
 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");
 }
Ejemplo n.º 23
0
 public void DistinguishedName_SpacesAtBeginningAndEnd()
 {
     var dn = new DistinguishedName(@"CN=\     John    \ ");
     Assert.AreEqual(dn.ToString(), @"CN=\     John    \ ");
 }
Ejemplo n.º 24
0
 public void DistinguishedName_AllSpaces()
 {
     var dn = new DistinguishedName("     ");
 }
Ejemplo n.º 25
0
 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");
 }
Ejemplo n.º 26
0
 public void DistinguishedName_MalformedRDN()
 {
     var dn = new DistinguishedName("CN=John,Employees,DC=adatum,DC=com");
 }
Ejemplo n.º 27
0
 public void DistinguishedName_UnescapedSpecialCharacter()
 {
     var dn = new DistinguishedName(@"CN=Winkin, Blinkin, and Nod,OU=Employees,DC=adatum,DC=com");
 }
Ejemplo n.º 28
0
 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");
 }
Ejemplo n.º 29
0
 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);
 }
Ejemplo n.º 30
0
 public void DistinguishedName_RDNComponentCount()
 {
     var dn = new DistinguishedName("CN=John,OU=Employees,DC=adatum,DC=com");
     Assert.AreEqual(dn.Components.Count, 4);
 }
Ejemplo n.º 31
0
 public abstract void ReadAttribute(string name, out DistinguishedName value);