Example #1
0
 internal override IADOPathNode IdentitySearchConverter(object identity)
 {
     if (identity != null)
     {
         string str = identity as string;
         if (str != null)
         {
             string str1 = ADDomainUtil.FindDomainNCHead(str, base.CmdletSessionInfo);
             if (str1 != null)
             {
                 return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", str1));
             }
         }
         SecurityIdentifier securityIdentifier = identity as SecurityIdentifier;
         if (securityIdentifier == null)
         {
             IADOPathNode aDOPathNode = base.IdentitySearchConverter(identity);
             return(aDOPathNode);
         }
         else
         {
             return(ADDomainUtil.CreateSidFilterClause(securityIdentifier));
         }
     }
     else
     {
         throw new ArgumentNullException("Identity");
     }
 }
Example #2
0
        internal override ADSessionInfo GetSessionInfo()
        {
            ADSessionInfo aDSessionInfo;

            try
            {
                aDSessionInfo = ADDomainUtil.ConstructSessionFromIdentity <SetADForestModeParameterSet, ADForest>(this, base.GetSessionInfo(), false);
            }
            catch (ArgumentException argumentException1)
            {
                ArgumentException argumentException = argumentException1;
                object[]          item = new object[1];
                item[0] = argumentException.Data["IdentityData"];
                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.CouldNotFindForestIdentity, item));
            }
            return(aDSessionInfo);
        }
Example #3
0
        public static ADSessionInfo ConstructSessionFromIdentity <P, T>(ADCmdletBase <P> cmdletInstance, ADSessionInfo baseSessionInfo, bool ignoreNonDomainIdentity)
            where P : ADParameterSet, new()
            where T : ADEntity, new()
        {
            string str = null;
            string str1;
            string item = cmdletInstance._cmdletParameters["Server"] as string;
            object obj  = cmdletInstance._cmdletParameters["Identity"];

            if (item != null || obj == null)
            {
                return(baseSessionInfo);
            }
            else
            {
                if (((ADEntity)obj).Identity == null)
                {
                    str1 = null;
                }
                else
                {
                    str1 = ((ADEntity)obj).Identity.ToString();
                }
                string str2 = str1;
                string str3 = ADDomainUtil.DiscoverDCFromIdentity <T>(obj, out str);
                if (str3 != null)
                {
                    ADSessionInfo aDSessionInfo = baseSessionInfo.Copy();
                    aDSessionInfo.Server = str;
                    return(aDSessionInfo);
                }
                else
                {
                    if (!ignoreNonDomainIdentity)
                    {
                        ArgumentException argumentException = new ArgumentException();
                        argumentException.Data.Add("IdentityData", str2);
                        throw argumentException;
                    }
                    else
                    {
                        return(baseSessionInfo);
                    }
                }
            }
        }
Example #4
0
 internal override ADSessionInfo GetSessionInfo()
 {
     return(ADDomainUtil.ConstructSessionFromIdentity <SetADDomainModeParameterSet, ADDomain>(this, base.GetSessionInfo(), true));
 }
Example #5
0
 internal override IADOPathNode IdentitySearchConverter(object identity)
 {
     if (identity != null)
     {
         if (identity as ADDefaultDomainPasswordPolicy != null)
         {
             ADDefaultDomainPasswordPolicy aDDefaultDomainPasswordPolicy = (ADDefaultDomainPasswordPolicy)identity;
             if (aDDefaultDomainPasswordPolicy.DistinguishedName == null)
             {
                 while (identity as ADDefaultDomainPasswordPolicy != null)
                 {
                     identity = ((ADDefaultDomainPasswordPolicy)identity).Identity;
                 }
             }
             else
             {
                 identity = aDDefaultDomainPasswordPolicy.DistinguishedName;
             }
         }
         string str = identity as string;
         if (str != null)
         {
             string str1 = ADDomainUtil.FindDomainNCHead(str, base.CmdletSessionInfo);
             if (str1 != null)
             {
                 return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", str1));
             }
         }
         SecurityIdentifier securityIdentifier = identity as SecurityIdentifier;
         if (securityIdentifier == null)
         {
             if (identity as string == null)
             {
                 if (!(identity is Guid))
                 {
                     if (identity as ADObject == null)
                     {
                         throw new ArgumentException(string.Format(StringResources.SearchConverterUnrecognizedObjectType, identity.GetType()));
                     }
                     else
                     {
                         ADObject            aDObject     = identity as ADObject;
                         List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(2);
                         if (!string.IsNullOrEmpty(aDObject.DistinguishedName))
                         {
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", aDObject.DistinguishedName));
                         }
                         Guid?objectGuid = aDObject.ObjectGuid;
                         if (objectGuid.HasValue)
                         {
                             Guid?nullable = aDObject.ObjectGuid;
                             Guid value    = nullable.Value;
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value.ToByteArray()));
                         }
                         if (aDOPathNodes.Count != 0)
                         {
                             return(ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray()));
                         }
                         else
                         {
                             throw new ArgumentException(StringResources.SearchConverterIdentityAttributeNotSet);
                         }
                     }
                 }
                 else
                 {
                     Guid guid = (Guid)identity;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", guid.ToByteArray()));
                 }
             }
             else
             {
                 Guid?nullable1 = null;
                 if (!Utils.TryParseGuid(str, out nullable1))
                 {
                     List <IADOPathNode> aDOPathNodes1 = new List <IADOPathNode>((int)ADDefaultDomainPasswordPolicyFactory <T> ._ddppIdentityLdapAttributes.Length);
                     string[]            strArrays     = ADDefaultDomainPasswordPolicyFactory <T> ._ddppIdentityLdapAttributes;
                     for (int i = 0; i < (int)strArrays.Length; i++)
                     {
                         string str2 = strArrays[i];
                         aDOPathNodes1.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str2, str));
                     }
                     if (aDOPathNodes1.Count <= 1)
                     {
                         return(aDOPathNodes1[0]);
                     }
                     else
                     {
                         return(ADOPathUtil.CreateOrClause(aDOPathNodes1.ToArray()));
                     }
                 }
                 else
                 {
                     Guid value1 = nullable1.Value;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value1.ToByteArray()));
                 }
             }
         }
         else
         {
             return(ADDomainUtil.CreateSidFilterClause(securityIdentifier));
         }
     }
     else
     {
         throw new ArgumentNullException("Identity");
     }
 }
