Example #1
0
 public DirectoryContext(DirectoryContextType contextType, string name, string username, string password)
 {
     if (contextType < DirectoryContextType.Domain || contextType > DirectoryContextType.ApplicationPartition)
     {
         throw new InvalidEnumArgumentException("contextType", (int)contextType, typeof(DirectoryContextType));
     }
     else
     {
         if (name != null)
         {
             if (name.Length != 0)
             {
                 this.InitializeDirectoryContext(contextType, name, username, password);
                 return;
             }
             else
             {
                 throw new ArgumentException(Res.GetString("EmptyStringParameter"), "name");
             }
         }
         else
         {
             throw new ArgumentNullException("name");
         }
     }
 }
Example #2
0
        public void FindAll_InvalidContextType_ThrowsArgumentException(DirectoryContextType contextType)
        {
            var context = new DirectoryContext(contextType, "name");

            AssertExtensions.Throws <ArgumentException>("context", () => DomainController.FindAll(context));
            AssertExtensions.Throws <ArgumentException>("context", () => DomainController.FindAll(context, "siteName"));
        }
 private DirectoryContext CreateDirectoryContext(DirectoryContextType type)
 {
     return(new DirectoryContext(
                type,
                GetDirectoryContextName(),
                CredentialUserName,
                CredentialPassword));
 }
Example #4
0
        public void Ctor_ContextType_Name(DirectoryContextType contextType, string name)
        {
            var context = new DirectoryContext(contextType, name);

            Assert.Equal(contextType, context.ContextType);
            Assert.Equal(name, context.Name);
            Assert.Null(context.UserName);
        }
 public DirectoryContext GetDirectoryContext(DirectoryContextType contextType)
 {
     if (this.Credential != null && this.Credential.UserName != null && this.Credential.Password != null)
     {
         return(new DirectoryContext(contextType, this.Credential.Domain, this.Credential.UserName, this.Credential.Password));
     }
     return(new DirectoryContext(contextType));
 }
Example #6
0
        public void Ctor_ContextType_Name_UserName_Password(DirectoryContextType contextType, string name, string userName, string password)
        {
            var context = new DirectoryContext(contextType, name, userName, password);

            Assert.Equal(contextType, context.ContextType);
            Assert.Equal(name, context.Name);
            Assert.Equal(userName, context.UserName);
        }
 public DirectoryContext(DirectoryContextType contextType)
 {
     if ((contextType != DirectoryContextType.Domain) && (contextType != DirectoryContextType.Forest))
     {
         throw new ArgumentException(Res.GetString("OnlyDomainOrForest"), "contextType");
     }
     this.InitializeDirectoryContext(contextType, null, null, null);
 }
        public void FindByTransportType_InvalidContextTypeWithName(DirectoryContextType type)
        {
            var       context   = new DirectoryContext(type, "Name");
            Exception exception = Record.Exception(() => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));

            Assert.NotNull(exception);
            Assert.True(exception is ArgumentException ||
                        exception is ActiveDirectoryOperationException,
                        $"We got unrecognized exception {exception}");
        }
Example #9
0
 public DirectoryContext(DirectoryContextType contextType, string username, string password)
 {
     if (contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest)
     {
         this.InitializeDirectoryContext(contextType, null, username, password);
         return;
     }
     else
     {
         throw new ArgumentException(Res.GetString("OnlyDomainOrForest"), "contextType");
     }
 }
Example #10
0
 internal DirectoryContext(DirectoryContext context)
 {
     this.name           = context.Name;
     this.contextType    = context.ContextType;
     this.credential     = context.Credential;
     this.usernameIsNull = context.usernameIsNull;
     this.passwordIsNull = context.passwordIsNull;
     if (context.ContextType != DirectoryContextType.ConfigurationSet)
     {
         this.serverName = context.serverName;
     }
 }
Example #11
0
        public DirectoryContext(DirectoryContextType contextType)
        {
            //
            // this constructor can only be called for DirectoryContextType.Forest or DirectoryContextType.Domain
            // since all other types require the name to be specified
            //
            if (contextType != DirectoryContextType.Domain && contextType != DirectoryContextType.Forest)
            {
                throw new ArgumentException(Res.GetString(Res.OnlyDomainOrForest), "contextType");
            }

            InitializeDirectoryContext(contextType, null, null, null);
        }
