コード例 #1
0
ファイル: Domain.cs プロジェクト: nickchal/pash
		public void RaiseDomainFunctionality(DomainMode domainMode)
		{
			base.CheckIfDisposed();
			if (domainMode < DomainMode.Windows2000MixedDomain || domainMode > DomainMode.Windows8Domain)
			{
				throw new InvalidEnumArgumentException("domainMode", (int)domainMode, typeof(DomainMode));
			}
			else
			{
				DomainMode domainMode1 = this.GetDomainMode();
				DirectoryEntry directoryEntry = null;
				using (directoryEntry)
				{
					try
					{
						directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, this.directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext));
						DomainMode domainMode2 = domainMode1;
						if (domainMode2 == DomainMode.Windows2000MixedDomain)
						{
							if (domainMode != DomainMode.Windows2000NativeDomain)
							{
								if (domainMode != DomainMode.Windows2003InterimDomain)
								{
									if (domainMode != DomainMode.Windows2003Domain)
									{
										throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
									}
									else
									{
										directoryEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
										directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
									}
								}
								else
								{
									directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 1;
								}
							}
							else
							{
								directoryEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
							}
						}
						else if (domainMode2 == DomainMode.Windows2000NativeDomain)
						{
							if (domainMode != DomainMode.Windows2003Domain)
							{
								if (domainMode != DomainMode.Windows2008Domain)
								{
									if (domainMode != DomainMode.Windows2008R2Domain)
									{
										if (domainMode != DomainMode.Windows8Domain)
										{
											throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
										}
										else
										{
											directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 5;
										}
									}
									else
									{
										directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 4;
									}
								}
								else
								{
									directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 3;
								}
							}
							else
							{
								directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
							}
						}
						else if (domainMode2 == DomainMode.Windows2003InterimDomain)
						{
							if (domainMode != DomainMode.Windows2003Domain)
							{
								throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
							}
							else
							{
								directoryEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
								directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
							}
						}
						else if (domainMode2 == DomainMode.Windows2003Domain)
						{
							if (domainMode != DomainMode.Windows2008Domain)
							{
								if (domainMode != DomainMode.Windows2008R2Domain)
								{
									if (domainMode != DomainMode.Windows8Domain)
									{
										throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
									}
									else
									{
										directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 5;
									}
								}
								else
								{
									directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 4;
								}
							}
							else
							{
								directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 3;
							}
						}
						else if (domainMode2 == DomainMode.Windows2008Domain)
						{
							if (domainMode != DomainMode.Windows2008R2Domain)
							{
								if (domainMode != DomainMode.Windows8Domain)
								{
									throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
								}
								else
								{
									directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 5;
								}
							}
							else
							{
								directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 4;
							}
						}
						else if (domainMode2 == DomainMode.Windows2008R2Domain)
						{
							if (domainMode != DomainMode.Windows8Domain)
							{
								throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
							}
							else
							{
								directoryEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 5;
							}
						}
						else if (domainMode2 == DomainMode.Windows8Domain)
						{
							throw new ArgumentException(Res.GetString("InvalidMode"), "domainMode");
						}
						else
						{
							throw new ActiveDirectoryOperationException();
						}
						directoryEntry.CommitChanges();
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						if (cOMException.ErrorCode != -2147016694)
						{
							throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
						}
						else
						{
							throw new ArgumentException(Res.GetString("NoW2K3DCs"), "domainMode");
						}
					}
				}
				this.currentDomainMode = DomainMode.Windows2000NativeDomain | DomainMode.Windows2003InterimDomain | DomainMode.Windows2003Domain | DomainMode.Windows2008Domain | DomainMode.Windows2008R2Domain | DomainMode.Windows8Domain;
				return;
			}
		}
コード例 #2
0
	public void RaiseDomainFunctionality(DomainMode domainMode) {}
