Exemplo n.º 1
0
        internal virtual ErrorRecord ConstructErrorRecord(Exception e)
        {
            object         obj;
            IADErrorTarget aDErrorTarget = this as IADErrorTarget;
            IHasErrorCode  hasErrorCode  = e as IHasErrorCode;
            string         str           = "ActiveDirectoryCmdlet:";

            if (hasErrorCode == null)
            {
                if (e != null)
                {
                    str = string.Concat(str, e.GetType().ToString());
                }
            }
            else
            {
                int errorCode = hasErrorCode.ErrorCode;
                str = string.Concat("ActiveDirectoryServer:", errorCode.ToString());
            }
            Exception exception = e;
            string    str1      = str;

            if (aDErrorTarget != null)
            {
                obj = aDErrorTarget.CurrentIdentity(e);
            }
            else
            {
                obj = null;
            }
            return(ADUtilities.GetErrorRecord(exception, str1, obj));
        }
 private bool SetADPrincipalGroupMembershipProcessCSRoutine()
 {
     if (this._cmdletParameters.Contains("Identity"))
     {
         ADPrincipal item = this._cmdletParameters["Identity"] as ADPrincipal;
         this.SetPipelinedSessionInfo(item.SessionInfo);
         CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();
         this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
         base.ValidateParameters();
         this.ValidateMemberOfParameter();
         try
         {
             ADPrincipal extendedObjectFromIdentity = this._factory.GetExtendedObjectFromIdentity(item, cmdletSessionInfo.DefaultPartitionPath);
             this._validExtendedPrincipalList.Add(extendedObjectFromIdentity);
         }
         catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
         {
             ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
             base.ThrowTerminatingError(ADUtilities.GetErrorRecord(aDIdentityNotFoundException, "SetADPrincipalGroupMembership:ProcessRecordOverride", item));
         }
         return(true);
     }
     else
     {
         object[] objArray = new object[1];
         objArray[0] = "Identity";
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray));
     }
 }