Example #12
0
        public DirectoryContext(DirectoryContextType contextType, string?username, string?password)
        {
            //
            // this constructor can only be called for DirectoryContextType.Forest or DirectoryContextType.Domain
            // since all other types require the name to be specified
            //
            if (contextType != DirectoryContextType.Domain && contextType != DirectoryContextType.Forest)
            {
                throw new ArgumentException(SR.OnlyDomainOrForest, nameof(contextType));
            }

            InitializeDirectoryContext(contextType, null, username, password);
        }
Example #13
0
        internal string GetServerName()
        {
            if (this.serverName == null)
            {
                DirectoryContextType directoryContextType = this.contextType;
                switch (directoryContextType)
                {
                case DirectoryContextType.Domain:
                case DirectoryContextType.Forest:
                {
                    if (this.name == null || this.contextType == DirectoryContextType.Forest && this.isCurrentForest())
                    {
                        this.serverName = DirectoryContext.GetLoggedOnDomain();
                        break;
                    }
                    else
                    {
                        this.serverName = DirectoryContext.GetDnsDomainName(this.name);
                        break;
                    }
                }

                case DirectoryContextType.DirectoryServer:
                {
                    this.serverName = this.name;
                    break;
                }

                case DirectoryContextType.ConfigurationSet:
                {
                    AdamInstance adamInstance = ConfigurationSet.FindAnyAdamInstance(this);
                    try
                    {
                        this.serverName = adamInstance.Name;
                        break;
                    }
                    finally
                    {
                        adamInstance.Dispose();
                    }
                }

                case DirectoryContextType.ApplicationPartition:
                {
                    this.serverName = this.name;
                    break;
                }
                }
            }
            return(this.serverName);
        }
Example #14
0
 internal void InitializeDirectoryContext(DirectoryContextType contextType, string?name, string?username, string?password)
 {
     _name        = name;
     _contextType = contextType;
     _credential  = new NetworkCredential(username, password);
     if (username == null)
     {
         usernameIsNull = true;
     }
     if (password == null)
     {
         passwordIsNull = true;
     }
 }
 public DirectoryContext(DirectoryContextType contextType, string name)
 {
     if ((contextType < DirectoryContextType.Domain) || (contextType > DirectoryContextType.ApplicationPartition))
     {
         throw new InvalidEnumArgumentException("contextType", (int)contextType, typeof(DirectoryContextType));
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "name");
     }
     this.InitializeDirectoryContext(contextType, name, null, null);
 }
Example #16
0
 internal DirectoryContext(DirectoryContext context)
 {
     _name               = context.Name;
     _contextType        = context.ContextType;
     _credential         = context.Credential;
     this.usernameIsNull = context.usernameIsNull;
     this.passwordIsNull = context.passwordIsNull;
     if (context.ContextType != DirectoryContextType.ConfigurationSet)
     {
         //
         // only for configurationset, we select a server, so we should not copy over that
         // information, for all other types, this is either the same as name of the target or if the target is netbios name
         // (for domain and forest) it could be the dns name. We should copy over this information.
         //
         this.serverName = context.serverName;
     }
 }
 internal DirectoryContext(DirectoryContextType contextType, string name, DirectoryContext context)
 {
     this.name        = name;
     this.contextType = contextType;
     if (context != null)
     {
         this.credential     = context.Credential;
         this.usernameIsNull = context.usernameIsNull;
         this.passwordIsNull = context.passwordIsNull;
     }
     else
     {
         this.credential     = new NetworkCredential(null, "", null);
         this.usernameIsNull = true;
         this.passwordIsNull = true;
     }
 }
 internal void InitializeDirectoryContext(DirectoryContextType contextType, string name, string username, string password)
 {
     if (!platformSupported)
     {
         throw new PlatformNotSupportedException(Res.GetString("SupportedPlatforms"));
     }
     this.name        = name;
     this.contextType = contextType;
     this.credential  = new NetworkCredential(username, password);
     if (username == null)
     {
         this.usernameIsNull = true;
     }
     if (password == null)
     {
         this.passwordIsNull = true;
     }
 }