コード例 #3
0
ファイル: Domain.cs プロジェクト: nickchal/pash
		internal Domain(DirectoryContext context, string domainName, DirectoryEntryManager directoryEntryMgr) : base(context, domainName)
		{
			this.currentDomainMode = DomainMode.Windows2000NativeDomain | DomainMode.Windows2003InterimDomain | DomainMode.Windows2003Domain | DomainMode.Windows2008Domain | DomainMode.Windows2008R2Domain | DomainMode.Windows8Domain;
			this.directoryEntryMgr = directoryEntryMgr;
		}
コード例 #4
0
 public void RaiseDomainFunctionality(DomainMode domainMode)
 {
 }
コード例 #5
0
ファイル: Domain.cs プロジェクト: chcosta/corefx
        public void RaiseDomainFunctionality(DomainMode domainMode)
        {
            DomainMode existingDomainMode;
            CheckIfDisposed();

            // check if domain mode is within the valid range
            if (domainMode < DomainMode.Windows2000MixedDomain || domainMode > DomainMode.Windows2012R2Domain)
            {
                throw new InvalidEnumArgumentException("domainMode", (int)domainMode, typeof(DomainMode));
            }

            // get the current domain mode
            existingDomainMode = GetDomainMode();

            // set the forest mode on AD  
            DirectoryEntry domainEntry = null;

            // CurrentDomain          Valid RequestedDomain      Action
            -----------------
            // Windows2000Mixed        Windows2000Native         ntMixedDomain = 0
            // Windows2000Mixed        Windows2003Interim        msDS-Behavior-Version = 1
            // Windows2000Mixed        Windows2003               ntMixedDomain = 0, msDS-Behavior-Version = 2
            //
            // Windows2003Interim      Windows2003               ntMixedDomain = 0, msDS-Behavior-Version = 2
            //
            // Windows2000Native       Windows2003 or above      
            // Windows2003             Windows2008 or above
            // Windows2008             Windows2008R2 or above 
            // Windows2008R2           Windows2012 or above
            // Windows2012             Windows2012R2 or above
            // Windows2012R2           ERROR

            try
            {
                domainEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext));

                switch (existingDomainMode)
                {
                    case DomainMode.Windows2000MixedDomain:
                        {
                            if (domainMode == DomainMode.Windows2000NativeDomain)
                            {
                                domainEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
                            }
                            else if (domainMode == DomainMode.Windows2003InterimDomain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 1;
                            }
                            else if (domainMode == DomainMode.Windows2003Domain)
                            {
                                domainEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }

                            break;
                        }

                    case DomainMode.Windows2003InterimDomain:
                        {
                            if (domainMode == DomainMode.Windows2003Domain)
                            {
                                domainEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }

                            break;
                        }

                    case DomainMode.Windows2000NativeDomain:
                    case DomainMode.Windows2003Domain:
                    case DomainMode.Windows2008Domain:
                    case DomainMode.Windows2008R2Domain:
                    case DomainMode.Windows8Domain:
                    case DomainMode.Windows2012R2Domain:
                        {
                            if (existingDomainMode >= domainMode)
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }

                            if (domainMode == DomainMode.Windows2003Domain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 2;
                            }
                            else if (domainMode == DomainMode.Windows2008Domain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 3;
                            }
                            else if (domainMode == DomainMode.Windows2008R2Domain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 4;
                            }
                            else if (domainMode == DomainMode.Windows8Domain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 5;
                            }
                            else if (domainMode == DomainMode.Windows2012R2Domain)
                            {
                                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = 6;
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }
                        }
                        break;
                    default:
                        {
                            // should not happen
                            throw new ActiveDirectoryOperationException();
                        }
                }

                // NOTE: 
                // If the domain controller we are talking to is W2K 
                // (more specifically the schema is a W2K schema) then the
                // msDS-Behavior-Version attribute will not be present.
                // If that is the case, the domain functionality cannot be raised
                // to Windows2003InterimDomain or Windows2003Domain (which is when we would set this attribute)
                // since there are only W2K domain controllers
                // So, we catch that exception and throw a more meaningful one.
                domainEntry.CommitChanges();
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x8007200A))
                {
                    // attribute does not exist which means this is not a W2K3 DC
                    // cannot raise domain functionality
                    throw new ArgumentException(Res.GetString(Res.NoW2K3DCs), "domainMode");
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }
            finally
            {
                if (domainEntry != null)
                {
                    domainEntry.Dispose();
                }
            }

            // at this point the raise domain function has succeeded
            // invalidate the domain mode so that we get it from the server the next time
            _currentDomainMode = (DomainMode)(-1);
            _domainModeLevel = -1;
        }
