Exemplo n.º 1
0
        private bool ADTargetScopeEnumerationServerPreProcessPipelineCSRoutine()
        {
            if (!this._cmdletParameters.ContainsKey("Target"))
            {
                ADScopeType?item = (ADScopeType?)(this._cmdletParameters["Scope"] as ADScopeType?);
                if (item.Value != ADScopeType.Server)
                {
                    CmdletSessionInfo  cmdletSessionInfo  = this.GetCmdletSessionInfo();
                    ADDomainController aDDomainController = new ADDomainController(cmdletSessionInfo.ADRootDSE.DNSHostName);
                    ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();
                    aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADDomainController extendedObjectFromIdentity = aDDomainControllerFactory.GetExtendedObjectFromIdentity(aDDomainController, null, null, false);
                    ADScopeType?       nullable       = (ADScopeType?)(this._cmdletParameters["Scope"] as ADScopeType?);
                    ADScopeType        valueOrDefault = nullable.GetValueOrDefault();
                    if (nullable.HasValue)
                    {
                        switch (valueOrDefault)
                        {
                        case ADScopeType.Domain:
                        {
                            string[] domain = new string[1];
                            domain[0] = extendedObjectFromIdentity.Domain;
                            this._cmdletParameters["Target"] = domain;
                            break;
                        }

                        case ADScopeType.Forest:
                        {
                            string[] forest = new string[1];
                            forest[0] = extendedObjectFromIdentity.Forest;
                            this._cmdletParameters["Target"] = forest;
                            break;
                        }

                        case ADScopeType.Site:
                        {
                            string[] site = new string[1];
                            site[0] = extendedObjectFromIdentity.Site;
                            this._cmdletParameters["Target"] = site;
                            break;
                        }
                        }
                    }
                }
                else
                {
                    throw new ADException(StringResources.ServerTargetParameterNotSpecified);
                }
            }
            return(true);
        }
        private bool SetADDCPrpProcessCSRoutine()
        {
            this._identityDCObj = this._cmdletParameters["Identity"] as ADDomainController;
            this.SetPipelinedSessionInfo(this._identityDCObj.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();
            ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();

            aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            ADObject      directoryObjectFromIdentity = aDDomainControllerFactory.GetDirectoryObjectFromIdentity(this._identityDCObj, cmdletSessionInfo.DefaultPartitionPath);
            StringBuilder stringBuilder = new StringBuilder("Set-ADObject -identity $args[0] ");

            if (this._operationType != SetADDCPasswordReplicationPolicyOperationType.AddPasswordReplicationPolicy)
            {
                if (this._operationType == SetADDCPasswordReplicationPolicyOperationType.RemovePasswordReplicationPolicy)
                {
                    stringBuilder.Append(" -Remove ");
                }
            }
            else
            {
                stringBuilder.Append(" -Add ");
            }
            stringBuilder.Append(" $args[1] ");
            if (base.ShouldProcessOverride(directoryObjectFromIdentity.IdentifyingString))
            {
                try
                {
                    object[] objArray = new object[2];
                    objArray[0] = directoryObjectFromIdentity;
                    objArray[1] = this._principalsToAddOrRemove;
                    base.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.Output, null, objArray);
                }
                catch (RuntimeException runtimeException1)
                {
                    RuntimeException runtimeException = runtimeException1;
                    object[]         message          = new object[1];
                    message[0] = runtimeException.Message;
                    string str = string.Format(CultureInfo.CurrentCulture, "Failed adding or removing the password-replication-policy:  {0}", message);
                    DebugLogger.LogError("SetADDCPasswordReplicationPolicy", str);
                    base.WriteError(new ErrorRecord(runtimeException, "0", ErrorCategory.WriteError, this._identityDCObj));
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 private bool ADGetSiteCmdletCalculateIdentityCSRoutine()
 {
     if (this._cmdletParameters["Identity"] == null)
     {
         if (this._cmdletParameters["Filter"] == null)
         {
             CmdletSessionInfo  cmdletSessionInfo  = this.GetCmdletSessionInfo();
             ADDomainController aDDomainController = new ADDomainController(cmdletSessionInfo.ADRootDSE.DNSHostName);
             ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();
             aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
             ADDomainController extendedObjectFromIdentity = aDDomainControllerFactory.GetExtendedObjectFromIdentity(aDDomainController, null, null, false);
             this._cmdletParameters["Identity"] = new ADReplicationSite(extendedObjectFromIdentity.Site);
             return(true);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 4
0
        private bool GetADAcctResPrpProcessCSRoutine()
        {
            ADResultantPasswordReplicationPolicy aDResultantPasswordReplicationPolicy = ADResultantPasswordReplicationPolicy.DenyExplicit;
            int?value;

            this._partitionPath     = this._cmdletParameters["Partition"] as string;
            this._identityADAccount = this._cmdletParameters["Identity"] as ADAccount;
            this._targetDCAccount   = this._cmdletParameters["DomainController"] as ADDomainController;
            base.SetPipelinedSessionInfo(this._identityADAccount.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();

            if (cmdletSessionInfo.ADRootDSE.IsWindows2008AndAbove())
            {
                if (!cmdletSessionInfo.ADRootDSE.IsWritable())
                {
                    object[] dNSHostName = new object[1];
                    dNSHostName[0] = cmdletSessionInfo.ADRootDSE.DNSHostName;
                    base.WriteWarning(string.Format(CultureInfo.CurrentCulture, StringResources.WarningResultantPRPNotAccurateOnRODC, dNSHostName));
                }
                ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();
                aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                ADAccountFactory <ADAccount> aDAccountFactory = new ADAccountFactory <ADAccount>();
                aDAccountFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                ADObject         directoryObjectFromIdentity = aDDomainControllerFactory.GetDirectoryObjectFromIdentity(this._targetDCAccount, cmdletSessionInfo.DefaultPartitionPath);
                ADObject         aDObject          = aDAccountFactory.GetDirectoryObjectFromIdentity(this._identityADAccount, cmdletSessionInfo.DefaultPartitionPath);
                ADObjectSearcher distinguishedName = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity.DistinguishedName, ADSearchScope.Base);
                using (distinguishedName)
                {
                    distinguishedName.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                    distinguishedName.Properties.Add("msDS-IsUserCachableAtRodc");
                    distinguishedName.InputDN = aDObject.DistinguishedName;
                    ADObject aDObject1 = distinguishedName.FindOne();
                    if (aDObject1["msDS-IsUserCachableAtRodc"] == null)
                    {
                        int?nullable = null;
                        value = nullable;
                    }
                    else
                    {
                        value = (int?)aDObject1["msDS-IsUserCachableAtRodc"].Value;
                    }
                    int?nullable1 = value;
                    if (nullable1.HasValue)
                    {
                        if (!Utils.TryParseEnum <ADResultantPasswordReplicationPolicy>(nullable1.ToString(), out aDResultantPasswordReplicationPolicy))
                        {
                            DebugLogger.LogInfo("GetADAccountResultantPasswordReplicationPolicy", string.Format("Error parsing resultant prp: {0} for account {1} on RODC {2}", aDResultantPasswordReplicationPolicy, aDObject.DistinguishedName, directoryObjectFromIdentity.DistinguishedName));
                            base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown);
                        }
                        else
                        {
                            base.WriteObject(aDResultantPasswordReplicationPolicy);
                        }
                    }
                    else
                    {
                        base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown);
                    }
                }
                return(true);
            }
            else
            {
                base.WriteError(new ErrorRecord(new ArgumentException(StringResources.ErrorResultantPRPSpecifyWindows2008OrAbove), "GetADAccountResultantPasswordReplicationPolicy:ProcessRecord", ErrorCategory.InvalidData, null));
                return(false);
            }
        }
Exemplo n.º 5
0
        internal override IADOPathNode IdentitySearchConverter(object identity)
        {
            IADOPathNode aDOPathNode;

            if (identity != null)
            {
                string str = identity as string;
                if (str == null)
                {
                    SecurityIdentifier securityIdentifier = identity as SecurityIdentifier;
                    if (securityIdentifier == null)
                    {
                        if (!(identity is Guid))
                        {
                            ADDomainController aDDomainController = identity as ADDomainController;
                            if (aDDomainController == null)
                            {
                                ADObject aDObject = identity as ADObject;
                                if (aDObject == null)
                                {
                                    throw new ArgumentException(string.Format(StringResources.SearchConverterUnrecognizedObjectType, identity.GetType()));
                                }
                                else
                                {
                                    ADComputer aDComputer = new ADComputer(aDObject);
                                    ADDomainControllerFactory <T> .ADComputerPseudoFactory aDComputerPseudoFactory = new ADDomainControllerFactory <T> .ADComputerPseudoFactory();

                                    aDComputerPseudoFactory.SetCmdletSessionInfo(base.CmdletSessionInfo);
                                    return(aDComputerPseudoFactory.BuildIdentityFilter(aDComputer));
                                }
                            }
                            else
                            {
                                IADOPathNode        aDOPathNode1 = base.IdentitySearchConverter(identity);
                                List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>();
                                if (aDDomainController["ComputerDN"] != null && aDDomainController["ComputerDN"].Value != null)
                                {
                                    aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", Utils.EscapeDNForFilter(aDDomainController["ComputerDN"].Value as string)));
                                }
                                aDOPathNodes.Add(aDOPathNode1);
                                if (aDOPathNodes.Count != 1)
                                {
                                    return(ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray()));
                                }
                                else
                                {
                                    return(aDOPathNodes[0]);
                                }
                            }
                        }
                        else
                        {
                            Guid guid = (Guid)identity;
                            return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", guid.ToByteArray()));
                        }
                    }
                    else
                    {
                        byte[] numArray = new byte[securityIdentifier.BinaryLength];
                        securityIdentifier.GetBinaryForm(numArray, 0);
                        return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", numArray));
                    }
                }
                else
                {
                    Guid?     nullable = null;
                    IPAddress pAddress = null;
                    if (!Utils.TryParseGuid(str, out nullable))
                    {
                        if (!IPAddress.TryParse(str, out pAddress))
                        {
                            List <IADOPathNode> aDOPathNodes1 = this.BuildIdentityFilterListFromString(str);
                            if (aDOPathNodes1.Count <= 1)
                            {
                                return(aDOPathNodes1[0]);
                            }
                            else
                            {
                                return(ADOPathUtil.CreateOrClause(aDOPathNodes1.ToArray()));
                            }
                        }
                        else
                        {
                            try
                            {
                                IPHostEntry hostEntry = Dns.GetHostEntry(pAddress);
                                aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "dNSHostName", hostEntry.HostName);
                            }
                            catch (SocketException socketException1)
                            {
                                SocketException socketException = socketException1;
                                object[]        objArray        = new object[1];
                                objArray[0] = pAddress;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.CannotResolveIPAddressToHostName, objArray), socketException);
                            }
                            return(aDOPathNode);
                        }
                    }
                    else
                    {
                        Guid value = nullable.Value;
                        return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value.ToByteArray()));
                    }
                }
            }
            else
            {
                throw new ArgumentNullException("identity");
            }
        }