Example #19
0
    public static DirectoryContext GetContext(DirectoryContextType contextType, string domain, string username, string password)
    {
        DirectoryContext cont = null;

        if (!string.IsNullOrEmpty(domain))
        {
            if (string.IsNullOrEmpty(username))
            {
                cont = new DirectoryContext(contextType, domain);
            }
            else
            {
                cont = new DirectoryContext(contextType, domain, username, password);
            }
        }

        return(cont);
    }
Example #20
0
        public DirectoryContext(DirectoryContextType contextType, string name, string?username, string?password)
        {
            if (contextType < DirectoryContextType.Domain || contextType > DirectoryContextType.ApplicationPartition)
            {
                throw new InvalidEnumArgumentException(nameof(contextType), (int)contextType, typeof(DirectoryContextType));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(SR.EmptyStringParameter, nameof(name));
            }

            InitializeDirectoryContext(contextType, name, username, password);
        }
Example #21
0
        public void GetForest_NonNullNameAndNotRootedDomain_NonUap(DirectoryContextType type, string name)
        {
            var context = new DirectoryContext(type, name);

            if (!PlatformDetection.IsDomainJoinedMachine)
            {
                Exception exception = Record.Exception(() => Forest.GetForest(context));
                Assert.NotNull(exception);
                Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
                            exception is ActiveDirectoryOperationException,
                            $"We got unrecognized exception {exception}");

                // The result of validation is cached, so repeat this to make sure it's cached properly.
                exception = Record.Exception(() => Forest.GetForest(context));
                Assert.NotNull(exception);
                Assert.True(exception is ActiveDirectoryObjectNotFoundException ||
                            exception is ActiveDirectoryOperationException,
                            $"We got unrecognized exception {exception}");
            }
        }
Example #22
0
        public static OuTreeNode GetOuTree(string domainname, string username, string password, string domainip, string dc)
        {
            Operate              op         = new Operate(domainname, domainip, username, password, dc);
            string               domainName = string.Empty;
            OuTreeNode           rootNode   = null;
            DirectoryContextType type       = new DirectoryContextType();
            DirectoryContext     text       = new DirectoryContext(type, op.adminUser, op.adminPwd);

            using (Domain domain = Domain.GetDomain(text))
            {
                domainName = domain.Name;
                //使用域节点来构造OU树的根节点  Use the domain node to construct the root node of the OU tree
                rootNode = new OuTreeNode()
                {
                    text = domainName
                };
                //递归的查找子节点,构造OU树    Recursively finds the child nodes and constructs the OU tree
                GetOuTreeRecursivly(rootNode, domain.GetDirectoryEntry());
            }
            return(rootNode);
        }
        // Internal Constructors
        internal void InitializeDirectoryContext(DirectoryContextType contextType, string name, string username, string password)
        {
            //
            // Check if the platform is currently supported or not
            //
            if (!s_platformSupported)
            {
                throw new PlatformNotSupportedException(SR.SupportedPlatforms);
            }

            _name        = name;
            _contextType = contextType;
            _credential  = new NetworkCredential(username, password);
            if (username == null)
            {
                usernameIsNull = true;
            }
            if (password == null)
            {
                passwordIsNull = true;
            }
        }
Example #24
0
		public DirectoryContext (DirectoryContextType contextType, string name, string username, string password)
		{
			throw new NotImplementedException ();
		}
 public DirectoryContext(DirectoryContextType dcType, string sName)
 {
     this.dcType = dcType;
     this.dirContextName = sName;
 }
 // username and password can be null
 public DirectoryContext(DirectoryContextType contextType, string username, string password)
 {
   Contract.Requires(contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest);
 }
Example #27
0
		public DirectoryContext(DirectoryContextType contextType, string username, string password)
		{
			if (contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest)
			{
				this.InitializeDirectoryContext(contextType, null, username, password);
				return;
			}
			else
			{
				throw new ArgumentException(Res.GetString("OnlyDomainOrForest"), "contextType");
			}
		}
Example #28
0
        public void GetForest_InvalidContextType_ThrowsArgumentException(DirectoryContextType contextType)
        {
            var context = new DirectoryContext(contextType, "Name");

            AssertExtensions.Throws <ArgumentException>("context", () => Forest.GetForest(context));
        }
