Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        internal override void PerServerProcessRecord()
        {
            ADEntity          rootDSE;
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();

            this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
            string[] strArrays = new string[2];
            strArrays[0] = "msDS-ReplConnectionFailures";
            strArrays[1] = "msDS-ReplLinkFailures";
            string[] strArrays1 = strArrays;
            using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(cmdletSessionInfo.ADSessionInfo))
            {
                rootDSE = aDObjectSearcher.GetRootDSE(strArrays1);
            }
            foreach (ADReplicationFailure extendedObjectFromDirectoryObject in this._factory.GetExtendedObjectFromDirectoryObject(rootDSE, "msDS-ReplLinkFailures", "DS_REPL_KCC_DSA_FAILURE"))
            {
                base.WriteObject(extendedObjectFromDirectoryObject);
            }
            foreach (ADReplicationFailure aDReplicationFailure in this._factory.GetExtendedObjectFromDirectoryObject(rootDSE, "msDS-ReplConnectionFailures", "DS_REPL_KCC_DSA_FAILURE"))
            {
                base.WriteObject(aDReplicationFailure);
            }
        }
Exemplo n.º 3
0
        private bool ADMoveCmdletBaseProcessCSRoutine()
        {
            bool flag;
            O    item = (O)this._cmdletParameters["Identity"];

            this.SetPipelinedSessionInfo(item.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();

            this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
            this.ValidateParameters();
            string   defaultPartitionPath        = this.GetDefaultPartitionPath();
            ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath);

            using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity))
            {
                if (base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Move"))
                {
                    O o = default(O);
                    if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o, this._cmdletParameters, directoryObjectFromIdentity))
                    {
                        aDActiveObject.Update();
                    }
                    string str       = this._cmdletParameters["TargetPath"] as string;
                    string childName = ADPathModule.GetChildName(directoryObjectFromIdentity.DistinguishedName, ADPathFormat.X500);
                    string item1     = null;
                    if (!this._cmdletParameters.Contains("TargetServer"))
                    {
                        aDActiveObject.Move(str, childName);
                    }
                    else
                    {
                        item1 = this._cmdletParameters["TargetServer"] as string;
                        aDActiveObject.CrossDomainMove(str, childName, item1);
                    }
                    O o1 = default(O);
                    this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o1, this._cmdletParameters, directoryObjectFromIdentity);
                    if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru"))
                    {
                        ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo;
                        if (this._cmdletParameters.Contains("TargetServer"))
                        {
                            aDSessionInfo.Server = item1;
                        }
                        string str1 = ADPathModule.MakePath(str, childName, ADPathFormat.X500);
                        F      f    = Activator.CreateInstance <F>();
                        using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo))
                        {
                            ADRootDSE     rootDSE       = aDObjectSearcher.GetRootDSE();
                            ADCmdletCache aDCmdletCache = new ADCmdletCache();
                            aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE);
                            CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, this, this._cmdletParameters);
                            f.SetCmdletSessionInfo(cmdletSessionInfo1);
                            O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str1);
                            base.WriteObject(extendedObjectFromDN);
                            aDCmdletCache.Clear();
                        }
                    }
                    return(true);
                }
                else
                {
                    flag = false;
                }
            }
            return(flag);
        }