コード例 #6
0
ファイル: Domain.cs プロジェクト: chcosta/corefx
        public void RaiseDomainFunctionalityLevel(int domainMode)
        {
            int existingDomainModeLevel;
            CheckIfDisposed();

            // check if domainMode is within the valid range
            if (domainMode < 0)
            {
                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
            }

            // get the current domain mode
            existingDomainModeLevel = DomainModeLevel;

            if (existingDomainModeLevel >= domainMode)
            {
                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
            }

            DomainMode existingDomainMode = DomainMode;

            // set the forest mode on AD  
            DirectoryEntry domainEntry = null;

            // CurrentDomain          Valid domainMode      Action
            -----------------
            // Windows2000Mixed        0                      ntMixedDomain = 0  msDS-Behavior-Version = 0
            // Windows2000Mixed        1                                         msDS-Behavior-Version = 1
            // Windows2000Mixed        2                      ntMixedDomain = 0, msDS-Behavior-Version = 2
            //
            // Windows2003Interim      2                      ntMixedDomain = 0, msDS-Behavior-Version = 2
            //
            // Rest                2 or above                 msDS-Behavior-Version = domainMode
            try
            {
                domainEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext));

                // set the new functional level
                domainEntry.Properties[PropertyManager.MsDSBehaviorVersion].Value = domainMode;

                switch (existingDomainMode)
                {
                    case DomainMode.Windows2000MixedDomain:
                        {
                            if (domainMode == 2 || domainMode == 0)
                            {
                                domainEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
                            }
                            else if (domainMode > 2) // new level should be less than or equal to Windows2003
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }
                            break;
                        }

                    case DomainMode.Windows2003InterimDomain:
                        {
                            if (domainMode == 2) // only Windows2003 allowed
                            {
                                domainEntry.Properties[PropertyManager.NTMixedDomain].Value = 0;
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString(Res.InvalidMode), "domainMode");
                            }

                            break;
                        }

                    default:
                        break;
                }

                // NOTE: 
                // If the domain controller we are talking to is W2K 
                // (more specifically the schema is a W2K schema) then the
                // msDS-Behavior-Version attribute will not be present.
                // If that is the case, the domain functionality cannot be raised
                // to Windows2003InterimDomain or Windows2003Domain (which is when we would set this attribute)
                // since there are only W2K domain controllers
                // So, we catch that exception and throw a more meaningful one.
                domainEntry.CommitChanges();
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x8007200A))
                {
                    // attribute does not exist which means this is not a W2K3 DC
                    // cannot raise domain functionality
                    throw new ArgumentException(Res.GetString(Res.NoW2K3DCs), "domainMode");
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }
            finally
            {
                if (domainEntry != null)
                {
                    domainEntry.Dispose();
                }
            }

            // at this point the raise domain function has succeeded
            // invalidate the domain mode so that we get it from the server the next time
            _currentDomainMode = (DomainMode)(-1);
            _domainModeLevel = -1;
        }
コード例 #7
0
 public void RaiseDomainFunctionality(DomainMode domainMode)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
ファイル: Domain.cs プロジェクト: nlhepler/mono
		public void RaiseDomainFunctionality (DomainMode domainMode)
		{
			throw new NotImplementedException ();
		}