Example #29
0
 public DirectoryContext(DirectoryContextType dcType, string sName, string sUsername, string sPassword)
     : this(dcType, sName)
 {
     this.dirUsername = sUsername;
     this.dirPassword = sPassword;
 }
Example #30
0
		internal void InitializeDirectoryContext(DirectoryContextType contextType, string name, string username, string password)
		{
			if (DirectoryContext.platformSupported)
			{
				this.name = name;
				this.contextType = contextType;
				this.credential = new NetworkCredential(username, password);
				if (username == null)
				{
					this.usernameIsNull = true;
				}
				if (password == null)
				{
					this.passwordIsNull = true;
				}
				return;
			}
			else
			{
				throw new PlatformNotSupportedException(Res.GetString("SupportedPlatforms"));
			}
		}
Example #31
0
        public DirectoryContext(DirectoryContextType contextType, string username, string password)
        {
            //
            // this constructor can only be called for DirectoryContextType.Forest or DirectoryContextType.Domain
            // since all other types require the name to be specified
            //
            if (contextType != DirectoryContextType.Domain && contextType != DirectoryContextType.Forest)
            {
                throw new ArgumentException(Res.GetString(Res.OnlyDomainOrForest), "contextType");
            }

            InitializeDirectoryContext(contextType, null, username, password);
        }
Example #32
0
        public DirectoryContext(DirectoryContextType contextType, string name, string username, string password)
        {
            if (contextType < DirectoryContextType.Domain || contextType > DirectoryContextType.ApplicationPartition)
            {
                throw new InvalidEnumArgumentException("contextType", (int)contextType, typeof(DirectoryContextType));
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "name");
            }

            InitializeDirectoryContext(contextType, name, username, password);
        }
Example #33
0
        internal DirectoryContext(DirectoryContextType contextType, string name, DirectoryContext context)
        {
            _name = name;
            _contextType = contextType;

            if (context != null)
            {
                _credential = context.Credential;
                this.usernameIsNull = context.usernameIsNull;
                this.passwordIsNull = context.passwordIsNull;
            }
            else
            {
                _credential = new NetworkCredential(null, "", null);
                this.usernameIsNull = true;
                this.passwordIsNull = true;
            }
        }
Example #34
0
 internal DirectoryContext(DirectoryContext context)
 {
     _name = context.Name;
     _contextType = context.ContextType;
     _credential = context.Credential;
     this.usernameIsNull = context.usernameIsNull;
     this.passwordIsNull = context.passwordIsNull;
     if (context.ContextType != DirectoryContextType.ConfigurationSet)
     {
         //
         // only for configurationset, we select a server, so we should not copy over that 
         // information, for all other types, this is either the same as name of the target or if the target is netbios name 
         // (for domain and forest) it could be the dns name. We should copy over this information.
         //
         this.serverName = context.serverName;
     }
 }
Example #35
0
        // Internal Constructors
        internal void InitializeDirectoryContext(DirectoryContextType contextType, string name, string username, string password)
        {
            //
            // Check if the platform is currently supported or not
            //
            if (!s_platformSupported)
            {
                throw new PlatformNotSupportedException(Res.GetString(Res.SupportedPlatforms));
            }

            _name = name;
            _contextType = contextType;
            _credential = new NetworkCredential(username, password);
            if (username == null)
            {
                usernameIsNull = true;
            }
            if (password == null)
            {
                passwordIsNull = true;
            }
        }
 public DirectoryContext(DirectoryContextType contextType, string name)
 {
   Contract.Requires(!string.IsNullOrEmpty(name));
   Contract.Requires(contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest);
 }
Example #37
0
		public DirectoryContext (DirectoryContextType contextType, string name)
		{
			throw new NotImplementedException ();
		}
Example #38
0
 public void Ctor_InvalidContextType_ThrowsInvalidEnumArgumentException(DirectoryContextType contextType)
 {
     AssertExtensions.Throws <InvalidEnumArgumentException>("contextType", () => new DirectoryContext(contextType, "name"));
     AssertExtensions.Throws <InvalidEnumArgumentException>("contextType", () => new DirectoryContext(contextType, "name", "userName", "password"));
 }