Exemplo n.º 4
0
 private bool ADGetADTrustCmdletProcessInputObjectCSRoutine()
 {
     if (this._cmdletParameters.Contains("InputObject"))
     {
         object item = this._cmdletParameters["InputObject"];
         if (item as PSObject != null)
         {
             item = ((PSObject)item).BaseObject;
         }
         ADEntity aDEntity = item as ADEntity;
         string   str      = item as string;
         if (aDEntity == null)
         {
             if (str == null)
             {
                 object[] type = new object[2];
                 type[0] = item.GetType();
                 type[1] = "InputObject";
                 base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, type))));
                 return(false);
             }
             else
             {
                 this._cmdletParameters["Identity"] = new ADTrust(str);
             }
         }
         else
         {
             if (aDEntity.IsSearchResult)
             {
                 if (aDEntity as ADForest != null || aDEntity as ADDomain != null || aDEntity as ADClaimTransformPolicy != null)
                 {
                     CmdletSessionInfo        cmdletSessionInfo      = this.GetCmdletSessionInfo();
                     ADTrustFactory <ADTrust> aDTrustFactory         = new ADTrustFactory <ADTrust>();
                     IADOPathNode             structuralObjectFilter = aDTrustFactory.StructuralObjectFilter;
                     if (aDEntity as ADForest != null || aDEntity as ADDomain != null)
                     {
                         if (!this._cmdletParameters.Contains("Server"))
                         {
                             ADSessionInfo aDSessionInfo = new ADSessionInfo(aDEntity["Name"].Value as string);
                             if (aDEntity as ADForest != null)
                             {
                                 aDSessionInfo.SetDefaultPort(LdapConstants.LDAP_GC_PORT);
                             }
                             if (cmdletSessionInfo.ADSessionInfo != null)
                             {
                                 aDSessionInfo.Credential = cmdletSessionInfo.ADSessionInfo.Credential;
                             }
                             cmdletSessionInfo.ADRootDSE     = null;
                             cmdletSessionInfo.ADSessionInfo = aDSessionInfo;
                             using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo))
                             {
                                 cmdletSessionInfo.ADRootDSE             = aDObjectSearcher.GetRootDSE();
                                 cmdletSessionInfo.ADRootDSE.SessionInfo = aDSessionInfo;
                             }
                             this.SetPipelinedSessionInfo(aDSessionInfo);
                         }
                         else
                         {
                             base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerParameterNotSupported, new object[0]))));
                             return(false);
                         }
                     }
                     else
                     {
                         IADOPathNode   aDOPathNode      = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-EgressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string);
                         IADOPathNode   aDOPathNode1     = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-IngressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string);
                         IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
                         aDOPathNodeArray[0]    = aDOPathNode;
                         aDOPathNodeArray[1]    = aDOPathNode1;
                         structuralObjectFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray);
                     }
                     base.BuildPropertySet();
                     this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
                     base.ValidateParameters();
                     base.OutputSearchResults(structuralObjectFilter);
                     return(false);
                 }
                 else
                 {
                     if (aDEntity as ADTrust == null)
                     {
                         if (string.Compare(this._factory.StructuralObjectClass, aDEntity["ObjectClass"].Value as string, StringComparison.OrdinalIgnoreCase) == 0)
                         {
                             this._cmdletParameters["Identity"] = new ADTrust((string)aDEntity["DistinguishedName"].Value);
                         }
                         else
                         {
                             object[] objArray = new object[2];
                             objArray[0] = aDEntity.GetType();
                             objArray[1] = "InputObject";
                             base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, objArray))));
                             return(false);
                         }
                     }
                     else
                     {
                         this._cmdletParameters["Identity"] = (ADTrust)aDEntity;
                     }
                 }
             }
             else
             {
                 base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0]))));
                 return(false);
             }
         }
     }
     return(true);
 }
        private void ValidateMemberOfParameter()
        {
            ADGroup extendedObjectFromIdentity;

            if (!this._isMemberOfValidated)
            {
                this._validExtendedGroupPartitionPairList = new List <SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair>();
                object        item             = this._cmdletParameters["MemberOf"];
                ADPrincipal[] aDPrincipalArray = item as ADGroup[];
                if (aDPrincipalArray == null)
                {
                    ADGroup aDGroup = item as ADGroup;
                    if (aDGroup != null)
                    {
                        ADGroup[] aDGroupArray = new ADGroup[1];
                        aDGroupArray[0]  = aDGroup;
                        aDPrincipalArray = aDGroupArray;
                    }
                }
                if (aDPrincipalArray != null)
                {
                    new Hashtable();
                    ADGroupFactory <ADGroup> aDGroupFactory    = new ADGroupFactory <ADGroup>();
                    CmdletSessionInfo        cmdletSessionInfo = base.GetCmdletSessionInfo();
                    aDGroupFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADPrincipal[] aDPrincipalArray1 = aDPrincipalArray;
                    for (int i = 0; i < (int)aDPrincipalArray1.Length; i++)
                    {
                        ADGroup aDGroup1 = (ADGroup)aDPrincipalArray1[i];
                        try
                        {
                            if (!aDGroup1.IsSearchResult)
                            {
                                extendedObjectFromIdentity = aDGroupFactory.GetExtendedObjectFromIdentity(aDGroup1, cmdletSessionInfo.DefaultPartitionPath);
                                this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity));
                            }
                            else
                            {
                                extendedObjectFromIdentity = aDGroup1;
                                using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(extendedObjectFromIdentity.SessionInfo))
                                {
                                    ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE();
                                    string    str     = ADForestPartitionInfo.ExtractAndValidatePartitionInfo(rootDSE, extendedObjectFromIdentity.DistinguishedName);
                                    this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity, str));
                                }
                            }
                        }
                        catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                        {
                            ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                            DebugLogger.LogError("SetADPrincipalGroupMembership", aDIdentityNotFoundException.ToString());
                            base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADPrincipalGroupMembership:ValidateMemberOfParameter", ErrorCategory.ObjectNotFound, aDGroup1));
                        }
                    }
                }
                this._isMemberOfValidated = true;
                return;
            }
            else
            {
                return;
            }
        }