Exemplo n.º 3
0
        private void ValidateSubjectsAndAddToList()
        {
            object item = this._cmdletParameters["Subjects"];

            ADPrincipal[] aDPrincipalArray = item as ADPrincipal[];
            if (aDPrincipalArray == null)
            {
                ADPrincipal aDPrincipal = item as ADPrincipal;
                if (aDPrincipal != null)
                {
                    ADPrincipal[] aDPrincipalArray1 = new ADPrincipal[1];
                    aDPrincipalArray1[0] = aDPrincipal;
                    aDPrincipalArray     = aDPrincipalArray1;
                }
            }
            ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>();

            if (aDPrincipalArray[0].IsSearchResult)
            {
                this.SetPipelinedSessionInfo(aDPrincipalArray[0].SessionInfo);
            }
            CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();

            aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            if (aDPrincipalArray != null)
            {
                new Hashtable();
                ADPrincipal[] aDPrincipalArray2 = aDPrincipalArray;
                for (int i = 0; i < (int)aDPrincipalArray2.Length; i++)
                {
                    ADPrincipal aDPrincipal1 = aDPrincipalArray2[i];
                    try
                    {
                        ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDPrincipal1, cmdletSessionInfo.DefaultPartitionPath);
                        this._appliesToDNList.Add(directoryObjectFromIdentity.DistinguishedName);
                    }
                    catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                    {
                        ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                        DebugLogger.LogError("SetADFineGrainedPasswordPolicySubject", aDIdentityNotFoundException.ToString());
                        base.ThrowTerminatingError(ADUtilities.GetErrorRecord(aDIdentityNotFoundException, "SetADFineGrainedPasswordPolicySubject:ValidateSubjectsAndAddToList", aDPrincipal1));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private bool MoveADDirectoryServerProcessCSRoutine()
        {
            this._identityDSObj = this._cmdletParameters["Identity"] as ADDirectoryServer;
            base.SetPipelinedSessionInfo(this._identityDSObj.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();
            ADDirectoryServerFactory <ADDirectoryServer> aDDirectoryServerFactory = new ADDirectoryServerFactory <ADDirectoryServer>();

            aDDirectoryServerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            ADObject         directoryObjectFromIdentity = aDDirectoryServerFactory.GetDirectoryObjectFromIdentity(this._identityDSObj, cmdletSessionInfo.DefaultPartitionPath);
            string           str = string.Concat("CN=Servers,", this._siteDirObj.DistinguishedName);
            ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base);

            using (aDObjectSearcher)
            {
                aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                ADObject aDObject = aDObjectSearcher.FindOne();
                if (aDObject == null)
                {
                    base.ThrowTerminatingError(ADUtilities.GetErrorRecord(new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])), "MoveADDirectoryServer:ProcessRecord", str));
                }
                StringBuilder stringBuilder = new StringBuilder("Move-ADObject -identity $args[0]  -Partition $args[1]  -TargetPath $args[2] ");
                try
                {
                    object[] configurationNamingContext = new object[3];
                    configurationNamingContext[0] = directoryObjectFromIdentity;
                    configurationNamingContext[1] = cmdletSessionInfo.ADRootDSE.ConfigurationNamingContext;
                    configurationNamingContext[2] = aDObject.DistinguishedName;
                    base.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.Output, null, configurationNamingContext);
                }
                catch (RuntimeException runtimeException1)
                {
                    RuntimeException runtimeException  = runtimeException1;
                    object[]         distinguishedName = new object[3];
                    distinguishedName[0] = directoryObjectFromIdentity.DistinguishedName;
                    distinguishedName[1] = this._siteDirObj.DistinguishedName;
                    distinguishedName[2] = runtimeException.Message;
                    string str1 = string.Format(CultureInfo.CurrentCulture, "Failed moving the directory server: {0} to new site: {1}. Error:  {2}", distinguishedName);
                    DebugLogger.LogError("MoveADDirectoryServer", str1);
                    base.WriteError(new ErrorRecord(runtimeException, "0", ErrorCategory.WriteError, this._identityDSObj));
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        private bool GetADRootDSEBeginCSRoutine()
        {
            bool flag;
            Collection <string> strs = new Collection <string>();

            string[] item = this._cmdletParameters["Properties"] as string[];
            strs.Add("*");
            if (item != null)
            {
                for (int i = 0; i < (int)item.Length; i++)
                {
                    strs.Add(item[i]);
                }
            }
            ADObjectSearcher aDObjectSearcher = null;

            using (aDObjectSearcher)
            {
                try
                {
                    aDObjectSearcher = new ADObjectSearcher(this.GetSessionInfo());
                    ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(strs);
                    rootDSE.SessionInfo = base.GetCmdletSessionInfo().ADSessionInfo;
                    base.WriteObject(rootDSE);
                    flag = true;
                }
                catch (ADException aDException1)
                {
                    ADException aDException = aDException1;
                    base.WriteError(ADUtilities.GetErrorRecord(aDException, "GetADRootDSE:BeginProcessing:ADError", null));
                    flag = false;
                }
                catch (AuthenticationException authenticationException1)
                {
                    AuthenticationException authenticationException = authenticationException1;
                    base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "GetADRootDSE:BeginProcessing:InvalidCredentials", null));
                    flag = false;
                }
            }
            return(flag);
        }
        protected internal virtual void WritePropertiesToOutput(O inputIdentity, ADEntity constructedIdentityObject)
        {
            bool flag = false;

            if (constructedIdentityObject == null)
            {
                DebugLogger.LogInfo("ADGetPropertiesCmdletBase", string.Format("Identity: {0} not found", inputIdentity));
            }
            else
            {
                CmdletSessionInfo         cmdletSessionInfo = this.GetCmdletSessionInfo();
                ADPropertyValueCollection item = constructedIdentityObject[this.SourceProperty];
                RO rO = Activator.CreateInstance <RO>();
                if (item == null)
                {
                    DebugLogger.LogInfo("ADGetPropertiesCmdletBase", string.Format("Could  not find property: {0} for identity: {1}", this.SourceProperty, inputIdentity));
                    return;
                }
                else
                {
                    List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(this._pageSize);
                    foreach (string str in item)
                    {
                        try
                        {
                            string str1 = this.ExtractIdentityInfoFromSourcePropertyValue(str, out flag);
                            if (str1 != null)
                            {
                                rO.Identity = str1;
                                if (!flag)
                                {
                                    RO extendedObjectFromIdentity = this._returnObjectFactory.GetExtendedObjectFromIdentity(rO, cmdletSessionInfo.DefaultPartitionPath);
                                    base.WriteObject(extendedObjectFromIdentity);
                                }
                                else
                                {
                                    IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", Utils.EscapeDNForFilter(str1));
                                    aDOPathNodes.Add(aDOPathNode);
                                    if (aDOPathNodes.Count >= this._pageSize)
                                    {
                                        this.WriteObjectsInBatch(aDOPathNodes);
                                        aDOPathNodes.Clear();
                                    }
                                }
                            }
                            else
                            {
                                DebugLogger.LogInfo("ADGetPropertiesCmdletBase", string.Format("ExtractIdentityInfoFromSourcePropertyValue returned NULL for propertyValue: {0} - skipping this value", str));
                            }
                        }
                        catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                        {
                            ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                            base.WriteError(ADUtilities.GetErrorRecord(aDIdentityNotFoundException, "ADGetPropertiesCmdletBase:WritePropertiesToOutput", str));
                        }
                    }
                    if (aDOPathNodes.Count > 0)
                    {
                        this.WriteObjectsInBatch(aDOPathNodes);
                        aDOPathNodes.Clear();
                        return;
                    }
                }
            }
        }