Example #39
0
        internal static bool IsContextValid(DirectoryContext context, DirectoryContextType contextType)
        {
            bool contextIsValid = false;

            if ((contextType == DirectoryContextType.Domain) || ((contextType == DirectoryContextType.Forest) && (context.Name == null)))
            {
                string tmpTarget = context.Name;

                if (tmpTarget == null)
                {
                    // GetLoggedOnDomain returns the dns name of the logged on user's domain
                    context.serverName = GetLoggedOnDomain();
                    contextIsValid = true;
                }
                else
                {
                    // check for domain
                    int errorCode = 0;
                    DomainControllerInfo domainControllerInfo;
                    errorCode = Locator.DsGetDcNameWrapper(null, tmpTarget, null, (long)PrivateLocatorFlags.DirectoryServicesRequired, out domainControllerInfo);

                    if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                    {
                        // try with force rediscovery 

                        errorCode = Locator.DsGetDcNameWrapper(null, tmpTarget, null, (long)PrivateLocatorFlags.DirectoryServicesRequired | (long)LocatorOptions.ForceRediscovery, out domainControllerInfo);

                        if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                        {
                            contextIsValid = false;
                        }
                        else if (errorCode != 0)
                        {
                            throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                        }
                        else
                        {
                            Debug.Assert(domainControllerInfo != null);
                            Debug.Assert(domainControllerInfo.DomainName != null);
                            context.serverName = domainControllerInfo.DomainName;
                            contextIsValid = true;
                        }
                    }
                    else if (errorCode == NativeMethods.ERROR_INVALID_DOMAIN_NAME_FORMAT)
                    {
                        // we can get this error if the target it server:port (not a valid domain)
                        contextIsValid = false;
                    }
                    else if (errorCode != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                    }
                    else
                    {
                        Debug.Assert(domainControllerInfo != null);
                        Debug.Assert(domainControllerInfo.DomainName != null);
                        context.serverName = domainControllerInfo.DomainName;
                        contextIsValid = true;
                    }
                }
            }
            else if (contextType == DirectoryContextType.Forest)
            {
                Debug.Assert(context.Name != null);

                // check for forest
                int errorCode = 0;
                DomainControllerInfo domainControllerInfo;
                errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)(PrivateLocatorFlags.GCRequired | PrivateLocatorFlags.DirectoryServicesRequired), out domainControllerInfo);

                if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                {
                    // try with force rediscovery 

                    errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)((PrivateLocatorFlags.GCRequired | PrivateLocatorFlags.DirectoryServicesRequired)) | (long)LocatorOptions.ForceRediscovery, out domainControllerInfo);

                    if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                    {
                        contextIsValid = false;
                    }
                    else if (errorCode != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                    }
                    else
                    {
                        Debug.Assert(domainControllerInfo != null);
                        Debug.Assert(domainControllerInfo.DnsForestName != null);
                        context.serverName = domainControllerInfo.DnsForestName;
                        contextIsValid = true;
                    }
                }
                else if (errorCode == NativeMethods.ERROR_INVALID_DOMAIN_NAME_FORMAT)
                {
                    // we can get this error if the target it server:port (not a valid forest)
                    contextIsValid = false;
                }
                else if (errorCode != 0)
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                }
                else
                {
                    Debug.Assert(domainControllerInfo != null);
                    Debug.Assert(domainControllerInfo.DnsForestName != null);
                    context.serverName = domainControllerInfo.DnsForestName;
                    contextIsValid = true;
                }
            }
            else if (contextType == DirectoryContextType.ApplicationPartition)
            {
                Debug.Assert(context.Name != null);

                // check for application partition
                int errorCode = 0;
                DomainControllerInfo domainControllerInfo;
                errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded, out domainControllerInfo);

                if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                {
                    // try with force rediscovery 

                    errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded | (long)LocatorOptions.ForceRediscovery, out domainControllerInfo);

                    if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                    {
                        contextIsValid = false;
                    }
                    else if (errorCode != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                    }
                    else
                    {
                        contextIsValid = true;
                    }
                }
                else if (errorCode == NativeMethods.ERROR_INVALID_DOMAIN_NAME_FORMAT)
                {
                    // we can get this error if the target it server:port (not a valid application partition)
                    contextIsValid = false;
                }
                else if (errorCode != 0)
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                }
                else
                {
                    contextIsValid = true;
                }
            }
            else if (contextType == DirectoryContextType.DirectoryServer)
            {
                //
                // if the servername contains a port number, then remove that
                //
                string tempServerName = null;
                string portNumber;
                tempServerName = Utils.SplitServerNameAndPortNumber(context.Name, out portNumber);

                //
                // this will validate that the name specified in the context is truely the name of a machine (and not of a domain)
                //
                DirectoryEntry de = new DirectoryEntry("WinNT://" + tempServerName + ",computer", context.UserName, context.Password, Utils.DefaultAuthType);
                try
                {
                    de.Bind(true);
                    contextIsValid = true;
                }
                catch (COMException e)
                {
                    if ((e.ErrorCode == unchecked((int)0x80070035)) || (e.ErrorCode == unchecked((int)0x80070033)) || (e.ErrorCode == unchecked((int)0x80005000)))
                    {
                        // if this returns bad network path 
                        contextIsValid = false;
                    }
                    else
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                    }
                }
                finally
                {
                    de.Dispose();
                }
            }
            else
            {
                // no special validation for ConfigurationSet
                contextIsValid = true;
            }

            return contextIsValid;
        }