Example #6
0
        private bool ADGetDomainCmdletBaseCalculateIdentityCSRoutine()
        {
            bool hasValue;
            bool flag;

            if (this._cmdletParameters["Identity"] == null)
            {
                string defaultNamingContext = null;
                string item = this._cmdletParameters["Server"] as string;
                ADCurrentDomainType?nullable = (ADCurrentDomainType?)(this._cmdletParameters["Current"] as ADCurrentDomainType?);
                if (!nullable.HasValue)
                {
                    if (item != null || ProviderUtils.IsCurrentDriveAD(base.SessionState))
                    {
                        ADRootDSE rootDSE = this.GetRootDSE();
                        defaultNamingContext = rootDSE.DefaultNamingContext;
                    }
                    else
                    {
                        nullable = new ADCurrentDomainType?(ADCurrentDomainType.LoggedOnUser);
                    }
                }
                ADCurrentDomainType?nullable1 = nullable;
                if (nullable1.GetValueOrDefault() != ADCurrentDomainType.LocalComputer)
                {
                    hasValue = false;
                }
                else
                {
                    hasValue = nullable1.HasValue;
                }
                if (!hasValue)
                {
                    ADCurrentDomainType?nullable2 = nullable;
                    if (nullable2.GetValueOrDefault() != ADCurrentDomainType.LoggedOnUser)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = nullable2.HasValue;
                    }
                    if (!flag)
                    {
                        if (nullable.HasValue)
                        {
                            throw new ArgumentException("Current");
                        }
                    }
                    else
                    {
                        defaultNamingContext = base.EffectiveDomainName;
                    }
                }
                else
                {
                    defaultNamingContext = ADDomainUtil.GetLocalComputerDomain();
                    if (defaultNamingContext == null)
                    {
                        throw new ArgumentException(StringResources.CouldNotDetermineLocalComputerDomain);
                    }
                }
                if (defaultNamingContext != null)
                {
                    this._cmdletParameters["Identity"] = this.ConstructObjectFromIdentity(defaultNamingContext);
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
Example #7
0
 public static string DiscoverDCFromIdentity <T>(object identity, out string domainDNSFromIdentity)
     where T : ADEntity, new()
 {
     return(ADDomainUtil.DiscoverDCFromIdentity <T>(identity, false, out domainDNSFromIdentity));
 }
Example #8
0
        private bool ModifyADOptionalFeatureBaseProcessCSRoutine()
        {
            string distinguishedName;
            string str;
            string str1 = null;
            bool   flag;

            if (this._cmdletParameters.Contains("Identity"))
            {
                ADOptionalFeature      item = this._cmdletParameters["Identity"] as ADOptionalFeature;
                ADOptionalFeatureScope aDOptionalFeatureScope = (ADOptionalFeatureScope)this._cmdletParameters["Scope"];
                ADEntity aDEntity = this._cmdletParameters["Target"] as ADEntity;
                this.SetPipelinedSessionInfo(item.SessionInfo);
                CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();
                this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
                if (aDOptionalFeatureScope != ADOptionalFeatureScope.Domain)
                {
                    if (aDOptionalFeatureScope != ADOptionalFeatureScope.ForestOrConfigurationSet)
                    {
                        distinguishedName = null;
                    }
                    else
                    {
                        string    item1   = this._cmdletParameters["Server"] as string;
                        ADRootDSE rootDSE = this.GetRootDSE();
                        if (rootDSE.ServerType != ADServerType.ADDS)
                        {
                            cmdletSessionInfo = this.GetCmdletSessionInfo();
                            ADObjectFactory <ADObject> aDObjectFactory = new ADObjectFactory <ADObject>();
                            aDObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                            ADObject aDObject = new ADObject();
                            aDObject.Identity = aDEntity.Identity;
                            ADObject directoryObjectFromIdentity = aDObjectFactory.GetDirectoryObjectFromIdentity(aDObject, rootDSE.ConfigurationNamingContext, false);
                            string   str2 = X500Path.StripX500Whitespace(directoryObjectFromIdentity.DistinguishedName);
                            if (string.Compare(rootDSE.ConfigurationNamingContext, str2, StringComparison.InvariantCultureIgnoreCase) == 0)
                            {
                                distinguishedName = string.Concat("CN=Partitions,", directoryObjectFromIdentity.DistinguishedName);
                            }
                            else
                            {
                                object[] objArray = new object[1];
                                objArray[0] = aDEntity.Identity.ToString();
                                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ConfigSetNotFound, objArray));
                            }
                        }
                        else
                        {
                            ADRootDSE aDRootDSE = null;
                            if (item1 != null)
                            {
                                aDRootDSE = rootDSE;
                            }
                            if (aDEntity as ADForest == null)
                            {
                                str = ADDomainUtil.DiscoverDCFromIdentity <ADForest>(aDEntity.Identity, out str1);
                            }
                            else
                            {
                                str = ADDomainUtil.DiscoverDCFromIdentity <ADForest>(aDEntity, out str1);
                            }
                            if (str != null)
                            {
                                ADSessionInfo sessionInfo = this.GetSessionInfo();
                                sessionInfo.Server = str1;
                                this.SetPipelinedSessionInfo(sessionInfo);
                                if (aDRootDSE != null)
                                {
                                    ADRootDSE rootDSE1 = this.GetRootDSE();
                                    if (rootDSE1.RootDomainNamingContext == aDRootDSE.RootDomainNamingContext)
                                    {
                                        sessionInfo.Server = item1;
                                        this.SetPipelinedSessionInfo(sessionInfo);
                                    }
                                    else
                                    {
                                        throw new ADIdentityNotFoundException();
                                    }
                                }
                                base.TargetOperationMasterRole(ADOperationMasterRole.DomainNamingMaster);
                                cmdletSessionInfo = this.GetCmdletSessionInfo();
                                this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
                                ADForestFactory <ADForest> aDForestFactory = new ADForestFactory <ADForest>();
                                aDForestFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                                ADForest aDForest = new ADForest(str1);
                                ADObject directoryObjectFromIdentity1 = aDForestFactory.GetDirectoryObjectFromIdentity(aDForest, this.GetRootDSE().DefaultNamingContext, false);
                                distinguishedName = directoryObjectFromIdentity1.DistinguishedName;
                            }
                            else
                            {
                                object[] defaultNamingContext = new object[2];
                                defaultNamingContext[0] = aDEntity.Identity.ToString();
                                defaultNamingContext[1] = this.GetRootDSE().DefaultNamingContext;
                                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, defaultNamingContext));
                            }
                        }
                    }
                }
                else
                {
                    ADDomainFactory <ADDomain> aDDomainFactory = new ADDomainFactory <ADDomain>();
                    aDDomainFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADDomain aDDomain = new ADDomain();
                    if (aDEntity as ADObject == null)
                    {
                        aDDomain = new ADDomain(aDEntity.Identity as string);
                    }
                    else
                    {
                        aDDomain.Identity = aDEntity;
                    }
                    ADObject aDObject1 = aDDomainFactory.GetDirectoryObjectFromIdentity(aDDomain, this.GetRootDSE().DefaultNamingContext, false);
                    distinguishedName = aDObject1.DistinguishedName;
                }
                this.ValidateParameters();
                item = this._factory.GetExtendedObjectFromIdentity(item, this.GetDefaultPartitionPath(), null, false);
                Guid?  featureGUID = item.FeatureGUID;
                string str3        = featureGUID.ToString();
                if (this._action != ModifyADOptionalFeatureBase <P> .ModifyADOptionalFeatureAction.Enable)
                {
                    if (this._action != ModifyADOptionalFeatureBase <P> .ModifyADOptionalFeatureAction.Disable)
                    {
                        throw new NotImplementedException(this._action.ToString());
                    }
                    else
                    {
                        flag = false;
                    }
                }
                else
                {
                    if (!item.IsDisableable)
                    {
                        base.WriteWarning(string.Format(StringResources.EnablingIsIrreversible, item.Name, distinguishedName));
                    }
                    flag = true;
                }
                if (base.ShouldProcessOverride(item.Name, this._action.ToString()))
                {
                    using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(cmdletSessionInfo.ADSessionInfo))
                    {
                        aDTopologyManagement.ChangeOptionalFeature(distinguishedName, flag, str3);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                object[] objArray1 = new object[1];
                objArray1[0] = "Identity,Instance";
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequiredMultiple, objArray1));
            }
        }