Exemplo n.º 6
0
        private bool SyncADObjectProcessCSRoutine()
        {
            CmdletSessionInfo cmdletSessionInfo;
            ADRootDSE         rootDSE;
            ADObject          directoryObjectFromIdentity;
            bool   flag;
            string empty;

            this.ValidateParameters();
            ADObject obj         = this._cmdletParameters.Object;
            string   destination = this._cmdletParameters.Destination;

            if (this.sourceServer == null)
            {
                if (!obj.IsSearchResult)
                {
                    if (this.currentADDriveServer == null)
                    {
                        object[] objArray = new object[1];
                        objArray[0] = "Source";
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray));
                    }
                    else
                    {
                        this.sourceServer = this.currentADDriveServer;
                    }
                }
                else
                {
                    this.sourceServer = obj.SessionInfo.Server;
                }
            }
            try
            {
                cmdletSessionInfo = this.GetCmdletSessionInfo();
            }
            catch (ADServerDownException aDServerDownException1)
            {
                ADServerDownException aDServerDownException = aDServerDownException1;
                object[] objArray1 = new object[1];
                objArray1[0] = destination;
                throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDown, objArray1), aDServerDownException.InnerException, destination);
            }
            if (!cmdletSessionInfo.ADRootDSE.IsWritable() || !this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly"))
            {
                string        dSServiceName = null;
                ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy();
                aDSessionInfo.Server = this.sourceServer;
                string distinguishedName = null;
                using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo))
                {
                    try
                    {
                        rootDSE       = aDObjectSearcher.GetRootDSE();
                        dSServiceName = rootDSE.DSServiceName;
                    }
                    catch (ADIdentityNotFoundException aDIdentityNotFoundException)
                    {
                        object[] objArray2 = new object[1];
                        objArray2[0] = this.sourceServer;
                        throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerDown, objArray2), this.sourceServer);
                    }
                    if (!obj.IsSearchResult)
                    {
                        ADCmdletCache aDCmdletCache = new ADCmdletCache();
                        aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE);
                        CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, null, this._cmdletParameters);
                        this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo1);
                        try
                        {
                            directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo1.DefaultPartitionPath);
                            distinguishedName           = directoryObjectFromIdentity.DistinguishedName;
                        }
                        catch (ADIdentityNotFoundException aDIdentityNotFoundException2)
                        {
                            this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                            try
                            {
                                directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo.DefaultPartitionPath);
                                Guid?objectGuid = directoryObjectFromIdentity.ObjectGuid;
                                distinguishedName = string.Concat("<GUID=", objectGuid.ToString(), ">");
                            }
                            catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                            {
                                object[] str = new object[1];
                                str[0] = obj.ToString();
                                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectToReplicateNotFoundOnSource, str));
                            }
                        }
                        aDCmdletCache.Clear();
                    }
                    else
                    {
                        distinguishedName = obj.DistinguishedName;
                    }
                }
                ADObject aDObject = new ADObject();
                aDObject.DistinguishedName = "";
                string str1 = string.Concat(dSServiceName, ":", distinguishedName);
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly"))
                {
                    str1 = string.Concat(str1, ":SECRETS_ONLY");
                }
                aDObject.Add("replicateSingleObject", str1);
                aDObject.TrackChanges = false;
                using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject))
                {
                    if (base.ShouldProcessOverride(obj.IdentifyingString, "Sync"))
                    {
                        try
                        {
                            aDActiveObject.Update();
                        }
                        catch (ADIdentityNotFoundException aDIdentityNotFoundException3)
                        {
                            object[] objArray3 = new object[2];
                            objArray3[0] = this.sourceServer;
                            objArray3[1] = destination;
                            throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerObjNotFoundOrObjToReplicateNotFound, objArray3));
                        }
                        catch (ArgumentException argumentException1)
                        {
                            ArgumentException argumentException = argumentException1;
                            Win32Exception    win32Exception    = new Win32Exception(0x200a);
                            if (string.Compare(win32Exception.Message, 0, argumentException.Message, 0, win32Exception.Message.Length, StringComparison.OrdinalIgnoreCase) != 0 || string.Compare("replicateSingleObject", argumentException.ParamName, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                throw argumentException;
                            }
                            else
                            {
                                object[] objArray4 = new object[1];
                                objArray4[0] = destination;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDoesNotSupportSynchronizingObject, objArray4));
                            }
                        }
                        if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru"))
                        {
                            this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                            ADObject extendedObjectFromDN = this._adObjectFactory.GetExtendedObjectFromDN(distinguishedName);
                            base.WriteObject(extendedObjectFromDN);
                        }
                        return(false);
                    }
                    else
                    {
                        flag = false;
                    }
                }
                return(flag);
            }
            else
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                string      passwordOnlySwitchAllowedOnlyOnRODC = StringResources.PasswordOnlySwitchAllowedOnlyOnRODC;
                object[]    objArray5   = new object[1];
                object[]    objArray6   = objArray5;
                int         num         = 0;
                string      dNSHostName = cmdletSessionInfo.ADRootDSE.DNSHostName;
                int?        portLDAP    = cmdletSessionInfo.ADRootDSE.PortLDAP;
                if (!portLDAP.HasValue)
                {
                    empty = string.Empty;
                }
                else
                {
                    int?nullable = cmdletSessionInfo.ADRootDSE.PortLDAP;
                    empty = string.Concat(":", nullable.ToString());
                }
                objArray6[num] = string.Concat(dNSHostName, empty);
                throw new ArgumentException(string.Format(currentCulture, passwordOnlySwitchAllowedOnlyOnRODC, objArray5));
            }
        }