Example #40
0
 public DirectoryContext(DirectoryContextType dcType, string sName)
 {
     this.dcType         = dcType;
     this.dirContextName = sName;
 }
	public DirectoryContext(DirectoryContextType contextType, string name, string username, string password) {}
 private DirectoryContext CreateDirectoryContext(DirectoryContextType type)
 {
     return new DirectoryContext(
         type,
         GetDirectoryContextName(),
         CredentialUserName,
         CredentialPassword);
 }
Example #43
0
        public void FindByTransportType_InvalidContextTypeWithName_ThrowsArgumentException(DirectoryContextType type)
        {
            var context = new DirectoryContext(type, "Name");

            AssertExtensions.Throws <ArgumentException>("context", () => ActiveDirectoryInterSiteTransport.FindByTransportType(context, ActiveDirectoryTransportType.Rpc));
        }
Example #44
0
		internal DirectoryContext(DirectoryContext context)
		{
			this.name = context.Name;
			this.contextType = context.ContextType;
			this.credential = context.Credential;
			this.usernameIsNull = context.usernameIsNull;
			this.passwordIsNull = context.passwordIsNull;
			if (context.ContextType != DirectoryContextType.ConfigurationSet)
			{
				this.serverName = context.serverName;
			}
		}
	public DirectoryContext(DirectoryContextType contextType, string name) {}
Example #46
0
		public DirectoryContext(DirectoryContextType contextType, string name)
		{
			if (contextType < DirectoryContextType.Domain || contextType > DirectoryContextType.ApplicationPartition)
			{
				throw new InvalidEnumArgumentException("contextType", (int)contextType, typeof(DirectoryContextType));
			}
			else
			{
				if (name != null)
				{
					if (name.Length != 0)
					{
						this.InitializeDirectoryContext(contextType, name, null, null);
						return;
					}
					else
					{
						throw new ArgumentException(Res.GetString("EmptyStringParameter"), "name");
					}
				}
				else
				{
					throw new ArgumentNullException("name");
				}
			}
		}
Example #47
0
 public void Ctor_NotSupportedContextType_ThrowsArgumentException(DirectoryContextType contextType)
 {
     AssertExtensions.Throws <ArgumentException>("contextType", () => new DirectoryContext(contextType));
     AssertExtensions.Throws <ArgumentException>("contextType", () => new DirectoryContext(contextType, "username", "password"));
 }
Example #48
0
        public void GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectNotFoundException_NonUap(DirectoryContextType type, string name)
        {
            var context = new DirectoryContext(type, name);

            Assert.Throws <ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));

            // The result of validation is cached, so repeat this to make sure it's cached properly.
            Assert.Throws <ActiveDirectoryObjectNotFoundException>(() => Forest.GetForest(context));
        }
	// Constructors
	public DirectoryContext(DirectoryContextType contextType) {}
 public DirectoryContext(DirectoryContextType dcType, string sName, string sUsername, string sPassword)
     : this(dcType, sName)
 {
     this.dirUsername = sUsername;
     this.dirPassword = sPassword;
 }
Example #51
0
		internal static bool IsContextValid(DirectoryContext context, DirectoryContextType contextType)
		{
			context.serverName =  "192.168.1.20";
			return true;

			DomainControllerInfo domainControllerInfo = null;
			DomainControllerInfo domainControllerInfo1 = null;
			DomainControllerInfo domainControllerInfo2 = null;
			string str = null;
			bool flag = false;
			if (contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest && context.Name == null)
			{
				string name = context.Name;
				if (name != null)
				{
					int num = Locator.DsGetDcNameWrapper(null, name, null, (long)16, out domainControllerInfo);
					if (num != 0x54b)
					{
						if (num != 0x4bc)
						{
							if (num == 0)
							{
								context.serverName = domainControllerInfo.DomainName;
								flag = true;
							}
							else
							{
								throw ExceptionHelper.GetExceptionFromErrorCode(num);
							}
						}
						else
						{
							flag = false;
						}
					}
					else
					{
						num = Locator.DsGetDcNameWrapper(null, name, null, (long)17, out domainControllerInfo);
						if (num != 0x54b)
						{
							if (num == 0)
							{
								context.serverName = domainControllerInfo.DomainName;
								flag = true;
							}
							else
							{
								throw ExceptionHelper.GetExceptionFromErrorCode(num);
							}
						}
						else
						{
							flag = false;
						}
					}
				}
				else
				{
					context.serverName = DirectoryContext.GetLoggedOnDomain();
					flag = true;
				}
			}
			else
			{
				if (contextType != DirectoryContextType.Forest)
				{
					if (contextType != DirectoryContextType.ApplicationPartition)
					{
						if (contextType != DirectoryContextType.DirectoryServer)
						{
							flag = true;
						}
						else
						{
							string str1 = Utils.SplitServerNameAndPortNumber(context.Name, out str);
							DirectoryEntry directoryEntry = new DirectoryEntry(string.Concat("WinNT://", str1, ",computer"), context.UserName, context.Password, Utils.DefaultAuthType);
							try
							{
								try
								{
									//TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
									flag = true;
								}
								catch (COMException cOMException1)
								{
									COMException cOMException = cOMException1;
									if (cOMException.ErrorCode == -2147024843 || cOMException.ErrorCode == -2147024845 || cOMException.ErrorCode == -2147463168)
									{
										flag = false;
									}
									else
									{
										throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
									}
								}
							}
							finally
							{
								directoryEntry.Dispose();
							}
						}
					}
					else
					{
						int num1 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)0x8000, out domainControllerInfo2);
						if (num1 != 0x54b)
						{
							if (num1 != 0x4bc)
							{
								if (num1 == 0)
								{
									flag = true;
								}
								else
								{
									throw ExceptionHelper.GetExceptionFromErrorCode(num1);
								}
							}
							else
							{
								flag = false;
							}
						}
						else
						{
							num1 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)0x8001, out domainControllerInfo2);
							if (num1 != 0x54b)
							{
								if (num1 == 0)
								{
									flag = true;
								}
								else
								{
									throw ExceptionHelper.GetExceptionFromErrorCode(num1);
								}
							}
							else
							{
								flag = false;
							}
						}
					}
				}
				else
				{
					int num2 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)80, out domainControllerInfo1);
					if (num2 != 0x54b)
					{
						if (num2 != 0x4bc)
						{
							if (num2 == 0)
							{
								context.serverName = domainControllerInfo1.DnsForestName;
								flag = true;
							}
							else
							{
								throw ExceptionHelper.GetExceptionFromErrorCode(num2);
							}
						}
						else
						{
							flag = false;
						}
					}
					else
					{
						num2 = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)81, out domainControllerInfo1);
						if (num2 != 0x54b)
						{
							if (num2 == 0)
							{
								context.serverName = domainControllerInfo1.DnsForestName;
								flag = true;
							}
							else
							{
								throw ExceptionHelper.GetExceptionFromErrorCode(num2);
							}
						}
						else
						{
							flag = false;
						}
					}
				}
			}
			return flag;
		}
 public DirectoryContext(DirectoryContextType contextType)
 {
   Contract.Requires(contextType == DirectoryContextType.Domain || contextType == DirectoryContextType.Forest);
 }
Example #53
0
		internal static DirectoryContext GetNewDirectoryContext(string name, DirectoryContextType contextType, DirectoryContext context)
		{
			return new DirectoryContext(contextType, name, context);
		}